@leafer/canvas 1.5.3 → 1.6.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/LeaferCanvasBase.ts +22 -27
- package/types/index.d.ts +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/canvas",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.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.
|
|
26
|
-
"@leafer/list": "1.
|
|
27
|
-
"@leafer/math": "1.
|
|
28
|
-
"@leafer/data": "1.
|
|
29
|
-
"@leafer/path": "1.
|
|
30
|
-
"@leafer/debug": "1.
|
|
31
|
-
"@leafer/platform": "1.
|
|
25
|
+
"@leafer/file": "1.6.0",
|
|
26
|
+
"@leafer/list": "1.6.0",
|
|
27
|
+
"@leafer/math": "1.6.0",
|
|
28
|
+
"@leafer/data": "1.6.0",
|
|
29
|
+
"@leafer/path": "1.6.0",
|
|
30
|
+
"@leafer/debug": "1.6.0",
|
|
31
|
+
"@leafer/platform": "1.6.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@leafer/interface": "1.
|
|
34
|
+
"@leafer/interface": "1.6.0"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/LeaferCanvasBase.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IBounds, ILeaferCanvas, ICanvasStrokeOptions, ILeaferCanvasConfig, IExportOptions, IMatrixData, IBoundsData, IAutoBounds, IScreenSizeData, IResizeEventListener, IMatrixWithBoundsData, IPointData, InnerId, ICanvasManager, IWindingRule, IBlendMode, IExportImageType, IExportFileType, IBlob, ICursorType, ILeaferCanvasView, IRadiusPointData, IObject } from '@leafer/interface'
|
|
1
|
+
import { IBounds, ILeaferCanvas, ICanvasStrokeOptions, ILeaferCanvasConfig, IExportOptions, IMatrixData, IBoundsData, IAutoBounds, IScreenSizeData, IResizeEventListener, IMatrixWithBoundsData, IPointData, InnerId, ICanvasManager, IWindingRule, IBlendMode, IExportImageType, IExportFileType, IBlob, ICursorType, ILeaferCanvasView, IRadiusPointData, IObject, IMatrixWithOptionHalfData } from '@leafer/interface'
|
|
2
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'
|
|
@@ -6,7 +6,7 @@ import { DataHelper } from '@leafer/data'
|
|
|
6
6
|
import { Canvas } from './Canvas'
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
const { copy } = MatrixHelper
|
|
9
|
+
const { copy, multiplyParent } = MatrixHelper, { round } = Math
|
|
10
10
|
const minSize: IScreenSizeData = { width: 1, height: 1, pixelRatio: 1 }
|
|
11
11
|
|
|
12
12
|
export const canvasSizeAttrs = ['width', 'height', 'pixelRatio']
|
|
@@ -28,6 +28,9 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
28
28
|
public get pixelWidth(): number { return this.width * this.pixelRatio }
|
|
29
29
|
public get pixelHeight(): number { return this.height * this.pixelRatio }
|
|
30
30
|
|
|
31
|
+
public get pixelSnap(): boolean { return this.config.pixelSnap }
|
|
32
|
+
public set pixelSnap(value: boolean) { this.config.pixelSnap = value }
|
|
33
|
+
|
|
31
34
|
public get allowBackgroundColor(): boolean { return this.view && this.parentView }
|
|
32
35
|
|
|
33
36
|
public bounds: IBounds
|
|
@@ -126,32 +129,24 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
126
129
|
|
|
127
130
|
public setCursor(_cursor: ICursorType | ICursorType[]): void { }
|
|
128
131
|
|
|
129
|
-
public setWorld(matrix:
|
|
130
|
-
const { pixelRatio } = this
|
|
131
|
-
const w = this.worldTransform
|
|
132
|
-
if (parentMatrix) {
|
|
133
|
-
|
|
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
|
-
)
|
|
132
|
+
public setWorld(matrix: IMatrixWithOptionHalfData, parentMatrix?: IMatrixData): void {
|
|
133
|
+
const { pixelRatio, pixelSnap } = this, w = this.worldTransform
|
|
143
134
|
|
|
144
|
-
|
|
135
|
+
if (parentMatrix) multiplyParent(matrix, parentMatrix, w)
|
|
145
136
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
137
|
+
w.a = matrix.a * pixelRatio
|
|
138
|
+
w.b = matrix.b * pixelRatio
|
|
139
|
+
w.c = matrix.c * pixelRatio
|
|
140
|
+
w.d = matrix.d * pixelRatio
|
|
141
|
+
w.e = matrix.e * pixelRatio
|
|
142
|
+
w.f = matrix.f * pixelRatio
|
|
143
|
+
|
|
144
|
+
if (pixelSnap) {
|
|
145
|
+
if (matrix.half && (matrix.half * pixelRatio) % 2) w.e = round(w.e - 0.5) + 0.5, w.f = round(w.f - 0.5) + 0.5
|
|
146
|
+
else w.e = round(w.e), w.f = round(w.f)
|
|
154
147
|
}
|
|
148
|
+
|
|
149
|
+
this.setTransform(w.a, w.b, w.c, w.d, w.e, w.f)
|
|
155
150
|
}
|
|
156
151
|
|
|
157
152
|
public useWorldTransform(worldTransform?: IMatrixData): void {
|
|
@@ -311,12 +306,12 @@ export class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
311
306
|
|
|
312
307
|
// 需要有 manager变量
|
|
313
308
|
public getSameCanvas(useSameWorldTransform?: boolean, useSameSmooth?: boolean): ILeaferCanvas {
|
|
314
|
-
const canvas = this.manager ? this.manager.get(
|
|
309
|
+
const { size, pixelSnap } = this, canvas = this.manager ? this.manager.get(size) : Creator.canvas({ ...size })
|
|
315
310
|
canvas.save()
|
|
316
311
|
|
|
317
|
-
|
|
318
312
|
if (useSameWorldTransform) copy(canvas.worldTransform, this.worldTransform), canvas.useWorldTransform()
|
|
319
313
|
if (useSameSmooth) canvas.smooth = this.smooth
|
|
314
|
+
canvas.pixelSnap !== pixelSnap && (canvas.pixelSnap = pixelSnap)
|
|
320
315
|
|
|
321
316
|
return canvas
|
|
322
317
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
1
|
+
import { ICanvasManager, ILeaferCanvas, IScreenSizeData, ICanvasAttr, InnerId, ICanvasContext2D, IBlendMode, IMatrixData, IPath2D, IWindingRule, ITextMetrics, IBounds, IBoundsData, ILeaferCanvasConfig, ILeaferCanvasView, IExportFileType, IExportOptions, IBlob, IExportImageType, IAutoBounds, IResizeEventListener, ICursorType, IMatrixWithOptionHalfData, ICanvasStrokeOptions, IPointData, IRadiusPointData, IMatrixWithBoundsData, IPathDrawer } from '@leafer/interface';
|
|
2
2
|
|
|
3
3
|
declare class CanvasManager implements ICanvasManager {
|
|
4
4
|
list: ILeaferCanvas[];
|
|
@@ -91,6 +91,8 @@ declare class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
91
91
|
get pixelRatio(): number;
|
|
92
92
|
get pixelWidth(): number;
|
|
93
93
|
get pixelHeight(): number;
|
|
94
|
+
get pixelSnap(): boolean;
|
|
95
|
+
set pixelSnap(value: boolean);
|
|
94
96
|
get allowBackgroundColor(): boolean;
|
|
95
97
|
bounds: IBounds;
|
|
96
98
|
clientBounds: IBoundsData;
|
|
@@ -116,7 +118,7 @@ declare class LeaferCanvasBase extends Canvas implements ILeaferCanvas {
|
|
|
116
118
|
startAutoLayout(_autoBounds: IAutoBounds, _listener: IResizeEventListener): void;
|
|
117
119
|
stopAutoLayout(): void;
|
|
118
120
|
setCursor(_cursor: ICursorType | ICursorType[]): void;
|
|
119
|
-
setWorld(matrix:
|
|
121
|
+
setWorld(matrix: IMatrixWithOptionHalfData, parentMatrix?: IMatrixData): void;
|
|
120
122
|
useWorldTransform(worldTransform?: IMatrixData): void;
|
|
121
123
|
setStroke(color: string | object, strokeWidth: number, options?: ICanvasStrokeOptions): void;
|
|
122
124
|
setStrokeOptions(options: ICanvasStrokeOptions): void;
|