@leafer/interface 1.0.0-alpha.7 → 1.0.0-bate

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-alpha.7",
3
+ "version": "1.0.0-bate",
4
4
  "description": "@leafer/interface",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -0,0 +1,6 @@
1
+ import { ILeafer } from './ILeafer'
2
+
3
+ export interface IApp extends ILeafer {
4
+ children: ILeafer[]
5
+ realCanvas: boolean
6
+ }
@@ -2,36 +2,40 @@ import { ILeaf } from '../display/ILeaf'
2
2
  import { IRenderer, IRendererConfig } from '../renderer/IRenderer'
3
3
  import { IHitCanvas, ILeaferCanvas, ILeaferCanvasConfig, IHitCanvasConfig } from '../canvas/ILeaferCanvas'
4
4
  import { ILayouter, ILayouterConfig } from '../layouter/ILayouter'
5
- import { ISelector } from '../selector/ISelector'
6
- import { IInteraction, IInteractionConfig } from '../interaction/IInteraction'
7
- import { IWatcher } from '../watcher/IWatcher'
5
+ import { ISelector, ISelectorConfig } from '../selector/ISelector'
6
+ import { IInteraction, IInteractionCanvas, IInteractionConfig } from '../interaction/IInteraction'
7
+ import { IWatcher, IWatcherConfig } from '../watcher/IWatcher'
8
8
  import { IAutoBounds, IScreenSizeData } from '../math/IMath'
9
9
  import { ICanvasManager } from '../canvas/ICanvasManager'
10
10
  import { IHitCanvasManager } from '../canvas/IHitCanvasManager'
11
11
  import { IImageManager } from '../image/IImageManager'
12
+ import { IEventListenerId } from '../event/IEventer'
12
13
  import { IObject } from '../data/IData'
13
14
  import { IZoomView } from '../display/IView'
14
- import { ISupperLeafer } from './ISupperLeafer'
15
+ import { IApp } from './IApp'
15
16
  import { ILeaferImage, ILeaferImageConfig } from '../image/ILeaferImage'
16
- import { IEvent } from '../event/IEvent'
17
+ import { IControl } from '../control/IControl'
17
18
 
18
19
 
20
+ export type ILeaferType = 'draw' | 'design' | 'board' | 'document' | 'user'
19
21
  export interface ILeaferConfig extends IRendererConfig, ILeaferCanvasConfig, IInteractionConfig, ILayouterConfig {
20
22
  start?: boolean
21
- zoom?: boolean
22
- move?: boolean
23
+ type?: ILeaferType
24
+ realCanvas?: boolean
23
25
  }
24
26
 
