mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Refactor Element Functions (#233)
* Remove `generatedraw` from element object - Create a function that renders a single element - Refactor rendering selected elements * Replace getElementAbsoluteXY with getElementAbsoluteCoords
This commit is contained in:
parent
85365e5bcb
commit
829a65b8cb
14 changed files with 206 additions and 184 deletions
|
@ -1,24 +1,23 @@
|
|||
import { ExcalidrawElement } from "../element/types";
|
||||
import {
|
||||
getElementAbsoluteX1,
|
||||
getElementAbsoluteX2,
|
||||
getElementAbsoluteY1,
|
||||
getElementAbsoluteY2
|
||||
} from "../element";
|
||||
import { getElementAbsoluteCoords } from "../element";
|
||||
|
||||
export function setSelection(
|
||||
elements: ExcalidrawElement[],
|
||||
selection: ExcalidrawElement
|
||||
) {
|
||||
const selectionX1 = getElementAbsoluteX1(selection);
|
||||
const selectionX2 = getElementAbsoluteX2(selection);
|
||||
const selectionY1 = getElementAbsoluteY1(selection);
|
||||
const selectionY2 = getElementAbsoluteY2(selection);
|
||||
const [
|
||||
selectionX1,
|
||||
selectionY1,
|
||||
selectionX2,
|
||||
selectionY2
|
||||
] = getElementAbsoluteCoords(selection);
|
||||
elements.forEach(element => {
|
||||
const elementX1 = getElementAbsoluteX1(element);
|
||||
const elementX2 = getElementAbsoluteX2(element);
|
||||
const elementY1 = getElementAbsoluteY1(element);
|
||||
const elementY2 = getElementAbsoluteY2(element);
|
||||
const [
|
||||
elementX1,
|
||||
elementY1,
|
||||
elementX2,
|
||||
elementY2
|
||||
] = getElementAbsoluteCoords(element);
|
||||
element.isSelected =
|
||||
element.type !== "selection" &&
|
||||
selectionX1 <= elementX1 &&
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue