Skip to content

Commit

Permalink
feat: 工具增加id
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan Heng committed Aug 2, 2023
1 parent 67cfd9c commit 72b2e76
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/tools/drawing-tool.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Konva from 'konva';

import { Tool } from '../types';
import { Point } from '../utils';
import { guid, Point } from '../utils';

import { selectTool } from './select-tool';

export const drawingTool = (): Tool => {
let points: Point[] = [];
const line = new Konva.Line({
id: guid(),
stroke: 'black',
strokeWidth: 2,
globalCompositeOperation: 'source-over',
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/tools/ellipse-tool.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Ellipse } from '../customs/ellipse';
import { AppMouseEvent, Tool } from '../types';
import { Point } from '../utils';
import { guid, Point } from '../utils';

import { selectTool } from './select-tool';

export const ellipseTool = (): Tool => {
const startPointer: Point = new Point(0, 0);
const ellipse: Ellipse = new Ellipse({
id: guid(),
radiusX: 0,
radiusY: 0,
fill: 'transparent',
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/tools/image-tool.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { readeFile, selectFile } from '@pictode/utils';

import { Image as Img } from '../customs/image';
import { Tool } from '../types';
import { guid, readeFile, selectFile } from '../utils';

import { selectTool } from './select-tool';

export const imageTool = (): Tool => {
const imageObject = new Image();
const img = new Img({
id: guid(),
image: imageObject,
stroke: 'black',
strokeWidth: 2,
});

return {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/tools/line-tool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Line } from '../customs/line';
import { Tool } from '../types';
import { Point } from '../utils';
import { guid, Point } from '../utils';

import { selectTool } from './select-tool';

Expand All @@ -10,6 +10,7 @@ const flatPoints = (points: Point[]): number[] =>
export const lineTool = (): Tool => {
let points: Point[] = [];
let line: Line = new Line({
id: guid(),
points: flatPoints(points),
fill: 'transparent',
stroke: 'black',
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/tools/rect-tool.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Rect } from '../customs/rect';
import { AppMouseEvent, Tool } from '../types';
import { Point } from '../utils';
import { guid, Point } from '../utils';

import { selectTool } from './select-tool';

export const rectTool = (): Tool => {
const startPointer: Point = new Point(0, 0);
const rectangle: Rect = new Rect({
id: guid(),
fill: 'transparent',
stroke: 'black',
strokeWidth: 2,
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/tools/regular-polygon-tool.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { RegularPolygon } from '../customs/regular-polygon';
import { Tool } from '../types';
import { Point } from '../utils';
import { guid, Point } from '../utils';

import { selectTool } from './select-tool';

export const regularPolygonTool = (): Tool => {
const startPointer: Point = new Point(0, 0);
const regularPolygon: RegularPolygon = new RegularPolygon({
id: guid(),
fill: 'transparent',
stroke: 'black',
strokeWidth: 2,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { AppConfig } from '../types';

export * from './math';

export { guid, readeFile, selectFile } from '@pictode/utils';

export const DEFAULT_APP_CONFIG: AppConfig = {
backgroundColor: '#ffffff',
};

0 comments on commit 72b2e76

Please sign in to comment.