Compare commits

..

8 Commits

Author SHA1 Message Date
zsviczian
60a3584e86 change css back to original 2023-10-07 10:38:46 +02:00
zsviczian
fa0e653236 lint 2023-10-07 10:37:37 +02:00
zsviczian
16de3d9243 add svgContainer offset 2023-10-07 10:35:06 +02:00
zsviczian
c65d6506f7 fix lasertool offset 2023-10-07 08:49:32 +02:00
David Luzar
a249f332a2 fix: ensure we do not stop laser update prematurely (#7100) 2023-10-06 12:00:35 +02:00
Are
2e61926a6b feat: initial Laser Pointer MVP (#6739)
* feat: initial Laser pointer mvp

* feat: add laser-pointer package and integrate it with collab

* chore: fix yarn.lock

* feat: update laser-pointer package, prevent panning from showing

* feat: add laser pointer tool button when collaborating, migrate to official package

* feat: reduce laser tool button size

* update icon

* fix icon & rotate

* fix: lock zoom level

* fix icon

* add `selected` state, simplify and reduce api

* set up pointer callbacks in viewMode if laser tool active

* highlight extra-tools button if one of the nested tools active

* add shortcut to laser pointer

* feat: don't update paths if nothing changed

* ensure we reset flag if no rAF scheduled

* move `lastUpdate` to instance to optimize

* return early

* factor out into constants and add doc

* skip iteration instead of exit

* fix naming

* feat: remove testing variable on window

* destroy on editor unmount

* fix incorrectly resetting `lastUpdate` in `stop()`

---------

Co-authored-by: dwelle <luzar.david@gmail.com>
2023-10-05 17:05:16 +02:00
DanielJGeiger
e921bfb1ae feat: Export iconFillColor() (#6996) 2023-10-04 18:17:22 -05:00
David Luzar
e6f74350ac refactor: DRY out tool typing (#7086) 2023-10-04 23:39:00 +02:00
3 changed files with 33 additions and 36 deletions

View File

@@ -106,6 +106,13 @@ export class LaserPathManager {
} }
startPath(x: number, y: number) { startPath(x: number, y: number) {
if (this.container) {
this.container.style.top = "0px";
this.container.style.left = "0px";
const { x, y } = this.container.getBoundingClientRect();
this.container.style.top = `${-y}px`;
this.container.style.left = `${-x}px`;
}
this.ownState.currentPath = instantiatePath(); this.ownState.currentPath = instantiatePath();
this.ownState.currentPath.addPoint([x, y, performance.now()]); this.ownState.currentPath.addPoint([x, y, performance.now()]);
this.updatePath(this.ownState); this.updatePath(this.ownState);

View File

@@ -6,7 +6,6 @@
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
z-index: 2; z-index: 2;
.LaserToolOverlayCanvas { .LaserToolOverlayCanvas {

View File

@@ -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,