konva 10.0.9 → 10.0.10

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.
Files changed (127) hide show
  1. package/konva.js +90 -44
  2. package/konva.min.js +4 -4
  3. package/package.json +1 -1
  4. package/lib/Animation.d.ts +0 -24
  5. package/lib/Animation.js +0 -142
  6. package/lib/BezierFunctions.d.ts +0 -6
  7. package/lib/BezierFunctions.js +0 -784
  8. package/lib/Canvas.d.ts +0 -33
  9. package/lib/Canvas.js +0 -137
  10. package/lib/Container.d.ts +0 -54
  11. package/lib/Container.js +0 -316
  12. package/lib/Context.d.ts +0 -95
  13. package/lib/Context.js +0 -561
  14. package/lib/Core.d.ts +0 -3
  15. package/lib/Core.js +0 -3
  16. package/lib/DragAndDrop.d.ts +0 -17
  17. package/lib/DragAndDrop.js +0 -110
  18. package/lib/Factory.d.ts +0 -22
  19. package/lib/Factory.js +0 -123
  20. package/lib/FastLayer.d.ts +0 -4
  21. package/lib/FastLayer.js +0 -12
  22. package/lib/Global.d.ts +0 -37
  23. package/lib/Global.js +0 -66
  24. package/lib/Group.d.ts +0 -9
  25. package/lib/Group.js +0 -13
  26. package/lib/Layer.d.ts +0 -62
  27. package/lib/Layer.js +0 -305
  28. package/lib/Node.d.ts +0 -323
  29. package/lib/Node.js +0 -1532
  30. package/lib/PointerEvents.d.ts +0 -11
  31. package/lib/PointerEvents.js +0 -37
  32. package/lib/Shape.d.ts +0 -196
  33. package/lib/Shape.js +0 -548
  34. package/lib/Stage.d.ts +0 -86
  35. package/lib/Stage.js +0 -715
  36. package/lib/Tween.d.ts +0 -90
  37. package/lib/Tween.js +0 -531
  38. package/lib/Util.d.ts +0 -133
  39. package/lib/Util.js +0 -866
  40. package/lib/Validators.d.ts +0 -11
  41. package/lib/Validators.js +0 -178
  42. package/lib/_CoreInternals.d.ts +0 -220
  43. package/lib/_CoreInternals.js +0 -34
  44. package/lib/_FullInternals.d.ts +0 -302
  45. package/lib/_FullInternals.js +0 -80
  46. package/lib/canvas-backend.d.ts +0 -2
  47. package/lib/canvas-backend.js +0 -27
  48. package/lib/filters/Blur.d.ts +0 -2
  49. package/lib/filters/Blur.js +0 -235
  50. package/lib/filters/Brighten.d.ts +0 -2
  51. package/lib/filters/Brighten.js +0 -12
  52. package/lib/filters/Brightness.d.ts +0 -2
  53. package/lib/filters/Brightness.js +0 -8
  54. package/lib/filters/Contrast.d.ts +0 -2
  55. package/lib/filters/Contrast.js +0 -35
  56. package/lib/filters/Emboss.d.ts +0 -2
  57. package/lib/filters/Emboss.js +0 -101
  58. package/lib/filters/Enhance.d.ts +0 -2
  59. package/lib/filters/Enhance.js +0 -84
  60. package/lib/filters/Grayscale.d.ts +0 -2
  61. package/lib/filters/Grayscale.js +0 -9
  62. package/lib/filters/HSL.d.ts +0 -2
  63. package/lib/filters/HSL.js +0 -24
  64. package/lib/filters/HSV.d.ts +0 -2
  65. package/lib/filters/HSV.js +0 -23
  66. package/lib/filters/Invert.d.ts +0 -2
  67. package/lib/filters/Invert.js +0 -8
  68. package/lib/filters/Kaleidoscope.d.ts +0 -2
  69. package/lib/filters/Kaleidoscope.js +0 -133
  70. package/lib/filters/Mask.d.ts +0 -2
  71. package/lib/filters/Mask.js +0 -151
  72. package/lib/filters/Noise.d.ts +0 -2
  73. package/lib/filters/Noise.js +0 -12
  74. package/lib/filters/Pixelate.d.ts +0 -2
  75. package/lib/filters/Pixelate.js +0 -60
  76. package/lib/filters/Posterize.d.ts +0 -2
  77. package/lib/filters/Posterize.js +0 -10
  78. package/lib/filters/RGB.d.ts +0 -2
  79. package/lib/filters/RGB.js +0 -38
  80. package/lib/filters/RGBA.d.ts +0 -2
  81. package/lib/filters/RGBA.js +0 -49
  82. package/lib/filters/Sepia.d.ts +0 -2
  83. package/lib/filters/Sepia.js +0 -11
  84. package/lib/filters/Solarize.d.ts +0 -2
  85. package/lib/filters/Solarize.js +0 -14
  86. package/lib/filters/Threshold.d.ts +0 -2
  87. package/lib/filters/Threshold.js +0 -10
  88. package/lib/index.d.ts +0 -2
  89. package/lib/index.js +0 -2
  90. package/lib/shapes/Arc.d.ts +0 -27
  91. package/lib/shapes/Arc.js +0 -60
  92. package/lib/shapes/Arrow.d.ts +0 -27
  93. package/lib/shapes/Arrow.js +0 -99
  94. package/lib/shapes/Circle.d.ts +0 -15
  95. package/lib/shapes/Circle.js +0 -33
  96. package/lib/shapes/Ellipse.d.ts +0 -18
  97. package/lib/shapes/Ellipse.js +0 -37
  98. package/lib/shapes/Image.d.ts +0 -29
  99. package/lib/shapes/Image.js +0 -131
  100. package/lib/shapes/Label.d.ts +0 -39
  101. package/lib/shapes/Label.js +0 -173
  102. package/lib/shapes/Line.d.ts +0 -29
  103. package/lib/shapes/Line.js +0 -156
  104. package/lib/shapes/Path.d.ts +0 -50
  105. package/lib/shapes/Path.js +0 -670
  106. package/lib/shapes/Rect.d.ts +0 -11
  107. package/lib/shapes/Rect.js +0 -22
  108. package/lib/shapes/RegularPolygon.d.ts +0 -26
  109. package/lib/shapes/RegularPolygon.js +0 -72
  110. package/lib/shapes/Ring.d.ts +0 -17
  111. package/lib/shapes/Ring.js +0 -33
  112. package/lib/shapes/Sprite.d.ts +0 -32
  113. package/lib/shapes/Sprite.js +0 -108
  114. package/lib/shapes/Star.d.ts +0 -19
  115. package/lib/shapes/Star.js +0 -38
  116. package/lib/shapes/Text.d.ts +0 -90
  117. package/lib/shapes/Text.js +0 -461
  118. package/lib/shapes/TextPath.d.ts +0 -72
  119. package/lib/shapes/TextPath.js +0 -268
  120. package/lib/shapes/Transformer.d.ts +0 -130
  121. package/lib/shapes/Transformer.js +0 -1009
  122. package/lib/shapes/Wedge.d.ts +0 -19
  123. package/lib/shapes/Wedge.js +0 -38
  124. package/lib/skia-backend.d.ts +0 -2
  125. package/lib/skia-backend.js +0 -24
  126. package/lib/types.d.ts +0 -56
  127. package/lib/types.js +0 -21
