konva 9.2.1 → 9.2.3
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/README.md +2 -2
- package/konva.js +47 -26
- package/konva.min.js +3 -3
- package/lib/Context.d.ts +5 -2
- package/lib/Context.js +2 -0
- package/lib/Global.js +1 -1
- package/lib/Shape.d.ts +2 -2
- package/lib/shapes/Text.d.ts +2 -0
- package/lib/shapes/Text.js +12 -3
- package/lib/shapes/Transformer.js +13 -20
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ This repository began as a GitHub fork of [ericdrowell/KineticJS](https://github
|
|
|
22
22
|
# Quick Look
|
|
23
23
|
|
|
24
24
|
```html
|
|
25
|
-
<script src="https://unpkg.com/konva@
|
|
25
|
+
<script src="https://unpkg.com/konva@9/konva.min.js"></script>
|
|
26
26
|
<div id="container"></div>
|
|
27
27
|
<script>
|
|
28
28
|
var stage = new Konva.Stage({
|
|
@@ -71,7 +71,7 @@ Konva supports UMD loading. So you can use all possible variants to load the fra
|
|
|
71
71
|
### Load Konva via classical `<script>` tag from CDN:
|
|
72
72
|
|
|
73
73
|
```html
|
|
74
|
-
<script src="https://unpkg.com/konva@
|
|
74
|
+
<script src="https://unpkg.com/konva@9/konva.min.js"></script>
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
### Install with npm:
|
package/konva.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* Konva JavaScript Framework v9.2.
|
|
8
|
+
* Konva JavaScript Framework v9.2.3
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date:
|
|
11
|
+
* Date: Tue Oct 31 2023
|
|
12
12
|
*
|
|
13
13
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
|
14
14
|
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
: {};
|
|
36
36
|
const Konva$2 = {
|
|
37
37
|
_global: glob,
|
|
38
|
-
version: '9.2.
|
|
38
|
+
version: '9.2.3',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -1485,11 +1485,13 @@
|
|
|
1485
1485
|
'shadowBlur',
|
|
1486
1486
|
'shadowOffsetX',
|
|
1487
1487
|
'shadowOffsetY',
|
|
1488
|
+
'letterSpacing',
|
|
1488
1489
|
'lineCap',
|
|
1489
1490
|
'lineDashOffset',
|
|
1490
1491
|
'lineJoin',
|
|
1491
1492
|
'lineWidth',
|
|
1492
1493
|
'miterLimit',
|
|
1494
|
+
'direction',
|
|
1493
1495
|
'font',
|
|
1494
1496
|
'textAlign',
|
|
1495
1497
|
'textBaseline',
|
|
@@ -14113,7 +14115,8 @@
|
|
|
14113
14115
|
// constants
|
|
14114
14116
|
var AUTO = 'auto',
|
|
14115
14117
|
//CANVAS = 'canvas',
|
|
14116
|
-
CENTER = 'center', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL$1 = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST$1 = [
|
|
14118
|
+
CENTER = 'center', INHERIT = 'inherit', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL$1 = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', RTL = 'rtl', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST$1 = [
|
|
14119
|
+
'direction',
|
|
14117
14120
|
'fontFamily',
|
|
14118
14121
|
'fontSize',
|
|
14119
14122
|
'fontStyle',
|
|
@@ -14176,6 +14179,7 @@
|
|
|
14176
14179
|
* @memberof Konva
|
|
14177
14180
|
* @augments Konva.Shape
|
|
14178
14181
|
* @param {Object} config
|
|
14182
|
+
* @param {String} [config.direction] default is inherit
|
|
14179
14183
|
* @param {String} [config.fontFamily] default is Arial
|
|
14180
14184
|
* @param {Number} [config.fontSize] in pixels. Default is 12
|
|
14181
14185
|
* @param {String} [config.fontStyle] can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.
|
|
@@ -14288,11 +14292,15 @@
|
|
|
14288
14292
|
if (!this.text()) {
|
|
14289
14293
|
return;
|
|
14290
14294
|
}
|
|
14291
|
-
var padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
|
|
14295
|
+
var padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
|
|
14296
|
+
direction = direction === INHERIT ? context.direction : direction;
|
|
14292
14297
|
var translateY = 0;
|
|
14293
14298
|
var translateY = lineHeightPx / 2;
|
|
14294
14299
|
var lineTranslateX = 0;
|
|
14295
14300
|
var lineTranslateY = 0;
|
|
14301
|
+
if (direction === RTL) {
|
|
14302
|
+
context.setAttr('direction', direction);
|
|
14303
|
+
}
|
|
14296
14304
|
context.setAttr('font', this._getContextFont());
|
|
14297
14305
|
context.setAttr('textBaseline', MIDDLE);
|
|
14298
14306
|
context.setAttr('textAlign', LEFT);
|
|
@@ -14351,7 +14359,10 @@
|
|
|
14351
14359
|
context.stroke();
|
|
14352
14360
|
context.restore();
|
|
14353
14361
|
}
|
|
14354
|
-
|
|
14362
|
+
// As `letterSpacing` isn't supported on Safari, we use this polyfill.
|
|
14363
|
+
// The exception is for RTL text, which we rely on native as it cannot
|
|
14364
|
+
// be supported otherwise.
|
|
14365
|
+
if (direction !== RTL && (letterSpacing !== 0 || align === JUSTIFY)) {
|
|
14355
14366
|
// var words = text.split(' ');
|
|
14356
14367
|
spacesNumber = text.split(' ').length - 1;
|
|
14357
14368
|
var array = stringToArray(text);
|
|
@@ -14373,6 +14384,9 @@
|
|
|
14373
14384
|
}
|
|
14374
14385
|
}
|
|
14375
14386
|
else {
|
|
14387
|
+
if (letterSpacing !== 0) {
|
|
14388
|
+
context.setAttr('letterSpacing', `${letterSpacing}px`);
|
|
14389
|
+
}
|
|
14376
14390
|
this._partialTextX = lineTranslateX;
|
|
14377
14391
|
this._partialTextY = translateY + lineTranslateY;
|
|
14378
14392
|
this._partialText = text;
|
|
@@ -14678,6 +14692,20 @@
|
|
|
14678
14692
|
* text.height() // will return calculated height, and not "auto"
|
|
14679
14693
|
*/
|
|
14680
14694
|
Factory.overWriteSetter(Text, 'height', getNumberOrAutoValidator());
|
|
14695
|
+
/**
|
|
14696
|
+
* get/set direction
|
|
14697
|
+
* @name Konva.Text#direction
|
|
14698
|
+
* @method
|
|
14699
|
+
* @param {String} direction
|
|
14700
|
+
* @returns {String}
|
|
14701
|
+
* @example
|
|
14702
|
+
* // get direction
|
|
14703
|
+
* var direction = text.direction();
|
|
14704
|
+
*
|
|
14705
|
+
* // set direction
|
|
14706
|
+
* text.direction('rtl');
|
|
14707
|
+
*/
|
|
14708
|
+
Factory.addGetterSetter(Text, 'direction', INHERIT);
|
|
14681
14709
|
/**
|
|
14682
14710
|
* get/set font family
|
|
14683
14711
|
* @name Konva.Text#fontFamily
|
|
@@ -16182,7 +16210,6 @@
|
|
|
16182
16210
|
this.update();
|
|
16183
16211
|
return;
|
|
16184
16212
|
}
|
|
16185
|
-
const allowNegativeScale = this.flipEnabled();
|
|
16186
16213
|
var t = new Transform();
|
|
16187
16214
|
t.rotate(Konva$2.getAngle(this.rotation()));
|
|
16188
16215
|
if (this._movingAnchorName &&
|
|
@@ -16198,10 +16225,6 @@
|
|
|
16198
16225
|
this._movingAnchorName = this._movingAnchorName.replace('left', 'right');
|
|
16199
16226
|
this._anchorDragOffset.x -= offset.x;
|
|
16200
16227
|
this._anchorDragOffset.y -= offset.y;
|
|
16201
|
-
if (!allowNegativeScale) {
|
|
16202
|
-
this.update();
|
|
16203
|
-
return;
|
|
16204
|
-
}
|
|
16205
16228
|
}
|
|
16206
16229
|
else if (this._movingAnchorName &&
|
|
16207
16230
|
newAttrs.width < 0 &&
|
|
@@ -16214,10 +16237,6 @@
|
|
|
16214
16237
|
this._anchorDragOffset.x -= offset.x;
|
|
16215
16238
|
this._anchorDragOffset.y -= offset.y;
|
|
16216
16239
|
newAttrs.width += this.padding() * 2;
|
|
16217
|
-
if (!allowNegativeScale) {
|
|
16218
|
-
this.update();
|
|
16219
|
-
return;
|
|
16220
|
-
}
|
|
16221
16240
|
}
|
|
16222
16241
|
if (this._movingAnchorName &&
|
|
16223
16242
|
newAttrs.height < 0 &&
|
|
@@ -16232,10 +16251,6 @@
|
|
|
16232
16251
|
this._anchorDragOffset.x -= offset.x;
|
|
16233
16252
|
this._anchorDragOffset.y -= offset.y;
|
|
16234
16253
|
newAttrs.height += this.padding() * 2;
|
|
16235
|
-
if (!allowNegativeScale) {
|
|
16236
|
-
this.update();
|
|
16237
|
-
return;
|
|
16238
|
-
}
|
|
16239
16254
|
}
|
|
16240
16255
|
else if (this._movingAnchorName &&
|
|
16241
16256
|
newAttrs.height < 0 &&
|
|
@@ -16248,10 +16263,6 @@
|
|
|
16248
16263
|
this._anchorDragOffset.x -= offset.x;
|
|
16249
16264
|
this._anchorDragOffset.y -= offset.y;
|
|
16250
16265
|
newAttrs.height += this.padding() * 2;
|
|
16251
|
-
if (!allowNegativeScale) {
|
|
16252
|
-
this.update();
|
|
16253
|
-
return;
|
|
16254
|
-
}
|
|
16255
16266
|
}
|
|
16256
16267
|
if (this.boundBoxFunc()) {
|
|
16257
16268
|
const bounded = this.boundBoxFunc()(oldAttrs, newAttrs);
|
|
@@ -16272,9 +16283,19 @@
|
|
|
16272
16283
|
oldTr.rotate(oldAttrs.rotation);
|
|
16273
16284
|
oldTr.scale(oldAttrs.width / baseSize, oldAttrs.height / baseSize);
|
|
16274
16285
|
const newTr = new Transform();
|
|
16275
|
-
|
|
16276
|
-
|
|
16277
|
-
|
|
16286
|
+
const newScaleX = newAttrs.width / baseSize;
|
|
16287
|
+
const newScaleY = newAttrs.height / baseSize;
|
|
16288
|
+
if (this.flipEnabled() === false) {
|
|
16289
|
+
newTr.translate(newAttrs.x, newAttrs.y);
|
|
16290
|
+
newTr.rotate(newAttrs.rotation);
|
|
16291
|
+
newTr.translate(newAttrs.width < 0 ? newAttrs.width : 0, newAttrs.height < 0 ? newAttrs.height : 0);
|
|
16292
|
+
newTr.scale(Math.abs(newScaleX), Math.abs(newScaleY));
|
|
16293
|
+
}
|
|
16294
|
+
else {
|
|
16295
|
+
newTr.translate(newAttrs.x, newAttrs.y);
|
|
16296
|
+
newTr.rotate(newAttrs.rotation);
|
|
16297
|
+
newTr.scale(newScaleX, newScaleY);
|
|
16298
|
+
}
|
|
16278
16299
|
// now lets think we had [old transform] and n ow we have [new transform]
|
|
16279
16300
|
// Now, the questions is: how can we transform "parent" to go from [old transform] into [new transform]
|
|
16280
16301
|
// in equation it will be:
|