mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-11 19:40:08 +02:00
Compare commits
4 Commits
zsviczian-
...
dependabot
Author | SHA1 | Date | |
---|---|---|---|
![]() |
947e6b8dcc | ||
![]() |
2e61926a6b | ||
![]() |
e921bfb1ae | ||
![]() |
e6f74350ac |
@@ -5189,10 +5189,10 @@ multicast-dns@^7.2.5:
|
|||||||
dns-packet "^5.2.2"
|
dns-packet "^5.2.2"
|
||||||
thunky "^1.0.2"
|
thunky "^1.0.2"
|
||||||
|
|
||||||
nanoid@^3.3.4:
|
nanoid@^3.3.6:
|
||||||
version "3.3.4"
|
version "3.3.6"
|
||||||
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.4.tgz#730b67e3cd09e2deacf03c027c81c9d9dbc5e8ab"
|
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c"
|
||||||
integrity sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==
|
integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==
|
||||||
|
|
||||||
negotiator@0.6.3:
|
negotiator@0.6.3:
|
||||||
version "0.6.3"
|
version "0.6.3"
|
||||||
@@ -5853,11 +5853,11 @@ postcss-zindex@^5.1.0:
|
|||||||
integrity sha512-fgFMf0OtVSBR1va1JNHYgMxYk73yhn/qb4uQDq1DLGYolz8gHCyr/sesEuGUaYs58E3ZJRcpoGuPVoB7Meiq9A==
|
integrity sha512-fgFMf0OtVSBR1va1JNHYgMxYk73yhn/qb4uQDq1DLGYolz8gHCyr/sesEuGUaYs58E3ZJRcpoGuPVoB7Meiq9A==
|
||||||
|
|
||||||
postcss@^8.3.11, postcss@^8.4.13, postcss@^8.4.14, postcss@^8.4.7:
|
postcss@^8.3.11, postcss@^8.4.13, postcss@^8.4.14, postcss@^8.4.7:
|
||||||
version "8.4.14"
|
version "8.4.31"
|
||||||
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.14.tgz#ee9274d5622b4858c1007a74d76e42e56fd21caf"
|
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.31.tgz#92b451050a9f914da6755af352bdc0192508656d"
|
||||||
integrity sha512-E398TUmfAYFPBSdzgeieK2Y1+1cpdxJx8yXbK/m57nRhKSmk1GB2tO4lbLBtlkfPQTDKfe4Xqv1ASWPpayPEig==
|
integrity sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
nanoid "^3.3.4"
|
nanoid "^3.3.6"
|
||||||
picocolors "^1.0.0"
|
picocolors "^1.0.0"
|
||||||
source-map-js "^1.0.2"
|
source-map-js "^1.0.2"
|
||||||
|
|
||||||
|
@@ -91,7 +91,7 @@ export class LaserPathManager {
|
|||||||
private collaboratorsState: Map<string, CollabolatorState> = new Map();
|
private collaboratorsState: Map<string, CollabolatorState> = new Map();
|
||||||
|
|
||||||
private rafId: number | undefined;
|
private rafId: number | undefined;
|
||||||
private isDrawing = false;
|
private lastUpdate = 0;
|
||||||
private container: SVGSVGElement | undefined;
|
private container: SVGSVGElement | undefined;
|
||||||
|
|
||||||
constructor(private app: App) {
|
constructor(private app: App) {
|
||||||
@@ -100,7 +100,7 @@ export class LaserPathManager {
|
|||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.stop();
|
this.stop();
|
||||||
this.isDrawing = false;
|
this.lastUpdate = 0;
|
||||||
this.ownState = instantiateCollabolatorState();
|
this.ownState = instantiateCollabolatorState();
|
||||||
this.collaboratorsState = new Map();
|
this.collaboratorsState = new Map();
|
||||||
}
|
}
|
||||||
@@ -127,7 +127,7 @@ export class LaserPathManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private updatePath(state: CollabolatorState) {
|
private updatePath(state: CollabolatorState) {
|
||||||
this.isDrawing = true;
|
this.lastUpdate = performance.now();
|
||||||
|
|
||||||
if (!this.isRunning) {
|
if (!this.isRunning) {
|
||||||
this.start();
|
this.start();
|
||||||
@@ -160,7 +160,7 @@ export class LaserPathManager {
|
|||||||
|
|
||||||
this.updateCollabolatorsState();
|
this.updateCollabolatorsState();
|
||||||
|
|
||||||
if (this.isDrawing) {
|
if (performance.now() - this.lastUpdate < DECAY_TIME * 2) {
|
||||||
this.update();
|
this.update();
|
||||||
} else {
|
} else {
|
||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
@@ -250,8 +250,6 @@ export class LaserPathManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let somePathsExist = false;
|
|
||||||
|
|
||||||
for (const [key, state] of this.collaboratorsState.entries()) {
|
for (const [key, state] of this.collaboratorsState.entries()) {
|
||||||
if (!this.app.state.collaborators.has(key)) {
|
if (!this.app.state.collaborators.has(key)) {
|
||||||
state.svg.remove();
|
state.svg.remove();
|
||||||
@@ -271,10 +269,6 @@ export class LaserPathManager {
|
|||||||
paths += ` ${this.draw(state.currentPath)}`;
|
paths += ` ${this.draw(state.currentPath)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paths.trim()) {
|
|
||||||
somePathsExist = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
state.svg.setAttribute("d", paths);
|
state.svg.setAttribute("d", paths);
|
||||||
state.svg.setAttribute("fill", getClientColor(key));
|
state.svg.setAttribute("fill", getClientColor(key));
|
||||||
}
|
}
|
||||||
@@ -293,17 +287,7 @@ export class LaserPathManager {
|
|||||||
paths += ` ${this.draw(this.ownState.currentPath)}`;
|
paths += ` ${this.draw(this.ownState.currentPath)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
paths = paths.trim();
|
|
||||||
|
|
||||||
if (paths) {
|
|
||||||
somePathsExist = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.ownState.svg.setAttribute("d", paths);
|
this.ownState.svg.setAttribute("d", paths);
|
||||||
this.ownState.svg.setAttribute("fill", "red");
|
this.ownState.svg.setAttribute("fill", "red");
|
||||||
|
|
||||||
if (!somePathsExist) {
|
|
||||||
this.isDrawing = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { updateBoundElements } from "./binding";
|
import { updateBoundElements } from "./binding";
|
||||||
import { Bounds, getCommonBounds } from "./bounds";
|
import { getCommonBounds } from "./bounds";
|
||||||
import { mutateElement } from "./mutateElement";
|
import { mutateElement } from "./mutateElement";
|
||||||
import { getPerfectElementSize } from "./sizeHelpers";
|
import { getPerfectElementSize } from "./sizeHelpers";
|
||||||
import { NonDeletedExcalidrawElement } from "./types";
|
import { NonDeletedExcalidrawElement } from "./types";
|
||||||
@@ -41,16 +41,14 @@ export const dragSelectedElements = (
|
|||||||
elementsInFrames.forEach((element) => elementsToUpdate.add(element));
|
elementsInFrames.forEach((element) => elementsToUpdate.add(element));
|
||||||
}
|
}
|
||||||
|
|
||||||
const commonBounds = getCommonBounds(Array.from(elementsToUpdate));
|
|
||||||
const adjustedOffset = calculateOffset(
|
|
||||||
commonBounds,
|
|
||||||
offset,
|
|
||||||
snapOffset,
|
|
||||||
gridSize,
|
|
||||||
);
|
|
||||||
|
|
||||||
elementsToUpdate.forEach((element) => {
|
elementsToUpdate.forEach((element) => {
|
||||||
updateElementCoords(pointerDownState, element, adjustedOffset);
|
updateElementCoords(
|
||||||
|
pointerDownState,
|
||||||
|
element,
|
||||||
|
offset,
|
||||||
|
snapOffset,
|
||||||
|
gridSize,
|
||||||
|
);
|
||||||
// update coords of bound text only if we're dragging the container directly
|
// update coords of bound text only if we're dragging the container directly
|
||||||
// (we don't drag the group that it's part of)
|
// (we don't drag the group that it's part of)
|
||||||
if (
|
if (
|
||||||
@@ -68,7 +66,13 @@ export const dragSelectedElements = (
|
|||||||
// updating its coords again
|
// updating its coords again
|
||||||
(!textElement.frameId || !frames.includes(textElement.frameId))
|
(!textElement.frameId || !frames.includes(textElement.frameId))
|
||||||
) {
|
) {
|
||||||
updateElementCoords(pointerDownState, textElement, adjustedOffset);
|
updateElementCoords(
|
||||||
|
pointerDownState,
|
||||||
|
textElement,
|
||||||
|
offset,
|
||||||
|
snapOffset,
|
||||||
|
gridSize,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateBoundElements(element, {
|
updateBoundElements(element, {
|
||||||
@@ -77,20 +81,23 @@ export const dragSelectedElements = (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const calculateOffset = (
|
const updateElementCoords = (
|
||||||
commonBounds: Bounds,
|
pointerDownState: PointerDownState,
|
||||||
|
element: NonDeletedExcalidrawElement,
|
||||||
dragOffset: { x: number; y: number },
|
dragOffset: { x: number; y: number },
|
||||||
snapOffset: { x: number; y: number },
|
snapOffset: { x: number; y: number },
|
||||||
gridSize: AppState["gridSize"],
|
gridSize: AppState["gridSize"],
|
||||||
): { x: number; y: number } => {
|
) => {
|
||||||
const [x, y] = commonBounds;
|
const originalElement =
|
||||||
let nextX = x + dragOffset.x + snapOffset.x;
|
pointerDownState.originalElements.get(element.id) ?? element;
|
||||||
let nextY = y + dragOffset.y + snapOffset.y;
|
|
||||||
|
let nextX = originalElement.x + dragOffset.x + snapOffset.x;
|
||||||
|
let nextY = originalElement.y + dragOffset.y + snapOffset.y;
|
||||||
|
|
||||||
if (snapOffset.x === 0 || snapOffset.y === 0) {
|
if (snapOffset.x === 0 || snapOffset.y === 0) {
|
||||||
const [nextGridX, nextGridY] = getGridPoint(
|
const [nextGridX, nextGridY] = getGridPoint(
|
||||||
x + dragOffset.x,
|
originalElement.x + dragOffset.x,
|
||||||
y + dragOffset.y,
|
originalElement.y + dragOffset.y,
|
||||||
gridSize,
|
gridSize,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -102,22 +109,6 @@ const calculateOffset = (
|
|||||||
nextY = nextGridY;
|
nextY = nextGridY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
x: nextX - x,
|
|
||||||
y: nextY - y,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateElementCoords = (
|
|
||||||
pointerDownState: PointerDownState,
|
|
||||||
element: NonDeletedExcalidrawElement,
|
|
||||||
dragOffset: { x: number; y: number },
|
|
||||||
) => {
|
|
||||||
const originalElement =
|
|
||||||
pointerDownState.originalElements.get(element.id) ?? element;
|
|
||||||
|
|
||||||
const nextX = originalElement.x + dragOffset.x;
|
|
||||||
const nextY = originalElement.y + dragOffset.y;
|
|
||||||
|
|
||||||
mutateElement(element, {
|
mutateElement(element, {
|
||||||
x: nextX,
|
x: nextX,
|
||||||
|
Reference in New Issue
Block a user