@leafer/interface 1.0.0-beta.4 → 1.0.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/interface",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.6",
4
4
  "description": "@leafer/interface",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -15,6 +15,7 @@ import { IZoomView } from '../display/IView'
15
15
  import { IApp } from './IApp'
16
16
  import { ILeaferImage, ILeaferImageConfig } from '../image/ILeaferImage'
17
17
  import { IControl } from '../control/IControl'
18
+ import { IFunction } from '../function/IFunction'
18
19
 
19
20
 
20
21
  export type ILeaferType = 'draw' | 'design' | 'board' | 'document' | 'user'
@@ -32,6 +33,7 @@ export interface ILeafer extends IZoomView, IControl {
32
33
  running: boolean
33
34
  ready: boolean
34
35
  viewReady: boolean
36
+ readonly viewLoaded: boolean
35
37
 
36
38
  pixelRatio: number
37
39
 
@@ -57,8 +59,10 @@ export interface ILeafer extends IZoomView, IControl {
57
59
  __eventIds: IEventListenerId[]
58
60
 
59
61
  init(userConfig?: ILeaferConfig, parentApp?: IApp): void
62
+ setZoomLayer(zoomLayer: ILeaf, moveLayer?: ILeaf): void
60
63
  forceFullRender(): void
61
64
  resize(size: IScreenSizeData): void
65
+ waitViewLoaded(fun: IFunction): void
62
66
  }
63
67
 
64
68
  export interface ILeaferTypeCreator {
@@ -67,6 +67,10 @@ declare var CanvasGradient: {
67
67
  new(): CanvasGradient
68
68
  }
69
69
 
70
+ interface ImageDataSettings {
71
+ colorSpace?: PredefinedColorSpace
72
+ }
73
+
70
74
  interface CanvasImageData {
71
75
  createImageData(sw: number, sh: number, settings?: ImageDataSettings): ImageData
72
76
  createImageData(imagedata: ImageData): ImageData
@@ -117,6 +117,7 @@ interface ICanvasMethod {
117
117
  copyWorld(canvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData, blendMode?: string): void
118
118
  copyWorldToInner(canvas: ILeaferCanvas, fromWorld: IMatrixWithBoundsData, toInnerBounds: IBoundsData, blendMode?: string): void
119
119
  useMask(maskCanvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData): void
120
+ useEraser(eraserCanvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData): void
120
121
 
121
122
  fillWorld(bounds: IBoundsData, color: string | object, blendMode?: string): void
122
123
  strokeWorld(bounds: IBoundsData, color: string | object, blendMode?: string): void
@@ -139,7 +140,10 @@ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
139
140
  pixelRatio: number
140
141
  readonly pixelWidth: number
141
142
  readonly pixelHeight: number
143
+
142
144
  readonly allowBackgroundColor?: boolean
145
+ backgroundColor?: string
146
+ hittable?: boolean
143
147
 
144
148
  bounds: IBounds
145
149
 
@@ -162,14 +166,15 @@ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
162
166
 
163
167
  init(): void
164
168
 
165
- setBackgroundColor(color: string): void
166
- setHittable(hittable: boolean): void
169
+ toBlob(type?: string, quality?: number): Promise<IBlob>
170
+ toDataURL(type?: string, quality?: number): string
171
+ saveAs(filename: string, quality?: number): Promise<boolean>
167
172
 
168
173
  startAutoLayout(autoBounds: IAutoBounds, listener: IResizeEventListener): void
169
174
  stopAutoLayout(): void
170
175
 
171
176
  resize(size: IScreenSizeData): void
172
- setViewSize(size: IScreenSizeData): void
177
+ updateViewSize(): void
173
178
 
174
179
  // other
175
180
  isSameSize(options: ILeaferCanvasConfig): boolean
@@ -182,4 +187,10 @@ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
182
187
  }
183
188
 
184
189
 
185
- export type IHitCanvas = ILeaferCanvas
190
+ export type IHitCanvas = ILeaferCanvas
191
+
192
+ export interface IBlobFunction {
193
+ (blob: IBlob | null): void
194
+ }
195
+
196
+ export type IBlob = any
@@ -0,0 +1,20 @@
1
+ import { IExportFileType, IExportImageType } from '../file/IFileType'
2
+
3
+ export type ICanvasType = 'skia' | 'canvas'
4
+
5
+ export interface ISkiaCanvas {
6
+ toBuffer(format: IExportFileType, config: ISkiaCanvasExportConfig): Promise<any>
7
+ toBufferSync(format: IExportFileType, config: ISkiaCanvasExportConfig): any
8
+ toDataURL(format: IExportImageType, config: ISkiaCanvasExportConfig): Promise<string>
9
+ toDataURLSync(format: IExportImageType, config: ISkiaCanvasExportConfig): string
10
+ saveAs(filename: string, config: ISkiaCanvasExportConfig): Promise<void>
11
+ saveAsSync(filename: string, config: ISkiaCanvasExportConfig): void
12
+ }
13
+
14
+ export interface ISkiaCanvasExportConfig {
15
+ page?: number,
16
+ matte?: string,
17
+ density?: number,
18
+ quality?: number,
19
+ outline?: boolean
20
+ }
@@ -5,6 +5,10 @@ export interface IDataProcessor extends IObject {
5
5
  __leaf: ILeaf
6
6
  __input: IObject
7
7
  __middle: IObject
8
+
9
+ __single: boolean
10
+ __checkSingle(): void
11
+
8
12
  __get(name: string): unknown
9
13
 
10
14
  __setInput(name: string, value: unknown): void
@@ -14,6 +18,7 @@ export interface IDataProcessor extends IObject {
14
18
 
15
19
  __setMiddle(name: string, value: unknown): void
16
20
  __getMiddle(name: string): unknown
21
+
17
22
  destroy(): void
18
23
  }
19
24
 
@@ -1,9 +1,8 @@
1
+ import { ILeaferCanvas } from '../canvas/ILeaferCanvas'
2
+ import { IRenderOptions } from '../renderer/IRenderer'
1
3
  import { ILeaf } from './ILeaf'
2
4
 
3
5
  export interface IBranch extends ILeaf {
4
6
  children: ILeaf[]
5
-
6
- // __updateSortChildren(): void
7
- // add(child: ILeaf, index?: number): void
8
- // remove(child?: ILeaf): void
7
+ __renderBranch?(canvas: ILeaferCanvas, options: IRenderOptions): void
9
8
  }
@@ -35,6 +35,7 @@ export interface ILeafAttrData {
35
35
  opacity: __Number
36
36
  visible: __Boolean
37
37
  isMask: __Boolean
38
+ isEraser?: __Boolean
38
39
  zIndex: __Number
39
40
 
40
41
  // layout data
@@ -100,6 +101,7 @@ export interface ILeafInputData {
100
101
  opacity?: __Number
101
102
  visible?: __Boolean
102
103
  isMask?: __Boolean
104
+ isEraser?: __Boolean
103
105
  zIndex?: __Number
104
106
 
105
107
  // layout data
@@ -131,6 +133,7 @@ export interface ILeafComputedData {
131
133
  opacity?: number
132
134
  visible?: boolean
133
135
  isMask?: boolean
136
+ isEraser?: boolean
134
137
  zIndex?: number
135
138
 
136
139
  // layout data
@@ -195,6 +198,7 @@ export interface ILeaf extends ILeafMask, ILeafRender, ILeafHit, ILeafBounds, IL
195
198
  __tempNumber?: number // 用于临时运算储存状态
196
199
 
197
200
  __hasMask?: boolean
201
+ __hasEraser?: boolean
198
202
  __hitCanvas?: IHitCanvas
199
203
 
200
204
  readonly __onlyHitMask: boolean
@@ -238,6 +242,7 @@ export interface ILeaf extends ILeafMask, ILeafRender, ILeafHit, ILeafBounds, IL
238
242
  __onUpdateSize(): void
239
243
 
240
244
  // IBranchMask ->
245
+ __updateEraser(value?: boolean): void
241
246
  __updateMask(value?: boolean): void
242
247
  __renderMask(canvas: ILeaferCanvas, content: ILeaferCanvas, mask: ILeaferCanvas): void
243
248
  __removeMask(child?: ILeaf): void
@@ -251,6 +256,10 @@ export interface ILeaf extends ILeafMask, ILeafRender, ILeafHit, ILeafBounds, IL
251
256
  worldToInner(world: IPointData, to?: IPointData, isMovePoint?: boolean): void
252
257
  innerToWorld(inner: IPointData, to?: IPointData, isMovePoint?: boolean): void
253
258
 
259
+ move(x: number, y?: number): void
260
+ scaleOf(origin: IPointData, x: number, y?: number): void
261
+ rotateOf(origin: IPointData, rotation: number): void
262
+
254
263
  // ILeafHit ->
255
264
  __hitWorld(point: IRadiusPointData): boolean
256
265
  __hit(local: IRadiusPointData): boolean
@@ -0,0 +1,10 @@
1
+ import { ILeaferCanvas } from '../../canvas/ILeaferCanvas'
2
+ import { IRenderOptions } from '../../renderer/IRenderer'
3
+ import { IBranch } from '../IBranch'
4
+ import { ILeafRender } from './ILeafRender'
5
+
6
+ export type IBranchRenderModule = IBranchRender & ThisType<IBranch>
7
+
8
+ export interface IBranchRender extends ILeafRender {
9
+ __renderBranch?(canvas: ILeaferCanvas, options: IRenderOptions): void
10
+ }
@@ -4,6 +4,7 @@ import { ILeaferCanvas } from '../../canvas/ILeaferCanvas'
4
4
  export type ILeafMaskModule = ILeafMask & ThisType<ILeaf>
5
5
 
6
6
  export interface ILeafMask {
7
+ __updateEraser?(value?: boolean): void
7
8
  __updateMask?(value?: boolean): void
8
9
  __renderMask?(canvas: ILeaferCanvas, content: ILeaferCanvas, mask: ILeaferCanvas): void
9
10
  __removeMask?(child?: ILeaf): void
@@ -5,19 +5,19 @@ import { ILeaf } from '../display/ILeaf'
5
5
  import { IScreenSizeData } from '../math/IMath'
6
6
 
7
7
  export interface IEvent {
8
- type: string
9
- target: IEventTarget
10
- current: IEventTarget
8
+ type?: string
9
+ target?: IEventTarget
10
+ current?: IEventTarget
11
11
 
12
12
  bubbles?: boolean
13
13
  phase?: number
14
14
 
15
- isStopDefault: boolean
16
- isStop: boolean
17
- isStopNow: boolean
18
- stopDefault(): void
19
- stopNow(): void
20
- stop(): void
15
+ isStopDefault?: boolean
16
+ isStop?: boolean
17
+ isStopNow?: boolean
18
+ stopDefault?(): void
19
+ stopNow?(): void
20
+ stop?(): void
21
21
  }
22
22
 
23
23
  export interface IEventTarget extends IEventer {
@@ -32,6 +32,10 @@ export interface IRenderEvent {
32
32
 
33
33
  }
34
34
 
35
+ export interface IAnimateEvent {
36
+
37
+ }
38
+
35
39
  export interface IChildEvent extends IEvent {
36
40
  parent?: ILeaf
37
41
  child?: ILeaf
@@ -7,33 +7,29 @@ export interface IUIEvent extends IEvent {
7
7
  x: number
8
8
  y: number
9
9
 
10
- altKey: boolean
11
- ctrlKey: boolean
12
- shiftKey: boolean
13
- metaKey: boolean
14
- readonly spaceKey: boolean
15
-
16
- readonly left: boolean
17
- readonly right: boolean
18
- readonly middle: boolean
19
- buttons: number
20
-
21
- path: ILeafList
10
+ altKey?: boolean
11
+ ctrlKey?: boolean
12
+ shiftKey?: boolean
13
+ metaKey?: boolean
14
+ readonly spaceKey?: boolean
15
+
16
+ readonly left?: boolean
17
+ readonly right?: boolean
18
+ readonly middle?: boolean
19
+ buttons?: number
20
+
21
+ path?: ILeafList
22
22
  throughPath?: ILeafList // 穿透path,不受层级影响,从上到下只要碰撞到区域就算,一般点击的时候
23
23
 
24
- origin: IObject
25
-
26
- stopDefault(): void
27
- stopNow(): void
28
- stop(): void
24
+ origin?: IObject
29
25
  }
30
26
 
31
27
 
32
28
  export interface IPointerEvent extends IUIEvent {
33
- width: number
34
- height: number
35
- pointerType: PointerType
36
- pressure: number
29
+ width?: number
30
+ height?: number
31
+ pointerType?: PointerType
32
+ pressure?: number
37
33
  tangentialPressure?: number
38
34
  tiltX?: number
39
35
  tiltY?: number
@@ -0,0 +1,2 @@
1
+ export type IExportImageType = 'jpg' | 'png' | 'webp'
2
+ export type IExportFileType = IExportImageType | 'svg' | 'pdf' | 'json'
@@ -1,7 +1,10 @@
1
1
  import { ILeaferImage, ILeaferImageConfig } from './ILeaferImage'
2
-
2
+ import { ITaskProcessor } from '../task/ITaskProcessor'
3
+ import { IFunction } from '../function/IFunction'
3
4
 
4
5
  export interface IImageManager {
6
+ tasker: ITaskProcessor
5
7
  get(config: ILeaferImageConfig): ILeaferImage
8
+ load(image: ILeaferImage, onSuccess: IFunction, onError: IFunction): void
6
9
  destory(): void
7
10
  }
@@ -18,7 +18,7 @@ export interface ILeaferImage {
18
18
  width: number
19
19
  height: number
20
20
  ready: boolean
21
- load(onSuccess?: ILeaferImageOnLoaded, onError?: ILeaferImageOnError): void
21
+ load(onSuccess?: ILeaferImageOnLoaded, onError?: ILeaferImageOnError): Promise<void>
22
22
  getCanvas(width: number, height: number, opacity?: number, _filters?: IObject): unknown
23
23
  }
24
24
 
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ export { ILeafHit, ILeafHitModule } from './display/module/ILeafHit'
15
15
  export { ILeafRender, ILeafRenderModule } from './display/module/ILeafRender'
16
16
  export { ILeafEventer, ILeafEventerModule } from './display/module/ILeafEventer'
17
17
  export { ILeafMask, ILeafMaskModule } from './display/module/ILeafMask'
18
+ export { IBranchRender, IBranchRenderModule } from './display/module/IBranchRender'
18
19
 
19
20
  export { IRenderer, IRendererConfig, IRenderOptions } from './renderer/IRenderer'
20
21
  export { IWatcher, IWatchEventData, IWatcherConfig } from './watcher/IWatcher'
@@ -25,21 +26,25 @@ export { ICanvasManager } from './canvas/ICanvasManager'
25
26
  export { IHitCanvasManager } from './canvas/IHitCanvasManager'
26
27
  export { IImageManager } from './image/IImageManager'
27
28
 
29
+ export { ITaskProcessor, ITaskProcessorConfig } from './task/ITaskProcessor'
30
+
28
31
 
29
32
  export { IControl } from './control/IControl'
30
33
  export { IPlatform } from './platform/IPlatform'
31
34
  export { IPlugin } from './plugin/IPlugin'
32
35
 
33
36
 
34
- export { ILeaferCanvas, IHitCanvas, ICanvasAttr, ICanvasStrokeOptions, ILeaferCanvasConfig, IHitCanvasConfig } from './canvas/ILeaferCanvas'
37
+ export { ILeaferCanvas, IHitCanvas, ICanvasAttr, ICanvasStrokeOptions, ILeaferCanvasConfig, IHitCanvasConfig, IBlobFunction, IBlob } from './canvas/ILeaferCanvas'
38
+ export { ISkiaCanvas, ISkiaCanvasExportConfig, ICanvasType } from './canvas/ISkiaCanvas'
35
39
  export { IPathDrawer, IPathCreator } from './path/IPathDrawer'
36
40
  export { IWindingRule, ICanvasContext2D, ITextMetrics, IPath2D } from './canvas/ICanvas'
37
41
  export { CanvasPathCommand, IPathCommandData, MCommandData, HCommandData, VCommandData, LCommandData, CCommandData, SCommandData, QCommandData, TCommandData, ZCommandData, ACommandData, RectCommandData, RoundRectCommandData, EllipseCommandData, ArcCommandData, ArcToCommandData } from './path/IPathCommand'
38
42
 
39
43
  export { ILeaferImage, ILeaferImageConfig, ILeaferImageOnLoaded, ILeaferImageOnError } from './image/ILeaferImage'
44
+ export { IExportFileType, IExportImageType } from './file/IFileType'
40
45
 
41
46
  export { InnerId, IEventer, IEventListener, IEventListenerOptions, IEventListenerMap, IEventListenerItem, IEventListenerId } from './event/IEventer'
42
- export { IEventTarget, IEvent, ILeaferEvent, IPropertyEvent, ILayoutEvent, IRenderEvent, IChildEvent, IResizeEvent, IResizeEventListener, IUpdateEvent, IWatchEvent, ITransformEvent, ITransformEventData, TransformMode } from './event/IEvent'
47
+ export { IEventTarget, IEvent, ILeaferEvent, IPropertyEvent, ILayoutEvent, IRenderEvent, IAnimateEvent, IChildEvent, IResizeEvent, IResizeEventListener, IUpdateEvent, IWatchEvent, ITransformEvent, ITransformEventData, TransformMode } from './event/IEvent'
43
48
  export { IUIEvent, IPointerEvent, PointerType, IDragEvent, IDropEvent, ISwipeEvent, IMoveEvent, IZoomEvent, IRotateEvent, IKeyEvent, IImageEvent } from './event/IUIEvent'
44
49
  export { IInteraction, IInteractionCanvas, IInteractionConfig, IWheelConfig, IPointerConfig } from './interaction/IInteraction'
45
50
 
@@ -31,6 +31,7 @@ export interface ILeafLayout {
31
31
  // matrix changed
32
32
  matrixChanged: boolean // include positionChanged scaleChanged skewChanged
33
33
  positionChanged: boolean // x, y
34
+ originChanged?: boolean // originX originY
34
35
  scaleChanged: boolean // scaleX scaleY
35
36
  rotationChanged: boolean // rotaiton, skewX scaleY 数据更新
36
37
 
@@ -60,7 +61,7 @@ export interface ILeafLayout {
60
61
  strokeBoxSpread: number
61
62
  renderShapeSpread: number
62
63
 
63
- checkUpdate(): void
64
+ checkUpdate(force?: boolean): void
64
65
 
65
66
  getTransform(locationType: ILayoutLocationType): IMatrixData
66
67
  decomposeTransform(locationType: ILayoutLocationType): IMatrixDecompositionData
package/src/math/IMath.ts CHANGED
@@ -152,16 +152,16 @@ export interface IMatrix extends IMatrixData {
152
152
  translateInner(x: number, y: number): IMatrix
153
153
 
154
154
  scale(x: number, y?: number): IMatrix
155
- scaleOf(center: IPointData, x: number, y?: number): IMatrix
156
- scaleOfInner(center: IPointData, x: number, y?: number): IMatrix
155
+ scaleOfOuter(origin: IPointData, x: number, y?: number): IMatrix
156
+ scaleOfInner(origin: IPointData, x: number, y?: number): IMatrix
157
157
 
158
158
  rotate(angle: number): IMatrix
159
- rotateOf(center: IPointData, angle: number): IMatrix
160
- rotateOfInner(center: IPointData, angle: number): IMatrix
159
+ rotateOfOuter(origin: IPointData, angle: number): IMatrix
160
+ rotateOfInner(origin: IPointData, angle: number): IMatrix
161
161
 
162
162
  skew(x: number, y?: number): IMatrix
163
- skewOf(center: IPointData, x: number, y?: number): IMatrix
164
- skewOfInner(center: IPointData, x: number, y?: number): IMatrix
163
+ skewOfOuter(origin: IPointData, x: number, y?: number): IMatrix
164
+ skewOfInner(origin: IPointData, x: number, y?: number): IMatrix
165
165
 
166
166
  multiply(matrix: IMatrixData): IMatrix
167
167
  divide(matrix: IMatrixData): IMatrix
@@ -1,6 +1,7 @@
1
1
  import { IFunction } from '../function/IFunction'
2
2
  import { ILeaferCanvas } from '../canvas/ILeaferCanvas'
3
3
  import { ILeaf } from '../display/ILeaf'
4
+ import { IExportFileType, IExportImageType } from '../file/IFileType'
4
5
 
5
6
  export interface IPlatform {
6
7
  requestRender?(render: IFunction): void
@@ -11,17 +12,13 @@ export interface IPlatform {
11
12
  conicGradientSupport?: boolean
12
13
  conicGradientRotate90?: boolean // fixfox need rotate
13
14
  fullImageShadow?: boolean // safari need
14
- layout(target: ILeaf): void
15
+ layout?(target: ILeaf): void
16
+ realtimeLayout?: boolean
15
17
  origin?: {
16
- createCanvas: ICreateCanvasFunction,
17
- loadImage: ILoadImageFunction
18
+ createCanvas(width: number, height: number, format?: 'svg' | 'pdf'): any
19
+ canvasToDataURL(canvas: any, type?: IExportImageType, quality?: number): string
20
+ canvasToBolb(canvas: any, type?: IExportFileType, quality?: number): Promise<any>
21
+ canvasSaveAs(canvas: any, filename: string, quality?: number): Promise<void>
22
+ loadImage(url: string): Promise<any>
18
23
  }
19
- }
20
-
21
- interface ICreateCanvasFunction {
22
- (width: number, height: number, format?: 'svg' | 'pdf'): any
23
- }
24
-
25
- interface ILoadImageFunction {
26
- (url: string): Promise<any>
27
24
  }
@@ -0,0 +1,28 @@
1
+ import { IFunction } from '../function/IFunction'
2
+
3
+ export interface ITaskProcessorConfig {
4
+ onComplete?: IFunction
5
+ onTask?: IFunction
6
+ onError?: IFunction
7
+ parallel?: number
8
+ }
9
+
10
+ export interface ITaskProcessor {
11
+ config: ITaskProcessorConfig
12
+ running: boolean
13
+ isComplete: boolean
14
+ percent: number
15
+ total: number
16
+ index: number
17
+ finishedIndex: number
18
+ remain: number
19
+ start(): void
20
+ pause(): void
21
+ resume(): void
22
+ skip(): void
23
+ stop(): void
24
+ add(taskCallback: IFunction, taskTime?: number): void
25
+ addParallel(taskCallback: IFunction, taskTime?: number): void
26
+ addEmpty(callback?: IFunction): void
27
+ destory(): void
28
+ }