mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
[skip ci] Remove temporary size hacks
This commit is contained in:
parent
cc01e16e52
commit
44df764a88
4 changed files with 9 additions and 167 deletions
|
@ -437,26 +437,12 @@ export const _generateElementShape = (
|
||||||
: [pointFrom<LocalPoint>(0, 0)];
|
: [pointFrom<LocalPoint>(0, 0)];
|
||||||
|
|
||||||
if (isElbowArrow(element)) {
|
if (isElbowArrow(element)) {
|
||||||
// NOTE (mtolmacs): Temporary fix for extremely big arrow shapes
|
shape = [
|
||||||
if (
|
generator.path(
|
||||||
!points.every(
|
generateElbowArrowShape(points, 16),
|
||||||
(point) => Math.abs(point[0]) <= 1e6 && Math.abs(point[1]) <= 1e6,
|
generateRoughOptions(element, true),
|
||||||
)
|
),
|
||||||
) {
|
];
|
||||||
console.error(
|
|
||||||
`Elbow arrow with extreme point positions detected. Arrow not rendered.`,
|
|
||||||
element.id,
|
|
||||||
JSON.stringify(points),
|
|
||||||
);
|
|
||||||
shape = [];
|
|
||||||
} else {
|
|
||||||
shape = [
|
|
||||||
generator.path(
|
|
||||||
generateElbowArrowShape(points, 16),
|
|
||||||
generateRoughOptions(element, true),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
} else if (!element.roundness) {
|
} else if (!element.roundness) {
|
||||||
// curve is always the first element
|
// curve is always the first element
|
||||||
// this simplifies finding the curve for an element
|
// this simplifies finding the curve for an element
|
||||||
|
|
|
@ -20,6 +20,7 @@ import {
|
||||||
tupleToCoors,
|
tupleToCoors,
|
||||||
getSizeFromPoints,
|
getSizeFromPoints,
|
||||||
isDevEnv,
|
isDevEnv,
|
||||||
|
isTestEnv,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import type { AppState } from "@excalidraw/excalidraw/types";
|
import type { AppState } from "@excalidraw/excalidraw/types";
|
||||||
|
@ -875,8 +876,6 @@ const handleEndpointDrag = (
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const MAX_POS = 1e6;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -897,51 +896,7 @@ export const updateElbowArrowPoints = (
|
||||||
return { points: updates.points ?? arrow.points };
|
return { points: updates.points ?? arrow.points };
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE (mtolmacs): This is a temporary check to ensure that the incoming elbow
|
if (isDevEnv() || isTestEnv()) {
|
||||||
// arrow size is valid. This check will be removed once the issue is identified
|
|
||||||
if (
|
|
||||||
arrow.x < -MAX_POS ||
|
|
||||||
arrow.x > MAX_POS ||
|
|
||||||
arrow.y < -MAX_POS ||
|
|
||||||
arrow.y > MAX_POS ||
|
|
||||||
arrow.x + (updates?.points?.[updates?.points?.length - 1]?.[0] ?? 0) <
|
|
||||||
-MAX_POS ||
|
|
||||||
arrow.x + (updates?.points?.[updates?.points?.length - 1]?.[0] ?? 0) >
|
|
||||||
MAX_POS ||
|
|
||||||
arrow.y + (updates?.points?.[updates?.points?.length - 1]?.[1] ?? 0) <
|
|
||||||
-MAX_POS ||
|
|
||||||
arrow.y + (updates?.points?.[updates?.points?.length - 1]?.[1] ?? 0) >
|
|
||||||
MAX_POS ||
|
|
||||||
arrow.x + (arrow?.points?.[arrow?.points?.length - 1]?.[0] ?? 0) <
|
|
||||||
-MAX_POS ||
|
|
||||||
arrow.x + (arrow?.points?.[arrow?.points?.length - 1]?.[0] ?? 0) >
|
|
||||||
MAX_POS ||
|
|
||||||
arrow.y + (arrow?.points?.[arrow?.points?.length - 1]?.[1] ?? 0) <
|
|
||||||
-MAX_POS ||
|
|
||||||
arrow.y + (arrow?.points?.[arrow?.points?.length - 1]?.[1] ?? 0) > MAX_POS
|
|
||||||
) {
|
|
||||||
console.error(
|
|
||||||
"Elbow arrow (or update) is outside reasonable bounds (> 1e6)",
|
|
||||||
{
|
|
||||||
arrow,
|
|
||||||
updates,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// @ts-ignore See above note
|
|
||||||
arrow.x = clamp(arrow.x, -MAX_POS, MAX_POS);
|
|
||||||
// @ts-ignore See above note
|
|
||||||
arrow.y = clamp(arrow.y, -MAX_POS, MAX_POS);
|
|
||||||
if (updates.points) {
|
|
||||||
updates.points = updates.points.map(([x, y]) =>
|
|
||||||
pointFrom<LocalPoint>(
|
|
||||||
clamp(x, -MAX_POS, MAX_POS),
|
|
||||||
clamp(y, -MAX_POS, MAX_POS),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!import.meta.env.PROD) {
|
|
||||||
invariant(
|
invariant(
|
||||||
!updates.points || updates.points.length >= 2,
|
!updates.points || updates.points.length >= 2,
|
||||||
"Updated point array length must match the arrow point length, contain " +
|
"Updated point array length must match the arrow point length, contain " +
|
||||||
|
@ -2120,29 +2075,6 @@ const normalizeArrowElementUpdate = (
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// NOTE (mtolmacs): This is a temporary check to see if the normalization
|
|
||||||
// creates an overly large arrow. This should be removed once we have an answer.
|
|
||||||
if (
|
|
||||||
offsetX < -MAX_POS ||
|
|
||||||
offsetX > MAX_POS ||
|
|
||||||
offsetY < -MAX_POS ||
|
|
||||||
offsetY > MAX_POS ||
|
|
||||||
offsetX + points[points.length - 1][0] < -MAX_POS ||
|
|
||||||
offsetY + points[points.length - 1][0] > MAX_POS ||
|
|
||||||
offsetX + points[points.length - 1][1] < -MAX_POS ||
|
|
||||||
offsetY + points[points.length - 1][1] > MAX_POS
|
|
||||||
) {
|
|
||||||
console.error(
|
|
||||||
"Elbow arrow normalization is outside reasonable bounds (> 1e6)",
|
|
||||||
{
|
|
||||||
x: offsetX,
|
|
||||||
y: offsetY,
|
|
||||||
points,
|
|
||||||
...getSizeFromPoints(points),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
points = points.map(([x, y]) =>
|
points = points.map(([x, y]) =>
|
||||||
pointFrom<LocalPoint>(clamp(x, -1e6, 1e6), clamp(y, -1e6, 1e6)),
|
pointFrom<LocalPoint>(clamp(x, -1e6, 1e6), clamp(y, -1e6, 1e6)),
|
||||||
);
|
);
|
||||||
|
|
|
@ -20,10 +20,6 @@ import {
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
import { getNonDeletedElements } from "@excalidraw/element";
|
import { getNonDeletedElements } from "@excalidraw/element";
|
||||||
import { normalizeFixedPoint } from "@excalidraw/element/binding";
|
import { normalizeFixedPoint } from "@excalidraw/element/binding";
|
||||||
import {
|
|
||||||
updateElbowArrowPoints,
|
|
||||||
validateElbowPoints,
|
|
||||||
} from "@excalidraw/element/elbowArrow";
|
|
||||||
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
|
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
|
||||||
import { bumpVersion } from "@excalidraw/element/mutateElement";
|
import { bumpVersion } from "@excalidraw/element/mutateElement";
|
||||||
import { getContainerElement } from "@excalidraw/element/textElement";
|
import { getContainerElement } from "@excalidraw/element/textElement";
|
||||||
|
@ -57,7 +53,6 @@ import type {
|
||||||
ExcalidrawTextElement,
|
ExcalidrawTextElement,
|
||||||
FixedPointBinding,
|
FixedPointBinding,
|
||||||
FontFamilyValues,
|
FontFamilyValues,
|
||||||
NonDeletedSceneElementsMap,
|
|
||||||
OrderedExcalidrawElement,
|
OrderedExcalidrawElement,
|
||||||
PointBinding,
|
PointBinding,
|
||||||
StrokeRoundness,
|
StrokeRoundness,
|
||||||
|
@ -585,73 +580,7 @@ export const restoreElements = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE (mtolmacs): Temporary fix for extremely large arrows
|
return restoredElements;
|
||||||
// Need to iterate again so we have attached text nodes in elementsMap
|
|
||||||
return restoredElements.map((element) => {
|
|
||||||
if (
|
|
||||||
isElbowArrow(element) &&
|
|
||||||
element.startBinding == null &&
|
|
||||||
element.endBinding == null &&
|
|
||||||
!validateElbowPoints(element.points)
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
...element,
|
|
||||||
...updateElbowArrowPoints(
|
|
||||||
element,
|
|
||||||
restoredElementsMap as NonDeletedSceneElementsMap,
|
|
||||||
{
|
|
||||||
points: [
|
|
||||||
pointFrom<LocalPoint>(0, 0),
|
|
||||||
element.points[element.points.length - 1],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
index: element.index,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
isElbowArrow(element) &&
|
|
||||||
element.startBinding &&
|
|
||||||
element.endBinding &&
|
|
||||||
element.startBinding.elementId === element.endBinding.elementId &&
|
|
||||||
element.points.length > 1 &&
|
|
||||||
element.points.some(
|
|
||||||
([rx, ry]) => Math.abs(rx) > 1e6 || Math.abs(ry) > 1e6,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
console.error("Fixing self-bound elbow arrow", element.id);
|
|
||||||
const boundElement = restoredElementsMap.get(
|
|
||||||
element.startBinding.elementId,
|
|
||||||
);
|
|
||||||
if (!boundElement) {
|
|
||||||
console.error(
|
|
||||||
"Bound element not found",
|
|
||||||
element.startBinding.elementId,
|
|
||||||
);
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...element,
|
|
||||||
x: boundElement.x + boundElement.width / 2,
|
|
||||||
y: boundElement.y - 5,
|
|
||||||
width: boundElement.width,
|
|
||||||
height: boundElement.height,
|
|
||||||
points: [
|
|
||||||
pointFrom<LocalPoint>(0, 0),
|
|
||||||
pointFrom<LocalPoint>(0, -10),
|
|
||||||
pointFrom<LocalPoint>(boundElement.width / 2 + 5, -10),
|
|
||||||
pointFrom<LocalPoint>(
|
|
||||||
boundElement.width / 2 + 5,
|
|
||||||
boundElement.height / 2 + 5,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return element;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const coalesceAppStateValue = <
|
const coalesceAppStateValue = <
|
||||||
|
|
|
@ -195,11 +195,6 @@ export const getEllipseShape = <Point extends GlobalPoint | LocalPoint>(
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCurvePathOps = (shape: Drawable): Op[] => {
|
export const getCurvePathOps = (shape: Drawable): Op[] => {
|
||||||
// NOTE (mtolmacs): Temporary fix for extremely large elements
|
|
||||||
if (!shape) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const set of shape.sets) {
|
for (const set of shape.sets) {
|
||||||
if (set.type === "path") {
|
if (set.type === "path") {
|
||||||
return set.ops;
|
return set.ops;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue