konva 9.3.16 → 9.3.17
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/konva.js +152 -134
- package/konva.min.js +3 -3
- package/lib/Context.js +3 -3
- package/lib/Factory.d.ts +18 -8
- package/lib/Factory.js +12 -11
- package/lib/Global.js +1 -1
- package/lib/Node.d.ts +1 -1
- package/lib/Node.js +2 -2
- package/lib/Shape.d.ts +5 -0
- package/lib/Shape.js +7 -7
- package/lib/Stage.js +7 -6
- package/lib/Tween.js +15 -11
- package/lib/Util.js +6 -5
- package/lib/Validators.d.ts +9 -9
- package/lib/Validators.js +6 -6
- package/lib/filters/Blur.js +2 -1
- package/lib/filters/Brighten.js +2 -2
- package/lib/filters/Contrast.js +3 -2
- package/lib/filters/Emboss.js +4 -3
- package/lib/filters/Enhance.js +6 -5
- package/lib/filters/Grayscale.js +3 -3
- package/lib/filters/HSL.js +2 -2
- package/lib/filters/Invert.js +2 -2
- package/lib/filters/Kaleidoscope.js +31 -31
- package/lib/filters/Mask.js +2 -1
- package/lib/filters/Posterize.js +2 -2
- package/lib/filters/RGB.js +3 -4
- package/lib/filters/Sepia.js +5 -5
- package/lib/shapes/Arrow.js +2 -2
- package/lib/shapes/Label.d.ts +3 -1
- package/lib/shapes/Text.js +12 -8
- package/lib/shapes/TextPath.js +2 -2
- package/lib/shapes/Transformer.js +1 -1
- package/package.json +14 -13
package/konva.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* Konva JavaScript Framework v9.3.
|
|
8
|
+
* Konva JavaScript Framework v9.3.17
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date: Mon
|
|
11
|
+
* Date: Mon Dec 23 2024
|
|
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.3.
|
|
38
|
+
version: '9.3.17',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -433,7 +433,7 @@
|
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
435
|
// CONSTANTS
|
|
436
|
-
|
|
436
|
+
const OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH$1 = '#', EMPTY_STRING$1 = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ', RGB_PAREN = 'rgb(', COLORS = {
|
|
437
437
|
aliceblue: [240, 248, 255],
|
|
438
438
|
antiquewhite: [250, 235, 215],
|
|
439
439
|
aqua: [0, 255, 255],
|
|
@@ -583,7 +583,8 @@
|
|
|
583
583
|
whitesmoke: [245, 245, 245],
|
|
584
584
|
yellow: [255, 255, 0],
|
|
585
585
|
yellowgreen: [154, 205, 5],
|
|
586
|
-
}, RGB_REGEX = /rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)
|
|
586
|
+
}, RGB_REGEX = /rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/;
|
|
587
|
+
let animQueue = [];
|
|
587
588
|
const req = (typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame) ||
|
|
588
589
|
function (f) {
|
|
589
590
|
setTimeout(f, 60);
|
|
@@ -1040,19 +1041,19 @@
|
|
|
1040
1041
|
return pc;
|
|
1041
1042
|
},
|
|
1042
1043
|
_prepareArrayForTween(startArray, endArray, isClosed) {
|
|
1043
|
-
|
|
1044
|
+
const start = [], end = [];
|
|
1044
1045
|
if (startArray.length > endArray.length) {
|
|
1045
1046
|
const temp = endArray;
|
|
1046
1047
|
endArray = startArray;
|
|
1047
1048
|
startArray = temp;
|
|
1048
1049
|
}
|
|
1049
|
-
for (n = 0; n < startArray.length; n += 2) {
|
|
1050
|
+
for (let n = 0; n < startArray.length; n += 2) {
|
|
1050
1051
|
start.push({
|
|
1051
1052
|
x: startArray[n],
|
|
1052
1053
|
y: startArray[n + 1],
|
|
1053
1054
|
});
|
|
1054
1055
|
}
|
|
1055
|
-
for (n = 0; n < endArray.length; n += 2) {
|
|
1056
|
+
for (let n = 0; n < endArray.length; n += 2) {
|
|
1056
1057
|
end.push({
|
|
1057
1058
|
x: endArray[n],
|
|
1058
1059
|
y: endArray[n + 1],
|
|
@@ -1186,8 +1187,8 @@
|
|
|
1186
1187
|
function getNumberOrArrayOfNumbersValidator(noOfElements) {
|
|
1187
1188
|
if (Konva$2.isUnminified) {
|
|
1188
1189
|
return function (val, attr) {
|
|
1189
|
-
|
|
1190
|
-
|
|
1190
|
+
let isNumber = Util._isNumber(val);
|
|
1191
|
+
let isValidArray = Util._isArray(val) && val.length == noOfElements;
|
|
1191
1192
|
if (!isNumber && !isValidArray) {
|
|
1192
1193
|
Util.warn(_formatValue(val) +
|
|
1193
1194
|
' is a not valid value for "' +
|
|
@@ -1203,8 +1204,8 @@
|
|
|
1203
1204
|
function getNumberOrAutoValidator() {
|
|
1204
1205
|
if (Konva$2.isUnminified) {
|
|
1205
1206
|
return function (val, attr) {
|
|
1206
|
-
|
|
1207
|
-
|
|
1207
|
+
var isNumber = Util._isNumber(val);
|
|
1208
|
+
var isAuto = val === 'auto';
|
|
1208
1209
|
if (!(isNumber || isAuto)) {
|
|
1209
1210
|
Util.warn(_formatValue(val) +
|
|
1210
1211
|
' is a not valid value for "' +
|
|
@@ -1233,7 +1234,7 @@
|
|
|
1233
1234
|
return function (val, attr) {
|
|
1234
1235
|
const isString = Util._isString(val);
|
|
1235
1236
|
const isGradient = Object.prototype.toString.call(val) === '[object CanvasGradient]' ||
|
|
1236
|
-
(val && val
|
|
1237
|
+
(val && val['addColorStop']);
|
|
1237
1238
|
if (!(isString || isGradient)) {
|
|
1238
1239
|
Util.warn(_formatValue(val) +
|
|
1239
1240
|
' is a not valid value for "' +
|
|
@@ -1277,7 +1278,7 @@
|
|
|
1277
1278
|
function getBooleanValidator() {
|
|
1278
1279
|
if (Konva$2.isUnminified) {
|
|
1279
1280
|
return function (val, attr) {
|
|
1280
|
-
|
|
1281
|
+
var isBool = val === true || val === false;
|
|
1281
1282
|
if (!isBool) {
|
|
1282
1283
|
Util.warn(_formatValue(val) +
|
|
1283
1284
|
' is a not valid value for "' +
|
|
@@ -1307,7 +1308,8 @@
|
|
|
1307
1308
|
}
|
|
1308
1309
|
}
|
|
1309
1310
|
|
|
1310
|
-
const GET = 'get'
|
|
1311
|
+
const GET = 'get';
|
|
1312
|
+
const SET$1 = 'set';
|
|
1311
1313
|
const Factory = {
|
|
1312
1314
|
addGetterSetter(constructor, attr, def, validator, after) {
|
|
1313
1315
|
Factory.addGetter(constructor, attr, def);
|
|
@@ -1315,7 +1317,7 @@
|
|
|
1315
1317
|
Factory.addOverloadedGetterSetter(constructor, attr);
|
|
1316
1318
|
},
|
|
1317
1319
|
addGetter(constructor, attr, def) {
|
|
1318
|
-
|
|
1320
|
+
var method = GET + Util._capitalize(attr);
|
|
1319
1321
|
constructor.prototype[method] =
|
|
1320
1322
|
constructor.prototype[method] ||
|
|
1321
1323
|
function () {
|
|
@@ -1324,13 +1326,13 @@
|
|
|
1324
1326
|
};
|
|
1325
1327
|
},
|
|
1326
1328
|
addSetter(constructor, attr, validator, after) {
|
|
1327
|
-
|
|
1329
|
+
var method = SET$1 + Util._capitalize(attr);
|
|
1328
1330
|
if (!constructor.prototype[method]) {
|
|
1329
1331
|
Factory.overWriteSetter(constructor, attr, validator, after);
|
|
1330
1332
|
}
|
|
1331
1333
|
},
|
|
1332
1334
|
overWriteSetter(constructor, attr, validator, after) {
|
|
1333
|
-
|
|
1335
|
+
var method = SET$1 + Util._capitalize(attr);
|
|
1334
1336
|
constructor.prototype[method] = function (val) {
|
|
1335
1337
|
if (validator && val !== undefined && val !== null) {
|
|
1336
1338
|
val = validator.call(this, val, attr);
|
|
@@ -1343,12 +1345,12 @@
|
|
|
1343
1345
|
};
|
|
1344
1346
|
},
|
|
1345
1347
|
addComponentsGetterSetter(constructor, attr, components, validator, after) {
|
|
1346
|
-
|
|
1348
|
+
const len = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), setter = SET$1 + capitalize(attr);
|
|
1347
1349
|
// getter
|
|
1348
1350
|
constructor.prototype[getter] = function () {
|
|
1349
1351
|
const ret = {};
|
|
1350
|
-
for (n = 0; n < len; n++) {
|
|
1351
|
-
component = components[n];
|
|
1352
|
+
for (let n = 0; n < len; n++) {
|
|
1353
|
+
const component = components[n];
|
|
1352
1354
|
ret[component] = this.getAttr(attr + capitalize(component));
|
|
1353
1355
|
}
|
|
1354
1356
|
return ret;
|
|
@@ -1356,14 +1358,14 @@
|
|
|
1356
1358
|
const basicValidator = getComponentValidator(components);
|
|
1357
1359
|
// setter
|
|
1358
1360
|
constructor.prototype[setter] = function (val) {
|
|
1359
|
-
|
|
1361
|
+
const oldVal = this.attrs[attr];
|
|
1360
1362
|
if (validator) {
|
|
1361
|
-
val = validator.call(this, val);
|
|
1363
|
+
val = validator.call(this, val, attr);
|
|
1362
1364
|
}
|
|
1363
1365
|
if (basicValidator) {
|
|
1364
1366
|
basicValidator.call(this, val, attr);
|
|
1365
1367
|
}
|
|
1366
|
-
for (key in val) {
|
|
1368
|
+
for (const key in val) {
|
|
1367
1369
|
if (!val.hasOwnProperty(key)) {
|
|
1368
1370
|
continue;
|
|
1369
1371
|
}
|
|
@@ -1383,7 +1385,7 @@
|
|
|
1383
1385
|
Factory.addOverloadedGetterSetter(constructor, attr);
|
|
1384
1386
|
},
|
|
1385
1387
|
addOverloadedGetterSetter(constructor, attr) {
|
|
1386
|
-
|
|
1388
|
+
var capitalizedAttr = Util._capitalize(attr), setter = SET$1 + capitalizedAttr, getter = GET + capitalizedAttr;
|
|
1387
1389
|
constructor.prototype[attr] = function () {
|
|
1388
1390
|
// setting
|
|
1389
1391
|
if (arguments.length) {
|
|
@@ -1433,9 +1435,9 @@
|
|
|
1433
1435
|
};
|
|
1434
1436
|
|
|
1435
1437
|
function simplifyArray(arr) {
|
|
1436
|
-
|
|
1437
|
-
for (n = 0; n < len; n++) {
|
|
1438
|
-
val = arr[n];
|
|
1438
|
+
const retArr = [], len = arr.length, util = Util;
|
|
1439
|
+
for (let n = 0; n < len; n++) {
|
|
1440
|
+
let val = arr[n];
|
|
1439
1441
|
if (util._isNumber(val)) {
|
|
1440
1442
|
val = Math.round(val * 1000) / 1000;
|
|
1441
1443
|
}
|
|
@@ -5060,7 +5062,7 @@
|
|
|
5060
5062
|
* // set offset y
|
|
5061
5063
|
* node.offsetY(3);
|
|
5062
5064
|
*/
|
|
5063
|
-
addGetterSetter(Node, 'dragDistance',
|
|
5065
|
+
addGetterSetter(Node, 'dragDistance', undefined, getNumberValidator());
|
|
5064
5066
|
/**
|
|
5065
5067
|
* get/set drag distance
|
|
5066
5068
|
* @name Konva.Node#dragDistance
|
|
@@ -5144,7 +5146,7 @@
|
|
|
5144
5146
|
* shape.preventDefault(false);
|
|
5145
5147
|
*/
|
|
5146
5148
|
addGetterSetter(Node, 'preventDefault', true, getBooleanValidator());
|
|
5147
|
-
addGetterSetter(Node, 'filters',
|
|
5149
|
+
addGetterSetter(Node, 'filters', undefined, function (val) {
|
|
5148
5150
|
this._filterUpToDate = false;
|
|
5149
5151
|
return val;
|
|
5150
5152
|
});
|
|
@@ -6093,8 +6095,8 @@
|
|
|
6093
6095
|
* @name Konva.Stage#clear
|
|
6094
6096
|
*/
|
|
6095
6097
|
clear() {
|
|
6096
|
-
|
|
6097
|
-
for (n = 0; n < len; n++) {
|
|
6098
|
+
const layers = this.children, len = layers.length;
|
|
6099
|
+
for (let n = 0; n < len; n++) {
|
|
6098
6100
|
layers[n].clear();
|
|
6099
6101
|
}
|
|
6100
6102
|
return this;
|
|
@@ -6193,8 +6195,8 @@
|
|
|
6193
6195
|
if (!pos) {
|
|
6194
6196
|
return null;
|
|
6195
6197
|
}
|
|
6196
|
-
|
|
6197
|
-
for (n = end; n >= 0; n--) {
|
|
6198
|
+
const layers = this.children, len = layers.length, end = len - 1;
|
|
6199
|
+
for (let n = end; n >= 0; n--) {
|
|
6198
6200
|
const shape = layers[n].getIntersection(pos);
|
|
6199
6201
|
if (shape) {
|
|
6200
6202
|
return shape;
|
|
@@ -6529,7 +6531,7 @@
|
|
|
6529
6531
|
// TODO: are we sure we need to prevent default at all?
|
|
6530
6532
|
// do not call this function on mobile because it prevent "click" event on all parent containers
|
|
6531
6533
|
// but apps may listen to it.
|
|
6532
|
-
if (evt.cancelable && eventType !== 'touch') {
|
|
6534
|
+
if (evt.cancelable && eventType !== 'touch' && eventType !== 'pointer') {
|
|
6533
6535
|
evt.preventDefault();
|
|
6534
6536
|
}
|
|
6535
6537
|
}
|
|
@@ -6588,7 +6590,8 @@
|
|
|
6588
6590
|
* });
|
|
6589
6591
|
*/
|
|
6590
6592
|
setPointersPositions(evt) {
|
|
6591
|
-
|
|
6593
|
+
const contentPosition = this._getContentPosition();
|
|
6594
|
+
let x = null, y = null;
|
|
6592
6595
|
evt = evt ? evt : window.event;
|
|
6593
6596
|
// touch events
|
|
6594
6597
|
if (evt.touches !== undefined) {
|
|
@@ -7307,17 +7310,17 @@
|
|
|
7307
7310
|
* shape.drawHitFromCache();
|
|
7308
7311
|
*/
|
|
7309
7312
|
drawHitFromCache(alphaThreshold = 0) {
|
|
7310
|
-
|
|
7313
|
+
const cachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight();
|
|
7311
7314
|
hitContext.clear();
|
|
7312
7315
|
hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight);
|
|
7313
7316
|
try {
|
|
7314
|
-
hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight);
|
|
7315
|
-
hitData = hitImageData.data;
|
|
7316
|
-
len = hitData.length;
|
|
7317
|
-
rgbColorKey = Util._hexToRgb(this.colorKey);
|
|
7317
|
+
const hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight);
|
|
7318
|
+
const hitData = hitImageData.data;
|
|
7319
|
+
const len = hitData.length;
|
|
7320
|
+
const rgbColorKey = Util._hexToRgb(this.colorKey);
|
|
7318
7321
|
// replace non transparent pixels with color key
|
|
7319
|
-
for (i = 0; i < len; i += 4) {
|
|
7320
|
-
alpha = hitData[i + 3];
|
|
7322
|
+
for (let i = 0; i < len; i += 4) {
|
|
7323
|
+
const alpha = hitData[i + 3];
|
|
7321
7324
|
if (alpha > alphaThreshold) {
|
|
7322
7325
|
hitData[i] = rgbColorKey.r;
|
|
7323
7326
|
hitData[i + 1] = rgbColorKey.g;
|
|
@@ -9151,13 +9154,14 @@
|
|
|
9151
9154
|
Animation.animIdCounter = 0;
|
|
9152
9155
|
Animation.animRunning = false;
|
|
9153
9156
|
|
|
9154
|
-
|
|
9157
|
+
const blacklist = {
|
|
9155
9158
|
node: 1,
|
|
9156
9159
|
duration: 1,
|
|
9157
9160
|
easing: 1,
|
|
9158
9161
|
onFinish: 1,
|
|
9159
9162
|
yoyo: 1,
|
|
9160
|
-
}, PAUSED = 1, PLAYING = 2, REVERSING = 3,
|
|
9163
|
+
}, PAUSED = 1, PLAYING = 2, REVERSING = 3, colorAttrs = ['fill', 'stroke', 'shadowColor'];
|
|
9164
|
+
let idCounter = 0;
|
|
9161
9165
|
class TweenEngine {
|
|
9162
9166
|
constructor(prop, propFunc, func, begin, finish, duration, yoyo) {
|
|
9163
9167
|
this.prop = prop;
|
|
@@ -9300,7 +9304,8 @@
|
|
|
9300
9304
|
*/
|
|
9301
9305
|
class Tween {
|
|
9302
9306
|
constructor(config) {
|
|
9303
|
-
|
|
9307
|
+
const that = this, node = config.node, nodeId = node._id, easing = config.easing || Easings.Linear, yoyo = !!config.yoyo;
|
|
9308
|
+
let duration, key;
|
|
9304
9309
|
if (typeof config.duration === 'undefined') {
|
|
9305
9310
|
duration = 0.3;
|
|
9306
9311
|
}
|
|
@@ -9348,14 +9353,15 @@
|
|
|
9348
9353
|
this.onUpdate = config.onUpdate;
|
|
9349
9354
|
}
|
|
9350
9355
|
_addAttr(key, end) {
|
|
9351
|
-
|
|
9356
|
+
const node = this.node, nodeId = node._id;
|
|
9357
|
+
let diff, len, trueEnd, trueStart, endRGBA;
|
|
9352
9358
|
// remove conflict from tween map if it exists
|
|
9353
|
-
tweenId = Tween.tweens[nodeId][key];
|
|
9359
|
+
const tweenId = Tween.tweens[nodeId][key];
|
|
9354
9360
|
if (tweenId) {
|
|
9355
9361
|
delete Tween.attrs[nodeId][tweenId][key];
|
|
9356
9362
|
}
|
|
9357
9363
|
// add to tween map
|
|
9358
|
-
start = node.getAttr(key);
|
|
9364
|
+
let start = node.getAttr(key);
|
|
9359
9365
|
if (Util._isArray(end)) {
|
|
9360
9366
|
diff = [];
|
|
9361
9367
|
len = Math.max(end.length, start.length);
|
|
@@ -9374,7 +9380,7 @@
|
|
|
9374
9380
|
}
|
|
9375
9381
|
}
|
|
9376
9382
|
if (key.indexOf('fill') === 0) {
|
|
9377
|
-
for (n = 0; n < len; n++) {
|
|
9383
|
+
for (let n = 0; n < len; n++) {
|
|
9378
9384
|
if (n % 2 === 0) {
|
|
9379
9385
|
diff.push(end[n] - start[n]);
|
|
9380
9386
|
}
|
|
@@ -9392,7 +9398,7 @@
|
|
|
9392
9398
|
}
|
|
9393
9399
|
}
|
|
9394
9400
|
else {
|
|
9395
|
-
for (n = 0; n < len; n++) {
|
|
9401
|
+
for (let n = 0; n < len; n++) {
|
|
9396
9402
|
diff.push(end[n] - start[n]);
|
|
9397
9403
|
}
|
|
9398
9404
|
}
|
|
@@ -9420,7 +9426,8 @@
|
|
|
9420
9426
|
Tween.tweens[nodeId][key] = this._id;
|
|
9421
9427
|
}
|
|
9422
9428
|
_tweenFunc(i) {
|
|
9423
|
-
|
|
9429
|
+
const node = this.node, attrs = Tween.attrs[node._id][this._id];
|
|
9430
|
+
let key, attr, start, diff, newVal, n, len, end;
|
|
9424
9431
|
for (key in attrs) {
|
|
9425
9432
|
attr = attrs[key];
|
|
9426
9433
|
start = attr.start;
|
|
@@ -9578,9 +9585,9 @@
|
|
|
9578
9585
|
* @name Konva.Tween#destroy
|
|
9579
9586
|
*/
|
|
9580
9587
|
destroy() {
|
|
9581
|
-
|
|
9588
|
+
const nodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId];
|
|
9582
9589
|
this.pause();
|
|
9583
|
-
for (key in attrs) {
|
|
9590
|
+
for (const key in attrs) {
|
|
9584
9591
|
delete Tween.tweens[nodeId][key];
|
|
9585
9592
|
}
|
|
9586
9593
|
delete Tween.attrs[nodeId][thisId];
|
|
@@ -12159,9 +12166,9 @@
|
|
|
12159
12166
|
const lineRect = super.getSelfRect();
|
|
12160
12167
|
const offset = this.pointerWidth() / 2;
|
|
12161
12168
|
return {
|
|
12162
|
-
x: lineRect.x
|
|
12169
|
+
x: lineRect.x,
|
|
12163
12170
|
y: lineRect.y - offset,
|
|
12164
|
-
width: lineRect.width
|
|
12171
|
+
width: lineRect.width,
|
|
12165
12172
|
height: lineRect.height + offset * 2,
|
|
12166
12173
|
};
|
|
12167
12174
|
}
|
|
@@ -14148,9 +14155,15 @@
|
|
|
14148
14155
|
function stringToArray(string) {
|
|
14149
14156
|
// Use Unicode-aware splitting
|
|
14150
14157
|
return [...string].reduce((acc, char, index, array) => {
|
|
14151
|
-
// Handle emoji
|
|
14152
|
-
if (/\p{
|
|
14153
|
-
acc.
|
|
14158
|
+
// Handle emoji with skin tone modifiers and ZWJ sequences
|
|
14159
|
+
if (/\p{Emoji}/u.test(char)) {
|
|
14160
|
+
if (acc.length > 0 && /\p{Emoji}/u.test(acc[acc.length - 1])) {
|
|
14161
|
+
// Combine with previous emoji if it's part of a sequence
|
|
14162
|
+
acc[acc.length - 1] += char;
|
|
14163
|
+
}
|
|
14164
|
+
else {
|
|
14165
|
+
acc.push(char);
|
|
14166
|
+
}
|
|
14154
14167
|
}
|
|
14155
14168
|
// Handle regional indicator symbols (flags)
|
|
14156
14169
|
else if (/\p{Regional_Indicator}{2}/u.test(char + (array[index + 1] || ''))) {
|
|
@@ -14378,7 +14391,7 @@
|
|
|
14378
14391
|
for (n = 0; n < textArrLen; n++) {
|
|
14379
14392
|
var lineTranslateX = 0;
|
|
14380
14393
|
var lineTranslateY = 0;
|
|
14381
|
-
var obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph, spacesNumber,
|
|
14394
|
+
var obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph, spacesNumber, lineWidth;
|
|
14382
14395
|
// horizontal alignment
|
|
14383
14396
|
context.save();
|
|
14384
14397
|
if (align === RIGHT) {
|
|
@@ -14397,7 +14410,6 @@
|
|
|
14397
14410
|
const y = translateY + lineTranslateY + yOffset;
|
|
14398
14411
|
context.moveTo(x, y);
|
|
14399
14412
|
spacesNumber = text.split(' ').length - 1;
|
|
14400
|
-
oneWord = spacesNumber === 0;
|
|
14401
14413
|
lineWidth =
|
|
14402
14414
|
align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
14403
14415
|
context.lineTo(x + Math.round(lineWidth), y);
|
|
@@ -14415,11 +14427,8 @@
|
|
|
14415
14427
|
const yOffset = Konva$2._fixTextRendering ? -Math.round(fontSize / 4) : 0;
|
|
14416
14428
|
context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset);
|
|
14417
14429
|
spacesNumber = text.split(' ').length - 1;
|
|
14418
|
-
oneWord = spacesNumber === 0;
|
|
14419
14430
|
lineWidth =
|
|
14420
|
-
align === JUSTIFY && lastLine
|
|
14421
|
-
? totalWidth - padding * 2
|
|
14422
|
-
: width;
|
|
14431
|
+
align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
14423
14432
|
context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
|
|
14424
14433
|
context.lineWidth = fontSize / 15;
|
|
14425
14434
|
const gradient = this._getLinearGradient();
|
|
@@ -14564,8 +14573,9 @@
|
|
|
14564
14573
|
_getTextWidth(text) {
|
|
14565
14574
|
const letterSpacing = this.letterSpacing();
|
|
14566
14575
|
const length = text.length;
|
|
14567
|
-
|
|
14568
|
-
|
|
14576
|
+
// letterSpacing * length is the total letter spacing for the text
|
|
14577
|
+
// previously we used letterSpacing * (length - 1) but it doesn't match DOM behavior
|
|
14578
|
+
return getDummyContext().measureText(text).width + letterSpacing * length;
|
|
14569
14579
|
}
|
|
14570
14580
|
_setTextData() {
|
|
14571
14581
|
let lines = this.text().split('\n'), fontSize = +this.fontSize(), textWidth = 0, 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(),
|
|
@@ -14573,7 +14583,9 @@
|
|
|
14573
14583
|
shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis();
|
|
14574
14584
|
this.textArr = [];
|
|
14575
14585
|
getDummyContext().font = this._getContextFont();
|
|
14576
|
-
const additionalWidth = shouldAddEllipsis
|
|
14586
|
+
const additionalWidth = shouldAddEllipsis
|
|
14587
|
+
? this._getTextWidth(ELLIPSIS)
|
|
14588
|
+
: 0;
|
|
14577
14589
|
for (let i = 0, max = lines.length; i < max; ++i) {
|
|
14578
14590
|
let line = lines[i];
|
|
14579
14591
|
let lineWidth = this._getTextWidth(line);
|
|
@@ -15482,7 +15494,7 @@
|
|
|
15482
15494
|
* // underline text
|
|
15483
15495
|
* shape.textDecoration('underline');
|
|
15484
15496
|
*/
|
|
15485
|
-
Factory.addGetterSetter(TextPath, 'textDecoration',
|
|
15497
|
+
Factory.addGetterSetter(TextPath, 'textDecoration', '');
|
|
15486
15498
|
/**
|
|
15487
15499
|
* get/set kerning function.
|
|
15488
15500
|
* @name Konva.TextPath#kerningFunc
|
|
@@ -15498,7 +15510,7 @@
|
|
|
15498
15510
|
* return 1;
|
|
15499
15511
|
* });
|
|
15500
15512
|
*/
|
|
15501
|
-
Factory.addGetterSetter(TextPath, 'kerningFunc',
|
|
15513
|
+
Factory.addGetterSetter(TextPath, 'kerningFunc', undefined);
|
|
15502
15514
|
|
|
15503
15515
|
const EVENTS_NAME = 'tr-konva';
|
|
15504
15516
|
const ATTR_CHANGE_LIST = [
|
|
@@ -16942,7 +16954,6 @@
|
|
|
16942
16954
|
* transformer.padding(10);
|
|
16943
16955
|
*/
|
|
16944
16956
|
Factory.addGetterSetter(Transformer, 'padding', 0, getNumberValidator());
|
|
16945
|
-
Factory.addGetterSetter(Transformer, 'node');
|
|
16946
16957
|
/**
|
|
16947
16958
|
* get/set attached nodes of the Transformer. Transformer will adapt to their size and listen to their events
|
|
16948
16959
|
* @method
|
|
@@ -16962,6 +16973,9 @@
|
|
|
16962
16973
|
* transformer.nodes(newNodes);
|
|
16963
16974
|
*/
|
|
16964
16975
|
Factory.addGetterSetter(Transformer, 'nodes');
|
|
16976
|
+
// @ts-ignore
|
|
16977
|
+
// deprecated
|
|
16978
|
+
Factory.addGetterSetter(Transformer, 'node');
|
|
16965
16979
|
/**
|
|
16966
16980
|
* get/set bounding box function. **IMPORTANT!** boundBondFunc operates in absolute coordinates.
|
|
16967
16981
|
* @name Konva.Transformer#boundBoxFunc
|
|
@@ -17320,7 +17334,8 @@
|
|
|
17320
17334
|
function filterGaussBlurRGBA(imageData, radius) {
|
|
17321
17335
|
const pixels = imageData.data, width = imageData.width, height = imageData.height;
|
|
17322
17336
|
let x, y, i, p, yp, 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;
|
|
17323
|
-
|
|
17337
|
+
const div = radius + radius + 1, widthMinus1 = width - 1, heightMinus1 = height - 1, radiusPlus1 = radius + 1, sumFactor = (radiusPlus1 * (radiusPlus1 + 1)) / 2, stackStart = new BlurStack(), mul_sum = mul_table[radius], shg_sum = shg_table[radius];
|
|
17338
|
+
let stackEnd = null, stack = stackStart, stackIn = null, stackOut = null;
|
|
17324
17339
|
for (i = 1; i < div; i++) {
|
|
17325
17340
|
stack = stack.next = new BlurStack();
|
|
17326
17341
|
if (i === radiusPlus1) {
|
|
@@ -17536,8 +17551,8 @@
|
|
|
17536
17551
|
* node.brightness(0.8);
|
|
17537
17552
|
*/
|
|
17538
17553
|
const Brighten = function (imageData) {
|
|
17539
|
-
|
|
17540
|
-
for (i = 0; i < len; i += 4) {
|
|
17554
|
+
const brightness = this.brightness() * 255, data = imageData.data, len = data.length;
|
|
17555
|
+
for (let i = 0; i < len; i += 4) {
|
|
17541
17556
|
// red
|
|
17542
17557
|
data[i] += brightness;
|
|
17543
17558
|
// green
|
|
@@ -17569,8 +17584,9 @@
|
|
|
17569
17584
|
*/
|
|
17570
17585
|
const Contrast = function (imageData) {
|
|
17571
17586
|
const adjust = Math.pow((this.contrast() + 100) / 100, 2);
|
|
17572
|
-
|
|
17573
|
-
|
|
17587
|
+
const data = imageData.data, nPixels = data.length;
|
|
17588
|
+
let red = 150, green = 150, blue = 150;
|
|
17589
|
+
for (let i = 0; i < nPixels; i += 4) {
|
|
17574
17590
|
red = data[i];
|
|
17575
17591
|
green = data[i + 1];
|
|
17576
17592
|
blue = data[i + 2];
|
|
@@ -17631,7 +17647,8 @@
|
|
|
17631
17647
|
// pixastic greyLevel is between 0 and 255. I want it between 0 and 1. Also,
|
|
17632
17648
|
// a max value of greyLevel yields a white emboss, and the min value yields a black
|
|
17633
17649
|
// emboss. Therefore, I changed greyLevel to whiteLevel
|
|
17634
|
-
|
|
17650
|
+
const strength = this.embossStrength() * 10, greyLevel = this.embossWhiteLevel() * 255, direction = this.embossDirection(), blend = this.embossBlend(), data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4;
|
|
17651
|
+
let dirY = 0, dirX = 0, y = h;
|
|
17635
17652
|
switch (direction) {
|
|
17636
17653
|
case 'top-left':
|
|
17637
17654
|
dirY = -1;
|
|
@@ -17740,7 +17757,7 @@
|
|
|
17740
17757
|
* @param {Number} embossWhiteLevel between 0 and 1. Default is 0.5
|
|
17741
17758
|
* @returns {Number}
|
|
17742
17759
|
*/
|
|
17743
|
-
Factory.addGetterSetter(Node, 'embossDirection', 'top-left',
|
|
17760
|
+
Factory.addGetterSetter(Node, 'embossDirection', 'top-left', undefined, Factory.afterSetFilter);
|
|
17744
17761
|
/**
|
|
17745
17762
|
* get/set emboss direction. Use with {@link Konva.Filters.Emboss} filter.
|
|
17746
17763
|
* @name Konva.Node#embossDirection
|
|
@@ -17749,7 +17766,7 @@
|
|
|
17749
17766
|
* The default is top-left
|
|
17750
17767
|
* @returns {String}
|
|
17751
17768
|
*/
|
|
17752
|
-
Factory.addGetterSetter(Node, 'embossBlend', false,
|
|
17769
|
+
Factory.addGetterSetter(Node, 'embossBlend', false, undefined, Factory.afterSetFilter);
|
|
17753
17770
|
/**
|
|
17754
17771
|
* get/set emboss blend. Use with {@link Konva.Filters.Emboss} filter.
|
|
17755
17772
|
* @name Konva.Node#embossBlend
|
|
@@ -17760,7 +17777,7 @@
|
|
|
17760
17777
|
|
|
17761
17778
|
function remap(fromValue, fromMin, fromMax, toMin, toMax) {
|
|
17762
17779
|
// Compute the range of the data
|
|
17763
|
-
|
|
17780
|
+
const fromRange = fromMax - fromMin, toRange = toMax - toMin;
|
|
17764
17781
|
// If either range is 0, then the value can only be mapped to 1 value
|
|
17765
17782
|
if (fromRange === 0) {
|
|
17766
17783
|
return toMin + toRange / 2;
|
|
@@ -17769,7 +17786,7 @@
|
|
|
17769
17786
|
return toMin;
|
|
17770
17787
|
}
|
|
17771
17788
|
// (1) untranslate, (2) unscale, (3) rescale, (4) retranslate
|
|
17772
|
-
toValue = (fromValue - fromMin) / fromRange;
|
|
17789
|
+
let toValue = (fromValue - fromMin) / fromRange;
|
|
17773
17790
|
toValue = toRange * toValue + toMin;
|
|
17774
17791
|
return toValue;
|
|
17775
17792
|
}
|
|
@@ -17788,14 +17805,15 @@
|
|
|
17788
17805
|
* node.enhance(0.4);
|
|
17789
17806
|
*/
|
|
17790
17807
|
const Enhance = function (imageData) {
|
|
17791
|
-
|
|
17808
|
+
const data = imageData.data, nSubPixels = data.length;
|
|
17809
|
+
let rMin = data[0], rMax = rMin, r, gMin = data[1], gMax = gMin, g, bMin = data[2], bMax = bMin, b;
|
|
17792
17810
|
// If we are not enhancing anything - don't do any computation
|
|
17793
17811
|
const enhanceAmount = this.enhance();
|
|
17794
17812
|
if (enhanceAmount === 0) {
|
|
17795
17813
|
return;
|
|
17796
17814
|
}
|
|
17797
17815
|
// 1st Pass - find the min and max for each channel:
|
|
17798
|
-
for (i = 0; i < nSubPixels; i += 4) {
|
|
17816
|
+
for (let i = 0; i < nSubPixels; i += 4) {
|
|
17799
17817
|
r = data[i + 0];
|
|
17800
17818
|
if (r < rMin) {
|
|
17801
17819
|
rMin = r;
|
|
@@ -17857,7 +17875,7 @@
|
|
|
17857
17875
|
bGoalMin = bMin + enhanceAmount * (bMin - bMid);
|
|
17858
17876
|
}
|
|
17859
17877
|
// Pass 2 - remap everything, except the alpha
|
|
17860
|
-
for (i = 0; i < nSubPixels; i += 4) {
|
|
17878
|
+
for (let i = 0; i < nSubPixels; i += 4) {
|
|
17861
17879
|
data[i + 0] = remap(data[i + 0], rMin, rMax, rGoalMin, rGoalMax);
|
|
17862
17880
|
data[i + 1] = remap(data[i + 1], gMin, gMax, gGoalMin, gGoalMax);
|
|
17863
17881
|
data[i + 2] = remap(data[i + 2], bMin, bMax, bGoalMin, bGoalMax);
|
|
@@ -17883,9 +17901,9 @@
|
|
|
17883
17901
|
* node.filters([Konva.Filters.Grayscale]);
|
|
17884
17902
|
*/
|
|
17885
17903
|
const Grayscale = function (imageData) {
|
|
17886
|
-
|
|
17887
|
-
for (i = 0; i < len; i += 4) {
|
|
17888
|
-
brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
|
|
17904
|
+
const data = imageData.data, len = data.length;
|
|
17905
|
+
for (let i = 0; i < len; i += 4) {
|
|
17906
|
+
const brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
|
|
17889
17907
|
// red
|
|
17890
17908
|
data[i] = brightness;
|
|
17891
17909
|
// green
|
|
@@ -17930,7 +17948,7 @@
|
|
|
17930
17948
|
* image.luminance(0.2);
|
|
17931
17949
|
*/
|
|
17932
17950
|
const HSL = function (imageData) {
|
|
17933
|
-
|
|
17951
|
+
const data = imageData.data, nPixels = data.length, v = 1, s = Math.pow(2, this.saturation()), h = Math.abs(this.hue() + 360) % 360, l = this.luminance() * 127;
|
|
17934
17952
|
// Basis for the technique used:
|
|
17935
17953
|
// http://beesbuzz.biz/code/hsv_color_transforms.php
|
|
17936
17954
|
// V is the value multiplier (1 for none, 2 for double, 0.5 for half)
|
|
@@ -17948,7 +17966,7 @@
|
|
|
17948
17966
|
const gr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.293 * vsw;
|
|
17949
17967
|
const br = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.586 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.2 * vsw;
|
|
17950
17968
|
let r, g, b, a;
|
|
17951
|
-
for (i = 0; i < nPixels; i += 4) {
|
|
17969
|
+
for (let i = 0; i < nPixels; i += 4) {
|
|
17952
17970
|
r = data[i + 0];
|
|
17953
17971
|
g = data[i + 1];
|
|
17954
17972
|
b = data[i + 2];
|
|
@@ -18036,8 +18054,8 @@
|
|
|
18036
18054
|
* node.filters([Konva.Filters.Invert]);
|
|
18037
18055
|
*/
|
|
18038
18056
|
const Invert = function (imageData) {
|
|
18039
|
-
|
|
18040
|
-
for (i = 0; i < len; i += 4) {
|
|
18057
|
+
const data = imageData.data, len = data.length;
|
|
18058
|
+
for (let i = 0; i < len; i += 4) {
|
|
18041
18059
|
// red
|
|
18042
18060
|
data[i] = 255 - data[i];
|
|
18043
18061
|
// green
|
|
@@ -18063,30 +18081,30 @@
|
|
|
18063
18081
|
* default is in the middle
|
|
18064
18082
|
*/
|
|
18065
18083
|
const ToPolar = function (src, dst, opt) {
|
|
18066
|
-
|
|
18084
|
+
const srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2;
|
|
18067
18085
|
// Find the largest radius
|
|
18068
|
-
let
|
|
18069
|
-
x = xSize - xMid;
|
|
18070
|
-
y = ySize - yMid;
|
|
18071
|
-
rad = Math.sqrt(x * x + y * y);
|
|
18086
|
+
let rMax = Math.sqrt(xMid * xMid + yMid * yMid);
|
|
18087
|
+
let x = xSize - xMid;
|
|
18088
|
+
let y = ySize - yMid;
|
|
18089
|
+
const rad = Math.sqrt(x * x + y * y);
|
|
18072
18090
|
rMax = rad > rMax ? rad : rMax;
|
|
18073
18091
|
// We'll be uisng y as the radius, and x as the angle (theta=t)
|
|
18074
|
-
|
|
18092
|
+
const rSize = ySize, tSize = xSize;
|
|
18075
18093
|
// We want to cover all angles (0-360) and we need to convert to
|
|
18076
18094
|
// radians (*PI/180)
|
|
18077
|
-
|
|
18095
|
+
const conversion = ((360 / tSize) * Math.PI) / 180;
|
|
18078
18096
|
// var x1, x2, x1i, x2i, y1, y2, y1i, y2i, scale;
|
|
18079
|
-
for (theta = 0; theta < tSize; theta += 1) {
|
|
18080
|
-
sin = Math.sin(theta * conversion);
|
|
18081
|
-
cos = Math.cos(theta * conversion);
|
|
18082
|
-
for (radius = 0; radius < rSize; radius += 1) {
|
|
18097
|
+
for (let theta = 0; theta < tSize; theta += 1) {
|
|
18098
|
+
const sin = Math.sin(theta * conversion);
|
|
18099
|
+
const cos = Math.cos(theta * conversion);
|
|
18100
|
+
for (let radius = 0; radius < rSize; radius += 1) {
|
|
18083
18101
|
x = Math.floor(xMid + ((rMax * radius) / rSize) * cos);
|
|
18084
18102
|
y = Math.floor(yMid + ((rMax * radius) / rSize) * sin);
|
|
18085
|
-
i = (y * xSize + x) * 4;
|
|
18086
|
-
r = srcPixels[i + 0];
|
|
18087
|
-
g = srcPixels[i + 1];
|
|
18088
|
-
b = srcPixels[i + 2];
|
|
18089
|
-
a = srcPixels[i + 3];
|
|
18103
|
+
let i = (y * xSize + x) * 4;
|
|
18104
|
+
const r = srcPixels[i + 0];
|
|
18105
|
+
const g = srcPixels[i + 1];
|
|
18106
|
+
const b = srcPixels[i + 2];
|
|
18107
|
+
const a = srcPixels[i + 3];
|
|
18090
18108
|
// Store it
|
|
18091
18109
|
//i = (theta * xSize + radius) * 4;
|
|
18092
18110
|
i = (theta + radius * xSize) * 4;
|
|
@@ -18114,15 +18132,15 @@
|
|
|
18114
18132
|
* 0 is no rotation, 360 degrees is a full rotation
|
|
18115
18133
|
*/
|
|
18116
18134
|
const FromPolar = function (src, dst, opt) {
|
|
18117
|
-
|
|
18135
|
+
const srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2;
|
|
18118
18136
|
// Find the largest radius
|
|
18119
|
-
let
|
|
18120
|
-
x = xSize - xMid;
|
|
18121
|
-
y = ySize - yMid;
|
|
18122
|
-
rad = Math.sqrt(x * x + y * y);
|
|
18137
|
+
let rMax = Math.sqrt(xMid * xMid + yMid * yMid);
|
|
18138
|
+
let x = xSize - xMid;
|
|
18139
|
+
let y = ySize - yMid;
|
|
18140
|
+
const rad = Math.sqrt(x * x + y * y);
|
|
18123
18141
|
rMax = rad > rMax ? rad : rMax;
|
|
18124
18142
|
// We'll be uisng x as the radius, and y as the angle (theta=t)
|
|
18125
|
-
|
|
18143
|
+
const rSize = ySize, tSize = xSize, phaseShift = 0;
|
|
18126
18144
|
// We need to convert to degrees and we need to make sure
|
|
18127
18145
|
// it's between (0-360)
|
|
18128
18146
|
// var conversion = tSize/360*180/Math.PI;
|
|
@@ -18130,18 +18148,18 @@
|
|
|
18130
18148
|
let x1, y1;
|
|
18131
18149
|
for (x = 0; x < xSize; x += 1) {
|
|
18132
18150
|
for (y = 0; y < ySize; y += 1) {
|
|
18133
|
-
dx = x - xMid;
|
|
18134
|
-
dy = y - yMid;
|
|
18135
|
-
radius = (Math.sqrt(dx * dx + dy * dy) * rSize) / rMax;
|
|
18136
|
-
theta = ((Math.atan2(dy, dx) * 180) / Math.PI + 360 + phaseShift) % 360;
|
|
18151
|
+
const dx = x - xMid;
|
|
18152
|
+
const dy = y - yMid;
|
|
18153
|
+
const radius = (Math.sqrt(dx * dx + dy * dy) * rSize) / rMax;
|
|
18154
|
+
let theta = ((Math.atan2(dy, dx) * 180) / Math.PI + 360 + phaseShift) % 360;
|
|
18137
18155
|
theta = (theta * tSize) / 360;
|
|
18138
18156
|
x1 = Math.floor(theta);
|
|
18139
18157
|
y1 = Math.floor(radius);
|
|
18140
|
-
i = (y1 * xSize + x1) * 4;
|
|
18141
|
-
r = srcPixels[i + 0];
|
|
18142
|
-
g = srcPixels[i + 1];
|
|
18143
|
-
b = srcPixels[i + 2];
|
|
18144
|
-
a = srcPixels[i + 3];
|
|
18158
|
+
let i = (y1 * xSize + x1) * 4;
|
|
18159
|
+
const r = srcPixels[i + 0];
|
|
18160
|
+
const g = srcPixels[i + 1];
|
|
18161
|
+
const b = srcPixels[i + 2];
|
|
18162
|
+
const a = srcPixels[i + 3];
|
|
18145
18163
|
// Store it
|
|
18146
18164
|
i = (y * xSize + x) * 4;
|
|
18147
18165
|
dstPixels[i + 0] = r;
|
|
@@ -18401,7 +18419,8 @@
|
|
|
18401
18419
|
*/
|
|
18402
18420
|
const Mask = function (imageData) {
|
|
18403
18421
|
// Detect pixels close to the background color
|
|
18404
|
-
|
|
18422
|
+
const threshold = this.threshold();
|
|
18423
|
+
let mask = backgroundMask(imageData, threshold);
|
|
18405
18424
|
if (mask) {
|
|
18406
18425
|
// Erode
|
|
18407
18426
|
mask = erodeMask(mask, imageData.width, imageData.height);
|
|
@@ -18545,8 +18564,8 @@
|
|
|
18545
18564
|
*/
|
|
18546
18565
|
const Posterize = function (imageData) {
|
|
18547
18566
|
// level must be between 1 and 255
|
|
18548
|
-
|
|
18549
|
-
for (i = 0; i < len; i += 1) {
|
|
18567
|
+
const levels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels;
|
|
18568
|
+
for (let i = 0; i < len; i += 1) {
|
|
18550
18569
|
data[i] = Math.floor(data[i] / scale) * scale;
|
|
18551
18570
|
}
|
|
18552
18571
|
};
|
|
@@ -18573,10 +18592,9 @@
|
|
|
18573
18592
|
* node.green(200);
|
|
18574
18593
|
*/
|
|
18575
18594
|
const RGB = function (imageData) {
|
|
18576
|
-
|
|
18577
|
-
for (i = 0; i < nPixels; i += 4) {
|
|
18578
|
-
brightness =
|
|
18579
|
-
(0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255;
|
|
18595
|
+
const data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue();
|
|
18596
|
+
for (let i = 0; i < nPixels; i += 4) {
|
|
18597
|
+
const brightness = (0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255;
|
|
18580
18598
|
data[i] = brightness * red; // r
|
|
18581
18599
|
data[i + 1] = brightness * green; // g
|
|
18582
18600
|
data[i + 2] = brightness * blue; // b
|
|
@@ -18737,11 +18755,11 @@
|
|
|
18737
18755
|
* node.filters([Konva.Filters.Sepia]);
|
|
18738
18756
|
*/
|
|
18739
18757
|
const Sepia = function (imageData) {
|
|
18740
|
-
|
|
18741
|
-
for (i = 0; i < nPixels; i += 4) {
|
|
18742
|
-
r = data[i + 0];
|
|
18743
|
-
g = data[i + 1];
|
|
18744
|
-
b = data[i + 2];
|
|
18758
|
+
const data = imageData.data, nPixels = data.length;
|
|
18759
|
+
for (let i = 0; i < nPixels; i += 4) {
|
|
18760
|
+
const r = data[i + 0];
|
|
18761
|
+
const g = data[i + 1];
|
|
18762
|
+
const b = data[i + 2];
|
|
18745
18763
|
data[i + 0] = Math.min(255, r * 0.393 + g * 0.769 + b * 0.189);
|
|
18746
18764
|
data[i + 1] = Math.min(255, r * 0.349 + g * 0.686 + b * 0.168);
|
|
18747
18765
|
data[i + 2] = Math.min(255, r * 0.272 + g * 0.534 + b * 0.131);
|