package/lib/Canvas.d.ts DELETED
@@ -1,33 +0,0 @@
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 DELETED
@@ -1,137 +0,0 @@
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
- function isCanvasFarblingActive() {
101
- const c = Util.createCanvasElement();
102
- c.width = 1;
103
- c.height = 1;
104
- const ctx = c.getContext('2d', {
105
- willReadFrequently: true,
106
- });
107
- ctx.clearRect(0, 0, 1, 1);
108
- ctx.fillStyle = 'rgba(255,0,255,1)';
109
- ctx.fillRect(0, 0, 1, 1);
110
- const d = ctx.getImageData(0, 0, 1, 1).data;
111
- const exact = d[0] === 255 && d[1] === 0 && d[2] === 255 && d[3] === 255;
112
- return !exact;
113
- }
114
- function isBraveBrowser() {
115
- var _a, _b;
116
- if (typeof navigator === 'undefined') {
117
- return false;
118
- }
119
- return (_b = (_a = navigator.brave) === null || _a === void 0 ? void 0 : _a.isBrave()) !== null && _b !== void 0 ? _b : false;
120
- }
121
- let warned = false;
122
- function checkHitCanvasSupport() {
123
- if (isBraveBrowser() && isCanvasFarblingActive() && !warned) {
124
- warned = true;
125
- Util.error('Looks like you have "Brave shield" enabled in your browser. It breaks KonvaJS internals. Please disable it. You may need to ask your users to do the same.');
126
- }
127
- return isBraveBrowser() && isCanvasFarblingActive();
128
- }
129
- export class HitCanvas extends Canvas {
130
- constructor(config = { width: 0, height: 0 }) {
131
- super(config);
132
- this.hitCanvas = true;
133
- this.context = new HitContext(this);
134
- this.setSize(config.width, config.height);
135
- checkHitCanvasSupport();
136
- }
137
- }
@@ -1,54 +0,0 @@
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 DELETED
@@ -1,316 +0,0 @@
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 DELETED
@@ -1,95 +0,0 @@
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 {};