konva 10.0.8 → 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 +95 -48
  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 -460
  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
@@ -1,268 +0,0 @@
1
- import { Util } from "../Util.js";
2
- import { Factory } from "../Factory.js";
3
- import { Shape } from "../Shape.js";
4
- import { Path } from "./Path.js";
5
- import { Text, stringToArray } from "./Text.js";
6
- import { getNumberValidator } from "../Validators.js";
7
- import { _registerNode } from "../Global.js";
8
- const EMPTY_STRING = '', NORMAL = 'normal';
9
- function _fillFunc(context) {
10
- context.fillText(this.partialText, 0, 0);
11
- }
12
- function _strokeFunc(context) {
13
- context.strokeText(this.partialText, 0, 0);
14
- }
15
- export class TextPath extends Shape {
16
- constructor(config) {
17
- super(config);
18
- this.dummyCanvas = Util.createCanvasElement();
19
- this.dataArray = [];
20
- this._readDataAttribute();
21
- this.on('dataChange.konva', function () {
22
- this._readDataAttribute();
23
- this._setTextData();
24
- });
25
- this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva', this._setTextData);
26
- this._setTextData();
27
- }
28
- _getTextPathLength() {
29
- return Path.getPathLength(this.dataArray);
30
- }
31
- _getPointAtLength(length) {
32
- if (!this.attrs.data) {
33
- return null;
34
- }
35
- const totalLength = this.pathLength;
36
- if (length > totalLength) {
37
- return null;
38
- }
39
- return Path.getPointAtLengthOfDataArray(length, this.dataArray);
40
- }
41
- _readDataAttribute() {
42
- this.dataArray = Path.parsePathData(this.attrs.data);
43
- this.pathLength = this._getTextPathLength();
44
- }
45
- _sceneFunc(context) {
46
- context.setAttr('font', this._getContextFont());
47
- context.setAttr('textBaseline', this.textBaseline());
48
- context.setAttr('textAlign', 'left');
49
- context.save();
50
- const textDecoration = this.textDecoration();
51
- const fill = this.fill();
52
- const fontSize = this.fontSize();
53
- const glyphInfo = this.glyphInfo;
54
- const hasUnderline = textDecoration.indexOf('underline') !== -1;
55
- const hasLineThrough = textDecoration.indexOf('line-through') !== -1;
56
- if (hasUnderline) {
57
- context.beginPath();
58
- }
59
- for (let i = 0; i < glyphInfo.length; i++) {
60
- context.save();
61
- const p0 = glyphInfo[i].p0;
62
- context.translate(p0.x, p0.y);
63
- context.rotate(glyphInfo[i].rotation);
64
- this.partialText = glyphInfo[i].text;
65
- context.fillStrokeShape(this);
66
- if (hasUnderline) {
67
- if (i === 0) {
68
- context.moveTo(0, fontSize / 2 + 1);
69
- }
70
- context.lineTo(glyphInfo[i].width, fontSize / 2 + 1);
71
- }
72
- context.restore();
73
- }
74
- if (hasUnderline) {
75
- context.strokeStyle = fill;
76
- context.lineWidth = fontSize / 20;
77
- context.stroke();
78
- }
79
- if (hasLineThrough) {
80
- context.beginPath();
81
- for (let i = 0; i < glyphInfo.length; i++) {
82
- context.save();
83
- const p0 = glyphInfo[i].p0;
84
- context.translate(p0.x, p0.y);
85
- context.rotate(glyphInfo[i].rotation);
86
- if (i === 0) {
87
- context.moveTo(0, 0);
88
- }
89
- context.lineTo(glyphInfo[i].width, 0);
90
- context.restore();
91
- }
92
- context.strokeStyle = fill;
93
- context.lineWidth = fontSize / 20;
94
- context.stroke();
95
- }
96
- context.restore();
97
- }
98
- _hitFunc(context) {
99
- context.beginPath();
100
- const glyphInfo = this.glyphInfo;
101
- if (glyphInfo.length >= 1) {
102
- const p0 = glyphInfo[0].p0;
103
- context.moveTo(p0.x, p0.y);
104
- }
105
- for (let i = 0; i < glyphInfo.length; i++) {
106
- const p1 = glyphInfo[i].p1;
107
- context.lineTo(p1.x, p1.y);
108
- }
109
- context.setAttr('lineWidth', this.fontSize());
110
- context.setAttr('strokeStyle', this.colorKey);
111
- context.stroke();
112
- }
113
- getTextWidth() {
114
- return this.textWidth;
115
- }
116
- getTextHeight() {
117
- Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
118
- return this.textHeight;
119
- }
120
- setText(text) {
121
- return Text.prototype.setText.call(this, text);
122
- }
123
- _getContextFont() {
124
- return Text.prototype._getContextFont.call(this);
125
- }
126
- _getTextSize(text) {
127
- const dummyCanvas = this.dummyCanvas;
128
- const _context = dummyCanvas.getContext('2d');
129
- _context.save();
130
- _context.font = this._getContextFont();
131
- const metrics = _context.measureText(text);
132
- _context.restore();
133
- return {
134
- width: metrics.width,
135
- height: parseInt(`${this.fontSize()}`, 10),
136
- };
137
- }
138
- _setTextData() {
139
- const charArr = stringToArray(this.text());
140
- const chars = [];
141
- let width = 0;
142
- for (let i = 0; i < charArr.length; i++) {
143
- chars.push({
144
- char: charArr[i],
145
- width: this._getTextSize(charArr[i]).width,
146
- });
147
- width += chars[i].width;
148
- }
149
- const { height } = this._getTextSize(this.attrs.text);
150
- this.textWidth = width;
151
- this.textHeight = height;
152
- this.glyphInfo = [];
153
- if (!this.attrs.data) {
154
- return null;
155
- }
156
- const letterSpacing = this.letterSpacing();
157
- const align = this.align();
158
- const kerningFunc = this.kerningFunc();
159
- const textWidth = Math.max(this.textWidth + ((this.attrs.text || '').length - 1) * letterSpacing, 0);
160
- let offset = 0;
161
- if (align === 'center') {
162
- offset = Math.max(0, this.pathLength / 2 - textWidth / 2);
163
- }
164
- if (align === 'right') {
165
- offset = Math.max(0, this.pathLength - textWidth);
166
- }
167
- let offsetToGlyph = offset;
168
- for (let i = 0; i < chars.length; i++) {
169
- const charStartPoint = this._getPointAtLength(offsetToGlyph);
170
- if (!charStartPoint)
171
- return;
172
- const char = chars[i].char;
173
- let glyphWidth = chars[i].width + letterSpacing;
174
- if (char === ' ' && align === 'justify') {
175
- const numberOfSpaces = this.text().split(' ').length - 1;
176
- glyphWidth += (this.pathLength - textWidth) / numberOfSpaces;
177
- }
178
- const charEndPoint = this._getPointAtLength(offsetToGlyph + glyphWidth);
179
- if (!charEndPoint) {
180
- return;
181
- }
182
- const width = Path.getLineLength(charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
183
- let kern = 0;
184
- if (kerningFunc) {
185
- try {
186
- kern = kerningFunc(chars[i - 1].char, char) * this.fontSize();
187
- }
188
- catch (e) {
189
- kern = 0;
190
- }
191
- }
192
- charStartPoint.x += kern;
193
- charEndPoint.x += kern;
194
- this.textWidth += kern;
195
- const midpoint = Path.getPointOnLine(kern + width / 2.0, charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
196
- const rotation = Math.atan2(charEndPoint.y - charStartPoint.y, charEndPoint.x - charStartPoint.x);
197
- this.glyphInfo.push({
198
- transposeX: midpoint.x,
199
- transposeY: midpoint.y,
200
- text: charArr[i],
201
- rotation: rotation,
202
- p0: charStartPoint,
203
- p1: charEndPoint,
204
- width: width,
205
- });
206
- offsetToGlyph += glyphWidth;
207
- }
208
- }
209
- getSelfRect() {
210
- if (!this.glyphInfo.length) {
211
- return {
212
- x: 0,
213
- y: 0,
214
- width: 0,
215
- height: 0,
216
- };
217
- }
218
- const points = [];
219
- this.glyphInfo.forEach(function (info) {
220
- points.push(info.p0.x);
221
- points.push(info.p0.y);
222
- points.push(info.p1.x);
223
- points.push(info.p1.y);
224
- });
225
- let minX = points[0] || 0;
226
- let maxX = points[0] || 0;
227
- let minY = points[1] || 0;
228
- let maxY = points[1] || 0;
229
- let x, y;
230
- for (let i = 0; i < points.length / 2; i++) {
231
- x = points[i * 2];
232
- y = points[i * 2 + 1];
233
- minX = Math.min(minX, x);
234
- maxX = Math.max(maxX, x);
235
- minY = Math.min(minY, y);
236
- maxY = Math.max(maxY, y);
237
- }
238
- const fontSize = this.fontSize();
239
- return {
240
- x: minX - fontSize / 2,
241
- y: minY - fontSize / 2,
242
- width: maxX - minX + fontSize,
243
- height: maxY - minY + fontSize,
244
- };
245
- }
246
- destroy() {
247
- Util.releaseCanvas(this.dummyCanvas);
248
- return super.destroy();
249
- }
250
- }
251
- TextPath.prototype._fillFunc = _fillFunc;
252
- TextPath.prototype._strokeFunc = _strokeFunc;
253
- TextPath.prototype._fillFuncHit = _fillFunc;
254
- TextPath.prototype._strokeFuncHit = _strokeFunc;
255
- TextPath.prototype.className = 'TextPath';
256
- TextPath.prototype._attrsAffectingSize = ['text', 'fontSize', 'data'];
257
- _registerNode(TextPath);
258
- Factory.addGetterSetter(TextPath, 'data');
259
- Factory.addGetterSetter(TextPath, 'fontFamily', 'Arial');
260
- Factory.addGetterSetter(TextPath, 'fontSize', 12, getNumberValidator());
261
- Factory.addGetterSetter(TextPath, 'fontStyle', NORMAL);
262
- Factory.addGetterSetter(TextPath, 'align', 'left');
263
- Factory.addGetterSetter(TextPath, 'letterSpacing', 0, getNumberValidator());
264
- Factory.addGetterSetter(TextPath, 'textBaseline', 'middle');
265
- Factory.addGetterSetter(TextPath, 'fontVariant', NORMAL);
266
- Factory.addGetterSetter(TextPath, 'text', EMPTY_STRING);
267
- Factory.addGetterSetter(TextPath, 'textDecoration', '');
268
- Factory.addGetterSetter(TextPath, 'kerningFunc', undefined);
@@ -1,130 +0,0 @@
1
- import { Transform } from '../Util.ts';
2
- import { Node } from '../Node.ts';
3
- import { Rect } from './Rect.ts';
4
- import { Group } from '../Group.ts';
5
- import type { ContainerConfig } from '../Container.ts';
6
- import type { GetSet, IRect, Vector2d } from '../types.ts';
7
- export interface Box extends IRect {
8
- rotation: number;
9
- }
10
- export interface TransformerConfig extends ContainerConfig {
11
- resizeEnabled?: boolean;
12
- rotateEnabled?: boolean;
13
- rotateLineVisible?: boolean;
14
- rotationSnaps?: Array<number>;
15
- rotationSnapTolerance?: number;
16
- rotateAnchorOffset?: number;
17
- rotateAnchorCursor?: string;
18
- borderEnabled?: boolean;
19
- borderStroke?: string;
20
- borderStrokeWidth?: number;
21
- borderDash?: Array<number>;
22
- anchorFill?: string;
23
- anchorStroke?: string;
24
- anchorStrokeWidth?: number;
25
- anchorSize?: number;
26
- anchorCornerRadius?: number;
27
- keepRatio?: boolean;
28
- shiftBehavior?: string;
29
- centeredScaling?: boolean;
30
- enabledAnchors?: Array<string>;
31
- flipEnabled?: boolean;
32
- node?: Rect;
33
- ignoreStroke?: boolean;
34
- boundBoxFunc?: (oldBox: Box, newBox: Box) => Box;
35
- useSingleNodeRotation?: boolean;
36
- shouldOverdrawWholeArea?: boolean;
37
- anchorDragBoundFunc?: (oldPos: Vector2d, newPos: Vector2d, evt: any) => Vector2d;
38
- anchorStyleFunc?: (anchor: Rect) => void;
39
- }
40
- export declare class Transformer extends Group {
41
- _nodes: Array<Node>;
42
- _movingAnchorName: string | null;
43
- _transforming: boolean;
44
- _anchorDragOffset: Vector2d;
45
- sin: number;
46
- cos: number;
47
- _cursorChange: boolean;
48
- static isTransforming: () => boolean;
49
- constructor(config?: TransformerConfig);
50
- attachTo(node: Node): this;
51
- setNode(node: Node): this;
52
- getNode(): Node<import("../Node.ts").NodeConfig>;
53
- _getEventNamespace(): string;
54
- setNodes(nodes?: Array<Node>): this;
55
- _proxyDrag(node: Node): void;
56
- getNodes(): Node<import("../Node.ts").NodeConfig>[];
57
- getActiveAnchor(): string | null;
58
- detach(): void;
59
- _resetTransformCache(): void;
60
- _getNodeRect(): any;
61
- __getNodeShape(node: Node, rot?: number, relative?: Node): {
62
- rotation: number;
63
- x: number;
64
- y: number;
65
- width: number;
66
- height: number;
67
- };
68
- __getNodeRect(): {
69
- x: number;
70
- y: number;
71
- width: number;
72
- height: number;
73
- rotation: number;
74
- };
75
- getX(): any;
76
- getY(): any;
77
- getWidth(): any;
78
- getHeight(): any;
79
- _createElements(): void;
80
- _createAnchor(name: any): void;
81
- _createBack(): void;
82
- _handleMouseDown(e: any): void;
83
- _handleMouseMove(e: any): void;
84
- _handleMouseUp(e: any): void;
85
- getAbsoluteTransform(): Transform;
86
- _removeEvents(e?: any): void;
87
- _fitNodesInto(newAttrs: any, evt?: any): void;
88
- forceUpdate(): void;
89
- _batchChangeChild(selector: string, attrs: any): void;
90
- update(): void;
91
- isTransforming(): boolean;
92
- stopTransform(): void;
93
- destroy(): this;
94
- toObject(): {
95
- attrs: any;
96
- className: string;
97
- children?: Array<any>;
98
- };
99
- clone(obj?: any): this;
100
- getClientRect(): IRect;
101
- nodes: GetSet<Node[], this>;
102
- enabledAnchors: GetSet<string[], this>;
103
- rotationSnaps: GetSet<number[], this>;
104
- anchorSize: GetSet<number, this>;
105
- resizeEnabled: GetSet<boolean, this>;
106
- rotateEnabled: GetSet<boolean, this>;
107
- rotateLineVisible: GetSet<boolean, this>;
108
- rotateAnchorOffset: GetSet<number, this>;
109
- rotationSnapTolerance: GetSet<number, this>;
110
- rotateAnchorCursor: GetSet<string, this>;
111
- padding: GetSet<number, this>;
112
- borderEnabled: GetSet<boolean, this>;
113
- borderStroke: GetSet<string, this>;
114
- borderStrokeWidth: GetSet<number, this>;
115
- borderDash: GetSet<number[], this>;
116
- anchorFill: GetSet<string, this>;
117
- anchorStroke: GetSet<string, this>;
118
- anchorCornerRadius: GetSet<number, this>;
119
- anchorStrokeWidth: GetSet<number, this>;
120
- keepRatio: GetSet<boolean, this>;
121
- shiftBehavior: GetSet<string, this>;
122
- centeredScaling: GetSet<boolean, this>;
123
- flipEnabled: GetSet<boolean, this>;
124
- ignoreStroke: GetSet<boolean, this>;
125
- boundBoxFunc: GetSet<(oldBox: Box, newBox: Box) => Box, this>;
126
- anchorDragBoundFunc: GetSet<(oldPos: Vector2d, newPos: Vector2d, e: MouseEvent) => Vector2d, this>;
127
- anchorStyleFunc: GetSet<null | ((Node: Rect) => void), this>;
128
- shouldOverdrawWholeArea: GetSet<boolean, this>;
129
- useSingleNodeRotation: GetSet<boolean, this>;
130
- }