konva 10.3.3 → 10.4.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 +1 -1
- package/konva.js +1327 -1572
- package/konva.min.js +4 -4
- package/lib/Animation.d.ts +63 -3
- package/lib/Animation.js +86 -65
- package/lib/BezierFunctions.d.ts +10 -0
- package/lib/BezierFunctions.js +32 -0
- package/lib/Canvas.d.ts +53 -0
- package/lib/Canvas.js +93 -34
- package/lib/Container.d.ts +156 -9
- package/lib/Container.js +260 -25
- package/lib/Context.d.ts +247 -0
- package/lib/Context.js +312 -74
- package/lib/Core.js +1 -0
- package/lib/DragAndDrop.d.ts +1 -0
- package/lib/DragAndDrop.js +66 -17
- package/lib/Factory.d.ts +24 -1
- package/lib/Factory.js +14 -20
- package/lib/FastLayer.d.ts +14 -1
- package/lib/FastLayer.js +14 -1
- package/lib/Global.d.ts +114 -3
- package/lib/Global.js +134 -5
- package/lib/Group.d.ts +11 -0
- package/lib/Group.js +11 -0
- package/lib/Layer.d.ts +128 -3
- package/lib/Layer.js +260 -49
- package/lib/Node.d.ts +692 -30
- package/lib/Node.js +1534 -202
- package/lib/PointerEvents.d.ts +2 -1
- package/lib/PointerEvents.js +19 -1
- package/lib/Shape.d.ts +99 -14
- package/lib/Shape.js +1101 -67
- package/lib/Stage.d.ts +81 -1
- package/lib/Stage.js +166 -7
- package/lib/Tween.d.ts +159 -4
- package/lib/Tween.js +243 -24
- package/lib/Util.d.ts +147 -4
- package/lib/Util.js +332 -82
- package/lib/Validators.d.ts +0 -2
- package/lib/Validators.js +3 -25
- package/lib/_CoreInternals.d.ts +10 -6
- package/lib/_CoreInternals.js +1 -0
- package/lib/_FullInternals.d.ts +15 -6
- package/lib/_FullInternals.js +7 -0
- package/lib/canvas-backend.js +6 -0
- package/lib/filters/Blur.d.ts +18 -0
- package/lib/filters/Blur.js +97 -24
- package/lib/filters/Brighten.d.ts +21 -0
- package/lib/filters/Brighten.js +24 -0
- package/lib/filters/Brightness.d.ts +11 -0
- package/lib/filters/Brightness.js +16 -0
- package/lib/filters/Contrast.d.ts +10 -0
- package/lib/filters/Contrast.js +21 -0
- package/lib/filters/Emboss.d.ts +20 -0
- package/lib/filters/Emboss.js +68 -8
- package/lib/filters/Enhance.d.ts +14 -0
- package/lib/filters/Enhance.js +34 -0
- package/lib/filters/Grayscale.d.ts +9 -0
- package/lib/filters/Grayscale.js +12 -0
- package/lib/filters/HSL.d.ts +17 -0
- package/lib/filters/HSL.js +48 -5
- package/lib/filters/HSV.d.ts +18 -0
- package/lib/filters/HSV.js +49 -5
- package/lib/filters/Invert.d.ts +9 -0
- package/lib/filters/Invert.js +12 -0
- package/lib/filters/Kaleidoscope.d.ts +12 -0
- package/lib/filters/Kaleidoscope.js +83 -0
- package/lib/filters/Mask.d.ts +11 -0
- package/lib/filters/Mask.js +18 -0
- package/lib/filters/Noise.d.ts +19 -0
- package/lib/filters/Noise.js +19 -0
- package/lib/filters/Pixelate.d.ts +20 -0
- package/lib/filters/Pixelate.js +28 -1
- package/lib/filters/Posterize.d.ts +21 -0
- package/lib/filters/Posterize.js +22 -0
- package/lib/filters/RGB.d.ts +21 -0
- package/lib/filters/RGB.js +43 -28
- package/lib/filters/RGBA.d.ts +23 -0
- package/lib/filters/RGBA.js +28 -41
- package/lib/filters/Sepia.d.ts +9 -0
- package/lib/filters/Sepia.js +10 -0
- package/lib/filters/Solarize.d.ts +10 -0
- package/lib/filters/Solarize.js +11 -0
- package/lib/filters/Threshold.d.ts +22 -0
- package/lib/filters/Threshold.js +22 -0
- package/lib/shapes/Arc.d.ts +40 -0
- package/lib/shapes/Arc.js +89 -6
- package/lib/shapes/Arrow.d.ts +24 -1
- package/lib/shapes/Arrow.js +83 -0
- package/lib/shapes/Circle.d.ts +18 -0
- package/lib/shapes/Circle.js +36 -9
- package/lib/shapes/Ellipse.d.ts +34 -2
- package/lib/shapes/Ellipse.js +67 -9
- package/lib/shapes/Image.d.ts +49 -0
- package/lib/shapes/Image.js +151 -22
- package/lib/shapes/Label.d.ts +65 -1
- package/lib/shapes/Label.js +113 -20
- package/lib/shapes/Line.d.ts +50 -8
- package/lib/shapes/Line.js +116 -20
- package/lib/shapes/Path.d.ts +40 -6
- package/lib/shapes/Path.js +187 -128
- package/lib/shapes/Rect.d.ts +18 -0
- package/lib/shapes/Rect.js +36 -0
- package/lib/shapes/RegularPolygon.d.ts +22 -0
- package/lib/shapes/RegularPolygon.js +70 -0
- package/lib/shapes/Ring.d.ts +19 -0
- package/lib/shapes/Ring.js +51 -5
- package/lib/shapes/Sprite.d.ts +78 -0
- package/lib/shapes/Sprite.js +238 -25
- package/lib/shapes/Star.d.ts +23 -0
- package/lib/shapes/Star.js +62 -0
- package/lib/shapes/Text.d.ts +59 -1
- package/lib/shapes/Text.js +481 -97
- package/lib/shapes/TextPath.d.ts +49 -3
- package/lib/shapes/TextPath.js +278 -34
- package/lib/shapes/Transformer.d.ts +108 -11
- package/lib/shapes/Transformer.js +744 -102
- package/lib/shapes/Wedge.d.ts +22 -0
- package/lib/shapes/Wedge.js +67 -3
- package/lib/skia-backend.js +9 -0
- package/lib/types.d.ts +2 -23
- package/lib/types.js +1 -21
- package/package.json +12 -16
package/lib/Validators.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
export declare function RGBComponent(val: number): number;
|
|
2
|
-
export declare function alphaComponent(val: number): number;
|
|
3
2
|
export declare function getNumberValidator<T>(): ((val: T, attr: string) => T) | undefined;
|
|
4
3
|
export declare function getNumberOrArrayOfNumbersValidator<T>(noOfElements: number): ((val: T, attr: string) => T) | undefined;
|
|
5
4
|
export declare function getNumberOrAutoValidator<T>(): ((val: T, attr: string) => T) | undefined;
|
|
6
5
|
export declare function getStringValidator<T>(): ((val: T, attr: string) => T) | undefined;
|
|
7
6
|
export declare function getStringOrGradientValidator<T>(): ((val: T, attr: string) => T) | undefined;
|
|
8
|
-
export declare function getFunctionValidator<T>(): ((val: T, attr: string) => T) | undefined;
|
|
9
7
|
export declare function getNumberArrayValidator<T>(): ((val: T, attr: string) => T) | undefined;
|
|
10
8
|
export declare function getBooleanValidator<T>(): ((val: T, attr: string) => T) | undefined;
|
|
11
9
|
export declare function getComponentValidator<T>(components: string[]): ((val: T, attr: string) => T) | undefined;
|
package/lib/Validators.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Konva } from "./Global.js";
|
|
2
|
-
import { Util } from "./Util.js";
|
|
2
|
+
import { TypedArray, Util } from "./Util.js";
|
|
3
3
|
function _formatValue(val) {
|
|
4
4
|
if (Util._isString(val)) {
|
|
5
5
|
return '"' + val + '"';
|
|
@@ -21,15 +21,6 @@ export function RGBComponent(val) {
|
|
|
21
21
|
}
|
|
22
22
|
return Math.round(val);
|
|
23
23
|
}
|
|
24
|
-
export function alphaComponent(val) {
|
|
25
|
-
if (val > 1) {
|
|
26
|
-
return 1;
|
|
27
|
-
}
|
|
28
|
-
else if (val < 0.0001) {
|
|
29
|
-
return 0.0001;
|
|
30
|
-
}
|
|
31
|
-
return val;
|
|
32
|
-
}
|
|
33
24
|
export function getNumberValidator() {
|
|
34
25
|
if (Konva.isUnminified) {
|
|
35
26
|
return function (val, attr) {
|
|
@@ -104,24 +95,10 @@ export function getStringOrGradientValidator() {
|
|
|
104
95
|
};
|
|
105
96
|
}
|
|
106
97
|
}
|
|
107
|
-
export function getFunctionValidator() {
|
|
108
|
-
if (Konva.isUnminified) {
|
|
109
|
-
return function (val, attr) {
|
|
110
|
-
if (!Util._isFunction(val)) {
|
|
111
|
-
Util.warn(_formatValue(val) +
|
|
112
|
-
' is a not valid value for "' +
|
|
113
|
-
attr +
|
|
114
|
-
'" attribute. The value should be a function.');
|
|
115
|
-
}
|
|
116
|
-
return val;
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
98
|
export function getNumberArrayValidator() {
|
|
121
99
|
if (Konva.isUnminified) {
|
|
122
100
|
return function (val, attr) {
|
|
123
|
-
|
|
124
|
-
if (TypedArray && val instanceof TypedArray) {
|
|
101
|
+
if (val instanceof TypedArray) {
|
|
125
102
|
return val;
|
|
126
103
|
}
|
|
127
104
|
if (!Util._isArray(val)) {
|
|
@@ -162,6 +139,7 @@ export function getBooleanValidator() {
|
|
|
162
139
|
export function getComponentValidator(components) {
|
|
163
140
|
if (Konva.isUnminified) {
|
|
164
141
|
return function (val, attr) {
|
|
142
|
+
// ignore validation on undefined value, because it will reset to defalt
|
|
165
143
|
if (val === undefined || val === null) {
|
|
166
144
|
return val;
|
|
167
145
|
}
|
package/lib/_CoreInternals.d.ts
CHANGED
|
@@ -28,9 +28,6 @@ export declare const Konva: {
|
|
|
28
28
|
_mouseInDblClickWindow: boolean;
|
|
29
29
|
_touchInDblClickWindow: boolean;
|
|
30
30
|
_pointerInDblClickWindow: boolean;
|
|
31
|
-
_mouseDblClickPointerId: null;
|
|
32
|
-
_touchDblClickPointerId: null;
|
|
33
|
-
_pointerDblClickPointerId: null;
|
|
34
31
|
_renderBackend: string;
|
|
35
32
|
legacyTextRendering: boolean;
|
|
36
33
|
pixelRatio: number;
|
|
@@ -117,13 +114,13 @@ export declare const Konva: {
|
|
|
117
114
|
b: number;
|
|
118
115
|
a: number;
|
|
119
116
|
} | undefined;
|
|
117
|
+
_getPointsRect(points: ArrayLike<number>): import("./types.ts").IRect;
|
|
120
118
|
haveIntersection(r1: import("./types.ts").IRect, r2: import("./types.ts").IRect): boolean;
|
|
121
119
|
cloneObject<Any>(obj: Any): Any;
|
|
120
|
+
_cloneValue(val: any): any;
|
|
122
121
|
cloneArray(arr: Array<any>): any[];
|
|
123
122
|
degToRad(deg: number): number;
|
|
124
123
|
radToDeg(rad: number): number;
|
|
125
|
-
_degToRad(deg: number): number;
|
|
126
|
-
_radToDeg(rad: number): number;
|
|
127
124
|
_getRotation(radians: number): number;
|
|
128
125
|
_capitalize(str: string): string;
|
|
129
126
|
throw(str: string): never;
|
|
@@ -134,10 +131,11 @@ export declare const Konva: {
|
|
|
134
131
|
_getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
|
|
135
132
|
_getProjectionToLine(pt: import("./types.ts").Vector2d, line: Array<import("./types.ts").Vector2d>, isClosed: boolean): import("./types.ts").Vector2d;
|
|
136
133
|
_prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
|
|
137
|
-
_prepareToStringify<T>(obj: any): T
|
|
134
|
+
_prepareToStringify<T>(obj: any, ancestors?: Set<object>): T;
|
|
138
135
|
_assign<T, U>(target: T, source: U): T & U;
|
|
139
136
|
_getFirstPointerId(evt: any): any;
|
|
140
137
|
releaseCanvas(...canvases: HTMLCanvasElement[]): void;
|
|
138
|
+
_cornerRadii(cornerRadius: number | number[], width: number, height: number): [number, number, number, number];
|
|
141
139
|
drawRoundedRectPath(context: Context, width: number, height: number, cornerRadius: number | number[]): void;
|
|
142
140
|
drawRoundedPolygonPath(context: Context, points: import("./types.ts").Vector2d[], sides: number, radius: number, cornerRadius: number | number[]): void;
|
|
143
141
|
};
|
|
@@ -158,6 +156,7 @@ export declare const Konva: {
|
|
|
158
156
|
startPointerPos: import("./types.ts").Vector2d;
|
|
159
157
|
offset: import("./types.ts").Vector2d;
|
|
160
158
|
pointerId?: number;
|
|
159
|
+
lastPos?: import("./types.ts").Vector2d;
|
|
161
160
|
startEvent?: any;
|
|
162
161
|
dragStatus: "ready" | "dragging" | "stopped";
|
|
163
162
|
}>;
|
|
@@ -195,6 +194,11 @@ export declare const Konva: {
|
|
|
195
194
|
};
|
|
196
195
|
export declare namespace Konva {
|
|
197
196
|
type Vector2d = import('./types.ts').Vector2d;
|
|
197
|
+
type IRect = import('./types.ts').IRect;
|
|
198
|
+
type GetSet<Type, This> = import('./types.ts').GetSet<Type, This>;
|
|
199
|
+
type Filter = import('./Node.ts').Filter;
|
|
200
|
+
type LineCap = import('./Shape.ts').LineCap;
|
|
201
|
+
type LineJoin = import('./Shape.ts').LineJoin;
|
|
198
202
|
type Node = import('./Node.ts').Node;
|
|
199
203
|
type NodeConfig = import('./Node.ts').NodeConfig;
|
|
200
204
|
type KonvaEventObject<EventType> = import('./Node.ts').KonvaEventObject<EventType>;
|
package/lib/_CoreInternals.js
CHANGED
package/lib/_FullInternals.d.ts
CHANGED
|
@@ -34,9 +34,6 @@ export declare const Konva: {
|
|
|
34
34
|
_mouseInDblClickWindow: boolean;
|
|
35
35
|
_touchInDblClickWindow: boolean;
|
|
36
36
|
_pointerInDblClickWindow: boolean;
|
|
37
|
-
_mouseDblClickPointerId: null;
|
|
38
|
-
_touchDblClickPointerId: null;
|
|
39
|
-
_pointerDblClickPointerId: null;
|
|
40
37
|
_renderBackend: string;
|
|
41
38
|
legacyTextRendering: boolean;
|
|
42
39
|
pixelRatio: number;
|
|
@@ -123,13 +120,13 @@ export declare const Konva: {
|
|
|
123
120
|
b: number;
|
|
124
121
|
a: number;
|
|
125
122
|
} | undefined;
|
|
123
|
+
_getPointsRect(points: ArrayLike<number>): import("./types.ts").IRect;
|
|
126
124
|
haveIntersection(r1: import("./types.ts").IRect, r2: import("./types.ts").IRect): boolean;
|
|
127
125
|
cloneObject<Any>(obj: Any): Any;
|
|
126
|
+
_cloneValue(val: any): any;
|
|
128
127
|
cloneArray(arr: Array<any>): any[];
|
|
129
128
|
degToRad(deg: number): number;
|
|
130
129
|
radToDeg(rad: number): number;
|
|
131
|
-
_degToRad(deg: number): number;
|
|
132
|
-
_radToDeg(rad: number): number;
|
|
133
130
|
_getRotation(radians: number): number;
|
|
134
131
|
_capitalize(str: string): string;
|
|
135
132
|
throw(str: string): never;
|
|
@@ -140,10 +137,11 @@ export declare const Konva: {
|
|
|
140
137
|
_getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
|
|
141
138
|
_getProjectionToLine(pt: import("./types.ts").Vector2d, line: Array<import("./types.ts").Vector2d>, isClosed: boolean): import("./types.ts").Vector2d;
|
|
142
139
|
_prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
|
|
143
|
-
_prepareToStringify<T>(obj: any): T
|
|
140
|
+
_prepareToStringify<T>(obj: any, ancestors?: Set<object>): T;
|
|
144
141
|
_assign<T, U>(target: T, source: U): T & U;
|
|
145
142
|
_getFirstPointerId(evt: any): any;
|
|
146
143
|
releaseCanvas(...canvases: HTMLCanvasElement[]): void;
|
|
144
|
+
_cornerRadii(cornerRadius: number | number[], width: number, height: number): [number, number, number, number];
|
|
147
145
|
drawRoundedRectPath(context: import("./Context.ts").Context, width: number, height: number, cornerRadius: number | number[]): void;
|
|
148
146
|
drawRoundedPolygonPath(context: import("./Context.ts").Context, points: import("./types.ts").Vector2d[], sides: number, radius: number, cornerRadius: number | number[]): void;
|
|
149
147
|
};
|
|
@@ -164,6 +162,7 @@ export declare const Konva: {
|
|
|
164
162
|
startPointerPos: import("./types.ts").Vector2d;
|
|
165
163
|
offset: import("./types.ts").Vector2d;
|
|
166
164
|
pointerId?: number;
|
|
165
|
+
lastPos?: import("./types.ts").Vector2d;
|
|
167
166
|
startEvent?: any;
|
|
168
167
|
dragStatus: "ready" | "dragging" | "stopped";
|
|
169
168
|
}>;
|
|
@@ -217,6 +216,10 @@ export declare const Konva: {
|
|
|
217
216
|
TextPath: typeof TextPath;
|
|
218
217
|
Transformer: typeof Transformer;
|
|
219
218
|
Wedge: typeof Wedge;
|
|
219
|
+
/**
|
|
220
|
+
* @namespace Filters
|
|
221
|
+
* @memberof Konva
|
|
222
|
+
*/
|
|
220
223
|
Filters: {
|
|
221
224
|
Blur: import("./Node.ts").Filter;
|
|
222
225
|
Brightness: import("./Node.ts").Filter;
|
|
@@ -242,6 +245,12 @@ export declare const Konva: {
|
|
|
242
245
|
};
|
|
243
246
|
export declare namespace Konva {
|
|
244
247
|
type Vector2d = Core.Vector2d;
|
|
248
|
+
type IRect = Core.IRect;
|
|
249
|
+
type GetSet<Type, This> = Core.GetSet<Type, This>;
|
|
250
|
+
type Filter = Core.Filter;
|
|
251
|
+
type LineCap = Core.LineCap;
|
|
252
|
+
type LineJoin = Core.LineJoin;
|
|
253
|
+
type Box = import('./shapes/Transformer.ts').Box;
|
|
245
254
|
type Node = Core.Node;
|
|
246
255
|
type NodeConfig = Core.NodeConfig;
|
|
247
256
|
type KonvaEventObject<EventType> = Core.KonvaEventObject<EventType>;
|
package/lib/_FullInternals.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
// we need to import core of the Konva and then extend it with all additional objects
|
|
1
2
|
import { Konva as Core } from "./_CoreInternals.js";
|
|
3
|
+
// shapes
|
|
2
4
|
import { Arc } from "./shapes/Arc.js";
|
|
3
5
|
import { Arrow } from "./shapes/Arrow.js";
|
|
4
6
|
import { Circle } from "./shapes/Circle.js";
|
|
@@ -16,6 +18,7 @@ import { Text } from "./shapes/Text.js";
|
|
|
16
18
|
import { TextPath } from "./shapes/TextPath.js";
|
|
17
19
|
import { Transformer } from "./shapes/Transformer.js";
|
|
18
20
|
import { Wedge } from "./shapes/Wedge.js";
|
|
21
|
+
// filters
|
|
19
22
|
import { Blur } from "./filters/Blur.js";
|
|
20
23
|
import { Brighten } from "./filters/Brighten.js";
|
|
21
24
|
import { Brightness } from "./filters/Brightness.js";
|
|
@@ -55,6 +58,10 @@ export const Konva = Core.Util._assign(Core, {
|
|
|
55
58
|
TextPath,
|
|
56
59
|
Transformer,
|
|
57
60
|
Wedge,
|
|
61
|
+
/**
|
|
62
|
+
* @namespace Filters
|
|
63
|
+
* @memberof Konva
|
|
64
|
+
*/
|
|
58
65
|
Filters: {
|
|
59
66
|
Blur,
|
|
60
67
|
Brightness,
|
package/lib/canvas-backend.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
var _b;
|
|
3
3
|
import { Konva } from "./_CoreInternals.js";
|
|
4
|
+
// @ts-ignore
|
|
4
5
|
import * as Canvas from 'canvas';
|
|
5
6
|
const canvas = Canvas['default'] || Canvas;
|
|
7
|
+
// @ts-ignore
|
|
6
8
|
global.DOMMatrix = canvas.DOMMatrix;
|
|
9
|
+
// @ts-ignore
|
|
7
10
|
(_a = (_b = global).Path2D) !== null && _a !== void 0 ? _a : (_b.Path2D = class Path2D {
|
|
8
11
|
constructor(path) {
|
|
9
12
|
this.path = path;
|
|
@@ -19,9 +22,12 @@ Konva.Util['createCanvasElement'] = () => {
|
|
|
19
22
|
}
|
|
20
23
|
return node;
|
|
21
24
|
};
|
|
25
|
+
// create image in Node env
|
|
22
26
|
Konva.Util.createImageElement = () => {
|
|
23
27
|
const node = new canvas.Image();
|
|
24
28
|
return node;
|
|
25
29
|
};
|
|
26
30
|
Konva._renderBackend = 'node-canvas';
|
|
31
|
+
// the core Konva object, without shapes and filters. `import 'konva'` extends
|
|
32
|
+
// this same object with them
|
|
27
33
|
export default Konva;
|
package/lib/filters/Blur.d.ts
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
1
|
import type { Filter } from '../Node.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Blur Filter
|
|
4
|
+
* @function
|
|
5
|
+
* @name Blur
|
|
6
|
+
* @memberof Konva.Filters
|
|
7
|
+
* @param {Object} imageData
|
|
8
|
+
* @example
|
|
9
|
+
* node.cache();
|
|
10
|
+
* node.filters([Konva.Filters.Blur]);
|
|
11
|
+
* node.blurRadius(10);
|
|
12
|
+
*/
|
|
2
13
|
export declare const Blur: Filter;
|
|
14
|
+
/**
|
|
15
|
+
* get/set blur radius. Use with {@link Konva.Filters.Blur} filter
|
|
16
|
+
* @name Konva.Node#blurRadius
|
|
17
|
+
* @method
|
|
18
|
+
* @param {Integer} radius
|
|
19
|
+
* @returns {Integer}
|
|
20
|
+
*/
|
package/lib/filters/Blur.js
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
import { Factory } from "../Factory.js";
|
|
2
2
|
import { Node } from "../Node.js";
|
|
3
3
|
import { getNumberValidator } from "../Validators.js";
|
|
4
|
+
/*
|
|
5
|
+
the Gauss filter
|
|
6
|
+
master repo: https://github.com/pavelpower/kineticjsGaussFilter
|
|
7
|
+
*/
|
|
8
|
+
/*
|
|
9
|
+
|
|
10
|
+
StackBlur - a fast almost Gaussian Blur For Canvas
|
|
11
|
+
|
|
12
|
+
Version: 0.5
|
|
13
|
+
Author: Mario Klingemann
|
|
14
|
+
Contact: mario@quasimondo.com
|
|
15
|
+
Website: http://www.quasimondo.com/StackBlurForCanvas
|
|
16
|
+
Twitter: @quasimondo
|
|
17
|
+
|
|
18
|
+
In case you find this class useful - especially in commercial projects -
|
|
19
|
+
I am not totally unhappy for a small donation to my PayPal account
|
|
20
|
+
mario@quasimondo.de
|
|
21
|
+
|
|
22
|
+
Or support me on flattr:
|
|
23
|
+
https://flattr.com/thing/72791/StackBlur-a-fast-almost-Gaussian-Blur-Effect-for-CanvasJavascript
|
|
24
|
+
|
|
25
|
+
Copyright (c) 2010 Mario Klingemann
|
|
26
|
+
|
|
27
|
+
Permission is hereby granted, free of charge, to any person
|
|
28
|
+
obtaining a copy of this software and associated documentation
|
|
29
|
+
files (the "Software"), to deal in the Software without
|
|
30
|
+
restriction, including without limitation the rights to use,
|
|
31
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
32
|
+
copies of the Software, and to permit persons to whom the
|
|
33
|
+
Software is furnished to do so, subject to the following
|
|
34
|
+
conditions:
|
|
35
|
+
|
|
36
|
+
The above copyright notice and this permission notice shall be
|
|
37
|
+
included in all copies or substantial portions of the Software.
|
|
38
|
+
|
|
39
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
40
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
41
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
42
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
43
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
44
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
45
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
46
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
47
|
+
* @license MIT
|
|
48
|
+
*/
|
|
4
49
|
function BlurStack() {
|
|
5
50
|
this.r = 0;
|
|
6
51
|
this.g = 0;
|
|
@@ -43,6 +88,14 @@ const shg_table = [
|
|
|
43
88
|
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
|
44
89
|
24, 24, 24, 24, 24, 24, 24,
|
|
45
90
|
];
|
|
91
|
+
// the horizontal pass blurs premultiplied colour, otherwise transparent
|
|
92
|
+
// pixels bleed their colour into their neighbours; the vertical pass
|
|
93
|
+
// unpremultiplies again
|
|
94
|
+
function premultiply(channel, alpha) {
|
|
95
|
+
return alpha === 255 ? channel : (channel * alpha) / 255;
|
|
96
|
+
}
|
|
97
|
+
// the stack sums overflow 32-bit integers above this radius
|
|
98
|
+
const MAX_RADIUS = 180;
|
|
46
99
|
function filterGaussBlurRGBA(imageData, radius) {
|
|
47
100
|
const pixels = imageData.data, width = imageData.width, height = imageData.height;
|
|
48
101
|
let p, yi, yw, r_sum, g_sum, b_sum, a_sum, r_out_sum, g_out_sum, b_out_sum, a_out_sum, r_in_sum, g_in_sum, b_in_sum, a_in_sum, pr, pg, pb, pa, rbs;
|
|
@@ -66,10 +119,14 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
66
119
|
b_sum =
|
|
67
120
|
a_sum =
|
|
68
121
|
0;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
122
|
+
pa = pixels[yi + 3];
|
|
123
|
+
pr = premultiply(pixels[yi], pa);
|
|
124
|
+
pg = premultiply(pixels[yi + 1], pa);
|
|
125
|
+
pb = premultiply(pixels[yi + 2], pa);
|
|
126
|
+
r_out_sum = radiusPlus1 * pr;
|
|
127
|
+
g_out_sum = radiusPlus1 * pg;
|
|
128
|
+
b_out_sum = radiusPlus1 * pb;
|
|
129
|
+
a_out_sum = radiusPlus1 * pa;
|
|
73
130
|
r_sum += sumFactor * pr;
|
|
74
131
|
g_sum += sumFactor * pg;
|
|
75
132
|
b_sum += sumFactor * pb;
|
|
@@ -84,10 +141,12 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
84
141
|
}
|
|
85
142
|
for (let i = 1; i < radiusPlus1; i++) {
|
|
86
143
|
p = yi + ((widthMinus1 < i ? widthMinus1 : i) << 2);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
144
|
+
pa = pixels[p + 3];
|
|
145
|
+
r_sum +=
|
|
146
|
+
(stack.r = pr = premultiply(pixels[p], pa)) * (rbs = radiusPlus1 - i);
|
|
147
|
+
g_sum += (stack.g = pg = premultiply(pixels[p + 1], pa)) * rbs;
|
|
148
|
+
b_sum += (stack.b = pb = premultiply(pixels[p + 2], pa)) * rbs;
|
|
149
|
+
a_sum += (stack.a = pa) * rbs;
|
|
91
150
|
r_in_sum += pr;
|
|
92
151
|
g_in_sum += pg;
|
|
93
152
|
b_in_sum += pb;
|
|
@@ -97,16 +156,10 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
97
156
|
stackIn = stackStart;
|
|
98
157
|
stackOut = stackEnd;
|
|
99
158
|
for (let x = 0; x < width; x++) {
|
|
100
|
-
pixels[yi
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
pixels[yi + 1] = ((g_sum * mul_sum) >> shg_sum) * pa;
|
|
105
|
-
pixels[yi + 2] = ((b_sum * mul_sum) >> shg_sum) * pa;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
pixels[yi] = pixels[yi + 1] = pixels[yi + 2] = 0;
|
|
109
|
-
}
|
|
159
|
+
pixels[yi] = (r_sum * mul_sum) >> shg_sum;
|
|
160
|
+
pixels[yi + 1] = (g_sum * mul_sum) >> shg_sum;
|
|
161
|
+
pixels[yi + 2] = (b_sum * mul_sum) >> shg_sum;
|
|
162
|
+
pixels[yi + 3] = (a_sum * mul_sum) >> shg_sum;
|
|
110
163
|
r_sum -= r_out_sum;
|
|
111
164
|
g_sum -= g_out_sum;
|
|
112
165
|
b_sum -= b_out_sum;
|
|
@@ -116,10 +169,11 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
116
169
|
b_out_sum -= stackIn.b;
|
|
117
170
|
a_out_sum -= stackIn.a;
|
|
118
171
|
p = (yw + ((p = x + radius + 1) < widthMinus1 ? p : widthMinus1)) << 2;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
172
|
+
pa = pixels[p + 3];
|
|
173
|
+
r_in_sum += stackIn.r = premultiply(pixels[p], pa);
|
|
174
|
+
g_in_sum += stackIn.g = premultiply(pixels[p + 1], pa);
|
|
175
|
+
b_in_sum += stackIn.b = premultiply(pixels[p + 2], pa);
|
|
176
|
+
a_in_sum += stackIn.a = pa;
|
|
123
177
|
r_sum += r_in_sum;
|
|
124
178
|
g_sum += g_in_sum;
|
|
125
179
|
b_sum += b_in_sum;
|
|
@@ -165,7 +219,8 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
165
219
|
stack.a = pa;
|
|
166
220
|
stack = stack.next;
|
|
167
221
|
}
|
|
168
|
-
|
|
222
|
+
// the pass primes from the second row, which a 1-pixel-tall image lacks
|
|
223
|
+
let yp = Math.min(1, heightMinus1) * width;
|
|
169
224
|
for (let i = 1; i <= radius; i++) {
|
|
170
225
|
yi = (yp + x) << 2;
|
|
171
226
|
r_sum += (stack.r = pr = pixels[yi]) * (rbs = radiusPlus1 - i);
|
|
@@ -226,10 +281,28 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
226
281
|
}
|
|
227
282
|
}
|
|
228
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Blur Filter
|
|
286
|
+
* @function
|
|
287
|
+
* @name Blur
|
|
288
|
+
* @memberof Konva.Filters
|
|
289
|
+
* @param {Object} imageData
|
|
290
|
+
* @example
|
|
291
|
+
* node.cache();
|
|
292
|
+
* node.filters([Konva.Filters.Blur]);
|
|
293
|
+
* node.blurRadius(10);
|
|
294
|
+
*/
|
|
229
295
|
export const Blur = function Blur(imageData) {
|
|
230
|
-
const radius = Math.round(this.blurRadius());
|
|
296
|
+
const radius = Math.min(Math.round(this.blurRadius()), MAX_RADIUS);
|
|
231
297
|
if (radius > 0) {
|
|
232
298
|
filterGaussBlurRGBA(imageData, radius);
|
|
233
299
|
}
|
|
234
300
|
};
|
|
235
301
|
Factory.addGetterSetter(Node, 'blurRadius', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
302
|
+
/**
|
|
303
|
+
* get/set blur radius. Use with {@link Konva.Filters.Blur} filter
|
|
304
|
+
* @name Konva.Node#blurRadius
|
|
305
|
+
* @method
|
|
306
|
+
* @param {Integer} radius
|
|
307
|
+
* @returns {Integer}
|
|
308
|
+
*/
|
|
@@ -1,2 +1,23 @@
|
|
|
1
1
|
import type { Filter } from '../Node.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Brighten Filter.
|
|
4
|
+
* @deprecated Use {@link Konva.Filters.Brightness} instead for CSS-compatible behavior.
|
|
5
|
+
* This filter uses additive brightness adjustment (adds a constant value to RGB channels).
|
|
6
|
+
* @function
|
|
7
|
+
* @memberof Konva.Filters
|
|
8
|
+
* @param {Object} imageData
|
|
9
|
+
* @example
|
|
10
|
+
* node.cache();
|
|
11
|
+
* node.filters([Konva.Filters.Brighten]);
|
|
12
|
+
* node.brightness(0.8);
|
|
13
|
+
*/
|
|
2
14
|
export declare const Brighten: Filter;
|
|
15
|
+
/**
|
|
16
|
+
* get/set filter brightness. With {@link Konva.Filters.Brighten} it is a number between -1 and 1
|
|
17
|
+
* added to every channel: positive values brighten the pixels and negative values darken them.
|
|
18
|
+
* With {@link Konva.Filters.Brightness} it is a CSS-like multiplier: 1 is no change, 1.5 is 50% brighter.
|
|
19
|
+
* @name Konva.Node#brightness
|
|
20
|
+
* @method
|
|
21
|
+
* @param {Number} brightness
|
|
22
|
+
* @returns {Number}
|
|
23
|
+
*/
|
package/lib/filters/Brighten.js
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
import { Factory } from "../Factory.js";
|
|
2
2
|
import { Node } from "../Node.js";
|
|
3
3
|
import { getNumberValidator } from "../Validators.js";
|
|
4
|
+
/**
|
|
5
|
+
* Brighten Filter.
|
|
6
|
+
* @deprecated Use {@link Konva.Filters.Brightness} instead for CSS-compatible behavior.
|
|
7
|
+
* This filter uses additive brightness adjustment (adds a constant value to RGB channels).
|
|
8
|
+
* @function
|
|
9
|
+
* @memberof Konva.Filters
|
|
10
|
+
* @param {Object} imageData
|
|
11
|
+
* @example
|
|
12
|
+
* node.cache();
|
|
13
|
+
* node.filters([Konva.Filters.Brighten]);
|
|
14
|
+
* node.brightness(0.8);
|
|
15
|
+
*/
|
|
4
16
|
export const Brighten = function (imageData) {
|
|
5
17
|
const brightness = this.brightness() * 255, data = imageData.data, len = data.length;
|
|
6
18
|
for (let i = 0; i < len; i += 4) {
|
|
19
|
+
// red
|
|
7
20
|
data[i] += brightness;
|
|
21
|
+
// green
|
|
8
22
|
data[i + 1] += brightness;
|
|
23
|
+
// blue
|
|
9
24
|
data[i + 2] += brightness;
|
|
10
25
|
}
|
|
11
26
|
};
|
|
12
27
|
Factory.addGetterSetter(Node, 'brightness', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
28
|
+
/**
|
|
29
|
+
* get/set filter brightness. With {@link Konva.Filters.Brighten} it is a number between -1 and 1
|
|
30
|
+
* added to every channel: positive values brighten the pixels and negative values darken them.
|
|
31
|
+
* With {@link Konva.Filters.Brightness} it is a CSS-like multiplier: 1 is no change, 1.5 is 50% brighter.
|
|
32
|
+
* @name Konva.Node#brightness
|
|
33
|
+
* @method
|
|
34
|
+
* @param {Number} brightness
|
|
35
|
+
* @returns {Number}
|
|
36
|
+
*/
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
import type { Filter } from '../Node.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Brightness Filter.
|
|
4
|
+
* CSS-compatible brightness filter that uses multiplicative approach.
|
|
5
|
+
* @function
|
|
6
|
+
* @memberof Konva.Filters
|
|
7
|
+
* @param {Object} imageData
|
|
8
|
+
* @example
|
|
9
|
+
* node.cache();
|
|
10
|
+
* node.filters([Konva.Filters.Brightness]);
|
|
11
|
+
* node.brightness(1.5); // 50% brighter (CSS-compatible)
|
|
12
|
+
*/
|
|
2
13
|
export declare const Brightness: Filter;
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brightness Filter.
|
|
3
|
+
* CSS-compatible brightness filter that uses multiplicative approach.
|
|
4
|
+
* @function
|
|
5
|
+
* @memberof Konva.Filters
|
|
6
|
+
* @param {Object} imageData
|
|
7
|
+
* @example
|
|
8
|
+
* node.cache();
|
|
9
|
+
* node.filters([Konva.Filters.Brightness]);
|
|
10
|
+
* node.brightness(1.5); // 50% brighter (CSS-compatible)
|
|
11
|
+
*/
|
|
1
12
|
export const Brightness = function (imageData) {
|
|
2
13
|
const brightness = this.brightness(), data = imageData.data, len = data.length;
|
|
3
14
|
for (let i = 0; i < len; i += 4) {
|
|
15
|
+
// red
|
|
4
16
|
data[i] = Math.min(255, data[i] * brightness);
|
|
17
|
+
// green
|
|
5
18
|
data[i + 1] = Math.min(255, data[i + 1] * brightness);
|
|
19
|
+
// blue
|
|
6
20
|
data[i + 2] = Math.min(255, data[i + 2] * brightness);
|
|
7
21
|
}
|
|
8
22
|
};
|
|
23
|
+
// Note: brightness property is already defined in Brighten.ts
|
|
24
|
+
// This filter reuses the existing brightness property but with CSS-compatible behavior
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import type { Filter } from '../Node.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Contrast Filter.
|
|
4
|
+
* @function
|
|
5
|
+
* @memberof Konva.Filters
|
|
6
|
+
* @param {Object} imageData
|
|
7
|
+
* @example
|
|
8
|
+
* node.cache();
|
|
9
|
+
* node.filters([Konva.Filters.Contrast]);
|
|
10
|
+
* node.contrast(10);
|
|
11
|
+
*/
|
|
2
12
|
export declare const Contrast: Filter;
|
package/lib/filters/Contrast.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { Factory } from "../Factory.js";
|
|
2
2
|
import { Node } from "../Node.js";
|
|
3
3
|
import { getNumberValidator } from "../Validators.js";
|
|
4
|
+
/**
|
|
5
|
+
* Contrast Filter.
|
|
6
|
+
* @function
|
|
7
|
+
* @memberof Konva.Filters
|
|
8
|
+
* @param {Object} imageData
|
|
9
|
+
* @example
|
|
10
|
+
* node.cache();
|
|
11
|
+
* node.filters([Konva.Filters.Contrast]);
|
|
12
|
+
* node.contrast(10);
|
|
13
|
+
*/
|
|
4
14
|
export const Contrast = function (imageData) {
|
|
5
15
|
const adjust = Math.pow((this.contrast() + 100) / 100, 2);
|
|
6
16
|
const data = imageData.data, nPixels = data.length;
|
|
@@ -9,16 +19,19 @@ export const Contrast = function (imageData) {
|
|
|
9
19
|
red = data[i];
|
|
10
20
|
green = data[i + 1];
|
|
11
21
|
blue = data[i + 2];
|
|
22
|
+
//Red channel
|
|
12
23
|
red /= 255;
|
|
13
24
|
red -= 0.5;
|
|
14
25
|
red *= adjust;
|
|
15
26
|
red += 0.5;
|
|
16
27
|
red *= 255;
|
|
28
|
+
//Green channel
|
|
17
29
|
green /= 255;
|
|
18
30
|
green -= 0.5;
|
|
19
31
|
green *= adjust;
|
|
20
32
|
green += 0.5;
|
|
21
33
|
green *= 255;
|
|
34
|
+
//Blue channel
|
|
22
35
|
blue /= 255;
|
|
23
36
|
blue -= 0.5;
|
|
24
37
|
blue *= adjust;
|
|
@@ -32,4 +45,12 @@ export const Contrast = function (imageData) {
|
|
|
32
45
|
data[i + 2] = blue;
|
|
33
46
|
}
|
|
34
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* get/set filter contrast. The contrast is a number between -100 and 100.
|
|
50
|
+
* Use with {@link Konva.Filters.Contrast} filter.
|
|
51
|
+
* @name Konva.Node#contrast
|
|
52
|
+
* @method
|
|
53
|
+
* @param {Number} contrast value between -100 and 100
|
|
54
|
+
* @returns {Number}
|
|
55
|
+
*/
|
|
35
56
|
Factory.addGetterSetter(Node, 'contrast', 0, getNumberValidator(), Factory.afterSetFilter);
|
package/lib/filters/Emboss.d.ts
CHANGED
|
@@ -1,2 +1,22 @@
|
|
|
1
1
|
import type { Filter } from '../Node.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Emboss Filter.
|
|
4
|
+
* @function
|
|
5
|
+
* @memberof Konva.Filters
|
|
6
|
+
* @param {Object} imageData
|
|
7
|
+
* @example
|
|
8
|
+
* node.cache();
|
|
9
|
+
* node.filters([Konva.Filters.Emboss]);
|
|
10
|
+
* node.embossStrength(0.8);
|
|
11
|
+
* node.embossWhiteLevel(0.3);
|
|
12
|
+
* node.embossDirection('right');
|
|
13
|
+
* node.embossBlend(true);
|
|
14
|
+
*/
|
|
2
15
|
export declare const Emboss: Filter;
|
|
16
|
+
/**
|
|
17
|
+
* get/set emboss blend. Use with {@link Konva.Filters.Emboss} filter.
|
|
18
|
+
* @name Konva.Node#embossBlend
|
|
19
|
+
* @method
|
|
20
|
+
* @param {Boolean} embossBlend
|
|
21
|
+
* @returns {Boolean}
|
|
22
|
+
*/
|