mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Merge 60907a5a0e
into debf2ad608
This commit is contained in:
commit
741ddd4e16
48 changed files with 860 additions and 851 deletions
|
@ -1,14 +1,9 @@
|
|||
import {
|
||||
pointFromPair,
|
||||
type GlobalPoint,
|
||||
type LocalPoint,
|
||||
} from "@excalidraw/math";
|
||||
import { type GenericPoint, pointFromPair } from "@excalidraw/math";
|
||||
import { pointFrom } from "@excalidraw/math";
|
||||
|
||||
import type { NullableGridSize } from "@excalidraw/excalidraw/types";
|
||||
|
||||
export const getSizeFromPoints = (
|
||||
points: readonly (GlobalPoint | LocalPoint)[],
|
||||
) => {
|
||||
export const getSizeFromPoints = (points: readonly GenericPoint[]) => {
|
||||
const xs = points.map((point) => point[0]);
|
||||
const ys = points.map((point) => point[1]);
|
||||
return {
|
||||
|
@ -18,7 +13,7 @@ export const getSizeFromPoints = (
|
|||
};
|
||||
|
||||
/** @arg dimension, 0 for rescaling only x, 1 for y */
|
||||
export const rescalePoints = <Point extends GlobalPoint | LocalPoint>(
|
||||
export const rescalePoints = <Point extends GenericPoint>(
|
||||
dimension: 0 | 1,
|
||||
newSize: number,
|
||||
points: readonly Point[],
|
||||
|
@ -65,16 +60,16 @@ export const rescalePoints = <Point extends GlobalPoint | LocalPoint>(
|
|||
};
|
||||
|
||||
// TODO: Rounding this point causes some shake when free drawing
|
||||
export const getGridPoint = (
|
||||
export const getGridPoint = <Point extends GenericPoint>(
|
||||
x: number,
|
||||
y: number,
|
||||
gridSize: NullableGridSize,
|
||||
): [number, number] => {
|
||||
): Point => {
|
||||
if (gridSize) {
|
||||
return [
|
||||
return pointFrom(
|
||||
Math.round(x / gridSize) * gridSize,
|
||||
Math.round(y / gridSize) * gridSize,
|
||||
];
|
||||
);
|
||||
}
|
||||
return [x, y];
|
||||
return pointFrom(x, y);
|
||||
};
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
import { average, pointFrom, type GlobalPoint } from "@excalidraw/math";
|
||||
import {
|
||||
average,
|
||||
pointFrom,
|
||||
type ViewportPoint,
|
||||
type GlobalPoint,
|
||||
type GenericPoint,
|
||||
} from "@excalidraw/math";
|
||||
|
||||
import type {
|
||||
ExcalidrawBindableElement,
|
||||
|
@ -448,11 +454,11 @@ export const viewportCoordsToSceneCoords = (
|
|||
scrollX: number;
|
||||
scrollY: number;
|
||||
},
|
||||
) => {
|
||||
): ViewportPoint => {
|
||||
const x = (clientX - offsetLeft) / zoom.value - scrollX;
|
||||
const y = (clientY - offsetTop) / zoom.value - scrollY;
|
||||
|
||||
return { x, y };
|
||||
return pointFrom<ViewportPoint>(x, y);
|
||||
};
|
||||
|
||||
export const sceneCoordsToViewportCoords = (
|
||||
|
@ -470,10 +476,10 @@ export const sceneCoordsToViewportCoords = (
|
|||
scrollX: number;
|
||||
scrollY: number;
|
||||
},
|
||||
) => {
|
||||
): ViewportPoint => {
|
||||
const x = (sceneX + scrollX) * zoom.value + offsetLeft;
|
||||
const y = (sceneY + scrollY) * zoom.value + offsetTop;
|
||||
return { x, y };
|
||||
return pointFrom<ViewportPoint>(x, y);
|
||||
};
|
||||
|
||||
export const getGlobalCSSVariable = (name: string) =>
|
||||
|
@ -492,11 +498,11 @@ const RE_RTL_CHECK = new RegExp(`^[^${RS_LTR_CHARS}]*[${RS_RTL_CHARS}]`);
|
|||
*/
|
||||
export const isRTL = (text: string) => RE_RTL_CHECK.test(text);
|
||||
|
||||
export const tupleToCoors = (
|
||||
export const tupleToCoors = <Point extends GenericPoint>(
|
||||
xyTuple: readonly [number, number],
|
||||
): { x: number; y: number } => {
|
||||
): Point => {
|
||||
const [x, y] = xyTuple;
|
||||
return { x, y };
|
||||
return pointFrom(x, y);
|
||||
};
|
||||
|
||||
/** use as a rejectionHandler to mute filesystem Abort errors */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue