chore: merge blocksuite source code (#9213)

This commit is contained in:
Mirone
2024-12-20 15:38:06 +08:00
committed by GitHub
parent 2c9ef916f4
commit 30200ff86d
2031 changed files with 238888 additions and 229 deletions
@@ -0,0 +1 @@
export * from './text.js';
@@ -0,0 +1,104 @@
import type { BaseElementProps } from '@blocksuite/block-std/gfx';
import { field, GfxPrimitiveElementModel } from '@blocksuite/block-std/gfx';
import type { IVec, SerializedXYWH } from '@blocksuite/global/utils';
import {
Bound,
getPointsFromBoundWithRotation,
linePolygonIntersects,
pointInPolygon,
polygonNearestPoint,
} from '@blocksuite/global/utils';
import { DocCollection, type Y } from '@blocksuite/store';
import {
type Color,
FontFamily,
FontStyle,
FontWeight,
TextAlign,
type TextStyleProps,
} from '../../consts/index.js';
export type TextElementProps = BaseElementProps & {
text: Y.Text;
hasMaxWidth?: boolean;
} & Omit<TextStyleProps, 'fontWeight' | 'fontStyle'> &
Partial<Pick<TextStyleProps, 'fontWeight' | 'fontStyle'>>;
export class TextElementModel extends GfxPrimitiveElementModel<TextElementProps> {
get type() {
return 'text';
}
static override propsToY(props: Record<string, unknown>) {
if (props.text && !(props.text instanceof DocCollection.Y.Text)) {
props.text = new DocCollection.Y.Text(props.text as string);
}
return props;
}
override containsBound(bounds: Bound): boolean {
const points = getPointsFromBoundWithRotation(this);
return points.some(point => bounds.containsPoint(point));
}
override getLineIntersections(start: IVec, end: IVec) {
const points = getPointsFromBoundWithRotation(this);
return linePolygonIntersects(start, end, points);
}
override getNearestPoint(point: IVec): IVec {
return polygonNearestPoint(
Bound.deserialize(this.xywh).points,
point
) as IVec;
}
override includesPoint(x: number, y: number): boolean {
const points = getPointsFromBoundWithRotation(this);
return pointInPolygon([x, y], points);
}
@field()
accessor color: Color = '#000000';
@field()
accessor fontFamily: FontFamily = FontFamily.Inter;
@field()
accessor fontSize: number = 16;
@field(FontStyle.Normal as FontStyle)
accessor fontStyle: FontStyle = FontStyle.Normal;
@field(FontWeight.Regular as FontWeight)
accessor fontWeight: FontWeight = FontWeight.Regular;
@field(false)
accessor hasMaxWidth: boolean = false;
@field(0)
accessor rotate: number = 0;
@field()
accessor text: Y.Text = new DocCollection.Y.Text();
@field()
accessor textAlign: TextAlign = TextAlign.Center;
@field()
accessor xywh: SerializedXYWH = '[0,0,16,16]';
}
declare global {
namespace BlockSuite {
interface SurfaceElementModelMap {
text: TextElementModel;
}
interface EdgelessTextModelMap {
text: TextElementModel;
}
}
}