diff --git a/docs/todo/core.md b/docs/todo/core.md index 7362726..f769bcd 100644 --- a/docs/todo/core.md +++ b/docs/todo/core.md @@ -1,7 +1,7 @@ # @idraw/core -* [] License text in JS result -* [] Options default data +* [x] License text in JS result +* [x] Options default data * [] Support gradient color * [] Listen keyboard action * [] Keep all num two decimals diff --git a/packages/idraw/src/config.ts b/packages/idraw/src/config.ts new file mode 100644 index 0000000..ac35f84 --- /dev/null +++ b/packages/idraw/src/config.ts @@ -0,0 +1,11 @@ +import { PrivateOptions } from './types'; + +export const defaultOptions: PrivateOptions = { + width: 400, + height: 300, + contextWidth: 400, + contextHeight: 300, + devicePixelRatio: 1, + onlyRender: false, + maxRecords: 10, +} \ No newline at end of file diff --git a/packages/idraw/src/index.ts b/packages/idraw/src/index.ts index 7911c37..2ba8fbc 100644 --- a/packages/idraw/src/index.ts +++ b/packages/idraw/src/index.ts @@ -1,22 +1,9 @@ import Core from '@idraw/core'; import { - TypeData, - TypeCoreOptions, - TypeConfig, + TypeData, TypeConfig, } from '@idraw/types'; - -type Options = { - maxRecords?: number; -} & TypeCoreOptions; - -type PrivateOptions = { - maxRecords: number; -} & Options; - -type Record = { - data: TypeData; - time: number; -} +import { Options, Record, PrivateOptions } from './types'; +import { defaultOptions } from './config'; const _opts = Symbol('_opts'); const _doRecords = Symbol('_doRecords'); @@ -33,12 +20,12 @@ class IDraw extends Core { constructor(mount: HTMLDivElement, opts: Options, config?: TypeConfig) { super(mount, { - width: opts.width, - height: opts.height, - contextWidth: opts.contextWidth, - contextHeight: opts.contextHeight, - devicePixelRatio: opts.devicePixelRatio, - onlyRender: opts.onlyRender + width: opts.width || defaultOptions.width, + height: opts.height || defaultOptions.height, + contextWidth: opts.contextWidth || defaultOptions.contextWidth, + contextHeight: opts.contextHeight || defaultOptions.contextHeight, + devicePixelRatio: opts.devicePixelRatio || defaultOptions.devicePixelRatio, + onlyRender: opts.onlyRender || defaultOptions.onlyRender, }, config || {}); this[_opts] = this._createOpts(opts); this[_initEvent](); @@ -109,10 +96,7 @@ class IDraw extends Core { } private _createOpts(opts: Options): PrivateOptions { - const defaultOpts = { - maxRecords: 10, - }; - return { ...defaultOpts, ...opts }; + return { ...defaultOptions, ...opts }; } } diff --git a/packages/idraw/src/types.ts b/packages/idraw/src/types.ts new file mode 100644 index 0000000..6513c72 --- /dev/null +++ b/packages/idraw/src/types.ts @@ -0,0 +1,17 @@ +import { + TypeData, + TypeCoreOptions, +} from '@idraw/types'; + +export type Options = { + maxRecords?: number; +} & TypeCoreOptions; + +export type PrivateOptions = { + maxRecords: number; +} & Options; + +export type Record = { + data: TypeData; + time: number; +} \ No newline at end of file