konva 10.9.1 → 10.10.0
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 +22 -10
- package/konva.js +18996 -18924
- package/konva.min.js +50 -50
- package/lib/Animation.js +3 -3
- package/lib/Canvas.js +11 -3
- package/lib/Container.js +3 -3
- package/lib/Context.d.ts +1 -2
- package/lib/Context.js +2 -19
- package/lib/Core.js +2 -2
- package/lib/DragAndDrop.js +1 -1
- package/lib/Factory.js +2 -2
- package/lib/FastLayer.js +3 -3
- package/lib/Global.d.ts +0 -1
- package/lib/Global.js +13 -7
- package/lib/Group.js +5 -5
- package/lib/Layer.d.ts +1 -1
- package/lib/Layer.js +8 -8
- package/lib/Node.js +32 -26
- package/lib/PointerEvents.js +1 -1
- package/lib/Shape.js +8 -27
- package/lib/Stage.js +8 -8
- package/lib/Tween.js +4 -4
- package/lib/Util.d.ts +67 -3
- package/lib/Util.js +122 -41
- package/lib/Validators.js +2 -2
- package/lib/_CoreInternals.d.ts +15 -11
- package/lib/_CoreInternals.js +16 -14
- package/lib/_FullInternals.d.ts +14 -10
- package/lib/_FullInternals.js +38 -38
- package/lib/canvas-backend.js +6 -15
- package/lib/filters/Blur.js +3 -3
- package/lib/filters/Brighten.js +3 -3
- package/lib/filters/Brightness.js +2 -2
- package/lib/filters/Contrast.js +3 -3
- package/lib/filters/Emboss.js +10 -9
- package/lib/filters/Enhance.js +3 -3
- package/lib/filters/HSL.js +3 -3
- package/lib/filters/HSV.js +3 -3
- package/lib/filters/Kaleidoscope.js +3 -3
- package/lib/filters/Mask.js +3 -3
- package/lib/filters/Noise.js +3 -3
- package/lib/filters/Pixelate.js +4 -4
- package/lib/filters/Posterize.js +3 -3
- package/lib/filters/RGB.js +3 -3
- package/lib/filters/RGBA.js +3 -3
- package/lib/filters/Threshold.js +3 -3
- package/lib/index.js +1 -1
- package/lib/napi-backend.d.ts +2 -0
- package/lib/napi-backend.js +15 -0
- package/lib/shapes/Arc.js +5 -5
- package/lib/shapes/Arrow.js +5 -5
- package/lib/shapes/Circle.js +4 -4
- package/lib/shapes/Ellipse.js +4 -4
- package/lib/shapes/Image.js +5 -5
- package/lib/shapes/Label.js +7 -7
- package/lib/shapes/Line.js +6 -6
- package/lib/shapes/Path.js +5 -5
- package/lib/shapes/Rect.js +5 -5
- package/lib/shapes/RegularPolygon.js +5 -5
- package/lib/shapes/Ring.js +4 -4
- package/lib/shapes/Sprite.js +5 -5
- package/lib/shapes/Star.js +4 -4
- package/lib/shapes/Text.d.ts +0 -1
- package/lib/shapes/Text.js +32 -30
- package/lib/shapes/TextPath.js +7 -7
- package/lib/shapes/Transformer.js +12 -11
- package/lib/shapes/Wedge.js +5 -5
- package/lib/skia-backend.js +17 -25
- package/package.json +31 -34
package/lib/filters/Emboss.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Util } from
|
|
3
|
-
import { Node } from
|
|
4
|
-
import { getNumberValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Util } from '../Util.js';
|
|
3
|
+
import { Node } from '../Node.js';
|
|
4
|
+
import { getNumberValidator } from '../Validators.js';
|
|
5
5
|
/**
|
|
6
6
|
* Emboss Filter.
|
|
7
7
|
* @function
|
|
@@ -16,13 +16,14 @@ import { getNumberValidator } from "../Validators.js";
|
|
|
16
16
|
* node.embossBlend(true);
|
|
17
17
|
*/
|
|
18
18
|
export const Emboss = function (imageData) {
|
|
19
|
-
var _a, _b, _c, _d
|
|
19
|
+
var _a, _b, _c, _d;
|
|
20
|
+
var _e, _f, _g, _h;
|
|
20
21
|
const data = imageData.data;
|
|
21
22
|
const w = imageData.width;
|
|
22
23
|
const h = imageData.height;
|
|
23
24
|
// Inputs from Konva node
|
|
24
|
-
const strength01 = Math.min(1, Math.max(0, (
|
|
25
|
-
const whiteLevel01 = Math.min(1, Math.max(0, (
|
|
25
|
+
const strength01 = Math.min(1, Math.max(0, (_e = (_a = this.embossStrength) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _e !== void 0 ? _e : 0.5)); // [0..1]
|
|
26
|
+
const whiteLevel01 = Math.min(1, Math.max(0, (_f = (_b = this.embossWhiteLevel) === null || _b === void 0 ? void 0 : _b.call(this)) !== null && _f !== void 0 ? _f : 0.5)); // [0..1]
|
|
26
27
|
// Convert string direction to degrees
|
|
27
28
|
const directionMap = {
|
|
28
29
|
'top-left': 315,
|
|
@@ -34,13 +35,13 @@ export const Emboss = function (imageData) {
|
|
|
34
35
|
'bottom-left': 45,
|
|
35
36
|
left: 0,
|
|
36
37
|
};
|
|
37
|
-
const direction = (
|
|
38
|
+
const direction = (_g = (_c = this.embossDirection) === null || _c === void 0 ? void 0 : _c.call(this)) !== null && _g !== void 0 ? _g : 'top-left';
|
|
38
39
|
let directionDeg = directionMap[direction]; // degrees
|
|
39
40
|
if (directionDeg === undefined) {
|
|
40
41
|
Util.warn('Unknown emboss direction: "' + direction + '". Using "top-left".');
|
|
41
42
|
directionDeg = directionMap['top-left'];
|
|
42
43
|
}
|
|
43
|
-
const blend = !!((_h = (
|
|
44
|
+
const blend = !!((_h = (_d = this.embossBlend) === null || _d === void 0 ? void 0 : _d.call(this)) !== null && _h !== void 0 ? _h : false);
|
|
44
45
|
// Internal mapping:
|
|
45
46
|
// - "strength" was 0..10; we honor your 0..1 API and scale accordingly.
|
|
46
47
|
// - Sobel directional response is roughly in [-1020..1020] for 8-bit luminance; scale to ~±128.
|
package/lib/filters/Enhance.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node } from
|
|
3
|
-
import { getNumberValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node } from '../Node.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
4
|
function remap(fromValue, fromMin, fromMax, toMin, toMax) {
|
|
5
5
|
// Compute the range of the data
|
|
6
6
|
const fromRange = fromMax - fromMin, toRange = toMax - toMin;
|
package/lib/filters/HSL.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node } from
|
|
3
|
-
import { getNumberValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node } from '../Node.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
4
|
Factory.addGetterSetter(Node, 'hue', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
5
5
|
/**
|
|
6
6
|
* get/set hsv hue in degrees. Use with {@link Konva.Filters.HSV} or {@link Konva.Filters.HSL} filter.
|
package/lib/filters/HSV.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node } from
|
|
3
|
-
import { getNumberValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node } from '../Node.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
4
|
/**
|
|
5
5
|
* HSV Filter. Adjusts the hue, saturation and value
|
|
6
6
|
* @function
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node } from
|
|
3
|
-
import { getNumberValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node } from '../Node.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
4
|
/*
|
|
5
5
|
* ToPolar Filter. Converts image data to polar coordinates. Performs
|
|
6
6
|
* w*h*4 pixel reads and w*h pixel writes. The r axis is placed along
|
package/lib/filters/Mask.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node } from
|
|
3
|
-
import { getNumberValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node } from '../Node.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
4
|
function pixelAt(idata, x, y) {
|
|
5
5
|
let idx = (y * idata.width + x) * 4;
|
|
6
6
|
const d = [];
|
package/lib/filters/Noise.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node } from
|
|
3
|
-
import { getNumberValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node } from '../Node.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
4
|
/**
|
|
5
5
|
* Noise Filter. Randomly adds or substracts to the color channels
|
|
6
6
|
* @function
|
package/lib/filters/Pixelate.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Util } from
|
|
3
|
-
import { Node } from
|
|
4
|
-
import { getNumberValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Util } from '../Util.js';
|
|
3
|
+
import { Node } from '../Node.js';
|
|
4
|
+
import { getNumberValidator } from '../Validators.js';
|
|
5
5
|
/**
|
|
6
6
|
* Pixelate Filter. Averages groups of pixels and redraws
|
|
7
7
|
* them as larger pixels
|
package/lib/filters/Posterize.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node } from
|
|
3
|
-
import { getNumberValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node } from '../Node.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
4
|
/**
|
|
5
5
|
* Posterize Filter. Adjusts the channels so that there are no more
|
|
6
6
|
* than n different values for that channel. This is also applied
|
package/lib/filters/RGB.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node } from
|
|
3
|
-
import { RGBComponent } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node } from '../Node.js';
|
|
3
|
+
import { RGBComponent } from '../Validators.js';
|
|
4
4
|
/**
|
|
5
5
|
* RGB Filter
|
|
6
6
|
* @function
|
package/lib/filters/RGBA.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node } from '../Node.js';
|
|
3
3
|
// red, green and blue are registered there
|
|
4
|
-
import
|
|
4
|
+
import './RGB.js';
|
|
5
5
|
/**
|
|
6
6
|
* RGBA Filter
|
|
7
7
|
* @function
|
package/lib/filters/Threshold.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Node } from
|
|
3
|
-
import { getNumberValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Node } from '../Node.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
4
|
/**
|
|
5
5
|
* Threshold Filter. Pushes any value above the mid point to
|
|
6
6
|
* the max and any value below the mid point to the min.
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Konva } from
|
|
1
|
+
import { Konva } from './_FullInternals.js';
|
|
2
2
|
export default Konva;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Konva } from './_CoreInternals.js';
|
|
2
|
+
import { Canvas, DOMMatrix, Image, Path2D } from '@napi-rs/canvas';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
global.DOMMatrix = DOMMatrix;
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
global.Path2D = Path2D;
|
|
7
|
+
Konva.setCanvasBackend({
|
|
8
|
+
name: 'napi-rs-canvas',
|
|
9
|
+
createCanvas: () => new Canvas(300, 300),
|
|
10
|
+
createImage: () => new Image(),
|
|
11
|
+
createPath2D: (path) => new Path2D(path),
|
|
12
|
+
});
|
|
13
|
+
// the core Konva object, without shapes and filters. `import 'konva'` extends
|
|
14
|
+
// this same object with them
|
|
15
|
+
export default Konva;
|
package/lib/shapes/Arc.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Shape } from
|
|
3
|
-
import { Konva } from
|
|
4
|
-
import { getNumberValidator, getBooleanValidator } from
|
|
5
|
-
import { _registerNode } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { Konva } from '../Global.js';
|
|
4
|
+
import { getNumberValidator, getBooleanValidator } from '../Validators.js';
|
|
5
|
+
import { _registerNode } from '../Global.js';
|
|
6
6
|
/**
|
|
7
7
|
* Arc constructor
|
|
8
8
|
* @constructor
|
package/lib/shapes/Arrow.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Line } from
|
|
3
|
-
import { getNumberValidator } from
|
|
4
|
-
import { _registerNode } from
|
|
5
|
-
import { Path } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Line } from './Line.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
|
+
import { Path } from './Path.js';
|
|
6
6
|
/**
|
|
7
7
|
* Arrow constructor
|
|
8
8
|
* @constructor
|
package/lib/shapes/Circle.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Shape } from
|
|
3
|
-
import { getNumberValidator } from
|
|
4
|
-
import { _registerNode } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
5
|
/**
|
|
6
6
|
* Circle constructor
|
|
7
7
|
* @constructor
|
package/lib/shapes/Ellipse.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Shape } from
|
|
3
|
-
import { getNumberValidator } from
|
|
4
|
-
import { _registerNode } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
5
|
/**
|
|
6
6
|
* Ellipse constructor
|
|
7
7
|
* @constructor
|
package/lib/shapes/Image.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Util } from
|
|
2
|
-
import { Factory } from
|
|
3
|
-
import { Shape } from
|
|
4
|
-
import { _registerNode } from
|
|
5
|
-
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from
|
|
1
|
+
import { Util } from '../Util.js';
|
|
2
|
+
import { Factory } from '../Factory.js';
|
|
3
|
+
import { Shape } from '../Shape.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
|
+
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from '../Validators.js';
|
|
6
6
|
/**
|
|
7
7
|
* Image constructor
|
|
8
8
|
* @constructor
|
package/lib/shapes/Label.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Util } from
|
|
3
|
-
import { Shape } from
|
|
4
|
-
import { Group } from
|
|
5
|
-
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from
|
|
6
|
-
import { _registerNode } from
|
|
7
|
-
import { Text } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Util } from '../Util.js';
|
|
3
|
+
import { Shape } from '../Shape.js';
|
|
4
|
+
import { Group } from '../Group.js';
|
|
5
|
+
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from '../Validators.js';
|
|
6
|
+
import { _registerNode } from '../Global.js';
|
|
7
|
+
import { Text } from './Text.js';
|
|
8
8
|
// constants
|
|
9
9
|
const ATTR_CHANGE_LIST = [
|
|
10
10
|
...Text.prototype._attrsAffectingSize,
|
package/lib/shapes/Line.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { getCubicExtremaPoints, getQuadraticExtremaPoints, } from
|
|
2
|
-
import { Factory } from
|
|
3
|
-
import { _registerNode } from
|
|
4
|
-
import { Shape } from
|
|
5
|
-
import { Util } from
|
|
6
|
-
import { getNumberArrayValidator, getNumberValidator } from
|
|
1
|
+
import { getCubicExtremaPoints, getQuadraticExtremaPoints, } from '../BezierFunctions.js';
|
|
2
|
+
import { Factory } from '../Factory.js';
|
|
3
|
+
import { _registerNode } from '../Global.js';
|
|
4
|
+
import { Shape } from '../Shape.js';
|
|
5
|
+
import { Util } from '../Util.js';
|
|
6
|
+
import { getNumberArrayValidator, getNumberValidator } from '../Validators.js';
|
|
7
7
|
function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
|
|
8
8
|
const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), dSum = d01 + d12;
|
|
9
9
|
// all three points are the same, so the control points collapse into that
|
package/lib/shapes/Path.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { _registerNode } from
|
|
3
|
-
import { Shape } from
|
|
4
|
-
import { Util } from
|
|
5
|
-
import { getCubicArcLength, getCubicExtremaPoints, getQuadraticArcLength, getQuadraticExtremaPoints, t2length, } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { _registerNode } from '../Global.js';
|
|
3
|
+
import { Shape } from '../Shape.js';
|
|
4
|
+
import { Util } from '../Util.js';
|
|
5
|
+
import { getCubicArcLength, getCubicExtremaPoints, getQuadraticArcLength, getQuadraticExtremaPoints, t2length, } from '../BezierFunctions.js';
|
|
6
6
|
// how many numbers each path command takes
|
|
7
7
|
const PARAM_COUNT = {
|
|
8
8
|
m: 2,
|
package/lib/shapes/Rect.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Shape } from
|
|
3
|
-
import { _registerNode } from
|
|
4
|
-
import { Util } from
|
|
5
|
-
import { getNumberOrArrayOfNumbersValidator } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { _registerNode } from '../Global.js';
|
|
4
|
+
import { Util } from '../Util.js';
|
|
5
|
+
import { getNumberOrArrayOfNumbersValidator } from '../Validators.js';
|
|
6
6
|
/**
|
|
7
7
|
* Rect constructor
|
|
8
8
|
* @constructor
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Shape } from
|
|
3
|
-
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from
|
|
4
|
-
import { _registerNode } from
|
|
5
|
-
import { Util } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
|
+
import { Util } from '../Util.js';
|
|
6
6
|
/**
|
|
7
7
|
* RegularPolygon constructor. Examples include triangles, squares, pentagons, hexagons, etc.
|
|
8
8
|
* @constructor
|
package/lib/shapes/Ring.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Shape } from
|
|
3
|
-
import { getNumberValidator } from
|
|
4
|
-
import { _registerNode } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
5
|
const PIx2 = Math.PI * 2;
|
|
6
6
|
/**
|
|
7
7
|
* Ring constructor
|
package/lib/shapes/Sprite.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Shape } from
|
|
3
|
-
import { Animation } from
|
|
4
|
-
import { getNumberValidator } from
|
|
5
|
-
import { _registerNode } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { Animation } from '../Animation.js';
|
|
4
|
+
import { getNumberValidator } from '../Validators.js';
|
|
5
|
+
import { _registerNode } from '../Global.js';
|
|
6
6
|
/**
|
|
7
7
|
* Sprite constructor
|
|
8
8
|
* @constructor
|
package/lib/shapes/Star.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Shape } from
|
|
3
|
-
import { getNumberValidator } from
|
|
4
|
-
import { _registerNode } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
5
|
/**
|
|
6
6
|
* Star constructor
|
|
7
7
|
* @constructor
|
package/lib/shapes/Text.d.ts
CHANGED
package/lib/shapes/Text.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Util } from
|
|
2
|
-
import { Factory } from
|
|
3
|
-
import { Shape } from
|
|
4
|
-
import { Konva } from
|
|
5
|
-
import { getNumberValidator, getStringValidator, getNumberOrAutoValidator, getBooleanValidator, } from
|
|
6
|
-
import { _registerNode } from
|
|
1
|
+
import { Util, _perCanvasBackend, getDummyContext } from '../Util.js';
|
|
2
|
+
import { Factory } from '../Factory.js';
|
|
3
|
+
import { Shape } from '../Shape.js';
|
|
4
|
+
import { Konva } from '../Global.js';
|
|
5
|
+
import { getNumberValidator, getStringValidator, getNumberOrAutoValidator, getBooleanValidator, } from '../Validators.js';
|
|
6
|
+
import { _registerNode } from '../Global.js';
|
|
7
7
|
// grapheme segmentation: one entry per user-perceived character, so flags,
|
|
8
8
|
// ZWJ emoji sequences and combining marks stay together
|
|
9
9
|
const segmenter = typeof Intl !== 'undefined' && Intl.Segmenter
|
|
@@ -25,7 +25,13 @@ export function stringToArray(string) {
|
|
|
25
25
|
// constants
|
|
26
26
|
const AUTO = 'auto',
|
|
27
27
|
//CANVAS = 'canvas',
|
|
28
|
-
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 = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', RTL = 'rtl', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…',
|
|
28
|
+
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 = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', RTL = 'rtl', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…',
|
|
29
|
+
// Chinese and Japanese have no spaces between words, so a line can break next
|
|
30
|
+
// to any of their characters. Korean does use spaces, so it is left out
|
|
31
|
+
CJK = /[\p{Script=Han}\u3000-\u30FF\uFF00-\uFF9F]/u,
|
|
32
|
+
// except where punctuation, or a mark like 々 that repeats the character
|
|
33
|
+
// before it, has to stay with the text it belongs to
|
|
34
|
+
NO_LINE_START = /[\p{Pe}\p{Pf}\p{Pd}、。,.!?:;…・,.!?:;々〻ゝゞヽヾ〃。、・%]/u, NO_LINE_END = /[\p{Ps}\p{Pi}]/u, ATTR_CHANGE_LIST = [
|
|
29
35
|
'direction',
|
|
30
36
|
'fontFamily',
|
|
31
37
|
'fontSize',
|
|
@@ -46,12 +52,8 @@ CENTER = 'center', INHERIT = 'inherit', JUSTIFY = 'justify', CHANGE_KONVA = 'Cha
|
|
|
46
52
|
// This feature check detects that bug so we can work around it with a buffer canvas.
|
|
47
53
|
// Not covered by automated tests (our CI doesn't run Safari).
|
|
48
54
|
// Once Safari fixes the issue this check can be removed.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (_shadowOpacityBuggy !== null) {
|
|
52
|
-
return _shadowOpacityBuggy;
|
|
53
|
-
}
|
|
54
|
-
_shadowOpacityBuggy = false;
|
|
55
|
+
const hasShadowOpacityBug = _perCanvasBackend(() => {
|
|
56
|
+
let buggy = false;
|
|
55
57
|
let c;
|
|
56
58
|
try {
|
|
57
59
|
c = Util.createCanvasElement();
|
|
@@ -70,7 +72,7 @@ function hasShadowOpacityBug() {
|
|
|
70
72
|
const data = ctx.getImageData(0, 0, 10, 10).data;
|
|
71
73
|
for (let i = 3; i < data.length; i += 4) {
|
|
72
74
|
if (data[i] > 0) {
|
|
73
|
-
|
|
75
|
+
buggy = true;
|
|
74
76
|
break;
|
|
75
77
|
}
|
|
76
78
|
}
|
|
@@ -84,8 +86,8 @@ function hasShadowOpacityBug() {
|
|
|
84
86
|
Util.releaseCanvas(c);
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
+
return buggy;
|
|
90
|
+
});
|
|
89
91
|
function normalizeFontFamily(fontFamily) {
|
|
90
92
|
return fontFamily
|
|
91
93
|
.split(',')
|
|
@@ -100,14 +102,6 @@ function normalizeFontFamily(fontFamily) {
|
|
|
100
102
|
})
|
|
101
103
|
.join(', ');
|
|
102
104
|
}
|
|
103
|
-
let dummyContext;
|
|
104
|
-
export function getDummyContext() {
|
|
105
|
-
if (dummyContext) {
|
|
106
|
-
return dummyContext;
|
|
107
|
-
}
|
|
108
|
-
dummyContext = Util.createCanvasElement().getContext(CONTEXT_2D);
|
|
109
|
-
return dummyContext;
|
|
110
|
-
}
|
|
111
105
|
function _fillFunc(context) {
|
|
112
106
|
// re-apply a per-character style set by charRenderFunc (see _sceneFunc)
|
|
113
107
|
if (this._partialFillStyle) {
|
|
@@ -488,7 +482,7 @@ export class Text extends Shape {
|
|
|
488
482
|
return getDummyContext().measureText(text).width + spacing;
|
|
489
483
|
}
|
|
490
484
|
_setTextData() {
|
|
491
|
-
let lines = this.text().split(
|
|
485
|
+
let lines = this.text().split(/\r?\n/), fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, width = this.attrs.width, height = this.attrs.height, fixedWidth = width !== AUTO && width !== undefined, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxWidth = width - padding * 2, maxHeightPx = height - padding * 2, currentHeightPx = 0, wrap = this.wrap(),
|
|
492
486
|
// align = this.align(),
|
|
493
487
|
shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis();
|
|
494
488
|
// measured here so getSelfRect, which runs per drag frame, needs no
|
|
@@ -523,7 +517,14 @@ export class Text extends Shape {
|
|
|
523
517
|
const length = graphemes.length;
|
|
524
518
|
let start = 0;
|
|
525
519
|
const text = (end) => graphemes.slice(start, end).join('');
|
|
526
|
-
|
|
520
|
+
// a line can end before or at a space, after a dash (never before
|
|
521
|
+
// one), or next to a Chinese or Japanese character
|
|
522
|
+
const isBreak = (i) => graphemes[i] === SPACE ||
|
|
523
|
+
graphemes[i + 1] === SPACE ||
|
|
524
|
+
(graphemes[i] === DASH && graphemes[i + 1] !== DASH) ||
|
|
525
|
+
((CJK.test(graphemes[i]) || CJK.test(graphemes[i + 1])) &&
|
|
526
|
+
!NO_LINE_START.test(graphemes[i + 1]) &&
|
|
527
|
+
!NO_LINE_END.test(graphemes[i]));
|
|
527
528
|
// graphemes per line, estimated from the average grapheme width
|
|
528
529
|
const perLine = Math.max(1, Math.ceil((length * maxWidth) / lineWidth));
|
|
529
530
|
while (start < length) {
|
|
@@ -580,10 +581,10 @@ export class Text extends Shape {
|
|
|
580
581
|
}
|
|
581
582
|
break;
|
|
582
583
|
}
|
|
583
|
-
if (wrapAtWord
|
|
584
|
-
//
|
|
584
|
+
if (wrapAtWord) {
|
|
585
|
+
// end the line at its last break opportunity
|
|
585
586
|
let wrapIndex = low - 1;
|
|
586
|
-
while (wrapIndex >= start && !isBreak(
|
|
587
|
+
while (wrapIndex >= start && !isBreak(wrapIndex)) {
|
|
587
588
|
wrapIndex--;
|
|
588
589
|
}
|
|
589
590
|
if (wrapIndex >= start) {
|
|
@@ -864,7 +865,8 @@ Factory.addGetterSetter(Text, 'lineHeight', 1, getNumberValidator());
|
|
|
864
865
|
/**
|
|
865
866
|
* get/set wrap. Can be "word", "char", or "none". Default is "word".
|
|
866
867
|
* In "word" wrapping any word still can be wrapped if it can't be placed in the required width
|
|
867
|
-
* without breaks.
|
|
868
|
+
* without breaks. Chinese and Japanese text can wrap between characters, but not
|
|
869
|
+
* before closing punctuation or after opening punctuation.
|
|
868
870
|
* @name Konva.Text#wrap
|
|
869
871
|
* @method
|
|
870
872
|
* @param {String} wrap
|
package/lib/shapes/TextPath.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Transform, Util } from
|
|
2
|
-
import { Factory } from
|
|
3
|
-
import { Shape } from
|
|
4
|
-
import { Path } from
|
|
5
|
-
import { Text, getDecorationLineWidth,
|
|
6
|
-
import { getNumberValidator } from
|
|
7
|
-
import { _registerNode } from
|
|
1
|
+
import { Transform, Util, getDummyContext } from '../Util.js';
|
|
2
|
+
import { Factory } from '../Factory.js';
|
|
3
|
+
import { Shape } from '../Shape.js';
|
|
4
|
+
import { Path } from './Path.js';
|
|
5
|
+
import { Text, getDecorationLineWidth, stringToArray } from './Text.js';
|
|
6
|
+
import { getNumberValidator } from '../Validators.js';
|
|
7
|
+
import { _registerNode } from '../Global.js';
|
|
8
8
|
const EMPTY_STRING = '', NORMAL = 'normal';
|
|
9
9
|
function _fillFunc(context) {
|
|
10
10
|
context.fillText(this.partialText, 0, 0);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Util, Transform } from
|
|
2
|
-
import { Factory } from
|
|
3
|
-
import { Node } from
|
|
4
|
-
import { Shape } from
|
|
5
|
-
import { Rect } from
|
|
6
|
-
import { Group } from
|
|
7
|
-
import { Container } from
|
|
8
|
-
import { Konva } from
|
|
9
|
-
import { getBooleanValidator, getNumberValidator } from
|
|
10
|
-
import { _registerNode } from
|
|
1
|
+
import { Util, Transform } from '../Util.js';
|
|
2
|
+
import { Factory } from '../Factory.js';
|
|
3
|
+
import { Node } from '../Node.js';
|
|
4
|
+
import { Shape } from '../Shape.js';
|
|
5
|
+
import { Rect } from './Rect.js';
|
|
6
|
+
import { Group } from '../Group.js';
|
|
7
|
+
import { Container } from '../Container.js';
|
|
8
|
+
import { Konva } from '../Global.js';
|
|
9
|
+
import { getBooleanValidator, getNumberValidator } from '../Validators.js';
|
|
10
|
+
import { _registerNode } from '../Global.js';
|
|
11
11
|
const EVENTS_NAME = 'tr-konva';
|
|
12
12
|
const ATTR_CHANGE_LIST = [
|
|
13
13
|
'resizeEnabledChange',
|
|
@@ -777,7 +777,8 @@ export class Transformer extends Group {
|
|
|
777
777
|
});
|
|
778
778
|
}
|
|
779
779
|
_handleMouseDown(e) {
|
|
780
|
-
var _a
|
|
780
|
+
var _a;
|
|
781
|
+
var _b;
|
|
781
782
|
if (e.evt.button !== undefined && !Konva.dragButtons.includes(e.evt.button))
|
|
782
783
|
return;
|
|
783
784
|
// do nothing if we already transforming
|
package/lib/shapes/Wedge.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Factory } from
|
|
2
|
-
import { Shape } from
|
|
3
|
-
import { Konva } from
|
|
4
|
-
import { getNumberValidator } from
|
|
5
|
-
import { _registerNode } from
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { Konva } from '../Global.js';
|
|
4
|
+
import { getNumberValidator } from '../Validators.js';
|
|
5
|
+
import { _registerNode } from '../Global.js';
|
|
6
6
|
/**
|
|
7
7
|
* Wedge constructor
|
|
8
8
|
* @constructor
|