@blocksuite/global
Advanced tools
Comparing version 0.17.19 to 0.17.20
# @blocksuite/global | ||
## 0.17.20 | ||
### Patch Changes | ||
- 99d69d5: ## Feat | ||
- feat(blocks): add more html transformer apis (#8573) | ||
- feat(blocks): support more markdown transformer api (#8564) | ||
- feat(blocks): add abort controller to peekviewservice (#8558) | ||
- feat: add docLinkMiddleware for linked doc export (#8553) | ||
## Fix | ||
- fix: mind map dragging issue (#8563) | ||
- fix(database): can't use horizontal scrollbar (#8576) | ||
- fix: note width is less than minimum width after resize and arrange (#8550) | ||
- fix: newly created note alignments cannot be stored persistently (#8551) | ||
- fix: inline range calculation not expected (#8552) | ||
- fix(database): avoid filter bar flickering (#8562) | ||
- fix(database): drag and drop block into database block (#8561) | ||
- fix(blocks): split paragraphs based on newlines (#8556) | ||
- fix(database): incorrect delete row logic (#8544) | ||
- fix: note height less than minimum height (#8542) | ||
## Chore | ||
- chore: add changelog generating script (#8582) | ||
- chore: optimize zip transformer api (#8580) | ||
- chore: adjust attachment click events, like image, to support opening in peek view (#8579) | ||
- chore: remove useless import (#8571) | ||
## Refactor | ||
- refactor: convert built-in component to widget (#8577) | ||
- refactor: migrating legacy tools (#8471) | ||
- refactor: edgeless tool manager (#8438) | ||
- refactor(playground): organize export and import menu items into submenus in the debug menu (#8557) | ||
- refactor: combine unsafeCSS and cssVar (#8545) | ||
## Perf | ||
- perf(edgeless): use css var to place collaboration cursors-n-selections on board zoom change (#8543) | ||
## 0.17.19 | ||
@@ -4,0 +47,0 @@ |
import { Bound, type IBound, type IVec } from './model/index.js'; | ||
export declare function getPointsFromBoundWithRotation(bounds: IBound, getPoints?: (bounds: IBound) => IVec[], resPadding?: [number, number]): IVec[]; | ||
export declare function getQuadBoundWithRotation(bounds: IBound): DOMRect; | ||
export declare function getBoundWithRotation(bound: IBound): IBound; | ||
/** | ||
* Returns the common bound of the given bounds. | ||
* The rotation of the bounds is not considered. | ||
* @param bounds | ||
* @returns | ||
*/ | ||
export declare function getCommonBound(bounds: IBound[]): Bound | null; | ||
export declare function getElementsBound(bounds: IBound[]): Bound; | ||
/** | ||
* Like `getCommonBound`, but considers the rotation of the bounds. | ||
* @returns | ||
*/ | ||
export declare function getCommonBoundWithRotation(bounds: IBound[]): Bound; | ||
export declare function getIBoundFromPoints(points: IVec[], rotation?: number): IBound & { | ||
maxX: number; | ||
maxY: number; | ||
minX: number; | ||
minY: number; | ||
}; | ||
export declare function getBoundFromPoints(points: IVec[]): Bound; | ||
@@ -5,0 +24,0 @@ export declare function inflateBound(bound: IBound, delta: number): Bound; |
@@ -1,3 +0,2 @@ | ||
import { getBoundsFromPoints, getBoundsWithRotation } from './math.js'; | ||
import { Bound } from './model/index.js'; | ||
import { Bound, Vec } from './model/index.js'; | ||
function getExpandedBound(a, b) { | ||
@@ -17,2 +16,51 @@ const minX = Math.min(a.x, b.x); | ||
} | ||
export function getPointsFromBoundWithRotation(bounds, getPoints = ({ x, y, w, h }) => [ | ||
// left-top | ||
[x, y], | ||
// right-top | ||
[x + w, y], | ||
// right-bottom | ||
[x + w, y + h], | ||
// left-bottom | ||
[x, y + h], | ||
], resPadding = [0, 0]) { | ||
const { rotate } = bounds; | ||
let points = getPoints({ | ||
x: bounds.x - resPadding[1], | ||
y: bounds.y - resPadding[0], | ||
w: bounds.w + resPadding[1] * 2, | ||
h: bounds.h + resPadding[0] * 2, | ||
}); | ||
if (rotate) { | ||
const { x, y, w, h } = bounds; | ||
const cx = x + w / 2; | ||
const cy = y + h / 2; | ||
const m = new DOMMatrix() | ||
.translateSelf(cx, cy) | ||
.rotateSelf(rotate) | ||
.translateSelf(-cx, -cy); | ||
points = points.map(point => { | ||
const { x, y } = new DOMPoint(...point).matrixTransform(m); | ||
return [x, y]; | ||
}); | ||
} | ||
return points; | ||
} | ||
export function getQuadBoundWithRotation(bounds) { | ||
const { x, y, w, h, rotate } = bounds; | ||
const rect = new DOMRect(x, y, w, h); | ||
if (!rotate) | ||
return rect; | ||
return new DOMQuad(...getPointsFromBoundWithRotation(bounds).map(point => new DOMPoint(...point))).getBounds(); | ||
} | ||
export function getBoundWithRotation(bound) { | ||
const { x, y, width: w, height: h } = getQuadBoundWithRotation(bound); | ||
return { x, y, w, h }; | ||
} | ||
/** | ||
* Returns the common bound of the given bounds. | ||
* The rotation of the bounds is not considered. | ||
* @param bounds | ||
* @returns | ||
*/ | ||
export function getCommonBound(bounds) { | ||
@@ -32,19 +80,49 @@ if (!bounds.length) { | ||
} | ||
export function getElementsBound(bounds) { | ||
let minX = Number.POSITIVE_INFINITY; | ||
let minY = Number.POSITIVE_INFINITY; | ||
let maxX = Number.NEGATIVE_INFINITY; | ||
let maxY = Number.NEGATIVE_INFINITY; | ||
bounds.forEach(ele => { | ||
const b = getBoundsWithRotation(ele); | ||
minX = Math.min(minX, b.x); | ||
minY = Math.min(minY, b.y); | ||
maxX = Math.max(maxX, b.x + b.w); | ||
maxY = Math.max(maxY, b.y + b.h); | ||
}); | ||
return new Bound(minX, minY, maxX - minX, maxY - minY); | ||
/** | ||
* Like `getCommonBound`, but considers the rotation of the bounds. | ||
* @returns | ||
*/ | ||
export function getCommonBoundWithRotation(bounds) { | ||
if (bounds.length === 0) { | ||
return new Bound(0, 0, 0, 0); | ||
} | ||
return bounds.reduce((pre, bound) => { | ||
return pre.unite(bound instanceof Bound ? bound : Bound.from(getBoundWithRotation(bound))); | ||
}, Bound.from(getBoundWithRotation(bounds[0]))); | ||
} | ||
export function getIBoundFromPoints(points, rotation = 0) { | ||
let minX = Infinity; | ||
let minY = Infinity; | ||
let maxX = -Infinity; | ||
let maxY = -Infinity; | ||
if (points.length < 1) { | ||
minX = 0; | ||
minY = 0; | ||
maxX = 1; | ||
maxY = 1; | ||
} | ||
else { | ||
for (const [x, y] of points) { | ||
minX = Math.min(x, minX); | ||
minY = Math.min(y, minY); | ||
maxX = Math.max(x, maxX); | ||
maxY = Math.max(y, maxY); | ||
} | ||
} | ||
if (rotation !== 0) { | ||
return getIBoundFromPoints(points.map(pt => Vec.rotWith(pt, [(minX + maxX) / 2, (minY + maxY) / 2], rotation))); | ||
} | ||
return { | ||
minX, | ||
minY, | ||
maxX, | ||
maxY, | ||
x: minX, | ||
y: minY, | ||
w: maxX - minX, | ||
h: maxY - minY, | ||
}; | ||
} | ||
export function getBoundFromPoints(points) { | ||
const { minX, minY, width, height } = getBoundsFromPoints(points); | ||
return new Bound(minX, minY, width, height); | ||
return Bound.from(getIBoundFromPoints(points)); | ||
} | ||
@@ -51,0 +129,0 @@ export function inflateBound(bound, delta) { |
@@ -8,16 +8,3 @@ import type { Bound, IBound } from './model/bound.js'; | ||
export declare const CURVETIME_EPSILON = 1e-8; | ||
interface TLBounds { | ||
minX: number; | ||
minY: number; | ||
maxX: number; | ||
maxY: number; | ||
width: number; | ||
height: number; | ||
rotation?: number; | ||
} | ||
export declare function randomSeed(): number; | ||
export declare function getBoundsFromPoints(points: IVec[], rotation?: number): TLBounds; | ||
export declare function getPointsFromBoundsWithRotation(bounds: IBound, getPoints?: (bounds: IBound) => IVec[], resPadding?: [number, number]): IVec[]; | ||
export declare function getQuadBoundsWithRotation(bounds: IBound): DOMRect; | ||
export declare function getBoundsWithRotation(bounds: IBound): IBound; | ||
export declare function lineIntersects(sp: IVec, ep: IVec, sp2: IVec, ep2: IVec, infinite?: boolean): IVec | null; | ||
@@ -62,3 +49,2 @@ export declare function polygonNearestPoint(points: IVec[], point: IVec): IVec; | ||
}; | ||
export {}; | ||
//# sourceMappingURL=math.d.ts.map |
@@ -10,76 +10,2 @@ import { PointLocation } from './model/point-location.js'; | ||
} | ||
export function getBoundsFromPoints(points, rotation = 0) { | ||
let minX = Infinity; | ||
let minY = Infinity; | ||
let maxX = -Infinity; | ||
let maxY = -Infinity; | ||
if (points.length < 1) { | ||
minX = 0; | ||
minY = 0; | ||
maxX = 1; | ||
maxY = 1; | ||
} | ||
else { | ||
for (const [x, y] of points) { | ||
minX = Math.min(x, minX); | ||
minY = Math.min(y, minY); | ||
maxX = Math.max(x, maxX); | ||
maxY = Math.max(y, maxY); | ||
} | ||
} | ||
if (rotation !== 0) { | ||
return getBoundsFromPoints(points.map(pt => Vec.rotWith(pt, [(minX + maxX) / 2, (minY + maxY) / 2], rotation))); | ||
} | ||
return { | ||
minX, | ||
minY, | ||
maxX, | ||
maxY, | ||
width: Math.max(1, maxX - minX), | ||
height: Math.max(1, maxY - minY), | ||
}; | ||
} | ||
export function getPointsFromBoundsWithRotation(bounds, getPoints = ({ x, y, w, h }) => [ | ||
// left-top | ||
[x, y], | ||
// right-top | ||
[x + w, y], | ||
// right-bottom | ||
[x + w, y + h], | ||
// left-bottom | ||
[x, y + h], | ||
], resPadding = [0, 0]) { | ||
const { rotate } = bounds; | ||
let points = getPoints({ | ||
x: bounds.x - resPadding[1], | ||
y: bounds.y - resPadding[0], | ||
w: bounds.w + resPadding[1] * 2, | ||
h: bounds.h + resPadding[0] * 2, | ||
}); | ||
if (rotate) { | ||
const { x, y, w, h } = bounds; | ||
const cx = x + w / 2; | ||
const cy = y + h / 2; | ||
const m = new DOMMatrix() | ||
.translateSelf(cx, cy) | ||
.rotateSelf(rotate) | ||
.translateSelf(-cx, -cy); | ||
points = points.map(point => { | ||
const { x, y } = new DOMPoint(...point).matrixTransform(m); | ||
return [x, y]; | ||
}); | ||
} | ||
return points; | ||
} | ||
export function getQuadBoundsWithRotation(bounds) { | ||
const { x, y, w, h, rotate } = bounds; | ||
const rect = new DOMRect(x, y, w, h); | ||
if (!rotate) | ||
return rect; | ||
return new DOMQuad(...getPointsFromBoundsWithRotation(bounds).map(point => new DOMPoint(...point))).getBounds(); | ||
} | ||
export function getBoundsWithRotation(bounds) { | ||
const { x, y, width: w, height: h } = getQuadBoundsWithRotation(bounds); | ||
return { x, y, w, h }; | ||
} | ||
export function lineIntersects(sp, ep, sp2, ep2, infinite = false) { | ||
@@ -86,0 +12,0 @@ const v1 = Vec.sub(ep, sp); |
@@ -1,2 +0,3 @@ | ||
import { EPSILON, getBoundsFromPoints, lineIntersects, polygonPointDistance, } from '../math.js'; | ||
import { getIBoundFromPoints } from '../bound.js'; | ||
import { EPSILON, lineIntersects, polygonPointDistance } from '../math.js'; | ||
import { deserializeXYWH, serializeXYWH } from '../xywh.js'; | ||
@@ -109,4 +110,3 @@ export class Bound { | ||
static fromPoints(points) { | ||
const { minX, minY, maxX, maxY } = getBoundsFromPoints(points); | ||
return new Bound(minX, minY, maxX - minX, maxY - minY); | ||
return Bound.from(getIBoundFromPoints(points)); | ||
} | ||
@@ -113,0 +113,0 @@ static fromXYWH(xywh) { |
{ | ||
"name": "@blocksuite/global", | ||
"version": "0.17.19", | ||
"version": "0.17.20", | ||
"types": "./index.d.ts", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -1,3 +0,2 @@ | ||
import { getBoundsFromPoints, getBoundsWithRotation } from './math.js'; | ||
import { Bound, type IBound, type IVec } from './model/index.js'; | ||
import { Bound, type IBound, type IVec, Vec } from './model/index.js'; | ||
@@ -20,2 +19,67 @@ function getExpandedBound(a: IBound, b: IBound): IBound { | ||
export function getPointsFromBoundWithRotation( | ||
bounds: IBound, | ||
getPoints: (bounds: IBound) => IVec[] = ({ x, y, w, h }: IBound) => [ | ||
// left-top | ||
[x, y], | ||
// right-top | ||
[x + w, y], | ||
// right-bottom | ||
[x + w, y + h], | ||
// left-bottom | ||
[x, y + h], | ||
], | ||
resPadding: [number, number] = [0, 0] | ||
): IVec[] { | ||
const { rotate } = bounds; | ||
let points = getPoints({ | ||
x: bounds.x - resPadding[1], | ||
y: bounds.y - resPadding[0], | ||
w: bounds.w + resPadding[1] * 2, | ||
h: bounds.h + resPadding[0] * 2, | ||
}); | ||
if (rotate) { | ||
const { x, y, w, h } = bounds; | ||
const cx = x + w / 2; | ||
const cy = y + h / 2; | ||
const m = new DOMMatrix() | ||
.translateSelf(cx, cy) | ||
.rotateSelf(rotate) | ||
.translateSelf(-cx, -cy); | ||
points = points.map(point => { | ||
const { x, y } = new DOMPoint(...point).matrixTransform(m); | ||
return [x, y]; | ||
}); | ||
} | ||
return points; | ||
} | ||
export function getQuadBoundWithRotation(bounds: IBound): DOMRect { | ||
const { x, y, w, h, rotate } = bounds; | ||
const rect = new DOMRect(x, y, w, h); | ||
if (!rotate) return rect; | ||
return new DOMQuad( | ||
...getPointsFromBoundWithRotation(bounds).map( | ||
point => new DOMPoint(...point) | ||
) | ||
).getBounds(); | ||
} | ||
export function getBoundWithRotation(bound: IBound): IBound { | ||
const { x, y, width: w, height: h } = getQuadBoundWithRotation(bound); | ||
return { x, y, w, h }; | ||
} | ||
/** | ||
* Returns the common bound of the given bounds. | ||
* The rotation of the bounds is not considered. | ||
* @param bounds | ||
* @returns | ||
*/ | ||
export function getCommonBound(bounds: IBound[]): Bound | null { | ||
@@ -25,2 +89,3 @@ if (!bounds.length) { | ||
} | ||
if (bounds.length === 1) { | ||
@@ -40,23 +105,71 @@ const { x, y, w, h } = bounds[0]; | ||
export function getElementsBound(bounds: IBound[]): Bound { | ||
let minX = Number.POSITIVE_INFINITY; | ||
let minY = Number.POSITIVE_INFINITY; | ||
let maxX = Number.NEGATIVE_INFINITY; | ||
let maxY = Number.NEGATIVE_INFINITY; | ||
/** | ||
* Like `getCommonBound`, but considers the rotation of the bounds. | ||
* @returns | ||
*/ | ||
export function getCommonBoundWithRotation(bounds: IBound[]): Bound { | ||
if (bounds.length === 0) { | ||
return new Bound(0, 0, 0, 0); | ||
} | ||
bounds.forEach(ele => { | ||
const b = getBoundsWithRotation(ele); | ||
return bounds.reduce( | ||
(pre, bound) => { | ||
return pre.unite( | ||
bound instanceof Bound ? bound : Bound.from(getBoundWithRotation(bound)) | ||
); | ||
}, | ||
Bound.from(getBoundWithRotation(bounds[0])) | ||
); | ||
} | ||
minX = Math.min(minX, b.x); | ||
minY = Math.min(minY, b.y); | ||
maxX = Math.max(maxX, b.x + b.w); | ||
maxY = Math.max(maxY, b.y + b.h); | ||
}); | ||
export function getIBoundFromPoints( | ||
points: IVec[], | ||
rotation = 0 | ||
): IBound & { | ||
maxX: number; | ||
maxY: number; | ||
minX: number; | ||
minY: number; | ||
} { | ||
let minX = Infinity; | ||
let minY = Infinity; | ||
let maxX = -Infinity; | ||
let maxY = -Infinity; | ||
return new Bound(minX, minY, maxX - minX, maxY - minY); | ||
if (points.length < 1) { | ||
minX = 0; | ||
minY = 0; | ||
maxX = 1; | ||
maxY = 1; | ||
} else { | ||
for (const [x, y] of points) { | ||
minX = Math.min(x, minX); | ||
minY = Math.min(y, minY); | ||
maxX = Math.max(x, maxX); | ||
maxY = Math.max(y, maxY); | ||
} | ||
} | ||
if (rotation !== 0) { | ||
return getIBoundFromPoints( | ||
points.map(pt => | ||
Vec.rotWith(pt, [(minX + maxX) / 2, (minY + maxY) / 2], rotation) | ||
) | ||
); | ||
} | ||
return { | ||
minX, | ||
minY, | ||
maxX, | ||
maxY, | ||
x: minX, | ||
y: minY, | ||
w: maxX - minX, | ||
h: maxY - minY, | ||
}; | ||
} | ||
export function getBoundFromPoints(points: IVec[]) { | ||
const { minX, minY, width, height } = getBoundsFromPoints(points); | ||
return new Bound(minX, minY, width, height); | ||
return Bound.from(getIBoundFromPoints(points)); | ||
} | ||
@@ -63,0 +176,0 @@ |
@@ -11,12 +11,2 @@ import type { Bound, IBound } from './model/bound.js'; | ||
interface TLBounds { | ||
minX: number; | ||
minY: number; | ||
maxX: number; | ||
maxY: number; | ||
width: number; | ||
height: number; | ||
rotation?: number; | ||
} | ||
export function randomSeed(): number { | ||
@@ -26,99 +16,2 @@ return Math.floor(Math.random() * 2 ** 31); | ||
export function getBoundsFromPoints(points: IVec[], rotation = 0): TLBounds { | ||
let minX = Infinity; | ||
let minY = Infinity; | ||
let maxX = -Infinity; | ||
let maxY = -Infinity; | ||
if (points.length < 1) { | ||
minX = 0; | ||
minY = 0; | ||
maxX = 1; | ||
maxY = 1; | ||
} else { | ||
for (const [x, y] of points) { | ||
minX = Math.min(x, minX); | ||
minY = Math.min(y, minY); | ||
maxX = Math.max(x, maxX); | ||
maxY = Math.max(y, maxY); | ||
} | ||
} | ||
if (rotation !== 0) { | ||
return getBoundsFromPoints( | ||
points.map(pt => | ||
Vec.rotWith(pt, [(minX + maxX) / 2, (minY + maxY) / 2], rotation) | ||
) | ||
); | ||
} | ||
return { | ||
minX, | ||
minY, | ||
maxX, | ||
maxY, | ||
width: Math.max(1, maxX - minX), | ||
height: Math.max(1, maxY - minY), | ||
}; | ||
} | ||
export function getPointsFromBoundsWithRotation( | ||
bounds: IBound, | ||
getPoints: (bounds: IBound) => IVec[] = ({ x, y, w, h }: IBound) => [ | ||
// left-top | ||
[x, y], | ||
// right-top | ||
[x + w, y], | ||
// right-bottom | ||
[x + w, y + h], | ||
// left-bottom | ||
[x, y + h], | ||
], | ||
resPadding: [number, number] = [0, 0] | ||
): IVec[] { | ||
const { rotate } = bounds; | ||
let points = getPoints({ | ||
x: bounds.x - resPadding[1], | ||
y: bounds.y - resPadding[0], | ||
w: bounds.w + resPadding[1] * 2, | ||
h: bounds.h + resPadding[0] * 2, | ||
}); | ||
if (rotate) { | ||
const { x, y, w, h } = bounds; | ||
const cx = x + w / 2; | ||
const cy = y + h / 2; | ||
const m = new DOMMatrix() | ||
.translateSelf(cx, cy) | ||
.rotateSelf(rotate) | ||
.translateSelf(-cx, -cy); | ||
points = points.map(point => { | ||
const { x, y } = new DOMPoint(...point).matrixTransform(m); | ||
return [x, y]; | ||
}); | ||
} | ||
return points; | ||
} | ||
export function getQuadBoundsWithRotation(bounds: IBound): DOMRect { | ||
const { x, y, w, h, rotate } = bounds; | ||
const rect = new DOMRect(x, y, w, h); | ||
if (!rotate) return rect; | ||
return new DOMQuad( | ||
...getPointsFromBoundsWithRotation(bounds).map( | ||
point => new DOMPoint(...point) | ||
) | ||
).getBounds(); | ||
} | ||
export function getBoundsWithRotation(bounds: IBound): IBound { | ||
const { x, y, width: w, height: h } = getQuadBoundsWithRotation(bounds); | ||
return { x, y, w, h }; | ||
} | ||
export function lineIntersects( | ||
@@ -125,0 +18,0 @@ sp: IVec, |
import type { SerializedXYWH, XYWH } from '../xywh.js'; | ||
import type { IVec } from './vec.js'; | ||
import { | ||
EPSILON, | ||
getBoundsFromPoints, | ||
lineIntersects, | ||
polygonPointDistance, | ||
} from '../math.js'; | ||
import { getIBoundFromPoints } from '../bound.js'; | ||
import { EPSILON, lineIntersects, polygonPointDistance } from '../math.js'; | ||
import { deserializeXYWH, serializeXYWH } from '../xywh.js'; | ||
@@ -160,4 +156,3 @@ | ||
static fromPoints(points: IVec[]) { | ||
const { minX, minY, maxX, maxY } = getBoundsFromPoints(points); | ||
return new Bound(minX, minY, maxX - minX, maxY - minY); | ||
return Bound.from(getIBoundFromPoints(points)); | ||
} | ||
@@ -164,0 +159,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
701942
13817
10925