mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 10:08:34 +00:00
feat: eslint packages code
This commit is contained in:
parent
e0076f654c
commit
c0b40a8b22
21 changed files with 50 additions and 49 deletions
|
|
@ -6,6 +6,7 @@ module.exports = {
|
|||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"semi": "error",
|
||||
"indent": ["error", 2, {
|
||||
"SwitchCase": 1,
|
||||
"VariableDeclarator": 1,
|
||||
|
|
|
|||
|
|
@ -78,15 +78,15 @@ class Board {
|
|||
}
|
||||
|
||||
clear() {
|
||||
this._displayCtx.clearRect(0, 0, this._displayCanvas.width, this._displayCanvas.height)
|
||||
this._displayCtx.clearRect(0, 0, this._displayCanvas.width, this._displayCanvas.height);
|
||||
}
|
||||
|
||||
on<T extends keyof TypeBoardEventArgMap >(name: T, callback: (p: TypeBoardEventArgMap[T]) => void) {
|
||||
this._watcher.on(name, callback)
|
||||
this._watcher.on(name, callback);
|
||||
}
|
||||
|
||||
off<T extends keyof TypeBoardEventArgMap >(name: T, callback: (p: TypeBoardEventArgMap[T]) => void) {
|
||||
this._watcher.off(name, callback)
|
||||
this._watcher.off(name, callback);
|
||||
}
|
||||
|
||||
private _render() {
|
||||
|
|
@ -113,8 +113,8 @@ class Board {
|
|||
private _parsePrivateOptions(opts: Options): PrivateOptions {
|
||||
const defaultOpts = {
|
||||
devicePixelRatio: 1,
|
||||
}
|
||||
return { ...defaultOpts, ...opts }
|
||||
};
|
||||
return { ...defaultOpts, ...opts };
|
||||
}
|
||||
|
||||
private _calculateSize(): { x: number; y: number; w: number; h: number } {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Context implements TypeContext {
|
|||
scale: 1,
|
||||
scrollX: 0,
|
||||
scrollY: 0,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getSize() {
|
||||
|
|
@ -42,7 +42,7 @@ class Context implements TypeContext {
|
|||
width: this._opts.width,
|
||||
height: this._opts.height,
|
||||
devicePixelRatio: this._opts.devicePixelRatio,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
setTransform(config: Transform) {
|
||||
|
|
@ -54,7 +54,7 @@ class Context implements TypeContext {
|
|||
scale: this._transform.scale,
|
||||
scrollX: this._transform.scrollX,
|
||||
scrollY: this._transform.scrollY,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
setFillStyle(color: string) {
|
||||
|
|
@ -132,7 +132,7 @@ class Context implements TypeContext {
|
|||
}
|
||||
|
||||
rotate(angle: number) {
|
||||
return this._ctx.rotate(angle)
|
||||
return this._ctx.rotate(angle);
|
||||
}
|
||||
|
||||
private _doSize(num: number) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { TypePoint } from '@idraw/types'
|
||||
import { TypePoint } from '@idraw/types';
|
||||
|
||||
export interface TypeBoardEventArgMap {
|
||||
'point': TypePoint;
|
||||
|
|
@ -29,7 +29,7 @@ export class BoardEvent implements TypeBoardEvent {
|
|||
if (this._listeners.has(eventKey)) {
|
||||
const callbacks = this._listeners.get(eventKey);
|
||||
callbacks?.push(callback);
|
||||
this._listeners.set(eventKey, callbacks || [])
|
||||
this._listeners.set(eventKey, callbacks || []);
|
||||
} else {
|
||||
this._listeners.set(eventKey, [callback]);
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ export class BoardEvent implements TypeBoardEvent {
|
|||
}
|
||||
}
|
||||
}
|
||||
this._listeners.set(eventKey, callbacks || [])
|
||||
this._listeners.set(eventKey, callbacks || []);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export const mergeCSS2StyleAttr = function(
|
|||
}
|
||||
const styleAttr = cssList.join('; ');
|
||||
return styleAttr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export function setStyle(
|
||||
|
|
@ -23,11 +23,11 @@ export function setStyle(
|
|||
style: {[key: string]: string}
|
||||
): void {
|
||||
const originStyle = getStyle(dom);
|
||||
const _style = {...originStyle, ...style}
|
||||
const _style = {...originStyle, ...style};
|
||||
const keys: string[] = Object.keys(_style);
|
||||
let styleStr = '';
|
||||
keys.forEach((key: string) => {
|
||||
styleStr += `${key}:${_style[key] || ''};`
|
||||
styleStr += `${key}:${_style[key] || ''};`;
|
||||
});
|
||||
dom.setAttribute('style', styleStr);
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ export function getStyle(dom: HTMLElement): {[key: string]: string} {
|
|||
if (dataList[0] && typeof dataList[0] === 'string') {
|
||||
styleObj[dataList[0]] = dataList[1] || '';
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
return styleObj;
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ export function getDomTransform(dom: HTMLElement): {
|
|||
scaleY: matrixList[3] || 1,
|
||||
translateX: matrixList[4] || 0,
|
||||
translateY: matrixList[5] || 0,
|
||||
}
|
||||
};
|
||||
return matrix;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ export class Watcher {
|
|||
}
|
||||
|
||||
on<T extends keyof TypeBoardEventArgMap >(name: T, callback: (p: TypeBoardEventArgMap[T]) => void): void {
|
||||
this._event.on(name, callback)
|
||||
this._event.on(name, callback);
|
||||
}
|
||||
|
||||
off<T extends keyof TypeBoardEventArgMap >(name: T, callback: (p: TypeBoardEventArgMap[T]) => void): void {
|
||||
this._event.off(name, callback)
|
||||
this._event.off(name, callback);
|
||||
}
|
||||
|
||||
_initEvent(): void {
|
||||
|
|
@ -106,7 +106,7 @@ export class Watcher {
|
|||
}
|
||||
|
||||
private _isVaildPoint(p: TypePoint): boolean {
|
||||
return ( p.x > 0 && p.y > 0)
|
||||
return ( p.x > 0 && p.y > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,12 +40,12 @@ export function calcRadian(center: TypePoint, start: TypePoint, end: TypePoint):
|
|||
|
||||
function calcLineAngle(center: TypePoint, p: TypePoint): number | null {
|
||||
const x = p.x - center.x;
|
||||
const y = center.y - p.y
|
||||
const y = center.y - p.y;
|
||||
if (x === 0) {
|
||||
if (y < 0) {
|
||||
return Math.PI / 2
|
||||
return Math.PI / 2;
|
||||
} else if (y > 0) {
|
||||
return Math.PI * ( 3 / 2 )
|
||||
return Math.PI * ( 3 / 2 );
|
||||
}
|
||||
} else if (y === 0) {
|
||||
if (x < 0) {
|
||||
|
|
@ -55,13 +55,13 @@ function calcLineAngle(center: TypePoint, p: TypePoint): number | null {
|
|||
}
|
||||
}
|
||||
if (x > 0 && y < 0) {
|
||||
return Math.atan(Math.abs(y) / Math.abs(x))
|
||||
return Math.atan(Math.abs(y) / Math.abs(x));
|
||||
} else if (x < 0 && y < 0) {
|
||||
return Math.PI - Math.atan(Math.abs(y) / Math.abs(x))
|
||||
return Math.PI - Math.atan(Math.abs(y) / Math.abs(x));
|
||||
} else if (x < 0 && y > 0) {
|
||||
return Math.PI + Math.atan(Math.abs(y) / Math.abs(x))
|
||||
return Math.PI + Math.atan(Math.abs(y) / Math.abs(x));
|
||||
} else if (x > 0 && y > 0) {
|
||||
return Math.PI * 2 - Math.atan(Math.abs(y) / Math.abs(x))
|
||||
return Math.PI * 2 - Math.atan(Math.abs(y) / Math.abs(x));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -7,13 +7,13 @@ const defaultConfig: TypeConfigStrict = {
|
|||
lineWidth: 1,
|
||||
lineDash: [4, 3],
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function mergeConfig(config?: TypeConfig): TypeConfigStrict {
|
||||
const result = defaultConfig;
|
||||
if (config) {
|
||||
if (config.elementWrapper) {
|
||||
result.elementWrapper = {...result.elementWrapper, ...config.elementWrapper}
|
||||
result.elementWrapper = {...result.elementWrapper, ...config.elementWrapper};
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
@ -21,5 +21,5 @@ function mergeConfig(config?: TypeConfig): TypeConfigStrict {
|
|||
|
||||
export {
|
||||
mergeConfig,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ const { isColorStr } = util.color;
|
|||
|
||||
export function drawContext(ctx: TypeContext, data: TypeData, config: TypeHelperConfig): void {
|
||||
const size = ctx.getSize();
|
||||
ctx.clearRect(0, 0, size.width, size.height)
|
||||
ctx.clearRect(0, 0, size.width, size.height);
|
||||
|
||||
if (typeof data.bgColor === 'string' && isColorStr(data.bgColor)) {
|
||||
drawBgColor(ctx, data.bgColor);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ export class Element {
|
|||
isPointInElement(p: TypePoint, data: TypeData): [number, string | null] {
|
||||
const ctx = this._ctx;
|
||||
let idx = -1;
|
||||
let uuid = null
|
||||
let uuid = null;
|
||||
for (let i = data.elements.length - 1; i >= 0; i--) {
|
||||
const ele = data.elements[i];
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export class Helper implements TypeHelper {
|
|||
getElementIndexByUUID(uuid: string): number | null {
|
||||
const index = this._helperConfig.elementIndexMap[uuid];
|
||||
if (index >= 0) {
|
||||
return index
|
||||
return index;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,4 +41,4 @@ function rotateContext(
|
|||
export {
|
||||
rotateContext,
|
||||
rotateElement,
|
||||
}
|
||||
};
|
||||
|
|
@ -24,4 +24,4 @@ export default {
|
|||
uuid: {
|
||||
createUUID
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -7,18 +7,18 @@ export function compose (middleware: Middleware[]): (context: any, next?: Middle
|
|||
|
||||
function dispatch (i: number): Promise<any> {
|
||||
// index = i
|
||||
let fn: Middleware = middleware[i]
|
||||
let fn: Middleware = middleware[i];
|
||||
if (i === middleware.length && next) {
|
||||
fn = next;
|
||||
}
|
||||
if (!fn) return Promise.resolve()
|
||||
if (!fn) return Promise.resolve();
|
||||
try {
|
||||
return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
|
||||
} catch (err) {
|
||||
return Promise.reject(err)
|
||||
return Promise.reject(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ export function delay(time: number): Promise<void> {
|
|||
setTimeout(() => {
|
||||
resolve();
|
||||
}, time);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export function throttle(fn: (...args: any[]) => any, timeout: number): (...args: any[]) => any {
|
||||
|
|
@ -39,7 +39,7 @@ export function throttle(fn: (...args: any[]) => any, timeout: number): (...args
|
|||
timer = setTimeout(() => {
|
||||
fn(...args);
|
||||
timer = -1;
|
||||
}, timeout)
|
||||
}
|
||||
}, timeout);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
class IDraw {
|
||||
render(): void {
|
||||
console.log('hello world')
|
||||
console.log('hello world');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@ type TypePoint = {
|
|||
|
||||
export {
|
||||
TypePoint,
|
||||
}
|
||||
};
|
||||
|
|
@ -19,4 +19,4 @@ type TypeConfigStrict = TypeConfig & {
|
|||
export {
|
||||
TypeConfig,
|
||||
TypeConfigStrict
|
||||
}
|
||||
};
|
||||
|
|
@ -35,4 +35,4 @@ interface TypeContext {
|
|||
|
||||
export {
|
||||
TypeContext
|
||||
}
|
||||
};
|
||||
|
|
@ -7,4 +7,4 @@ type TypeData = {
|
|||
|
||||
export {
|
||||
TypeData
|
||||
}
|
||||
};
|
||||
|
|
@ -47,4 +47,4 @@ export {
|
|||
TypeElemDescCircle,
|
||||
TypeElemDesc,
|
||||
TypeElement,
|
||||
}
|
||||
};
|
||||
|
|
@ -51,4 +51,4 @@ export {
|
|||
TypeHelperConfig,
|
||||
TypeHelperUpdateOpts,
|
||||
TypeHelperWrapperDotDirection,
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue