@leafer-ui/interaction 1.0.0-rc.26 → 1.0.0-rc.27

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-ui/interaction",
3
- "version": "1.0.0-rc.26",
3
+ "version": "1.0.0-rc.27",
4
4
  "description": "@leafer-ui/interaction",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,12 +22,12 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/core": "1.0.0-rc.26",
26
- "@leafer-ui/draw": "1.0.0-rc.26",
27
- "@leafer-ui/event": "1.0.0-rc.26"
25
+ "@leafer/core": "1.0.0-rc.27",
26
+ "@leafer-ui/draw": "1.0.0-rc.27",
27
+ "@leafer-ui/event": "1.0.0-rc.27"
28
28
  },
29
29
  "devDependencies": {
30
- "@leafer/interface": "1.0.0-rc.26",
31
- "@leafer-ui/interface": "1.0.0-rc.26"
30
+ "@leafer/interface": "1.0.0-rc.27",
31
+ "@leafer-ui/interface": "1.0.0-rc.27"
32
32
  }
33
33
  }
package/src/index.ts CHANGED
@@ -2,28 +2,3 @@ export { InteractionBase } from './Interaction'
2
2
  export { InteractionHelper } from './InteractionHelper'
3
3
  export { MultiTouchHelper } from './MultiTouchHelper'
4
4
  export { Cursor } from './Cursor'
5
- export { HitCanvasManager } from './HitCanvasManager'
6
-
7
- import { IPointData, IRadiusPointData, IWindingRule } from '@leafer/interface'
8
- import { LeaferCanvasBase, tempBounds } from '@leafer/core'
9
-
10
-
11
- const canvas = LeaferCanvasBase.prototype
12
-
13
- canvas.hitFill = function (point: IPointData, fillRule?: IWindingRule): boolean {
14
- return fillRule ? this.context.isPointInPath(point.x, point.y, fillRule) : this.context.isPointInPath(point.x, point.y)
15
- }
16
-
17
- canvas.hitStroke = function (point: IPointData, strokeWidth?: number): boolean {
18
- this.strokeWidth = strokeWidth
19
- return this.context.isPointInStroke(point.x, point.y)
20
- }
21
-
22
- canvas.hitPixel = function (radiusPoint: IRadiusPointData, offset?: IPointData, scale = 1): boolean { // 画布必须有alpha通道
23
- let { x, y, radiusX, radiusY } = radiusPoint
24
- if (offset) x -= offset.x, y -= offset.y
25
- tempBounds.set(x - radiusX, y - radiusY, radiusX * 2, radiusY * 2).scale(scale).ceil()
26
- const { data } = this.context.getImageData(tempBounds.x, tempBounds.y, tempBounds.width, tempBounds.height)
27
- for (let i = 0, len = data.length; i < len; i += 4) { if (data[i + 3] > 0) return true }
28
- return data[3] > 0
29
- }
package/types/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer, IDragEvent, IPointerEvent, ILeafList, IPointDataMap, IFunction, ILeaf, IInteraction, IInteractionCanvas, ISelector, IInteractionConfig, ICursorType, IPickBottom, IBounds, IEventListenerId, IBooleanMap, IUIEvent, IKeepTouchData, IKeyEvent, IPickOptions, IClientPointData, IPointData, IEvent, IObject, IDropEvent, ISwipeEvent, IMultiTouchData, ICursorTypeMap, IHitCanvasManager, ILeaferCanvasConfig, IHitCanvas } from '@leafer/interface';
2
- import { LeafList, CanvasManager } from '@leafer/core';
1
+ import { IMoveEvent, IZoomEvent, IRotateEvent, ITimer, IDragEvent, IPointerEvent, ILeafList, IPointDataMap, IFunction, ILeaf, IInteraction, IInteractionCanvas, ISelector, IInteractionConfig, ICursorType, IPickBottom, IBounds, IEventListenerId, IBooleanMap, IUIEvent, IKeepTouchData, IKeyEvent, IPickOptions, IClientPointData, IPointData, IEvent, IObject, IDropEvent, ISwipeEvent, IMultiTouchData, ICursorTypeMap } from '@leafer/interface';
2
+ import { LeafList } from '@leafer/core';
3
3
 
4
4
  declare class Transformer {
5
5
  protected interaction: InteractionBase;
@@ -167,17 +167,4 @@ declare class Cursor {
167
167
  static get(name: string): ICursorType | ICursorType[];
168
168
  }
169
169
 
170
- declare class HitCanvasManager extends CanvasManager implements IHitCanvasManager {
171
- maxTotal: number;
172
- protected pathList: ILeafList;
173
- protected pixelList: ILeafList;
174
- getPixelType(leaf: ILeaf, config: ILeaferCanvasConfig): IHitCanvas;
175
- getPathType(leaf: ILeaf): IHitCanvas;
176
- clearImageType(): void;
177
- clearPathType(): void;
178
- protected __clearLeafList(leafList: ILeafList): void;
179
- protected __autoClear(): void;
180
- clear(): void;
181
- }
182
-
183
- export { Cursor, HitCanvasManager, InteractionBase, InteractionHelper, MultiTouchHelper };
170
+ export { Cursor, InteractionBase, InteractionHelper, MultiTouchHelper };
@@ -1,53 +0,0 @@
1
- import { IHitCanvasManager, ILeaf, IHitCanvas, ILeafList, ILeaferCanvasConfig } from '@leafer/interface'
2
- import { CanvasManager, LeafList, Creator } from '@leafer/core'
3
-
4
-
5
- export class HitCanvasManager extends CanvasManager implements IHitCanvasManager {
6
-
7
- public maxTotal = 1000 // 最多缓存多少张画布
8
-
9
- protected pathList: ILeafList = new LeafList()
10
- protected pixelList: ILeafList = new LeafList()
11
-
12
- public getPixelType(leaf: ILeaf, config: ILeaferCanvasConfig): IHitCanvas {
13
- this.__autoClear()
14
- this.pixelList.add(leaf)
15
- return Creator.hitCanvas(config)
16
- }
17
-
18
- public getPathType(leaf: ILeaf): IHitCanvas {
19
- this.__autoClear()
20
- this.pathList.add(leaf)
21
- return Creator.hitCanvas()
22
- }
23
-
24
- public clearImageType(): void {
25
- this.__clearLeafList(this.pixelList)
26
- }
27
-
28
- public clearPathType(): void {
29
- this.__clearLeafList(this.pathList)
30
- }
31
-
32
- protected __clearLeafList(leafList: ILeafList): void {
33
- if (leafList.length) {
34
- leafList.forEach(leaf => {
35
- if (leaf.__hitCanvas) {
36
- leaf.__hitCanvas.destroy()
37
- leaf.__hitCanvas = null
38
- }
39
- })
40
- leafList.reset()
41
- }
42
- }
43
-
44
- protected __autoClear(): void {
45
- if (this.pathList.length + this.pixelList.length > this.maxTotal) this.clear()
46
- }
47
-
48
- public clear(): void {
49
- this.clearPathType()
50
- this.clearImageType()
51
- }
52
-
53
- }