BlockSuite API Documentation / @blocksuite/affine-block-surface / CommonUtils
Variable: CommonUtils
constCommonUtils:object
Type declaration
almostEqual()
almostEqual: (
a,b,epsilon?) =>boolean
Parameters
a
number
b
number
epsilon?
number
Returns
boolean
clamp()
clamp: (
n,min,max?) =>number
Parameters
n
number
min
number
max?
number
Returns
number
generateElementId()
generateElementId: () =>
string
Returns
string
generateKeyBetween()
generateKeyBetween: (
a,b,digits?) =>string
Parameters
a
undefined | null | string
b
undefined | null | string
digits?
string
Returns
string
getPointFromBoundsWithRotation()
getPointFromBoundsWithRotation: (
bounds,point) =>IVec
Parameters
bounds
IBound
point
IVec
Returns
IVec
getStroke()
getStroke: (
points,options?) =>IVec[]
getStroke
Parameters
points
(IVec | IVec3 | { pressure: number; x: number; y: number; })[]
An array of points (as [x, y, pressure] or {x, y, pressure}). Pressure is optional in both cases.
options?
StrokeOptions
(optional) An object with options.
Returns
IVec[]
Description
Get an array of points describing a polygon that surrounds the input points.
getSvgPathFromStroke()
getSvgPathFromStroke: (
points,closed?) =>string
Parameters
points
IVec[]
closed?
boolean
Returns
string
intersects()
intersects: (
a,b) =>boolean
Parameters
a
IBound
b
IBound
Returns
boolean
isOverlap()
isOverlap: (
line1,line2,axis,strict?) =>boolean
Parameters
line1
IVec[]
line2
IVec[]
axis
0 | 1
strict?
boolean
Returns
boolean
isPointIn()
isPointIn: (
a,x,y) =>boolean
Parameters
a
IBound
x
number
y
number
Returns
boolean
lineIntersects()
lineIntersects: (
sp,ep,sp2,ep2,infinite?) =>IVec|null
Parameters
sp
IVec
ep
IVec
sp2
IVec
ep2
IVec
infinite?
boolean
Returns
IVec | null
linePolygonIntersects()
linePolygonIntersects: (
sp,ep,points) =>PointLocation[] |null
Parameters
sp
IVec
ep
IVec
points
IVec[]
Returns
PointLocation[] | null
normalizeDegAngle()
normalizeDegAngle: (
angle) =>number
Parameters
angle
number
Returns
number
normalizeWheelDeltaY()
normalizeWheelDeltaY: (
delta,zoom) =>number
Normalizes wheel delta.
See https://stackoverflow.com/a/13650579
From https://github.com/excalidraw/excalidraw/blob/master/src/components/App.tsx MIT License
Parameters
delta
number
zoom
number = 1
Returns
number
polygonGetPointTangent()
polygonGetPointTangent: (
points,point) =>IVec
Parameters
points
IVec[]
point
IVec
Returns
IVec
polygonNearestPoint()
polygonNearestPoint: (
points,point) =>IVec
Parameters
points
IVec[]
point
IVec
Returns
IVec
polygonPointDistance()
polygonPointDistance: (
points,point) =>number
Parameters
points
IVec[]
point
IVec
Returns
number
polyLineNearestPoint()
polyLineNearestPoint: (
points,point) =>IVec
Parameters
points
IVec[]
point
IVec
Returns
IVec
rotatePoints()
rotatePoints: <
T>(points,center,rotate) =>T[]
Type Parameters
• T extends IVec
Parameters
points
T[]
center
IVec
rotate
number
Returns
T[]
sign()
sign: (
number) =>1|-1
Parameters
number
number
Returns
1 | -1
toDegree()
toDegree: (
radian) =>number
Parameters
radian
number
Returns
number
toRadian()
toRadian: (
angle) =>number
Parameters
angle
number
Returns
number
Defined in
packages/affine/block-surface/src/index.ts:120