@leafer/canvas 1.0.0-rc.8 → 1.0.0
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 +9 -9
- package/src/Canvas.ts +0 -3
- package/src/CanvasManager.ts +1 -4
- package/src/LeaferCanvasBase.ts +64 -111
- package/src/index.ts +0 -1
- package/types/index.d.ts +18 -27
- package/src/HitCanvasManager.ts +0 -48
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/canvas",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "@leafer/canvas",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/file": "1.0.0
|
|
26
|
-
"@leafer/list": "1.0.0
|
|
27
|
-
"@leafer/math": "1.0.0
|
|
28
|
-
"@leafer/data": "1.0.0
|
|
29
|
-
"@leafer/path": "1.0.0
|
|
30
|
-
"@leafer/debug": "1.0.0
|
|
31
|
-
"@leafer/platform": "1.0.0
|
|
25
|
+
"@leafer/file": "1.0.0",
|
|
26
|
+
"@leafer/list": "1.0.0",
|
|
27
|
+
"@leafer/math": "1.0.0",
|
|
28
|
+
"@leafer/data": "1.0.0",
|
|
29
|
+
"@leafer/path": "1.0.0",
|
|
30
|
+
"@leafer/debug": "1.0.0",
|
|
31
|
+
"@leafer/platform": "1.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@leafer/interface": "1.0.0
|
|
34
|
+
"@leafer/interface": "1.0.0"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/Canvas.ts
CHANGED
package/src/CanvasManager.ts
CHANGED
package/src/LeaferCanvasBase.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { IBounds, ILeaferCanvas, ICanvasStrokeOptions, ILeaferCanvasConfig, IMatrixData, IBoundsData, IAutoBounds, IScreenSizeData, IResizeEventListener, IMatrixWithBoundsData, IPointData, InnerId, ICanvasManager, IWindingRule, IBlendMode, IExportImageType, IExportFileType, IBlob, ICursorType } from '@leafer/interface'
|
|
2
|
-
import { Bounds, BoundsHelper, IncrementId } from '@leafer/math'
|
|
1
|
+
import { IBounds, ILeaferCanvas, ICanvasStrokeOptions, ILeaferCanvasConfig, IExportOptions, IMatrixData, IBoundsData, IAutoBounds, IScreenSizeData, IResizeEventListener, IMatrixWithBoundsData, IPointData, InnerId, ICanvasManager, IWindingRule, IBlendMode, IExportImageType, IExportFileType, IBlob, ICursorType, ILeaferCanvasView, IRadiusPointData } from '@leafer/interface'
|
|
2
|
+
import { Bounds, tempBounds, BoundsHelper, MatrixHelper, IncrementId } from '@leafer/math'
|
|
3
3
|
import { Creator, Platform } from '@leafer/platform'
|
|
4
4
|
import { DataHelper } from '@leafer/data'
|
|
5
|
-
import { FileHelper } from '@leafer/file'
|
|
6
|
-
import { Debug } from '@leafer/debug'
|
|
7
5
|
|
|
8
6
|
import { Canvas } from './Canvas'
|
|
9
7
|
|
|
10
8
|
|
|
11
|
-
const
|
|
9
|
+
const { copy } = MatrixHelper
|
|
12
10
|
const minSize: IScreenSizeData = { width: 1, height: 1, pixelRatio: 1 }
|
|
13
|
-
const debug = Debug.get('LeaferCanvasBase')
|
|
14
11
|
|
|
15
12
|
export const canvasSizeAttrs = ['width', 'height', 'pixelRatio']
|
|
16
13
|
|
|
@@ -22,7 +19,12 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
22
19
|
|
|
23
20
|
public manager: ICanvasManager
|
|
24
21
|
|
|
25
|
-
public
|
|
22
|
+
public size: IScreenSizeData = {} as IScreenSizeData
|
|
23
|
+
|
|
24
|
+
public get width(): number { return this.size.width }
|
|
25
|
+
public get height(): number { return this.size.height }
|
|
26
|
+
|
|
27
|
+
public get pixelRatio(): number { return this.size.pixelRatio }
|
|
26
28
|
public get pixelWidth(): number { return this.width * this.pixelRatio }
|
|
27
29
|
public get pixelHeight(): number { return this.height * this.pixelRatio }
|
|
28
30
|
|
|
@@ -35,7 +37,7 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
35
37
|
|
|
36
38
|
public autoLayout: boolean
|
|
37
39
|
|
|
38
|
-
public view:
|
|
40
|
+
public view: ILeaferCanvasView
|
|
39
41
|
public parentView: any
|
|
40
42
|
|
|
41
43
|
public unreal?: boolean
|
|
@@ -57,7 +59,7 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
57
59
|
const { width, height, pixelRatio } = config
|
|
58
60
|
this.autoLayout = !width || !height
|
|
59
61
|
|
|
60
|
-
this.pixelRatio = pixelRatio
|
|
62
|
+
this.size.pixelRatio = pixelRatio
|
|
61
63
|
this.config = config
|
|
62
64
|
|
|
63
65
|
this.init()
|
|
@@ -66,52 +68,23 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
66
68
|
public init(): void { }
|
|
67
69
|
|
|
68
70
|
public __createContext(): void {
|
|
69
|
-
|
|
71
|
+
const { view } = this
|
|
72
|
+
const { contextSettings } = this.config
|
|
73
|
+
this.context = contextSettings ? view.getContext('2d', contextSettings) : view.getContext('2d')
|
|
70
74
|
this.__bindContext()
|
|
71
75
|
}
|
|
72
76
|
|
|
73
|
-
|
|
74
|
-
return new Promise((resolve) => {
|
|
75
|
-
const canvas = this.getSaveCanvas(type)
|
|
76
|
-
Platform.origin.canvasToBolb(canvas.view, type, quality).then((blob) => {
|
|
77
|
-
canvas.recycle()
|
|
78
|
-
resolve(blob)
|
|
79
|
-
}).catch((e) => {
|
|
80
|
-
debug.error(e)
|
|
81
|
-
resolve(null)
|
|
82
|
-
})
|
|
83
|
-
})
|
|
84
|
-
}
|
|
77
|
+
// @leafer-ui/export rewrite
|
|
85
78
|
|
|
86
|
-
public
|
|
87
|
-
const canvas = this.getSaveCanvas(type)
|
|
88
|
-
const data = Platform.origin.canvasToDataURL(canvas.view, type, quality)
|
|
89
|
-
canvas.recycle()
|
|
90
|
-
return data
|
|
91
|
-
}
|
|
79
|
+
public export(_filename: IExportFileType | string, _options?: IExportOptions | number | boolean): string | Promise<any> { return undefined }
|
|
92
80
|
|
|
93
|
-
public
|
|
94
|
-
return new Promise((resolve) => {
|
|
95
|
-
const canvas = this.getSaveCanvas(FileHelper.fileType(filename))
|
|
96
|
-
Platform.origin.canvasSaveAs(canvas.view, filename, quality).then(() => {
|
|
97
|
-
canvas.recycle()
|
|
98
|
-
resolve(true)
|
|
99
|
-
}).catch((e) => {
|
|
100
|
-
debug.error(e)
|
|
101
|
-
resolve(false)
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
}
|
|
81
|
+
public toBlob(_type?: IExportFileType, _quality?: number): Promise<IBlob> { return undefined }
|
|
105
82
|
|
|
106
|
-
public
|
|
107
|
-
const { backgroundColor, bounds } = this as ILeaferCanvas
|
|
108
|
-
const canvas = this.getSameCanvas()
|
|
109
|
-
if (['jpg', 'jpeg'].includes(type)) canvas.fillWorld(bounds, '#FFFFFF')
|
|
110
|
-
if (backgroundColor) canvas.fillWorld(bounds, backgroundColor)
|
|
111
|
-
canvas.copyWorld(this)
|
|
112
|
-
return canvas
|
|
113
|
-
}
|
|
83
|
+
public toDataURL(_type?: IExportImageType, _quality?: number): string | Promise<string> { return undefined }
|
|
114
84
|
|
|
85
|
+
public saveAs(_filename: string, _quality?: number): Promise<boolean> { return undefined }
|
|
86
|
+
|
|
87
|
+
// ---
|
|
115
88
|
|
|
116
89
|
public resize(size: IScreenSizeData): void {
|
|
117
90
|
if (this.isSameSize(size)) return
|
|
@@ -122,9 +95,10 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
122
95
|
takeCanvas.copyWorld(this)
|
|
123
96
|
}
|
|
124
97
|
|
|
125
|
-
DataHelper.copyAttrs(this, size, canvasSizeAttrs)
|
|
98
|
+
DataHelper.copyAttrs(this.size, size, canvasSizeAttrs)
|
|
99
|
+
this.size.pixelRatio || (this.size.pixelRatio = 1)
|
|
100
|
+
|
|
126
101
|
this.bounds = new Bounds(0, 0, this.width, this.height)
|
|
127
|
-
this.pixelRatio || (this.pixelRatio = 1)
|
|
128
102
|
|
|
129
103
|
if (!this.unreal) {
|
|
130
104
|
this.updateViewSize()
|
|
@@ -142,37 +116,30 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
142
116
|
|
|
143
117
|
public updateViewSize(): void { }
|
|
144
118
|
public updateClientBounds(): void { }
|
|
119
|
+
public getClientBounds(update?: boolean): IBoundsData {
|
|
120
|
+
if (update) this.updateClientBounds()
|
|
121
|
+
return this.clientBounds || this.bounds
|
|
122
|
+
}
|
|
145
123
|
|
|
146
124
|
public startAutoLayout(_autoBounds: IAutoBounds, _listener: IResizeEventListener): void { }
|
|
147
125
|
public stopAutoLayout(): void { }
|
|
148
126
|
|
|
149
127
|
public setCursor(_cursor: ICursorType | ICursorType[]): void { }
|
|
150
128
|
|
|
151
|
-
public setWorld(matrix: IMatrixData, parentMatrix?: IMatrixData
|
|
129
|
+
public setWorld(matrix: IMatrixData, parentMatrix?: IMatrixData): void {
|
|
152
130
|
const { pixelRatio } = this
|
|
153
131
|
const w = this.worldTransform
|
|
154
132
|
if (parentMatrix) {
|
|
155
133
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
} else {
|
|
166
|
-
const { a, b, c, d, e, f } = parentMatrix
|
|
167
|
-
this.setTransform(
|
|
168
|
-
w.a = ((matrix.a * a) + (matrix.b * c)) * pixelRatio,
|
|
169
|
-
w.b = ((matrix.a * b) + (matrix.b * d)) * pixelRatio,
|
|
170
|
-
w.c = ((matrix.c * a) + (matrix.d * c)) * pixelRatio,
|
|
171
|
-
w.d = ((matrix.c * b) + (matrix.d * d)) * pixelRatio,
|
|
172
|
-
w.e = (((matrix.e * a) + (matrix.f * c) + e)) * pixelRatio,
|
|
173
|
-
w.f = (((matrix.e * b) + (matrix.f * d) + f)) * pixelRatio
|
|
174
|
-
)
|
|
175
|
-
}
|
|
134
|
+
const { a, b, c, d, e, f } = parentMatrix
|
|
135
|
+
this.setTransform(
|
|
136
|
+
w.a = ((matrix.a * a) + (matrix.b * c)) * pixelRatio,
|
|
137
|
+
w.b = ((matrix.a * b) + (matrix.b * d)) * pixelRatio,
|
|
138
|
+
w.c = ((matrix.c * a) + (matrix.d * c)) * pixelRatio,
|
|
139
|
+
w.d = ((matrix.c * b) + (matrix.d * d)) * pixelRatio,
|
|
140
|
+
w.e = (((matrix.e * a) + (matrix.f * c) + e)) * pixelRatio,
|
|
141
|
+
w.f = (((matrix.e * b) + (matrix.f * d) + f)) * pixelRatio
|
|
142
|
+
)
|
|
176
143
|
|
|
177
144
|
} else {
|
|
178
145
|
|
|
@@ -200,7 +167,7 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
200
167
|
}
|
|
201
168
|
|
|
202
169
|
public setStrokeOptions(options: ICanvasStrokeOptions): void {
|
|
203
|
-
this.strokeCap = options.strokeCap
|
|
170
|
+
this.strokeCap = options.strokeCap === 'none' ? 'butt' : options.strokeCap
|
|
204
171
|
this.strokeJoin = options.strokeJoin
|
|
205
172
|
this.dashPattern = options.dashPattern
|
|
206
173
|
this.dashOffset = options.dashOffset
|
|
@@ -216,15 +183,15 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
216
183
|
this.blendMode = this.savedBlendMode
|
|
217
184
|
}
|
|
218
185
|
|
|
219
|
-
|
|
220
|
-
return fillRule ? this.context.isPointInPath(point.x, point.y, fillRule) : this.context.isPointInPath(point.x, point.y)
|
|
221
|
-
}
|
|
186
|
+
// @leafer-ui/interaction rewrite
|
|
222
187
|
|
|
223
|
-
public
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
188
|
+
public hitFill(_point: IPointData, _fillRule?: IWindingRule): boolean { return true }
|
|
189
|
+
|
|
190
|
+
public hitStroke(_point: IPointData, _strokeWidth?: number): boolean { return true }
|
|
191
|
+
|
|
192
|
+
public hitPixel(_radiusPoint: IRadiusPointData, _offset?: IPointData, _scale = 1): boolean { return true }
|
|
227
193
|
|
|
194
|
+
// ---
|
|
228
195
|
|
|
229
196
|
public setWorldShadow(x: number, y: number, blur: number, color?: string): void {
|
|
230
197
|
const { pixelRatio } = this
|
|
@@ -266,10 +233,10 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
266
233
|
if (blendMode) this.blendMode = 'source-over'
|
|
267
234
|
}
|
|
268
235
|
|
|
269
|
-
public copyWorldByReset(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: IBlendMode): void {
|
|
236
|
+
public copyWorldByReset(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: IBlendMode, onlyResetTransform?: boolean): void {
|
|
270
237
|
this.resetTransform()
|
|
271
238
|
this.copyWorld(canvas, from, to, blendMode)
|
|
272
|
-
this.useWorldTransform()
|
|
239
|
+
if (!onlyResetTransform) this.useWorldTransform() // restore world transform
|
|
273
240
|
}
|
|
274
241
|
|
|
275
242
|
public useMask(maskCanvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData): void {
|
|
@@ -283,37 +250,37 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
283
250
|
public fillWorld(bounds: IBoundsData, color: string | object, blendMode?: IBlendMode): void {
|
|
284
251
|
if (blendMode) this.blendMode = blendMode
|
|
285
252
|
this.fillStyle = color
|
|
286
|
-
|
|
287
|
-
this.fillRect(
|
|
253
|
+
tempBounds.set(bounds).scale(this.pixelRatio)
|
|
254
|
+
this.fillRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height)
|
|
288
255
|
if (blendMode) this.blendMode = 'source-over'
|
|
289
256
|
}
|
|
290
257
|
|
|
291
258
|
public strokeWorld(bounds: IBoundsData, color: string | object, blendMode?: IBlendMode): void {
|
|
292
259
|
if (blendMode) this.blendMode = blendMode
|
|
293
260
|
this.strokeStyle = color
|
|
294
|
-
|
|
295
|
-
this.strokeRect(
|
|
261
|
+
tempBounds.set(bounds).scale(this.pixelRatio)
|
|
262
|
+
this.strokeRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height)
|
|
296
263
|
if (blendMode) this.blendMode = 'source-over'
|
|
297
264
|
}
|
|
298
265
|
|
|
299
266
|
public clearWorld(bounds: IBoundsData, ceilPixel?: boolean): void {
|
|
300
|
-
|
|
301
|
-
if (ceilPixel)
|
|
302
|
-
this.clearRect(
|
|
267
|
+
tempBounds.set(bounds).scale(this.pixelRatio)
|
|
268
|
+
if (ceilPixel) tempBounds.ceil()
|
|
269
|
+
this.clearRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height)
|
|
303
270
|
}
|
|
304
271
|
|
|
305
272
|
public clipWorld(bounds: IBoundsData, ceilPixel?: boolean): void {
|
|
306
273
|
this.beginPath()
|
|
307
|
-
|
|
308
|
-
if (ceilPixel)
|
|
309
|
-
this.rect(
|
|
274
|
+
tempBounds.set(bounds).scale(this.pixelRatio)
|
|
275
|
+
if (ceilPixel) tempBounds.ceil()
|
|
276
|
+
this.rect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height)
|
|
310
277
|
this.clip()
|
|
311
278
|
|
|
312
279
|
}
|
|
313
280
|
|
|
314
281
|
public clear(): void {
|
|
315
282
|
const { pixelRatio } = this
|
|
316
|
-
this.clearRect(0, 0, this.width * pixelRatio, this.height * pixelRatio)
|
|
283
|
+
this.clearRect(0, 0, this.width * pixelRatio + 2, this.height * pixelRatio + 2)
|
|
317
284
|
}
|
|
318
285
|
|
|
319
286
|
|
|
@@ -325,34 +292,20 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
325
292
|
|
|
326
293
|
// 需要有 manager变量
|
|
327
294
|
public getSameCanvas(useSameWorldTransform?: boolean, useSameSmooth?: boolean): ILeaferCanvas {
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
const options = { width, height, pixelRatio }
|
|
331
|
-
const canvas = this.manager ? this.manager.get(options) : Creator.canvas(options)
|
|
332
|
-
|
|
295
|
+
const canvas = this.manager ? this.manager.get(this.size) : Creator.canvas({ ...this.size })
|
|
333
296
|
canvas.save()
|
|
334
297
|
|
|
335
|
-
if (useSameWorldTransform) canvas.useWorldTransform({ ...this.worldTransform })
|
|
336
|
-
if (useSameSmooth) canvas.smooth = this.smooth
|
|
337
|
-
|
|
338
|
-
return canvas
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
public getBiggerCanvas(addWidth: number, addHeight: number): ILeaferCanvas {
|
|
342
|
-
let { width, height, pixelRatio } = this
|
|
343
|
-
if (addWidth) width += addWidth
|
|
344
|
-
if (addHeight) height += addHeight
|
|
345
298
|
|
|
346
|
-
|
|
347
|
-
|
|
299
|
+
if (useSameWorldTransform) copy(canvas.worldTransform, this.worldTransform), canvas.useWorldTransform()
|
|
300
|
+
if (useSameSmooth) canvas.smooth = this.smooth
|
|
348
301
|
|
|
349
|
-
canvas.save()
|
|
350
302
|
return canvas
|
|
351
303
|
}
|
|
352
304
|
|
|
353
|
-
public recycle(): void {
|
|
305
|
+
public recycle(clearBounds?: IBoundsData): void {
|
|
354
306
|
if (!this.recycled) {
|
|
355
307
|
this.restore()
|
|
308
|
+
clearBounds ? this.clearWorld(clearBounds, true) : this.clear()
|
|
356
309
|
this.manager ? this.manager.recycle(this) : this.destroy()
|
|
357
310
|
}
|
|
358
311
|
}
|
package/src/index.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ICanvasManager, ILeaferCanvas, IScreenSizeData,
|
|
1
|
+
import { ICanvasManager, ILeaferCanvas, IScreenSizeData, ICanvasAttr, InnerId, ICanvasContext2D, IBlendMode, IMatrixData, IPath2D, IWindingRule, ITextMetrics, IBounds, IBoundsData, ILeaferCanvasConfig, ILeaferCanvasView, IExportFileType, IExportOptions, IBlob, IExportImageType, IAutoBounds, IResizeEventListener, ICursorType, ICanvasStrokeOptions, IPointData, IRadiusPointData, IMatrixWithBoundsData, IPathDrawer } from '@leafer/interface';
|
|
2
2
|
|
|
3
3
|
declare class CanvasManager implements ICanvasManager {
|
|
4
4
|
list: ILeaferCanvas[];
|
|
@@ -10,21 +10,8 @@ declare class CanvasManager implements ICanvasManager {
|
|
|
10
10
|
destroy(): void;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
declare class HitCanvasManager extends CanvasManager implements IHitCanvasManager {
|
|
14
|
-
protected pathTypeList: ILeafList;
|
|
15
|
-
protected imageTypeList: ILeafList;
|
|
16
|
-
getImageType(leaf: ILeaf, size: IScreenSizeData): IHitCanvas;
|
|
17
|
-
getPathType(leaf: ILeaf): IHitCanvas;
|
|
18
|
-
clearImageType(): void;
|
|
19
|
-
clearPathType(): void;
|
|
20
|
-
protected __clearLeafList(leafList: ILeafList): void;
|
|
21
|
-
clear(): void;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
13
|
declare class Canvas implements ICanvasAttr {
|
|
25
14
|
readonly innerId: InnerId;
|
|
26
|
-
width: number;
|
|
27
|
-
height: number;
|
|
28
15
|
context: ICanvasContext2D;
|
|
29
16
|
smooth: boolean;
|
|
30
17
|
smoothLevel: ImageSmoothingQuality;
|
|
@@ -98,7 +85,10 @@ declare class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
98
85
|
readonly innerId: InnerId;
|
|
99
86
|
name: string;
|
|
100
87
|
manager: ICanvasManager;
|
|
101
|
-
|
|
88
|
+
size: IScreenSizeData;
|
|
89
|
+
get width(): number;
|
|
90
|
+
get height(): number;
|
|
91
|
+
get pixelRatio(): number;
|
|
102
92
|
get pixelWidth(): number;
|
|
103
93
|
get pixelHeight(): number;
|
|
104
94
|
get allowBackgroundColor(): boolean;
|
|
@@ -106,7 +96,7 @@ declare class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
106
96
|
clientBounds: IBoundsData;
|
|
107
97
|
config: ILeaferCanvasConfig;
|
|
108
98
|
autoLayout: boolean;
|
|
109
|
-
view:
|
|
99
|
+
view: ILeaferCanvasView;
|
|
110
100
|
parentView: any;
|
|
111
101
|
unreal?: boolean;
|
|
112
102
|
recycled?: boolean;
|
|
@@ -115,29 +105,31 @@ declare class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
115
105
|
constructor(config?: ILeaferCanvasConfig, manager?: ICanvasManager);
|
|
116
106
|
init(): void;
|
|
117
107
|
__createContext(): void;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
108
|
+
export(_filename: IExportFileType | string, _options?: IExportOptions | number | boolean): string | Promise<any>;
|
|
109
|
+
toBlob(_type?: IExportFileType, _quality?: number): Promise<IBlob>;
|
|
110
|
+
toDataURL(_type?: IExportImageType, _quality?: number): string | Promise<string>;
|
|
111
|
+
saveAs(_filename: string, _quality?: number): Promise<boolean>;
|
|
122
112
|
resize(size: IScreenSizeData): void;
|
|
123
113
|
updateViewSize(): void;
|
|
124
114
|
updateClientBounds(): void;
|
|
115
|
+
getClientBounds(update?: boolean): IBoundsData;
|
|
125
116
|
startAutoLayout(_autoBounds: IAutoBounds, _listener: IResizeEventListener): void;
|
|
126
117
|
stopAutoLayout(): void;
|
|
127
118
|
setCursor(_cursor: ICursorType | ICursorType[]): void;
|
|
128
|
-
setWorld(matrix: IMatrixData, parentMatrix?: IMatrixData
|
|
119
|
+
setWorld(matrix: IMatrixData, parentMatrix?: IMatrixData): void;
|
|
129
120
|
useWorldTransform(worldTransform?: IMatrixData): void;
|
|
130
121
|
setStroke(color: string | object, strokeWidth: number, options?: ICanvasStrokeOptions): void;
|
|
131
122
|
setStrokeOptions(options: ICanvasStrokeOptions): void;
|
|
132
123
|
saveBlendMode(blendMode: IBlendMode): void;
|
|
133
124
|
restoreBlendMode(): void;
|
|
134
|
-
hitFill(
|
|
135
|
-
hitStroke(
|
|
125
|
+
hitFill(_point: IPointData, _fillRule?: IWindingRule): boolean;
|
|
126
|
+
hitStroke(_point: IPointData, _strokeWidth?: number): boolean;
|
|
127
|
+
hitPixel(_radiusPoint: IRadiusPointData, _offset?: IPointData, _scale?: number): boolean;
|
|
136
128
|
setWorldShadow(x: number, y: number, blur: number, color?: string): void;
|
|
137
129
|
setWorldBlur(blur: number): void;
|
|
138
130
|
copyWorld(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: IBlendMode): void;
|
|
139
131
|
copyWorldToInner(canvas: ILeaferCanvas, fromWorld: IMatrixWithBoundsData, toInnerBounds: IBoundsData, blendMode?: IBlendMode): void;
|
|
140
|
-
copyWorldByReset(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: IBlendMode): void;
|
|
132
|
+
copyWorldByReset(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: IBlendMode, onlyResetTransform?: boolean): void;
|
|
141
133
|
useMask(maskCanvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData): void;
|
|
142
134
|
useEraser(eraserCanvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData): void;
|
|
143
135
|
fillWorld(bounds: IBoundsData, color: string | object, blendMode?: IBlendMode): void;
|
|
@@ -147,8 +139,7 @@ declare class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
147
139
|
clear(): void;
|
|
148
140
|
isSameSize(size: IScreenSizeData): boolean;
|
|
149
141
|
getSameCanvas(useSameWorldTransform?: boolean, useSameSmooth?: boolean): ILeaferCanvas;
|
|
150
|
-
|
|
151
|
-
recycle(): void;
|
|
142
|
+
recycle(clearBounds?: IBoundsData): void;
|
|
152
143
|
updateRender(): void;
|
|
153
144
|
unrealCanvas(): void;
|
|
154
145
|
destroy(): void;
|
|
@@ -156,4 +147,4 @@ declare class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
156
147
|
|
|
157
148
|
declare function canvasPatch(drawer: IPathDrawer): void;
|
|
158
149
|
|
|
159
|
-
export { CanvasManager,
|
|
150
|
+
export { CanvasManager, LeaferCanvasBase, canvasPatch, canvasSizeAttrs };
|
package/src/HitCanvasManager.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { IScreenSizeData, IHitCanvasManager, ILeaf, IHitCanvas, ILeafList } from '@leafer/interface'
|
|
2
|
-
import { LeafList } from '@leafer/list'
|
|
3
|
-
import { Creator } from '@leafer/platform'
|
|
4
|
-
|
|
5
|
-
import { CanvasManager } from './CanvasManager'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export class HitCanvasManager extends CanvasManager implements IHitCanvasManager {
|
|
9
|
-
|
|
10
|
-
protected pathTypeList: ILeafList = new LeafList()
|
|
11
|
-
protected imageTypeList: ILeafList = new LeafList()
|
|
12
|
-
|
|
13
|
-
public getImageType(leaf: ILeaf, size: IScreenSizeData): IHitCanvas {
|
|
14
|
-
this.imageTypeList.add(leaf)
|
|
15
|
-
return Creator.hitCanvas(size)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public getPathType(leaf: ILeaf): IHitCanvas {
|
|
19
|
-
this.pathTypeList.add(leaf)
|
|
20
|
-
return Creator.hitCanvas()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public clearImageType(): void {
|
|
24
|
-
this.__clearLeafList(this.imageTypeList)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public clearPathType(): void {
|
|
28
|
-
this.__clearLeafList(this.pathTypeList)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
protected __clearLeafList(leafList: ILeafList): void {
|
|
32
|
-
if (leafList.length) {
|
|
33
|
-
leafList.forEach(leaf => {
|
|
34
|
-
if (leaf.__hitCanvas) {
|
|
35
|
-
leaf.__hitCanvas.destroy()
|
|
36
|
-
leaf.__hitCanvas = null
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
leafList.reset()
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public clear(): void {
|
|
44
|
-
this.clearPathType()
|
|
45
|
-
this.clearImageType()
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}
|