Compare commits

...

36 Commits

Author SHA1 Message Date
Márk Tolmács 4eb1bd8036 Merge branch 'master' into mtolmacs/fix/small-elbow-routing 2025-05-05 09:56:19 +02:00
Márk Tolmács e19fd1332a feat: Precise highlights for bindings (#9472) 2025-05-05 09:51:20 +02:00
Hazem Krimi 6e655cdb24 fix: When moving a frame through the stats inputs or drags move along its children (#9433)
Co-authored-by: Mark Tolmacs <mark@lazycat.hu>
2025-05-02 17:07:17 +02:00
Márk Tolmács 8d7ffa21d1 Merge branch 'master' into mtolmacs/fix/small-elbow-routing 2025-05-02 09:47:18 +02:00
Gowtham Selvaraj 192c4e7658 docs: added shape cycling shortcut in helper dialog (#9465)
* docs: added shape cycling shortcut in helper dialog

- Document Tab and Shift+Tab usage for shape cycling

* docs: added shape cycling shortcut in helper dialog

* Update packages/excalidraw/components/HelpDialog.tsx

* Update packages/excalidraw/locales/en.json

---------

Co-authored-by: David Luzar <5153846+dwelle@users.noreply.github.com>
2025-05-01 12:12:45 +02:00
Ryan Di 195a743874 feat: switch between basic shapes (#9270)
* feat: switch between basic shapes

* add tab for testing

* style tweaks

* only show hint when a new node is created

* fix panel state

* refactor

* combine captures into one

* keep original font size

* switch multi

* switch different types altogether

* use tab only

* fix font size atom

* do not switch from active tool change

* prefer generic when mixed

* provide an optional direction when shape switching

* adjust panel bg & shadow

* redraw to correctly position text

* remove redundant code

* only tab to switch if focusing on app container

* limit which linear elements can be switched

* add shape switch to command palette

* remove hint

* cache initial panel position

* bend line to elbow if needed

* remove debug logic

* clean switch of arrows using app state

* safe conversion between line, sharp, curved, and elbow

* cache linear when panel shows up

* type safe element conversion

* rename type

* respect initial type when switching between linears

* fix elbow segment indexing

* use latest linear

* merge converted elbow points if too close

* focus on panel after click

* set roudness to null to fix drag points offset for elbows

* remove Mutable

* add arrowBoundToElement check

* make it dependent on one signle state

* unmount when not showing

* simpler types, tidy up code

* can change linear when it's linear + non-generic

* fix popup component lifecycle

* move constant to CLASSES

* DRY out type detection

* file & variable renaming

* refactor

* throw in not-prod instead

* simplify

* semi-fix bindings on `generic` type conversion

---------

Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
2025-04-30 18:07:31 +02:00
dwelle 82cef23c3d DEBUG 2025-04-30 10:39:54 +02:00
David Luzar 4a60fe3d22 fix: remove noreferrer on internal links (#9452)
* fix: remove `noreferrer` on internal links

* fix snaps

* fix lint
2025-04-29 18:45:17 +02:00
Mark Tolmacs 541725ff5a Test fixes 2025-04-28 19:49:41 +02:00
Mark Tolmacs 28066034d7 Arrowhead padding 2025-04-28 19:37:50 +02:00
Mark Tolmacs 7d0d6aec7a Another algo forpaddings 2025-04-28 19:31:30 +02:00
Mark Tolmacs e6ade3b627 Fix test 2025-04-25 18:58:05 +02:00
Mark Tolmacs 9a2bd18904 Further adjustments for edge cases 2025-04-25 18:54:18 +02:00
Mark Tolmacs c7c6a4c3f1 Fix test 2025-04-25 14:33:34 +02:00
Márk Tolmács 9c27f936de Merge branch 'master' into mtolmacs/fix/small-elbow-routing 2025-04-25 14:27:15 +02:00
Mark Tolmacs b8fdd7ef23 Remove unneeded imports 2025-04-25 14:26:01 +02:00
Mark Tolmacs ece841326b Refine corner avoidance 2025-04-25 14:25:40 +02:00
Narek Malkhasyan 2a0d15799c fix: when dragging arrow endpoint, update binding only on the dragged side (#9367) 2025-04-25 10:46:58 +02:00
CharitSinghChauhan a18b139a60 fix: laser pointer trail disappearing on pointerup (#9413) (#9427)
* Fix laser pointer trail disappearing on pointerup (#9413)

Previously, the laser pointer trail would disappear as soon as the pointerup event was triggered. This fix delays the trail removal to ensure it persists for a smoother visual experience.

Fixes #9413.

* Remove extra blank lines

Minor formatting cleanup. No functional changes.
2025-04-24 10:05:08 +10:00
Mark Tolmacs 41711af210 Adjust padding so smaller objects have smaller padding 2025-04-21 17:24:13 +02:00
Mark Tolmacs 230e47fd52 Remove debug 2025-04-21 14:56:58 +02:00
Mark Tolmacs 52445aeb68 Fix a particular routing issue 2025-04-21 14:56:36 +02:00
Márk Tolmács bc9f34e71e Merge branch 'master' into mtolmacs/fix/small-elbow-routing 2025-04-21 12:30:49 +02:00
Márk Tolmács 22aade07b3 Merge branch 'master' into mtolmacs/fix/small-elbow-routing 2025-04-16 21:50:42 +02:00
Mark Tolmacs c2de1304b7 Add snapshot update
Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
2025-04-15 16:13:01 +02:00
Mark Tolmacs 25fb43f5b7 Snapshot update
Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
2025-04-14 19:05:34 +02:00
Márk Tolmács 6dfa5de66c Merge branch 'master' into mtolmacs/fix/small-elbow-routing 2025-04-14 18:54:01 +02:00
Mark Tolmacs 7abbb2afa3 New heuristic based on minimal arrow extent
Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
2025-04-14 18:52:51 +02:00
Mark Tolmacs aa91a3d610 Adaptive segment unification 2025-04-13 13:52:24 +02:00
Mark Tolmacs 25d6e517c9 Revert attempt to exclude some files from coverage 2025-04-13 13:29:21 +02:00
Mark Tolmacs d5e33730ab Reduce scope of coverage reports 2025-04-13 13:19:45 +02:00
Mark Tolmacs c06b78c1b2 Further fine-tune adaptive padding 2025-04-13 13:08:22 +02:00
Mark Tolmacs eaa869620e Fine tuning 2025-04-11 21:53:23 +02:00
Mark Tolmacs a8338cdb5a More adaptive elbow dongle offset 2025-04-11 21:08:55 +02:00
Mark Tolmacs 1ee3676784 Move visal debug to @excalidraw/util 2025-04-11 15:39:31 +02:00
Mark Tolmacs f12f7e4b50 Fix sentry#6530117915 2025-04-11 10:24:02 +02:00
44 changed files with 2160 additions and 390 deletions
+6
View File
@@ -32,6 +32,12 @@
"name": "jotai",
"message": "Do not import from \"jotai\" directly. Use our app-specific modules (\"editor-jotai\" or \"app-jotai\")."
}
],
"react/jsx-no-target-blank": [
"error",
{
"allowReferrer": true
}
]
}
}
+1 -1
View File
@@ -73,7 +73,7 @@ export const AIComponents = ({
</br>
<div>You can also try <a href="${
import.meta.env.VITE_APP_PLUS_LP
}/plus?utm_source=excalidraw&utm_medium=app&utm_content=d2c" target="_blank" rel="noreferrer noopener">Excalidraw+</a> to get more requests.</div>
}/plus?utm_source=excalidraw&utm_medium=app&utm_content=d2c" target="_blank" rel="noopener">Excalidraw+</a> to get more requests.</div>
</div>
</body>
</html>`,
+1 -1
View File
@@ -18,7 +18,7 @@ import {
} from "@excalidraw/math";
import { isCurve } from "@excalidraw/math/curve";
import type { DebugElement } from "@excalidraw/excalidraw/visualdebug";
import type { DebugElement } from "@excalidraw/utils/visualdebug";
import type { Curve } from "@excalidraw/math";
+1 -1
View File
@@ -10,7 +10,7 @@ export const EncryptedIcon = () => {
className="encrypted-icon tooltip"
href="https://plus.excalidraw.com/blog/end-to-end-encryption"
target="_blank"
rel="noopener noreferrer"
rel="noopener"
aria-label={t("encrypted.link")}
>
<Tooltip label={t("encrypted.tooltip")} long={true}>
@@ -10,7 +10,7 @@ export const ExcalidrawPlusAppLink = () => {
import.meta.env.VITE_APP_PLUS_APP
}?utm_source=excalidraw&utm_medium=app&utm_content=signedInUserRedirectButton#excalidraw-redirect`}
target="_blank"
rel="noreferrer"
rel="noopener"
className="plus-button"
>
Go to Excalidraw+
@@ -198,7 +198,7 @@ exports[`Test MobileMenu > should initialize with welcome screen and hide once u
<a
class="welcome-screen-menu-item "
href="undefined/plus?utm_source=excalidraw&utm_medium=app&utm_content=welcomeScreenGuest"
rel="noreferrer"
rel="noopener"
target="_blank"
>
<div
+1
View File
@@ -119,6 +119,7 @@ export const CLASSES = {
SHAPE_ACTIONS_MENU: "App-menu__left",
ZOOM_ACTIONS: "zoom-actions",
SEARCH_MENU_INPUT_WRAPPER: "layer-ui__search-inputWrapper",
CONVERT_ELEMENT_TYPE_POPUP: "ConvertElementTypePopup",
};
export const CJK_HAND_DRAWN_FALLBACK_FONT = "Xiaolai";
+75 -33
View File
@@ -43,6 +43,12 @@ import {
import { intersectElementWithLineSegment } from "./collision";
import { distanceToBindableElement } from "./distance";
import {
compareHeading,
HEADING_DOWN,
HEADING_LEFT,
HEADING_RIGHT,
HEADING_UP,
headingForPoint,
headingForPointFromElement,
headingIsHorizontal,
vectorToHeading,
@@ -81,7 +87,6 @@ import type {
NonDeletedSceneElementsMap,
ExcalidrawTextElement,
ExcalidrawArrowElement,
OrderedExcalidrawElement,
ExcalidrawElbowArrowElement,
FixedPoint,
FixedPointBinding,
@@ -276,15 +281,6 @@ const getBindingStrategyForDraggingArrowEndpoints = (
zoom,
)
: null // If binding is disabled and start is dragged, break all binds
: !isElbowArrow(selectedElement)
? // We have to update the focus and gap of the binding, so let's rebind
getElligibleElementForBindingElement(
selectedElement,
"start",
elementsMap,
elements,
zoom,
)
: "keep";
const end = endDragged
? isBindingEnabled
@@ -296,15 +292,6 @@ const getBindingStrategyForDraggingArrowEndpoints = (
zoom,
)
: null // If binding is disabled and end is dragged, break all binds
: !isElbowArrow(selectedElement)
? // We have to update the focus and gap of the binding, so let's rebind
getElligibleElementForBindingElement(
selectedElement,
"end",
elementsMap,
elements,
zoom,
)
: "keep";
return [start, end];
@@ -728,29 +715,32 @@ const calculateFocusAndGap = (
// Supports translating, rotating and scaling `changedElement` with bound
// linear elements.
// Because scaling involves moving the focus points as well, it is
// done before the `changedElement` is updated, and the `newSize` is passed
// in explicitly.
export const updateBoundElements = (
changedElement: NonDeletedExcalidrawElement,
scene: Scene,
options?: {
simultaneouslyUpdated?: readonly ExcalidrawElement[];
newSize?: { width: number; height: number };
changedElements?: Map<string, OrderedExcalidrawElement>;
changedElements?: Map<string, ExcalidrawElement>;
},
) => {
if (!isBindableElement(changedElement)) {
return;
}
const { newSize, simultaneouslyUpdated } = options ?? {};
const simultaneouslyUpdatedElementIds = getSimultaneouslyUpdatedElementIds(
simultaneouslyUpdated,
);
if (!isBindableElement(changedElement)) {
return;
let elementsMap: ElementsMap = scene.getNonDeletedElementsMap();
if (options?.changedElements) {
elementsMap = new Map(elementsMap) as typeof elementsMap;
options.changedElements.forEach((element) => {
elementsMap.set(element.id, element);
});
}
const elementsMap = scene.getNonDeletedElementsMap();
boundElementsVisitor(elementsMap, changedElement, (element) => {
if (!isLinearElement(element) || element.isDeleted) {
return;
@@ -854,6 +844,25 @@ export const updateBoundElements = (
});
};
export const updateBindings = (
latestElement: ExcalidrawElement,
scene: Scene,
options?: {
simultaneouslyUpdated?: readonly ExcalidrawElement[];
newSize?: { width: number; height: number };
zoom?: AppState["zoom"];
},
) => {
if (isLinearElement(latestElement)) {
bindOrUnbindLinearElements([latestElement], true, [], scene, options?.zoom);
} else {
updateBoundElements(latestElement, scene, {
...options,
changedElements: new Map([[latestElement.id, latestElement]]),
});
}
};
const doesNeedUpdate = (
boundElement: NonDeleted<ExcalidrawLinearElement>,
changedElement: ExcalidrawBindableElement,
@@ -1022,7 +1031,14 @@ export const avoidRectangularCorner = (
if (nonRotatedPoint[0] < element.x && nonRotatedPoint[1] < element.y) {
// Top left
if (nonRotatedPoint[1] - element.y > -FIXED_BINDING_DISTANCE) {
const heading = headingForPoint(
nonRotatedPoint,
pointFrom(element.x, element.y),
);
if (
compareHeading(heading, HEADING_DOWN) ||
compareHeading(heading, HEADING_LEFT)
) {
return pointRotateRads<GlobalPoint>(
pointFrom(element.x - FIXED_BINDING_DISTANCE, element.y),
center,
@@ -1039,7 +1055,14 @@ export const avoidRectangularCorner = (
nonRotatedPoint[1] > element.y + element.height
) {
// Bottom left
if (nonRotatedPoint[0] - element.x > -FIXED_BINDING_DISTANCE) {
const heading = headingForPoint(
nonRotatedPoint,
pointFrom(element.x, element.y + element.height),
);
if (
compareHeading(heading, HEADING_DOWN) ||
compareHeading(heading, HEADING_RIGHT)
) {
return pointRotateRads(
pointFrom(
element.x,
@@ -1059,9 +1082,13 @@ export const avoidRectangularCorner = (
nonRotatedPoint[1] > element.y + element.height
) {
// Bottom right
const heading = headingForPoint(
nonRotatedPoint,
pointFrom(element.x + element.width, element.y + element.height),
);
if (
nonRotatedPoint[0] - element.x <
element.width + FIXED_BINDING_DISTANCE
compareHeading(heading, HEADING_DOWN) ||
compareHeading(heading, HEADING_LEFT)
) {
return pointRotateRads(
pointFrom(
@@ -1085,9 +1112,13 @@ export const avoidRectangularCorner = (
nonRotatedPoint[1] < element.y
) {
// Top right
const heading = headingForPoint(
nonRotatedPoint,
pointFrom(element.x + element.width, element.y),
);
if (
nonRotatedPoint[0] - element.x <
element.width + FIXED_BINDING_DISTANCE
compareHeading(heading, HEADING_UP) ||
compareHeading(heading, HEADING_LEFT)
) {
return pointRotateRads(
pointFrom(
@@ -1105,6 +1136,17 @@ export const avoidRectangularCorner = (
);
}
// Break up explicit border bindings to have better elbow arrow routing
if (p[0] === element.x) {
return pointFrom(p[0] - FIXED_BINDING_DISTANCE, p[1]);
} else if (p[0] === element.x + element.width) {
return pointFrom(p[0] + FIXED_BINDING_DISTANCE, p[1]);
} else if (p[1] === element.y) {
return pointFrom(p[0], p[1] - FIXED_BINDING_DISTANCE);
} else if (p[1] === element.y + element.height) {
return pointFrom(p[0], p[1] + FIXED_BINDING_DISTANCE);
}
return p;
};
+15 -15
View File
@@ -1,17 +1,17 @@
import rough from "roughjs/bin/rough";
import {
rescalePoints,
arrayToMap,
invariant,
rescalePoints,
sizeOf,
} from "@excalidraw/common";
import {
degreesToRadians,
lineSegment,
pointFrom,
pointDistance,
pointFrom,
pointFromArray,
pointRotateRads,
} from "@excalidraw/math";
@@ -33,8 +33,8 @@ import type { AppState } from "@excalidraw/excalidraw/types";
import type { Mutable } from "@excalidraw/common/utility-types";
import { ShapeCache } from "./ShapeCache";
import { generateRoughOptions } from "./Shape";
import { ShapeCache } from "./ShapeCache";
import { LinearElementEditor } from "./linearElementEditor";
import { getBoundTextElement, getContainerElement } from "./textElement";
import {
@@ -52,20 +52,20 @@ import {
deconstructRectanguloidElement,
} from "./utils";
import type {
ExcalidrawElement,
ExcalidrawLinearElement,
Arrowhead,
ExcalidrawFreeDrawElement,
NonDeleted,
ExcalidrawTextElementWithContainer,
ElementsMap,
ExcalidrawRectanguloidElement,
ExcalidrawEllipseElement,
ElementsMapOrArray,
} from "./types";
import type { Drawable, Op } from "roughjs/bin/core";
import type { Point as RoughPoint } from "roughjs/bin/geometry";
import type {
Arrowhead,
ElementsMap,
ElementsMapOrArray,
ExcalidrawElement,
ExcalidrawEllipseElement,
ExcalidrawFreeDrawElement,
ExcalidrawLinearElement,
ExcalidrawRectanguloidElement,
ExcalidrawTextElementWithContainer,
NonDeleted,
} from "./types";
export type RectangleBox = {
x: number;
+164 -62
View File
@@ -52,7 +52,7 @@ import {
type NonDeletedSceneElementsMap,
} from "./types";
import { aabbForElement, pointInsideBounds } from "./shapes";
import { aabbForElement, aabbForPoints, pointInsideBounds } from "./shapes";
import type { Bounds } from "./bounds";
import type { Heading } from "./heading";
@@ -65,6 +65,8 @@ import type {
NonDeletedExcalidrawElement,
} from "./types";
import { debugDrawBounds } from "@excalidraw/utils/visualdebug";
type GridAddress = [number, number] & { _brand: "gridaddress" };
type Node = {
@@ -106,8 +108,32 @@ type ElbowArrowData = {
hoveredEndElement: ExcalidrawBindableElement | null;
};
const DEDUP_TRESHOLD = 1;
export const BASE_PADDING = 40;
const calculateDedupTreshhold = <Point extends GlobalPoint | LocalPoint>(
a: Point,
b: Point,
) => 1 + pointDistance(a, b) / 300;
const calculatePadding = (
aabb: Bounds,
startBoundingBox: Bounds,
endBoundingBox: Bounds,
) => {
return Math.max(
Math.min(
Math.hypot(
startBoundingBox[2] - startBoundingBox[0],
startBoundingBox[3] - startBoundingBox[1],
) / 4,
Math.hypot(
endBoundingBox[2] - endBoundingBox[0],
endBoundingBox[3] - endBoundingBox[1],
) / 4,
Math.hypot(aabb[2] - aabb[0], aabb[3] - aabb[1]) / 4,
40,
),
30,
);
};
const handleSegmentRenormalization = (
arrow: ExcalidrawElbowArrowElement,
@@ -183,7 +209,11 @@ const handleSegmentRenormalization = (
if (
// Remove segments that are too short
pointDistance(points[i - 2], points[i - 1]) < DEDUP_TRESHOLD
pointDistance(points[i - 2], points[i - 1]) <
calculateDedupTreshhold(
points[i - 3] ?? points[i - 3],
points[i] ?? points[i - 1],
)
) {
const prevPrevSegmentIdx =
nextFixedSegments?.findIndex((segment) => segment.index === i - 2) ??
@@ -359,6 +389,10 @@ const handleSegmentRelease = (
null,
);
if (!restoredPoints) {
return {};
}
const nextPoints: GlobalPoint[] = [];
// First part of the arrow are the old points
@@ -463,6 +497,13 @@ const handleSegmentMove = (
hoveredStartElement: ExcalidrawBindableElement | null,
hoveredEndElement: ExcalidrawBindableElement | null,
): ElementUpdate<ExcalidrawElbowArrowElement> => {
const BASE_PADDING = calculatePadding(
aabbForElement(arrow),
hoveredStartElement
? aabbForElement(hoveredStartElement)
: [10, 10, 10, 10],
hoveredEndElement ? aabbForElement(hoveredEndElement) : [10, 10, 10, 10],
);
const activelyModifiedSegmentIdx = fixedSegments
.map((segment, i) => {
if (
@@ -707,6 +748,13 @@ const handleEndpointDrag = (
hoveredStartElement: ExcalidrawBindableElement | null,
hoveredEndElement: ExcalidrawBindableElement | null,
) => {
const BASE_PADDING = calculatePadding(
aabbForPoints([startGlobalPoint, endGlobalPoint]),
hoveredStartElement
? aabbForElement(hoveredStartElement)
: [10, 10, 10, 10],
hoveredEndElement ? aabbForElement(hoveredEndElement) : [10, 10, 10, 10],
);
let startIsSpecial = arrow.startIsSpecial ?? null;
let endIsSpecial = arrow.endIsSpecial ?? null;
const globalUpdatedPoints = updatedPoints.map((p, i) =>
@@ -741,6 +789,7 @@ const handleEndpointDrag = (
// Calculate the moving second point connection and add the start point
{
startIsSpecial = arrow.startIsSpecial && globalUpdatedPoints.length > 2;
const secondPoint = globalUpdatedPoints[startIsSpecial ? 2 : 1];
const thirdPoint = globalUpdatedPoints[startIsSpecial ? 3 : 2];
const startIsHorizontal = headingIsHorizontal(startHeading);
@@ -801,6 +850,7 @@ const handleEndpointDrag = (
// Calculate the moving second to last point connection
{
endIsSpecial = arrow.endIsSpecial && globalUpdatedPoints.length > 2;
const secondToLastPoint =
globalUpdatedPoints[globalUpdatedPoints.length - (endIsSpecial ? 3 : 2)];
const thirdToLastPoint =
@@ -1293,29 +1343,28 @@ const getElbowArrowData = (
endGlobalPoint[0] + 2,
endGlobalPoint[1] + 2,
] as Bounds;
const BASE_PADDING = calculatePadding(
aabbForPoints([startGlobalPoint, endGlobalPoint]),
hoveredStartElement
? aabbForElement(hoveredStartElement)
: [10, 10, 10, 10],
hoveredEndElement ? aabbForElement(hoveredEndElement) : [10, 10, 10, 10],
);
const startOffsets = offsetFromHeading(
startHeading,
arrow.startArrowhead ? FIXED_BINDING_DISTANCE * 4 : FIXED_BINDING_DISTANCE,
1,
);
const endOffsets = offsetFromHeading(
endHeading,
arrow.endArrowhead ? FIXED_BINDING_DISTANCE * 4 : FIXED_BINDING_DISTANCE,
1,
);
const startElementBounds = hoveredStartElement
? aabbForElement(
hoveredStartElement,
offsetFromHeading(
startHeading,
arrow.startArrowhead
? FIXED_BINDING_DISTANCE * 6
: FIXED_BINDING_DISTANCE * 2,
1,
),
)
? aabbForElement(hoveredStartElement, startOffsets)
: startPointBounds;
const endElementBounds = hoveredEndElement
? aabbForElement(
hoveredEndElement,
offsetFromHeading(
endHeading,
arrow.endArrowhead
? FIXED_BINDING_DISTANCE * 6
: FIXED_BINDING_DISTANCE * 2,
1,
),
)
? aabbForElement(hoveredEndElement, endOffsets)
: endPointBounds;
const boundsOverlap =
pointInsideBounds(
@@ -1358,7 +1407,7 @@ const getElbowArrowData = (
: BASE_PADDING -
(arrow.startArrowhead
? FIXED_BINDING_DISTANCE * 6
: FIXED_BINDING_DISTANCE * 2),
: FIXED_BINDING_DISTANCE),
BASE_PADDING,
),
boundsOverlap
@@ -1374,13 +1423,29 @@ const getElbowArrowData = (
: BASE_PADDING -
(arrow.endArrowhead
? FIXED_BINDING_DISTANCE * 6
: FIXED_BINDING_DISTANCE * 2),
: FIXED_BINDING_DISTANCE),
BASE_PADDING,
),
boundsOverlap,
hoveredStartElement && aabbForElement(hoveredStartElement),
hoveredEndElement && aabbForElement(hoveredEndElement),
hoveredStartElement
? aabbForElement(hoveredStartElement)
: startPointBounds,
hoveredEndElement ? aabbForElement(hoveredEndElement) : endPointBounds,
);
debugDrawBounds(startElementBounds, {
permanent: false,
color: "red",
});
debugDrawBounds(endElementBounds, {
permanent: false,
color: "green",
});
debugDrawBounds(dynamicAABBs, {
permanent: false,
color: "blue",
});
const startDonglePosition = getDonglePosition(
dynamicAABBs[0],
startHeading,
@@ -1651,11 +1716,11 @@ const generateDynamicAABBs = (
a: Bounds,
b: Bounds,
common: Bounds,
startDifference?: [number, number, number, number],
endDifference?: [number, number, number, number],
disableSideHack?: boolean,
startElementBounds?: Bounds | null,
endElementBounds?: Bounds | null,
startDifference: [number, number, number, number],
endDifference: [number, number, number, number],
disableSideHack: boolean,
startElementBounds: Bounds,
endElementBounds: Bounds,
): Bounds[] => {
const startEl = startElementBounds ?? a;
const endEl = endElementBounds ?? b;
@@ -1735,15 +1800,24 @@ const generateDynamicAABBs = (
(second[0] + second[2]) / 2,
(second[1] + second[3]) / 2,
];
if (b[0] > a[2] && a[1] > b[3]) {
if (
endElementBounds[0] > startElementBounds[2] &&
startElementBounds[1] > endElementBounds[3]
) {
// BOTTOM LEFT
const cX = first[2] + (second[0] - first[2]) / 2;
const cY = second[3] + (first[1] - second[3]) / 2;
if (
vectorCross(
vector(a[2] - endCenterX, a[1] - endCenterY),
vector(a[0] - endCenterX, a[3] - endCenterY),
vector(
startElementBounds[2] - endCenterX,
startElementBounds[1] - endCenterY,
),
vector(
startElementBounds[0] - endCenterX,
startElementBounds[3] - endCenterY,
),
) > 0
) {
return [
@@ -1756,15 +1830,24 @@ const generateDynamicAABBs = (
[first[0], cY, first[2], first[3]],
[second[0], second[1], second[2], cY],
];
} else if (a[2] < b[0] && a[3] < b[1]) {
} else if (
startElementBounds[2] < endElementBounds[0] &&
startElementBounds[3] < endElementBounds[1]
) {
// TOP LEFT
const cX = first[2] + (second[0] - first[2]) / 2;
const cY = first[3] + (second[1] - first[3]) / 2;
if (
vectorCross(
vector(a[0] - endCenterX, a[1] - endCenterY),
vector(a[2] - endCenterX, a[3] - endCenterY),
vector(
startElementBounds[0] - endCenterX,
startElementBounds[1] - endCenterY,
),
vector(
startElementBounds[2] - endCenterX,
startElementBounds[3] - endCenterY,
),
) > 0
) {
return [
@@ -1777,15 +1860,24 @@ const generateDynamicAABBs = (
[first[0], first[1], cX, first[3]],
[cX, second[1], second[2], second[3]],
];
} else if (a[0] > b[2] && a[3] < b[1]) {
} else if (
startElementBounds[0] > endElementBounds[2] &&
startElementBounds[3] < endElementBounds[1]
) {
// TOP RIGHT
const cX = second[2] + (first[0] - second[2]) / 2;
const cY = first[3] + (second[1] - first[3]) / 2;
if (
vectorCross(
vector(a[2] - endCenterX, a[1] - endCenterY),
vector(a[0] - endCenterX, a[3] - endCenterY),
vector(
startElementBounds[2] - endCenterX,
startElementBounds[1] - endCenterY,
),
vector(
startElementBounds[0] - endCenterX,
startElementBounds[3] - endCenterY,
),
) > 0
) {
return [
@@ -1798,15 +1890,24 @@ const generateDynamicAABBs = (
[first[0], first[1], first[2], cY],
[second[0], cY, second[2], second[3]],
];
} else if (a[0] > b[2] && a[1] > b[3]) {
} else if (
startElementBounds[0] > endElementBounds[2] &&
startElementBounds[1] > endElementBounds[3]
) {
// BOTTOM RIGHT
const cX = second[2] + (first[0] - second[2]) / 2;
const cY = second[3] + (first[1] - second[3]) / 2;
if (
vectorCross(
vector(a[0] - endCenterX, a[1] - endCenterY),
vector(a[2] - endCenterX, a[3] - endCenterY),
vector(
startElementBounds[0] - endCenterX,
startElementBounds[1] - endCenterY,
),
vector(
startElementBounds[2] - endCenterX,
startElementBounds[3] - endCenterY,
),
) > 0
) {
return [
@@ -2088,16 +2189,11 @@ const normalizeArrowElementUpdate = (
nextFixedSegments: readonly FixedSegment[] | null,
startIsSpecial?: ExcalidrawElbowArrowElement["startIsSpecial"],
endIsSpecial?: ExcalidrawElbowArrowElement["startIsSpecial"],
): {
points: LocalPoint[];
x: number;
y: number;
width: number;
height: number;
fixedSegments: readonly FixedSegment[] | null;
startIsSpecial?: ExcalidrawElbowArrowElement["startIsSpecial"];
endIsSpecial?: ExcalidrawElbowArrowElement["startIsSpecial"];
} => {
): ElementUpdate<ExcalidrawElbowArrowElement> => {
if (global.length === 0) {
return {};
}
const offsetX = global[0][0];
const offsetY = global[0][1];
let points = global.map((p) =>
@@ -2185,7 +2281,10 @@ const removeElbowArrowShortSegments = (
const prev = points[idx - 1];
const prevDist = pointDistance(prev, p);
return prevDist > DEDUP_TRESHOLD;
return (
prevDist >
calculateDedupTreshhold(points[idx - 2] ?? prev, points[idx + 1] ?? p)
);
});
}
@@ -2288,13 +2387,16 @@ const gridAddressesEqual = (a: GridAddress, b: GridAddress): boolean =>
export const validateElbowPoints = <P extends GlobalPoint | LocalPoint>(
points: readonly P[],
tolerance: number = DEDUP_TRESHOLD,
tolerance?: number,
) =>
points
.slice(1)
.map(
(p, i) =>
Math.abs(p[0] - points[i][0]) < tolerance ||
Math.abs(p[1] - points[i][1]) < tolerance,
)
.map((p, i) => {
const t =
tolerance ??
calculateDedupTreshhold(points[i - 1] ?? points[i], points[i + 2] ?? p);
return (
Math.abs(p[0] - points[i][0]) < t || Math.abs(p[1] - points[i][1]) < t
);
})
.every(Boolean);
+1 -2
View File
@@ -44,7 +44,6 @@ import type {
ExcalidrawIframeElement,
ElementsMap,
ExcalidrawArrowElement,
FixedSegment,
ExcalidrawElbowArrowElement,
} from "./types";
@@ -478,7 +477,7 @@ export const newArrowElement = <T extends boolean>(
endArrowhead?: Arrowhead | null;
points?: ExcalidrawArrowElement["points"];
elbowed?: T;
fixedSegments?: FixedSegment[] | null;
fixedSegments?: ExcalidrawElbowArrowElement["fixedSegments"] | null;
} & ElementConstructorOpts,
): T extends true
? NonDeleted<ExcalidrawElbowArrowElement>
+9
View File
@@ -282,6 +282,15 @@ export const mapIntervalToBezierT = <P extends GlobalPoint | LocalPoint>(
);
};
export const aabbForPoints = <Point extends GlobalPoint | LocalPoint>(
points: Point[],
): Bounds => [
Math.min(...points.map((point) => point[0])),
Math.min(...points.map((point) => point[1])),
Math.max(...points.map((point) => point[0])),
Math.max(...points.map((point) => point[1])),
];
/**
* Get the axis-aligned bounding box for a given element
*/
+18
View File
@@ -119,6 +119,20 @@ export const isElbowArrow = (
return isArrowElement(element) && element.elbowed;
};
export const isSharpArrow = (
element?: ExcalidrawElement,
): element is ExcalidrawArrowElement => {
return isArrowElement(element) && !element.elbowed && !element.roundness;
};
export const isCurvedArrow = (
element?: ExcalidrawElement,
): element is ExcalidrawArrowElement => {
return (
isArrowElement(element) && !element.elbowed && element.roundness !== null
);
};
export const isLinearElementType = (
elementType: ElementOrToolType,
): boolean => {
@@ -271,6 +285,10 @@ export const isBoundToContainer = (
);
};
export const isArrowBoundToElement = (element: ExcalidrawArrowElement) => {
return !!element.startBinding || !!element.endBinding;
};
export const isUsingAdaptiveRadius = (type: string) =>
type === "rectangle" ||
type === "embeddable" ||
+8
View File
@@ -412,3 +412,11 @@ export type NonDeletedSceneElementsMap = Map<
export type ElementsMapOrArray =
| readonly ExcalidrawElement[]
| Readonly<ElementsMap>;
export type ConvertibleGenericTypes = "rectangle" | "diamond" | "ellipse";
export type ConvertibleLinearTypes =
| "line"
| "sharpArrow"
| "curvedArrow"
| "elbowArrow";
export type ConvertibleTypes = ConvertibleGenericTypes | ConvertibleLinearTypes;
+5 -5
View File
@@ -195,7 +195,7 @@ describe("elbow arrow routing", () => {
expect(arrow.startBinding).not.toBe(null);
expect(arrow.endBinding).not.toBe(null);
h.app.scene.mutateElement(arrow, {
scene.mutateElement(arrow, {
points: [pointFrom<LocalPoint>(0, 0), pointFrom<LocalPoint>(90, 200)],
});
@@ -295,11 +295,11 @@ describe("elbow arrow ui", () => {
) as HTMLInputElement;
UI.updateInput(inputAngle, String("40"));
expect(arrow.points.map((point) => point.map(Math.round))).toEqual([
expect(arrow.points).toCloselyEqualPoints([
[0, 0],
[35, 0],
[35, 165],
[103, 165],
[34.7791, 0],
[34.7791, 164.67],
[102.931, 164.67],
]);
});
+4 -4
View File
@@ -510,12 +510,12 @@ describe("arrow element", () => {
h.state,
)[0] as ExcalidrawElbowArrowElement;
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1);
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1.05);
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.75);
UI.resize(rectangle, "se", [-200, -150]);
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1);
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1.05);
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.75);
});
@@ -538,11 +538,11 @@ describe("arrow element", () => {
h.state,
)[0] as ExcalidrawElbowArrowElement;
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1);
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1.05);
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.75);
UI.resize([rectangle, arrow], "nw", [300, 350]);
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(0);
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(-0.05);
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.25);
});
});
@@ -73,12 +73,12 @@ describe("flipping re-centers selection", () => {
API.executeAction(actionFlipHorizontal);
const rec1 = h.elements.find((el) => el.id === "rec1")!;
expect(rec1.x).toBeCloseTo(100, 0);
expect(rec1.y).toBeCloseTo(100, 0);
expect(rec1.x).toBeCloseTo(97.8678, 0);
expect(rec1.y).toBeCloseTo(97.444, 0);
const rec2 = h.elements.find((el) => el.id === "rec2")!;
expect(rec2.x).toBeCloseTo(220, 0);
expect(rec2.y).toBeCloseTo(250, 0);
expect(rec2.x).toBeCloseTo(218, 0);
expect(rec2.y).toBeCloseTo(247, 0);
});
});
@@ -0,0 +1,34 @@
import type { ExcalidrawElement } from "@excalidraw/element/types";
import {
getConversionTypeFromElements,
convertElementTypePopupAtom,
} from "../components/ConvertElementTypePopup";
import { editorJotaiStore } from "../editor-jotai";
import { CaptureUpdateAction } from "../store";
import { register } from "./register";
export const actionToggleShapeSwitch = register({
name: "toggleShapeSwitch",
label: "labels.shapeSwitch",
icon: () => null,
viewMode: true,
trackEvent: {
category: "shape_switch",
action: "toggle",
},
keywords: ["change", "switch", "swap"],
perform(elements, appState, _, app) {
editorJotaiStore.set(convertElementTypePopupAtom, {
type: "panel",
});
return {
captureUpdate: CaptureUpdateAction.NEVER,
};
},
checked: (appState) => appState.gridModeEnabled,
predicate: (elements, appState, props) =>
getConversionTypeFromElements(elements as ExcalidrawElement[]) !== null,
});
+4 -2
View File
@@ -140,7 +140,8 @@ export type ActionName =
| "linkToElement"
| "cropEditor"
| "wrapSelectionInFrame"
| "toggleLassoTool";
| "toggleLassoTool"
| "toggleShapeSwitch";
export type PanelComponentProps = {
elements: readonly ExcalidrawElement[];
@@ -195,7 +196,8 @@ export interface Action {
| "menu"
| "collab"
| "hyperlink"
| "search_menu";
| "search_menu"
| "shape_switch";
action?: string;
predicate?: (
appState: Readonly<AppState>,
-1
View File
@@ -129,7 +129,6 @@ export class AnimatedTrail implements Trail {
}
private update() {
this.pastTrails = [];
this.start();
if (this.trailAnimation) {
this.trailAnimation.setAttribute("begin", "indefinite");
+64 -5
View File
@@ -100,6 +100,7 @@ import {
arrayToMap,
type EXPORT_IMAGE_TYPES,
randomInteger,
CLASSES,
} from "@excalidraw/common";
import {
@@ -431,7 +432,7 @@ import {
} from "../components/hyperlink/Hyperlink";
import { Fonts } from "../fonts";
import { editorJotaiStore } from "../editor-jotai";
import { editorJotaiStore, type WritableAtom } from "../editor-jotai";
import { ImageSceneDataError } from "../errors";
import {
getSnapLinesAtPointer,
@@ -467,6 +468,12 @@ import { LassoTrail } from "../lasso";
import { EraserTrail } from "../eraser";
import ConvertElementTypePopup, {
getConversionTypeFromElements,
convertElementTypePopupAtom,
convertElementTypes,
} from "./ConvertElementTypePopup";
import { activeConfirmDialogAtom } from "./ActiveConfirmDialog";
import BraveMeasureTextError from "./BraveMeasureTextError";
import { ContextMenu, CONTEXT_MENU_SEPARATOR } from "./ContextMenu";
@@ -498,7 +505,6 @@ import type { ExportedElements } from "../data";
import type { ContextMenuItems } from "./ContextMenu";
import type { FileSystemHandle } from "../data/filesystem";
import type { ExcalidrawElementSkeleton } from "../data/transform";
import type {
AppClassProperties,
AppProps,
@@ -815,6 +821,15 @@ class App extends React.Component<AppProps, AppState> {
);
}
updateEditorAtom = <Value, Args extends unknown[], Result>(
atom: WritableAtom<Value, Args, Result>,
...args: Args
): Result => {
const result = editorJotaiStore.set(atom, ...args);
this.triggerRender();
return result;
};
private onWindowMessage(event: MessageEvent) {
if (
event.origin !== "https://player.vimeo.com" &&
@@ -1583,6 +1598,9 @@ class App extends React.Component<AppProps, AppState> {
const firstSelectedElement = selectedElements[0];
const showShapeSwitchPanel =
editorJotaiStore.get(convertElementTypePopupAtom)?.type === "panel";
return (
<div
className={clsx("excalidraw excalidraw-container", {
@@ -1857,6 +1875,9 @@ class App extends React.Component<AppProps, AppState> {
/>
)}
{this.renderFrameNames()}
{showShapeSwitchPanel && (
<ConvertElementTypePopup app={this} />
)}
</ExcalidrawActionManagerContext.Provider>
{this.renderEmbeddables()}
</ExcalidrawElementsContext.Provider>
@@ -2138,7 +2159,7 @@ class App extends React.Component<AppProps, AppState> {
};
private openEyeDropper = ({ type }: { type: "stroke" | "background" }) => {
editorJotaiStore.set(activeEyeDropperAtom, {
this.updateEditorAtom(activeEyeDropperAtom, {
swapPreviewOnAlt: true,
colorPickerType:
type === "stroke" ? "elementStroke" : "elementBackground",
@@ -4157,6 +4178,40 @@ class App extends React.Component<AppProps, AppState> {
return;
}
// Shape switching
if (event.key === KEYS.ESCAPE) {
this.updateEditorAtom(convertElementTypePopupAtom, null);
} else if (
event.key === KEYS.TAB &&
(document.activeElement === this.excalidrawContainerRef?.current ||
document.activeElement?.classList.contains(
CLASSES.CONVERT_ELEMENT_TYPE_POPUP,
))
) {
event.preventDefault();
const conversionType =
getConversionTypeFromElements(selectedElements);
if (
editorJotaiStore.get(convertElementTypePopupAtom)?.type === "panel"
) {
if (
convertElementTypes(this, {
conversionType,
direction: event.shiftKey ? "left" : "right",
})
) {
this.store.shouldCaptureIncrement();
}
}
if (conversionType) {
this.updateEditorAtom(convertElementTypePopupAtom, {
type: "panel",
});
}
}
if (
event.key === KEYS.ESCAPE &&
this.flowChartCreator.isCreatingChart
@@ -4615,7 +4670,7 @@ class App extends React.Component<AppProps, AppState> {
event[KEYS.CTRL_OR_CMD] &&
(event.key === KEYS.BACKSPACE || event.key === KEYS.DELETE)
) {
editorJotaiStore.set(activeConfirmDialogAtom, "clearCanvas");
this.updateEditorAtom(activeConfirmDialogAtom, "clearCanvas");
}
// eye dropper
@@ -6364,7 +6419,11 @@ class App extends React.Component<AppProps, AppState> {
focus: false,
})),
}));
editorJotaiStore.set(searchItemInFocusAtom, null);
this.updateEditorAtom(searchItemInFocusAtom, null);
}
if (editorJotaiStore.get(convertElementTypePopupAtom)) {
this.updateEditorAtom(convertElementTypePopupAtom, null);
}
// since contextMenu options are potentially evaluated on each render,
@@ -11,6 +11,8 @@ import {
isWritableElement,
} from "@excalidraw/common";
import { actionToggleShapeSwitch } from "@excalidraw/excalidraw/actions/actionToggleShapeSwitch";
import type { MarkRequired } from "@excalidraw/common/utility-types";
import {
@@ -410,6 +412,14 @@ function CommandPaletteInner({
actionManager.executeAction(actionToggleSearchMenu);
},
},
{
label: t("labels.shapeSwitch"),
category: DEFAULT_CATEGORIES.elements,
icon: boltIcon,
perform: () => {
actionManager.executeAction(actionToggleShapeSwitch);
},
},
{
label: t("labels.changeStroke"),
keywords: ["color", "outline"],
@@ -0,0 +1,18 @@
@import "../css//variables.module.scss";
.excalidraw {
.ConvertElementTypePopup {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 0.2rem;
border-radius: 0.5rem;
background: var(--island-bg-color);
box-shadow: var(--shadow-island);
padding: 0.5rem;
&:focus {
outline: none;
}
}
}
File diff suppressed because it is too large Load Diff
@@ -21,7 +21,7 @@ const Header = () => (
className="HelpDialog__btn"
href="https://docs.excalidraw.com"
target="_blank"
rel="noopener noreferrer"
rel="noopener"
>
<div className="HelpDialog__link-icon">{ExternalLinkIcon}</div>
{t("helpDialog.documentation")}
@@ -30,7 +30,7 @@ const Header = () => (
className="HelpDialog__btn"
href="https://plus.excalidraw.com/blog"
target="_blank"
rel="noopener noreferrer"
rel="noopener"
>
<div className="HelpDialog__link-icon">{ExternalLinkIcon}</div>
{t("helpDialog.blog")}
@@ -247,6 +247,11 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
label={t("toolBar.link")}
shortcuts={[getShortcutKey("CtrlOrCmd+K")]}
/>
<Shortcut
label={t("toolBar.convertElementType")}
shortcuts={["Tab", "Shift+Tab"]}
isOr={true}
/>
</ShortcutIsland>
<ShortcutIsland
className="HelpDialog__island--view"
@@ -389,7 +389,7 @@ const PublishLibrary = ({
<a
href="https://libraries.excalidraw.com"
target="_blank"
rel="noopener noreferrer"
rel="noopener"
>
{el}
</a>
@@ -11,8 +11,10 @@ import type Scene from "@excalidraw/element/Scene";
import { angleIcon } from "../icons";
import { updateBindings } from "../../../element/src/binding";
import DragInput from "./DragInput";
import { getStepSizedValue, isPropertyEditable, updateBindings } from "./utils";
import { getStepSizedValue, isPropertyEditable } from "./utils";
import type { DragInputCallbackType } from "./DragInput";
import type { AppState } from "../../types";
@@ -10,7 +10,12 @@ import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import StatsDragInput from "./DragInput";
import { getAtomicUnits, getStepSizedValue, isPropertyEditable } from "./utils";
import {
getAtomicUnits,
getStepSizedValue,
isPropertyEditable,
STEP_SIZE,
} from "./utils";
import { getElementsInAtomicUnit, moveElement } from "./utils";
import type { DragInputCallbackType } from "./DragInput";
@@ -26,8 +31,6 @@ interface MultiPositionProps {
appState: AppState;
}
const STEP_SIZE = 10;
const moveElements = (
property: MultiPositionProps["property"],
changeInTopX: number,
@@ -11,7 +11,7 @@ import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
import type Scene from "@excalidraw/element/Scene";
import StatsDragInput from "./DragInput";
import { getStepSizedValue, moveElement } from "./utils";
import { getStepSizedValue, moveElement, STEP_SIZE } from "./utils";
import type { DragInputCallbackType } from "./DragInput";
import type { AppState } from "../../types";
@@ -24,8 +24,6 @@ interface PositionProps {
appState: AppState;
}
const STEP_SIZE = 10;
const handlePositionChange: DragInputCallbackType<"x" | "y"> = ({
accumulatedChange,
instantChange,
+67 -21
View File
@@ -1,13 +1,8 @@
import { pointFrom, pointRotateRads } from "@excalidraw/math";
import {
bindOrUnbindLinearElements,
updateBoundElements,
} from "@excalidraw/element/binding";
import { getBoundTextElement } from "@excalidraw/element/textElement";
import {
isFrameLikeElement,
isLinearElement,
isTextElement,
} from "@excalidraw/element/typeChecks";
@@ -17,6 +12,8 @@ import {
isInGroup,
} from "@excalidraw/element/groups";
import { getFrameChildren } from "@excalidraw/element/frame";
import type { Radians } from "@excalidraw/math";
import type {
@@ -27,6 +24,8 @@ import type {
import type Scene from "@excalidraw/element/Scene";
import { updateBindings } from "../../../element/src/binding";
import type { AppState } from "../../types";
export type StatsInputProperty =
@@ -39,6 +38,7 @@ export type StatsInputProperty =
| "gridStep";
export const SMALLEST_DELTA = 0.01;
export const STEP_SIZE = 10;
export const isPropertyEditable = (
element: ExcalidrawElement,
@@ -172,6 +172,68 @@ export const moveElement = (
{ informMutation: shouldInformMutation, isDragging: false },
);
}
if (isFrameLikeElement(originalElement)) {
const originalChildren = getFrameChildren(
originalElementsMap,
originalElement.id,
);
originalChildren.forEach((child) => {
const latestChildElement = elementsMap.get(child.id);
if (!latestChildElement) {
return;
}
const [childCX, childCY] = [
child.x + child.width / 2,
child.y + child.height / 2,
];
const [childTopLeftX, childTopLeftY] = pointRotateRads(
pointFrom(child.x, child.y),
pointFrom(childCX, childCY),
child.angle,
);
const childNewTopLeftX = Math.round(childTopLeftX + changeInX);
const childNewTopLeftY = Math.round(childTopLeftY + changeInY);
const [childX, childY] = pointRotateRads(
pointFrom(childNewTopLeftX, childNewTopLeftY),
pointFrom(childCX + changeInX, childCY + changeInY),
-child.angle as Radians,
);
scene.mutateElement(
latestChildElement,
{
x: childX,
y: childY,
},
{ informMutation: shouldInformMutation, isDragging: false },
);
updateBindings(latestChildElement, scene, {
simultaneouslyUpdated: originalChildren,
});
const boundTextElement = getBoundTextElement(
latestChildElement,
originalElementsMap,
);
if (boundTextElement) {
const latestBoundTextElement = elementsMap.get(boundTextElement.id);
latestBoundTextElement &&
scene.mutateElement(
latestBoundTextElement,
{
x: boundTextElement.x + changeInX,
y: boundTextElement.y + changeInY,
},
{ informMutation: shouldInformMutation, isDragging: false },
);
}
});
}
};
export const getAtomicUnits = (
@@ -194,19 +256,3 @@ export const getAtomicUnits = (
});
return _atomicUnits;
};
export const updateBindings = (
latestElement: ExcalidrawElement,
scene: Scene,
options?: {
simultaneouslyUpdated?: readonly ExcalidrawElement[];
newSize?: { width: number; height: number };
zoom?: AppState["zoom"];
},
) => {
if (isLinearElement(latestElement)) {
bindOrUnbindLinearElements([latestElement], true, [], scene, options?.zoom);
} else {
updateBoundElements(latestElement, scene, options);
}
};
@@ -16,7 +16,7 @@ const DropdownMenuItemLink = ({
onSelect,
className = "",
selected,
rel = "noreferrer",
rel = "noopener",
...rest
}: {
href: string;
@@ -31,11 +31,12 @@ const DropdownMenuItemLink = ({
const handleClick = useHandleDropdownMenuItemClick(rest.onClick, onSelect);
return (
// eslint-disable-next-line react/jsx-no-target-blank
<a
{...rest}
href={href}
target="_blank"
rel="noreferrer"
rel={rel || "noopener"}
className={getDropdownMenuItemClassName(className, selected)}
title={rest.title ?? rest["aria-label"]}
onClick={handleClick}
@@ -78,7 +78,7 @@ const WelcomeScreenMenuItemLink = ({
className={`welcome-screen-menu-item ${className}`}
href={href}
target="_blank"
rel="noreferrer"
rel="noopener"
>
<WelcomeScreenMenuItemContent icon={icon} shortcut={shortcut}>
{children}
+2 -2
View File
@@ -29,6 +29,7 @@ import { bumpVersion } from "@excalidraw/element/mutateElement";
import { getContainerElement } from "@excalidraw/element/textElement";
import { detectLineHeight } from "@excalidraw/element/textMeasurements";
import {
isArrowBoundToElement,
isArrowElement,
isElbowArrow,
isFixedPointBinding,
@@ -594,8 +595,7 @@ export const restoreElements = (
return restoredElements.map((element) => {
if (
isElbowArrow(element) &&
element.startBinding == null &&
element.endBinding == null &&
!isArrowBoundToElement(element) &&
!validateElbowPoints(element.points)
) {
return {
+7 -2
View File
@@ -1,10 +1,15 @@
// eslint-disable-next-line no-restricted-imports
import { atom, createStore, type PrimitiveAtom } from "jotai";
import {
atom,
createStore,
type PrimitiveAtom,
type WritableAtom,
} from "jotai";
import { createIsolation } from "jotai-scope";
const jotai = createIsolation();
export { atom, PrimitiveAtom };
export { atom, PrimitiveAtom, WritableAtom };
export const { useAtom, useSetAtom, useAtomValue, useStore } = jotai;
export const EditorJotaiProvider: ReturnType<
typeof createIsolation
+5 -2
View File
@@ -165,7 +165,9 @@
"unCroppedDimension": "Uncropped dimension",
"copyElementLink": "Copy link to object",
"linkToElement": "Link to object",
"wrapSelectionInFrame": "Wrap selection in frame"
"wrapSelectionInFrame": "Wrap selection in frame",
"tab": "Tab",
"shapeSwitch": "Switch shape"
},
"elementLink": {
"title": "Link to object",
@@ -296,7 +298,8 @@
"laser": "Laser pointer",
"hand": "Hand (panning tool)",
"extraTools": "More tools",
"mermaidToExcalidraw": "Mermaid to Excalidraw"
"mermaidToExcalidraw": "Mermaid to Excalidraw",
"convertElementType": "Toggle shape type"
},
"element": {
"rectangle": "Rectangle",
+421 -2
View File
@@ -1,7 +1,30 @@
import { THEME, THEME_FILTER } from "@excalidraw/common";
import { elementCenterPoint, THEME, THEME_FILTER } from "@excalidraw/common";
import { FIXED_BINDING_DISTANCE } from "@excalidraw/element/binding";
import { getDiamondPoints } from "@excalidraw/element/bounds";
import { getCornerRadius } from "@excalidraw/element/shapes";
import {
bezierEquation,
curve,
curveTangent,
type GlobalPoint,
pointFrom,
pointFromVector,
pointRotateRads,
vector,
vectorNormal,
vectorNormalize,
vectorScale,
} from "@excalidraw/math";
import type {
ExcalidrawDiamondElement,
ExcalidrawRectanguloidElement,
} from "@excalidraw/element/types";
import type { StaticCanvasRenderConfig } from "../scene/types";
import type { StaticCanvasAppState, AppState } from "../types";
import type { AppState, StaticCanvasAppState } from "../types";
export const fillCircle = (
context: CanvasRenderingContext2D,
@@ -72,3 +95,399 @@ export const bootstrapCanvas = ({
return context;
};
function drawCatmullRomQuadraticApprox(
ctx: CanvasRenderingContext2D,
points: GlobalPoint[],
segments = 20,
) {
ctx.lineTo(points[0][0], points[0][1]);
for (let i = 0; i < points.length - 1; i++) {
const p0 = points[i - 1 < 0 ? 0 : i - 1];
const p1 = points[i];
const p2 = points[i + 1 >= points.length ? points.length - 1 : i + 1];
for (let t = 0; t <= 1; t += 1 / segments) {
const t2 = t * t;
const x =
(1 - t) * (1 - t) * p0[0] + 2 * (1 - t) * t * p1[0] + t2 * p2[0];
const y =
(1 - t) * (1 - t) * p0[1] + 2 * (1 - t) * t * p1[1] + t2 * p2[1];
ctx.lineTo(x, y);
}
}
}
function drawCatmullRomCubicApprox(
ctx: CanvasRenderingContext2D,
points: GlobalPoint[],
segments = 20,
) {
ctx.lineTo(points[0][0], points[0][1]);
for (let i = 0; i < points.length - 1; i++) {
const p0 = points[i - 1 < 0 ? 0 : i - 1];
const p1 = points[i];
const p2 = points[i + 1 >= points.length ? points.length - 1 : i + 1];
const p3 = points[i + 2 >= points.length ? points.length - 1 : i + 2];
for (let t = 0; t <= 1; t += 1 / segments) {
const t2 = t * t;
const t3 = t2 * t;
const x =
0.5 *
(2 * p1[0] +
(-p0[0] + p2[0]) * t +
(2 * p0[0] - 5 * p1[0] + 4 * p2[0] - p3[0]) * t2 +
(-p0[0] + 3 * p1[0] - 3 * p2[0] + p3[0]) * t3);
const y =
0.5 *
(2 * p1[1] +
(-p0[1] + p2[1]) * t +
(2 * p0[1] - 5 * p1[1] + 4 * p2[1] - p3[1]) * t2 +
(-p0[1] + 3 * p1[1] - 3 * p2[1] + p3[1]) * t3);
ctx.lineTo(x, y);
}
}
}
export const drawHighlightForRectWithRotation = (
context: CanvasRenderingContext2D,
element: ExcalidrawRectanguloidElement,
padding: number,
) => {
const [x, y] = pointRotateRads(
pointFrom<GlobalPoint>(element.x, element.y),
elementCenterPoint(element),
element.angle,
);
context.save();
context.translate(x, y);
context.rotate(element.angle);
let radius = getCornerRadius(
Math.min(element.width, element.height),
element,
);
if (radius === 0) {
radius = 0.01;
}
context.beginPath();
{
const topLeftApprox = offsetQuadraticBezier(
pointFrom(0, 0 + radius),
pointFrom(0, 0),
pointFrom(0 + radius, 0),
padding,
);
const topRightApprox = offsetQuadraticBezier(
pointFrom(element.width - radius, 0),
pointFrom(element.width, 0),
pointFrom(element.width, radius),
padding,
);
const bottomRightApprox = offsetQuadraticBezier(
pointFrom(element.width, element.height - radius),
pointFrom(element.width, element.height),
pointFrom(element.width - radius, element.height),
padding,
);
const bottomLeftApprox = offsetQuadraticBezier(
pointFrom(radius, element.height),
pointFrom(0, element.height),
pointFrom(0, element.height - radius),
padding,
);
context.moveTo(
topLeftApprox[topLeftApprox.length - 1][0],
topLeftApprox[topLeftApprox.length - 1][1],
);
context.lineTo(topRightApprox[0][0], topRightApprox[0][1]);
drawCatmullRomQuadraticApprox(context, topRightApprox);
context.lineTo(bottomRightApprox[0][0], bottomRightApprox[0][1]);
drawCatmullRomQuadraticApprox(context, bottomRightApprox);
context.lineTo(bottomLeftApprox[0][0], bottomLeftApprox[0][1]);
drawCatmullRomQuadraticApprox(context, bottomLeftApprox);
context.lineTo(topLeftApprox[0][0], topLeftApprox[0][1]);
drawCatmullRomQuadraticApprox(context, topLeftApprox);
}
// Counter-clockwise for the cutout in the middle. We need to have an "inverse
// mask" on a filled shape for the diamond highlight, because stroking creates
// sharp inset edges on line joins < 90 degrees.
{
const topLeftApprox = offsetQuadraticBezier(
pointFrom(0 + radius, 0),
pointFrom(0, 0),
pointFrom(0, 0 + radius),
-FIXED_BINDING_DISTANCE,
);
const topRightApprox = offsetQuadraticBezier(
pointFrom(element.width, radius),
pointFrom(element.width, 0),
pointFrom(element.width - radius, 0),
-FIXED_BINDING_DISTANCE,
);
const bottomRightApprox = offsetQuadraticBezier(
pointFrom(element.width - radius, element.height),
pointFrom(element.width, element.height),
pointFrom(element.width, element.height - radius),
-FIXED_BINDING_DISTANCE,
);
const bottomLeftApprox = offsetQuadraticBezier(
pointFrom(0, element.height - radius),
pointFrom(0, element.height),
pointFrom(radius, element.height),
-FIXED_BINDING_DISTANCE,
);
context.moveTo(
topLeftApprox[topLeftApprox.length - 1][0],
topLeftApprox[topLeftApprox.length - 1][1],
);
context.lineTo(bottomLeftApprox[0][0], bottomLeftApprox[0][1]);
drawCatmullRomQuadraticApprox(context, bottomLeftApprox);
context.lineTo(bottomRightApprox[0][0], bottomRightApprox[0][1]);
drawCatmullRomQuadraticApprox(context, bottomRightApprox);
context.lineTo(topRightApprox[0][0], topRightApprox[0][1]);
drawCatmullRomQuadraticApprox(context, topRightApprox);
context.lineTo(topLeftApprox[0][0], topLeftApprox[0][1]);
drawCatmullRomQuadraticApprox(context, topLeftApprox);
}
context.closePath();
context.fill();
context.restore();
};
export const strokeEllipseWithRotation = (
context: CanvasRenderingContext2D,
width: number,
height: number,
cx: number,
cy: number,
angle: number,
) => {
context.beginPath();
context.ellipse(cx, cy, width / 2, height / 2, angle, 0, Math.PI * 2);
context.stroke();
};
export const strokeRectWithRotation = (
context: CanvasRenderingContext2D,
x: number,
y: number,
width: number,
height: number,
cx: number,
cy: number,
angle: number,
fill: boolean = false,
/** should account for zoom */
radius: number = 0,
) => {
context.save();
context.translate(cx, cy);
context.rotate(angle);
if (fill) {
context.fillRect(x - cx, y - cy, width, height);
}
if (radius && context.roundRect) {
context.beginPath();
context.roundRect(x - cx, y - cy, width, height, radius);
context.stroke();
context.closePath();
} else {
context.strokeRect(x - cx, y - cy, width, height);
}
context.restore();
};
export const drawHighlightForDiamondWithRotation = (
context: CanvasRenderingContext2D,
padding: number,
element: ExcalidrawDiamondElement,
) => {
const [x, y] = pointRotateRads(
pointFrom<GlobalPoint>(element.x, element.y),
elementCenterPoint(element),
element.angle,
);
context.save();
context.translate(x, y);
context.rotate(element.angle);
{
context.beginPath();
const [topX, topY, rightX, rightY, bottomX, bottomY, leftX, leftY] =
getDiamondPoints(element);
const verticalRadius = element.roundness
? getCornerRadius(Math.abs(topX - leftX), element)
: (topX - leftX) * 0.01;
const horizontalRadius = element.roundness
? getCornerRadius(Math.abs(rightY - topY), element)
: (rightY - topY) * 0.01;
const topApprox = offsetCubicBezier(
pointFrom(topX - verticalRadius, topY + horizontalRadius),
pointFrom(topX, topY),
pointFrom(topX, topY),
pointFrom(topX + verticalRadius, topY + horizontalRadius),
padding,
);
const rightApprox = offsetCubicBezier(
pointFrom(rightX - verticalRadius, rightY - horizontalRadius),
pointFrom(rightX, rightY),
pointFrom(rightX, rightY),
pointFrom(rightX - verticalRadius, rightY + horizontalRadius),
padding,
);
const bottomApprox = offsetCubicBezier(
pointFrom(bottomX + verticalRadius, bottomY - horizontalRadius),
pointFrom(bottomX, bottomY),
pointFrom(bottomX, bottomY),
pointFrom(bottomX - verticalRadius, bottomY - horizontalRadius),
padding,
);
const leftApprox = offsetCubicBezier(
pointFrom(leftX + verticalRadius, leftY + horizontalRadius),
pointFrom(leftX, leftY),
pointFrom(leftX, leftY),
pointFrom(leftX + verticalRadius, leftY - horizontalRadius),
padding,
);
context.moveTo(
topApprox[topApprox.length - 1][0],
topApprox[topApprox.length - 1][1],
);
context.lineTo(rightApprox[0][0], rightApprox[0][1]);
drawCatmullRomCubicApprox(context, rightApprox);
context.lineTo(bottomApprox[0][0], bottomApprox[0][1]);
drawCatmullRomCubicApprox(context, bottomApprox);
context.lineTo(leftApprox[0][0], leftApprox[0][1]);
drawCatmullRomCubicApprox(context, leftApprox);
context.lineTo(topApprox[0][0], topApprox[0][1]);
drawCatmullRomCubicApprox(context, topApprox);
}
// Counter-clockwise for the cutout in the middle. We need to have an "inverse
// mask" on a filled shape for the diamond highlight, because stroking creates
// sharp inset edges on line joins < 90 degrees.
{
const [topX, topY, rightX, rightY, bottomX, bottomY, leftX, leftY] =
getDiamondPoints(element);
const verticalRadius = element.roundness
? getCornerRadius(Math.abs(topX - leftX), element)
: (topX - leftX) * 0.01;
const horizontalRadius = element.roundness
? getCornerRadius(Math.abs(rightY - topY), element)
: (rightY - topY) * 0.01;
const topApprox = offsetCubicBezier(
pointFrom(topX + verticalRadius, topY + horizontalRadius),
pointFrom(topX, topY),
pointFrom(topX, topY),
pointFrom(topX - verticalRadius, topY + horizontalRadius),
-FIXED_BINDING_DISTANCE,
);
const rightApprox = offsetCubicBezier(
pointFrom(rightX - verticalRadius, rightY + horizontalRadius),
pointFrom(rightX, rightY),
pointFrom(rightX, rightY),
pointFrom(rightX - verticalRadius, rightY - horizontalRadius),
-FIXED_BINDING_DISTANCE,
);
const bottomApprox = offsetCubicBezier(
pointFrom(bottomX - verticalRadius, bottomY - horizontalRadius),
pointFrom(bottomX, bottomY),
pointFrom(bottomX, bottomY),
pointFrom(bottomX + verticalRadius, bottomY - horizontalRadius),
-FIXED_BINDING_DISTANCE,
);
const leftApprox = offsetCubicBezier(
pointFrom(leftX + verticalRadius, leftY - horizontalRadius),
pointFrom(leftX, leftY),
pointFrom(leftX, leftY),
pointFrom(leftX + verticalRadius, leftY + horizontalRadius),
-FIXED_BINDING_DISTANCE,
);
context.moveTo(
topApprox[topApprox.length - 1][0],
topApprox[topApprox.length - 1][1],
);
context.lineTo(leftApprox[0][0], leftApprox[0][1]);
drawCatmullRomCubicApprox(context, leftApprox);
context.lineTo(bottomApprox[0][0], bottomApprox[0][1]);
drawCatmullRomCubicApprox(context, bottomApprox);
context.lineTo(rightApprox[0][0], rightApprox[0][1]);
drawCatmullRomCubicApprox(context, rightApprox);
context.lineTo(topApprox[0][0], topApprox[0][1]);
drawCatmullRomCubicApprox(context, topApprox);
}
context.closePath();
context.fill();
context.restore();
};
function offsetCubicBezier(
p0: GlobalPoint,
p1: GlobalPoint,
p2: GlobalPoint,
p3: GlobalPoint,
offsetDist: number,
steps = 20,
) {
const offsetPoints = [];
for (let i = 0; i <= steps; i++) {
const t = i / steps;
const c = curve(p0, p1, p2, p3);
const point = bezierEquation(c, t);
const tangent = vectorNormalize(curveTangent(c, t));
const normal = vectorNormal(tangent);
offsetPoints.push(pointFromVector(vectorScale(normal, offsetDist), point));
}
return offsetPoints;
}
function offsetQuadraticBezier(
p0: GlobalPoint,
p1: GlobalPoint,
p2: GlobalPoint,
offsetDist: number,
steps = 20,
) {
const offsetPoints = [];
for (let i = 0; i <= steps; i++) {
const t = i / steps;
const t1 = 1 - t;
const point = pointFrom<GlobalPoint>(
t1 * t1 * p0[0] + 2 * t1 * t * p1[0] + t * t * p2[0],
t1 * t1 * p0[1] + 2 * t1 * t * p1[1] + t * t * p2[1],
);
const tangentX = 2 * (1 - t) * (p1[0] - p0[0]) + 2 * t * (p2[0] - p1[0]);
const tangentY = 2 * (1 - t) * (p1[1] - p0[1]) + 2 * t * (p2[1] - p1[1]);
const tangent = vectorNormalize(vector(tangentX, tangentY));
const normal = vectorNormal(tangent);
offsetPoints.push(pointFromVector(vectorScale(normal, offsetDist), point));
}
return offsetPoints;
}
+21 -107
View File
@@ -1,23 +1,22 @@
import oc from "open-color";
import {
pointFrom,
type GlobalPoint,
type LocalPoint,
type Radians,
} from "@excalidraw/math";
import oc from "open-color";
import {
arrayToMap,
DEFAULT_TRANSFORM_HANDLE_SPACING,
FRAME_STYLE,
THEME,
arrayToMap,
invariant,
THEME,
throttleRAF,
} from "@excalidraw/common";
import {
BINDING_HIGHLIGHT_OFFSET,
BINDING_HIGHLIGHT_THICKNESS,
FIXED_BINDING_DISTANCE,
maxBindingGap,
} from "@excalidraw/element/binding";
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
@@ -35,14 +34,12 @@ import {
isTextElement,
} from "@excalidraw/element/typeChecks";
import { getCornerRadius } from "@excalidraw/element/shapes";
import { renderSelectionElement } from "@excalidraw/element/renderElement";
import {
isSelectedViaGroup,
getSelectedGroupIds,
getElementsInGroup,
getSelectedGroupIds,
isSelectedViaGroup,
selectGroupsFromGivenElements,
} from "@excalidraw/element/groups";
@@ -86,8 +83,12 @@ import { getClientColor, renderRemoteCursors } from "../clients";
import {
bootstrapCanvas,
drawHighlightForDiamondWithRotation,
drawHighlightForRectWithRotation,
fillCircle,
getNormalizedCanvasDimensions,
strokeEllipseWithRotation,
strokeRectWithRotation,
} from "./helpers";
import type {
@@ -160,57 +161,6 @@ const highlightPoint = <Point extends LocalPoint | GlobalPoint>(
);
};
const strokeRectWithRotation = (
context: CanvasRenderingContext2D,
x: number,
y: number,
width: number,
height: number,
cx: number,
cy: number,
angle: number,
fill: boolean = false,
/** should account for zoom */
radius: number = 0,
) => {
context.save();
context.translate(cx, cy);
context.rotate(angle);
if (fill) {
context.fillRect(x - cx, y - cy, width, height);
}
if (radius && context.roundRect) {
context.beginPath();
context.roundRect(x - cx, y - cy, width, height, radius);
context.stroke();
context.closePath();
} else {
context.strokeRect(x - cx, y - cy, width, height);
}
context.restore();
};
const strokeDiamondWithRotation = (
context: CanvasRenderingContext2D,
width: number,
height: number,
cx: number,
cy: number,
angle: number,
) => {
context.save();
context.translate(cx, cy);
context.rotate(angle);
context.beginPath();
context.moveTo(0, height / 2);
context.lineTo(width / 2, 0);
context.lineTo(0, -height / 2);
context.lineTo(-width / 2, 0);
context.closePath();
context.stroke();
context.restore();
};
const renderSingleLinearPoint = <Point extends GlobalPoint | LocalPoint>(
context: CanvasRenderingContext2D,
appState: InteractiveCanvasAppState,
@@ -237,19 +187,6 @@ const renderSingleLinearPoint = <Point extends GlobalPoint | LocalPoint>(
);
};
const strokeEllipseWithRotation = (
context: CanvasRenderingContext2D,
width: number,
height: number,
cx: number,
cy: number,
angle: number,
) => {
context.beginPath();
context.ellipse(cx, cy, width / 2, height / 2, angle, 0, Math.PI * 2);
context.stroke();
};
const renderBindingHighlightForBindableElement = (
context: CanvasRenderingContext2D,
element: ExcalidrawBindableElement,
@@ -261,16 +198,10 @@ const renderBindingHighlightForBindableElement = (
const height = y2 - y1;
context.strokeStyle = "rgba(0,0,0,.05)";
// When zooming out, make line width greater for visibility
const zoomValue = zoom.value < 1 ? zoom.value : 1;
context.lineWidth = BINDING_HIGHLIGHT_THICKNESS / zoomValue;
// To ensure the binding highlight doesn't overlap the element itself
const padding = context.lineWidth / 2 + BINDING_HIGHLIGHT_OFFSET;
context.fillStyle = "rgba(0,0,0,.05)";
const radius = getCornerRadius(
Math.min(element.width, element.height),
element,
);
// To ensure the binding highlight doesn't overlap the element itself
const padding = maxBindingGap(element, element.width, element.height, zoom);
switch (element.type) {
case "rectangle":
@@ -280,37 +211,20 @@ const renderBindingHighlightForBindableElement = (
case "embeddable":
case "frame":
case "magicframe":
strokeRectWithRotation(
context,
x1 - padding,
y1 - padding,
width + padding * 2,
height + padding * 2,
x1 + width / 2,
y1 + height / 2,
element.angle,
undefined,
radius,
);
drawHighlightForRectWithRotation(context, element, padding);
break;
case "diamond":
const side = Math.hypot(width, height);
const wPadding = (padding * side) / height;
const hPadding = (padding * side) / width;
strokeDiamondWithRotation(
context,
width + wPadding * 2,
height + hPadding * 2,
x1 + width / 2,
y1 + height / 2,
element.angle,
);
drawHighlightForDiamondWithRotation(context, padding, element);
break;
case "ellipse":
context.lineWidth =
maxBindingGap(element, element.width, element.height, zoom) -
FIXED_BINDING_DISTANCE;
strokeEllipseWithRotation(
context,
width + padding * 2,
height + padding * 2,
width + padding + FIXED_BINDING_DISTANCE,
height + padding + FIXED_BINDING_DISTANCE,
x1 + width / 2,
y1 + height / 2,
element.angle,
@@ -21,7 +21,7 @@ exports[`<Excalidraw/> > <MainMenu/> > should render main menu with host menu it
<a
class="dropdown-menu-item dropdown-menu-item-base"
href="blog.excalidaw.com"
rel="noreferrer"
rel="noopener"
target="_blank"
>
<div
@@ -392,7 +392,7 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
aria-label="GitHub"
class="dropdown-menu-item dropdown-menu-item-base"
href="https://github.com/excalidraw/excalidraw"
rel="noreferrer"
rel="noopener"
target="_blank"
title="GitHub"
>
@@ -426,7 +426,7 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
aria-label="X"
class="dropdown-menu-item dropdown-menu-item-base"
href="https://x.com/excalidraw"
rel="noreferrer"
rel="noopener"
target="_blank"
title="X"
>
@@ -472,7 +472,7 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
aria-label="Discord"
class="dropdown-menu-item dropdown-menu-item-base"
href="https://discord.gg/UexuTaE"
rel="noreferrer"
rel="noopener"
target="_blank"
title="Discord"
>
@@ -171,7 +171,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 19,
"version": 9,
"width": 100,
"x": 100,
"y": -50,
@@ -198,7 +198,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"fillStyle": "solid",
"frameId": null,
"groupIds": [],
"height": "102.35417",
"height": "102.45605",
"id": "id172",
"index": "a2",
"isDeleted": false,
@@ -212,8 +212,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
0,
],
[
"101.77517",
"102.35417",
"102.80179",
"102.45605",
],
],
"roughness": 1,
@@ -227,9 +227,9 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"strokeWidth": 2,
"type": "arrow",
"updated": 1,
"version": 40,
"width": "101.77517",
"x": "0.70711",
"version": 37,
"width": "102.80179",
"x": "-0.42182",
"y": 0,
}
`;
@@ -264,7 +264,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 6,
"version": 14,
"width": 50,
"x": 100,
"y": 100,
@@ -291,22 +291,39 @@ History {
"added": Map {},
"removed": Map {},
"updated": Map {
"id171" => Delta {
"deleted": {
"boundElements": [],
},
"inserted": {
"boundElements": [
{
"id": "id172",
"type": "arrow",
},
],
},
},
"id172" => Delta {
"deleted": {
"endBinding": {
"elementId": "id171",
"focus": "0.00990",
"elementId": "id175",
"fixedPoint": [
"0.50000",
1,
],
"focus": 0,
"gap": 1,
},
"height": "0.98586",
"height": "70.45017",
"points": [
[
0,
0,
],
[
"98.58579",
"-0.98586",
"100.70774",
"70.45017",
],
],
"startBinding": {
@@ -321,7 +338,7 @@ History {
"focus": "-0.02000",
"gap": 1,
},
"height": "0.00000",
"height": "0.09250",
"points": [
[
0,
@@ -329,7 +346,7 @@ History {
],
[
"98.58579",
"0.00000",
"0.09250",
],
],
"startBinding": {
@@ -339,6 +356,19 @@ History {
},
},
},
"id175" => Delta {
"deleted": {
"boundElements": [
{
"id": "id172",
"type": "arrow",
},
],
},
"inserted": {
"boundElements": [],
},
},
},
},
},
@@ -366,59 +396,32 @@ History {
],
},
},
"id171" => Delta {
"deleted": {
"boundElements": [],
},
"inserted": {
"boundElements": [
{
"id": "id172",
"type": "arrow",
},
],
},
},
"id172" => Delta {
"deleted": {
"endBinding": {
"elementId": "id175",
"fixedPoint": [
"0.50000",
1,
],
"focus": 0,
"gap": 1,
},
"height": "102.35417",
"height": "102.45584",
"points": [
[
0,
0,
],
[
"101.77517",
"102.35417",
"102.79971",
"102.45584",
],
],
"startBinding": null,
"y": 0,
},
"inserted": {
"endBinding": {
"elementId": "id171",
"focus": "0.00990",
"gap": 1,
},
"height": "0.98586",
"height": "70.33521",
"points": [
[
0,
0,
],
[
"98.58579",
"-0.98586",
"100.78887",
"70.33521",
],
],
"startBinding": {
@@ -426,20 +429,7 @@ History {
"focus": "0.02970",
"gap": 1,
},
"y": "0.99364",
},
},
"id175" => Delta {
"deleted": {
"boundElements": [
{
"id": "id172",
"type": "arrow",
},
],
},
"inserted": {
"boundElements": [],
"y": "35.20327",
},
},
},
@@ -739,7 +729,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"strokeWidth": 2,
"type": "rectangle",
"updated": 1,
"version": 9,
"version": 19,
"width": 100,
"x": 150,
"y": -50,
@@ -819,8 +809,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"strokeWidth": 2,
"type": "arrow",
"updated": 1,
"version": 30,
"width": 0,
"version": 33,
"width": 100,
"x": "149.29289",
"y": 0,
}
@@ -846,20 +836,22 @@ History {
"added": Map {},
"removed": Map {},
"updated": Map {
"id167" => Delta {
"id166" => Delta {
"deleted": {
"points": [
[
0,
0,
],
[
0,
0,
],
],
"boundElements": [],
},
"inserted": {
"boundElements": [
{
"id": "id167",
"type": "arrow",
},
],
},
},
"id167" => Delta {
"deleted": {
"endBinding": null,
"points": [
[
0,
@@ -871,6 +863,23 @@ History {
],
],
},
"inserted": {
"endBinding": {
"elementId": "id166",
"focus": -0,
"gap": 1,
},
"points": [
[
0,
0,
],
[
0,
0,
],
],
},
},
},
},
@@ -899,22 +908,8 @@ History {
],
},
},
"id166" => Delta {
"deleted": {
"boundElements": [],
},
"inserted": {
"boundElements": [
{
"id": "id167",
"type": "arrow",
},
],
},
},
"id167" => Delta {
"deleted": {
"endBinding": null,
"points": [
[
0,
@@ -928,18 +923,13 @@ History {
"startBinding": null,
},
"inserted": {
"endBinding": {
"elementId": "id166",
"focus": -0,
"gap": 1,
},
"points": [
[
0,
0,
],
[
0,
100,
0,
],
],
+1
View File
@@ -714,6 +714,7 @@ export type AppClassProperties = {
excalidrawContainerValue: App["excalidrawContainerValue"];
onPointerUpEmitter: App["onPointerUpEmitter"];
updateEditorAtom: App["updateEditorAtom"];
};
export type PointerDownState = Readonly<{
+5 -2
View File
@@ -80,6 +80,8 @@ const getTransform = (
return `translate(${translateX}px, ${translateY}px) scale(${zoom.value}) rotate(${degree}deg)`;
};
type SubmitHandler = () => void;
export const textWysiwyg = ({
id,
onChange,
@@ -106,7 +108,7 @@ export const textWysiwyg = ({
excalidrawContainer: HTMLDivElement | null;
app: App;
autoSelect?: boolean;
}) => {
}): SubmitHandler => {
const textPropertiesUpdated = (
updatedTextElement: ExcalidrawTextElement,
editable: HTMLTextAreaElement,
@@ -186,7 +188,6 @@ export const textWysiwyg = ({
}
maxWidth = getBoundTextMaxWidth(container, updatedTextElement);
maxHeight = getBoundTextMaxHeight(
container,
updatedTextElement as ExcalidrawTextElementWithContainer,
@@ -735,4 +736,6 @@ export const textWysiwyg = ({
excalidrawContainer
?.querySelector(".excalidraw-textEditorContainer")!
.appendChild(editable);
return handleSubmit;
};
+22 -1
View File
@@ -2,6 +2,7 @@ import type { Bounds } from "@excalidraw/element/bounds";
import { isPoint, pointDistance, pointFrom } from "./point";
import { rectangle, rectangleIntersectLineSegment } from "./rectangle";
import { vector } from "./vector";
import type { Curve, GlobalPoint, LineSegment, LocalPoint } from "./types";
@@ -82,7 +83,7 @@ function solve(
return [t0, s0];
}
const bezierEquation = <Point extends GlobalPoint | LocalPoint>(
export const bezierEquation = <Point extends GlobalPoint | LocalPoint>(
c: Curve<Point>,
t: number,
) =>
@@ -274,6 +275,26 @@ export function isCurve<P extends GlobalPoint | LocalPoint>(
);
}
export function curveTangent<Point extends GlobalPoint | LocalPoint>(
[p0, p1, p2, p3]: Curve<Point>,
t: number,
) {
return vector(
-3 * (1 - t) * (1 - t) * p0[0] +
3 * (1 - t) * (1 - t) * p1[0] -
6 * t * (1 - t) * p1[0] -
3 * t * t * p2[0] +
6 * t * (1 - t) * p2[0] +
3 * t * t * p3[0],
-3 * (1 - t) * (1 - t) * p0[1] +
3 * (1 - t) * (1 - t) * p1[1] -
6 * t * (1 - t) * p1[1] -
3 * t * t * p2[1] +
6 * t * (1 - t) * p2[1] +
3 * t * t * p3[1],
);
}
function curveBounds<Point extends GlobalPoint | LocalPoint>(
c: Curve<Point>,
): Bounds {
+5
View File
@@ -143,3 +143,8 @@ export const vectorNormalize = (v: Vector): Vector => {
return vector(v[0] / m, v[1] / m);
};
/**
* Calculate the right-hand normal of the vector.
*/
export const vectorNormal = (v: Vector): Vector => vector(v[1], -v[0]);