@leafer/canvas
Advanced tools
+9
-9
| { | ||
| "name": "@leafer/canvas", | ||
| "version": "1.9.1", | ||
| "version": "1.9.2", | ||
| "description": "@leafer/canvas", | ||
@@ -25,13 +25,13 @@ "author": "Chao (Leafer) Wan", | ||
| "dependencies": { | ||
| "@leafer/file": "1.9.1", | ||
| "@leafer/list": "1.9.1", | ||
| "@leafer/math": "1.9.1", | ||
| "@leafer/data": "1.9.1", | ||
| "@leafer/path": "1.9.1", | ||
| "@leafer/debug": "1.9.1", | ||
| "@leafer/platform": "1.9.1" | ||
| "@leafer/file": "1.9.2", | ||
| "@leafer/list": "1.9.2", | ||
| "@leafer/math": "1.9.2", | ||
| "@leafer/data": "1.9.2", | ||
| "@leafer/path": "1.9.2", | ||
| "@leafer/debug": "1.9.2", | ||
| "@leafer/platform": "1.9.2" | ||
| }, | ||
| "devDependencies": { | ||
| "@leafer/interface": "1.9.1" | ||
| "@leafer/interface": "1.9.2" | ||
| } | ||
| } |
+45
-35
| import { IBounds, ILeaferCanvas, ICanvasStrokeOptions, ILeaferCanvasConfig, IWindingRuleData, IExportOptions, IMatrixData, IBoundsData, IAutoBounds, IScreenSizeData, IResizeEventListener, IMatrixWithBoundsData, IPointData, InnerId, ICanvasManager, IWindingRule, IBlendMode, IExportImageType, IExportFileType, IBlob, ICursorType, ILeaferCanvasView, IRadiusPointData, IObject, IMatrixWithOptionHalfData } from '@leafer/interface' | ||
| import { Bounds, tempBounds, BoundsHelper, MatrixHelper, IncrementId } from '@leafer/math' | ||
| import { Bounds, BoundsHelper, MatrixHelper, IncrementId } from '@leafer/math' | ||
| import { Creator, Platform } from '@leafer/platform' | ||
@@ -9,3 +9,3 @@ import { DataHelper, isUndefined } from '@leafer/data' | ||
| const { copy, multiplyParent } = MatrixHelper, { round } = Math | ||
| const { copy, multiplyParent } = MatrixHelper, { round } = Math, tempPixelBounds = new Bounds(), tempPixelBounds2 = new Bounds() | ||
| const minSize: IScreenSizeData = { width: 1, height: 1, pixelRatio: 1 } | ||
@@ -214,8 +214,10 @@ | ||
| public copyWorld(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: IBlendMode): void { | ||
| public copyWorld(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: IBlendMode, ceilPixel: boolean = true): void { | ||
| if (blendMode) this.blendMode = blendMode | ||
| if (from) { | ||
| const { pixelRatio } = this | ||
| if (!to) to = from | ||
| this.drawImage(canvas.view as HTMLCanvasElement, from.x * pixelRatio, from.y * pixelRatio, from.width * pixelRatio, from.height * pixelRatio, to.x * pixelRatio, to.y * pixelRatio, to.width * pixelRatio, to.height * pixelRatio) | ||
| this.setTempPixelBounds(from, ceilPixel) | ||
| if (!to) to = tempPixelBounds // to = from | ||
| else this.setTempPixelBounds2(to, ceilPixel), to = tempPixelBounds2 | ||
| this.drawImage(canvas.view as HTMLCanvasElement, tempPixelBounds.x, tempPixelBounds.y, tempPixelBounds.width, tempPixelBounds.height, to.x, to.y, to.width, to.height) | ||
| } else { | ||
@@ -227,19 +229,19 @@ this.drawImage(canvas.view as HTMLCanvasElement, 0, 0) | ||
| public copyWorldToInner(canvas: ILeaferCanvas, fromWorld: IMatrixWithBoundsData, toInnerBounds: IBoundsData, blendMode?: IBlendMode): void { | ||
| if (blendMode) this.blendMode = blendMode | ||
| public copyWorldToInner(canvas: ILeaferCanvas, fromWorld: IMatrixWithBoundsData, toInnerBounds: IBoundsData, blendMode?: IBlendMode, ceilPixel: boolean = true): void { | ||
| if (fromWorld.b || fromWorld.c) { | ||
| this.save() | ||
| this.resetTransform() | ||
| this.copyWorld(canvas, fromWorld, BoundsHelper.tempToOuterOf(toInnerBounds, fromWorld)) | ||
| this.copyWorld(canvas, fromWorld, BoundsHelper.tempToOuterOf(toInnerBounds, fromWorld), blendMode, ceilPixel) | ||
| this.restore() | ||
| } else { | ||
| const { pixelRatio } = this | ||
| this.drawImage(canvas.view as HTMLCanvasElement, fromWorld.x * pixelRatio, fromWorld.y * pixelRatio, fromWorld.width * pixelRatio, fromWorld.height * pixelRatio, toInnerBounds.x, toInnerBounds.y, toInnerBounds.width, toInnerBounds.height) | ||
| if (blendMode) this.blendMode = blendMode | ||
| this.setTempPixelBounds(fromWorld, ceilPixel) | ||
| this.drawImage(canvas.view as HTMLCanvasElement, tempPixelBounds.x, tempPixelBounds.y, tempPixelBounds.width, tempPixelBounds.height, toInnerBounds.x, toInnerBounds.y, toInnerBounds.width, toInnerBounds.height) | ||
| if (blendMode) this.blendMode = 'source-over' | ||
| } | ||
| if (blendMode) this.blendMode = 'source-over' | ||
| } | ||
| public copyWorldByReset(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: IBlendMode, onlyResetTransform?: boolean): void { | ||
| public copyWorldByReset(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: IBlendMode, onlyResetTransform?: boolean, ceilPixel: boolean = true): void { | ||
| this.resetTransform() | ||
| this.copyWorld(canvas, from, to, blendMode) | ||
| this.copyWorld(canvas, from, to, blendMode, ceilPixel) | ||
| if (!onlyResetTransform) this.useWorldTransform() // restore world transform | ||
@@ -249,6 +251,6 @@ } | ||
| public useGrayscaleAlpha(bounds: IBoundsData): void { // 先实现功能,后期需通过 shader 优化性能 | ||
| this.setTempBounds(bounds, true, true) | ||
| this.setTempPixelBounds(bounds, true, true) | ||
| let alpha: number, pixel: number | ||
| const { context } = this, imageData = context.getImageData(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height), { data } = imageData | ||
| const { context } = this, imageData = context.getImageData(tempPixelBounds.x, tempPixelBounds.y, tempPixelBounds.width, tempPixelBounds.height), { data } = imageData | ||
@@ -260,3 +262,3 @@ for (let i = 0, len = data.length; i < len; i += 4) { | ||
| context.putImageData(imageData, tempBounds.x, tempBounds.y) | ||
| context.putImageData(imageData, tempPixelBounds.x, tempPixelBounds.y) | ||
| } | ||
@@ -272,22 +274,22 @@ | ||
| public fillWorld(bounds: IBoundsData, color: string | object, blendMode?: IBlendMode): void { | ||
| public fillWorld(bounds: IBoundsData, color: string | object, blendMode?: IBlendMode, ceilPixel?: boolean): void { | ||
| if (blendMode) this.blendMode = blendMode | ||
| this.fillStyle = color | ||
| this.setTempBounds(bounds) | ||
| this.fillRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height) | ||
| this.setTempPixelBounds(bounds, ceilPixel) | ||
| this.fillRect(tempPixelBounds.x, tempPixelBounds.y, tempPixelBounds.width, tempPixelBounds.height) | ||
| if (blendMode) this.blendMode = 'source-over' | ||
| } | ||
| public strokeWorld(bounds: IBoundsData, color: string | object, blendMode?: IBlendMode): void { | ||
| public strokeWorld(bounds: IBoundsData, color: string | object, blendMode?: IBlendMode, ceilPixel?: boolean): void { | ||
| if (blendMode) this.blendMode = blendMode | ||
| this.strokeStyle = color | ||
| this.setTempBounds(bounds) | ||
| this.strokeRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height) | ||
| this.setTempPixelBounds(bounds, ceilPixel) | ||
| this.strokeRect(tempPixelBounds.x, tempPixelBounds.y, tempPixelBounds.width, tempPixelBounds.height) | ||
| if (blendMode) this.blendMode = 'source-over' | ||
| } | ||
| public clipWorld(bounds: IBoundsData, ceilPixel?: boolean): void { | ||
| public clipWorld(bounds: IBoundsData, ceilPixel: boolean = true): void { | ||
| this.beginPath() | ||
| this.setTempBounds(bounds, ceilPixel) | ||
| this.rect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height) | ||
| this.setTempPixelBounds(bounds, ceilPixel) | ||
| this.rect(tempPixelBounds.x, tempPixelBounds.y, tempPixelBounds.width, tempPixelBounds.height) | ||
| this.clip() | ||
@@ -301,5 +303,5 @@ | ||
| public clearWorld(bounds: IBoundsData, ceilPixel?: boolean): void { | ||
| this.setTempBounds(bounds, ceilPixel) | ||
| this.clearRect(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height) | ||
| public clearWorld(bounds: IBoundsData, ceilPixel: boolean = true): void { | ||
| this.setTempPixelBounds(bounds, ceilPixel) | ||
| this.clearRect(tempPixelBounds.x, tempPixelBounds.y, tempPixelBounds.width, tempPixelBounds.height) | ||
| } | ||
@@ -315,9 +317,17 @@ | ||
| protected setTempBounds(bounds: IBoundsData, ceil?: boolean, intersect?: boolean): void { | ||
| tempBounds.set(bounds) | ||
| if (intersect) tempBounds.intersect(this.bounds) | ||
| tempBounds.scale(this.pixelRatio) | ||
| if (ceil) tempBounds.ceil() | ||
| protected setTempPixelBounds(bounds: IBoundsData, ceil?: boolean, intersect?: boolean): void { | ||
| this.copyToPixelBounds(tempPixelBounds, bounds, ceil, intersect) | ||
| } | ||
| protected setTempPixelBounds2(bounds: IBoundsData, ceil?: boolean, intersect?: boolean): void { | ||
| this.copyToPixelBounds(tempPixelBounds2, bounds, ceil, intersect) | ||
| } | ||
| protected copyToPixelBounds(pixelBounds: IBounds, bounds: IBoundsData, ceil?: boolean, intersect?: boolean): void { | ||
| pixelBounds.set(bounds) | ||
| if (intersect) pixelBounds.intersect(this.bounds) | ||
| pixelBounds.scale(this.pixelRatio) | ||
| if (ceil) pixelBounds.ceil() | ||
| } | ||
| public isSameSize(size: IScreenSizeData): boolean { | ||
@@ -342,3 +352,3 @@ return this.width === size.width && this.height === size.height && (!size.pixelRatio || this.pixelRatio === size.pixelRatio) | ||
| this.restore() | ||
| clearBounds ? this.clearWorld(clearBounds, true) : this.clear() | ||
| clearBounds ? this.clearWorld(clearBounds) : this.clear() | ||
| this.manager ? this.manager.recycle(this) : this.destroy() | ||
@@ -345,0 +355,0 @@ } |
+8
-6
@@ -132,10 +132,10 @@ 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, IWindingRuleData, IPathDrawer } from '@leafer/interface'; | ||
| setWorldBlur(blur: number): void; | ||
| copyWorld(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: IBlendMode): void; | ||
| copyWorldToInner(canvas: ILeaferCanvas, fromWorld: IMatrixWithBoundsData, toInnerBounds: IBoundsData, blendMode?: IBlendMode): void; | ||
| copyWorldByReset(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: IBlendMode, onlyResetTransform?: boolean): void; | ||
| copyWorld(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: IBlendMode, ceilPixel?: boolean): void; | ||
| copyWorldToInner(canvas: ILeaferCanvas, fromWorld: IMatrixWithBoundsData, toInnerBounds: IBoundsData, blendMode?: IBlendMode, ceilPixel?: boolean): void; | ||
| copyWorldByReset(canvas: ILeaferCanvas, from?: IBoundsData, to?: IBoundsData, blendMode?: IBlendMode, onlyResetTransform?: boolean, ceilPixel?: boolean): void; | ||
| useGrayscaleAlpha(bounds: IBoundsData): void; | ||
| useMask(maskCanvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData): void; | ||
| useEraser(eraserCanvas: ILeaferCanvas, fromBounds?: IBoundsData, toBounds?: IBoundsData): void; | ||
| fillWorld(bounds: IBoundsData, color: string | object, blendMode?: IBlendMode): void; | ||
| strokeWorld(bounds: IBoundsData, color: string | object, blendMode?: IBlendMode): void; | ||
| fillWorld(bounds: IBoundsData, color: string | object, blendMode?: IBlendMode, ceilPixel?: boolean): void; | ||
| strokeWorld(bounds: IBoundsData, color: string | object, blendMode?: IBlendMode, ceilPixel?: boolean): void; | ||
| clipWorld(bounds: IBoundsData, ceilPixel?: boolean): void; | ||
@@ -145,3 +145,5 @@ clipUI(ruleData: IWindingRuleData): void; | ||
| clear(): void; | ||
| protected setTempBounds(bounds: IBoundsData, ceil?: boolean, intersect?: boolean): void; | ||
| protected setTempPixelBounds(bounds: IBoundsData, ceil?: boolean, intersect?: boolean): void; | ||
| protected setTempPixelBounds2(bounds: IBoundsData, ceil?: boolean, intersect?: boolean): void; | ||
| protected copyToPixelBounds(pixelBounds: IBounds, bounds: IBoundsData, ceil?: boolean, intersect?: boolean): void; | ||
| isSameSize(size: IScreenSizeData): boolean; | ||
@@ -148,0 +150,0 @@ getSameCanvas(useSameWorldTransform?: boolean, useSameSmooth?: boolean): ILeaferCanvas; |
35136
3.37%677
1.35%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated
Updated
Updated
Updated