25
- export interface ILeafer extends IZoomView {
27
+ export interface ILeafer extends IZoomView, IControl {
26
28
 
27
- creator: ICreator
28
-
29
- readonly isSupperLeafer: boolean
30
- parent?: ISupperLeafer
29
+ readonly isApp: boolean
30
+ parent?: IApp
31
31
 
32
32
  running: boolean
33
+ ready: boolean
34
+ viewReady: boolean
33
35
 
34
- autoLayout?: IAutoBounds
36
+ pixelRatio: number
37
+
38
+ view: unknown
35
39
 
36
40
  canvas: ILeaferCanvas
37
41
  renderer: IRenderer
@@ -46,26 +50,39 @@ export interface ILeafer extends IZoomView {
46
50
  hitCanvasManager?: IHitCanvasManager
47
51
  imageManager: IImageManager
48
52
 
49
- start(): void
50
- stop(): void
53
+ autoLayout?: IAutoBounds
54
+
55
+ config: ILeaferConfig
56
+
57
+ __eventIds: IEventListenerId[]
58
+
59
+ init(userConfig?: ILeaferConfig, parentApp?: IApp): void
60
+
61
+ forceFullRender(): void
51
62
 
52
63
  resize(size: IScreenSizeData): void
53
64
  }
54
65
 
55
- export interface ICreator {
56
- ui?(tag: string, data?: IObject): ILeaf
57
- event?(type: string, event: IEvent): IEvent
66
+ export interface ILeaferTypeFunction {
67
+ (leafer: ILeafer): void
68
+ }
58
69
 
70
+ export interface ILeaferTypeList {
71
+ [key: string]: ILeaferTypeFunction
72
+ }
73
+
74
+
75
+ export interface ICreator {
59
76
  image?(options?: ILeaferImageConfig): ILeaferImage
60
77
  canvas?(options?: ILeaferCanvasConfig, manager?: ICanvasManager): ILeaferCanvas
61
78
  hitCanvas?(options?: IHitCanvasConfig, manager?: ICanvasManager): IHitCanvas
62
79
 
63
- watcher?(target: ILeaf): IWatcher
64
- layouter?(target: ILeaf): ILayouter
65
- renderer?(target: ILeaf, canvas: ILeaferCanvas, options: IRendererConfig): IRenderer
66
- selector?(target: ILeaf): ISelector
80
+ watcher?(target: ILeaf, options?: IWatcherConfig): IWatcher
81
+ layouter?(target: ILeaf, options?: ILayouterConfig): ILayouter
82
+ renderer?(target: ILeaf, canvas: ILeaferCanvas, options?: IRendererConfig): IRenderer
83
+ selector?(target: ILeaf, options?: ISelectorConfig): ISelector
67
84
 
68
- interaction?(target: ILeaf, canvas: ILeaferCanvas, selector: ISelector, options?: IInteractionConfig): IInteraction
85
+ interaction?(target: ILeaf, canvas: IInteractionCanvas, selector: ISelector, options?: IInteractionConfig): IInteraction
69
86
  }
70
87
 
71
88
  export interface IUICreator {
@@ -1,6 +1,6 @@
1
1
  type GlobalCompositeOperation = 'color' | 'color-burn' | 'color-dodge' | 'copy' | 'darken' | 'destination-atop' | 'destination-in' | 'destination-out' | 'destination-over' | 'difference' | 'exclusion' | 'hard-light' | 'hue' | 'lighten' | 'lighter' | 'luminosity' | 'multiply' | 'overlay' | 'saturation' | 'screen' | 'soft-light' | 'source-atop' | 'source-in' | 'source-out' | 'source-over' | 'xor'
2
2
  type CanvasDirection = 'inherit' | 'ltr' | 'rtl'
3
- export type ICanvasFillRule = 'evenodd' | 'nonzero'
3
+ export type IWindingRule = 'evenodd' | 'nonzero'
4
4
  // type CanvasFontKerning = 'auto' | 'none' | 'normal'
5
5
  // type CanvasFontStretch = 'condensed' | 'expanded' | 'extra-condensed' | 'extra-expanded' | 'normal' | 'semi-condensed' | 'semi-expanded' | 'ultra-condensed' | 'ultra-expanded'
6
6
  // type CanvasFontVariantCaps = 'all-petite-caps' | 'all-small-caps' | 'normal' | 'petite-caps' | 'small-caps' | 'titling-caps' | 'unicase'
@@ -10,9 +10,7 @@ type CanvasTextAlign = 'center' | 'end' | 'left' | 'right' | 'start'
10
10
  type CanvasTextBaseline = 'alphabetic' | 'bottom' | 'hanging' | 'ideographic' | 'middle' | 'top'
11
11
  //type CanvasTextRendering = 'auto' | 'geometricPrecision' | 'optimizeLegibility' | 'optimizeSpeed'
12
12
 
13
- /** This Canvas 2D API interface is used to declare a path that can then be used on a CanvasRenderingContext2D object. The path methods of the CanvasRenderingContext2D interface are also present on this interface, which gives you the convenience of being able to retain and replay your path whenever desired. */
14
13
  export interface IPath2D extends CanvasPath {
15
- /** Adds to the path the path given by the argument. */
16
14
  addPath(path: IPath2D, transform?: DOMMatrix2DInit): void
17
15
  }
18
16
 
@@ -35,12 +33,12 @@ interface CanvasDrawImage {
35
33
 
36
34
  interface CanvasDrawPath {
37
35
  beginPath(): void
38
- clip(fillRule?: ICanvasFillRule): void
39
- clip(path: IPath2D, fillRule?: ICanvasFillRule): void
40
- fill(fillRule?: ICanvasFillRule): void
41
- fill(path: IPath2D, fillRule?: ICanvasFillRule): void
42
- isPointInPath(x: number, y: number, fillRule?: ICanvasFillRule): boolean
43
- isPointInPath(path: IPath2D, x: number, y: number, fillRule?: ICanvasFillRule): boolean
36
+ clip(fillRule?: IWindingRule): void
37
+ clip(path: IPath2D, fillRule?: IWindingRule): void
38
+ fill(fillRule?: IWindingRule): void
39
+ fill(path: IPath2D, fillRule?: IWindingRule): void
40
+ isPointInPath(x: number, y: number, fillRule?: IWindingRule): boolean
41
+ isPointInPath(path: IPath2D, x: number, y: number, fillRule?: IWindingRule): boolean
44
42
  isPointInStroke(x: number, y: number): boolean
45
43
  isPointInStroke(path: IPath2D, x: number, y: number): boolean
46
44
  stroke(): void
@@ -60,13 +58,7 @@ interface CanvasFilters {
60
58
  filter: string
61
59
  }
62
60
 
63
- /** An opaque object describing a gradient. It is returned by the methods CanvasRenderingContext2D.createLinearGradient() or CanvasRenderingContext2D.createRadialGradient(). */
64
61
  export interface CanvasGradient {
65
- /**
66
- * Adds a color stop with the given color to the gradient at the given offset. 0.0 is the offset at one end of the gradient, 1.0 is the offset at the other end.
67
- *
68
- * Throws an 'IndexSizeError' DOMException if the offset is out of range. Throws a 'SyntaxError' DOMException if the color cannot be parsed.
69
- */
70
62
  addColorStop(offset: number, color: string): void
71
63
  }
72
64
 
@@ -89,11 +81,11 @@ interface CanvasImageSmoothing {
89
81
  }
90
82
 
91
83
  interface CanvasPath {
92
- arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void
84
+ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void
93
85
  arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
94
86
  bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void
95
87
  closePath(): void
96
- ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void
88
+ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void
97
89
  lineTo(x: number, y: number): void
98
90
  moveTo(x: number, y: number): void
99
91
  quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
@@ -111,9 +103,7 @@ interface CanvasPathDrawingStyles {
111
103
  setLineDash(segments: number[]): void
112
104
  }
113
105
 
114
- /** An opaque object describing a pattern, based on an image, a canvas, or a video, created by the CanvasRenderingContext2D.createPattern() method. */
115
106
  export interface CanvasPattern {
116
- /** Sets the transformation matrix that will be used when rendering the pattern during a fill or stroke painting operation. */
117
107
  setTransform(transform?: DOMMatrix2DInit): void
118
108
  }
119
109
 
@@ -135,16 +125,14 @@ interface CanvasRenderingContext2DSettings {
135
125
  desynchronized?: boolean
136
126
  willReadFrequently?: boolean
137
127
  }
138
-
139
- /** The CanvasRenderingContext2D interface, part of the Canvas API, provides the 2D rendering context for the drawing surface of a <canvas> element. It is used for drawing shapes, text, images, and other objects. */
140
- export interface ICanvasRenderingContext2D extends CanvasCompositing, CanvasDrawImage, CanvasDrawPath, CanvasFillStrokeStyles, CanvasFilters, CanvasImageData, CanvasImageSmoothing, CanvasPath, CanvasPathDrawingStyles, CanvasRect, CanvasShadowStyles, CanvasState, CanvasText, CanvasTextDrawingStyles, CanvasTransform, CanvasUserInterface {
128
+ export interface ICanvasContext2D extends CanvasCompositing, CanvasDrawImage, CanvasDrawPath, CanvasFillStrokeStyles, CanvasFilters, CanvasImageData, CanvasImageSmoothing, CanvasPath, CanvasPathDrawingStyles, CanvasRect, CanvasShadowStyles, CanvasState, CanvasText, CanvasTextDrawingStyles, CanvasTransform, CanvasUserInterface {
141
129
  readonly canvas: HTMLCanvasElement
142
130
  getContextAttributes(): CanvasRenderingContext2DSettings
143
131
  }
144
132
 
145
- declare var ICanvasRenderingContext2D: {
146
- prototype: ICanvasRenderingContext2D
147
- new(): ICanvasRenderingContext2D
133
+ declare var ICanvasContext2D: {
134
+ prototype: ICanvasContext2D
135
+ new(): ICanvasContext2D
148
136
  }
149
137
 
150
138
  interface CanvasShadowStyles {
@@ -165,7 +153,6 @@ interface CanvasUserInterface {
165
153
  }
166
154
 
167
155
 
168
- /** The dimensions of a piece of text in the canvas, as created by the CanvasRenderingContext2D.measureText() method. */
169
156
  export interface ITextMetrics {
170
157
  /** Returns the measurement described below. */
171
158
  readonly actualBoundingBoxAscent: number
@@ -277,7 +264,6 @@ interface DOMMatrixReadOnly {
277
264
  rotateFromVector(x?: number, y?: number): DOMMatrix
278
265
  scale(scaleX?: number, scaleY?: number, scaleZ?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix
279
266
  scale3d(scale?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix
280
- /** @deprecated */
281
267
  scaleNonUniform(scaleX?: number, scaleY?: number): DOMMatrix
282
268
  skewX(sx?: number): DOMMatrix
283
269
  skewY(sy?: number): DOMMatrix
@@ -1,19 +1,18 @@
1
1
  import { IObject } from '../data/IData'
2
2
  import { IBounds, IMatrixData, IBoundsData, IAutoBoundsData, IAutoBounds, IScreenSizeData, IMatrixWithBoundsData, IPointData } from '../math/IMath'
3
- import { ICanvasRenderingContext2D, ICanvasFillRule, IPath2D, ITextMetrics, CanvasGradient, CanvasPattern } from './ICanvas'
3
+ import { ICanvasContext2D, IWindingRule, IPath2D, ITextMetrics, CanvasGradient, CanvasPattern } from './ICanvas'
4
4
  import { IResizeEventListener } from '../event/IEvent'
5
- import { ICanvasDrawPath } from './ICanvasPathDrawer'
5
+ import { IPathDrawer } from '../path/IPathDrawer'
6
6
  import { InnerId } from '../event/IEventer'
7
7
  import { ICanvasManager } from './ICanvasManager'
8
8
 
9
- export interface ILeaferCanvasContext extends ICanvasRenderingContext2D {
10
-
11
- }
12
-
13
9
  export interface ILeaferCanvasConfig extends IAutoBoundsData {
14
10
  view?: string | IObject
15
11
  fill?: string
16
12
  pixelRatio?: number
13
+ smooth?: boolean
14
+ hittable?: boolean
15
+ offscreen?: boolean
17
16
  webgl?: boolean
18
17
  }
19
18
 
@@ -30,7 +29,7 @@ export interface ICanvasStrokeOptions {
30
29
  miterLimit?: number
31
30
  }
32
31
 
33
- export interface ICanvasAttr extends ICanvasStrokeOptions {
32
+ export interface ICanvasAttr extends ICanvasStrokeOptions, IObject {
34
33
 
35
34
  smooth: boolean // imageSmoothingEnabled: boolean
36
35
  smoothLevel: string // imageSmoothingQuality: string
@@ -67,14 +66,15 @@ interface ICanvasMethod {
67
66
  save(): void
68
67
  restore(): void
69
68
 
70
- fill(path?: IPath2D | ICanvasFillRule, rule?: ICanvasFillRule): void
69
+ fill(path?: IPath2D | IWindingRule, rule?: IWindingRule): void
71
70
  stroke(path?: IPath2D): void
72
- clip(path?: IPath2D | ICanvasFillRule, rule?: ICanvasFillRule): void
71
+ clip(path?: IPath2D | IWindingRule, rule?: IWindingRule): void
73
72
 
74
73
  fillRect(x: number, y: number, width: number, height: number): void
75
74
  strokeRect(x: number, y: number, width: number, height: number): void
76
75
  clearRect(x: number, y: number, width: number, height: number): void
77
76
 
77
+ transform(a: number, b: number, c: number, d: number, e: number, f: number): void
78
78
  translate(x: number, y: number): void
79
79
  scale(x: number, y: number): void
80
80
  rotate(angle: number): void
@@ -100,32 +100,38 @@ interface ICanvasMethod {
100
100
 
101
101
  // custom
102
102
 
103
- setStroke(strokeStyle: string | object, strokeWidth: number, options?: ICanvasStrokeOptions): void
104
- setShadow(x: number, y: number, blur: number, color?: string): void
105
- setBlur(blur: number): void
103
+ saveBlendMode(blendMode?: string): void
104
+ restoreBlendMode(): void
106
105
 
106
+ hitFill(point: IPointData, fillRule?: string): boolean
107
+ hitStroke(point: IPointData, strokeWidth?: number): boolean
108
+
109
+ setStroke(strokeStyle: string | object, strokeWidth: number, options?: ICanvasStrokeOptions): void
110
+ setStrokeOptions(options: ICanvasStrokeOptions): void
107
111
 
108
112
  setWorld(matrix: IMatrixData, parentMatrix?: IMatrixData): void
109
113
 
114
+ setWorldShadow(x: number, y: number, blur: number, color?: string): void
115
+ setWorldBlur(blur: number): void
116
+
117
+ copyWorld(canvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData, blendMode?: string): void
118
+ copyWorldToInner(canvas: ILeaferCanvas, fromWorld: IMatrixWithBoundsData, toInnerBounds: IBoundsData, blendMode?: string): void
119
+ useMask(maskCanvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData): void
110
120
 
111
- hitPath(point: IPointData, fillRule?: string): boolean
112
- hitStroke(point: IPointData): boolean
121
+ fillWorld(bounds: IBoundsData, color: string | object, blendMode?: string): void
122
+ strokeWorld(bounds: IBoundsData, color: string | object, blendMode?: string): void
123
+ clipWorld(bounds: IBoundsData, ceilPixel?: boolean): void
124
+ clearWorld(bounds: IBoundsData, ceilPixel?: boolean): void
113
125
 
114
- replaceBy(canvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData): void
115
- copy(canvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData, blendMode?: string): void
116
- copyWorldToLocal(canvas: ILeaferCanvas, fromWorld: IMatrixWithBoundsData, toLocalBounds: IBoundsData, blendMode?: string): void
117
- fillBounds(bounds: IBoundsData, color: string | object, blendMode?: string): void
118
- strokeBounds(bounds: IBoundsData, color: string | object, blendMode?: string): void
119
- clipBounds(bounds: IBoundsData): void
120
- clearBounds(bounds: IBoundsData): void
121
126
  clear(): void
122
127
  }
123
128
 
124
- export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, ICanvasDrawPath {
125
-
126
- manager: ICanvasManager
129
+ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, IPathDrawer {
127
130
 
128
131
  readonly innerId: InnerId
132
+ name: string
133
+
134
+ manager: ICanvasManager
129
135
 
130
136
  width: number
131
137
  height: number
@@ -133,29 +139,45 @@ export interface ILeaferCanvas extends ICanvasAttr, ICanvasMethod, ICanvasDrawPa
133
139
  pixelRatio: number
134
140
  readonly pixelWidth: number
135
141
  readonly pixelHeight: number
142
+ readonly allowBackgroundColor?: boolean
136
143
 
137
144
  bounds: IBounds
138
145
 
146
+ config: ILeaferCanvasConfig
147
+
148
+ autoLayout: boolean
149
+
139
150
  view: unknown
140
- context: ILeaferCanvasContext
151
+ parentView: unknown
152
+
153
+ unreal?: boolean
154
+
155
+ offscreen: boolean
156
+
157
+ context: ICanvasContext2D
141
158
 
142
159
  recycled?: boolean
143
160
 
144
- debug(): void
161
+ worldTransform: IMatrixData
162
+
163
+ init(): void
164
+
165
+ setBackgroundColor(color: string): void
166
+ setHittable(hittable: boolean): void
145
167
 
146
- autoLayout(autoBounds: IAutoBounds, listener: IResizeEventListener): void
168
+ startAutoLayout(autoBounds: IAutoBounds, listener: IResizeEventListener): void
147
169
  stopAutoLayout(): void
148
170
 
149
171
  resize(size: IScreenSizeData): void
150
- pixel(num: number): number
172
+ setViewSize(size: IScreenSizeData): void
151
173
 
152
174
  // other
153
175
  isSameSize(options: ILeaferCanvasConfig): boolean
154
- getSameCanvas(useSameTransform?: boolean): ILeaferCanvas
176
+ getSameCanvas(useSameWorldTransform?: boolean): ILeaferCanvas
155
177
  getBiggerCanvas(addWidth: number, addHeight: number): ILeaferCanvas
156
- useSameTransform(canvas: ILeaferCanvas): void
157
178
  recycle(): void
158
179
 
180
+ unrealCanvas(): void
159
181
  destroy(): void
160
182
  }
161
183
 
@@ -0,0 +1,5 @@
1
+ export interface IControl {
2
+ start(): void
3
+ stop(): void
4
+ destroy(): void
5
+ }
package/src/data/IData.ts CHANGED
@@ -3,8 +3,7 @@ export type __Boolean = boolean // boolean | string will convert to boolean
3
3
  export type __String = string // string | other will convert to string
4
4
  export type __Object = IObject // will convert to object
5
5
  export type __Value = __Number | __Boolean | __String | __Object //
6
-
7
-
6
+ export type ITimer = any
8
7
  export interface IObject {
9
8
  [name: string]: any
10
9
  }
@@ -5,8 +5,13 @@ export interface IDataProcessor extends IObject {
5
5
  __leaf: ILeaf
6
6
  __input: IObject
7
7
  __middle: IObject
8
+ __get(name: string): unknown
9
+
8
10
  __setInput(name: string, value: unknown): void
9
11
  __getInput(name: string): unknown
12
+ __removeInput(name: string): void
13
+ __getInputData(): IObject
14
+
10
15
  __setMiddle(name: string, value: unknown): void
11
16
  __getMiddle(name: string): unknown
12
17
  destroy(): void
@@ -3,7 +3,7 @@ import { ILeaf } from './ILeaf'
3
3
  export interface IBranch extends ILeaf {
4
4
  children: ILeaf[]
5
5
 
6
- __updateSortChildren(): void
7
- add(child: ILeaf, index?: number): void
8
- remove(child?: ILeaf): void
6
+ // __updateSortChildren(): void
7
+ // add(child: ILeaf, index?: number): void
8
+ // remove(child?: ILeaf): void
9
9
  }