Skip to content

Commit

Permalink
feat: add core package
Browse files Browse the repository at this point in the history
  • Loading branch information
F-star committed Jan 21, 2024
1 parent 78d36d3 commit 775b4d4
Show file tree
Hide file tree
Showing 127 changed files with 518 additions and 276 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"packages/*"
],
"scripts": {
"dev": "run-p \"watch common\" \"watch icons\" \"watch components\" \"watch geo\" app:dev",
"dev": "run-p \"watch common\" \"watch icons\" \"watch components\" \"watch geo\" \"watch core\" app:dev",
"watch": "node scripts/dev.js",
"app:dev": "pnpm --filter @suika/suika dev",
"app:build": "pnpm --filter @suika/suika build",
Expand Down
14 changes: 14 additions & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
"build": "tsc && vite build"
},
"devDependencies": {
"@types/uuid": "^9.0.2",
"@types/lodash.clonedeep": "^4.5.7",
"@types/lodash.debounce": "^4.0.7",
"@types/lodash.isequal": "^4.5.6",
"@types/lodash.omit": "^4.5.7",
"@types/lodash.throttle": "^4.1.7",
"vite": "^4.2.0"
},
"dependencies": {
"lodash.clonedeep": "^4.5.0",
"lodash.debounce": "^4.0.8",
"lodash.isequal": "^4.5.0",
"lodash.omit": "^4.5.0",
"lodash.throttle": "^4.1.1",
"uuid": "^9.0.0"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export * from './event_emitter';
export * from './common';
export * from './lodash';
export * from './array_util';
export * from './color';
7 changes: 7 additions & 0 deletions packages/common/src/lodash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import cloneDeep from 'lodash.clonedeep';
import debounce from 'lodash.debounce';
import isEqual from 'lodash.isequal';
import omit from 'lodash.omit';
import throttle from 'lodash.throttle';

export { cloneDeep, debounce, isEqual, omit, throttle };
4 changes: 3 additions & 1 deletion packages/common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,

"allowSyntheticDefaultImports": true
},
"include": ["src"]
}
1 change: 1 addition & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
editor core
21 changes: 21 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@suika/core",
"private": true,
"version": "0.0.1",
"type": "module",
"main": "dist/core.es.js",
"module": "dist/core.es.js",
"types": "dist/core.d.ts",
"scripts": {
"build": "tsc && vite build"
},
"devDependencies": {
"@suika/common": "workspace:^",
"@suika/geo": "workspace:^",
"@types/stats.js": "^0.17.3",
"vite": "^4.2.0"
},
"dependencies": {
"stats.js": "^0.17.0"
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Editor } from './editor';
import { noop } from '../utils/common';
import { arrMap } from '../utils/array_util';
import omit from 'lodash.omit';
import { noop, arrMap } from '@suika/common';
import { omit } from '@suika/common';
import { AddShapeCommand } from './commands/add_shape';
import { IEditorPaperData } from '../type';
import { IEditorPaperData } from './type';
import { Graph } from './scene/graph';

