konva 8.3.9 → 8.3.12
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/cmj/DragAndDrop.js +6 -2
- package/cmj/Factory.d.ts +1 -1
- package/cmj/Factory.js +5 -0
- package/cmj/Global.js +1 -1
- package/cmj/Node.d.ts +13 -3
- package/cmj/Node.js +29 -7
- package/cmj/Stage.js +1 -1
- package/cmj/Validators.js +7 -0
- package/cmj/shapes/Label.js +8 -1
- package/cmj/shapes/Line.d.ts +1 -1
- package/cmj/shapes/Text.d.ts +2 -0
- package/cmj/shapes/Text.js +26 -13
- package/cmj/shapes/TextPath.js +1 -1
- package/cmj/shapes/Transformer.d.ts +1 -0
- package/cmj/shapes/Transformer.js +8 -0
- package/konva.js +137 -30
- package/konva.min.js +3 -3
- package/lib/DragAndDrop.js +6 -2
- package/lib/Factory.d.ts +1 -1
- package/lib/Factory.js +5 -0
- package/lib/Global.js +1 -1
- package/lib/Node.d.ts +13 -3
- package/lib/Node.js +29 -7
- package/lib/Stage.js +1 -1
- package/lib/Validators.js +7 -0
- package/lib/shapes/Label.js +8 -1
- package/lib/shapes/Line.d.ts +1 -1
- package/lib/shapes/Text.d.ts +2 -0
- package/lib/shapes/Text.js +26 -13
- package/lib/shapes/TextPath.js +1 -1
- package/lib/shapes/Transformer.d.ts +1 -0
- package/lib/shapes/Transformer.js +8 -0
- package/package.json +14 -14
package/lib/DragAndDrop.js
CHANGED
|
@@ -55,6 +55,7 @@ export const DD = {
|
|
|
55
55
|
});
|
|
56
56
|
},
|
|
57
57
|
_endDragBefore(evt) {
|
|
58
|
+
const drawNodes = [];
|
|
58
59
|
DD._dragElements.forEach((elem) => {
|
|
59
60
|
const { node } = elem;
|
|
60
61
|
const stage = node.getStage();
|
|
@@ -74,10 +75,13 @@ export const DD = {
|
|
|
74
75
|
}
|
|
75
76
|
const drawNode = elem.node.getLayer() ||
|
|
76
77
|
(elem.node instanceof Konva['Stage'] && elem.node);
|
|
77
|
-
if (drawNode) {
|
|
78
|
-
|
|
78
|
+
if (drawNode && drawNodes.indexOf(drawNode) === -1) {
|
|
79
|
+
drawNodes.push(drawNode);
|
|
79
80
|
}
|
|
80
81
|
});
|
|
82
|
+
drawNodes.forEach((drawNode) => {
|
|
83
|
+
drawNode.draw();
|
|
84
|
+
});
|
|
81
85
|
},
|
|
82
86
|
_endDragAfter(evt) {
|
|
83
87
|
DD._dragElements.forEach((elem, key) => {
|
package/lib/Factory.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare const Factory: {
|
|
|
3
3
|
addGetter(constructor: any, attr: any, def?: any): void;
|
|
4
4
|
addSetter(constructor: any, attr: any, validator?: any, after?: any): void;
|
|
5
5
|
overWriteSetter(constructor: any, attr: any, validator?: any, after?: any): void;
|
|
6
|
-
addComponentsGetterSetter(constructor: any, attr:
|
|
6
|
+
addComponentsGetterSetter(constructor: any, attr: string, components: Array<string>, validator?: Function, after?: Function): void;
|
|
7
7
|
addOverloadedGetterSetter(constructor: any, attr: any): void;
|
|
8
8
|
addDeprecatedGetterSetter(constructor: any, attr: any, def: any, validator: any): void;
|
|
9
9
|
backCompat(constructor: any, methods: any): void;
|
package/lib/Factory.js
CHANGED
|
@@ -60,6 +60,11 @@ export const Factory = {
|
|
|
60
60
|
}
|
|
61
61
|
this._setAttr(attr + capitalize(key), val[key]);
|
|
62
62
|
}
|
|
63
|
+
if (!val) {
|
|
64
|
+
components.forEach((component) => {
|
|
65
|
+
this._setAttr(attr + capitalize(component), undefined);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
63
68
|
this._fireChangeEvent(attr, oldVal, val);
|
|
64
69
|
if (after) {
|
|
65
70
|
after.call(this);
|
package/lib/Global.js
CHANGED
|
@@ -13,7 +13,7 @@ export const glob = typeof global !== 'undefined'
|
|
|
13
13
|
: {};
|
|
14
14
|
export const Konva = {
|
|
15
15
|
_global: glob,
|
|
16
|
-
version: '8.3.
|
|
16
|
+
version: '8.3.12',
|
|
17
17
|
isBrowser: detectBrowser(),
|
|
18
18
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
19
19
|
dblClickWindow: 400,
|
package/lib/Node.d.ts
CHANGED
|
@@ -179,7 +179,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
179
179
|
getParent(): Container<Node<NodeConfig>>;
|
|
180
180
|
findAncestors(selector: string, includeSelf?: boolean, stopNode?: Node): Node<NodeConfig>[];
|
|
181
181
|
isAncestorOf(node: Node): boolean;
|
|
182
|
-
findAncestor(selector?: string, includeSelf?: boolean, stopNode?: Container):
|
|
182
|
+
findAncestor(selector?: string, includeSelf?: boolean, stopNode?: Container): Node<NodeConfig>;
|
|
183
183
|
_isMatch(selector: string | Function): any;
|
|
184
184
|
getLayer(): Layer | null;
|
|
185
185
|
getStage(): Stage | null;
|
|
@@ -216,7 +216,17 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
216
216
|
mimeType?: string;
|
|
217
217
|
quality?: number;
|
|
218
218
|
callback?: (img: HTMLImageElement) => void;
|
|
219
|
-
}):
|
|
219
|
+
}): Promise<unknown>;
|
|
220
|
+
toBlob(config?: {
|
|
221
|
+
x?: number;
|
|
222
|
+
y?: number;
|
|
223
|
+
width?: number;
|
|
224
|
+
height?: number;
|
|
225
|
+
pixelRatio?: number;
|
|
226
|
+
mimeType?: string;
|
|
227
|
+
quality?: number;
|
|
228
|
+
callback?: (blob: Blob) => void;
|
|
229
|
+
}): Promise<unknown>;
|
|
220
230
|
setSize(size: any): this;
|
|
221
231
|
getSize(): {
|
|
222
232
|
width: number;
|
|
@@ -293,7 +303,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
293
303
|
opacity: GetSet<number, this>;
|
|
294
304
|
rotation: GetSet<number, this>;
|
|
295
305
|
zIndex: GetSet<number, this>;
|
|
296
|
-
scale: GetSet<Vector2d, this>;
|
|
306
|
+
scale: GetSet<Vector2d | undefined, this>;
|
|
297
307
|
scaleX: GetSet<number, this>;
|
|
298
308
|
scaleY: GetSet<number, this>;
|
|
299
309
|
skew: GetSet<Vector2d, this>;
|
package/lib/Node.js
CHANGED
|
@@ -964,13 +964,35 @@ export class Node {
|
|
|
964
964
|
return url;
|
|
965
965
|
}
|
|
966
966
|
toImage(config) {
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
967
|
+
return new Promise((resolve, reject) => {
|
|
968
|
+
try {
|
|
969
|
+
const callback = config === null || config === void 0 ? void 0 : config.callback;
|
|
970
|
+
if (callback)
|
|
971
|
+
delete config.callback;
|
|
972
|
+
Util._urlToImage(this.toDataURL(config), function (img) {
|
|
973
|
+
resolve(img);
|
|
974
|
+
callback === null || callback === void 0 ? void 0 : callback(img);
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
catch (err) {
|
|
978
|
+
reject(err);
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
toBlob(config) {
|
|
983
|
+
return new Promise((resolve, reject) => {
|
|
984
|
+
try {
|
|
985
|
+
const callback = config === null || config === void 0 ? void 0 : config.callback;
|
|
986
|
+
if (callback)
|
|
987
|
+
delete config.callback;
|
|
988
|
+
this.toCanvas(config).toBlob((blob) => {
|
|
989
|
+
resolve(blob);
|
|
990
|
+
callback === null || callback === void 0 ? void 0 : callback(blob);
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
catch (err) {
|
|
994
|
+
reject(err);
|
|
995
|
+
}
|
|
974
996
|
});
|
|
975
997
|
}
|
|
976
998
|
setSize(size) {
|
package/lib/Stage.js
CHANGED
package/lib/Validators.js
CHANGED
|
@@ -120,6 +120,10 @@ export function getFunctionValidator() {
|
|
|
120
120
|
export function getNumberArrayValidator() {
|
|
121
121
|
if (Konva.isUnminified) {
|
|
122
122
|
return function (val, attr) {
|
|
123
|
+
const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null;
|
|
124
|
+
if (TypedArray && val instanceof TypedArray) {
|
|
125
|
+
return val;
|
|
126
|
+
}
|
|
123
127
|
if (!Util._isArray(val)) {
|
|
124
128
|
Util.warn(_formatValue(val) +
|
|
125
129
|
' is a not valid value for "' +
|
|
@@ -158,6 +162,9 @@ export function getBooleanValidator() {
|
|
|
158
162
|
export function getComponentValidator(components) {
|
|
159
163
|
if (Konva.isUnminified) {
|
|
160
164
|
return function (val, attr) {
|
|
165
|
+
if (val === undefined || val === null) {
|
|
166
|
+
return val;
|
|
167
|
+
}
|
|
161
168
|
if (!Util.isObject(val)) {
|
|
162
169
|
Util.warn(_formatValue(val) +
|
|
163
170
|
' is a not valid value for "' +
|
package/lib/shapes/Label.js
CHANGED
|
@@ -12,6 +12,9 @@ var ATTR_CHANGE_LIST = [
|
|
|
12
12
|
'text',
|
|
13
13
|
'width',
|
|
14
14
|
'height',
|
|
15
|
+
'pointerDirection',
|
|
16
|
+
'pointerWidth',
|
|
17
|
+
'pointerHeight',
|
|
15
18
|
], CHANGE_KONVA = 'Change.konva', NONE = 'none', UP = 'up', RIGHT = 'right', DOWN = 'down', LEFT = 'left', attrChangeListLen = ATTR_CHANGE_LIST.length;
|
|
16
19
|
export class Label extends Group {
|
|
17
20
|
constructor(config) {
|
|
@@ -93,7 +96,11 @@ export class Tag extends Shape {
|
|
|
93
96
|
let bottomLeft = 0;
|
|
94
97
|
let bottomRight = 0;
|
|
95
98
|
if (typeof cornerRadius === 'number') {
|
|
96
|
-
topLeft =
|
|
99
|
+
topLeft =
|
|
100
|
+
topRight =
|
|
101
|
+
bottomLeft =
|
|
102
|
+
bottomRight =
|
|
103
|
+
Math.min(cornerRadius, width / 2, height / 2);
|
|
97
104
|
}
|
|
98
105
|
else {
|
|
99
106
|
topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
package/lib/shapes/Line.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Shape, ShapeConfig } from '../Shape';
|
|
|
2
2
|
import { GetSet } from '../types';
|
|
3
3
|
import { Context } from '../Context';
|
|
4
4
|
export interface LineConfig extends ShapeConfig {
|
|
5
|
-
points?: number[];
|
|
5
|
+
points?: number[] | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
|
|
6
6
|
tension?: number;
|
|
7
7
|
closed?: boolean;
|
|
8
8
|
bezier?: boolean;
|
package/lib/shapes/Text.d.ts
CHANGED
|
@@ -43,6 +43,8 @@ export declare class Text extends Shape<TextConfig> {
|
|
|
43
43
|
_addTextLine(line: any): number;
|
|
44
44
|
_getTextWidth(text: any): any;
|
|
45
45
|
_setTextData(): void;
|
|
46
|
+
_shouldHandleEllipsis(currentHeightPx: number): boolean;
|
|
47
|
+
_tryToAddEllipsisToLastLine(): void;
|
|
46
48
|
getStrokeScaleEnabled(): boolean;
|
|
47
49
|
fontFamily: GetSet<string, this>;
|
|
48
50
|
fontSize: GetSet<number, this>;
|
package/lib/shapes/Text.js
CHANGED
|
@@ -274,19 +274,9 @@ export class Text extends Shape {
|
|
|
274
274
|
this._addTextLine(match);
|
|
275
275
|
textWidth = Math.max(textWidth, matchWidth);
|
|
276
276
|
currentHeightPx += lineHeightPx;
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if (lastLine) {
|
|
281
|
-
if (shouldAddEllipsis) {
|
|
282
|
-
var haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
|
|
283
|
-
if (!haveSpace) {
|
|
284
|
-
lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
|
|
285
|
-
}
|
|
286
|
-
this.textArr.splice(this.textArr.length - 1, 1);
|
|
287
|
-
this._addTextLine(lastLine.text + ELLIPSIS);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
277
|
+
var shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);
|
|
278
|
+
if (shouldHandleEllipsis) {
|
|
279
|
+
this._tryToAddEllipsisToLastLine();
|
|
290
280
|
break;
|
|
291
281
|
}
|
|
292
282
|
line = line.slice(low);
|
|
@@ -310,6 +300,9 @@ export class Text extends Shape {
|
|
|
310
300
|
this._addTextLine(line);
|
|
311
301
|
currentHeightPx += lineHeightPx;
|
|
312
302
|
textWidth = Math.max(textWidth, lineWidth);
|
|
303
|
+
if (this._shouldHandleEllipsis(currentHeightPx) && i < max - 1) {
|
|
304
|
+
this._tryToAddEllipsisToLastLine();
|
|
305
|
+
}
|
|
313
306
|
}
|
|
314
307
|
if (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx) {
|
|
315
308
|
break;
|
|
@@ -321,6 +314,26 @@ export class Text extends Shape {
|
|
|
321
314
|
this.textHeight = fontSize;
|
|
322
315
|
this.textWidth = textWidth;
|
|
323
316
|
}
|
|
317
|
+
_shouldHandleEllipsis(currentHeightPx) {
|
|
318
|
+
var fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE;
|
|
319
|
+
return (!shouldWrap ||
|
|
320
|
+
(fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx));
|
|
321
|
+
}
|
|
322
|
+
_tryToAddEllipsisToLastLine() {
|
|
323
|
+
var width = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();
|
|
324
|
+
var lastLine = this.textArr[this.textArr.length - 1];
|
|
325
|
+
if (!lastLine || !shouldAddEllipsis) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
if (fixedWidth) {
|
|
329
|
+
var haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
|
|
330
|
+
if (!haveSpace) {
|
|
331
|
+
lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
this.textArr.splice(this.textArr.length - 1, 1);
|
|
335
|
+
this._addTextLine(lastLine.text + ELLIPSIS);
|
|
336
|
+
}
|
|
324
337
|
getStrokeScaleEnabled() {
|
|
325
338
|
return true;
|
|
326
339
|
}
|
package/lib/shapes/TextPath.js
CHANGED
|
@@ -896,6 +896,14 @@ export class Transformer extends Group {
|
|
|
896
896
|
toObject() {
|
|
897
897
|
return Node.prototype.toObject.call(this);
|
|
898
898
|
}
|
|
899
|
+
getClientRect() {
|
|
900
|
+
if (this.nodes().length > 0) {
|
|
901
|
+
return super.getClientRect();
|
|
902
|
+
}
|
|
903
|
+
else {
|
|
904
|
+
return { x: 0, y: 0, width: 0, height: 0 };
|
|
905
|
+
}
|
|
906
|
+
}
|
|
899
907
|
}
|
|
900
908
|
function validateAnchors(val) {
|
|
901
909
|
if (!(val instanceof Array)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "konva",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.12",
|
|
4
4
|
"author": "Anton Lavrenov",
|
|
5
5
|
"files": [
|
|
6
6
|
"README.md",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"build": "npm run compile && cp ./src/index-types.d.ts ./lib && gulp build && node ./rename-imports.mjs",
|
|
48
48
|
"test:import": "npm run build && node ./test/import-test.cjs &&node ./test/import-test.mjs",
|
|
49
49
|
"test": "npm run test:browser && npm run test:node",
|
|
50
|
-
"test:build": "parcel build ./test/unit-tests.html --dist-dir test-build --target none --public-url ./ --no-source-maps",
|
|
50
|
+
"test:build": "parcel build ./test/unit-tests.html --dist-dir ./test-build --target none --public-url ./ --no-source-maps",
|
|
51
51
|
"test:browser": "npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security",
|
|
52
|
-
"test:node": "
|
|
52
|
+
"test:node": "ts-mocha -p ./test/tsconfig.json test/unit/**/*.ts --exit && npm run test:import",
|
|
53
53
|
"test:watch": "rm -rf ./parcel-cache && parcel serve ./test/unit-tests.html ./test/manual-tests.html ./test/sandbox.html",
|
|
54
54
|
"tsc": "tsc --removeComments && tsc --build ./tsconfig-cmj.json",
|
|
55
55
|
"rollup": "rollup -c",
|
|
@@ -88,10 +88,10 @@
|
|
|
88
88
|
}
|
|
89
89
|
],
|
|
90
90
|
"devDependencies": {
|
|
91
|
-
"@parcel/transformer-image": "2.
|
|
92
|
-
"@size-limit/preset-big-lib": "^
|
|
91
|
+
"@parcel/transformer-image": "2.7.0",
|
|
92
|
+
"@size-limit/preset-big-lib": "^8.0.0",
|
|
93
93
|
"@types/mocha": "^9.1.1",
|
|
94
|
-
"canvas": "^2.9.
|
|
94
|
+
"canvas": "^2.9.3",
|
|
95
95
|
"chai": "4.3.6",
|
|
96
96
|
"filehound": "^1.17.6",
|
|
97
97
|
"gulp": "^4.0.2",
|
|
@@ -105,19 +105,19 @@
|
|
|
105
105
|
"gulp-uglify": "^3.0.2",
|
|
106
106
|
"gulp-uglify-es": "^3.0.0",
|
|
107
107
|
"gulp-util": "^3.0.8",
|
|
108
|
-
"mocha": "
|
|
108
|
+
"mocha": "10.0.0",
|
|
109
109
|
"mocha-headless-chrome": "^4.0.0",
|
|
110
|
-
"parcel": "2.
|
|
110
|
+
"parcel": "2.7.0",
|
|
111
111
|
"process": "^0.11.10",
|
|
112
|
-
"rollup": "^2.
|
|
112
|
+
"rollup": "^2.77.2",
|
|
113
113
|
"rollup-plugin-commonjs": "^10.1.0",
|
|
114
114
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
115
115
|
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
116
|
-
"rollup-plugin-typescript2": "^0.
|
|
117
|
-
"size-limit": "^
|
|
118
|
-
"ts-mocha": "^
|
|
119
|
-
"ts-node": "^9.1
|
|
120
|
-
"typescript": "^4.
|
|
116
|
+
"rollup-plugin-typescript2": "^0.32.1",
|
|
117
|
+
"size-limit": "^8.0.0",
|
|
118
|
+
"ts-mocha": "^10.0.0",
|
|
119
|
+
"ts-node": "^10.9.1",
|
|
120
|
+
"typescript": "^4.7.4"
|
|
121
121
|
},
|
|
122
122
|
"keywords": [
|
|
123
123
|
"canvas",
|