@leafer/canvas-web 1.0.0-alpha.1 → 1.0.0-alpha.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 +9 -7
- package/src/CanvasBase.ts +29 -29
- package/src/LeaferCanvas.ts +3 -3
- package/src/patch/roundRect.ts +3 -3
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/canvas-web",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.6",
|
|
4
4
|
"description": "@leafer/canvas-web",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.ts",
|
|
8
|
-
"files": [
|
|
8
|
+
"files": [
|
|
9
|
+
"src"
|
|
10
|
+
],
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
11
13
|
"url": "https://github.com/leaferjs/leafer.git"
|
|
@@ -17,11 +19,11 @@
|
|
|
17
19
|
"leaferjs"
|
|
18
20
|
],
|
|
19
21
|
"dependencies": {
|
|
20
|
-
"@leafer/math": "1.0.0-alpha.
|
|
21
|
-
"@leafer/event": "1.0.0-alpha.
|
|
22
|
-
"@leafer/debug": "1.0.0-alpha.
|
|
22
|
+
"@leafer/math": "1.0.0-alpha.6",
|
|
23
|
+
"@leafer/event": "1.0.0-alpha.6",
|
|
24
|
+
"@leafer/debug": "1.0.0-alpha.6"
|
|
23
25
|
},
|
|
24
26
|
"devDependencies": {
|
|
25
|
-
|
|
27
|
+
"@leafer/interface": "1.0.0-alpha.6"
|
|
26
28
|
}
|
|
27
|
-
}
|
|
29
|
+
}
|
package/src/CanvasBase.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ICanvasAttr,
|
|
1
|
+
import { ICanvasAttr, ICanvasFillRule, ITextMetrics, ICanvasRenderingContext2D, IPath2D, IObject, InnerId, IMatrixData, IFunction } from '@leafer/interface'
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
function contextAttr(realName?: string) {
|
|
@@ -14,7 +14,7 @@ function contextAttr(realName?: string) {
|
|
|
14
14
|
|
|
15
15
|
const contextMethodNameList: string[] = []
|
|
16
16
|
function contextMethod() {
|
|
17
|
-
return (
|
|
17
|
+
return (_target: CanvasBase, key: string) => {
|
|
18
18
|
contextMethodNameList.push(key)
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -29,7 +29,7 @@ export class CanvasBase {
|
|
|
29
29
|
|
|
30
30
|
public __: ICanvasAttr
|
|
31
31
|
|
|
32
|
-
public context:
|
|
32
|
+
public context: ICanvasRenderingContext2D
|
|
33
33
|
|
|
34
34
|
// canvas attr
|
|
35
35
|
|
|
@@ -133,7 +133,7 @@ export class CanvasBase {
|
|
|
133
133
|
// canvas method
|
|
134
134
|
|
|
135
135
|
@contextMethod()
|
|
136
|
-
public setTransform(
|
|
136
|
+
public setTransform(_a: number | IMatrixData, _b?: number, _c?: number, _d?: number, _e?: number, _f?: number): void { }
|
|
137
137
|
|
|
138
138
|
@contextMethod()
|
|
139
139
|
public resetTransform(): void { }
|
|
@@ -148,31 +148,31 @@ export class CanvasBase {
|
|
|
148
148
|
public restore(): void { }
|
|
149
149
|
|
|
150
150
|
@contextMethod()
|
|
151
|
-
public translate(
|
|
151
|
+
public translate(_x: number, _y: number): void { }
|
|
152
152
|
|
|
153
153
|
@contextMethod()
|
|
154
|
-
public scale(
|
|
154
|
+
public scale(_x: number, _y: number): void { }
|
|
155
155
|
|
|
156
156
|
@contextMethod()
|
|
157
|
-
public rotate(
|
|
157
|
+
public rotate(_angle: number): void { }
|
|
158
158
|
|
|
159
159
|
@contextMethod()
|
|
160
|
-
public fill(
|
|
160
|
+
public fill(_path2d?: IPath2D | ICanvasFillRule, _rule?: ICanvasFillRule): void { }
|
|
161
161
|
|
|
162
162
|
@contextMethod()
|
|
163
|
-
public stroke(
|
|
163
|
+
public stroke(_path2d?: IPath2D): void { }
|
|
164
164
|
|
|
165
165
|
@contextMethod()
|
|
166
|
-
public clip(
|
|
166
|
+
public clip(_path2d?: IPath2D | ICanvasFillRule, _rule?: ICanvasFillRule): void { }
|
|
167
167
|
|
|
168
168
|
@contextMethod()
|
|
169
|
-
public fillRect(
|
|
169
|
+
public fillRect(_x: number, _y: number, _width: number, _height: number): void { }
|
|
170
170
|
|
|
171
171
|
@contextMethod()
|
|
172
|
-
public strokeRect(
|
|
172
|
+
public strokeRect(_x: number, _y: number, _width: number, _height: number): void { }
|
|
173
173
|
|
|
174
174
|
@contextMethod()
|
|
175
|
-
public clearRect(
|
|
175
|
+
public clearRect(_x: number, _y: number, _width: number, _height: number): void { }
|
|
176
176
|
|
|
177
177
|
public drawImage(image: CanvasImageSource, sx: number, sy: number, sw?: number, sh?: number, dx?: number, dy?: number, dw?: number, dh?: number): void {
|
|
178
178
|
switch (arguments.length) {
|
|
@@ -211,60 +211,60 @@ export class CanvasBase {
|
|
|
211
211
|
public beginPath(): void { }
|
|
212
212
|
|
|
213
213
|
@contextMethod()
|
|
214
|
-
public moveTo(
|
|
214
|
+
public moveTo(_x: number, _y: number): void { }
|
|
215
215
|
|
|
216
216
|
@contextMethod()
|
|
217
|
-
public lineTo(
|
|
217
|
+
public lineTo(_x: number, _y: number): void { }
|
|
218
218
|
|
|
219
219
|
@contextMethod()
|
|
220
|
-
public bezierCurveTo(
|
|
220
|
+
public bezierCurveTo(_cp1x: number, _cp1y: number, _cp2x: number, _cp2y: number, _x: number, _y: number): void { }
|
|
221
221
|
|
|
222
222
|
@contextMethod()
|
|
223
|
-
public quadraticCurveTo(
|
|
223
|
+
public quadraticCurveTo(_cpx: number, _cpy: number, _x: number, _y: number): void { }
|
|
224
224
|
|
|
225
225
|
@contextMethod()
|
|
226
226
|
public closePath(): void { }
|
|
227
227
|
|
|
228
228
|
@contextMethod()
|
|
229
|
-
public arc(
|
|
229
|
+
public arc(_x: number, _y: number, _radius: number, _startAngle: number, _endAngle: number, _counterclockwise?: boolean): void { }
|
|
230
230
|
|
|
231
231
|
@contextMethod()
|
|
232
|
-
public arcTo(
|
|
232
|
+
public arcTo(_x1: number, _y1: number, _x2: number, _y2: number, _radius: number): void { }
|
|
233
233
|
|
|
234
234
|
@contextMethod()
|
|
235
|
-
public ellipse(
|
|
235
|
+
public ellipse(_x: number, _y: number, _radiusX: number, _radiusY: number, _rotation: number, _startAngle: number, _endAngle: number, _counterclockwise?: boolean): void { }
|
|
236
236
|
|
|
237
237
|
@contextMethod()
|
|
238
|
-
public rect(
|
|
238
|
+
public rect(_x: number, _y: number, _width: number, _height: number): void { }
|
|
239
239
|
|
|
240
240
|
@contextMethod()
|
|
241
|
-
public roundRect(
|
|
241
|
+
public roundRect(_x: number, _y: number, _width: number, _height: number, _radius?: number | number[]): void { }
|
|
242
242
|
|
|
243
243
|
// end canvas draw
|
|
244
244
|
|
|
245
245
|
// paint
|
|
246
246
|
|
|
247
247
|
@contextMethod()
|
|
248
|
-
public createConicGradient(
|
|
248
|
+
public createConicGradient(_startAngle: number, _x: number, _y: number): CanvasGradient { return void 0 }
|
|
249
249
|
|
|
250
250
|
@contextMethod()
|
|
251
|
-
public createLinearGradient(
|
|
251
|
+
public createLinearGradient(_x0: number, _y0: number, _x1: number, _y1: number): CanvasGradient { return void 0 }
|
|
252
252
|
|
|
253
253
|
@contextMethod()
|
|
254
|
-
public createPattern(
|
|
254
|
+
public createPattern(_image: CanvasImageSource, _repetition: string | null): CanvasPattern | null { return void 0 }
|
|
255
255
|
|
|
256
256
|
@contextMethod()
|
|
257
|
-
public createRadialGradient(
|
|
257
|
+
public createRadialGradient(_x0: number, _y0: number, _r0: number, _x1: number, _y1: number, _r1: number): CanvasGradient { return void 0 }
|
|
258
258
|
|
|
259
259
|
// text
|
|
260
260
|
@contextMethod()
|
|
261
|
-
public fillText(
|
|
261
|
+
public fillText(_text: string, _x: number, _y: number, _maxWidth?: number): void { }
|
|
262
262
|
|
|
263
263
|
@contextMethod()
|
|
264
|
-
public measureText(
|
|
264
|
+
public measureText(_text: string): ITextMetrics { return void 0 }
|
|
265
265
|
|
|
266
266
|
@contextMethod()
|
|
267
|
-
public strokeText(
|
|
267
|
+
public strokeText(_text: string, _x: number, _y: number, _maxWidth?: number): void { }
|
|
268
268
|
|
|
269
269
|
public destroy(): void {
|
|
270
270
|
this.context = undefined
|
package/src/LeaferCanvas.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IBounds, ILeaferCanvas, ICanvasStrokeOptions,
|
|
1
|
+
import { IBounds, ILeaferCanvas, ICanvasStrokeOptions, ICanvasFillRule, ICanvasRenderingContext2D, ILeaferCanvasConfig, IMatrixData, IBoundsData, IAutoBounds, ISizeData, IScreenSizeData, IResizeEventListener, IMatrixWithBoundsData, IPointData, InnerId, ICanvasManager } from '@leafer/interface'
|
|
2
2
|
import { Bounds, BoundsHelper, IncrementId } from '@leafer/math'
|
|
3
3
|
import { ResizeEvent } from '@leafer/event'
|
|
4
4
|
import { Debug } from '@leafer/debug'
|
|
@@ -72,7 +72,7 @@ export class LeaferCanvas extends CanvasBase implements ILeaferCanvas {
|
|
|
72
72
|
this.pixelRatio = config.pixelRatio
|
|
73
73
|
|
|
74
74
|
if (!config.webgl) {
|
|
75
|
-
this.context = this.view.getContext('2d')
|
|
75
|
+
this.context = this.view.getContext('2d') as ICanvasRenderingContext2D
|
|
76
76
|
this.smooth = true
|
|
77
77
|
if (config.fill) this.view.style.backgroundColor = config.fill
|
|
78
78
|
if (config.width && config.height) this.resize(config as IScreenSizeData)
|
|
@@ -215,7 +215,7 @@ export class LeaferCanvas extends CanvasBase implements ILeaferCanvas {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
|
|
218
|
-
public hitPath(point: IPointData, fillRule?:
|
|
218
|
+
public hitPath(point: IPointData, fillRule?: ICanvasFillRule): boolean {
|
|
219
219
|
return this.context.isPointInPath(point.x, point.y, fillRule)
|
|
220
220
|
}
|
|
221
221
|
|
package/src/patch/roundRect.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IObject } from '@leafer/interface'
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
export function roundRect(): void {
|
|
5
5
|
|
|
6
|
-
if (!(CanvasRenderingContext2D.prototype as
|
|
6
|
+
if (!(CanvasRenderingContext2D.prototype as IObject).roundRect) {
|
|
7
7
|
|
|
8
|
-
(CanvasRenderingContext2D.prototype as
|
|
8
|
+
(CanvasRenderingContext2D.prototype as IObject).roundRect = (Path2D.prototype as IObject).roundRect = function (x: number, y: number, w: number, h: number, r: number | number[]): void {
|
|
9
9
|
|
|
10
10
|
let topLeft: number, topRight: number, bottomRight: number, bottomLeft: number
|
|
11
11
|
|