konva 10.0.10 → 10.0.11
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/konva.js +2 -2
- package/konva.min.js +2 -2
- package/lib/Animation.d.ts +24 -0
- package/lib/Animation.js +142 -0
- package/lib/BezierFunctions.d.ts +6 -0
- package/lib/BezierFunctions.js +784 -0
- package/lib/Canvas.d.ts +33 -0
- package/lib/Canvas.js +107 -0
- package/lib/Container.d.ts +54 -0
- package/lib/Container.js +316 -0
- package/lib/Context.d.ts +95 -0
- package/lib/Context.js +561 -0
- package/lib/Core.d.ts +3 -0
- package/lib/Core.js +3 -0
- package/lib/DragAndDrop.d.ts +17 -0
- package/lib/DragAndDrop.js +110 -0
- package/lib/Factory.d.ts +22 -0
- package/lib/Factory.js +123 -0
- package/lib/FastLayer.d.ts +4 -0
- package/lib/FastLayer.js +12 -0
- package/lib/Global.d.ts +37 -0
- package/lib/Global.js +66 -0
- package/lib/Group.d.ts +9 -0
- package/lib/Group.js +13 -0
- package/lib/Layer.d.ts +62 -0
- package/lib/Layer.js +305 -0
- package/lib/Node.d.ts +323 -0
- package/lib/Node.js +1532 -0
- package/lib/PointerEvents.d.ts +11 -0
- package/lib/PointerEvents.js +37 -0
- package/lib/Shape.d.ts +196 -0
- package/lib/Shape.js +555 -0
- package/lib/Stage.d.ts +86 -0
- package/lib/Stage.js +715 -0
- package/lib/Tween.d.ts +90 -0
- package/lib/Tween.js +531 -0
- package/lib/Util.d.ts +137 -0
- package/lib/Util.js +909 -0
- package/lib/Validators.d.ts +11 -0
- package/lib/Validators.js +178 -0
- package/lib/_CoreInternals.d.ts +224 -0
- package/lib/_CoreInternals.js +34 -0
- package/lib/_FullInternals.d.ts +306 -0
- package/lib/_FullInternals.js +80 -0
- package/lib/canvas-backend.d.ts +2 -0
- package/lib/canvas-backend.js +27 -0
- package/lib/filters/Blur.d.ts +2 -0
- package/lib/filters/Blur.js +235 -0
- package/lib/filters/Brighten.d.ts +2 -0
- package/lib/filters/Brighten.js +12 -0
- package/lib/filters/Brightness.d.ts +2 -0
- package/lib/filters/Brightness.js +8 -0
- package/lib/filters/Contrast.d.ts +2 -0
- package/lib/filters/Contrast.js +35 -0
- package/lib/filters/Emboss.d.ts +2 -0
- package/lib/filters/Emboss.js +101 -0
- package/lib/filters/Enhance.d.ts +2 -0
- package/lib/filters/Enhance.js +84 -0
- package/lib/filters/Grayscale.d.ts +2 -0
- package/lib/filters/Grayscale.js +9 -0
- package/lib/filters/HSL.d.ts +2 -0
- package/lib/filters/HSL.js +24 -0
- package/lib/filters/HSV.d.ts +2 -0
- package/lib/filters/HSV.js +23 -0
- package/lib/filters/Invert.d.ts +2 -0
- package/lib/filters/Invert.js +8 -0
- package/lib/filters/Kaleidoscope.d.ts +2 -0
- package/lib/filters/Kaleidoscope.js +133 -0
- package/lib/filters/Mask.d.ts +2 -0
- package/lib/filters/Mask.js +151 -0
- package/lib/filters/Noise.d.ts +2 -0
- package/lib/filters/Noise.js +12 -0
- package/lib/filters/Pixelate.d.ts +2 -0
- package/lib/filters/Pixelate.js +60 -0
- package/lib/filters/Posterize.d.ts +2 -0
- package/lib/filters/Posterize.js +10 -0
- package/lib/filters/RGB.d.ts +2 -0
- package/lib/filters/RGB.js +38 -0
- package/lib/filters/RGBA.d.ts +2 -0
- package/lib/filters/RGBA.js +49 -0
- package/lib/filters/Sepia.d.ts +2 -0
- package/lib/filters/Sepia.js +11 -0
- package/lib/filters/Solarize.d.ts +2 -0
- package/lib/filters/Solarize.js +14 -0
- package/lib/filters/Threshold.d.ts +2 -0
- package/lib/filters/Threshold.js +10 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/shapes/Arc.d.ts +27 -0
- package/lib/shapes/Arc.js +60 -0
- package/lib/shapes/Arrow.d.ts +27 -0
- package/lib/shapes/Arrow.js +99 -0
- package/lib/shapes/Circle.d.ts +15 -0
- package/lib/shapes/Circle.js +33 -0
- package/lib/shapes/Ellipse.d.ts +18 -0
- package/lib/shapes/Ellipse.js +37 -0
- package/lib/shapes/Image.d.ts +29 -0
- package/lib/shapes/Image.js +131 -0
- package/lib/shapes/Label.d.ts +39 -0
- package/lib/shapes/Label.js +173 -0
- package/lib/shapes/Line.d.ts +29 -0
- package/lib/shapes/Line.js +156 -0
- package/lib/shapes/Path.d.ts +50 -0
- package/lib/shapes/Path.js +670 -0
- package/lib/shapes/Rect.d.ts +11 -0
- package/lib/shapes/Rect.js +22 -0
- package/lib/shapes/RegularPolygon.d.ts +26 -0
- package/lib/shapes/RegularPolygon.js +72 -0
- package/lib/shapes/Ring.d.ts +17 -0
- package/lib/shapes/Ring.js +33 -0
- package/lib/shapes/Sprite.d.ts +32 -0
- package/lib/shapes/Sprite.js +108 -0
- package/lib/shapes/Star.d.ts +19 -0
- package/lib/shapes/Star.js +38 -0
- package/lib/shapes/Text.d.ts +90 -0
- package/lib/shapes/Text.js +461 -0
- package/lib/shapes/TextPath.d.ts +72 -0
- package/lib/shapes/TextPath.js +268 -0
- package/lib/shapes/Transformer.d.ts +130 -0
- package/lib/shapes/Transformer.js +1009 -0
- package/lib/shapes/Wedge.d.ts +19 -0
- package/lib/shapes/Wedge.js +38 -0
- package/lib/skia-backend.d.ts +2 -0
- package/lib/skia-backend.js +24 -0
- package/lib/types.d.ts +56 -0
- package/lib/types.js +21 -0
- package/package.json +1 -1
package/lib/Canvas.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Context } from './Context.ts';
|
|
2
|
+
interface ICanvasConfig {
|
|
3
|
+
width?: number;
|
|
4
|
+
height?: number;
|
|
5
|
+
pixelRatio?: number;
|
|
6
|
+
willReadFrequently?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class Canvas {
|
|
9
|
+
pixelRatio: number;
|
|
10
|
+
_canvas: HTMLCanvasElement;
|
|
11
|
+
context: Context;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
isCache: boolean;
|
|
15
|
+
constructor(config: ICanvasConfig);
|
|
16
|
+
getContext(): Context;
|
|
17
|
+
getPixelRatio(): number;
|
|
18
|
+
setPixelRatio(pixelRatio: any): void;
|
|
19
|
+
setWidth(width: any): void;
|
|
20
|
+
setHeight(height: any): void;
|
|
21
|
+
getWidth(): number;
|
|
22
|
+
getHeight(): number;
|
|
23
|
+
setSize(width: any, height: any): void;
|
|
24
|
+
toDataURL(mimeType: any, quality: any): string;
|
|
25
|
+
}
|
|
26
|
+
export declare class SceneCanvas extends Canvas {
|
|
27
|
+
constructor(config?: ICanvasConfig);
|
|
28
|
+
}
|
|
29
|
+
export declare class HitCanvas extends Canvas {
|
|
30
|
+
hitCanvas: boolean;
|
|
31
|
+
constructor(config?: ICanvasConfig);
|
|
32
|
+
}
|
|
33
|
+
export {};
|
package/lib/Canvas.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Util } from "./Util.js";
|
|
2
|
+
import { SceneContext, HitContext } from "./Context.js";
|
|
3
|
+
import { Konva } from "./Global.js";
|
|
4
|
+
let _pixelRatio;
|
|
5
|
+
function getDevicePixelRatio() {
|
|
6
|
+
if (_pixelRatio) {
|
|
7
|
+
return _pixelRatio;
|
|
8
|
+
}
|
|
9
|
+
const canvas = Util.createCanvasElement();
|
|
10
|
+
const context = canvas.getContext('2d');
|
|
11
|
+
_pixelRatio = (function () {
|
|
12
|
+
const devicePixelRatio = Konva._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio ||
|
|
13
|
+
context.mozBackingStorePixelRatio ||
|
|
14
|
+
context.msBackingStorePixelRatio ||
|
|
15
|
+
context.oBackingStorePixelRatio ||
|
|
16
|
+
context.backingStorePixelRatio ||
|
|
17
|
+
1;
|
|
18
|
+
return devicePixelRatio / backingStoreRatio;
|
|
19
|
+
})();
|
|
20
|
+
Util.releaseCanvas(canvas);
|
|
21
|
+
return _pixelRatio;
|
|
22
|
+
}
|
|
23
|
+
export class Canvas {
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.pixelRatio = 1;
|
|
26
|
+
this.width = 0;
|
|
27
|
+
this.height = 0;
|
|
28
|
+
this.isCache = false;
|
|
29
|
+
const conf = config || {};
|
|
30
|
+
const pixelRatio = conf.pixelRatio || Konva.pixelRatio || getDevicePixelRatio();
|
|
31
|
+
this.pixelRatio = pixelRatio;
|
|
32
|
+
this._canvas = Util.createCanvasElement();
|
|
33
|
+
this._canvas.style.padding = '0';
|
|
34
|
+
this._canvas.style.margin = '0';
|
|
35
|
+
this._canvas.style.border = '0';
|
|
36
|
+
this._canvas.style.background = 'transparent';
|
|
37
|
+
this._canvas.style.position = 'absolute';
|
|
38
|
+
this._canvas.style.top = '0';
|
|
39
|
+
this._canvas.style.left = '0';
|
|
40
|
+
}
|
|
41
|
+
getContext() {
|
|
42
|
+
return this.context;
|
|
43
|
+
}
|
|
44
|
+
getPixelRatio() {
|
|
45
|
+
return this.pixelRatio;
|
|
46
|
+
}
|
|
47
|
+
setPixelRatio(pixelRatio) {
|
|
48
|
+
const previousRatio = this.pixelRatio;
|
|
49
|
+
this.pixelRatio = pixelRatio;
|
|
50
|
+
this.setSize(this.getWidth() / previousRatio, this.getHeight() / previousRatio);
|
|
51
|
+
}
|
|
52
|
+
setWidth(width) {
|
|
53
|
+
this.width = this._canvas.width = width * this.pixelRatio;
|
|
54
|
+
this._canvas.style.width = width + 'px';
|
|
55
|
+
const pixelRatio = this.pixelRatio, _context = this.getContext()._context;
|
|
56
|
+
_context.scale(pixelRatio, pixelRatio);
|
|
57
|
+
}
|
|
58
|
+
setHeight(height) {
|
|
59
|
+
this.height = this._canvas.height = height * this.pixelRatio;
|
|
60
|
+
this._canvas.style.height = height + 'px';
|
|
61
|
+
const pixelRatio = this.pixelRatio, _context = this.getContext()._context;
|
|
62
|
+
_context.scale(pixelRatio, pixelRatio);
|
|
63
|
+
}
|
|
64
|
+
getWidth() {
|
|
65
|
+
return this.width;
|
|
66
|
+
}
|
|
67
|
+
getHeight() {
|
|
68
|
+
return this.height;
|
|
69
|
+
}
|
|
70
|
+
setSize(width, height) {
|
|
71
|
+
this.setWidth(width || 0);
|
|
72
|
+
this.setHeight(height || 0);
|
|
73
|
+
}
|
|
74
|
+
toDataURL(mimeType, quality) {
|
|
75
|
+
try {
|
|
76
|
+
return this._canvas.toDataURL(mimeType, quality);
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
try {
|
|
80
|
+
return this._canvas.toDataURL();
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
Util.error('Unable to get data URL. ' +
|
|
84
|
+
err.message +
|
|
85
|
+
' For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html.');
|
|
86
|
+
return '';
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export class SceneCanvas extends Canvas {
|
|
92
|
+
constructor(config = { width: 0, height: 0, willReadFrequently: false }) {
|
|
93
|
+
super(config);
|
|
94
|
+
this.context = new SceneContext(this, {
|
|
95
|
+
willReadFrequently: config.willReadFrequently,
|
|
96
|
+
});
|
|
97
|
+
this.setSize(config.width, config.height);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export class HitCanvas extends Canvas {
|
|
101
|
+
constructor(config = { width: 0, height: 0 }) {
|
|
102
|
+
super(config);
|
|
103
|
+
this.hitCanvas = true;
|
|
104
|
+
this.context = new HitContext(this);
|
|
105
|
+
this.setSize(config.width, config.height);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { HitCanvas, SceneCanvas } from './Canvas.ts';
|
|
2
|
+
import type { SceneContext } from './Context.ts';
|
|
3
|
+
import type { NodeConfig } from './Node.ts';
|
|
4
|
+
import { Node } from './Node.ts';
|
|
5
|
+
import type { Shape } from './Shape.ts';
|
|
6
|
+
import type { GetSet, IRect } from './types.ts';
|
|
7
|
+
export type ClipFuncOutput = void | [Path2D | CanvasFillRule] | [Path2D, CanvasFillRule];
|
|
8
|
+
export interface ContainerConfig extends NodeConfig {
|
|
9
|
+
clearBeforeDraw?: boolean;
|
|
10
|
+
clipFunc?: (ctx: SceneContext) => ClipFuncOutput;
|
|
11
|
+
clipX?: number;
|
|
12
|
+
clipY?: number;
|
|
13
|
+
clipWidth?: number;
|
|
14
|
+
clipHeight?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare abstract class Container<ChildType extends Node = Node, Config extends ContainerConfig = ContainerConfig> extends Node<Config> {
|
|
17
|
+
children: Array<ChildType>;
|
|
18
|
+
getChildren(filterFunc?: (item: Node) => boolean): ChildType[];
|
|
19
|
+
hasChildren(): boolean;
|
|
20
|
+
removeChildren(): this;
|
|
21
|
+
destroyChildren(): this;
|
|
22
|
+
abstract _validateAdd(node: Node): void;
|
|
23
|
+
add(...children: ChildType[]): this;
|
|
24
|
+
destroy(): this;
|
|
25
|
+
find<ChildNode extends Node>(selector: any): Array<ChildNode>;
|
|
26
|
+
findOne<ChildNode extends Node = Node>(selector: string | Function): ChildNode | undefined;
|
|
27
|
+
_generalFind<ChildNode extends Node>(selector: string | Function, findOne: boolean): ChildNode[];
|
|
28
|
+
private _descendants;
|
|
29
|
+
toObject(): {
|
|
30
|
+
attrs: any;
|
|
31
|
+
className: string;
|
|
32
|
+
children?: Array<any>;
|
|
33
|
+
};
|
|
34
|
+
isAncestorOf(node: Node): boolean;
|
|
35
|
+
clone(obj?: any): this;
|
|
36
|
+
getAllIntersections(pos: any): Shape<import("./Shape.ts").ShapeConfig>[];
|
|
37
|
+
_clearSelfAndDescendantCache(attr?: string): void;
|
|
38
|
+
_setChildrenIndices(): void;
|
|
39
|
+
drawScene(can?: SceneCanvas, top?: Node, bufferCanvas?: SceneCanvas): this;
|
|
40
|
+
drawHit(can?: HitCanvas, top?: Node): this;
|
|
41
|
+
_drawChildren(drawMethod: any, canvas: any, top: any, bufferCanvas?: any): void;
|
|
42
|
+
getClientRect(config?: {
|
|
43
|
+
skipTransform?: boolean;
|
|
44
|
+
skipShadow?: boolean;
|
|
45
|
+
skipStroke?: boolean;
|
|
46
|
+
relativeTo?: Container<Node>;
|
|
47
|
+
}): IRect;
|
|
48
|
+
clip: GetSet<IRect, this>;
|
|
49
|
+
clipX: GetSet<number, this>;
|
|
50
|
+
clipY: GetSet<number, this>;
|
|
51
|
+
clipWidth: GetSet<number, this>;
|
|
52
|
+
clipHeight: GetSet<number, this>;
|
|
53
|
+
clipFunc: GetSet<(ctx: CanvasRenderingContext2D, shape: Container) => ClipFuncOutput, this>;
|
|
54
|
+
}
|
package/lib/Container.js
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { Factory } from "./Factory.js";
|
|
2
|
+
import { Node } from "./Node.js";
|
|
3
|
+
import { getNumberValidator } from "./Validators.js";
|
|
4
|
+
export class Container extends Node {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.children = [];
|
|
8
|
+
}
|
|
9
|
+
getChildren(filterFunc) {
|
|
10
|
+
const children = this.children || [];
|
|
11
|
+
if (filterFunc) {
|
|
12
|
+
return children.filter(filterFunc);
|
|
13
|
+
}
|
|
14
|
+
return children;
|
|
15
|
+
}
|
|
16
|
+
hasChildren() {
|
|
17
|
+
return this.getChildren().length > 0;
|
|
18
|
+
}
|
|
19
|
+
removeChildren() {
|
|
20
|
+
this.getChildren().forEach((child) => {
|
|
21
|
+
child.parent = null;
|
|
22
|
+
child.index = 0;
|
|
23
|
+
child.remove();
|
|
24
|
+
});
|
|
25
|
+
this.children = [];
|
|
26
|
+
this._requestDraw();
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
destroyChildren() {
|
|
30
|
+
this.getChildren().forEach((child) => {
|
|
31
|
+
child.parent = null;
|
|
32
|
+
child.index = 0;
|
|
33
|
+
child.destroy();
|
|
34
|
+
});
|
|
35
|
+
this.children = [];
|
|
36
|
+
this._requestDraw();
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
add(...children) {
|
|
40
|
+
if (children.length === 0) {
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
if (children.length > 1) {
|
|
44
|
+
for (let i = 0; i < children.length; i++) {
|
|
45
|
+
this.add(children[i]);
|
|
46
|
+
}
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
const child = children[0];
|
|
50
|
+
if (child.getParent()) {
|
|
51
|
+
child.moveTo(this);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
this._validateAdd(child);
|
|
55
|
+
child.index = this.getChildren().length;
|
|
56
|
+
child.parent = this;
|
|
57
|
+
child._clearCaches();
|
|
58
|
+
this.getChildren().push(child);
|
|
59
|
+
this._fire('add', {
|
|
60
|
+
child: child,
|
|
61
|
+
});
|
|
62
|
+
this._requestDraw();
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
destroy() {
|
|
66
|
+
if (this.hasChildren()) {
|
|
67
|
+
this.destroyChildren();
|
|
68
|
+
}
|
|
69
|
+
super.destroy();
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
find(selector) {
|
|
73
|
+
return this._generalFind(selector, false);
|
|
74
|
+
}
|
|
75
|
+
findOne(selector) {
|
|
76
|
+
const result = this._generalFind(selector, true);
|
|
77
|
+
return result.length > 0 ? result[0] : undefined;
|
|
78
|
+
}
|
|
79
|
+
_generalFind(selector, findOne) {
|
|
80
|
+
const retArr = [];
|
|
81
|
+
this._descendants((node) => {
|
|
82
|
+
const valid = node._isMatch(selector);
|
|
83
|
+
if (valid) {
|
|
84
|
+
retArr.push(node);
|
|
85
|
+
}
|
|
86
|
+
if (valid && findOne) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
});
|
|
91
|
+
return retArr;
|
|
92
|
+
}
|
|
93
|
+
_descendants(fn) {
|
|
94
|
+
let shouldStop = false;
|
|
95
|
+
const children = this.getChildren();
|
|
96
|
+
for (const child of children) {
|
|
97
|
+
shouldStop = fn(child);
|
|
98
|
+
if (shouldStop) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
if (!child.hasChildren()) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
shouldStop = child._descendants(fn);
|
|
105
|
+
if (shouldStop) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
toObject() {
|
|
112
|
+
const obj = Node.prototype.toObject.call(this);
|
|
113
|
+
obj.children = [];
|
|
114
|
+
this.getChildren().forEach((child) => {
|
|
115
|
+
obj.children.push(child.toObject());
|
|
116
|
+
});
|
|
117
|
+
return obj;
|
|
118
|
+
}
|
|
119
|
+
isAncestorOf(node) {
|
|
120
|
+
let parent = node.getParent();
|
|
121
|
+
while (parent) {
|
|
122
|
+
if (parent._id === this._id) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
parent = parent.getParent();
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
clone(obj) {
|
|
130
|
+
const node = Node.prototype.clone.call(this, obj);
|
|
131
|
+
this.getChildren().forEach(function (no) {
|
|
132
|
+
node.add(no.clone());
|
|
133
|
+
});
|
|
134
|
+
return node;
|
|
135
|
+
}
|
|
136
|
+
getAllIntersections(pos) {
|
|
137
|
+
const arr = [];
|
|
138
|
+
this.find('Shape').forEach((shape) => {
|
|
139
|
+
if (shape.isVisible() && shape.intersects(pos)) {
|
|
140
|
+
arr.push(shape);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return arr;
|
|
144
|
+
}
|
|
145
|
+
_clearSelfAndDescendantCache(attr) {
|
|
146
|
+
var _a;
|
|
147
|
+
super._clearSelfAndDescendantCache(attr);
|
|
148
|
+
if (this.isCached()) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (node) {
|
|
152
|
+
node._clearSelfAndDescendantCache(attr);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
_setChildrenIndices() {
|
|
156
|
+
var _a;
|
|
157
|
+
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child, n) {
|
|
158
|
+
child.index = n;
|
|
159
|
+
});
|
|
160
|
+
this._requestDraw();
|
|
161
|
+
}
|
|
162
|
+
drawScene(can, top, bufferCanvas) {
|
|
163
|
+
const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;
|
|
164
|
+
const caching = canvas && canvas.isCache;
|
|
165
|
+
if (!this.isVisible() && !caching) {
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
if (cachedSceneCanvas) {
|
|
169
|
+
context.save();
|
|
170
|
+
const m = this.getAbsoluteTransform(top).getMatrix();
|
|
171
|
+
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
172
|
+
this._drawCachedSceneCanvas(context);
|
|
173
|
+
context.restore();
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
this._drawChildren('drawScene', canvas, top, bufferCanvas);
|
|
177
|
+
}
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
drawHit(can, top) {
|
|
181
|
+
if (!this.shouldDrawHit(top)) {
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
const layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
|
185
|
+
if (cachedHitCanvas) {
|
|
186
|
+
context.save();
|
|
187
|
+
const m = this.getAbsoluteTransform(top).getMatrix();
|
|
188
|
+
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
189
|
+
this._drawCachedHitCanvas(context);
|
|
190
|
+
context.restore();
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
this._drawChildren('drawHit', canvas, top);
|
|
194
|
+
}
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
_drawChildren(drawMethod, canvas, top, bufferCanvas) {
|
|
198
|
+
var _a;
|
|
199
|
+
const context = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = (typeof clipWidth === 'number' && typeof clipHeight === 'number') ||
|
|
200
|
+
clipFunc;
|
|
201
|
+
const selfCache = top === this;
|
|
202
|
+
if (hasClip) {
|
|
203
|
+
context.save();
|
|
204
|
+
const transform = this.getAbsoluteTransform(top);
|
|
205
|
+
let m = transform.getMatrix();
|
|
206
|
+
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
207
|
+
context.beginPath();
|
|
208
|
+
let clipArgs;
|
|
209
|
+
if (clipFunc) {
|
|
210
|
+
clipArgs = clipFunc.call(this, context, this);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
const clipX = this.clipX();
|
|
214
|
+
const clipY = this.clipY();
|
|
215
|
+
context.rect(clipX || 0, clipY || 0, clipWidth, clipHeight);
|
|
216
|
+
}
|
|
217
|
+
context.clip.apply(context, clipArgs);
|
|
218
|
+
m = transform.copy().invert().getMatrix();
|
|
219
|
+
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
220
|
+
}
|
|
221
|
+
const hasComposition = !selfCache &&
|
|
222
|
+
this.globalCompositeOperation() !== 'source-over' &&
|
|
223
|
+
drawMethod === 'drawScene';
|
|
224
|
+
if (hasComposition) {
|
|
225
|
+
context.save();
|
|
226
|
+
context._applyGlobalCompositeOperation(this);
|
|
227
|
+
}
|
|
228
|
+
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
|
|
229
|
+
child[drawMethod](canvas, top, bufferCanvas);
|
|
230
|
+
});
|
|
231
|
+
if (hasComposition) {
|
|
232
|
+
context.restore();
|
|
233
|
+
}
|
|
234
|
+
if (hasClip) {
|
|
235
|
+
context.restore();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
getClientRect(config = {}) {
|
|
239
|
+
var _a;
|
|
240
|
+
const skipTransform = config.skipTransform;
|
|
241
|
+
const relativeTo = config.relativeTo;
|
|
242
|
+
let minX, minY, maxX, maxY;
|
|
243
|
+
let selfRect = {
|
|
244
|
+
x: Infinity,
|
|
245
|
+
y: Infinity,
|
|
246
|
+
width: 0,
|
|
247
|
+
height: 0,
|
|
248
|
+
};
|
|
249
|
+
const that = this;
|
|
250
|
+
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
|
|
251
|
+
if (!child.visible()) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const rect = child.getClientRect({
|
|
255
|
+
relativeTo: that,
|
|
256
|
+
skipShadow: config.skipShadow,
|
|
257
|
+
skipStroke: config.skipStroke,
|
|
258
|
+
});
|
|
259
|
+
if (rect.width === 0 && rect.height === 0) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (minX === undefined) {
|
|
263
|
+
minX = rect.x;
|
|
264
|
+
minY = rect.y;
|
|
265
|
+
maxX = rect.x + rect.width;
|
|
266
|
+
maxY = rect.y + rect.height;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
minX = Math.min(minX, rect.x);
|
|
270
|
+
minY = Math.min(minY, rect.y);
|
|
271
|
+
maxX = Math.max(maxX, rect.x + rect.width);
|
|
272
|
+
maxY = Math.max(maxY, rect.y + rect.height);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
const shapes = this.find('Shape');
|
|
276
|
+
let hasVisible = false;
|
|
277
|
+
for (let i = 0; i < shapes.length; i++) {
|
|
278
|
+
const shape = shapes[i];
|
|
279
|
+
if (shape._isVisible(this)) {
|
|
280
|
+
hasVisible = true;
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (hasVisible && minX !== undefined) {
|
|
285
|
+
selfRect = {
|
|
286
|
+
x: minX,
|
|
287
|
+
y: minY,
|
|
288
|
+
width: maxX - minX,
|
|
289
|
+
height: maxY - minY,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
selfRect = {
|
|
294
|
+
x: 0,
|
|
295
|
+
y: 0,
|
|
296
|
+
width: 0,
|
|
297
|
+
height: 0,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
if (!skipTransform) {
|
|
301
|
+
return this._transformedRect(selfRect, relativeTo);
|
|
302
|
+
}
|
|
303
|
+
return selfRect;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
Factory.addComponentsGetterSetter(Container, 'clip', [
|
|
307
|
+
'x',
|
|
308
|
+
'y',
|
|
309
|
+
'width',
|
|
310
|
+
'height',
|
|
311
|
+
]);
|
|
312
|
+
Factory.addGetterSetter(Container, 'clipX', undefined, getNumberValidator());
|
|
313
|
+
Factory.addGetterSetter(Container, 'clipY', undefined, getNumberValidator());
|
|
314
|
+
Factory.addGetterSetter(Container, 'clipWidth', undefined, getNumberValidator());
|
|
315
|
+
Factory.addGetterSetter(Container, 'clipHeight', undefined, getNumberValidator());
|
|
316
|
+
Factory.addGetterSetter(Container, 'clipFunc');
|
package/lib/Context.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Canvas } from './Canvas.ts';
|
|
2
|
+
import type { Shape } from './Shape.ts';
|
|
3
|
+
import type { IRect } from './types.ts';
|
|
4
|
+
import type { Node } from './Node.ts';
|
|
5
|
+
declare const CONTEXT_PROPERTIES: readonly ["fillStyle", "strokeStyle", "shadowColor", "shadowBlur", "shadowOffsetX", "shadowOffsetY", "letterSpacing", "lineCap", "lineDashOffset", "lineJoin", "lineWidth", "miterLimit", "direction", "font", "textAlign", "textBaseline", "globalAlpha", "globalCompositeOperation", "imageSmoothingEnabled", "filter"];
|
|
6
|
+
export declare function isCSSFiltersSupported(): boolean;
|
|
7
|
+
interface ExtendedCanvasRenderingContext2D extends CanvasRenderingContext2D {
|
|
8
|
+
letterSpacing: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class Context {
|
|
11
|
+
canvas: Canvas;
|
|
12
|
+
_context: CanvasRenderingContext2D;
|
|
13
|
+
traceArr: Array<string>;
|
|
14
|
+
constructor(canvas: Canvas);
|
|
15
|
+
fillShape(shape: Shape): void;
|
|
16
|
+
_fill(shape: Shape): void;
|
|
17
|
+
strokeShape(shape: Shape): void;
|
|
18
|
+
_stroke(shape: Shape): void;
|
|
19
|
+
fillStrokeShape(shape: Shape): void;
|
|
20
|
+
getTrace(relaxed?: boolean, rounded?: boolean): string;
|
|
21
|
+
clearTrace(): void;
|
|
22
|
+
_trace(str: any): void;
|
|
23
|
+
reset(): void;
|
|
24
|
+
getCanvas(): Canvas;
|
|
25
|
+
clear(bounds?: IRect): void;
|
|
26
|
+
_applyLineCap(shape: Shape): void;
|
|
27
|
+
_applyOpacity(shape: Node): void;
|
|
28
|
+
_applyLineJoin(shape: Shape): void;
|
|
29
|
+
_applyMiterLimit(shape: Shape): void;
|
|
30
|
+
setAttr(attr: string, val: any): void;
|
|
31
|
+
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterClockwise?: boolean): void;
|
|
32
|
+
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
|
|
33
|
+
beginPath(): void;
|
|
34
|
+
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
|
|
35
|
+
clearRect(x: number, y: number, width: number, height: number): void;
|
|
36
|
+
clip(fillRule?: CanvasFillRule): void;
|
|
37
|
+
clip(path: Path2D, fillRule?: CanvasFillRule): void;
|
|
38
|
+
closePath(): void;
|
|
39
|
+
createImageData(width: any, height: any): ImageData | undefined;
|
|
40
|
+
createLinearGradient(x0: number, y0: number, x1: number, y1: number): CanvasGradient;
|
|
41
|
+
createPattern(image: CanvasImageSource, repetition: string | null): CanvasPattern | null;
|
|
42
|
+
createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): CanvasGradient;
|
|
43
|
+
drawImage(image: CanvasImageSource, sx: number, sy: number, sWidth?: number, sHeight?: number, dx?: number, dy?: number, dWidth?: number, dHeight?: number): void;
|
|
44
|
+
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void;
|
|
45
|
+
isPointInPath(x: number, y: number, path?: Path2D, fillRule?: CanvasFillRule): boolean;
|
|
46
|
+
fill(fillRule?: CanvasFillRule): void;
|
|
47
|
+
fill(path: Path2D, fillRule?: CanvasFillRule): void;
|
|
48
|
+
fillRect(x: number, y: number, width: number, height: number): void;
|
|
49
|
+
strokeRect(x: number, y: number, width: number, height: number): void;
|
|
50
|
+
fillText(text: string, x: number, y: number, maxWidth?: number): void;
|
|
51
|
+
measureText(text: string): TextMetrics;
|
|
52
|
+
getImageData(sx: number, sy: number, sw: number, sh: number): ImageData;
|
|
53
|
+
lineTo(x: number, y: number): void;
|
|
54
|
+
moveTo(x: number, y: number): void;
|
|
55
|
+
rect(x: number, y: number, width: number, height: number): void;
|
|
56
|
+
roundRect(x: number, y: number, width: number, height: number, radii: number | DOMPointInit | (number | DOMPointInit)[]): void;
|
|
57
|
+
putImageData(imageData: ImageData, dx: number, dy: number): void;
|
|
58
|
+
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
|
|
59
|
+
restore(): void;
|
|
60
|
+
rotate(angle: number): void;
|
|
61
|
+
save(): void;
|
|
62
|
+
scale(x: number, y: number): void;
|
|
63
|
+
setLineDash(segments: number[]): void;
|
|
64
|
+
getLineDash(): number[];
|
|
65
|
+
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
66
|
+
stroke(path2d?: Path2D): void;
|
|
67
|
+
strokeText(text: string, x: number, y: number, maxWidth?: number): void;
|
|
68
|
+
transform(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
69
|
+
translate(x: number, y: number): void;
|
|
70
|
+
_enableTrace(): void;
|
|
71
|
+
_applyGlobalCompositeOperation(node: any): void;
|
|
72
|
+
}
|
|
73
|
+
type CanvasContextProps = Pick<ExtendedCanvasRenderingContext2D, (typeof CONTEXT_PROPERTIES)[number]>;
|
|
74
|
+
export interface Context extends CanvasContextProps {
|
|
75
|
+
}
|
|
76
|
+
export declare class SceneContext extends Context {
|
|
77
|
+
constructor(canvas: Canvas, { willReadFrequently }?: {
|
|
78
|
+
willReadFrequently?: boolean | undefined;
|
|
79
|
+
});
|
|
80
|
+
_fillColor(shape: Shape): void;
|
|
81
|
+
_fillPattern(shape: Shape): void;
|
|
82
|
+
_fillLinearGradient(shape: Shape): void;
|
|
83
|
+
_fillRadialGradient(shape: Shape): void;
|
|
84
|
+
_fill(shape: any): void;
|
|
85
|
+
_strokeLinearGradient(shape: any): void;
|
|
86
|
+
_stroke(shape: any): void;
|
|
87
|
+
_applyShadow(shape: any): void;
|
|
88
|
+
}
|
|
89
|
+
export declare class HitContext extends Context {
|
|
90
|
+
constructor(canvas: Canvas);
|
|
91
|
+
_fill(shape: Shape): void;
|
|
92
|
+
strokeShape(shape: Shape): void;
|
|
93
|
+
_stroke(shape: any): void;
|
|
94
|
+
}
|
|
95
|
+
export {};
|