/**
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Graph } from '../scene/graph';
import { Editor } from '../editor';
import { ICommand } from './type';

export enum AlignType {
Expand All @@ -19,12 +18,7 @@ export enum AlignType {
export class AlignCmd implements ICommand {
dx: number[] = [];
dy: number[] = [];
constructor(
public desc: string,
private editor: Editor,
private elements: Graph[],
type: AlignType,
) {
constructor(public desc: string, private elements: Graph[], type: AlignType) {
if (elements.length < 2) {
throw new Error('you can not algin zero or one element');
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions packages/core/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export * from './add_shape';
export * from './align';
export * from './command_manager';
export * from './group';
export * from './move_elements';
export * from './remove_element';
export * from './set_elements_attrs';
export * from './type';
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions packages/core/src/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const DOUBLE_PI = Math.PI * 2;

export const HALF_PI = Math.PI / 2;
14 changes: 14 additions & 0 deletions packages/core/src/cursor_manager/cursor.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { normalizeDegree } from '@suika/geo';
import { Editor } from '../editor';
import './cursor.scss';
import isEqual from 'lodash.isequal';
import './cursor.css';
import { isEqual } from '@suika/common';
import { getIconSvgDataUrl } from './util';

export interface ICursorRotation {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
genId,
sceneCoordsToViewportUtil,
viewportCoordsToSceneUtil,
} from '../utils/common';
} from '@suika/common';
import { CommandManager } from './commands/command_manager';
import { HostEventManager } from './host_event_manager';
import Ruler from './ruler';
Expand All @@ -25,7 +25,7 @@ import { GroupManager } from './group_manager';
import { ControlHandleManager } from './scene/control_handle_manager';
import { SelectedBox } from './selected_box';
import { CanvasDragger } from './canvas_dragger';
import { IEditorPaperData } from '../type';
import { IEditorPaperData } from './type';

interface IEditorOptions {
containerElement: HTMLDivElement;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getClosestTimesVal, nearestPixelVal } from '../utils/common';
import { getClosestTimesVal, nearestPixelVal } from '@suika/common';
import { Editor } from './editor';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IObject } from '../../type';
import { genId, objectNameGenerator } from '../../utils/common';
import { IObject } from '../type';
import { genId, objectNameGenerator } from '@suika/common';
import { IGroupAttrs } from './type';

export class Group implements IGroupAttrs {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { IPoint } from '../../type';
import { IPoint } from '../type';
import { EventEmitter } from '@suika/common';
import { Editor } from '../editor';
import { MoveGraphsKeyBinding } from './move_graphs_key_binding';
import { CommandKeyBinding } from './command_key_binding';
import { ICursor } from '../cursor_manager';

interface Events {
shiftToggle(press: boolean): void;
Expand Down Expand Up @@ -32,7 +31,6 @@ export class HostEventManager {
private moveGraphsKeyBinding: MoveGraphsKeyBinding;
private commandKeyBinding: CommandKeyBinding;

private prevCursor: ICursor = 'default';
private eventEmitter = new EventEmitter<Events>();
private unbindHandlers: Array<() => void> = [];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import debounce from 'lodash.debounce';
import { debounce } from '@suika/common';
import { SetElementsAttrs } from '../commands/set_elements_attrs';
import { arrMap } from '../../utils/array_util';
import { Editor } from '../editor';
import { Graph } from '../scene/graph';
import { IPoint } from '../../type';
import { noop } from '../../utils/common';
import { IPoint } from '../type';
import { noop, arrMap } from '@suika/common';

/**
* move graphs by arrow key binding
Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type { SettingValue } from './setting';

export { ArrangeType } from './commands/arrange';

export * from './editor';
export * from './service';
export * from './service';
export * from './texture';
export { Graph, type GraphAttrs } from './scene/graph';
export * from './commands';

export type { IGroupsData } from './group_manager';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isWindows } from '../utils/common';
import { isWindows } from '@suika/common';
import { Editor } from './editor';

interface IKey {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Editor } from './editor';
import { IPoint, IVerticalLine, IHorizontalLine } from '../type';
import { IPoint, IVerticalLine, IHorizontalLine } from './type';
import {
bboxToBbox2,
bboxToBboxWithMid,
isRectIntersect2,
pointsToHLines,
pointsToVLines,
} from '../utils/geo';
import { getClosestValInSortedArr } from '../utils/common';
import { drawLine, drawXShape } from '../utils/canvas';
import { arrMap, forEach } from '../utils/array_util';
} from './utils';
import { arrMap, forEach, getClosestValInSortedArr } from '@suika/common';
import { drawLine, drawXShape } from './utils';

/**
* reference line
Expand Down Expand Up @@ -110,9 +109,9 @@ export class RefLine {
) {
const line = m.get(xOrY);
if (line) {
forEach(xsOrYs, (xOrY) => {
for (const xOrY of xsOrYs) {
line.add(xOrY);
});
}
} else {
m.set(xOrY, new Set(xsOrYs));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HALF_PI } from '../constant';
import { rotateInCanvas } from '../utils/canvas';
import { getClosestTimesVal, nearestPixelVal } from '../utils/common';
import { HALF_PI } from './constant';
import { rotateInCanvas } from './utils';
import { getClosestTimesVal, nearestPixelVal } from '@suika/common';
import { Editor } from './editor';

const getStepByZoom = (zoom: number) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseHexToRGBA } from '../../../utils/color';
import { parseHexToRGBA } from '@suika/common';
import { ITexture, TextureType } from '../../texture';
import { Rect } from '../rect';
import { ControlHandle } from './control_handle';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DOUBLE_PI } from '../../constant';
import { GraphType } from '../../type';
import { rotateInCanvas } from '../../utils/canvas';
import { parseRGBAStr } from '../../utils/color';
import { DOUBLE_PI } from '../constant';
import { GraphType } from '../type';
import { rotateInCanvas } from '../utils';
import { transformRotate } from '@suika/geo';
import { ImgManager } from '../Img_manager';
import { TextureType } from '../texture';
import { Graph, GraphAttrs } from './graph';
import { parseRGBAStr } from '@suika/common';

export type EllipseAttrs = GraphAttrs;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { IBox, IBox2, GraphType, IPoint, IBox2WithRotation } from '../../type';
import { IRect, getResizedRect } from '@suika/geo';
import { calcCoverScale, genId, objectNameGenerator } from '../../utils/common';
import { IBox, IBox2, GraphType, IPoint, IBox2WithRotation } from '../type';
import { IRect, getRectRotatedXY, getResizedRect } from '@suika/geo';
import { calcCoverScale, genId, objectNameGenerator } from '@suika/common';
import { IRectWithRotation, isPointInRect, isRectIntersect } from '@suika/geo';
import {
getAbsoluteCoords,
getRectRotatedXY,
getRectCenterPoint,
} from '../../utils/geo';
drawRoundRectPath,
rotateInCanvas,
} from '../utils';
import { normalizeRadian, isRectContain } from '@suika/geo';
import { transformRotate } from '@suika/geo';
import { DEFAULT_IMAGE, ITexture, TextureImage } from '../texture';
import { ImgManager } from '../Img_manager';
import { HALF_PI } from '../../constant';
import { drawRoundRectPath, rotateInCanvas } from '../../utils/canvas';
import { HALF_PI } from '../constant';
import { ControlHandle } from './control_handle_manager';
import { getResizedLine } from './utils';

Expand Down Expand Up @@ -334,11 +334,11 @@ export class Graph {
}
draw(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
ctx: CanvasRenderingContext2D,
_ctx: CanvasRenderingContext2D,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
imgManager?: ImgManager,
_imgManager?: ImgManager,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
smooth?: boolean,
_smooth?: boolean,
) {
throw new Error('draw Method not implemented.');
}
Expand All @@ -362,7 +362,7 @@ export class Graph {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
strokeTexture(ctx: CanvasRenderingContext2D) {
strokeTexture(_ctx: CanvasRenderingContext2D) {
throw new Error('Method not implemented.');
}
/**
Expand Down Expand Up @@ -500,7 +500,7 @@ export class Graph {
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
getControlHandles(zoom: number, initial?: boolean): ControlHandle[] {
getControlHandles(_zoom: number, _initial?: boolean): ControlHandle[] {
return [];
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GraphType } from '../../type';
import { rotateInCanvas } from '../../utils/canvas';
import { parseRGBAStr } from '../../utils/color';
import { GraphType } from '../type';
import { rotateInCanvas } from '../utils';
import { parseRGBAStr } from '@suika/common';
import { TextureType } from '../texture';
import { Graph, GraphAttrs } from './graph';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GraphType, IBox2WithRotation, IPoint } from '../../type';
import { rotateInCanvas } from '../../utils/canvas';
import { parseHexToRGBA, parseRGBAStr } from '../../utils/color';
import { GraphType, IBox2WithRotation, IPoint } from '../type';
import { rotateInCanvas } from '../utils';
import { parseHexToRGBA, parseRGBAStr } from '@suika/common';
import { ImgManager } from '../Img_manager';
import { TextureType } from '../texture';
import { Graph, GraphAttrs } from './graph';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Editor } from '../editor';
import { GraphType, IEditorPaperData, IObject } from '../../type';
import { GraphType, IEditorPaperData, IObject } from '../type';
import { IRect } from '@suika/geo';
import { EventEmitter } from '@suika/common';
import { isRectIntersect } from '@suika/geo';
import rafThrottle from '../../utils/raf_throttle';
import { rafThrottle } from '../utils';
import { arrMap, forEach } from '@suika/common';
import { Ellipse } from './ellipse';
import { Graph, GraphAttrs } from './graph';
import { Rect } from './rect';
import { arrMap, forEach } from '../../utils/array_util';
import Grid from '../grid';
import { getDevicePixelRatio } from '../../utils/common';
import { getDevicePixelRatio } from '@suika/common';
import { TextGraph } from './text';
import { Line } from './line';

Expand Down
Loading

0 comments on commit 775b4d4

Please sign in to comment.