diff --git a/docs/todo/core.md b/docs/todo/core.md index 08265ae..05122a3 100644 --- a/docs/todo/core.md +++ b/docs/todo/core.md @@ -1,8 +1,8 @@ # @idraw/core * [x] Can't controll element at scroll-area -* [] Disable controll element -* [] static check/is type declare +* [x] Disable controll element +* [x] static check/is type declare * [x] Force update image/svg image when element change * [x] Reset board's size * [] Keep all num two decimals diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 696bc68..26642aa 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -12,8 +12,8 @@ import { Mapper } from './lib/mapper'; import { mergeConfig } from './lib/config'; import { CoreEvent, TypeCoreEventArgMap } from './lib/core-event'; import { parseData } from './lib/parse'; -import is from './lib/is'; -import check from './lib/check'; +import is, { TypeIs } from './lib/is'; +import check, { TypeCheck } from './lib/check'; import { _board, _data, _opts, _config, _renderer, _element, _helper, _hasInited, _hasInitedData, _mode, _selectedUUID, _prevPoint, _selectedDotDirection, @@ -52,8 +52,8 @@ class Core { private [_selectedDotDirection]: TypeHelperWrapperDotDirection | null = null; private [_onlyRender]: boolean = false; - static is: any = is; - static check: any = check; + static is: TypeIs = is; + static check: TypeCheck = check; constructor(mount: HTMLDivElement, opts: TypeCoreOptions, config?: TypeConfig) { this[_data] = { elements: [] }; diff --git a/packages/core/src/lib/check.ts b/packages/core/src/lib/check.ts index be292ee..4663ff9 100644 --- a/packages/core/src/lib/check.ts +++ b/packages/core/src/lib/check.ts @@ -103,6 +103,17 @@ const check = { svgDesc, textDesc, } - + +type TypeCheck = { + attrs: (value: any) => boolean, + rectDesc: (value: any) => boolean, + imageDesc: (value: any) => boolean, + svgDesc: (value: any) => boolean, + textDesc: (value: any) => boolean, +} + +export { + TypeCheck +} export default check; \ No newline at end of file diff --git a/packages/core/src/lib/is.ts b/packages/core/src/lib/is.ts index 4c65227..4d9dc9f 100644 --- a/packages/core/src/lib/is.ts +++ b/packages/core/src/lib/is.ts @@ -2,6 +2,8 @@ import util from "@idraw/util"; const { isColorStr } = util.color; + + function number(value: any) { return (typeof value === 'number' && (value > 0 || value <= 0)) } @@ -74,11 +76,37 @@ function fontFamily(value: any) { return typeof value === 'string' && value.length > 0; } -const is = { +const is: TypeIs = { x, y, w, h, angle, number, borderWidth, borderRadius, color, imageSrc, imageURL, imageBase64, svg, text, fontSize, lineHeight, textAlign, fontFamily, } -export default is; \ No newline at end of file +type TypeIs = { + x: (value: any) => boolean, + y: (value: any) => boolean, + w: (value: any) => boolean, + h: (value: any) => boolean, + angle: (value: any) => boolean, + number: (value: any) => boolean, + borderWidth: (value: any) => boolean, + borderRadius: (value: any) => boolean, + color: (value: any) => boolean, + imageSrc: (value: any) => boolean, + imageURL: (value: any) => boolean, + imageBase64: (value: any) => boolean, + svg: (value: any) => boolean, + text: (value: any) => boolean, + fontSize: (value: any) => boolean, + lineHeight: (value: any) => boolean, + textAlign: (value: any) => boolean, + fontFamily: (value: any) => boolean, +} + +export default is; + + +export { + TypeIs, +} \ No newline at end of file