Compare commits

..

5 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
3 changed files with 40 additions and 9 deletions

View File

@@ -91,7 +91,7 @@ export class LaserPathManager {
private collaboratorsState: Map<string, CollabolatorState> = new Map();
private rafId: number | undefined;
private lastUpdate = 0;
private isDrawing = false;
private container: SVGSVGElement | undefined;
constructor(private app: App) {
@@ -100,12 +100,19 @@ export class LaserPathManager {
destroy() {
this.stop();
this.lastUpdate = 0;
this.isDrawing = false;
this.ownState = instantiateCollabolatorState();
this.collaboratorsState = new Map();
}
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.addPoint([x, y, performance.now()]);
this.updatePath(this.ownState);
@@ -127,7 +134,7 @@ export class LaserPathManager {
}
private updatePath(state: CollabolatorState) {
this.lastUpdate = performance.now();
this.isDrawing = true;
if (!this.isRunning) {
this.start();
@@ -160,7 +167,7 @@ export class LaserPathManager {
this.updateCollabolatorsState();
if (performance.now() - this.lastUpdate < DECAY_TIME * 2) {
if (this.isDrawing) {
this.update();
} else {
this.isRunning = false;
@@ -250,6 +257,8 @@ export class LaserPathManager {
return;
}
let somePathsExist = false;
for (const [key, state] of this.collaboratorsState.entries()) {
if (!this.app.state.collaborators.has(key)) {
state.svg.remove();
@@ -269,6 +278,10 @@ export class LaserPathManager {
paths += ` ${this.draw(state.currentPath)}`;
}
if (paths.trim()) {
somePathsExist = true;
}
state.svg.setAttribute("d", paths);
state.svg.setAttribute("fill", getClientColor(key));
}
@@ -287,7 +300,17 @@ export class LaserPathManager {
paths += ` ${this.draw(this.ownState.currentPath)}`;
}
paths = paths.trim();
if (paths) {
somePathsExist = true;
}
this.ownState.svg.setAttribute("d", paths);
this.ownState.svg.setAttribute("fill", "red");
if (!somePathsExist) {
this.isDrawing = false;
}
}
}

View File

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

View File

@@ -5994,10 +5994,19 @@ portfinder@^1.0.28:
debug "^3.2.7"
mkdirp "^0.5.6"
postcss@^8.4.23, postcss@^8.4.24:
version "8.4.31"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.31.tgz#92b451050a9f914da6755af352bdc0192508656d"
integrity sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==
postcss@^8.4.23:
version "8.4.24"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.24.tgz#f714dba9b2284be3cc07dbd2fc57ee4dc972d2df"
integrity sha512-M0RzbcI0sO/XJNucsGjvWU9ERWxb/ytp1w6dKtxTKgixdtQDq4rmx/g8W1hnaheq9jgwL/oyEdH5Bc4WwJKMqg==
dependencies:
nanoid "^3.3.6"
picocolors "^1.0.0"
source-map-js "^1.0.2"
postcss@^8.4.24:
version "8.4.25"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.25.tgz#4a133f5e379eda7f61e906c3b1aaa9b81292726f"
integrity sha512-7taJ/8t2av0Z+sQEvNzCkpDynl0tX3uJMCODi6nT3PfASC7dYCWV9aQ+uiCf+KBD4SEFcu+GvJdGdwzQ6OSjCw==
dependencies:
nanoid "^3.3.6"
picocolors "^1.0.0"