diff --git a/client-src/views/draw/state/state.ts b/client-src/views/draw/state/state.ts index 9cadd07..6672727 100644 --- a/client-src/views/draw/state/state.ts +++ b/client-src/views/draw/state/state.ts @@ -4,8 +4,8 @@ import { TLPointerEventHandler, TLShapeUtilsMap, Utils } from "@tldraw/core"; import { Vec } from "@tldraw/vec"; import { StateManager } from "rko"; import { draw, DrawUtil } from "./shapes"; -import sample from "./sample.json"; import type { StateSelector } from "zustand"; +import { VecRound } from "../utils.ts"; export const shapeUtils: TLShapeUtilsMap = { draw: new DrawUtil(), @@ -168,7 +168,7 @@ export class AppState extends StateManager { const camera = state.pageState.camera; const newPoint = [ - ...Vec.sub(Vec.round(Vec.sub(point, camera.point)), shape.point), + ...Vec.sub(VecRound(Vec.sub(point, camera.point)), shape.point), pressure, Date.now() - currentStroke.startTime, ]; @@ -183,14 +183,14 @@ export class AppState extends StateManager { if (offset[0] < 0 || offset[1] < 0) { // If so, then we need to move the shape to cancel the offset shapePoint = [ - ...Vec.round(Vec.add(shapePoint, offset)), + ...VecRound(Vec.add(shapePoint, offset)), shapePoint[2], shapePoint[3], ]; // And we need to move the shape points to cancel the offset shapePoints = shapePoints.map((pt) => - Vec.round(Vec.sub(pt, offset)).concat(pt[2], pt[3]), + VecRound(Vec.sub(pt, offset)).concat(pt[2], pt[3]), ); } diff --git a/client-src/views/draw/utils.ts b/client-src/views/draw/utils.ts new file mode 100644 index 0000000..c3cd71b --- /dev/null +++ b/client-src/views/draw/utils.ts @@ -0,0 +1,3 @@ +export const VecRound = (a: number[], d = 2) => { + return a.map((v) => +v.toFixed(d)); +}; diff --git a/package.json b/package.json index af6c660..f81aefc 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,9 @@ "@tailwindcss/vite": "^4.1.17", "@tanstack/react-query": "^5.90.9", "@tanstack/react-router": "^1.136.2", - "@tldraw/core": "^0.1.19", - "@tldraw/intersect": "^0.1.3", - "@tldraw/vec": "^0.1.3", + "@tldraw/core": "^1.23.2", + "@tldraw/intersect": "^1.9.2", + "@tldraw/vec": "^1.9.2", "hono": "^4.9.8", "hono-party": "^0.0.17", "partyserver": "^0.0.75", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 262e987..508b719 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -33,14 +33,14 @@ importers: specifier: ^1.136.2 version: 1.136.2(react-dom@19.2.0(react@19.2.0))(react@19.2.0) '@tldraw/core': - specifier: ^0.1.19 - version: 0.1.21(react-dom@19.2.0(react@19.2.0))(react@19.2.0) + specifier: ^1.23.2 + version: 1.23.2(react-dom@19.2.0(react@19.2.0))(react@19.2.0) '@tldraw/intersect': - specifier: ^0.1.3 - version: 0.1.4 + specifier: ^1.9.2 + version: 1.9.2 '@tldraw/vec': - specifier: ^0.1.3 - version: 0.1.3 + specifier: ^1.9.2 + version: 1.9.2 hono: specifier: ^4.9.8 version: 4.10.6 @@ -1333,21 +1333,15 @@ packages: resolution: {integrity: sha512-IKwZENsK7owmW1Lm5FhuHegY/SyQ8KqtL/7mTSnzoKJgfzhrrf9qwKB1rmkKkt+svUuy/Zw3uVEpZtUzQruWtA==} engines: {node: '>=12'} - '@tldraw/core@0.1.21': - resolution: {integrity: sha512-qaqXqVbeEq9jbjBsODS+UV/7opf4TyLOAi58gw94XC6tPwHpl8pkIvCKnyl10lHhac0GxGxSB+MPyKhlKioeZg==} + '@tldraw/core@1.23.2': + resolution: {integrity: sha512-cx+KfqemSHvVonNGwEolosMOsJt5cl3PGRBaXcZOOXQxnFALF22dnMtm6lbmlQQA71EfqNMP5e+qV3jCwuYaqA==} peerDependencies: react: '>=16.8' - react-dom: ^16.8 || ^17.0 - - '@tldraw/intersect@0.1.4': - resolution: {integrity: sha512-pxNMyUD9BMy0JqUSik4RXhf/meRA1TwJ3zESLebQ3EB3kThd9zICIUH5U8RmosvBx0c7dLMTvVzA1yVRbQBslQ==} + react-dom: '>=16.8' '@tldraw/intersect@1.9.2': resolution: {integrity: sha512-teUQLy+p5YT4PIKOHaL+zM0NYD1779mPp02xabP+5LGLvv7tt9VaqJ9D899EYppQbBLN6be6CJUrmibrvLtnUQ==} - '@tldraw/vec@0.1.3': - resolution: {integrity: sha512-QIQu6xHWqYBarfCR2Cd55pb+HECCEFI3RlU0VEueztzGe2k5Mwcv1EuuIdPTZ1tg5o95Deo7mYgZKeZTcUCIxA==} - '@tldraw/vec@1.9.2': resolution: {integrity: sha512-k9vH52MRpJHjVcaahWu6VqvhLeE9h1qL5Z2gLobS9zTMpUJ59kBQPNo0VPzPlDYBpXdS4GxuB4jYQMnKvuPAZg==} @@ -3556,24 +3550,19 @@ snapshots: '@tanstack/virtual-file-routes@1.133.19': {} - '@tldraw/core@0.1.21(react-dom@19.2.0(react@19.2.0))(react@19.2.0)': + '@tldraw/core@1.23.2(react-dom@19.2.0(react@19.2.0))(react@19.2.0)': dependencies: '@tldraw/intersect': 1.9.2 '@tldraw/vec': 1.9.2 '@use-gesture/react': 10.3.1(react@19.2.0) + perfect-freehand: 1.2.2 react: 19.2.0 react-dom: 19.2.0(react@19.2.0) - '@tldraw/intersect@0.1.4': - dependencies: - '@tldraw/vec': 0.1.3 - '@tldraw/intersect@1.9.2': dependencies: '@tldraw/vec': 1.9.2 - '@tldraw/vec@0.1.3': {} - '@tldraw/vec@1.9.2': {} '@types/babel__core@7.20.5':