konva 9.3.20 → 9.3.22

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.20
8
+ * Konva JavaScript Framework v9.3.22
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Thu Mar 20 2025
11
+ * Date: Tue Jul 08 2025
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.20',
38
+ version: '9.3.22',
39
39
  isBrowser: detectBrowser(),
40
40
  isUnminified: /param/.test(function (param) { }.toString()),
41
41
  dblClickWindow: 400,
@@ -151,7 +151,7 @@
151
151
  },
152
152
  isTransforming() {
153
153
  var _a;
154
- return (_a = Konva$2['Transformer']) === null || _a === undefined ? undefined : _a.isTransforming();
154
+ return (_a = Konva$2['Transformer']) === null || _a === void 0 ? void 0 : _a.isTransforming();
155
155
  },
156
156
  /**
157
157
  * returns whether or not a drag and drop operation is ready, but may
@@ -1150,290 +1150,6 @@
1150
1150
  },
1151
1151
  };
1152
1152
 
1153
- function _formatValue(val) {
1154
- if (Util._isString(val)) {
1155
- return '"' + val + '"';
1156
- }
1157
- if (Object.prototype.toString.call(val) === '[object Number]') {
1158
- return val;
1159
- }
1160
- if (Util._isBoolean(val)) {
1161
- return val;
1162
- }
1163
- return Object.prototype.toString.call(val);
1164
- }
1165
- function RGBComponent(val) {
1166
- if (val > 255) {
1167
- return 255;
1168
- }
1169
- else if (val < 0) {
1170
- return 0;
1171
- }
1172
- return Math.round(val);
1173
- }
1174
- function getNumberValidator() {
1175
- if (Konva$2.isUnminified) {
1176
- return function (val, attr) {
1177
- if (!Util._isNumber(val)) {
1178
- Util.warn(_formatValue(val) +
1179
- ' is a not valid value for "' +
1180
- attr +
1181
- '" attribute. The value should be a number.');
1182
- }
1183
- return val;
1184
- };
1185
- }
1186
- }
1187
- function getNumberOrArrayOfNumbersValidator(noOfElements) {
1188
- if (Konva$2.isUnminified) {
1189
- return function (val, attr) {
1190
- let isNumber = Util._isNumber(val);
1191
- let isValidArray = Util._isArray(val) && val.length == noOfElements;
1192
- if (!isNumber && !isValidArray) {
1193
- Util.warn(_formatValue(val) +
1194
- ' is a not valid value for "' +
1195
- attr +
1196
- '" attribute. The value should be a number or Array<number>(' +
1197
- noOfElements +
1198
- ')');
1199
- }
1200
- return val;
1201
- };
1202
- }
1203
- }
1204
- function getNumberOrAutoValidator() {
1205
- if (Konva$2.isUnminified) {
1206
- return function (val, attr) {
1207
- var isNumber = Util._isNumber(val);
1208
- var isAuto = val === 'auto';
1209
- if (!(isNumber || isAuto)) {
1210
- Util.warn(_formatValue(val) +
1211
- ' is a not valid value for "' +
1212
- attr +
1213
- '" attribute. The value should be a number or "auto".');
1214
- }
1215
- return val;
1216
- };
1217
- }
1218
- }
1219
- function getStringValidator() {
1220
- if (Konva$2.isUnminified) {
1221
- return function (val, attr) {
1222
- if (!Util._isString(val)) {
1223
- Util.warn(_formatValue(val) +
1224
- ' is a not valid value for "' +
1225
- attr +
1226
- '" attribute. The value should be a string.');
1227
- }
1228
- return val;
1229
- };
1230
- }
1231
- }
1232
- function getStringOrGradientValidator() {
1233
- if (Konva$2.isUnminified) {
1234
- return function (val, attr) {
1235
- const isString = Util._isString(val);
1236
- const isGradient = Object.prototype.toString.call(val) === '[object CanvasGradient]' ||
1237
- (val && val['addColorStop']);
1238
- if (!(isString || isGradient)) {
1239
- Util.warn(_formatValue(val) +
1240
- ' is a not valid value for "' +
1241
- attr +
1242
- '" attribute. The value should be a string or a native gradient.');
1243
- }
1244
- return val;
1245
- };
1246
- }
1247
- }
1248
- function getNumberArrayValidator() {
1249
- if (Konva$2.isUnminified) {
1250
- return function (val, attr) {
1251
- // Retrieve TypedArray constructor as found in MDN (if TypedArray is available)
1252
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#description
1253
- const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null;
1254
- if (TypedArray && val instanceof TypedArray) {
1255
- return val;
1256
- }
1257
- if (!Util._isArray(val)) {
1258
- Util.warn(_formatValue(val) +
1259
- ' is a not valid value for "' +
1260
- attr +
1261
- '" attribute. The value should be a array of numbers.');
1262
- }
1263
- else {
1264
- val.forEach(function (item) {
1265
- if (!Util._isNumber(item)) {
1266
- Util.warn('"' +
1267
- attr +
1268
- '" attribute has non numeric element ' +
1269
- item +
1270
- '. Make sure that all elements are numbers.');
1271
- }
1272
- });
1273
- }
1274
- return val;
1275
- };
1276
- }
1277
- }
1278
- function getBooleanValidator() {
1279
- if (Konva$2.isUnminified) {
1280
- return function (val, attr) {
1281
- var isBool = val === true || val === false;
1282
- if (!isBool) {
1283
- Util.warn(_formatValue(val) +
1284
- ' is a not valid value for "' +
1285
- attr +
1286
- '" attribute. The value should be a boolean.');
1287
- }
1288
- return val;
1289
- };
1290
- }
1291
- }
1292
- function getComponentValidator(components) {
1293
- if (Konva$2.isUnminified) {
1294
- return function (val, attr) {
1295
- // ignore validation on undefined value, because it will reset to defalt
1296
- if (val === undefined || val === null) {
1297
- return val;
1298
- }
1299
- if (!Util.isObject(val)) {
1300
- Util.warn(_formatValue(val) +
1301
- ' is a not valid value for "' +
1302
- attr +
1303
- '" attribute. The value should be an object with properties ' +
1304
- components);
1305
- }
1306
- return val;
1307
- };
1308
- }
1309
- }
1310
-
1311
- const GET = 'get';
1312
- const SET$1 = 'set';
1313
- const Factory = {
1314
- addGetterSetter(constructor, attr, def, validator, after) {
1315
- Factory.addGetter(constructor, attr, def);
1316
- Factory.addSetter(constructor, attr, validator, after);
1317
- Factory.addOverloadedGetterSetter(constructor, attr);
1318
- },
1319
- addGetter(constructor, attr, def) {
1320
- var method = GET + Util._capitalize(attr);
1321
- constructor.prototype[method] =
1322
- constructor.prototype[method] ||
1323
- function () {
1324
- const val = this.attrs[attr];
1325
- return val === undefined ? def : val;
1326
- };
1327
- },
1328
- addSetter(constructor, attr, validator, after) {
1329
- var method = SET$1 + Util._capitalize(attr);
1330
- if (!constructor.prototype[method]) {
1331
- Factory.overWriteSetter(constructor, attr, validator, after);
1332
- }
1333
- },
1334
- overWriteSetter(constructor, attr, validator, after) {
1335
- var method = SET$1 + Util._capitalize(attr);
1336
- constructor.prototype[method] = function (val) {
1337
- if (validator && val !== undefined && val !== null) {
1338
- val = validator.call(this, val, attr);
1339
- }
1340
- this._setAttr(attr, val);
1341
- if (after) {
1342
- after.call(this);
1343
- }
1344
- return this;
1345
- };
1346
- },
1347
- addComponentsGetterSetter(constructor, attr, components, validator, after) {
1348
- const len = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), setter = SET$1 + capitalize(attr);
1349
- // getter
1350
- constructor.prototype[getter] = function () {
1351
- const ret = {};
1352
- for (let n = 0; n < len; n++) {
1353
- const component = components[n];
1354
- ret[component] = this.getAttr(attr + capitalize(component));
1355
- }
1356
- return ret;
1357
- };
1358
- const basicValidator = getComponentValidator(components);
1359
- // setter
1360
- constructor.prototype[setter] = function (val) {
1361
- const oldVal = this.attrs[attr];
1362
- if (validator) {
1363
- val = validator.call(this, val, attr);
1364
- }
1365
- if (basicValidator) {
1366
- basicValidator.call(this, val, attr);
1367
- }
1368
- for (const key in val) {
1369
- if (!val.hasOwnProperty(key)) {
1370
- continue;
1371
- }
1372
- this._setAttr(attr + capitalize(key), val[key]);
1373
- }
1374
- if (!val) {
1375
- components.forEach((component) => {
1376
- this._setAttr(attr + capitalize(component), undefined);
1377
- });
1378
- }
1379
- this._fireChangeEvent(attr, oldVal, val);
1380
- if (after) {
1381
- after.call(this);
1382
- }
1383
- return this;
1384
- };
1385
- Factory.addOverloadedGetterSetter(constructor, attr);
1386
- },
1387
- addOverloadedGetterSetter(constructor, attr) {
1388
- var capitalizedAttr = Util._capitalize(attr), setter = SET$1 + capitalizedAttr, getter = GET + capitalizedAttr;
1389
- constructor.prototype[attr] = function () {
1390
- // setting
1391
- if (arguments.length) {
1392
- this[setter](arguments[0]);
1393
- return this;
1394
- }
1395
- // getting
1396
- return this[getter]();
1397
- };
1398
- },
1399
- addDeprecatedGetterSetter(constructor, attr, def, validator) {
1400
- Util.error('Adding deprecated ' + attr);
1401
- const method = GET + Util._capitalize(attr);
1402
- const message = attr +
1403
- ' property is deprecated and will be removed soon. Look at Konva change log for more information.';
1404
- constructor.prototype[method] = function () {
1405
- Util.error(message);
1406
- const val = this.attrs[attr];
1407
- return val === undefined ? def : val;
1408
- };
1409
- Factory.addSetter(constructor, attr, validator, function () {
1410
- Util.error(message);
1411
- });
1412
- Factory.addOverloadedGetterSetter(constructor, attr);
1413
- },
1414
- backCompat(constructor, methods) {
1415
- Util.each(methods, function (oldMethodName, newMethodName) {
1416
- const method = constructor.prototype[newMethodName];
1417
- const oldGetter = GET + Util._capitalize(oldMethodName);
1418
- const oldSetter = SET$1 + Util._capitalize(oldMethodName);
1419
- function deprecated() {
1420
- method.apply(this, arguments);
1421
- Util.error('"' +
1422
- oldMethodName +
1423
- '" method is deprecated and will be removed soon. Use ""' +
1424
- newMethodName +
1425
- '" instead.');
1426
- }
1427
- constructor.prototype[oldMethodName] = deprecated;
1428
- constructor.prototype[oldGetter] = deprecated;
1429
- constructor.prototype[oldSetter] = deprecated;
1430
- });
1431
- },
1432
- afterSetFilter() {
1433
- this._filterUpToDate = false;
1434
- },
1435
- };
1436
-
1437
1153
  function simplifyArray(arr) {
1438
1154
  const retArr = [], len = arr.length, util = Util;
1439
1155
  for (let n = 0; n < len; n++) {
@@ -2178,7 +1894,7 @@
2178
1894
  }
2179
1895
  _applyShadow(shape) {
2180
1896
  var _a, _b, _c;
2181
- const color = (_a = shape.getShadowRGBA()) !== null && _a !== undefined ? _a : 'black', blur = (_b = shape.getShadowBlur()) !== null && _b !== undefined ? _b : 5, offset = (_c = shape.getShadowOffset()) !== null && _c !== undefined ? _c : {
1897
+ const color = (_a = shape.getShadowRGBA()) !== null && _a !== void 0 ? _a : 'black', blur = (_b = shape.getShadowBlur()) !== null && _b !== void 0 ? _b : 5, offset = (_c = shape.getShadowOffset()) !== null && _c !== void 0 ? _c : {
2182
1898
  x: 0,
2183
1899
  y: 0,
2184
1900
  }, scale = shape.getAbsoluteScale(), ratio = this.canvas.getPixelRatio(), scaleX = scale.x * ratio, scaleY = scale.y * ratio;
@@ -2278,243 +1994,527 @@
2278
1994
  this._canvas.style.top = '0';
2279
1995
  this._canvas.style.left = '0';
2280
1996
  }
2281
- /**
2282
- * get canvas context
2283
- * @method
2284
- * @name Konva.Canvas#getContext
2285
- * @returns {CanvasContext} context
2286
- */
2287
- getContext() {
2288
- return this.context;
1997
+ /**
1998
+ * get canvas context
1999
+ * @method
2000
+ * @name Konva.Canvas#getContext
2001
+ * @returns {CanvasContext} context
2002
+ */
2003
+ getContext() {
2004
+ return this.context;
2005
+ }
2006
+ /**
2007
+ * get pixel ratio
2008
+ * @method
2009
+ * @name Konva.Canvas#getPixelRatio
2010
+ * @returns {Number} pixel ratio
2011
+ * @example
2012
+ * var pixelRatio = layer.getCanvas.getPixelRatio();
2013
+ */
2014
+ getPixelRatio() {
2015
+ return this.pixelRatio;
2016
+ }
2017
+ /**
2018
+ * set pixel ratio
2019
+ * KonvaJS automatically handles pixel ratio adustments in order to render crisp drawings
2020
+ * on all devices. Most desktops, low end tablets, and low end phones, have device pixel ratios
2021
+ * of 1. Some high end tablets and phones, like iPhones and iPads have a device pixel ratio
2022
+ * of 2. Some Macbook Pros, and iMacs also have a device pixel ratio of 2. Some high end Android devices have pixel
2023
+ * ratios of 2 or 3. Some browsers like Firefox allow you to configure the pixel ratio of the viewport. Unless otherwise
2024
+ * specificed, the pixel ratio will be defaulted to the actual device pixel ratio. You can override the device pixel
2025
+ * ratio for special situations, or, if you don't want the pixel ratio to be taken into account, you can set it to 1.
2026
+ * @method
2027
+ * @name Konva.Canvas#setPixelRatio
2028
+ * @param {Number} pixelRatio
2029
+ * @example
2030
+ * layer.getCanvas().setPixelRatio(3);
2031
+ */
2032
+ setPixelRatio(pixelRatio) {
2033
+ const previousRatio = this.pixelRatio;
2034
+ this.pixelRatio = pixelRatio;
2035
+ this.setSize(this.getWidth() / previousRatio, this.getHeight() / previousRatio);
2036
+ }
2037
+ setWidth(width) {
2038
+ // take into account pixel ratio
2039
+ this.width = this._canvas.width = width * this.pixelRatio;
2040
+ this._canvas.style.width = width + 'px';
2041
+ const pixelRatio = this.pixelRatio, _context = this.getContext()._context;
2042
+ _context.scale(pixelRatio, pixelRatio);
2043
+ }
2044
+ setHeight(height) {
2045
+ // take into account pixel ratio
2046
+ this.height = this._canvas.height = height * this.pixelRatio;
2047
+ this._canvas.style.height = height + 'px';
2048
+ const pixelRatio = this.pixelRatio, _context = this.getContext()._context;
2049
+ _context.scale(pixelRatio, pixelRatio);
2050
+ }
2051
+ getWidth() {
2052
+ return this.width;
2053
+ }
2054
+ getHeight() {
2055
+ return this.height;
2056
+ }
2057
+ setSize(width, height) {
2058
+ this.setWidth(width || 0);
2059
+ this.setHeight(height || 0);
2060
+ }
2061
+ /**
2062
+ * to data url
2063
+ * @method
2064
+ * @name Konva.Canvas#toDataURL
2065
+ * @param {String} mimeType
2066
+ * @param {Number} quality between 0 and 1 for jpg mime types
2067
+ * @returns {String} data url string
2068
+ */
2069
+ toDataURL(mimeType, quality) {
2070
+ try {
2071
+ // If this call fails (due to browser bug, like in Firefox 3.6),
2072
+ // then revert to previous no-parameter image/png behavior
2073
+ return this._canvas.toDataURL(mimeType, quality);
2074
+ }
2075
+ catch (e) {
2076
+ try {
2077
+ return this._canvas.toDataURL();
2078
+ }
2079
+ catch (err) {
2080
+ Util.error('Unable to get data URL. ' +
2081
+ err.message +
2082
+ ' For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html.');
2083
+ return '';
2084
+ }
2085
+ }
2086
+ }
2087
+ }
2088
+ class SceneCanvas extends Canvas {
2089
+ constructor(config = { width: 0, height: 0, willReadFrequently: false }) {
2090
+ super(config);
2091
+ this.context = new SceneContext(this, {
2092
+ willReadFrequently: config.willReadFrequently,
2093
+ });
2094
+ this.setSize(config.width, config.height);
2095
+ }
2096
+ }
2097
+ class HitCanvas extends Canvas {
2098
+ constructor(config = { width: 0, height: 0 }) {
2099
+ super(config);
2100
+ this.hitCanvas = true;
2101
+ this.context = new HitContext(this);
2102
+ this.setSize(config.width, config.height);
2103
+ }
2104
+ }
2105
+
2106
+ const DD = {
2107
+ get isDragging() {
2108
+ let flag = false;
2109
+ DD._dragElements.forEach((elem) => {
2110
+ if (elem.dragStatus === 'dragging') {
2111
+ flag = true;
2112
+ }
2113
+ });
2114
+ return flag;
2115
+ },
2116
+ justDragged: false,
2117
+ get node() {
2118
+ // return first dragging node
2119
+ let node;
2120
+ DD._dragElements.forEach((elem) => {
2121
+ node = elem.node;
2122
+ });
2123
+ return node;
2124
+ },
2125
+ _dragElements: new Map(),
2126
+ // methods
2127
+ _drag(evt) {
2128
+ const nodesToFireEvents = [];
2129
+ DD._dragElements.forEach((elem, key) => {
2130
+ const { node } = elem;
2131
+ // we need to find pointer relative to that node
2132
+ const stage = node.getStage();
2133
+ stage.setPointersPositions(evt);
2134
+ // it is possible that user call startDrag without any event
2135
+ // it that case we need to detect first movable pointer and attach it into the node
2136
+ if (elem.pointerId === undefined) {
2137
+ elem.pointerId = Util._getFirstPointerId(evt);
2138
+ }
2139
+ const pos = stage._changedPointerPositions.find((pos) => pos.id === elem.pointerId);
2140
+ // not related pointer
2141
+ if (!pos) {
2142
+ return;
2143
+ }
2144
+ if (elem.dragStatus !== 'dragging') {
2145
+ const dragDistance = node.dragDistance();
2146
+ const distance = Math.max(Math.abs(pos.x - elem.startPointerPos.x), Math.abs(pos.y - elem.startPointerPos.y));
2147
+ if (distance < dragDistance) {
2148
+ return;
2149
+ }
2150
+ node.startDrag({ evt });
2151
+ // a user can stop dragging inside `dragstart`
2152
+ if (!node.isDragging()) {
2153
+ return;
2154
+ }
2155
+ }
2156
+ node._setDragPosition(evt, elem);
2157
+ nodesToFireEvents.push(node);
2158
+ });
2159
+ // call dragmove only after ALL positions are changed
2160
+ nodesToFireEvents.forEach((node) => {
2161
+ node.fire('dragmove', {
2162
+ type: 'dragmove',
2163
+ target: node,
2164
+ evt: evt,
2165
+ }, true);
2166
+ });
2167
+ },
2168
+ // dragBefore and dragAfter allows us to set correct order of events
2169
+ // setup all in dragbefore, and stop dragging only after pointerup triggered.
2170
+ _endDragBefore(evt) {
2171
+ const drawNodes = [];
2172
+ DD._dragElements.forEach((elem) => {
2173
+ const { node } = elem;
2174
+ // we need to find pointer relative to that node
2175
+ const stage = node.getStage();
2176
+ if (evt) {
2177
+ stage.setPointersPositions(evt);
2178
+ }
2179
+ const pos = stage._changedPointerPositions.find((pos) => pos.id === elem.pointerId);
2180
+ // that pointer is not related
2181
+ if (!pos) {
2182
+ return;
2183
+ }
2184
+ if (elem.dragStatus === 'dragging' || elem.dragStatus === 'stopped') {
2185
+ // if a node is stopped manually we still need to reset events:
2186
+ DD.justDragged = true;
2187
+ Konva$2._mouseListenClick = false;
2188
+ Konva$2._touchListenClick = false;
2189
+ Konva$2._pointerListenClick = false;
2190
+ elem.dragStatus = 'stopped';
2191
+ }
2192
+ const drawNode = elem.node.getLayer() ||
2193
+ (elem.node instanceof Konva$2['Stage'] && elem.node);
2194
+ if (drawNode && drawNodes.indexOf(drawNode) === -1) {
2195
+ drawNodes.push(drawNode);
2196
+ }
2197
+ });
2198
+ // draw in a sync way
2199
+ // because mousemove event may trigger BEFORE batch draw is called
2200
+ // but as we have not hit canvas updated yet, it will trigger incorrect mouseover/mouseout events
2201
+ drawNodes.forEach((drawNode) => {
2202
+ drawNode.draw();
2203
+ });
2204
+ },
2205
+ _endDragAfter(evt) {
2206
+ DD._dragElements.forEach((elem, key) => {
2207
+ if (elem.dragStatus === 'stopped') {
2208
+ elem.node.fire('dragend', {
2209
+ type: 'dragend',
2210
+ target: elem.node,
2211
+ evt: evt,
2212
+ }, true);
2213
+ }
2214
+ if (elem.dragStatus !== 'dragging') {
2215
+ DD._dragElements.delete(key);
2216
+ }
2217
+ });
2218
+ },
2219
+ };
2220
+ if (Konva$2.isBrowser) {
2221
+ window.addEventListener('mouseup', DD._endDragBefore, true);
2222
+ window.addEventListener('touchend', DD._endDragBefore, true);
2223
+ // add touchcancel to fix this: https://github.com/konvajs/konva/issues/1843
2224
+ window.addEventListener('touchcancel', DD._endDragBefore, true);
2225
+ window.addEventListener('mousemove', DD._drag);
2226
+ window.addEventListener('touchmove', DD._drag);
2227
+ window.addEventListener('mouseup', DD._endDragAfter, false);
2228
+ window.addEventListener('touchend', DD._endDragAfter, false);
2229
+ window.addEventListener('touchcancel', DD._endDragAfter, false);
2230
+ }
2231
+
2232
+ function _formatValue(val) {
2233
+ if (Util._isString(val)) {
2234
+ return '"' + val + '"';
2235
+ }
2236
+ if (Object.prototype.toString.call(val) === '[object Number]') {
2237
+ return val;
2289
2238
  }
2290
- /**
2291
- * get pixel ratio
2292
- * @method
2293
- * @name Konva.Canvas#getPixelRatio
2294
- * @returns {Number} pixel ratio
2295
- * @example
2296
- * var pixelRatio = layer.getCanvas.getPixelRatio();
2297
- */
2298
- getPixelRatio() {
2299
- return this.pixelRatio;
2239
+ if (Util._isBoolean(val)) {
2240
+ return val;
2300
2241
  }
2301
- /**
2302
- * set pixel ratio
2303
- * KonvaJS automatically handles pixel ratio adustments in order to render crisp drawings
2304
- * on all devices. Most desktops, low end tablets, and low end phones, have device pixel ratios
2305
- * of 1. Some high end tablets and phones, like iPhones and iPads have a device pixel ratio
2306
- * of 2. Some Macbook Pros, and iMacs also have a device pixel ratio of 2. Some high end Android devices have pixel
2307
- * ratios of 2 or 3. Some browsers like Firefox allow you to configure the pixel ratio of the viewport. Unless otherwise
2308
- * specificed, the pixel ratio will be defaulted to the actual device pixel ratio. You can override the device pixel
2309
- * ratio for special situations, or, if you don't want the pixel ratio to be taken into account, you can set it to 1.
2310
- * @method
2311
- * @name Konva.Canvas#setPixelRatio
2312
- * @param {Number} pixelRatio
2313
- * @example
2314
- * layer.getCanvas().setPixelRatio(3);
2315
- */
2316
- setPixelRatio(pixelRatio) {
2317
- const previousRatio = this.pixelRatio;
2318
- this.pixelRatio = pixelRatio;
2319
- this.setSize(this.getWidth() / previousRatio, this.getHeight() / previousRatio);
2242
+ return Object.prototype.toString.call(val);
2243
+ }
2244
+ function RGBComponent(val) {
2245
+ if (val > 255) {
2246
+ return 255;
2320
2247
  }
2321
- setWidth(width) {
2322
- // take into account pixel ratio
2323
- this.width = this._canvas.width = width * this.pixelRatio;
2324
- this._canvas.style.width = width + 'px';
2325
- const pixelRatio = this.pixelRatio, _context = this.getContext()._context;
2326
- _context.scale(pixelRatio, pixelRatio);
2248
+ else if (val < 0) {
2249
+ return 0;
2327
2250
  }
2328
- setHeight(height) {
2329
- // take into account pixel ratio
2330
- this.height = this._canvas.height = height * this.pixelRatio;
2331
- this._canvas.style.height = height + 'px';
2332
- const pixelRatio = this.pixelRatio, _context = this.getContext()._context;
2333
- _context.scale(pixelRatio, pixelRatio);
2251
+ return Math.round(val);
2252
+ }
2253
+ function getNumberValidator() {
2254
+ if (Konva$2.isUnminified) {
2255
+ return function (val, attr) {
2256
+ if (!Util._isNumber(val)) {
2257
+ Util.warn(_formatValue(val) +
2258
+ ' is a not valid value for "' +
2259
+ attr +
2260
+ '" attribute. The value should be a number.');
2261
+ }
2262
+ return val;
2263
+ };
2334
2264
  }
2335
- getWidth() {
2336
- return this.width;
2265
+ }
2266
+ function getNumberOrArrayOfNumbersValidator(noOfElements) {
2267
+ if (Konva$2.isUnminified) {
2268
+ return function (val, attr) {
2269
+ let isNumber = Util._isNumber(val);
2270
+ let isValidArray = Util._isArray(val) && val.length == noOfElements;
2271
+ if (!isNumber && !isValidArray) {
2272
+ Util.warn(_formatValue(val) +
2273
+ ' is a not valid value for "' +
2274
+ attr +
2275
+ '" attribute. The value should be a number or Array<number>(' +
2276
+ noOfElements +
2277
+ ')');
2278
+ }
2279
+ return val;
2280
+ };
2337
2281
  }
2338
- getHeight() {
2339
- return this.height;
2282
+ }
2283
+ function getNumberOrAutoValidator() {
2284
+ if (Konva$2.isUnminified) {
2285
+ return function (val, attr) {
2286
+ const isNumber = Util._isNumber(val);
2287
+ const isAuto = val === 'auto';
2288
+ if (!(isNumber || isAuto)) {
2289
+ Util.warn(_formatValue(val) +
2290
+ ' is a not valid value for "' +
2291
+ attr +
2292
+ '" attribute. The value should be a number or "auto".');
2293
+ }
2294
+ return val;
2295
+ };
2340
2296
  }
2341
- setSize(width, height) {
2342
- this.setWidth(width || 0);
2343
- this.setHeight(height || 0);
2297
+ }
2298
+ function getStringValidator() {
2299
+ if (Konva$2.isUnminified) {
2300
+ return function (val, attr) {
2301
+ if (!Util._isString(val)) {
2302
+ Util.warn(_formatValue(val) +
2303
+ ' is a not valid value for "' +
2304
+ attr +
2305
+ '" attribute. The value should be a string.');
2306
+ }
2307
+ return val;
2308
+ };
2344
2309
  }
2345
- /**
2346
- * to data url
2347
- * @method
2348
- * @name Konva.Canvas#toDataURL
2349
- * @param {String} mimeType
2350
- * @param {Number} quality between 0 and 1 for jpg mime types
2351
- * @returns {String} data url string
2352
- */
2353
- toDataURL(mimeType, quality) {
2354
- try {
2355
- // If this call fails (due to browser bug, like in Firefox 3.6),
2356
- // then revert to previous no-parameter image/png behavior
2357
- return this._canvas.toDataURL(mimeType, quality);
2358
- }
2359
- catch (e) {
2360
- try {
2361
- return this._canvas.toDataURL();
2310
+ }
2311
+ function getStringOrGradientValidator() {
2312
+ if (Konva$2.isUnminified) {
2313
+ return function (val, attr) {
2314
+ const isString = Util._isString(val);
2315
+ const isGradient = Object.prototype.toString.call(val) === '[object CanvasGradient]' ||
2316
+ (val && val['addColorStop']);
2317
+ if (!(isString || isGradient)) {
2318
+ Util.warn(_formatValue(val) +
2319
+ ' is a not valid value for "' +
2320
+ attr +
2321
+ '" attribute. The value should be a string or a native gradient.');
2362
2322
  }
2363
- catch (err) {
2364
- Util.error('Unable to get data URL. ' +
2365
- err.message +
2366
- ' For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html.');
2367
- return '';
2323
+ return val;
2324
+ };
2325
+ }
2326
+ }
2327
+ function getNumberArrayValidator() {
2328
+ if (Konva$2.isUnminified) {
2329
+ return function (val, attr) {
2330
+ // Retrieve TypedArray constructor as found in MDN (if TypedArray is available)
2331
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#description
2332
+ const TypedArray = Int8Array ? Object.getPrototypeOf(Int8Array) : null;
2333
+ if (TypedArray && val instanceof TypedArray) {
2334
+ return val;
2368
2335
  }
2369
- }
2336
+ if (!Util._isArray(val)) {
2337
+ Util.warn(_formatValue(val) +
2338
+ ' is a not valid value for "' +
2339
+ attr +
2340
+ '" attribute. The value should be a array of numbers.');
2341
+ }
2342
+ else {
2343
+ val.forEach(function (item) {
2344
+ if (!Util._isNumber(item)) {
2345
+ Util.warn('"' +
2346
+ attr +
2347
+ '" attribute has non numeric element ' +
2348
+ item +
2349
+ '. Make sure that all elements are numbers.');
2350
+ }
2351
+ });
2352
+ }
2353
+ return val;
2354
+ };
2370
2355
  }
2371
2356
  }
2372
- class SceneCanvas extends Canvas {
2373
- constructor(config = { width: 0, height: 0, willReadFrequently: false }) {
2374
- super(config);
2375
- this.context = new SceneContext(this, {
2376
- willReadFrequently: config.willReadFrequently,
2377
- });
2378
- this.setSize(config.width, config.height);
2357
+ function getBooleanValidator() {
2358
+ if (Konva$2.isUnminified) {
2359
+ return function (val, attr) {
2360
+ const isBool = val === true || val === false;
2361
+ if (!isBool) {
2362
+ Util.warn(_formatValue(val) +
2363
+ ' is a not valid value for "' +
2364
+ attr +
2365
+ '" attribute. The value should be a boolean.');
2366
+ }
2367
+ return val;
2368
+ };
2379
2369
  }
2380
2370
  }
2381
- class HitCanvas extends Canvas {
2382
- constructor(config = { width: 0, height: 0 }) {
2383
- super(config);
2384
- this.hitCanvas = true;
2385
- this.context = new HitContext(this);
2386
- this.setSize(config.width, config.height);
2371
+ function getComponentValidator(components) {
2372
+ if (Konva$2.isUnminified) {
2373
+ return function (val, attr) {
2374
+ // ignore validation on undefined value, because it will reset to defalt
2375
+ if (val === undefined || val === null) {
2376
+ return val;
2377
+ }
2378
+ if (!Util.isObject(val)) {
2379
+ Util.warn(_formatValue(val) +
2380
+ ' is a not valid value for "' +
2381
+ attr +
2382
+ '" attribute. The value should be an object with properties ' +
2383
+ components);
2384
+ }
2385
+ return val;
2386
+ };
2387
2387
  }
2388
2388
  }
2389
2389
 
2390
- const DD = {
2391
- get isDragging() {
2392
- let flag = false;
2393
- DD._dragElements.forEach((elem) => {
2394
- if (elem.dragStatus === 'dragging') {
2395
- flag = true;
2396
- }
2397
- });
2398
- return flag;
2390
+ const GET = 'get';
2391
+ const SET$1 = 'set';
2392
+ const Factory = {
2393
+ addGetterSetter(constructor, attr, def, validator, after) {
2394
+ Factory.addGetter(constructor, attr, def);
2395
+ Factory.addSetter(constructor, attr, validator, after);
2396
+ Factory.addOverloadedGetterSetter(constructor, attr);
2397
+ },
2398
+ addGetter(constructor, attr, def) {
2399
+ const method = GET + Util._capitalize(attr);
2400
+ constructor.prototype[method] =
2401
+ constructor.prototype[method] ||
2402
+ function () {
2403
+ const val = this.attrs[attr];
2404
+ return val === undefined ? def : val;
2405
+ };
2399
2406
  },
2400
- justDragged: false,
2401
- get node() {
2402
- // return first dragging node
2403
- let node;
2404
- DD._dragElements.forEach((elem) => {
2405
- node = elem.node;
2406
- });
2407
- return node;
2407
+ addSetter(constructor, attr, validator, after) {
2408
+ const method = SET$1 + Util._capitalize(attr);
2409
+ if (!constructor.prototype[method]) {
2410
+ Factory.overWriteSetter(constructor, attr, validator, after);
2411
+ }
2408
2412
  },
2409
- _dragElements: new Map(),
2410
- // methods
2411
- _drag(evt) {
2412
- const nodesToFireEvents = [];
2413
- DD._dragElements.forEach((elem, key) => {
2414
- const { node } = elem;
2415
- // we need to find pointer relative to that node
2416
- const stage = node.getStage();
2417
- stage.setPointersPositions(evt);
2418
- // it is possible that user call startDrag without any event
2419
- // it that case we need to detect first movable pointer and attach it into the node
2420
- if (elem.pointerId === undefined) {
2421
- elem.pointerId = Util._getFirstPointerId(evt);
2422
- }
2423
- const pos = stage._changedPointerPositions.find((pos) => pos.id === elem.pointerId);
2424
- // not related pointer
2425
- if (!pos) {
2426
- return;
2413
+ overWriteSetter(constructor, attr, validator, after) {
2414
+ const method = SET$1 + Util._capitalize(attr);
2415
+ constructor.prototype[method] = function (val) {
2416
+ if (validator && val !== undefined && val !== null) {
2417
+ val = validator.call(this, val, attr);
2427
2418
  }
2428
- if (elem.dragStatus !== 'dragging') {
2429
- const dragDistance = node.dragDistance();
2430
- const distance = Math.max(Math.abs(pos.x - elem.startPointerPos.x), Math.abs(pos.y - elem.startPointerPos.y));
2431
- if (distance < dragDistance) {
2432
- return;
2433
- }
2434
- node.startDrag({ evt });
2435
- // a user can stop dragging inside `dragstart`
2436
- if (!node.isDragging()) {
2437
- return;
2438
- }
2419
+ this._setAttr(attr, val);
2420
+ if (after) {
2421
+ after.call(this);
2439
2422
  }
2440
- node._setDragPosition(evt, elem);
2441
- nodesToFireEvents.push(node);
2442
- });
2443
- // call dragmove only after ALL positions are changed
2444
- nodesToFireEvents.forEach((node) => {
2445
- node.fire('dragmove', {
2446
- type: 'dragmove',
2447
- target: node,
2448
- evt: evt,
2449
- }, true);
2450
- });
2423
+ return this;
2424
+ };
2451
2425
  },
2452
- // dragBefore and dragAfter allows us to set correct order of events
2453
- // setup all in dragbefore, and stop dragging only after pointerup triggered.
2454
- _endDragBefore(evt) {
2455
- const drawNodes = [];
2456
- DD._dragElements.forEach((elem) => {
2457
- const { node } = elem;
2458
- // we need to find pointer relative to that node
2459
- const stage = node.getStage();
2460
- if (evt) {
2461
- stage.setPointersPositions(evt);
2426
+ addComponentsGetterSetter(constructor, attr, components, validator, after) {
2427
+ const len = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), setter = SET$1 + capitalize(attr);
2428
+ // getter
2429
+ constructor.prototype[getter] = function () {
2430
+ const ret = {};
2431
+ for (let n = 0; n < len; n++) {
2432
+ const component = components[n];
2433
+ ret[component] = this.getAttr(attr + capitalize(component));
2462
2434
  }
2463
- const pos = stage._changedPointerPositions.find((pos) => pos.id === elem.pointerId);
2464
- // that pointer is not related
2465
- if (!pos) {
2466
- return;
2435
+ return ret;
2436
+ };
2437
+ const basicValidator = getComponentValidator(components);
2438
+ // setter
2439
+ constructor.prototype[setter] = function (val) {
2440
+ const oldVal = this.attrs[attr];
2441
+ if (validator) {
2442
+ val = validator.call(this, val, attr);
2467
2443
  }
2468
- if (elem.dragStatus === 'dragging' || elem.dragStatus === 'stopped') {
2469
- // if a node is stopped manually we still need to reset events:
2470
- DD.justDragged = true;
2471
- Konva$2._mouseListenClick = false;
2472
- Konva$2._touchListenClick = false;
2473
- Konva$2._pointerListenClick = false;
2474
- elem.dragStatus = 'stopped';
2444
+ if (basicValidator) {
2445
+ basicValidator.call(this, val, attr);
2475
2446
  }
2476
- const drawNode = elem.node.getLayer() ||
2477
- (elem.node instanceof Konva$2['Stage'] && elem.node);
2478
- if (drawNode && drawNodes.indexOf(drawNode) === -1) {
2479
- drawNodes.push(drawNode);
2447
+ for (const key in val) {
2448
+ if (!val.hasOwnProperty(key)) {
2449
+ continue;
2450
+ }
2451
+ this._setAttr(attr + capitalize(key), val[key]);
2480
2452
  }
2481
- });
2482
- // draw in a sync way
2483
- // because mousemove event may trigger BEFORE batch draw is called
2484
- // but as we have not hit canvas updated yet, it will trigger incorrect mouseover/mouseout events
2485
- drawNodes.forEach((drawNode) => {
2486
- drawNode.draw();
2487
- });
2453
+ if (!val) {
2454
+ components.forEach((component) => {
2455
+ this._setAttr(attr + capitalize(component), undefined);
2456
+ });
2457
+ }
2458
+ this._fireChangeEvent(attr, oldVal, val);
2459
+ if (after) {
2460
+ after.call(this);
2461
+ }
2462
+ return this;
2463
+ };
2464
+ Factory.addOverloadedGetterSetter(constructor, attr);
2488
2465
  },
2489
- _endDragAfter(evt) {
2490
- DD._dragElements.forEach((elem, key) => {
2491
- if (elem.dragStatus === 'stopped') {
2492
- elem.node.fire('dragend', {
2493
- type: 'dragend',
2494
- target: elem.node,
2495
- evt: evt,
2496
- }, true);
2466
+ addOverloadedGetterSetter(constructor, attr) {
2467
+ const capitalizedAttr = Util._capitalize(attr), setter = SET$1 + capitalizedAttr, getter = GET + capitalizedAttr;
2468
+ constructor.prototype[attr] = function () {
2469
+ // setting
2470
+ if (arguments.length) {
2471
+ this[setter](arguments[0]);
2472
+ return this;
2497
2473
  }
2498
- if (elem.dragStatus !== 'dragging') {
2499
- DD._dragElements.delete(key);
2474
+ // getting
2475
+ return this[getter]();
2476
+ };
2477
+ },
2478
+ addDeprecatedGetterSetter(constructor, attr, def, validator) {
2479
+ Util.error('Adding deprecated ' + attr);
2480
+ const method = GET + Util._capitalize(attr);
2481
+ const message = attr +
2482
+ ' property is deprecated and will be removed soon. Look at Konva change log for more information.';
2483
+ constructor.prototype[method] = function () {
2484
+ Util.error(message);
2485
+ const val = this.attrs[attr];
2486
+ return val === undefined ? def : val;
2487
+ };
2488
+ Factory.addSetter(constructor, attr, validator, function () {
2489
+ Util.error(message);
2490
+ });
2491
+ Factory.addOverloadedGetterSetter(constructor, attr);
2492
+ },
2493
+ backCompat(constructor, methods) {
2494
+ Util.each(methods, function (oldMethodName, newMethodName) {
2495
+ const method = constructor.prototype[newMethodName];
2496
+ const oldGetter = GET + Util._capitalize(oldMethodName);
2497
+ const oldSetter = SET$1 + Util._capitalize(oldMethodName);
2498
+ function deprecated() {
2499
+ method.apply(this, arguments);
2500
+ Util.error('"' +
2501
+ oldMethodName +
2502
+ '" method is deprecated and will be removed soon. Use ""' +
2503
+ newMethodName +
2504
+ '" instead.');
2500
2505
  }
2506
+ constructor.prototype[oldMethodName] = deprecated;
2507
+ constructor.prototype[oldGetter] = deprecated;
2508
+ constructor.prototype[oldSetter] = deprecated;
2501
2509
  });
2502
2510
  },
2511
+ afterSetFilter() {
2512
+ this._filterUpToDate = false;
2513
+ },
2503
2514
  };
2504
- if (Konva$2.isBrowser) {
2505
- window.addEventListener('mouseup', DD._endDragBefore, true);
2506
- window.addEventListener('touchend', DD._endDragBefore, true);
2507
- // add touchcancel to fix this: https://github.com/konvajs/konva/issues/1843
2508
- window.addEventListener('touchcancel', DD._endDragBefore, true);
2509
- window.addEventListener('mousemove', DD._drag);
2510
- window.addEventListener('touchmove', DD._drag);
2511
- window.addEventListener('mouseup', DD._endDragAfter, false);
2512
- window.addEventListener('touchend', DD._endDragAfter, false);
2513
- window.addEventListener('touchcancel', DD._endDragAfter, false);
2514
- }
2515
2515
 
2516
2516
  // CONSTANTS
2517
- const ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER$1 = 'mouseenter', MOUSELEAVE$1 = 'mouseleave', SET = 'set', SHAPE = 'Shape', SPACE$1 = ' ', STAGE$1 = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR$1 = [
2517
+ const ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER$1 = 'mouseenter', MOUSELEAVE$1 = 'mouseleave', POINTERENTER$1 = 'pointerenter', POINTERLEAVE$1 = 'pointerleave', TOUCHENTER = 'touchenter', TOUCHLEAVE = 'touchleave', SET = 'set', SHAPE = 'Shape', SPACE$1 = ' ', STAGE$1 = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR$1 = [
2518
2518
  'xChange.konva',
2519
2519
  'yChange.konva',
2520
2520
  'scaleXChange.konva',
@@ -2646,8 +2646,8 @@
2646
2646
  */
2647
2647
  clearCache() {
2648
2648
  if (this._cache.has(CANVAS)) {
2649
- const { scene, filter, hit } = this._cache.get(CANVAS);
2650
- Util.releaseCanvas(scene, filter, hit);
2649
+ const { scene, filter, hit, buffer } = this._cache.get(CANVAS);
2650
+ Util.releaseCanvas(scene, filter, hit, buffer);
2651
2651
  this._cache.delete(CANVAS);
2652
2652
  }
2653
2653
  this._clearSelfAndDescendantCache();
@@ -2749,6 +2749,14 @@
2749
2749
  width: width,
2750
2750
  height: height,
2751
2751
  }), sceneContext = cachedSceneCanvas.getContext(), hitContext = cachedHitCanvas.getContext();
2752
+ const bufferCanvas = new SceneCanvas({
2753
+ // width and height already multiplied by pixelRatio
2754
+ // so we need to revert that
2755
+ // also increase size by x nd y offset to make sure content fits canvas
2756
+ width: cachedSceneCanvas.width / cachedSceneCanvas.pixelRatio + Math.abs(x),
2757
+ height: cachedSceneCanvas.height / cachedSceneCanvas.pixelRatio + Math.abs(y),
2758
+ pixelRatio: cachedSceneCanvas.pixelRatio,
2759
+ }), bufferContext = bufferCanvas.getContext();
2752
2760
  cachedHitCanvas.isCache = true;
2753
2761
  cachedSceneCanvas.isCache = true;
2754
2762
  this._cache.delete(CANVAS);
@@ -2759,13 +2767,20 @@
2759
2767
  }
2760
2768
  sceneContext.save();
2761
2769
  hitContext.save();
2770
+ bufferContext.save();
2762
2771
  sceneContext.translate(-x, -y);
2763
2772
  hitContext.translate(-x, -y);
2773
+ bufferContext.translate(-x, -y);
2774
+ // hard-code offset to make sure content fits canvas
2775
+ // @ts-ignore
2776
+ bufferCanvas.x = x;
2777
+ // @ts-ignore
2778
+ bufferCanvas.y = y;
2764
2779
  // extra flag to skip on getAbsolute opacity calc
2765
2780
  this._isUnderCache = true;
2766
2781
  this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);
2767
2782
  this._clearSelfAndDescendantCache(ABSOLUTE_SCALE);
2768
- this.drawScene(cachedSceneCanvas, this);
2783
+ this.drawScene(cachedSceneCanvas, this, bufferCanvas);
2769
2784
  this.drawHit(cachedHitCanvas, this);
2770
2785
  this._isUnderCache = false;
2771
2786
  sceneContext.restore();
@@ -2786,6 +2801,7 @@
2786
2801
  scene: cachedSceneCanvas,
2787
2802
  filter: cachedFilterCanvas,
2788
2803
  hit: cachedHitCanvas,
2804
+ buffer: bufferCanvas,
2789
2805
  x: x,
2790
2806
  y: y,
2791
2807
  });
@@ -2985,29 +3001,28 @@
2985
3001
  * });
2986
3002
  */
2987
3003
  on(evtStr, handler) {
2988
- this._cache && this._cache.delete(ALL_LISTENERS);
3004
+ if (this._cache) {
3005
+ this._cache.delete(ALL_LISTENERS);
3006
+ }
2989
3007
  if (arguments.length === 3) {
2990
3008
  return this._delegate.apply(this, arguments);
2991
3009
  }
2992
- let events = evtStr.split(SPACE$1), len = events.length, n, event, parts, baseEvent, name;
3010
+ const events = evtStr.split(SPACE$1);
2993
3011
  /*
2994
3012
  * loop through types and attach event listeners to
2995
3013
  * each one. eg. 'click mouseover.namespace mouseout'
2996
3014
  * will create three event bindings
2997
3015
  */
2998
- for (n = 0; n < len; n++) {
2999
- event = events[n];
3000
- parts = event.split('.');
3001
- baseEvent = parts[0];
3002
- name = parts[1] || '';
3016
+ for (let n = 0; n < events.length; n++) {
3017
+ const event = events[n];
3018
+ const parts = event.split('.');
3019
+ const baseEvent = parts[0];
3020
+ const name = parts[1] || '';
3003
3021
  // create events array if it doesn't exist
3004
3022
  if (!this.eventListeners[baseEvent]) {
3005
3023
  this.eventListeners[baseEvent] = [];
3006
3024
  }
3007
- this.eventListeners[baseEvent].push({
3008
- name: name,
3009
- handler: handler,
3010
- });
3025
+ this.eventListeners[baseEvent].push({ name, handler });
3011
3026
  }
3012
3027
  return this;
3013
3028
  }
@@ -4029,7 +4044,7 @@
4029
4044
  // I was trying to use attributes directly here
4030
4045
  // but it doesn't work for Transformer well
4031
4046
  // because it overwrite x,y getters
4032
- const x = this.x(), y = this.y(), rotation = Konva$2.getAngle(this.rotation()), scaleX = (_a = this.attrs.scaleX) !== null && _a !== undefined ? _a : 1, scaleY = (_b = this.attrs.scaleY) !== null && _b !== undefined ? _b : 1, skewX = this.attrs.skewX || 0, skewY = this.attrs.skewY || 0, offsetX = this.attrs.offsetX || 0, offsetY = this.attrs.offsetY || 0;
4047
+ const x = this.x(), y = this.y(), rotation = Konva$2.getAngle(this.rotation()), scaleX = (_a = this.attrs.scaleX) !== null && _a !== void 0 ? _a : 1, scaleY = (_b = this.attrs.scaleY) !== null && _b !== void 0 ? _b : 1, skewX = this.attrs.skewX || 0, skewY = this.attrs.skewY || 0, offsetX = this.attrs.offsetX || 0, offsetY = this.attrs.offsetY || 0;
4033
4048
  if (x !== 0 || y !== 0) {
4034
4049
  m.translate(x, y);
4035
4050
  }
@@ -4416,7 +4431,7 @@
4416
4431
  _requestDraw() {
4417
4432
  if (Konva$2.autoDrawEnabled) {
4418
4433
  const drawNode = this.getLayer() || this.getStage();
4419
- drawNode === null || drawNode === undefined ? undefined : drawNode.batchDraw();
4434
+ drawNode === null || drawNode === void 0 ? void 0 : drawNode.batchDraw();
4420
4435
  }
4421
4436
  }
4422
4437
  _setAttr(key, val) {
@@ -4451,7 +4466,15 @@
4451
4466
  if (evt && this.nodeType === SHAPE) {
4452
4467
  evt.target = this;
4453
4468
  }
4454
- const shouldStop = (eventType === MOUSEENTER$1 || eventType === MOUSELEAVE$1) &&
4469
+ const nonBubbling = [
4470
+ MOUSEENTER$1,
4471
+ MOUSELEAVE$1,
4472
+ POINTERENTER$1,
4473
+ POINTERLEAVE$1,
4474
+ TOUCHENTER,
4475
+ TOUCHLEAVE,
4476
+ ];
4477
+ const shouldStop = nonBubbling.indexOf(eventType) !== -1 &&
4455
4478
  ((compareShape &&
4456
4479
  (this === compareShape ||
4457
4480
  (this.isAncestorOf && this.isAncestorOf(compareShape)))) ||
@@ -4459,7 +4482,7 @@
4459
4482
  if (!shouldStop) {
4460
4483
  this._fire(eventType, evt);
4461
4484
  // simulate event bubbling
4462
- const stopBubble = (eventType === MOUSEENTER$1 || eventType === MOUSELEAVE$1) &&
4485
+ const stopBubble = nonBubbling.indexOf(eventType) !== -1 &&
4463
4486
  compareShape &&
4464
4487
  compareShape.isAncestorOf &&
4465
4488
  compareShape.isAncestorOf(this) &&
@@ -4479,14 +4502,14 @@
4479
4502
  }
4480
4503
  _getProtoListeners(eventType) {
4481
4504
  var _a, _b, _c;
4482
- const allListeners = (_a = this._cache.get(ALL_LISTENERS)) !== null && _a !== undefined ? _a : {};
4483
- let events = allListeners === null || allListeners === undefined ? undefined : allListeners[eventType];
4505
+ const allListeners = (_a = this._cache.get(ALL_LISTENERS)) !== null && _a !== void 0 ? _a : {};
4506
+ let events = allListeners === null || allListeners === void 0 ? void 0 : allListeners[eventType];
4484
4507
  if (events === undefined) {
4485
4508
  //recalculate cache
4486
4509
  events = [];
4487
4510
  let obj = Object.getPrototypeOf(this);
4488
4511
  while (obj) {
4489
- const hierarchyEvents = (_c = (_b = obj.eventListeners) === null || _b === undefined ? undefined : _b[eventType]) !== null && _c !== undefined ? _c : [];
4512
+ const hierarchyEvents = (_c = (_b = obj.eventListeners) === null || _b === void 0 ? void 0 : _b[eventType]) !== null && _c !== void 0 ? _c : [];
4490
4513
  events.push(...hierarchyEvents);
4491
4514
  obj = Object.getPrototypeOf(obj);
4492
4515
  }
@@ -4502,7 +4525,7 @@
4502
4525
  evt.type = eventType;
4503
4526
  const topListeners = this._getProtoListeners(eventType);
4504
4527
  if (topListeners) {
4505
- for (var i = 0; i < topListeners.length; i++) {
4528
+ for (let i = 0; i < topListeners.length; i++) {
4506
4529
  topListeners[i].handler.call(this, evt);
4507
4530
  }
4508
4531
  }
@@ -4510,7 +4533,7 @@
4510
4533
  // because events can be added/removed while firing
4511
4534
  const selfListeners = this.eventListeners[eventType];
4512
4535
  if (selfListeners) {
4513
- for (var i = 0; i < selfListeners.length; i++) {
4536
+ for (let i = 0; i < selfListeners.length; i++) {
4514
4537
  selfListeners[i].handler.call(this, evt);
4515
4538
  }
4516
4539
  }
@@ -5331,17 +5354,11 @@
5331
5354
  * });
5332
5355
  */
5333
5356
  getChildren(filterFunc) {
5334
- if (!filterFunc) {
5335
- return this.children || [];
5336
- }
5337
5357
  const children = this.children || [];
5338
- const results = [];
5339
- children.forEach(function (child) {
5340
- if (filterFunc(child)) {
5341
- results.push(child);
5342
- }
5343
- });
5344
- return results;
5358
+ if (filterFunc) {
5359
+ return children.filter(filterFunc);
5360
+ }
5361
+ return children;
5345
5362
  }
5346
5363
  /**
5347
5364
  * determine if node has children
@@ -5398,8 +5415,6 @@
5398
5415
  * layer.add(shape1, shape2, shape3);
5399
5416
  * // empty arrays are accepted, though each individual child must be defined
5400
5417
  * layer.add(...shapes);
5401
- * // remember to redraw layer if you changed something
5402
- * layer.draw();
5403
5418
  */
5404
5419
  add(...children) {
5405
5420
  if (children.length === 0) {
@@ -5598,13 +5613,13 @@
5598
5613
  if (this.isCached()) {
5599
5614
  return;
5600
5615
  }
5601
- (_a = this.children) === null || _a === undefined ? undefined : _a.forEach(function (node) {
5616
+ (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (node) {
5602
5617
  node._clearSelfAndDescendantCache(attr);
5603
5618
  });
5604
5619
  }
5605
5620
  _setChildrenIndices() {
5606
5621
  var _a;
5607
- (_a = this.children) === null || _a === undefined ? undefined : _a.forEach(function (child, n) {
5622
+ (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child, n) {
5608
5623
  child.index = n;
5609
5624
  });
5610
5625
  this._requestDraw();
@@ -5675,7 +5690,7 @@
5675
5690
  context.save();
5676
5691
  context._applyGlobalCompositeOperation(this);
5677
5692
  }
5678
- (_a = this.children) === null || _a === undefined ? undefined : _a.forEach(function (child) {
5693
+ (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
5679
5694
  child[drawMethod](canvas, top, bufferCanvas);
5680
5695
  });
5681
5696
  if (hasComposition) {
@@ -5697,7 +5712,7 @@
5697
5712
  height: 0,
5698
5713
  };
5699
5714
  const that = this;
5700
- (_a = this.children) === null || _a === undefined ? undefined : _a.forEach(function (child) {
5715
+ (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
5701
5716
  // skip invisible children
5702
5717
  if (!child.visible()) {
5703
5718
  return;
@@ -5920,6 +5935,7 @@
5920
5935
  [POINTERMOVE, '_pointermove'],
5921
5936
  [POINTERUP, '_pointerup'],
5922
5937
  [POINTERCANCEL, '_pointercancel'],
5938
+ [POINTERLEAVE, '_pointerleave'],
5923
5939
  [LOSTPOINTERCAPTURE, '_lostpointercapture'],
5924
5940
  ];
5925
5941
  const EVENTS_MAP = {
@@ -6061,12 +6077,12 @@
6061
6077
  */
6062
6078
  setContainer(container) {
6063
6079
  if (typeof container === STRING) {
6080
+ let id;
6064
6081
  if (container.charAt(0) === '.') {
6065
6082
  const className = container.slice(1);
6066
6083
  container = document.getElementsByClassName(className)[0];
6067
6084
  }
6068
6085
  else {
6069
- var id;
6070
6086
  if (container.charAt(0) !== '#') {
6071
6087
  id = container;
6072
6088
  }
@@ -6900,10 +6916,16 @@
6900
6916
  this.colorKey = key;
6901
6917
  shapes[key] = this;
6902
6918
  }
6919
+ /**
6920
+ * @deprecated
6921
+ */
6903
6922
  getContext() {
6904
6923
  Util.warn('shape.getContext() method is deprecated. Please do not use it.');
6905
6924
  return this.getLayer().getContext();
6906
6925
  }
6926
+ /**
6927
+ * @deprecated
6928
+ */
6907
6929
  getCanvas() {
6908
6930
  Util.warn('shape.getCanvas() method is deprecated. Please do not use it.');
6909
6931
  return this.getLayer().getCanvas();
@@ -7109,7 +7131,7 @@
7109
7131
  // it probably will be simpler, then copy/paste the code
7110
7132
  var _a;
7111
7133
  // force skip buffer canvas
7112
- const perfectDrawEnabled = (_a = this.attrs.perfectDrawEnabled) !== null && _a !== undefined ? _a : true;
7134
+ const perfectDrawEnabled = (_a = this.attrs.perfectDrawEnabled) !== null && _a !== void 0 ? _a : true;
7113
7135
  if (!perfectDrawEnabled) {
7114
7136
  return false;
7115
7137
  }
@@ -7213,8 +7235,8 @@
7213
7235
  // 2 - when we are caching current
7214
7236
  // 3 - when node is cached and we need to draw it into layer
7215
7237
  const layer = this.getLayer();
7216
- let canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferContext;
7217
- const skipBuffer = canvas.isCache;
7238
+ const canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow();
7239
+ let stage;
7218
7240
  const cachingSelf = top === this;
7219
7241
  if (!this.isVisible() && !cachingSelf) {
7220
7242
  return this;
@@ -7233,15 +7255,15 @@
7233
7255
  }
7234
7256
  context.save();
7235
7257
  // if buffer canvas is needed
7236
- if (this._useBufferCanvas() && !skipBuffer) {
7258
+ if (this._useBufferCanvas() && true) {
7237
7259
  stage = this.getStage();
7238
7260
  const bc = bufferCanvas || stage.bufferCanvas;
7239
- bufferContext = bc.getContext();
7261
+ const bufferContext = bc.getContext();
7240
7262
  bufferContext.clear();
7241
7263
  bufferContext.save();
7242
7264
  bufferContext._applyLineJoin(this);
7243
7265
  // layer might be undefined if we are using cache before adding to layer
7244
- var o = this.getAbsoluteTransform(top).getMatrix();
7266
+ const o = this.getAbsoluteTransform(top).getMatrix();
7245
7267
  bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
7246
7268
  drawFunc.call(this, bufferContext, this);
7247
7269
  bufferContext.restore();
@@ -7251,12 +7273,12 @@
7251
7273
  }
7252
7274
  context._applyOpacity(this);
7253
7275
  context._applyGlobalCompositeOperation(this);
7254
- context.drawImage(bc._canvas, 0, 0, bc.width / ratio, bc.height / ratio);
7276
+ context.drawImage(bc._canvas, bc.x || 0, bc.y || 0, bc.width / ratio, bc.height / ratio);
7255
7277
  }
7256
7278
  else {
7257
7279
  context._applyLineJoin(this);
7258
7280
  if (!cachingSelf) {
7259
- var o = this.getAbsoluteTransform(top).getMatrix();
7281
+ const o = this.getAbsoluteTransform(top).getMatrix();
7260
7282
  context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
7261
7283
  context._applyOpacity(this);
7262
7284
  context._applyGlobalCompositeOperation(this);
@@ -8734,7 +8756,7 @@
8734
8756
  // empty pixel
8735
8757
  return {};
8736
8758
  }
8737
- drawScene(can, top) {
8759
+ drawScene(can, top, bufferCanvas) {
8738
8760
  const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas());
8739
8761
  this._fire(BEFORE_DRAW, {
8740
8762
  node: this,
@@ -8742,7 +8764,7 @@
8742
8764
  if (this.clearBeforeDraw()) {
8743
8765
  canvas.getContext().clear();
8744
8766
  }
8745
- Container.prototype.drawScene.call(this, canvas, top);
8767
+ Container.prototype.drawScene.call(this, canvas, top, bufferCanvas);
8746
8768
  this._fire(DRAW, {
8747
8769
  node: this,
8748
8770
  });
@@ -9589,10 +9611,25 @@
9589
9611
  destroy() {
9590
9612
  const nodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId];
9591
9613
  this.pause();
9614
+ // Clean up animation
9615
+ if (this.anim) {
9616
+ this.anim.stop();
9617
+ }
9618
+ // Clean up tween entries
9592
9619
  for (const key in attrs) {
9593
9620
  delete Tween.tweens[nodeId][key];
9594
9621
  }
9622
+ // Clean up attrs entry
9595
9623
  delete Tween.attrs[nodeId][thisId];
9624
+ // Clean up parent objects if empty
9625
+ if (Tween.tweens[nodeId]) {
9626
+ if (Object.keys(Tween.tweens[nodeId]).length === 0) {
9627
+ delete Tween.tweens[nodeId];
9628
+ }
9629
+ if (Object.keys(Tween.attrs[nodeId]).length === 0) {
9630
+ delete Tween.attrs[nodeId];
9631
+ }
9632
+ }
9596
9633
  }
9597
9634
  }
9598
9635
  Tween.attrs = {};
@@ -10212,16 +10249,17 @@
10212
10249
  });
10213
10250
  }
10214
10251
  _sceneFunc(context) {
10215
- let points = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier(), tp, len, n;
10252
+ const points = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier();
10216
10253
  if (!length) {
10217
10254
  return;
10218
10255
  }
10256
+ let n = 0;
10219
10257
  context.beginPath();
10220
10258
  context.moveTo(points[0], points[1]);
10221
10259
  // tension
10222
10260
  if (tension !== 0 && length > 4) {
10223
- tp = this.getTensionPoints();
10224
- len = tp.length;
10261
+ const tp = this.getTensionPoints();
10262
+ const len = tp.length;
10225
10263
  n = closed ? 0 : 4;
10226
10264
  if (!closed) {
10227
10265
  context.quadraticCurveTo(tp[0], tp[1], tp[2], tp[3]);
@@ -11328,10 +11366,10 @@
11328
11366
  context.quadraticCurveTo(p[0], p[1], p[2], p[3]);
11329
11367
  break;
11330
11368
  case 'A':
11331
- var cx = p[0], cy = p[1], rx = p[2], ry = p[3], theta = p[4], dTheta = p[5], psi = p[6], fs = p[7];
11332
- var r = rx > ry ? rx : ry;
11333
- var scaleX = rx > ry ? 1 : rx / ry;
11334
- var scaleY = rx > ry ? ry / rx : 1;
11369
+ const cx = p[0], cy = p[1], rx = p[2], ry = p[3], theta = p[4], dTheta = p[5], psi = p[6], fs = p[7];
11370
+ const r = rx > ry ? rx : ry;
11371
+ const scaleX = rx > ry ? 1 : rx / ry;
11372
+ const scaleY = rx > ry ? ry / rx : 1;
11335
11373
  context.translate(cx, cy);
11336
11374
  context.rotate(psi);
11337
11375
  context.scale(scaleX, scaleY);
@@ -11470,11 +11508,20 @@
11470
11508
  };
11471
11509
  }
11472
11510
  if (length < 0.01) {
11473
- points = dataArray[i].points.slice(0, 2);
11474
- return {
11475
- x: points[0],
11476
- y: points[1],
11477
- };
11511
+ const cmd = dataArray[i].command;
11512
+ if (cmd === 'M') {
11513
+ points = dataArray[i].points.slice(0, 2);
11514
+ return {
11515
+ x: points[0],
11516
+ y: points[1],
11517
+ };
11518
+ }
11519
+ else {
11520
+ return {
11521
+ x: dataArray[i].start.x,
11522
+ y: dataArray[i].start.y,
11523
+ };
11524
+ }
11478
11525
  }
11479
11526
  const cp = dataArray[i];
11480
11527
  const p = cp.points;
@@ -11490,15 +11537,16 @@
11490
11537
  return getQuadraticArcLength([cp.start.x, p[0], p[2]], [cp.start.y, p[1], p[3]], i);
11491
11538
  }), cp.start.x, cp.start.y, p[0], p[1], p[2], p[3]);
11492
11539
  case 'A':
11493
- var cx = p[0], cy = p[1], rx = p[2], ry = p[3], theta = p[4], dTheta = p[5], psi = p[6];
11540
+ const cx = p[0], cy = p[1], rx = p[2], ry = p[3], dTheta = p[5], psi = p[6];
11541
+ let theta = p[4];
11494
11542
  theta += (dTheta * length) / cp.pathLength;
11495
11543
  return Path.getPointOnEllipticalArc(cx, cy, rx, ry, theta, psi);
11496
11544
  }
11497
11545
  return null;
11498
11546
  }
11499
11547
  static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX, fromY) {
11500
- fromX = fromX !== null && fromX !== undefined ? fromX : P1x;
11501
- fromY = fromY !== null && fromY !== undefined ? fromY : P1y;
11548
+ fromX = fromX !== null && fromX !== void 0 ? fromX : P1x;
11549
+ fromY = fromY !== null && fromY !== void 0 ? fromY : P1y;
11502
11550
  const len = this.getLineLength(P1x, P1y, P2x, P2y);
11503
11551
  if (len < 1e-10) {
11504
11552
  return { x: P1x, y: P1y };
@@ -11537,10 +11585,7 @@
11537
11585
  }
11538
11586
  const x = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct);
11539
11587
  const y = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct);
11540
- return {
11541
- x: x,
11542
- y: y,
11543
- };
11588
+ return { x, y };
11544
11589
  }
11545
11590
  static getPointOnQuadraticBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y) {
11546
11591
  function QB1(t) {
@@ -11554,10 +11599,7 @@
11554
11599
  }
11555
11600
  const x = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct);
11556
11601
  const y = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct);
11557
- return {
11558
- x: x,
11559
- y: y,
11560
- };
11602
+ return { x, y };
11561
11603
  }
11562
11604
  static getPointOnEllipticalArc(cx, cy, rx, ry, theta, psi) {
11563
11605
  const cosPsi = Math.cos(psi), sinPsi = Math.sin(psi);
@@ -11630,7 +11672,7 @@
11630
11672
  // convert white spaces to commas
11631
11673
  cs = cs.replace(new RegExp(' ', 'g'), ',');
11632
11674
  // create pipes so that we can split the data
11633
- for (var n = 0; n < cc.length; n++) {
11675
+ for (let n = 0; n < cc.length; n++) {
11634
11676
  cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
11635
11677
  }
11636
11678
  // create array
@@ -11642,7 +11684,7 @@
11642
11684
  let cpy = 0;
11643
11685
  const re = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;
11644
11686
  let match;
11645
- for (n = 1; n < arr.length; n++) {
11687
+ for (let n = 1; n < arr.length; n++) {
11646
11688
  let str = arr[n];
11647
11689
  let c = str.charAt(0);
11648
11690
  str = str.slice(1);
@@ -11677,8 +11719,8 @@
11677
11719
  let points = [];
11678
11720
  const startX = cpx, startY = cpy;
11679
11721
  // Move var from within the switch to up here (jshint)
11680
- var prevCmd, ctlPtx, ctlPty; // Ss, Tt
11681
- var rx, ry, psi, fa, fs, x1, y1; // Aa
11722
+ let prevCmd, ctlPtx, ctlPty; // Ss, Tt
11723
+ let rx, ry, psi, fa, fs, x1, y1; // Aa
11682
11724
  // convert l, H, h, V, and v to L
11683
11725
  switch (c) {
11684
11726
  // Note: Keep the lineTo's above the moveTo's in this switch
@@ -11695,8 +11737,8 @@
11695
11737
  break;
11696
11738
  // Note: lineTo handlers need to be above this point
11697
11739
  case 'm':
11698
- var dx = p.shift();
11699
- var dy = p.shift();
11740
+ const dx = p.shift();
11741
+ const dy = p.shift();
11700
11742
  cpx += dx;
11701
11743
  cpy += dy;
11702
11744
  cmd = 'M';
@@ -11884,12 +11926,12 @@
11884
11926
  case 'A':
11885
11927
  // Approximates by breaking curve into line segments
11886
11928
  len = 0.0;
11887
- var start = points[4];
11929
+ const start = points[4];
11888
11930
  // 4 = theta
11889
- var dTheta = points[5];
11931
+ const dTheta = points[5];
11890
11932
  // 5 = dTheta
11891
- var end = points[4] + dTheta;
11892
- var inc = Math.PI / 180.0;
11933
+ const end = points[4] + dTheta;
11934
+ let inc = Math.PI / 180.0;
11893
11935
  // 1 degree resolution
11894
11936
  if (Math.abs(start - end) < inc) {
11895
11937
  inc = Math.abs(start - end);
@@ -12737,11 +12779,11 @@
12737
12779
  }
12738
12780
  getWidth() {
12739
12781
  var _a, _b;
12740
- return (_a = this.attrs.width) !== null && _a !== undefined ? _a : (_b = this.image()) === null || _b === undefined ? undefined : _b.width;
12782
+ return (_a = this.attrs.width) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.width;
12741
12783
  }
12742
12784
  getHeight() {
12743
12785
  var _a, _b;
12744
- return (_a = this.attrs.height) !== null && _a !== undefined ? _a : (_b = this.image()) === null || _b === undefined ? undefined : _b.height;
12786
+ return (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height;
12745
12787
  }
12746
12788
  /**
12747
12789
  * load image from given url and create `Konva.Image` instance
@@ -12754,7 +12796,6 @@
12754
12796
  * Konva.Image.fromURL(imageURL, function(image){
12755
12797
  * // image is Konva.Image instance
12756
12798
  * layer.add(image);
12757
- * layer.draw();
12758
12799
  * });
12759
12800
  */
12760
12801
  static fromURL(url, callback, onError = null) {
@@ -14279,7 +14320,7 @@
14279
14320
  * @param {String} [config.fontVariant] can be normal or small-caps. Default is normal
14280
14321
  * @param {String} [config.textDecoration] can be line-through, underline or empty string. Default is empty string.
14281
14322
  * @param {String} config.text
14282
- * @param {String} [config.align] can be left, center, or right
14323
+ * @param {String} [config.align] can be left, center, right or justify
14283
14324
  * @param {String} [config.verticalAlign] can be top, middle or bottom
14284
14325
  * @param {Number} [config.padding]
14285
14326
  * @param {Number} [config.lineHeight] default is 1
@@ -14396,8 +14437,6 @@
14396
14437
  (metrics.fontBoundingBoxAscent - metrics.fontBoundingBoxDescent) / 2 +
14397
14438
  lineHeightPx / 2;
14398
14439
  }
14399
- var lineTranslateX = 0;
14400
- var lineTranslateY = 0;
14401
14440
  if (direction === RTL) {
14402
14441
  context.setAttr('direction', direction);
14403
14442
  }
@@ -14414,9 +14453,9 @@
14414
14453
  context.translate(padding, alignY + padding);
14415
14454
  // draw text lines
14416
14455
  for (n = 0; n < textArrLen; n++) {
14417
- var lineTranslateX = 0;
14418
- var lineTranslateY = 0;
14419
- var obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph, spacesNumber, lineWidth;
14456
+ let lineTranslateX = 0;
14457
+ let lineTranslateY = 0;
14458
+ const obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph;
14420
14459
  // horizontal alignment
14421
14460
  context.save();
14422
14461
  if (align === RIGHT) {
@@ -14434,9 +14473,7 @@
14434
14473
  const x = lineTranslateX;
14435
14474
  const y = translateY + lineTranslateY + yOffset;
14436
14475
  context.moveTo(x, y);
14437
- spacesNumber = text.split(' ').length - 1;
14438
- lineWidth =
14439
- align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
14476
+ const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
14440
14477
  context.lineTo(x + Math.round(lineWidth), y);
14441
14478
  // I have no idea what is real ratio
14442
14479
  // just /15 looks good enough
@@ -14451,9 +14488,7 @@
14451
14488
  context.beginPath();
14452
14489
  const yOffset = Konva$2._fixTextRendering ? -Math.round(fontSize / 4) : 0;
14453
14490
  context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset);
14454
- spacesNumber = text.split(' ').length - 1;
14455
- lineWidth =
14456
- align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
14491
+ const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
14457
14492
  context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
14458
14493
  context.lineWidth = fontSize / 15;
14459
14494
  const gradient = this._getLinearGradient();
@@ -14466,7 +14501,7 @@
14466
14501
  // be supported otherwise.
14467
14502
  if (direction !== RTL && (letterSpacing !== 0 || align === JUSTIFY)) {
14468
14503
  // var words = text.split(' ');
14469
- spacesNumber = text.split(' ').length - 1;
14504
+ const spacesNumber = text.split(' ').length - 1;
14470
14505
  const array = stringToArray(text);
14471
14506
  for (let li = 0; li < array.length; li++) {
14472
14507
  const letter = array[li];
@@ -14559,17 +14594,17 @@
14559
14594
  const scaleFactor = fontSize / 100;
14560
14595
  // Note, fallback values are from chrome browser with 100px font size and font-family "Arial"
14561
14596
  return {
14562
- actualBoundingBoxAscent: (_a = metrics.actualBoundingBoxAscent) !== null && _a !== undefined ? _a : 71.58203125 * scaleFactor,
14563
- actualBoundingBoxDescent: (_b = metrics.actualBoundingBoxDescent) !== null && _b !== undefined ? _b : 0, // Remains zero as there is no descent in the provided metrics
14564
- actualBoundingBoxLeft: (_c = metrics.actualBoundingBoxLeft) !== null && _c !== undefined ? _c : -7.421875 * scaleFactor,
14565
- actualBoundingBoxRight: (_d = metrics.actualBoundingBoxRight) !== null && _d !== undefined ? _d : 75.732421875 * scaleFactor,
14566
- alphabeticBaseline: (_e = metrics.alphabeticBaseline) !== null && _e !== undefined ? _e : 0, // Remains zero as it's typically relative to the baseline itself
14567
- emHeightAscent: (_f = metrics.emHeightAscent) !== null && _f !== undefined ? _f : 100 * scaleFactor,
14568
- emHeightDescent: (_g = metrics.emHeightDescent) !== null && _g !== undefined ? _g : -20 * scaleFactor,
14569
- fontBoundingBoxAscent: (_h = metrics.fontBoundingBoxAscent) !== null && _h !== undefined ? _h : 91 * scaleFactor,
14570
- fontBoundingBoxDescent: (_j = metrics.fontBoundingBoxDescent) !== null && _j !== undefined ? _j : 21 * scaleFactor,
14571
- hangingBaseline: (_k = metrics.hangingBaseline) !== null && _k !== undefined ? _k : 72.80000305175781 * scaleFactor,
14572
- ideographicBaseline: (_l = metrics.ideographicBaseline) !== null && _l !== undefined ? _l : -21 * scaleFactor,
14597
+ actualBoundingBoxAscent: (_a = metrics.actualBoundingBoxAscent) !== null && _a !== void 0 ? _a : 71.58203125 * scaleFactor,
14598
+ actualBoundingBoxDescent: (_b = metrics.actualBoundingBoxDescent) !== null && _b !== void 0 ? _b : 0, // Remains zero as there is no descent in the provided metrics
14599
+ actualBoundingBoxLeft: (_c = metrics.actualBoundingBoxLeft) !== null && _c !== void 0 ? _c : -7.421875 * scaleFactor,
14600
+ actualBoundingBoxRight: (_d = metrics.actualBoundingBoxRight) !== null && _d !== void 0 ? _d : 75.732421875 * scaleFactor,
14601
+ alphabeticBaseline: (_e = metrics.alphabeticBaseline) !== null && _e !== void 0 ? _e : 0, // Remains zero as it's typically relative to the baseline itself
14602
+ emHeightAscent: (_f = metrics.emHeightAscent) !== null && _f !== void 0 ? _f : 100 * scaleFactor,
14603
+ emHeightDescent: (_g = metrics.emHeightDescent) !== null && _g !== void 0 ? _g : -20 * scaleFactor,
14604
+ fontBoundingBoxAscent: (_h = metrics.fontBoundingBoxAscent) !== null && _h !== void 0 ? _h : 91 * scaleFactor,
14605
+ fontBoundingBoxDescent: (_j = metrics.fontBoundingBoxDescent) !== null && _j !== void 0 ? _j : 21 * scaleFactor,
14606
+ hangingBaseline: (_k = metrics.hangingBaseline) !== null && _k !== void 0 ? _k : 72.80000305175781 * scaleFactor,
14607
+ ideographicBaseline: (_l = metrics.ideographicBaseline) !== null && _l !== void 0 ? _l : -21 * scaleFactor,
14573
14608
  width: metrics.width,
14574
14609
  height: fontSize, // Typically set to the font size
14575
14610
  };
@@ -14923,6 +14958,8 @@
14923
14958
  *
14924
14959
  * // align text to right
14925
14960
  * text.align('right');
14961
+ *
14962
+ * // justify text
14926
14963
  */
14927
14964
  Factory.addGetterSetter(Text, 'align', LEFT);
14928
14965
  /**
@@ -16178,10 +16215,10 @@
16178
16215
  else {
16179
16216
  keepProportion = this.keepRatio() || e.shiftKey;
16180
16217
  }
16181
- var centeredScaling = this.centeredScaling() || e.altKey;
16218
+ let centeredScaling = this.centeredScaling() || e.altKey;
16182
16219
  if (this._movingAnchorName === 'top-left') {
16183
16220
  if (keepProportion) {
16184
- var comparePoint = centeredScaling
16221
+ const comparePoint = centeredScaling
16185
16222
  ? {
16186
16223
  x: this.width() / 2,
16187
16224
  y: this.height() / 2,
@@ -16192,8 +16229,8 @@
16192
16229
  };
16193
16230
  newHypotenuse = Math.sqrt(Math.pow(comparePoint.x - anchorNode.x(), 2) +
16194
16231
  Math.pow(comparePoint.y - anchorNode.y(), 2));
16195
- var reverseX = this.findOne('.top-left').x() > comparePoint.x ? -1 : 1;
16196
- var reverseY = this.findOne('.top-left').y() > comparePoint.y ? -1 : 1;
16232
+ const reverseX = this.findOne('.top-left').x() > comparePoint.x ? -1 : 1;
16233
+ const reverseY = this.findOne('.top-left').y() > comparePoint.y ? -1 : 1;
16197
16234
  x = newHypotenuse * this.cos * reverseX;
16198
16235
  y = newHypotenuse * this.sin * reverseY;
16199
16236
  this.findOne('.top-left').x(comparePoint.x - x);
@@ -16205,7 +16242,7 @@
16205
16242
  }
16206
16243
  else if (this._movingAnchorName === 'top-right') {
16207
16244
  if (keepProportion) {
16208
- var comparePoint = centeredScaling
16245
+ const comparePoint = centeredScaling
16209
16246
  ? {
16210
16247
  x: this.width() / 2,
16211
16248
  y: this.height() / 2,
@@ -16216,8 +16253,8 @@
16216
16253
  };
16217
16254
  newHypotenuse = Math.sqrt(Math.pow(anchorNode.x() - comparePoint.x, 2) +
16218
16255
  Math.pow(comparePoint.y - anchorNode.y(), 2));
16219
- var reverseX = this.findOne('.top-right').x() < comparePoint.x ? -1 : 1;
16220
- var reverseY = this.findOne('.top-right').y() > comparePoint.y ? -1 : 1;
16256
+ const reverseX = this.findOne('.top-right').x() < comparePoint.x ? -1 : 1;
16257
+ const reverseY = this.findOne('.top-right').y() > comparePoint.y ? -1 : 1;
16221
16258
  x = newHypotenuse * this.cos * reverseX;
16222
16259
  y = newHypotenuse * this.sin * reverseY;
16223
16260
  this.findOne('.top-right').x(comparePoint.x + x);
@@ -16235,7 +16272,7 @@
16235
16272
  }
16236
16273
  else if (this._movingAnchorName === 'bottom-left') {
16237
16274
  if (keepProportion) {
16238
- var comparePoint = centeredScaling
16275
+ const comparePoint = centeredScaling
16239
16276
  ? {
16240
16277
  x: this.width() / 2,
16241
16278
  y: this.height() / 2,
@@ -16246,8 +16283,8 @@
16246
16283
  };
16247
16284
  newHypotenuse = Math.sqrt(Math.pow(comparePoint.x - anchorNode.x(), 2) +
16248
16285
  Math.pow(anchorNode.y() - comparePoint.y, 2));
16249
- var reverseX = comparePoint.x < anchorNode.x() ? -1 : 1;
16250
- var reverseY = anchorNode.y() < comparePoint.y ? -1 : 1;
16286
+ const reverseX = comparePoint.x < anchorNode.x() ? -1 : 1;
16287
+ const reverseY = anchorNode.y() < comparePoint.y ? -1 : 1;
16251
16288
  x = newHypotenuse * this.cos * reverseX;
16252
16289
  y = newHypotenuse * this.sin * reverseY;
16253
16290
  anchorNode.x(comparePoint.x - x);
@@ -16262,7 +16299,7 @@
16262
16299
  }
16263
16300
  else if (this._movingAnchorName === 'bottom-right') {
16264
16301
  if (keepProportion) {
16265
- var comparePoint = centeredScaling
16302
+ const comparePoint = centeredScaling
16266
16303
  ? {
16267
16304
  x: this.width() / 2,
16268
16305
  y: this.height() / 2,
@@ -16273,8 +16310,8 @@
16273
16310
  };
16274
16311
  newHypotenuse = Math.sqrt(Math.pow(anchorNode.x() - comparePoint.x, 2) +
16275
16312
  Math.pow(anchorNode.y() - comparePoint.y, 2));
16276
- var reverseX = this.findOne('.bottom-right').x() < comparePoint.x ? -1 : 1;
16277
- var reverseY = this.findOne('.bottom-right').y() < comparePoint.y ? -1 : 1;
16313
+ const reverseX = this.findOne('.bottom-right').x() < comparePoint.x ? -1 : 1;
16314
+ const reverseY = this.findOne('.bottom-right').y() < comparePoint.y ? -1 : 1;
16278
16315
  x = newHypotenuse * this.cos * reverseX;
16279
16316
  y = newHypotenuse * this.sin * reverseY;
16280
16317
  this.findOne('.bottom-right').x(comparePoint.x + x);
@@ -16285,7 +16322,7 @@
16285
16322
  console.error(new Error('Wrong position argument of selection resizer: ' +
16286
16323
  this._movingAnchorName));
16287
16324
  }
16288
- var centeredScaling = this.centeredScaling() || e.altKey;
16325
+ centeredScaling = this.centeredScaling() || e.altKey;
16289
16326
  if (centeredScaling) {
16290
16327
  const topLeft = this.findOne('.top-left');
16291
16328
  const bottomRight = this.findOne('.bottom-right');
@@ -16335,13 +16372,13 @@
16335
16372
  activeTransformersCount--;
16336
16373
  this._fire('transformend', { evt: e, target: node });
16337
16374
  // redraw layer to restore hit graph
16338
- (_a = this.getLayer()) === null || _a === undefined ? undefined : _a.batchDraw();
16375
+ (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
16339
16376
  if (node) {
16340
16377
  this._nodes.forEach((target) => {
16341
16378
  var _a;
16342
16379
  target._fire('transformend', { evt: e, target });
16343
16380
  // redraw layer to restore hit graph
16344
- (_a = target.getLayer()) === null || _a === undefined ? undefined : _a.batchDraw();
16381
+ (_a = target.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
16345
16382
  });
16346
16383
  }
16347
16384
  this._movingAnchorName = null;
@@ -16470,7 +16507,7 @@
16470
16507
  .multiply(localTransform);
16471
16508
  const attrs = newLocalTransform.decompose();
16472
16509
  node.setAttrs(attrs);
16473
- (_a = node.getLayer()) === null || _a === undefined ? undefined : _a.batchDraw();
16510
+ (_a = node.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
16474
16511
  });
16475
16512
  this.rotation(Util._getRotation(newAttrs.rotation));
16476
16513
  // trigger transform event AFTER we update rotation
@@ -16592,7 +16629,7 @@
16592
16629
  styleFunc(node);
16593
16630
  });
16594
16631
  }
16595
- (_a = this.getLayer()) === null || _a === undefined ? undefined : _a.batchDraw();
16632
+ (_a = this.getLayer()) === null || _a === void 0 ? void 0 : _a.batchDraw();
16596
16633
  }
16597
16634
  /**
16598
16635
  * determine if transformer is in active transform
@@ -17371,10 +17408,10 @@
17371
17408
  ];
17372
17409
  function filterGaussBlurRGBA(imageData, radius) {
17373
17410
  const pixels = imageData.data, width = imageData.width, height = imageData.height;
17374
- 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;
17411
+ 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;
17375
17412
  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];
17376
17413
  let stackEnd = null, stack = stackStart, stackIn = null, stackOut = null;
17377
- for (i = 1; i < div; i++) {
17414
+ for (let i = 1; i < div; i++) {
17378
17415
  stack = stack.next = new BlurStack();
17379
17416
  if (i === radiusPlus1) {
17380
17417
  stackEnd = stack;
@@ -17382,7 +17419,7 @@
17382
17419
  }
17383
17420
  stack.next = stackStart;
17384
17421
  yw = yi = 0;
17385
- for (y = 0; y < height; y++) {
17422
+ for (let y = 0; y < height; y++) {
17386
17423
  r_in_sum =
17387
17424
  g_in_sum =
17388
17425
  b_in_sum =
@@ -17401,14 +17438,14 @@
17401
17438
  b_sum += sumFactor * pb;
17402
17439
  a_sum += sumFactor * pa;
17403
17440
  stack = stackStart;
17404
- for (i = 0; i < radiusPlus1; i++) {
17441
+ for (let i = 0; i < radiusPlus1; i++) {
17405
17442
  stack.r = pr;
17406
17443
  stack.g = pg;
17407
17444
  stack.b = pb;
17408
17445
  stack.a = pa;
17409
17446
  stack = stack.next;
17410
17447
  }
17411
- for (i = 1; i < radiusPlus1; i++) {
17448
+ for (let i = 1; i < radiusPlus1; i++) {
17412
17449
  p = yi + ((widthMinus1 < i ? widthMinus1 : i) << 2);
17413
17450
  r_sum += (stack.r = pr = pixels[p]) * (rbs = radiusPlus1 - i);
17414
17451
  g_sum += (stack.g = pg = pixels[p + 1]) * rbs;
@@ -17422,7 +17459,7 @@
17422
17459
  }
17423
17460
  stackIn = stackStart;
17424
17461
  stackOut = stackEnd;
17425
- for (x = 0; x < width; x++) {
17462
+ for (let x = 0; x < width; x++) {
17426
17463
  pixels[yi + 3] = pa = (a_sum * mul_sum) >> shg_sum;
17427
17464
  if (pa !== 0) {
17428
17465
  pa = 255 / pa;
@@ -17464,7 +17501,7 @@
17464
17501
  }
17465
17502
  yw += width;
17466
17503
  }
17467
- for (x = 0; x < width; x++) {
17504
+ for (let x = 0; x < width; x++) {
17468
17505
  g_in_sum =
17469
17506
  b_in_sum =
17470
17507
  a_in_sum =
@@ -17484,15 +17521,15 @@
17484
17521
  b_sum += sumFactor * pb;
17485
17522
  a_sum += sumFactor * pa;
17486
17523
  stack = stackStart;
17487
- for (i = 0; i < radiusPlus1; i++) {
17524
+ for (let i = 0; i < radiusPlus1; i++) {
17488
17525
  stack.r = pr;
17489
17526
  stack.g = pg;
17490
17527
  stack.b = pb;
17491
17528
  stack.a = pa;
17492
17529
  stack = stack.next;
17493
17530
  }
17494
- yp = width;
17495
- for (i = 1; i <= radius; i++) {
17531
+ let yp = width;
17532
+ for (let i = 1; i <= radius; i++) {
17496
17533
  yi = (yp + x) << 2;
17497
17534
  r_sum += (stack.r = pr = pixels[yi]) * (rbs = radiusPlus1 - i);
17498
17535
  g_sum += (stack.g = pg = pixels[yi + 1]) * rbs;
@@ -17510,7 +17547,7 @@
17510
17547
  yi = x;
17511
17548
  stackIn = stackStart;
17512
17549
  stackOut = stackEnd;
17513
- for (y = 0; y < height; y++) {
17550
+ for (let y = 0; y < height; y++) {
17514
17551
  p = yi << 2;
17515
17552
  pixels[p + 3] = pa = (a_sum * mul_sum) >> shg_sum;
17516
17553
  if (pa > 0) {
@@ -17890,7 +17927,7 @@
17890
17927
  bMax = 255;
17891
17928
  bMin = 0;
17892
17929
  }
17893
- let rMid, rGoalMax, rGoalMin, gMid, gGoalMax, gGoalMin, bMid, bGoalMax, bGoalMin;
17930
+ let rGoalMax, rGoalMin, gGoalMax, gGoalMin, bGoalMax, bGoalMin;
17894
17931
  // If the enhancement is positive - stretch the histogram
17895
17932
  if (enhanceAmount > 0) {
17896
17933
  rGoalMax = rMax + enhanceAmount * (255 - rMax);
@@ -17902,13 +17939,13 @@
17902
17939
  // If the enhancement is negative - compress the histogram
17903
17940
  }
17904
17941
  else {
17905
- rMid = (rMax + rMin) * 0.5;
17942
+ const rMid = (rMax + rMin) * 0.5;
17906
17943
  rGoalMax = rMax + enhanceAmount * (rMax - rMid);
17907
17944
  rGoalMin = rMin + enhanceAmount * (rMin - rMid);
17908
- gMid = (gMax + gMin) * 0.5;
17945
+ const gMid = (gMax + gMin) * 0.5;
17909
17946
  gGoalMax = gMax + enhanceAmount * (gMax - gMid);
17910
17947
  gGoalMin = gMin + enhanceAmount * (gMin - gMid);
17911
- bMid = (bMax + bMin) * 0.5;
17948
+ const bMid = (bMax + bMin) * 0.5;
17912
17949
  bGoalMax = bMax + enhanceAmount * (bMax - bMid);
17913
17950
  bGoalMin = bMin + enhanceAmount * (bMin - bMid);
17914
17951
  }
@@ -18045,12 +18082,11 @@
18045
18082
  const rr = 0.299 * v + 0.701 * vsu + 0.167 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw;
18046
18083
  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;
18047
18084
  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;
18048
- let r, g, b, a;
18049
18085
  for (let i = 0; i < nPixels; i += 4) {
18050
- r = data[i + 0];
18051
- g = data[i + 1];
18052
- b = data[i + 2];
18053
- a = data[i + 3];
18086
+ const r = data[i + 0];
18087
+ const g = data[i + 1];
18088
+ const b = data[i + 2];
18089
+ const a = data[i + 3];
18054
18090
  data[i + 0] = rr * r + rg * g + rb * b;
18055
18091
  data[i + 1] = gr * r + gg * g + gb * b;
18056
18092
  data[i + 2] = br * r + bg * g + bb * b;
@@ -18297,7 +18333,7 @@
18297
18333
  }
18298
18334
  }
18299
18335
  // Convert back from polar coordinates
18300
- FromPolar(scratchData, imageData, { polarRotation: 0 });
18336
+ FromPolar(scratchData, imageData, { });
18301
18337
  };
18302
18338
  /**
18303
18339
  * get/set kaleidoscope power. Use with {@link Konva.Filters.Kaleidoscope} filter.
@@ -18516,36 +18552,36 @@
18516
18552
  * node.pixelSize(10);
18517
18553
  */
18518
18554
  const Pixelate = function (imageData) {
18519
- let pixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height, x, y, i,
18555
+ let pixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height,
18520
18556
  //pixelsPerBin = pixelSize * pixelSize,
18521
- red, green, blue, alpha, nBinsX = Math.ceil(width / pixelSize), nBinsY = Math.ceil(height / pixelSize), xBinStart, xBinEnd, yBinStart, yBinEnd, xBin, yBin, pixelsInBin, data = imageData.data;
18557
+ nBinsX = Math.ceil(width / pixelSize), nBinsY = Math.ceil(height / pixelSize), data = imageData.data;
18522
18558
  if (pixelSize <= 0) {
18523
18559
  Util.error('pixelSize value can not be <= 0');
18524
18560
  return;
18525
18561
  }
18526
- for (xBin = 0; xBin < nBinsX; xBin += 1) {
18527
- for (yBin = 0; yBin < nBinsY; yBin += 1) {
18562
+ for (let xBin = 0; xBin < nBinsX; xBin += 1) {
18563
+ for (let yBin = 0; yBin < nBinsY; yBin += 1) {
18528
18564
  // Initialize the color accumlators to 0
18529
- red = 0;
18530
- green = 0;
18531
- blue = 0;
18532
- alpha = 0;
18565
+ let red = 0;
18566
+ let green = 0;
18567
+ let blue = 0;
18568
+ let alpha = 0;
18533
18569
  // Determine which pixels are included in this bin
18534
- xBinStart = xBin * pixelSize;
18535
- xBinEnd = xBinStart + pixelSize;
18536
- yBinStart = yBin * pixelSize;
18537
- yBinEnd = yBinStart + pixelSize;
18570
+ const xBinStart = xBin * pixelSize;
18571
+ const xBinEnd = xBinStart + pixelSize;
18572
+ const yBinStart = yBin * pixelSize;
18573
+ const yBinEnd = yBinStart + pixelSize;
18538
18574
  // Add all of the pixels to this bin!
18539
- pixelsInBin = 0;
18540
- for (x = xBinStart; x < xBinEnd; x += 1) {
18575
+ let pixelsInBin = 0;
18576
+ for (let x = xBinStart; x < xBinEnd; x += 1) {
18541
18577
  if (x >= width) {
18542
18578
  continue;
18543
18579
  }
18544
- for (y = yBinStart; y < yBinEnd; y += 1) {
18580
+ for (let y = yBinStart; y < yBinEnd; y += 1) {
18545
18581
  if (y >= height) {
18546
18582
  continue;
18547
18583
  }
18548
- i = (width * y + x) * 4;
18584
+ const i = (width * y + x) * 4;
18549
18585
  red += data[i + 0];
18550
18586
  green += data[i + 1];
18551
18587
  blue += data[i + 2];
@@ -18559,15 +18595,15 @@
18559
18595
  blue = blue / pixelsInBin;
18560
18596
  alpha = alpha / pixelsInBin;
18561
18597
  // Draw this bin
18562
- for (x = xBinStart; x < xBinEnd; x += 1) {
18598
+ for (let x = xBinStart; x < xBinEnd; x += 1) {
18563
18599
  if (x >= width) {
18564
18600
  continue;
18565
18601
  }
18566
- for (y = yBinStart; y < yBinEnd; y += 1) {
18602
+ for (let y = yBinStart; y < yBinEnd; y += 1) {
18567
18603
  if (y >= height) {
18568
18604
  continue;
18569
18605
  }
18570
- i = (width * y + x) * 4;
18606
+ const i = (width * y + x) * 4;
18571
18607
  data[i + 0] = red;
18572
18608
  data[i + 1] = green;
18573
18609
  data[i + 2] = blue;