Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #2

Merged
merged 6 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add types/elements
  • Loading branch information
chenshenhai committed May 26, 2021
commit 53935a884b40247564ddf31a3a35eb21266ae0e0
4 changes: 3 additions & 1 deletion packages/board/src/util/context.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TypeContext } from '@idraw/types';

type Options = {
width: number;
height: number;
Expand All @@ -16,7 +18,7 @@ type PrivateConfig = {
scrollY: number;
}

class Context {
class Context implements TypeContext {
private _opts: Options;
private _ctx: CanvasRenderingContext2D;
private _conf: PrivateConfig;
Expand Down
4 changes: 3 additions & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './lib/data';
export * from './lib/board';
export * from './lib/board';
export * from './lib/paint';
export * from './lib/element';
21 changes: 20 additions & 1 deletion packages/types/src/lib/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ type TypePoint = {
y: number;
}

interface TypeContext {
setConfig(config: {
scale?: number;
scrollX?: number;
scrollY?: number;
}): void;
setFillStyle(color: string): void;
fillRect(x: number, y: number, w: number, h: number): void;
clearRect(x: number, y: number, w: number, h: number): void;
beginPath(): void;
closePath(): void;
lineTo(x: number, y: number): void;
setLineWidth(w: number): void;
isPointInPath(x: number, y: number): boolean;
setStrokeStyle(color: string): void;
stroke(): void;
}

export {
TypePoint
TypePoint,
TypeContext
}
29 changes: 4 additions & 25 deletions packages/types/src/lib/data.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
import { TypeElementsDesc } from './element';


type ElementsDescMap = {
text: {
size: number;
},
rect: {
color: string;
},
circle: {
color: string;
r: number;
x: number;
y: number;
},
image: {
src: number;
},
paint: {

}
}

type TypeDataElement<T extends keyof ElementsDescMap> = {
type TypeDataElement<T extends keyof TypeElementsDesc> = {
uuid?: string;
x: number;
y: number;
w: number;
h: number;
type: T;
desc: ElementsDescMap[T];
desc: TypeElementsDesc[T];
}

type TypeData = {
elements: TypeDataElement<keyof ElementsDescMap>[]
elements: TypeDataElement<keyof TypeElementsDesc>[]
selectedElements?: string[] // uuids
}

Expand Down
37 changes: 37 additions & 0 deletions packages/types/src/lib/element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { TypePaintData } from './paint';

type TypeElementsDesc = {
text: TypeElemDescText,
rect: TypeElemDescRect,
circle: TypeElemDescCircle,
image: TypeElemDescImage,
paint: TypeElemDescPaint
}

type TypeElemDescRect = {
color: string;
}

type TypeElemDescText = {
size: number;
color: number;
}

type TypeElemDescCircle = {
r: number;
x: number;
y: number;
}

type TypeElemDescImage = {
src: number;
}

type TypeElemDescPaint = TypePaintData

export {
TypeElemDescText,
TypeElemDescRect,
TypeElemDescCircle,
TypeElementsDesc,
}
23 changes: 23 additions & 0 deletions packages/types/src/lib/paint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export type TypePaintData = {
brushMap: {[name: string]: TypePaintBrush},
paths: TypePaintPath[],
}

export type TypePaintBrush = {
name: string;
src: string;
}

export type TypePaintPath = {
brush: string,
size: number;
positions: TypePaintPosition[],
color: string;
pressure: number;
}

export type TypePaintPosition = {
x: number,
y: number,
t: number,
}