konva 9.3.16 → 9.3.18

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 CHANGED
@@ -5,10 +5,10 @@
5
5
  })(this, (function () { 'use strict';
6
6
 
7
7
  /*
8
- * Konva JavaScript Framework v9.3.16
8
+ * Konva JavaScript Framework v9.3.18
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Mon Oct 21 2024
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.16',
38
+ version: '9.3.18',
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
- let 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 = {
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})\)/, animQueue = [];
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
- let n, start = [], end = [];
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
- const isNumber = Util._isNumber(val);
1190
- const isValidArray = Util._isArray(val) && val.length == noOfElements;
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
- const isNumber = Util._isNumber(val);
1207
- const isAuto = val === 'auto';
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.addColorStop);
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
- const isBool = val === true || val === false;
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', SET$1 = 'set';
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
- const method = GET + Util._capitalize(attr);
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
- const method = SET$1 + Util._capitalize(attr);
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
- const method = SET$1 + Util._capitalize(attr);
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
- let len = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), setter = SET$1 + capitalize(attr), n, component;
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
- let oldVal = this.attrs[attr], key;
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
- const capitalizedAttr = Util._capitalize(attr), setter = SET$1 + capitalizedAttr, getter = GET + capitalizedAttr;
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
- let retArr = [], len = arr.length, util = Util, n, val;
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', null, getNumberValidator());
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', null, function (val) {
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
- let layers = this.children, len = layers.length, n;
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
- let layers = this.children, len = layers.length, end = len - 1, n;
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
- let contentPosition = this._getContentPosition(), x = null, y = null;
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
- let cachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight(), hitImageData, hitData, len, rgbColorKey, i, alpha;
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
- let blacklist = {
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, idCounter = 0, colorAttrs = ['fill', 'stroke', 'shadowColor'];
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
- let that = this, node = config.node, nodeId = node._id, duration, easing = config.easing || Easings.Linear, yoyo = !!config.yoyo, key;
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
- let node = this.node, nodeId = node._id, start, diff, tweenId, n, len, trueEnd, trueStart, endRGBA;
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
- let node = this.node, attrs = Tween.attrs[node._id][this._id], key, attr, start, diff, newVal, n, len, end;
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
- let nodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId], key;
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 - offset,
12169
+ x: lineRect.x,
12163
12170
  y: lineRect.y - offset,
12164
- width: lineRect.width + offset * 2,
12171
+ width: lineRect.width,
12165
12172
  height: lineRect.height + offset * 2,
12166
12173
  };
12167
12174
  }
@@ -14148,9 +14155,20 @@
14148
14155
  function stringToArray(string) {
14149
14156
  // Use Unicode-aware splitting
14150
14157
  return [...string].reduce((acc, char, index, array) => {
14151
- // Handle emoji sequences (including ZWJ sequences)
14152
- if (/\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?(?:\u200D\p{Emoji_Presentation})+/u.test(char)) {
14153
- acc.push(char);
14158
+ // Handle emoji with skin tone modifiers and ZWJ sequences
14159
+ if (/\p{Emoji}/u.test(char)) {
14160
+ // Check if next character is a modifier or ZWJ sequence
14161
+ const nextChar = array[index + 1];
14162
+ if (nextChar && /\p{Emoji_Modifier}|\u200D/u.test(nextChar)) {
14163
+ // If we have a modifier, combine with current emoji
14164
+ acc.push(char + nextChar);
14165
+ // Skip the next character since we've used it
14166
+ array[index + 1] = '';
14167
+ }
14168
+ else {
14169
+ // No modifier - treat as separate emoji
14170
+ acc.push(char);
14171
+ }
14154
14172
  }
14155
14173
  // Handle regional indicator symbols (flags)
14156
14174
  else if (/\p{Regional_Indicator}{2}/u.test(char + (array[index + 1] || ''))) {
@@ -14161,7 +14179,8 @@
14161
14179
  acc[acc.length - 1] += char;
14162
14180
  }
14163
14181
  // Handle other characters
14164
- else {
14182
+ else if (char) {
14183
+ // Only push if not an empty string (skipped modifier)
14165
14184
  acc.push(char);
14166
14185
  }
14167
14186
  return acc;
@@ -14378,7 +14397,7 @@
14378
14397
  for (n = 0; n < textArrLen; n++) {
14379
14398
  var lineTranslateX = 0;
14380
14399
  var lineTranslateY = 0;
14381
- var obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph, spacesNumber, oneWord, lineWidth;
14400
+ var obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph, spacesNumber, lineWidth;
14382
14401
  // horizontal alignment
14383
14402
  context.save();
14384
14403
  if (align === RIGHT) {
@@ -14397,7 +14416,6 @@
14397
14416
  const y = translateY + lineTranslateY + yOffset;
14398
14417
  context.moveTo(x, y);
14399
14418
  spacesNumber = text.split(' ').length - 1;
14400
- oneWord = spacesNumber === 0;
14401
14419
  lineWidth =
14402
14420
  align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
14403
14421
  context.lineTo(x + Math.round(lineWidth), y);
@@ -14415,11 +14433,8 @@
14415
14433
  const yOffset = Konva$2._fixTextRendering ? -Math.round(fontSize / 4) : 0;
14416
14434
  context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset);
14417
14435
  spacesNumber = text.split(' ').length - 1;
14418
- oneWord = spacesNumber === 0;
14419
14436
  lineWidth =
14420
- align === JUSTIFY && lastLine && !oneWord
14421
- ? totalWidth - padding * 2
14422
- : width;
14437
+ align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
14423
14438
  context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
14424
14439
  context.lineWidth = fontSize / 15;
14425
14440
  const gradient = this._getLinearGradient();
@@ -14564,8 +14579,9 @@
14564
14579
  _getTextWidth(text) {
14565
14580
  const letterSpacing = this.letterSpacing();
14566
14581
  const length = text.length;
14567
- return (getDummyContext().measureText(text).width +
14568
- (length ? letterSpacing * (length - 1) : 0));
14582
+ // letterSpacing * length is the total letter spacing for the text
14583
+ // previously we used letterSpacing * (length - 1) but it doesn't match DOM behavior
14584
+ return getDummyContext().measureText(text).width + letterSpacing * length;
14569
14585
  }
14570
14586
  _setTextData() {
14571
14587
  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 +14589,9 @@
14573
14589
  shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis();
14574
14590
  this.textArr = [];
14575
14591
  getDummyContext().font = this._getContextFont();
14576
- const additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0;
14592
+ const additionalWidth = shouldAddEllipsis
14593
+ ? this._getTextWidth(ELLIPSIS)
14594
+ : 0;
14577
14595
  for (let i = 0, max = lines.length; i < max; ++i) {
14578
14596
  let line = lines[i];
14579
14597
  let lineWidth = this._getTextWidth(line);
@@ -14587,9 +14605,12 @@
14587
14605
  * use binary search to find the longest substring that
14588
14606
  * that would fit in the specified width
14589
14607
  */
14590
- let low = 0, high = line.length, match = '', matchWidth = 0;
14608
+ let low = 0, high = stringToArray(line).length, // Convert to array for proper emoji handling
14609
+ match = '', matchWidth = 0;
14591
14610
  while (low < high) {
14592
- const mid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth;
14611
+ const mid = (low + high) >>> 1,
14612
+ // Convert array indices to string
14613
+ lineArray = stringToArray(line), substr = lineArray.slice(0, mid + 1).join(''), substrWidth = this._getTextWidth(substr) + additionalWidth;
14593
14614
  if (substrWidth <= maxWidth) {
14594
14615
  low = mid + 1;
14595
14616
  match = substr;
@@ -14608,21 +14629,23 @@
14608
14629
  // a fitting substring was found
14609
14630
  if (wrapAtWord) {
14610
14631
  // try to find a space or dash where wrapping could be done
14611
- var wrapIndex;
14612
- const nextChar = line[match.length];
14632
+ const lineArray = stringToArray(line);
14633
+ const matchArray = stringToArray(match);
14634
+ const nextChar = lineArray[matchArray.length];
14613
14635
  const nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;
14636
+ let wrapIndex;
14614
14637
  if (nextIsSpaceOrDash && matchWidth <= maxWidth) {
14615
- wrapIndex = match.length;
14638
+ wrapIndex = matchArray.length;
14616
14639
  }
14617
14640
  else {
14618
- wrapIndex =
14619
- Math.max(match.lastIndexOf(SPACE), match.lastIndexOf(DASH)) +
14620
- 1;
14641
+ // Find last space or dash in the array
14642
+ const lastSpaceIndex = matchArray.lastIndexOf(SPACE);
14643
+ const lastDashIndex = matchArray.lastIndexOf(DASH);
14644
+ wrapIndex = Math.max(lastSpaceIndex, lastDashIndex) + 1;
14621
14645
  }
14622
14646
  if (wrapIndex > 0) {
14623
- // re-cut the substring found at the space/dash position
14624
14647
  low = wrapIndex;
14625
- match = match.slice(0, low);
14648
+ match = lineArray.slice(0, low).join('');
14626
14649
  matchWidth = this._getTextWidth(match);
14627
14650
  }
14628
14651
  }
@@ -14641,13 +14664,12 @@
14641
14664
  */
14642
14665
  break;
14643
14666
  }
14644
- line = line.slice(low);
14645
- line = line.trimLeft();
14667
+ // Convert remaining text using array operations
14668
+ const lineArray = stringToArray(line);
14669
+ line = lineArray.slice(low).join('').trimLeft();
14646
14670
  if (line.length > 0) {
14647
- // Check if the remaining text would fit on one line
14648
14671
  lineWidth = this._getTextWidth(line);
14649
14672
  if (lineWidth <= maxWidth) {
14650
- // if it does, add the line and break out of the loop
14651
14673
  this._addTextLine(line);
14652
14674
  currentHeightPx += lineHeightPx;
14653
14675
  textWidth = Math.max(textWidth, lineWidth);
@@ -15482,7 +15504,7 @@
15482
15504
  * // underline text
15483
15505
  * shape.textDecoration('underline');
15484
15506
  */
15485
- Factory.addGetterSetter(TextPath, 'textDecoration', null);
15507
+ Factory.addGetterSetter(TextPath, 'textDecoration', '');
15486
15508
  /**
15487
15509
  * get/set kerning function.
15488
15510
  * @name Konva.TextPath#kerningFunc
@@ -15498,7 +15520,7 @@
15498
15520
  * return 1;
15499
15521
  * });
15500
15522
  */
15501
- Factory.addGetterSetter(TextPath, 'kerningFunc', null);
15523
+ Factory.addGetterSetter(TextPath, 'kerningFunc', undefined);
15502
15524
 
15503
15525
  const EVENTS_NAME = 'tr-konva';
15504
15526
  const ATTR_CHANGE_LIST = [
@@ -16942,7 +16964,6 @@
16942
16964
  * transformer.padding(10);
16943
16965
  */
16944
16966
  Factory.addGetterSetter(Transformer, 'padding', 0, getNumberValidator());
16945
- Factory.addGetterSetter(Transformer, 'node');
16946
16967
  /**
16947
16968
  * get/set attached nodes of the Transformer. Transformer will adapt to their size and listen to their events
16948
16969
  * @method
@@ -16962,6 +16983,9 @@
16962
16983
  * transformer.nodes(newNodes);
16963
16984
  */
16964
16985
  Factory.addGetterSetter(Transformer, 'nodes');
16986
+ // @ts-ignore
16987
+ // deprecated
16988
+ Factory.addGetterSetter(Transformer, 'node');
16965
16989
  /**
16966
16990
  * get/set bounding box function. **IMPORTANT!** boundBondFunc operates in absolute coordinates.
16967
16991
  * @name Konva.Transformer#boundBoxFunc
@@ -17320,7 +17344,8 @@
17320
17344
  function filterGaussBlurRGBA(imageData, radius) {
17321
17345
  const pixels = imageData.data, width = imageData.width, height = imageData.height;
17322
17346
  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
- let div = radius + radius + 1, widthMinus1 = width - 1, heightMinus1 = height - 1, radiusPlus1 = radius + 1, sumFactor = (radiusPlus1 * (radiusPlus1 + 1)) / 2, stackStart = new BlurStack(), stackEnd = null, stack = stackStart, stackIn = null, stackOut = null, mul_sum = mul_table[radius], shg_sum = shg_table[radius];
17347
+ 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];
17348
+ let stackEnd = null, stack = stackStart, stackIn = null, stackOut = null;
17324
17349
  for (i = 1; i < div; i++) {
17325
17350
  stack = stack.next = new BlurStack();
17326
17351
  if (i === radiusPlus1) {
@@ -17536,8 +17561,8 @@
17536
17561
  * node.brightness(0.8);
17537
17562
  */
17538
17563
  const Brighten = function (imageData) {
17539
- let brightness = this.brightness() * 255, data = imageData.data, len = data.length, i;
17540
- for (i = 0; i < len; i += 4) {
17564
+ const brightness = this.brightness() * 255, data = imageData.data, len = data.length;
17565
+ for (let i = 0; i < len; i += 4) {
17541
17566
  // red
17542
17567
  data[i] += brightness;
17543
17568
  // green
@@ -17569,8 +17594,9 @@
17569
17594
  */
17570
17595
  const Contrast = function (imageData) {
17571
17596
  const adjust = Math.pow((this.contrast() + 100) / 100, 2);
17572
- let data = imageData.data, nPixels = data.length, red = 150, green = 150, blue = 150, i;
17573
- for (i = 0; i < nPixels; i += 4) {
17597
+ const data = imageData.data, nPixels = data.length;
17598
+ let red = 150, green = 150, blue = 150;
17599
+ for (let i = 0; i < nPixels; i += 4) {
17574
17600
  red = data[i];
17575
17601
  green = data[i + 1];
17576
17602
  blue = data[i + 2];
@@ -17631,7 +17657,8 @@
17631
17657
  // pixastic greyLevel is between 0 and 255. I want it between 0 and 1. Also,
17632
17658
  // a max value of greyLevel yields a white emboss, and the min value yields a black
17633
17659
  // emboss. Therefore, I changed greyLevel to whiteLevel
17634
- let strength = this.embossStrength() * 10, greyLevel = this.embossWhiteLevel() * 255, direction = this.embossDirection(), blend = this.embossBlend(), dirY = 0, dirX = 0, data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4, y = h;
17660
+ 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;
17661
+ let dirY = 0, dirX = 0, y = h;
17635
17662
  switch (direction) {
17636
17663
  case 'top-left':
17637
17664
  dirY = -1;
@@ -17740,7 +17767,7 @@
17740
17767
  * @param {Number} embossWhiteLevel between 0 and 1. Default is 0.5
17741
17768
  * @returns {Number}
17742
17769
  */
17743
- Factory.addGetterSetter(Node, 'embossDirection', 'top-left', null, Factory.afterSetFilter);
17770
+ Factory.addGetterSetter(Node, 'embossDirection', 'top-left', undefined, Factory.afterSetFilter);
17744
17771
  /**
17745
17772
  * get/set emboss direction. Use with {@link Konva.Filters.Emboss} filter.
17746
17773
  * @name Konva.Node#embossDirection
@@ -17749,7 +17776,7 @@
17749
17776
  * The default is top-left
17750
17777
  * @returns {String}
17751
17778
  */
17752
- Factory.addGetterSetter(Node, 'embossBlend', false, null, Factory.afterSetFilter);
17779
+ Factory.addGetterSetter(Node, 'embossBlend', false, undefined, Factory.afterSetFilter);
17753
17780
  /**
17754
17781
  * get/set emboss blend. Use with {@link Konva.Filters.Emboss} filter.
17755
17782
  * @name Konva.Node#embossBlend
@@ -17760,7 +17787,7 @@
17760
17787
 
17761
17788
  function remap(fromValue, fromMin, fromMax, toMin, toMax) {
17762
17789
  // Compute the range of the data
17763
- let fromRange = fromMax - fromMin, toRange = toMax - toMin, toValue;
17790
+ const fromRange = fromMax - fromMin, toRange = toMax - toMin;
17764
17791
  // If either range is 0, then the value can only be mapped to 1 value
17765
17792
  if (fromRange === 0) {
17766
17793
  return toMin + toRange / 2;
@@ -17769,7 +17796,7 @@
17769
17796
  return toMin;
17770
17797
  }
17771
17798
  // (1) untranslate, (2) unscale, (3) rescale, (4) retranslate
17772
- toValue = (fromValue - fromMin) / fromRange;
17799
+ let toValue = (fromValue - fromMin) / fromRange;
17773
17800
  toValue = toRange * toValue + toMin;
17774
17801
  return toValue;
17775
17802
  }
@@ -17788,14 +17815,15 @@
17788
17815
  * node.enhance(0.4);
17789
17816
  */
17790
17817
  const Enhance = function (imageData) {
17791
- let data = imageData.data, nSubPixels = data.length, rMin = data[0], rMax = rMin, r, gMin = data[1], gMax = gMin, g, bMin = data[2], bMax = bMin, b, i;
17818
+ const data = imageData.data, nSubPixels = data.length;
17819
+ let rMin = data[0], rMax = rMin, r, gMin = data[1], gMax = gMin, g, bMin = data[2], bMax = bMin, b;
17792
17820
  // If we are not enhancing anything - don't do any computation
17793
17821
  const enhanceAmount = this.enhance();
17794
17822
  if (enhanceAmount === 0) {
17795
17823
  return;
17796
17824
  }
17797
17825
  // 1st Pass - find the min and max for each channel:
17798
- for (i = 0; i < nSubPixels; i += 4) {
17826
+ for (let i = 0; i < nSubPixels; i += 4) {
17799
17827
  r = data[i + 0];
17800
17828
  if (r < rMin) {
17801
17829
  rMin = r;
@@ -17857,7 +17885,7 @@
17857
17885
  bGoalMin = bMin + enhanceAmount * (bMin - bMid);
17858
17886
  }
17859
17887
  // Pass 2 - remap everything, except the alpha
17860
- for (i = 0; i < nSubPixels; i += 4) {
17888
+ for (let i = 0; i < nSubPixels; i += 4) {
17861
17889
  data[i + 0] = remap(data[i + 0], rMin, rMax, rGoalMin, rGoalMax);
17862
17890
  data[i + 1] = remap(data[i + 1], gMin, gMax, gGoalMin, gGoalMax);
17863
17891
  data[i + 2] = remap(data[i + 2], bMin, bMax, bGoalMin, bGoalMax);
@@ -17883,9 +17911,9 @@
17883
17911
  * node.filters([Konva.Filters.Grayscale]);
17884
17912
  */
17885
17913
  const Grayscale = function (imageData) {
17886
- let data = imageData.data, len = data.length, i, brightness;
17887
- for (i = 0; i < len; i += 4) {
17888
- brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
17914
+ const data = imageData.data, len = data.length;
17915
+ for (let i = 0; i < len; i += 4) {
17916
+ const brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
17889
17917
  // red
17890
17918
  data[i] = brightness;
17891
17919
  // green
@@ -17930,7 +17958,7 @@
17930
17958
  * image.luminance(0.2);
17931
17959
  */
17932
17960
  const HSL = function (imageData) {
17933
- let 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, i;
17961
+ 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
17962
  // Basis for the technique used:
17935
17963
  // http://beesbuzz.biz/code/hsv_color_transforms.php
17936
17964
  // V is the value multiplier (1 for none, 2 for double, 0.5 for half)
@@ -17948,7 +17976,7 @@
17948
17976
  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
17977
  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
17978
  let r, g, b, a;
17951
- for (i = 0; i < nPixels; i += 4) {
17979
+ for (let i = 0; i < nPixels; i += 4) {
17952
17980
  r = data[i + 0];
17953
17981
  g = data[i + 1];
17954
17982
  b = data[i + 2];
@@ -18036,8 +18064,8 @@
18036
18064
  * node.filters([Konva.Filters.Invert]);
18037
18065
  */
18038
18066
  const Invert = function (imageData) {
18039
- let data = imageData.data, len = data.length, i;
18040
- for (i = 0; i < len; i += 4) {
18067
+ const data = imageData.data, len = data.length;
18068
+ for (let i = 0; i < len; i += 4) {
18041
18069
  // red
18042
18070
  data[i] = 255 - data[i];
18043
18071
  // green
@@ -18063,30 +18091,30 @@
18063
18091
  * default is in the middle
18064
18092
  */
18065
18093
  const ToPolar = function (src, dst, opt) {
18066
- let srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2, i, x, y, r = 0, g = 0, b = 0, a = 0;
18094
+ const srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2;
18067
18095
  // Find the largest radius
18068
- let rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);
18069
- x = xSize - xMid;
18070
- y = ySize - yMid;
18071
- rad = Math.sqrt(x * x + y * y);
18096
+ let rMax = Math.sqrt(xMid * xMid + yMid * yMid);
18097
+ let x = xSize - xMid;
18098
+ let y = ySize - yMid;
18099
+ const rad = Math.sqrt(x * x + y * y);
18072
18100
  rMax = rad > rMax ? rad : rMax;
18073
18101
  // We'll be uisng y as the radius, and x as the angle (theta=t)
18074
- let rSize = ySize, tSize = xSize, radius, theta;
18102
+ const rSize = ySize, tSize = xSize;
18075
18103
  // We want to cover all angles (0-360) and we need to convert to
18076
18104
  // radians (*PI/180)
18077
- let conversion = ((360 / tSize) * Math.PI) / 180, sin, cos;
18105
+ const conversion = ((360 / tSize) * Math.PI) / 180;
18078
18106
  // 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) {
18107
+ for (let theta = 0; theta < tSize; theta += 1) {
18108
+ const sin = Math.sin(theta * conversion);
18109
+ const cos = Math.cos(theta * conversion);
18110
+ for (let radius = 0; radius < rSize; radius += 1) {
18083
18111
  x = Math.floor(xMid + ((rMax * radius) / rSize) * cos);
18084
18112
  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];
18113
+ let i = (y * xSize + x) * 4;
18114
+ const r = srcPixels[i + 0];
18115
+ const g = srcPixels[i + 1];
18116
+ const b = srcPixels[i + 2];
18117
+ const a = srcPixels[i + 3];
18090
18118
  // Store it
18091
18119
  //i = (theta * xSize + radius) * 4;
18092
18120
  i = (theta + radius * xSize) * 4;
@@ -18114,15 +18142,15 @@
18114
18142
  * 0 is no rotation, 360 degrees is a full rotation
18115
18143
  */
18116
18144
  const FromPolar = function (src, dst, opt) {
18117
- let srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2, i, x, y, dx, dy, r = 0, g = 0, b = 0, a = 0;
18145
+ const srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2;
18118
18146
  // Find the largest radius
18119
- let rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);
18120
- x = xSize - xMid;
18121
- y = ySize - yMid;
18122
- rad = Math.sqrt(x * x + y * y);
18147
+ let rMax = Math.sqrt(xMid * xMid + yMid * yMid);
18148
+ let x = xSize - xMid;
18149
+ let y = ySize - yMid;
18150
+ const rad = Math.sqrt(x * x + y * y);
18123
18151
  rMax = rad > rMax ? rad : rMax;
18124
18152
  // We'll be uisng x as the radius, and y as the angle (theta=t)
18125
- let rSize = ySize, tSize = xSize, radius, theta, phaseShift = 0;
18153
+ const rSize = ySize, tSize = xSize, phaseShift = 0;
18126
18154
  // We need to convert to degrees and we need to make sure
18127
18155
  // it's between (0-360)
18128
18156
  // var conversion = tSize/360*180/Math.PI;
@@ -18130,18 +18158,18 @@
18130
18158
  let x1, y1;
18131
18159
  for (x = 0; x < xSize; x += 1) {
18132
18160
  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;
18161
+ const dx = x - xMid;
18162
+ const dy = y - yMid;
18163
+ const radius = (Math.sqrt(dx * dx + dy * dy) * rSize) / rMax;
18164
+ let theta = ((Math.atan2(dy, dx) * 180) / Math.PI + 360 + phaseShift) % 360;
18137
18165
  theta = (theta * tSize) / 360;
18138
18166
  x1 = Math.floor(theta);
18139
18167
  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];
18168
+ let i = (y1 * xSize + x1) * 4;
18169
+ const r = srcPixels[i + 0];
18170
+ const g = srcPixels[i + 1];
18171
+ const b = srcPixels[i + 2];
18172
+ const a = srcPixels[i + 3];
18145
18173
  // Store it
18146
18174
  i = (y * xSize + x) * 4;
18147
18175
  dstPixels[i + 0] = r;
@@ -18401,7 +18429,8 @@
18401
18429
  */
18402
18430
  const Mask = function (imageData) {
18403
18431
  // Detect pixels close to the background color
18404
- let threshold = this.threshold(), mask = backgroundMask(imageData, threshold);
18432
+ const threshold = this.threshold();
18433
+ let mask = backgroundMask(imageData, threshold);
18405
18434
  if (mask) {
18406
18435
  // Erode
18407
18436
  mask = erodeMask(mask, imageData.width, imageData.height);
@@ -18545,8 +18574,8 @@
18545
18574
  */
18546
18575
  const Posterize = function (imageData) {
18547
18576
  // level must be between 1 and 255
18548
- let levels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels, i;
18549
- for (i = 0; i < len; i += 1) {
18577
+ const levels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels;
18578
+ for (let i = 0; i < len; i += 1) {
18550
18579
  data[i] = Math.floor(data[i] / scale) * scale;
18551
18580
  }
18552
18581
  };
@@ -18573,10 +18602,9 @@
18573
18602
  * node.green(200);
18574
18603
  */
18575
18604
  const RGB = function (imageData) {
18576
- let data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), i, brightness;
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;
18605
+ const data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue();
18606
+ for (let i = 0; i < nPixels; i += 4) {
18607
+ const brightness = (0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255;
18580
18608
  data[i] = brightness * red; // r
18581
18609
  data[i + 1] = brightness * green; // g
18582
18610
  data[i + 2] = brightness * blue; // b
@@ -18737,11 +18765,11 @@
18737
18765
  * node.filters([Konva.Filters.Sepia]);
18738
18766
  */
18739
18767
  const Sepia = function (imageData) {
18740
- let data = imageData.data, nPixels = data.length, i, r, g, b;
18741
- for (i = 0; i < nPixels; i += 4) {
18742
- r = data[i + 0];
18743
- g = data[i + 1];
18744
- b = data[i + 2];
18768
+ const data = imageData.data, nPixels = data.length;
18769
+ for (let i = 0; i < nPixels; i += 4) {
18770
+ const r = data[i + 0];
18771
+ const g = data[i + 1];
18772
+ const b = data[i + 2];
18745
18773
  data[i + 0] = Math.min(255, r * 0.393 + g * 0.769 + b * 0.189);
18746
18774
  data[i + 1] = Math.min(255, r * 0.349 + g * 0.686 + b * 0.168);
18747
18775
  data[i + 2] = Math.min(255, r * 0.272 + g * 0.534 + b * 0.131);