Changeset 0c6b92a for imaps-frontend/node_modules/konva/konva.js
- Timestamp:
- 12/12/24 17:06:06 (5 weeks ago)
- Branches:
- main
- Parents:
- d565449
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/konva/konva.js
rd565449 r0c6b92a 6 6 7 7 /* 8 * Konva JavaScript Framework v9.3.1 48 * Konva JavaScript Framework v9.3.16 9 9 * http://konvajs.org/ 10 10 * Licensed under the MIT 11 * Date: Tue Jul 16202411 * Date: Mon Oct 21 2024 12 12 * 13 13 * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) … … 36 36 const Konva$2 = { 37 37 _global: glob, 38 version: '9.3.1 4',38 version: '9.3.16', 39 39 isBrowser: detectBrowser(), 40 40 isUnminified: /param/.test(function (param) { }.toString()), … … 250 250 */ 251 251 point(point) { 252 varm = this.m;252 const m = this.m; 253 253 return { 254 254 x: m[0] * point.x + m[2] * point.y + m[4], … … 292 292 */ 293 293 rotate(rad) { 294 varc = Math.cos(rad);295 vars = Math.sin(rad);296 varm11 = this.m[0] * c + this.m[2] * s;297 varm12 = this.m[1] * c + this.m[3] * s;298 varm21 = this.m[0] * -s + this.m[2] * c;299 varm22 = this.m[1] * -s + this.m[3] * c;294 const c = Math.cos(rad); 295 const s = Math.sin(rad); 296 const m11 = this.m[0] * c + this.m[2] * s; 297 const m12 = this.m[1] * c + this.m[3] * s; 298 const m21 = this.m[0] * -s + this.m[2] * c; 299 const m22 = this.m[1] * -s + this.m[3] * c; 300 300 this.m[0] = m11; 301 301 this.m[1] = m12; … … 325 325 */ 326 326 skew(sx, sy) { 327 varm11 = this.m[0] + this.m[2] * sy;328 varm12 = this.m[1] + this.m[3] * sy;329 varm21 = this.m[2] + this.m[0] * sx;330 varm22 = this.m[3] + this.m[1] * sx;327 const m11 = this.m[0] + this.m[2] * sy; 328 const m12 = this.m[1] + this.m[3] * sy; 329 const m21 = this.m[2] + this.m[0] * sx; 330 const m22 = this.m[3] + this.m[1] * sx; 331 331 this.m[0] = m11; 332 332 this.m[1] = m12; … … 343 343 */ 344 344 multiply(matrix) { 345 varm11 = this.m[0] * matrix.m[0] + this.m[2] * matrix.m[1];346 varm12 = this.m[1] * matrix.m[0] + this.m[3] * matrix.m[1];347 varm21 = this.m[0] * matrix.m[2] + this.m[2] * matrix.m[3];348 varm22 = this.m[1] * matrix.m[2] + this.m[3] * matrix.m[3];349 vardx = this.m[0] * matrix.m[4] + this.m[2] * matrix.m[5] + this.m[4];350 vardy = this.m[1] * matrix.m[4] + this.m[3] * matrix.m[5] + this.m[5];345 const m11 = this.m[0] * matrix.m[0] + this.m[2] * matrix.m[1]; 346 const m12 = this.m[1] * matrix.m[0] + this.m[3] * matrix.m[1]; 347 const m21 = this.m[0] * matrix.m[2] + this.m[2] * matrix.m[3]; 348 const m22 = this.m[1] * matrix.m[2] + this.m[3] * matrix.m[3]; 349 const dx = this.m[0] * matrix.m[4] + this.m[2] * matrix.m[5] + this.m[4]; 350 const dy = this.m[1] * matrix.m[4] + this.m[3] * matrix.m[5] + this.m[5]; 351 351 this.m[0] = m11; 352 352 this.m[1] = m12; … … 364 364 */ 365 365 invert() { 366 vard = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]);367 varm0 = this.m[3] * d;368 varm1 = -this.m[1] * d;369 varm2 = -this.m[2] * d;370 varm3 = this.m[0] * d;371 varm4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]);372 varm5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]);366 const d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]); 367 const m0 = this.m[3] * d; 368 const m1 = -this.m[1] * d; 369 const m2 = -this.m[2] * d; 370 const m3 = this.m[0] * d; 371 const m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]); 372 const m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]); 373 373 this.m[0] = m0; 374 374 this.m[1] = m1; … … 394 394 */ 395 395 decompose() { 396 vara = this.m[0];397 varb = this.m[1];398 varc = this.m[2];399 vard = this.m[3];400 vare = this.m[4];401 varf = this.m[5];402 vardelta = a * d - b * c;403 let result = {396 const a = this.m[0]; 397 const b = this.m[1]; 398 const c = this.m[2]; 399 const d = this.m[3]; 400 const e = this.m[4]; 401 const f = this.m[5]; 402 const delta = a * d - b * c; 403 const result = { 404 404 x: e, 405 405 y: f, … … 412 412 // Apply the QR-like decomposition. 413 413 if (a != 0 || b != 0) { 414 varr = Math.sqrt(a * a + b * b);414 const r = Math.sqrt(a * a + b * b); 415 415 result.rotation = b > 0 ? Math.acos(a / r) : -Math.acos(a / r); 416 416 result.scaleX = r; … … 420 420 } 421 421 else if (c != 0 || d != 0) { 422 vars = Math.sqrt(c * c + d * d);422 const s = Math.sqrt(c * c + d * d); 423 423 result.rotation = 424 424 Math.PI / 2 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s)); … … 434 434 } 435 435 // CONSTANTS 436 varOBJECT_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 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 = { 437 437 aliceblue: [240, 248, 255], 438 438 antiquewhite: [250, 235, 215], … … 628 628 return false; 629 629 } 630 varfirstChar = selector[0];630 const firstChar = selector[0]; 631 631 return (firstChar === '#' || 632 632 firstChar === '.' || … … 659 659 }, 660 660 createCanvasElement() { 661 varcanvas = document.createElement('canvas');661 const canvas = document.createElement('canvas'); 662 662 // on some environments canvas.style is readonly 663 663 try { … … 683 683 _urlToImage(url, callback) { 684 684 // if arg is a string, then it's a data url 685 varimageObj = Util.createImageElement();685 const imageObj = Util.createImageElement(); 686 686 imageObj.onload = function () { 687 687 callback(imageObj); … … 694 694 _hexToRgb(hex) { 695 695 hex = hex.replace(HASH$1, EMPTY_STRING$1); 696 varbigint = parseInt(hex, 16);696 const bigint = parseInt(hex, 16); 697 697 return { 698 698 r: (bigint >> 16) & 255, … … 709 709 */ 710 710 getRandomColor() { 711 varrandColor = ((Math.random() * 0xffffff) << 0).toString(16);711 let randColor = ((Math.random() * 0xffffff) << 0).toString(16); 712 712 while (randColor.length < 6) { 713 713 randColor = ZERO + randColor; … … 727 727 */ 728 728 getRGB(color) { 729 varrgb;729 let rgb; 730 730 // color string 731 731 if (color in COLORS) { … … 774 774 // Parse named css color. Like "green" 775 775 _namedColorToRBA(str) { 776 varc = COLORS[str.toLowerCase()];776 const c = COLORS[str.toLowerCase()]; 777 777 if (!c) { 778 778 return null; … … 789 789 if (str.indexOf('rgb(') === 0) { 790 790 str = str.match(/rgb\(([^)]+)\)/)[1]; 791 varparts = str.split(/ *, */).map(Number);791 const parts = str.split(/ *, */).map(Number); 792 792 return { 793 793 r: parts[0], … … 802 802 if (str.indexOf('rgba(') === 0) { 803 803 str = str.match(/rgba\(([^)]+)\)/)[1]; 804 varparts = str.split(/ *, */).map((n, index) => {804 const parts = str.split(/ *, */).map((n, index) => { 805 805 if (n.slice(-1) === '%') { 806 806 return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255; … … 935 935 }, 936 936 cloneObject(obj) { 937 varretObj = {};938 for ( varkey in obj) {937 const retObj = {}; 938 for (const key in obj) { 939 939 if (this._isPlainObject(obj[key])) { 940 940 retObj[key] = this.cloneObject(obj[key]); … … 985 985 }, 986 986 each(obj, func) { 987 for ( varkey in obj) {987 for (const key in obj) { 988 988 func(key, obj[key]); 989 989 } … … 993 993 }, 994 994 _getProjectionToSegment(x1, y1, x2, y2, x3, y3) { 995 varx, y, dist;996 varpd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);995 let x, y, dist; 996 const pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); 997 997 if (pd2 == 0) { 998 998 x = x1; … … 1001 1001 } 1002 1002 else { 1003 varu = ((x3 - x1) * (x2 - x1) + (y3 - y1) * (y2 - y1)) / pd2;1003 const u = ((x3 - x1) * (x2 - x1) + (y3 - y1) * (y2 - y1)) / pd2; 1004 1004 if (u < 0) { 1005 1005 x = x1; … … 1023 1023 // line might be closed 1024 1024 _getProjectionToLine(pt, line, isClosed) { 1025 varpc = Util.cloneObject(pt);1026 vardist = Number.MAX_VALUE;1025 const pc = Util.cloneObject(pt); 1026 let dist = Number.MAX_VALUE; 1027 1027 line.forEach(function (p1, i) { 1028 1028 if (!isClosed && i === line.length - 1) { 1029 1029 return; 1030 1030 } 1031 varp2 = line[(i + 1) % line.length];1032 varproj = Util._getProjectionToSegment(p1.x, p1.y, p2.x, p2.y, pt.x, pt.y);1033 varpx = proj[0], py = proj[1], pdist = proj[2];1031 const p2 = line[(i + 1) % line.length]; 1032 const proj = Util._getProjectionToSegment(p1.x, p1.y, p2.x, p2.y, pt.x, pt.y); 1033 const px = proj[0], py = proj[1], pdist = proj[2]; 1034 1034 if (pdist < dist) { 1035 1035 pc.x = px; … … 1041 1041 }, 1042 1042 _prepareArrayForTween(startArray, endArray, isClosed) { 1043 varn, start = [], end = [];1043 let n, start = [], end = []; 1044 1044 if (startArray.length > endArray.length) { 1045 vartemp = endArray;1045 const temp = endArray; 1046 1046 endArray = startArray; 1047 1047 startArray = temp; … … 1059 1059 }); 1060 1060 } 1061 varnewStart = [];1061 const newStart = []; 1062 1062 end.forEach(function (point) { 1063 varpr = Util._getProjectionToLine(point, start, isClosed);1063 const pr = Util._getProjectionToLine(point, start, isClosed); 1064 1064 newStart.push(pr.x); 1065 1065 newStart.push(pr.y); … … 1068 1068 }, 1069 1069 _prepareToStringify(obj) { 1070 vardesc;1070 let desc; 1071 1071 obj.visitedByCircularReferenceRemoval = true; 1072 for ( varkey in obj) {1072 for (const key in obj) { 1073 1073 if (!(obj.hasOwnProperty(key) && obj[key] && typeof obj[key] == 'object')) { 1074 1074 continue; … … 1098 1098 // very simplified version of Object.assign 1099 1099 _assign(target, source) { 1100 for ( varkey in source) {1100 for (const key in source) { 1101 1101 target[key] = source[key]; 1102 1102 } … … 1187 1187 if (Konva$2.isUnminified) { 1188 1188 return function (val, attr) { 1189 let isNumber = Util._isNumber(val);1190 let isValidArray = Util._isArray(val) && val.length == noOfElements;1189 const isNumber = Util._isNumber(val); 1190 const isValidArray = Util._isArray(val) && val.length == noOfElements; 1191 1191 if (!isNumber && !isValidArray) { 1192 1192 Util.warn(_formatValue(val) + … … 1204 1204 if (Konva$2.isUnminified) { 1205 1205 return function (val, attr) { 1206 varisNumber = Util._isNumber(val);1207 varisAuto = val === 'auto';1206 const isNumber = Util._isNumber(val); 1207 const isAuto = val === 'auto'; 1208 1208 if (!(isNumber || isAuto)) { 1209 1209 Util.warn(_formatValue(val) + … … 1278 1278 if (Konva$2.isUnminified) { 1279 1279 return function (val, attr) { 1280 varisBool = val === true || val === false;1280 const isBool = val === true || val === false; 1281 1281 if (!isBool) { 1282 1282 Util.warn(_formatValue(val) + … … 1308 1308 } 1309 1309 1310 varGET = 'get', SET$1 = 'set';1310 const GET = 'get', SET$1 = 'set'; 1311 1311 const Factory = { 1312 1312 addGetterSetter(constructor, attr, def, validator, after) { … … 1316 1316 }, 1317 1317 addGetter(constructor, attr, def) { 1318 varmethod = GET + Util._capitalize(attr);1318 const method = GET + Util._capitalize(attr); 1319 1319 constructor.prototype[method] = 1320 1320 constructor.prototype[method] || 1321 1321 function () { 1322 varval = this.attrs[attr];1322 const val = this.attrs[attr]; 1323 1323 return val === undefined ? def : val; 1324 1324 }; 1325 1325 }, 1326 1326 addSetter(constructor, attr, validator, after) { 1327 varmethod = SET$1 + Util._capitalize(attr);1327 const method = SET$1 + Util._capitalize(attr); 1328 1328 if (!constructor.prototype[method]) { 1329 1329 Factory.overWriteSetter(constructor, attr, validator, after); … … 1331 1331 }, 1332 1332 overWriteSetter(constructor, attr, validator, after) { 1333 varmethod = SET$1 + Util._capitalize(attr);1333 const method = SET$1 + Util._capitalize(attr); 1334 1334 constructor.prototype[method] = function (val) { 1335 1335 if (validator && val !== undefined && val !== null) { … … 1344 1344 }, 1345 1345 addComponentsGetterSetter(constructor, attr, components, validator, after) { 1346 varlen = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), setter = SET$1 + capitalize(attr), n, component;1346 let len = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), setter = SET$1 + capitalize(attr), n, component; 1347 1347 // getter 1348 1348 constructor.prototype[getter] = function () { 1349 varret = {};1349 const ret = {}; 1350 1350 for (n = 0; n < len; n++) { 1351 1351 component = components[n]; … … 1354 1354 return ret; 1355 1355 }; 1356 varbasicValidator = getComponentValidator(components);1356 const basicValidator = getComponentValidator(components); 1357 1357 // setter 1358 1358 constructor.prototype[setter] = function (val) { 1359 varoldVal = this.attrs[attr], key;1359 let oldVal = this.attrs[attr], key; 1360 1360 if (validator) { 1361 1361 val = validator.call(this, val); … … 1384 1384 }, 1385 1385 addOverloadedGetterSetter(constructor, attr) { 1386 varcapitalizedAttr = Util._capitalize(attr), setter = SET$1 + capitalizedAttr, getter = GET + capitalizedAttr;1386 const capitalizedAttr = Util._capitalize(attr), setter = SET$1 + capitalizedAttr, getter = GET + capitalizedAttr; 1387 1387 constructor.prototype[attr] = function () { 1388 1388 // setting … … 1397 1397 addDeprecatedGetterSetter(constructor, attr, def, validator) { 1398 1398 Util.error('Adding deprecated ' + attr); 1399 varmethod = GET + Util._capitalize(attr);1400 varmessage = attr +1399 const method = GET + Util._capitalize(attr); 1400 const message = attr + 1401 1401 ' property is deprecated and will be removed soon. Look at Konva change log for more information.'; 1402 1402 constructor.prototype[method] = function () { 1403 1403 Util.error(message); 1404 varval = this.attrs[attr];1404 const val = this.attrs[attr]; 1405 1405 return val === undefined ? def : val; 1406 1406 }; … … 1412 1412 backCompat(constructor, methods) { 1413 1413 Util.each(methods, function (oldMethodName, newMethodName) { 1414 varmethod = constructor.prototype[newMethodName];1415 varoldGetter = GET + Util._capitalize(oldMethodName);1416 varoldSetter = SET$1 + Util._capitalize(oldMethodName);1414 const method = constructor.prototype[newMethodName]; 1415 const oldGetter = GET + Util._capitalize(oldMethodName); 1416 const oldSetter = SET$1 + Util._capitalize(oldMethodName); 1417 1417 function deprecated() { 1418 1418 method.apply(this, arguments); … … 1434 1434 1435 1435 function simplifyArray(arr) { 1436 varretArr = [], len = arr.length, util = Util, n, val;1436 let retArr = [], len = arr.length, util = Util, n, val; 1437 1437 for (n = 0; n < len; n++) { 1438 1438 val = arr[n]; … … 1447 1447 return retArr; 1448 1448 } 1449 varCOMMA = ',', OPEN_PAREN = '(', CLOSE_PAREN = ')', OPEN_PAREN_BRACKET = '([', CLOSE_BRACKET_PAREN = '])', SEMICOLON = ';', DOUBLE_PAREN = '()',1449 const COMMA = ',', OPEN_PAREN = '(', CLOSE_PAREN = ')', OPEN_PAREN_BRACKET = '([', CLOSE_BRACKET_PAREN = '])', SEMICOLON = ';', DOUBLE_PAREN = '()', 1450 1450 // EMPTY_STRING = '', 1451 1451 EQUALS = '=', … … 1485 1485 'translate', 1486 1486 ]; 1487 varCONTEXT_PROPERTIES = [1487 const CONTEXT_PROPERTIES = [ 1488 1488 'fillStyle', 1489 1489 'strokeStyle', … … 1582 1582 } 1583 1583 getTrace(relaxed, rounded) { 1584 vartraceArr = this.traceArr, len = traceArr.length, str = '', n, trace, method, args;1584 let traceArr = this.traceArr, len = traceArr.length, str = '', n, trace, method, args; 1585 1585 for (n = 0; n < len; n++) { 1586 1586 trace = traceArr[n]; … … 1620 1620 } 1621 1621 _trace(str) { 1622 vartraceArr = this.traceArr, len;1622 let traceArr = this.traceArr, len; 1623 1623 traceArr.push(str); 1624 1624 len = traceArr.length; … … 1633 1633 */ 1634 1634 reset() { 1635 varpixelRatio = this.getCanvas().getPixelRatio();1635 const pixelRatio = this.getCanvas().getPixelRatio(); 1636 1636 this.setTransform(1 * pixelRatio, 0, 0, 1 * pixelRatio, 0, 0); 1637 1637 } … … 1656 1656 */ 1657 1657 clear(bounds) { 1658 varcanvas = this.getCanvas();1658 const canvas = this.getCanvas(); 1659 1659 if (bounds) { 1660 1660 this.clearRect(bounds.x || 0, bounds.y || 0, bounds.width || 0, bounds.height || 0); … … 1671 1671 } 1672 1672 _applyOpacity(shape) { 1673 varabsOpacity = shape.getAbsoluteOpacity();1673 const absOpacity = shape.getAbsoluteOpacity(); 1674 1674 if (absOpacity !== 1) { 1675 1675 this.setAttr('globalAlpha', absOpacity); … … 1743 1743 */ 1744 1744 createImageData(width, height) { 1745 vara = arguments;1745 const a = arguments; 1746 1746 if (a.length === 2) { 1747 1747 return this._context.createImageData(width, height); … … 1782 1782 drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) { 1783 1783 // this._context.drawImage(...arguments); 1784 vara = arguments, _context = this._context;1784 const a = arguments, _context = this._context; 1785 1785 if (a.length === 3) { 1786 1786 _context.drawImage(image, sx, sy); … … 2015 2015 } 2016 2016 _enableTrace() { 2017 varthat = this, len = CONTEXT_METHODS.length, origSetter = this.setAttr, n, args;2017 let that = this, len = CONTEXT_METHODS.length, origSetter = this.setAttr, n, args; 2018 2018 // to prevent creating scope function at each loop 2019 varfunc = function (methodName) {2020 varorigMethod = that[methodName], ret;2019 const func = function (methodName) { 2020 let origMethod = that[methodName], ret; 2021 2021 that[methodName] = function () { 2022 2022 args = simplifyArray(Array.prototype.slice.call(arguments, 0)); … … 2036 2036 that.setAttr = function () { 2037 2037 origSetter.apply(that, arguments); 2038 varprop = arguments[0];2039 varval = arguments[1];2038 const prop = arguments[0]; 2039 let val = arguments[1]; 2040 2040 if (prop === 'shadowOffsetX' || 2041 2041 prop === 'shadowOffsetY' || … … 2051 2051 _applyGlobalCompositeOperation(node) { 2052 2052 const op = node.attrs.globalCompositeOperation; 2053 vardef = !op || op === 'source-over';2053 const def = !op || op === 'source-over'; 2054 2054 if (!def) { 2055 2055 this.setAttr('globalCompositeOperation', op); … … 2075 2075 } 2076 2076 _fillColor(shape) { 2077 varfill = shape.fill();2077 const fill = shape.fill(); 2078 2078 this.setAttr('fillStyle', fill); 2079 2079 shape._fillFunc(this); … … 2084 2084 } 2085 2085 _fillLinearGradient(shape) { 2086 vargrd = shape._getLinearGradient();2086 const grd = shape._getLinearGradient(); 2087 2087 if (grd) { 2088 2088 this.setAttr('fillStyle', grd); … … 2137 2137 if (colorStops) { 2138 2138 // build color stops 2139 for ( varn = 0; n < colorStops.length; n += 2) {2139 for (let n = 0; n < colorStops.length; n += 2) { 2140 2140 grd.addColorStop(colorStops[n], colorStops[n + 1]); 2141 2141 } … … 2144 2144 } 2145 2145 _stroke(shape) { 2146 vardash = shape.dash(),2146 const dash = shape.dash(), 2147 2147 // ignore strokeScaleEnabled for Text 2148 2148 strokeScaleEnabled = shape.getStrokeScaleEnabled(); … … 2150 2150 if (!strokeScaleEnabled) { 2151 2151 this.save(); 2152 varpixelRatio = this.getCanvas().getPixelRatio();2152 const pixelRatio = this.getCanvas().getPixelRatio(); 2153 2153 this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0); 2154 2154 } … … 2162 2162 this.setAttr('shadowColor', 'rgba(0,0,0,0)'); 2163 2163 } 2164 varhasLinearGradient = shape.getStrokeLinearGradientColorStops();2164 const hasLinearGradient = shape.getStrokeLinearGradientColorStops(); 2165 2165 if (hasLinearGradient) { 2166 2166 this._strokeLinearGradient(shape); … … 2177 2177 _applyShadow(shape) { 2178 2178 var _a, _b, _c; 2179 varcolor = (_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 : {2179 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 : { 2180 2180 x: 0, 2181 2181 y: 0, … … 2211 2211 if (!strokeScaleEnabled) { 2212 2212 this.save(); 2213 varpixelRatio = this.getCanvas().getPixelRatio();2213 const pixelRatio = this.getCanvas().getPixelRatio(); 2214 2214 this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0); 2215 2215 } 2216 2216 this._applyLineCap(shape); 2217 varhitStrokeWidth = shape.hitStrokeWidth();2218 varstrokeWidth = hitStrokeWidth === 'auto' ? shape.strokeWidth() : hitStrokeWidth;2217 const hitStrokeWidth = shape.hitStrokeWidth(); 2218 const strokeWidth = hitStrokeWidth === 'auto' ? shape.strokeWidth() : hitStrokeWidth; 2219 2219 this.setAttr('lineWidth', strokeWidth); 2220 2220 this.setAttr('strokeStyle', shape.colorKey); … … 2228 2228 2229 2229 // calculate pixel ratio 2230 var_pixelRatio;2230 let _pixelRatio; 2231 2231 function getDevicePixelRatio() { 2232 2232 if (_pixelRatio) { 2233 2233 return _pixelRatio; 2234 2234 } 2235 varcanvas = Util.createCanvasElement();2236 varcontext = canvas.getContext('2d');2235 const canvas = Util.createCanvasElement(); 2236 const context = canvas.getContext('2d'); 2237 2237 _pixelRatio = (function () { 2238 vardevicePixelRatio = Konva$2._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio ||2238 const devicePixelRatio = Konva$2._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio || 2239 2239 context.mozBackingStorePixelRatio || 2240 2240 context.msBackingStorePixelRatio || … … 2264 2264 this.height = 0; 2265 2265 this.isCache = false; 2266 varconf = config || {};2267 varpixelRatio = conf.pixelRatio || Konva$2.pixelRatio || getDevicePixelRatio();2266 const conf = config || {}; 2267 const pixelRatio = conf.pixelRatio || Konva$2.pixelRatio || getDevicePixelRatio(); 2268 2268 this.pixelRatio = pixelRatio; 2269 2269 this._canvas = Util.createCanvasElement(); … … 2290 2290 } 2291 2291 setPixelRatio(pixelRatio) { 2292 varpreviousRatio = this.pixelRatio;2292 const previousRatio = this.pixelRatio; 2293 2293 this.pixelRatio = pixelRatio; 2294 2294 this.setSize(this.getWidth() / previousRatio, this.getHeight() / previousRatio); … … 2298 2298 this.width = this._canvas.width = width * this.pixelRatio; 2299 2299 this._canvas.style.width = width + 'px'; 2300 varpixelRatio = this.pixelRatio, _context = this.getContext()._context;2300 const pixelRatio = this.pixelRatio, _context = this.getContext()._context; 2301 2301 _context.scale(pixelRatio, pixelRatio); 2302 2302 } … … 2305 2305 this.height = this._canvas.height = height * this.pixelRatio; 2306 2306 this._canvas.style.height = height + 'px'; 2307 varpixelRatio = this.pixelRatio, _context = this.getContext()._context;2307 const pixelRatio = this.pixelRatio, _context = this.getContext()._context; 2308 2308 _context.scale(pixelRatio, pixelRatio); 2309 2309 } … … 2386 2386 const DD = { 2387 2387 get isDragging() { 2388 varflag = false;2388 let flag = false; 2389 2389 DD._dragElements.forEach((elem) => { 2390 2390 if (elem.dragStatus === 'dragging') { … … 2397 2397 get node() { 2398 2398 // return first dragging node 2399 varnode;2399 let node; 2400 2400 DD._dragElements.forEach((elem) => { 2401 2401 node = elem.node; … … 2423 2423 } 2424 2424 if (elem.dragStatus !== 'dragging') { 2425 vardragDistance = node.dragDistance();2426 vardistance = Math.max(Math.abs(pos.x - elem.startPointerPos.x), Math.abs(pos.y - elem.startPointerPos.y));2425 const dragDistance = node.dragDistance(); 2426 const distance = Math.max(Math.abs(pos.x - elem.startPointerPos.x), Math.abs(pos.y - elem.startPointerPos.y)); 2427 2427 if (distance < dragDistance) { 2428 2428 return; … … 2501 2501 window.addEventListener('mouseup', DD._endDragBefore, true); 2502 2502 window.addEventListener('touchend', DD._endDragBefore, true); 2503 // add touchcancel to fix this: https://github.com/konvajs/konva/issues/1843 2504 window.addEventListener('touchcancel', DD._endDragBefore, true); 2503 2505 window.addEventListener('mousemove', DD._drag); 2504 2506 window.addEventListener('touchmove', DD._drag); 2505 2507 window.addEventListener('mouseup', DD._endDragAfter, false); 2506 2508 window.addEventListener('touchend', DD._endDragAfter, false); 2509 window.addEventListener('touchcancel', DD._endDragAfter, false); 2507 2510 } 2508 2511 2509 2512 // CONSTANTS 2510 varABSOLUTE_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 = [2513 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 = [ 2511 2514 'xChange.konva', 2512 2515 'yChange.konva', … … 2591 2594 } 2592 2595 _getCache(attr, privateGetter) { 2593 varcache = this._cache.get(attr);2596 let cache = this._cache.get(attr); 2594 2597 // for transform the cache can be NOT empty 2595 2598 // but we still need to recalculate it if it is dirty 2596 varisTransform = attr === TRANSFORM || attr === ABSOLUTE_TRANSFORM;2597 varinvalid = cache === undefined || (isTransform && cache.dirty === true);2599 const isTransform = attr === TRANSFORM || attr === ABSOLUTE_TRANSFORM; 2600 const invalid = cache === undefined || (isTransform && cache.dirty === true); 2598 2601 // if not cached, we need to set it using the private getter method. 2599 2602 if (invalid) { … … 2693 2696 */ 2694 2697 cache(config) { 2695 varconf = config || {};2696 varrect = {};2698 const conf = config || {}; 2699 let rect = {}; 2697 2700 // don't call getClientRect if we have all attributes 2698 2701 // it means call it only if have one undefined … … 2706 2709 }); 2707 2710 } 2708 varwidth = Math.ceil(conf.width || rect.width), height = Math.ceil(conf.height || rect.height), pixelRatio = conf.pixelRatio, x = conf.x === undefined ? Math.floor(rect.x) : conf.x, y = conf.y === undefined ? Math.floor(rect.y) : conf.y, offset = conf.offset || 0, drawBorder = conf.drawBorder || false, hitCanvasPixelRatio = conf.hitCanvasPixelRatio || 1;2711 let width = Math.ceil(conf.width || rect.width), height = Math.ceil(conf.height || rect.height), pixelRatio = conf.pixelRatio, x = conf.x === undefined ? Math.floor(rect.x) : conf.x, y = conf.y === undefined ? Math.floor(rect.y) : conf.y, offset = conf.offset || 0, drawBorder = conf.drawBorder || false, hitCanvasPixelRatio = conf.hitCanvasPixelRatio || 1; 2709 2712 if (!width || !height) { 2710 2713 Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.'); … … 2729 2732 // } 2730 2733 // console.log({ x, y, width, height }, rect); 2731 varcachedSceneCanvas = new SceneCanvas({2734 const cachedSceneCanvas = new SceneCanvas({ 2732 2735 pixelRatio: pixelRatio, 2733 2736 width: width, … … 2837 2840 } 2838 2841 _transformedRect(rect, top) { 2839 varpoints = [2842 const points = [ 2840 2843 { x: rect.x, y: rect.y }, 2841 2844 { x: rect.x + rect.width, y: rect.y }, … … 2843 2846 { x: rect.x, y: rect.y + rect.height }, 2844 2847 ]; 2845 varminX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;2846 vartrans = this.getAbsoluteTransform(top);2848 let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity; 2849 const trans = this.getAbsoluteTransform(top); 2847 2850 points.forEach(function (point) { 2848 vartransformed = trans.point(point);2851 const transformed = trans.point(point); 2849 2852 if (minX === undefined) { 2850 2853 minX = maxX = transformed.x; … … 2869 2872 const canvasCache = this._getCanvasCache(); 2870 2873 context.translate(canvasCache.x, canvasCache.y); 2871 varcacheCanvas = this._getCachedSceneCanvas();2872 varratio = cacheCanvas.pixelRatio;2874 const cacheCanvas = this._getCachedSceneCanvas(); 2875 const ratio = cacheCanvas.pixelRatio; 2873 2876 context.drawImage(cacheCanvas._canvas, 0, 0, cacheCanvas.width / ratio, cacheCanvas.height / ratio); 2874 2877 context.restore(); 2875 2878 } 2876 2879 _drawCachedHitCanvas(context) { 2877 varcanvasCache = this._getCanvasCache(), hitCanvas = canvasCache.hit;2880 const canvasCache = this._getCanvasCache(), hitCanvas = canvasCache.hit; 2878 2881 context.save(); 2879 2882 context.translate(canvasCache.x, canvasCache.y); … … 2882 2885 } 2883 2886 _getCachedSceneCanvas() { 2884 varfilters = this.filters(), cachedCanvas = this._getCanvasCache(), sceneCanvas = cachedCanvas.scene, filterCanvas = cachedCanvas.filter, filterContext = filterCanvas.getContext(), len, imageData, n, filter;2887 let filters = this.filters(), cachedCanvas = this._getCanvasCache(), sceneCanvas = cachedCanvas.scene, filterCanvas = cachedCanvas.filter, filterContext = filterCanvas.getContext(), len, imageData, n, filter; 2885 2888 if (filters) { 2886 2889 if (!this._filterUpToDate) { 2887 varratio = sceneCanvas.pixelRatio;2890 const ratio = sceneCanvas.pixelRatio; 2888 2891 filterCanvas.setSize(sceneCanvas.width / sceneCanvas.pixelRatio, sceneCanvas.height / sceneCanvas.pixelRatio); 2889 2892 try { … … 2983 2986 return this._delegate.apply(this, arguments); 2984 2987 } 2985 varevents = evtStr.split(SPACE$1), len = events.length, n, event, parts, baseEvent, name;2988 let events = evtStr.split(SPACE$1), len = events.length, n, event, parts, baseEvent, name; 2986 2989 /* 2987 2990 * loop through types and attach event listeners to … … 3027 3030 */ 3028 3031 off(evtStr, callback) { 3029 varevents = (evtStr || '').split(SPACE$1), len = events.length, n, t, event, parts, baseEvent, name;3032 let events = (evtStr || '').split(SPACE$1), len = events.length, n, t, event, parts, baseEvent, name; 3030 3033 this._cache && this._cache.delete(ALL_LISTENERS); 3031 3034 if (!evtStr) { … … 3055 3058 // some event aliases for third party integration like HammerJS 3056 3059 dispatchEvent(evt) { 3057 vare = {3060 const e = { 3058 3061 target: this, 3059 3062 type: evt.type, … … 3076 3079 // like node.on 3077 3080 _delegate(event, selector, handler) { 3078 varstopNode = this;3081 const stopNode = this; 3079 3082 this.on(event, function (evt) { 3080 vartargets = evt.target.findAncestors(selector, true, stopNode);3081 for ( vari = 0; i < targets.length; i++) {3083 const targets = evt.target.findAncestors(selector, true, stopNode); 3084 for (let i = 0; i < targets.length; i++) { 3082 3085 evt = Util.cloneObject(evt); 3083 3086 evt.currentTarget = targets[i]; … … 3116 3119 // traversal must be cleared when removing a node 3117 3120 this._clearCaches(); 3118 varparent = this.getParent();3121 const parent = this.getParent(); 3119 3122 if (parent && parent.children) { 3120 3123 parent.children.splice(this.index, 1); … … 3146 3149 */ 3147 3150 getAttr(attr) { 3148 varmethod = 'get' + Util._capitalize(attr);3151 const method = 'get' + Util._capitalize(attr); 3149 3152 if (Util._isFunction(this[method])) { 3150 3153 return this[method](); … … 3164 3167 */ 3165 3168 getAncestors() { 3166 varparent = this.getParent(), ancestors = [];3169 let parent = this.getParent(), ancestors = []; 3167 3170 while (parent) { 3168 3171 ancestors.push(parent); … … 3194 3197 setAttrs(config) { 3195 3198 this._batchTransformChanges(() => { 3196 varkey, method;3199 let key, method; 3197 3200 if (!config) { 3198 3201 return this; … … 3280 3283 return this._isVisible(top) && this._isListening(top); 3281 3284 } 3282 varlayer = this.getLayer();3283 varlayerUnderDrag = false;3285 const layer = this.getLayer(); 3286 let layerUnderDrag = false; 3284 3287 DD._dragElements.forEach((elem) => { 3285 3288 if (elem.dragStatus !== 'dragging') { … … 3293 3296 } 3294 3297 }); 3295 vardragSkip = !skipDragCheck &&3298 const dragSkip = !skipDragCheck && 3296 3299 !Konva$2.hitOnDragEnabled && 3297 3300 (layerUnderDrag || Konva$2.isTransforming()); … … 3329 3332 */ 3330 3333 getAbsoluteZIndex() { 3331 vardepth = this.getDepth(), that = this, index = 0, nodes, len, n, child;3334 let depth = this.getDepth(), that = this, index = 0, nodes, len, n, child; 3332 3335 function addChildren(children) { 3333 3336 nodes = []; … … 3362 3365 */ 3363 3366 getDepth() { 3364 vardepth = 0, parent = this.parent;3367 let depth = 0, parent = this.parent; 3365 3368 while (parent) { 3366 3369 depth++; … … 3414 3417 } 3415 3418 // get pointer (say mouse or touch) position 3416 varpos = stage.getPointerPosition();3419 const pos = stage.getPointerPosition(); 3417 3420 if (!pos) { 3418 3421 return null; 3419 3422 } 3420 vartransform = this.getAbsoluteTransform().copy();3423 const transform = this.getAbsoluteTransform().copy(); 3421 3424 // to detect relative position we need to invert transform 3422 3425 transform.invert(); … … 3454 3457 top = true; 3455 3458 } 3456 varabsoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Transform(), offset = this.offset();3459 const absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Transform(), offset = this.offset(); 3457 3460 // clone the matrix array 3458 3461 absoluteTransform.m = absoluteMatrix.slice(); … … 3467 3470 // important, use non cached value 3468 3471 this._clearCache(TRANSFORM); 3469 varit = this._getAbsoluteTransform().copy();3472 const it = this._getAbsoluteTransform().copy(); 3470 3473 it.invert(); 3471 3474 it.translate(pos.x, pos.y); … … 3481 3484 } 3482 3485 _setTransform(trans) { 3483 varkey;3486 let key; 3484 3487 for (key in trans) { 3485 3488 this.attrs[key] = trans[key]; … … 3489 3492 } 3490 3493 _clearTransform() { 3491 vartrans = {3494 const trans = { 3492 3495 x: this.x(), 3493 3496 y: this.y(), … … 3528 3531 */ 3529 3532 move(change) { 3530 varchangeX = change.x, changeY = change.y, x = this.x(), y = this.y();3533 let changeX = change.x, changeY = change.y, x = this.x(), y = this.y(); 3531 3534 if (changeX !== undefined) { 3532 3535 x += changeX; … … 3539 3542 } 3540 3543 _eachAncestorReverse(func, top) { 3541 varfamily = [], parent = this.getParent(), len, n;3544 let family = [], parent = this.getParent(), len, n; 3542 3545 // if top node is defined, and this node is top node, 3543 3546 // there's no need to build a family tree. just execute … … 3579 3582 return false; 3580 3583 } 3581 varindex = this.index, len = this.parent.getChildren().length;3584 const index = this.index, len = this.parent.getChildren().length; 3582 3585 if (index < len - 1) { 3583 3586 this.parent.children.splice(index, 1); … … 3599 3602 return false; 3600 3603 } 3601 varindex = this.index, len = this.parent.getChildren().length;3604 const index = this.index, len = this.parent.getChildren().length; 3602 3605 if (index < len - 1) { 3603 3606 this.parent.children.splice(index, 1); … … 3619 3622 return false; 3620 3623 } 3621 varindex = this.index;3624 const index = this.index; 3622 3625 if (index > 0) { 3623 3626 this.parent.children.splice(index, 1); … … 3639 3642 return false; 3640 3643 } 3641 varindex = this.index;3644 const index = this.index; 3642 3645 if (index > 0) { 3643 3646 this.parent.children.splice(index, 1); … … 3660 3663 '.'); 3661 3664 } 3662 varindex = this.index;3665 const index = this.index; 3663 3666 this.parent.children.splice(index, 1); 3664 3667 this.parent.children.splice(zIndex, 0, this); … … 3676 3679 } 3677 3680 _getAbsoluteOpacity() { 3678 varabsOpacity = this.opacity();3679 varparent = this.getParent();3681 let absOpacity = this.opacity(); 3682 const parent = this.getParent(); 3680 3683 if (parent && !parent._isUnderCache) { 3681 3684 absOpacity *= parent.getAbsoluteOpacity(); … … 3708 3711 */ 3709 3712 toObject() { 3710 varattrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject;3713 let attrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject; 3711 3714 const obj = { 3712 3715 attrs: {}, … … 3765 3768 */ 3766 3769 findAncestors(selector, includeSelf, stopNode) { 3767 varres = [];3770 const res = []; 3768 3771 if (includeSelf && this._isMatch(selector)) { 3769 3772 res.push(this); 3770 3773 } 3771 varancestor = this.parent;3774 let ancestor = this.parent; 3772 3775 while (ancestor) { 3773 3776 if (ancestor === stopNode) { … … 3807 3810 return selector(this); 3808 3811 } 3809 varselectorArr = selector.replace(/ /g, '').split(','), len = selectorArr.length, n, sel;3812 let selectorArr = selector.replace(/ /g, '').split(','), len = selectorArr.length, n, sel; 3810 3813 for (n = 0; n < len; n++) { 3811 3814 sel = selectorArr[n]; … … 3842 3845 */ 3843 3846 getLayer() { 3844 varparent = this.getParent();3847 const parent = this.getParent(); 3845 3848 return parent ? parent.getLayer() : null; 3846 3849 } … … 3855 3858 } 3856 3859 _getStage() { 3857 varparent = this.getParent();3860 const parent = this.getParent(); 3858 3861 if (parent) { 3859 3862 return parent.getStage(); … … 3917 3920 } 3918 3921 _getAbsoluteTransform(top) { 3919 varat;3922 let at; 3920 3923 // we we need position relative to an ancestor, we will iterate for all 3921 3924 if (top) { … … 3923 3926 // start with stage and traverse downwards to self 3924 3927 this._eachAncestorReverse(function (node) { 3925 vartransformsEnabled = node.transformsEnabled();3928 const transformsEnabled = node.transformsEnabled(); 3926 3929 if (transformsEnabled === 'all') { 3927 3930 at.multiply(node.getTransform()); … … 3943 3946 at.reset(); 3944 3947 } 3945 vartransformsEnabled = this.transformsEnabled();3948 const transformsEnabled = this.transformsEnabled(); 3946 3949 if (transformsEnabled === 'all') { 3947 3950 at.multiply(this.getTransform()); … … 3973 3976 // because it use cache transform 3974 3977 // this is special logic for caching with some shapes with shadow 3975 varparent = this;3978 let parent = this; 3976 3979 while (parent) { 3977 3980 if (parent._isUnderCache) { … … 4018 4021 _getTransform() { 4019 4022 var _a, _b; 4020 varm = this._cache.get(TRANSFORM) || new Transform();4023 const m = this._cache.get(TRANSFORM) || new Transform(); 4021 4024 m.reset(); 4022 4025 // I was trying to use attributes directly here 4023 4026 // but it doesn't work for Transformer well 4024 4027 // because it overwrite x,y getters 4025 varx = 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;4028 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; 4026 4029 if (x !== 0 || y !== 0) { 4027 4030 m.translate(x, y); … … 4061 4064 clone(obj) { 4062 4065 // instantiate new node 4063 varattrs = Util.cloneObject(this.attrs), key, allListeners, len, n, listener;4066 let attrs = Util.cloneObject(this.attrs), key, allListeners, len, n, listener; 4064 4067 // apply attr overrides 4065 4068 for (key in obj) { 4066 4069 attrs[key] = obj[key]; 4067 4070 } 4068 varnode = new this.constructor(attrs);4071 const node = new this.constructor(attrs); 4069 4072 // copy over listeners 4070 4073 for (key in this.eventListeners) { … … 4090 4093 _toKonvaCanvas(config) { 4091 4094 config = config || {}; 4092 varbox = this.getClientRect();4093 varstage = this.getStage(), x = config.x !== undefined ? config.x : Math.floor(box.x), y = config.y !== undefined ? config.y : Math.floor(box.y), pixelRatio = config.pixelRatio || 1, canvas = new SceneCanvas({4095 const box = this.getClientRect(); 4096 const stage = this.getStage(), x = config.x !== undefined ? config.x : Math.floor(box.x), y = config.y !== undefined ? config.y : Math.floor(box.y), pixelRatio = config.pixelRatio || 1, canvas = new SceneCanvas({ 4094 4097 width: config.width || Math.ceil(box.width) || (stage ? stage.width() : 0), 4095 4098 height: config.height || … … 4163 4166 toDataURL(config) { 4164 4167 config = config || {}; 4165 varmimeType = config.mimeType || null, quality = config.quality || null;4166 varurl = this._toKonvaCanvas(config).toDataURL(mimeType, quality);4168 const mimeType = config.mimeType || null, quality = config.quality || null; 4169 const url = this._toKonvaCanvas(config).toDataURL(mimeType, quality); 4167 4170 if (config.callback) { 4168 4171 config.callback(url); … … 4296 4299 } 4297 4300 _off(type, name, callback) { 4298 varevtListeners = this.eventListeners[type], i, evtName, handler;4301 let evtListeners = this.eventListeners[type], i, evtName, handler; 4299 4302 for (i = 0; i < evtListeners.length; i++) { 4300 4303 evtName = evtListeners[i].name; … … 4335 4338 addName(name) { 4336 4339 if (!this.hasName(name)) { 4337 varoldName = this.name();4338 varnewName = oldName ? oldName + ' ' + name : name;4340 const oldName = this.name(); 4341 const newName = oldName ? oldName + ' ' + name : name; 4339 4342 this.name(newName); 4340 4343 } … … 4362 4365 } 4363 4366 // if name is '' the "names" will be [''], so I added extra check above 4364 varnames = (fullName || '').split(/\s/g);4367 const names = (fullName || '').split(/\s/g); 4365 4368 return names.indexOf(name) !== -1; 4366 4369 } … … 4378 4381 */ 4379 4382 removeName(name) { 4380 varnames = (this.name() || '').split(/\s/g);4381 varindex = names.indexOf(name);4383 const names = (this.name() || '').split(/\s/g); 4384 const index = names.indexOf(name); 4382 4385 if (index !== -1) { 4383 4386 names.splice(index, 1); … … 4397 4400 */ 4398 4401 setAttr(attr, val) { 4399 varfunc = this[SET + Util._capitalize(attr)];4402 const func = this[SET + Util._capitalize(attr)]; 4400 4403 if (Util._isFunction(func)) { 4401 4404 func.call(this, val); … … 4414 4417 } 4415 4418 _setAttr(key, val) { 4416 varoldVal = this.attrs[key];4419 const oldVal = this.attrs[key]; 4417 4420 if (oldVal === val && !Util.isObject(val)) { 4418 4421 return; … … 4430 4433 } 4431 4434 _setComponentAttr(key, component, val) { 4432 varoldVal;4435 let oldVal; 4433 4436 if (val !== undefined) { 4434 4437 oldVal = this.attrs[key]; … … 4445 4448 evt.target = this; 4446 4449 } 4447 varshouldStop = (eventType === MOUSEENTER$1 || eventType === MOUSELEAVE$1) &&4450 const shouldStop = (eventType === MOUSEENTER$1 || eventType === MOUSELEAVE$1) && 4448 4451 ((compareShape && 4449 4452 (this === compareShape || … … 4453 4456 this._fire(eventType, evt); 4454 4457 // simulate event bubbling 4455 varstopBubble = (eventType === MOUSEENTER$1 || eventType === MOUSELEAVE$1) &&4458 const stopBubble = (eventType === MOUSEENTER$1 || eventType === MOUSELEAVE$1) && 4456 4459 compareShape && 4457 4460 compareShape.isAncestorOf && … … 4522 4525 // drag & drop 4523 4526 _createDragElement(evt) { 4524 varpointerId = evt ? evt.pointerId : undefined;4525 varstage = this.getStage();4526 varap = this.getAbsolutePosition();4527 const pointerId = evt ? evt.pointerId : undefined; 4528 const stage = this.getStage(); 4529 const ap = this.getAbsolutePosition(); 4527 4530 if (!stage) { 4528 4531 return; 4529 4532 } 4530 varpos = stage._getPointerById(pointerId) ||4533 const pos = stage._getPointerById(pointerId) || 4531 4534 stage._changedPointerPositions[0] || 4532 4535 ap; … … 4566 4569 return; 4567 4570 } 4568 varnewNodePos = {4571 let newNodePos = { 4569 4572 x: pos.x - elem.offset.x, 4570 4573 y: pos.y - elem.offset.y, 4571 4574 }; 4572 vardbf = this.dragBoundFunc();4575 const dbf = this.dragBoundFunc(); 4573 4576 if (dbf !== undefined) { 4574 4577 const bounded = dbf.call(this, newNodePos, evt); … … 4617 4620 this._dragCleanup(); 4618 4621 this.on('mousedown.konva touchstart.konva', function (evt) { 4619 varshouldCheckButton = evt.evt['button'] !== undefined;4620 varcanDrag = !shouldCheckButton || Konva$2.dragButtons.indexOf(evt.evt['button']) >= 0;4622 const shouldCheckButton = evt.evt['button'] !== undefined; 4623 const canDrag = !shouldCheckButton || Konva$2.dragButtons.indexOf(evt.evt['button']) >= 0; 4621 4624 if (!canDrag) { 4622 4625 return; … … 4625 4628 return; 4626 4629 } 4627 varhasDraggingChild = false;4630 let hasDraggingChild = false; 4628 4631 DD._dragElements.forEach((elem) => { 4629 4632 if (this.isAncestorOf(elem.node)) { … … 4650 4653 * drag and drop mode 4651 4654 */ 4652 varstage = this.getStage();4655 const stage = this.getStage(); 4653 4656 if (!stage) { 4654 4657 return; … … 4717 4720 } 4718 4721 static _createNode(obj, container) { 4719 varclassName = Node.prototype.getClassName.call(obj), children = obj.children, no, len, n;4722 let className = Node.prototype.getClassName.call(obj), children = obj.children, no, len, n; 4720 4723 // if container was passed in, add it to attrs 4721 4724 if (container) { … … 5329 5332 } 5330 5333 const children = this.children || []; 5331 varresults = [];5334 const results = []; 5332 5335 children.forEach(function (child) { 5333 5336 if (filterFunc(child)) { … … 5400 5403 } 5401 5404 if (children.length > 1) { 5402 for ( vari = 0; i < children.length; i++) {5405 for (let i = 0; i < children.length; i++) { 5403 5406 this.add(children[i]); 5404 5407 } … … 5493 5496 */ 5494 5497 findOne(selector) { 5495 varresult = this._generalFind(selector, true);5498 const result = this._generalFind(selector, true); 5496 5499 return result.length > 0 ? result[0] : undefined; 5497 5500 } 5498 5501 _generalFind(selector, findOne) { 5499 varretArr = [];5502 const retArr = []; 5500 5503 this._descendants((node) => { 5501 5504 const valid = node._isMatch(selector); … … 5530 5533 // extenders 5531 5534 toObject() { 5532 varobj = Node.prototype.toObject.call(this);5535 const obj = Node.prototype.toObject.call(this); 5533 5536 obj.children = []; 5534 5537 this.getChildren().forEach((child) => { … … 5545 5548 */ 5546 5549 isAncestorOf(node) { 5547 varparent = node.getParent();5550 let parent = node.getParent(); 5548 5551 while (parent) { 5549 5552 if (parent._id === this._id) { … … 5556 5559 clone(obj) { 5557 5560 // call super method 5558 varnode = Node.prototype.clone.call(this, obj);5561 const node = Node.prototype.clone.call(this, obj); 5559 5562 this.getChildren().forEach(function (no) { 5560 5563 node.add(no.clone()); … … 5576 5579 */ 5577 5580 getAllIntersections(pos) { 5578 vararr = [];5581 const arr = []; 5579 5582 this.find('Shape').forEach((shape) => { 5580 5583 if (shape.isVisible() && shape.intersects(pos)) { … … 5604 5607 } 5605 5608 drawScene(can, top, bufferCanvas) { 5606 varlayer = this.getLayer(), canvas = can || (layer && layer.getCanvas()), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;5607 varcaching = canvas && canvas.isCache;5609 const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene; 5610 const caching = canvas && canvas.isCache; 5608 5611 if (!this.isVisible() && !caching) { 5609 5612 return this; … … 5611 5614 if (cachedSceneCanvas) { 5612 5615 context.save(); 5613 varm = this.getAbsoluteTransform(top).getMatrix();5616 const m = this.getAbsoluteTransform(top).getMatrix(); 5614 5617 context.transform(m[0], m[1], m[2], m[3], m[4], m[5]); 5615 5618 this._drawCachedSceneCanvas(context); … … 5625 5628 return this; 5626 5629 } 5627 varlayer = this.getLayer(), canvas = can || (layer && layer.hitCanvas), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;5630 const layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit; 5628 5631 if (cachedHitCanvas) { 5629 5632 context.save(); 5630 varm = this.getAbsoluteTransform(top).getMatrix();5633 const m = this.getAbsoluteTransform(top).getMatrix(); 5631 5634 context.transform(m[0], m[1], m[2], m[3], m[4], m[5]); 5632 5635 this._drawCachedHitCanvas(context); … … 5640 5643 _drawChildren(drawMethod, canvas, top, bufferCanvas) { 5641 5644 var _a; 5642 varcontext = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = (typeof clipWidth === 'number' && typeof clipHeight === 'number') ||5645 const context = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = (typeof clipWidth === 'number' && typeof clipHeight === 'number') || 5643 5646 clipFunc; 5644 5647 const selfCache = top === this; 5645 5648 if (hasClip) { 5646 5649 context.save(); 5647 vartransform = this.getAbsoluteTransform(top);5648 varm = transform.getMatrix();5650 const transform = this.getAbsoluteTransform(top); 5651 let m = transform.getMatrix(); 5649 5652 context.transform(m[0], m[1], m[2], m[3], m[4], m[5]); 5650 5653 context.beginPath(); … … 5654 5657 } 5655 5658 else { 5656 varclipX = this.clipX();5657 varclipY = this.clipY();5659 const clipX = this.clipX(); 5660 const clipY = this.clipY(); 5658 5661 context.rect(clipX || 0, clipY || 0, clipWidth, clipHeight); 5659 5662 } … … 5662 5665 context.transform(m[0], m[1], m[2], m[3], m[4], m[5]); 5663 5666 } 5664 varhasComposition = !selfCache &&5667 const hasComposition = !selfCache && 5665 5668 this.globalCompositeOperation() !== 'source-over' && 5666 5669 drawMethod === 'drawScene'; … … 5681 5684 getClientRect(config = {}) { 5682 5685 var _a; 5683 varskipTransform = config.skipTransform;5684 varrelativeTo = config.relativeTo;5685 varminX, minY, maxX, maxY;5686 varselfRect = {5686 const skipTransform = config.skipTransform; 5687 const relativeTo = config.relativeTo; 5688 let minX, minY, maxX, maxY; 5689 let selfRect = { 5687 5690 x: Infinity, 5688 5691 y: Infinity, … … 5690 5693 height: 0, 5691 5694 }; 5692 varthat = this;5695 const that = this; 5693 5696 (_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) { 5694 5697 // skip invisible children … … 5696 5699 return; 5697 5700 } 5698 varrect = child.getClientRect({5701 const rect = child.getClientRect({ 5699 5702 relativeTo: that, 5700 5703 skipShadow: config.skipShadow, … … 5720 5723 }); 5721 5724 // if child is group we need to make sure it has visible shapes inside 5722 varshapes = this.find('Shape');5723 varhasVisible = false;5724 for ( vari = 0; i < shapes.length; i++) {5725 varshape = shapes[i];5725 const shapes = this.find('Shape'); 5726 let hasVisible = false; 5727 for (let i = 0; i < shapes.length; i++) { 5728 const shape = shapes[i]; 5726 5729 if (shape._isVisible(this)) { 5727 5730 hasVisible = true; … … 5897 5900 5898 5901 // CONSTANTS 5899 varSTAGE = 'Stage', STRING = 'string', PX = 'px', MOUSEOUT = 'mouseout', MOUSELEAVE = 'mouseleave', MOUSEOVER = 'mouseover', MOUSEENTER = 'mouseenter', MOUSEMOVE = 'mousemove', MOUSEDOWN = 'mousedown', MOUSEUP = 'mouseup', POINTERMOVE = 'pointermove', POINTERDOWN = 'pointerdown', POINTERUP = 'pointerup', POINTERCANCEL = 'pointercancel', LOSTPOINTERCAPTURE = 'lostpointercapture', POINTEROUT = 'pointerout', POINTERLEAVE = 'pointerleave', POINTEROVER = 'pointerover', POINTERENTER = 'pointerenter', CONTEXTMENU = 'contextmenu', TOUCHSTART = 'touchstart', TOUCHEND = 'touchend', TOUCHMOVE = 'touchmove', TOUCHCANCEL = 'touchcancel', WHEEL = 'wheel', MAX_LAYERS_NUMBER = 5, EVENTS = [5902 const STAGE = 'Stage', STRING = 'string', PX = 'px', MOUSEOUT = 'mouseout', MOUSELEAVE = 'mouseleave', MOUSEOVER = 'mouseover', MOUSEENTER = 'mouseenter', MOUSEMOVE = 'mousemove', MOUSEDOWN = 'mousedown', MOUSEUP = 'mouseup', POINTERMOVE = 'pointermove', POINTERDOWN = 'pointerdown', POINTERUP = 'pointerup', POINTERCANCEL = 'pointercancel', LOSTPOINTERCAPTURE = 'lostpointercapture', POINTEROUT = 'pointerout', POINTERLEAVE = 'pointerleave', POINTEROVER = 'pointerover', POINTERENTER = 'pointerenter', CONTEXTMENU = 'contextmenu', TOUCHSTART = 'touchstart', TOUCHEND = 'touchend', TOUCHMOVE = 'touchmove', TOUCHCANCEL = 'touchcancel', WHEEL = 'wheel', MAX_LAYERS_NUMBER = 5, EVENTS = [ 5900 5903 [MOUSEENTER, '_pointerenter'], 5901 5904 [MOUSEDOWN, '_pointerdown'], … … 6056 6059 if (typeof container === STRING) { 6057 6060 if (container.charAt(0) === '.') { 6058 varclassName = container.slice(1);6061 const className = container.slice(1); 6059 6062 container = document.getElementsByClassName(className)[0]; 6060 6063 } … … 6091 6094 */ 6092 6095 clear() { 6093 varlayers = this.children, len = layers.length, n;6096 let layers = this.children, len = layers.length, n; 6094 6097 for (n = 0; n < len; n++) { 6095 6098 layers[n].clear(); … … 6107 6110 destroy() { 6108 6111 super.destroy(); 6109 varcontent = this.content;6112 const content = this.content; 6110 6113 if (content && Util._isInDocument(content)) { 6111 6114 this.container().removeChild(content); 6112 6115 } 6113 varindex = stages.indexOf(this);6116 const index = stages.indexOf(this); 6114 6117 if (index > -1) { 6115 6118 stages.splice(index, 1); … … 6155 6158 config.width = config.width || this.width(); 6156 6159 config.height = config.height || this.height(); 6157 varcanvas = new SceneCanvas({6160 const canvas = new SceneCanvas({ 6158 6161 width: config.width, 6159 6162 height: config.height, 6160 6163 pixelRatio: config.pixelRatio || 1, 6161 6164 }); 6162 var_context = canvas.getContext()._context;6163 varlayers = this.children;6165 const _context = canvas.getContext()._context; 6166 const layers = this.children; 6164 6167 if (config.x || config.y) { 6165 6168 _context.translate(-1 * config.x, -1 * config.y); … … 6169 6172 return; 6170 6173 } 6171 varlayerCanvas = layer._toKonvaCanvas(config);6174 const layerCanvas = layer._toKonvaCanvas(config); 6172 6175 _context.drawImage(layerCanvas._canvas, config.x, config.y, layerCanvas.getWidth() / layerCanvas.getPixelRatio(), layerCanvas.getHeight() / layerCanvas.getPixelRatio()); 6173 6176 }); … … 6191 6194 return null; 6192 6195 } 6193 varlayers = this.children, len = layers.length, end = len - 1, n;6196 let layers = this.children, len = layers.length, end = len - 1, n; 6194 6197 for (n = end; n >= 0; n--) { 6195 6198 const shape = layers[n].getIntersection(pos); … … 6201 6204 } 6202 6205 _resizeDOM() { 6203 varwidth = this.width();6204 varheight = this.height();6206 const width = this.width(); 6207 const height = this.height(); 6205 6208 if (this.content) { 6206 6209 // set content dimensions … … 6218 6221 add(layer, ...rest) { 6219 6222 if (arguments.length > 1) { 6220 for ( vari = 0; i < arguments.length; i++) {6223 for (let i = 0; i < arguments.length; i++) { 6221 6224 this.add(arguments[i]); 6222 6225 } … … 6224 6227 } 6225 6228 super.add(layer); 6226 varlength = this.children.length;6229 const length = this.children.length; 6227 6230 if (length > MAX_LAYERS_NUMBER) { 6228 6231 Util.warn('The stage has ' + … … 6308 6311 } 6309 6312 this.setPointersPositions(evt); 6310 vartargetShape = this._getTargetShape(eventType);6311 vareventsEnabled = !(Konva$2.isDragging() || Konva$2.isTransforming()) || Konva$2.hitOnDragEnabled;6313 const targetShape = this._getTargetShape(eventType); 6314 const eventsEnabled = !(Konva$2.isDragging() || Konva$2.isTransforming()) || Konva$2.hitOnDragEnabled; 6312 6315 if (targetShape && eventsEnabled) { 6313 6316 targetShape._fireAndBubble(events.pointerout, { evt: evt }); … … 6342 6345 } 6343 6346 this.setPointersPositions(evt); 6344 vartriggeredOnShape = false;6347 let triggeredOnShape = false; 6345 6348 this._changedPointerPositions.forEach((pos) => { 6346 varshape = this.getIntersection(pos);6349 const shape = this.getIntersection(pos); 6347 6350 DD.justDragged = false; 6348 6351 // probably we are staring a click … … 6390 6393 } 6391 6394 this.setPointersPositions(evt); 6392 vareventsEnabled = !(Konva$2.isDragging() || Konva$2.isTransforming()) || Konva$2.hitOnDragEnabled;6395 const eventsEnabled = !(Konva$2.isDragging() || Konva$2.isTransforming()) || Konva$2.hitOnDragEnabled; 6393 6396 if (!eventsEnabled) { 6394 6397 return; 6395 6398 } 6396 varprocessedShapesIds = {};6399 const processedShapesIds = {}; 6397 6400 let triggeredOnShape = false; 6398 vartargetShape = this._getTargetShape(eventType);6401 const targetShape = this._getTargetShape(eventType); 6399 6402 this._changedPointerPositions.forEach((pos) => { 6400 6403 const shape = (getCapturedShape(pos.id) || … … 6402 6405 const pointerId = pos.id; 6403 6406 const event = { evt: evt, pointerId }; 6404 vardifferentTarget = targetShape !== shape;6407 const differentTarget = targetShape !== shape; 6405 6408 if (differentTarget && targetShape) { 6406 6409 targetShape._fireAndBubble(events.pointerout, { ...event }, shape); … … 6452 6455 const clickStartShape = this[eventType + 'ClickStartShape']; 6453 6456 const clickEndShape = this[eventType + 'ClickEndShape']; 6454 varprocessedShapesIds = {};6457 const processedShapesIds = {}; 6455 6458 let triggeredOnShape = false; 6456 6459 this._changedPointerPositions.forEach((pos) => { … … 6533 6536 _contextmenu(evt) { 6534 6537 this.setPointersPositions(evt); 6535 varshape = this.getIntersection(this.getPointerPosition());6538 const shape = this.getIntersection(this.getPointerPosition()); 6536 6539 if (shape && shape.isListening()) { 6537 6540 shape._fireAndBubble(CONTEXTMENU, { evt: evt }); … … 6547 6550 _wheel(evt) { 6548 6551 this.setPointersPositions(evt); 6549 varshape = this.getIntersection(this.getPointerPosition());6552 const shape = this.getIntersection(this.getPointerPosition()); 6550 6553 if (shape && shape.isListening()) { 6551 6554 shape._fireAndBubble(WHEEL, { evt: evt }); … … 6586 6589 */ 6587 6590 setPointersPositions(evt) { 6588 varcontentPosition = this._getContentPosition(), x = null, y = null;6591 let contentPosition = this._getContentPosition(), x = null, y = null; 6589 6592 evt = evt ? evt : window.event; 6590 6593 // touch events … … 6636 6639 }; 6637 6640 } 6638 varrect = this.content.getBoundingClientRect();6641 const rect = this.content.getBoundingClientRect(); 6639 6642 return { 6640 6643 top: rect.top, … … 6659 6662 return; 6660 6663 } 6661 varcontainer = this.container();6664 const container = this.container(); 6662 6665 if (!container) { 6663 6666 throw 'Stage has no container. A container is required.'; … … 6723 6726 } 6724 6727 6725 varHAS_SHADOW = 'hasShadow';6726 varSHADOW_RGBA = 'shadowRGBA';6727 varpatternImage = 'patternImage';6728 varlinearGradient = 'linearGradient';6729 varradialGradient = 'radialGradient';6728 const HAS_SHADOW = 'hasShadow'; 6729 const SHADOW_RGBA = 'shadowRGBA'; 6730 const patternImage = 'patternImage'; 6731 const linearGradient = 'linearGradient'; 6732 const radialGradient = 'radialGradient'; 6730 6733 let dummyContext$1; 6731 6734 function getDummyContext$1() { … … 6929 6932 __getFillPattern() { 6930 6933 if (this.fillPatternImage()) { 6931 varctx = getDummyContext$1();6934 const ctx = getDummyContext$1(); 6932 6935 const pattern = ctx.createPattern(this.fillPatternImage(), this.fillPatternRepeat() || 'repeat'); 6933 6936 if (pattern && pattern.setTransform) { … … 6957 6960 } 6958 6961 __getLinearGradient() { 6959 varcolorStops = this.fillLinearGradientColorStops();6962 const colorStops = this.fillLinearGradientColorStops(); 6960 6963 if (colorStops) { 6961 varctx = getDummyContext$1();6962 varstart = this.fillLinearGradientStartPoint();6963 varend = this.fillLinearGradientEndPoint();6964 vargrd = ctx.createLinearGradient(start.x, start.y, end.x, end.y);6964 const ctx = getDummyContext$1(); 6965 const start = this.fillLinearGradientStartPoint(); 6966 const end = this.fillLinearGradientEndPoint(); 6967 const grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y); 6965 6968 // build color stops 6966 for ( varn = 0; n < colorStops.length; n += 2) {6969 for (let n = 0; n < colorStops.length; n += 2) { 6967 6970 grd.addColorStop(colorStops[n], colorStops[n + 1]); 6968 6971 } … … 6974 6977 } 6975 6978 __getRadialGradient() { 6976 varcolorStops = this.fillRadialGradientColorStops();6979 const colorStops = this.fillRadialGradientColorStops(); 6977 6980 if (colorStops) { 6978 varctx = getDummyContext$1();6979 varstart = this.fillRadialGradientStartPoint();6980 varend = this.fillRadialGradientEndPoint();6981 vargrd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius());6981 const ctx = getDummyContext$1(); 6982 const start = this.fillRadialGradientStartPoint(); 6983 const end = this.fillRadialGradientEndPoint(); 6984 const grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius()); 6982 6985 // build color stops 6983 for ( varn = 0; n < colorStops.length; n += 2) {6986 for (let n = 0; n < colorStops.length; n += 2) { 6984 6987 grd.addColorStop(colorStops[n], colorStops[n + 1]); 6985 6988 } … … 6994 6997 return; 6995 6998 } 6996 varrgba = Util.colorToRGBA(this.shadowColor());6999 const rgba = Util.colorToRGBA(this.shadowColor()); 6997 7000 if (rgba) { 6998 7001 return ('rgba(' + … … 7077 7080 */ 7078 7081 intersects(point) { 7079 varstage = this.getStage();7082 const stage = this.getStage(); 7080 7083 if (!stage) { 7081 7084 return false; … … 7149 7152 */ 7150 7153 getSelfRect() { 7151 varsize = this.size();7154 const size = this.size(); 7152 7155 return { 7153 7156 x: this._centroid ? -size.width / 2 : 0, … … 7205 7208 // 2 - when we are caching current 7206 7209 // 3 - when node is cached and we need to draw it into layer 7207 varlayer = this.getLayer();7208 varcanvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferContext;7209 varskipBuffer = canvas.isCache;7210 varcachingSelf = top === this;7210 const layer = this.getLayer(); 7211 let canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferContext; 7212 const skipBuffer = canvas.isCache; 7213 const cachingSelf = top === this; 7211 7214 if (!this.isVisible() && !cachingSelf) { 7212 7215 return this; … … 7215 7218 if (cachedCanvas) { 7216 7219 context.save(); 7217 varm = this.getAbsoluteTransform(top).getMatrix();7220 const m = this.getAbsoluteTransform(top).getMatrix(); 7218 7221 context.transform(m[0], m[1], m[2], m[3], m[4], m[5]); 7219 7222 this._drawCachedSceneCanvas(context); … … 7238 7241 drawFunc.call(this, bufferContext, this); 7239 7242 bufferContext.restore(); 7240 varratio = bc.pixelRatio;7243 const ratio = bc.pixelRatio; 7241 7244 if (hasShadow) { 7242 7245 context._applyShadow(this); … … 7266 7269 return this; 7267 7270 } 7268 varlayer = this.getLayer(), canvas = can || layer.hitCanvas, context = canvas && canvas.getContext(), drawFunc = this.hitFunc() || this.sceneFunc(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;7271 const layer = this.getLayer(), canvas = can || layer.hitCanvas, context = canvas && canvas.getContext(), drawFunc = this.hitFunc() || this.sceneFunc(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit; 7269 7272 if (!this.colorKey) { 7270 7273 Util.warn('Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()'); … … 7272 7275 if (cachedHitCanvas) { 7273 7276 context.save(); 7274 varm = this.getAbsoluteTransform(top).getMatrix();7277 const m = this.getAbsoluteTransform(top).getMatrix(); 7275 7278 context.transform(m[0], m[1], m[2], m[3], m[4], m[5]); 7276 7279 this._drawCachedHitCanvas(context); … … 7285 7288 const selfCache = this === top; 7286 7289 if (!selfCache) { 7287 varo = this.getAbsoluteTransform(top).getMatrix();7290 const o = this.getAbsoluteTransform(top).getMatrix(); 7288 7291 context.transform(o[0], o[1], o[2], o[3], o[4], o[5]); 7289 7292 } … … 7305 7308 */ 7306 7309 drawHitFromCache(alphaThreshold = 0) { 7307 varcachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight(), hitImageData, hitData, len, rgbColorKey, i, alpha;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; 7308 7311 hitContext.clear(); 7309 7312 hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight); … … 8369 8372 8370 8373 // constants 8371 varHASH = '#', BEFORE_DRAW = 'beforeDraw', DRAW = 'draw',8374 const HASH = '#', BEFORE_DRAW = 'beforeDraw', DRAW = 'draw', 8372 8375 /* 8373 8376 * 2 - 3 - 4 … … 8484 8487 setZIndex(index) { 8485 8488 super.setZIndex(index); 8486 varstage = this.getStage();8489 const stage = this.getStage(); 8487 8490 if (stage && stage.content) { 8488 8491 stage.content.removeChild(this.getNativeCanvasElement()); … … 8498 8501 moveToTop() { 8499 8502 Node.prototype.moveToTop.call(this); 8500 varstage = this.getStage();8503 const stage = this.getStage(); 8501 8504 if (stage && stage.content) { 8502 8505 stage.content.removeChild(this.getNativeCanvasElement()); … … 8506 8509 } 8507 8510 moveUp() { 8508 varmoved = Node.prototype.moveUp.call(this);8511 const moved = Node.prototype.moveUp.call(this); 8509 8512 if (!moved) { 8510 8513 return false; 8511 8514 } 8512 varstage = this.getStage();8515 const stage = this.getStage(); 8513 8516 if (!stage || !stage.content) { 8514 8517 return false; … … 8526 8529 moveDown() { 8527 8530 if (Node.prototype.moveDown.call(this)) { 8528 varstage = this.getStage();8531 const stage = this.getStage(); 8529 8532 if (stage) { 8530 varchildren = stage.children;8533 const children = stage.children; 8531 8534 if (stage.content) { 8532 8535 stage.content.removeChild(this.getNativeCanvasElement()); … … 8541 8544 moveToBottom() { 8542 8545 if (Node.prototype.moveToBottom.call(this)) { 8543 varstage = this.getStage();8546 const stage = this.getStage(); 8544 8547 if (stage) { 8545 varchildren = stage.children;8548 const children = stage.children; 8546 8549 if (stage.content) { 8547 8550 stage.content.removeChild(this.getNativeCanvasElement()); … … 8557 8560 } 8558 8561 remove() { 8559 var_canvas = this.getNativeCanvasElement();8562 const _canvas = this.getNativeCanvasElement(); 8560 8563 Node.prototype.remove.call(this); 8561 8564 if (_canvas && _canvas.parentNode && Util._isInDocument(_canvas)) { … … 8574 8577 } 8575 8578 _validateAdd(child) { 8576 vartype = child.getType();8579 const type = child.getType(); 8577 8580 if (type !== 'Group' && type !== 'Shape') { 8578 8581 Util.throw('You may only add groups and shapes to a layer.'); … … 8671 8674 // in some cases antialiased area may be bigger than 1px 8672 8675 // it is possible if we will cache node, then scale it a lot 8673 varspiralSearchDistance = 1;8674 varcontinueSearch = false;8676 let spiralSearchDistance = 1; 8677 let continueSearch = false; 8675 8678 while (true) { 8676 8679 for (let i = 0; i < INTERSECTION_OFFSETS_LEN; i++) { … … 8728 8731 } 8729 8732 drawScene(can, top) { 8730 varlayer = this.getLayer(), canvas = can || (layer && layer.getCanvas());8733 const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()); 8731 8734 this._fire(BEFORE_DRAW, { 8732 8735 node: this, … … 8742 8745 } 8743 8746 drawHit(can, top) { 8744 varlayer = this.getLayer(), canvas = can || (layer && layer.hitCanvas);8747 const layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas); 8745 8748 if (layer && layer.clearBeforeDraw()) { 8746 8749 layer.getHitCanvas().getContext().clear(); … … 8786 8789 return; 8787 8790 } 8788 varparent = this.parent;8789 varadded = !!this.hitCanvas._canvas.parentNode;8791 const parent = this.parent; 8792 const added = !!this.hitCanvas._canvas.parentNode; 8790 8793 if (added) { 8791 8794 parent.content.removeChild(this.hitCanvas._canvas); … … 8924 8927 class Group extends Container { 8925 8928 _validateAdd(child) { 8926 vartype = child.getType();8929 const type = child.getType(); 8927 8930 if (type !== 'Group' && type !== 'Shape') { 8928 8931 Util.throw('You may only add groups and shapes to groups.'); … … 9121 9124 } 9122 9125 } 9123 for ( let key in layerHash) {9126 for (const key in layerHash) { 9124 9127 if (!layerHash.hasOwnProperty(key)) { 9125 9128 continue; … … 9149 9152 Animation.animRunning = false; 9150 9153 9151 varblacklist = {9154 let blacklist = { 9152 9155 node: 1, 9153 9156 duration: 1, … … 9175 9178 } 9176 9179 fire(str) { 9177 varhandler = this[str];9180 const handler = this[str]; 9178 9181 if (handler) { 9179 9182 handler(); … … 9254 9257 } 9255 9258 onEnterFrame() { 9256 vart = this.getTimer() - this._startTime;9259 const t = this.getTimer() - this._startTime; 9257 9260 if (this.state === PLAYING) { 9258 9261 this.setTime(t); … … 9298 9301 class Tween { 9299 9302 constructor(config) { 9300 varthat = this, node = config.node, nodeId = node._id, duration, easing = config.easing || Easings.Linear, yoyo = !!config.yoyo, key;9303 let that = this, node = config.node, nodeId = node._id, duration, easing = config.easing || Easings.Linear, yoyo = !!config.yoyo, key; 9301 9304 if (typeof config.duration === 'undefined') { 9302 9305 duration = 0.3; … … 9311 9314 this.node = node; 9312 9315 this._id = idCounter++; 9313 varlayers = node.getLayer() ||9316 const layers = node.getLayer() || 9314 9317 (node instanceof Konva$2['Stage'] ? node.getLayers() : null); 9315 9318 if (!layers) { … … 9346 9349 } 9347 9350 _addAttr(key, end) { 9348 varnode = this.node, nodeId = node._id, start, diff, tweenId, n, len, trueEnd, trueStart, endRGBA;9351 let node = this.node, nodeId = node._id, start, diff, tweenId, n, len, trueEnd, trueStart, endRGBA; 9349 9352 // remove conflict from tween map if it exists 9350 9353 tweenId = Tween.tweens[nodeId][key]; … … 9377 9380 } 9378 9381 else { 9379 varstartRGBA = Util.colorToRGBA(start[n]);9382 const startRGBA = Util.colorToRGBA(start[n]); 9380 9383 endRGBA = Util.colorToRGBA(end[n]); 9381 9384 start[n] = startRGBA; … … 9418 9421 } 9419 9422 _tweenFunc(i) { 9420 varnode = this.node, attrs = Tween.attrs[node._id][this._id], key, attr, start, diff, newVal, n, len, end;9423 let node = this.node, attrs = Tween.attrs[node._id][this._id], key, attr, start, diff, newVal, n, len, end; 9421 9424 for (key in attrs) { 9422 9425 attr = attrs[key]; … … 9482 9485 }; 9483 9486 this.tween.onFinish = () => { 9484 varnode = this.node;9487 const node = this.node; 9485 9488 // after tweening points of line we need to set original end 9486 varattrs = Tween.attrs[node._id][this._id];9489 const attrs = Tween.attrs[node._id][this._id]; 9487 9490 if (attrs.points && attrs.points.trueEnd) { 9488 9491 node.setAttr('points', attrs.points.trueEnd); … … 9493 9496 }; 9494 9497 this.tween.onReset = () => { 9495 varnode = this.node;9498 const node = this.node; 9496 9499 // after tweening points of line we need to set original start 9497 varattrs = Tween.attrs[node._id][this._id];9500 const attrs = Tween.attrs[node._id][this._id]; 9498 9501 if (attrs.points && attrs.points.trueStart) { 9499 9502 node.points(attrs.points.trueStart); … … 9576 9579 */ 9577 9580 destroy() { 9578 varnodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId], key;9581 let nodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId], key; 9579 9582 this.pause(); 9580 9583 for (key in attrs) { … … 9601 9604 */ 9602 9605 Node.prototype.to = function (params) { 9603 varonFinish = params.onFinish;9606 const onFinish = params.onFinish; 9604 9607 params.node = this; 9605 9608 params.onFinish = function () { … … 9609 9612 } 9610 9613 }; 9611 vartween = new Tween(params);9614 const tween = new Tween(params); 9612 9615 tween.play(); 9613 9616 }; … … 9627 9630 */ 9628 9631 BackEaseIn(t, b, c, d) { 9629 vars = 1.70158;9632 const s = 1.70158; 9630 9633 return c * (t /= d) * t * ((s + 1) * t - s) + b; 9631 9634 }, … … 9636 9639 */ 9637 9640 BackEaseOut(t, b, c, d) { 9638 vars = 1.70158;9641 const s = 1.70158; 9639 9642 return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; 9640 9643 }, … … 9645 9648 */ 9646 9649 BackEaseInOut(t, b, c, d) { 9647 vars = 1.70158;9650 let s = 1.70158; 9648 9651 if ((t /= d / 2) < 1) { 9649 9652 return (c / 2) * (t * t * (((s *= 1.525) + 1) * t - s)) + b; … … 9658 9661 ElasticEaseIn(t, b, c, d, a, p) { 9659 9662 // added s = 0 9660 vars = 0;9663 let s = 0; 9661 9664 if (t === 0) { 9662 9665 return b; … … 9686 9689 ElasticEaseOut(t, b, c, d, a, p) { 9687 9690 // added s = 0 9688 vars = 0;9691 let s = 0; 9689 9692 if (t === 0) { 9690 9693 return b; … … 9714 9717 ElasticEaseInOut(t, b, c, d, a, p) { 9715 9718 // added s = 0 9716 vars = 0;9719 let s = 0; 9717 9720 if (t === 0) { 9718 9721 return b; … … 9968 9971 class Arc extends Shape { 9969 9972 _sceneFunc(context) { 9970 varangle = Konva$2.getAngle(this.angle()), clockwise = this.clockwise();9973 const angle = Konva$2.getAngle(this.angle()), clockwise = this.clockwise(); 9971 9974 context.beginPath(); 9972 9975 context.arc(0, 0, this.outerRadius(), 0, angle, clockwise); … … 10074 10077 10075 10078 function getControlPoints(x0, y0, x1, y1, x2, y2, t) { 10076 vard01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), fa = (t * d01) / (d01 + d12), fb = (t * d12) / (d01 + d12), p1x = x1 - fa * (x2 - x0), p1y = y1 - fa * (y2 - y0), p2x = x1 + fb * (x2 - x0), p2y = y1 + fb * (y2 - y0);10079 const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), fa = (t * d01) / (d01 + d12), fb = (t * d12) / (d01 + d12), p1x = x1 - fa * (x2 - x0), p1y = y1 - fa * (y2 - y0), p2x = x1 + fb * (x2 - x0), p2y = y1 + fb * (y2 - y0); 10077 10080 return [p1x, p1y, p2x, p2y]; 10078 10081 } 10079 10082 function expandPoints(p, tension) { 10080 var len = p.length, allPoints = [], n, cp;10081 for ( n = 2; n < len - 2; n += 2) {10082 c p = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension);10083 const len = p.length, allPoints = []; 10084 for (let n = 2; n < len - 2; n += 2) { 10085 const cp = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension); 10083 10086 if (isNaN(cp[0])) { 10084 10087 continue; … … 10196 10199 } 10197 10200 _sceneFunc(context) { 10198 varpoints = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier(), tp, len, n;10201 let points = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier(), tp, len, n; 10199 10202 if (!length) { 10200 10203 return; … … 10252 10255 } 10253 10256 _getTensionPointsClosed() { 10254 varp = this.points(), len = p.length, tension = this.tension(), firstControlPoints = getControlPoints(p[len - 2], p[len - 1], p[0], p[1], p[2], p[3], tension), lastControlPoints = getControlPoints(p[len - 4], p[len - 3], p[len - 2], p[len - 1], p[0], p[1], tension), middle = expandPoints(p, tension), tp = [firstControlPoints[2], firstControlPoints[3]]10257 const p = this.points(), len = p.length, tension = this.tension(), firstControlPoints = getControlPoints(p[len - 2], p[len - 1], p[0], p[1], p[2], p[3], tension), lastControlPoints = getControlPoints(p[len - 4], p[len - 3], p[len - 2], p[len - 1], p[0], p[1], tension), middle = expandPoints(p, tension), tp = [firstControlPoints[2], firstControlPoints[3]] 10255 10258 .concat(middle) 10256 10259 .concat([ … … 10276 10279 // overload size detection 10277 10280 getSelfRect() { 10278 varpoints = this.points();10281 let points = this.points(); 10279 10282 if (points.length < 4) { 10280 10283 return { … … 10297 10300 points = this.points(); 10298 10301 } 10299 varminX = points[0];10300 varmaxX = points[0];10301 varminY = points[1];10302 varmaxY = points[1];10303 varx, y;10304 for ( vari = 0; i < points.length / 2; i++) {10302 let minX = points[0]; 10303 let maxX = points[0]; 10304 let minY = points[1]; 10305 let maxY = points[1]; 10306 let x, y; 10307 for (let i = 0; i < points.length / 2; i++) { 10305 10308 x = points[i * 2]; 10306 10309 y = points[i * 2 + 1]; … … 11075 11078 const binomialCoefficients = [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]]; 11076 11079 const getCubicArcLength = (xs, ys, t) => { 11077 let z;11078 11080 let sum; 11079 11081 let correctedT; … … 11082 11084 }*/ 11083 11085 const n = 20; 11084 z = t / 2;11086 const z = t / 2; 11085 11087 sum = 0; 11086 11088 for (let i = 0; i < n; i++) { … … 11292 11294 } 11293 11295 _sceneFunc(context) { 11294 varca = this.dataArray;11296 const ca = this.dataArray; 11295 11297 // context position 11296 11298 context.beginPath(); 11297 varisClosed = false;11298 for ( varn = 0; n < ca.length; n++) {11299 varc = ca[n].command;11300 varp = ca[n].points;11299 let isClosed = false; 11300 for (let n = 0; n < ca.length; n++) { 11301 const c = ca[n].command; 11302 const p = ca[n].points; 11301 11303 switch (c) { 11302 11304 case 'L': … … 11339 11341 } 11340 11342 getSelfRect() { 11341 varpoints = [];11343 let points = []; 11342 11344 this.dataArray.forEach(function (data) { 11343 11345 if (data.command === 'A') { 11344 11346 // Approximates by breaking curve into line segments 11345 varstart = data.points[4];11347 const start = data.points[4]; 11346 11348 // 4 = theta 11347 vardTheta = data.points[5];11349 const dTheta = data.points[5]; 11348 11350 // 5 = dTheta 11349 varend = data.points[4] + dTheta;11350 varinc = Math.PI / 180.0;11351 const end = data.points[4] + dTheta; 11352 let inc = Math.PI / 180.0; 11351 11353 // 1 degree resolution 11352 11354 if (Math.abs(start - end) < inc) { … … 11380 11382 } 11381 11383 }); 11382 varminX = points[0];11383 varmaxX = points[0];11384 varminY = points[1];11385 varmaxY = points[1];11386 varx, y;11387 for ( vari = 0; i < points.length / 2; i++) {11384 let minX = points[0]; 11385 let maxX = points[0]; 11386 let minY = points[1]; 11387 let maxY = points[1]; 11388 let x, y; 11389 for (let i = 0; i < points.length / 2; i++) { 11388 11390 x = points[i * 2]; 11389 11391 y = points[i * 2 + 1]; … … 11433 11435 static getPathLength(dataArray) { 11434 11436 let pathLength = 0; 11435 for ( vari = 0; i < dataArray.length; ++i) {11437 for (let i = 0; i < dataArray.length; ++i) { 11436 11438 pathLength += dataArray[i].pathLength; 11437 11439 } … … 11439 11441 } 11440 11442 static getPointAtLengthOfDataArray(length, dataArray) { 11441 var point, i = 0, ii = dataArray.length;11443 let points, i = 0, ii = dataArray.length; 11442 11444 if (!ii) { 11443 11445 return null; … … 11448 11450 } 11449 11451 if (i === ii) { 11450 point = dataArray[i - 1].points.slice(-2);11452 points = dataArray[i - 1].points.slice(-2); 11451 11453 return { 11452 x: point [0],11453 y: point [1],11454 x: points[0], 11455 y: points[1], 11454 11456 }; 11455 11457 } 11456 11458 if (length < 0.01) { 11457 point = dataArray[i].points.slice(0, 2);11459 points = dataArray[i].points.slice(0, 2); 11458 11460 return { 11459 x: point [0],11460 y: point [1],11461 x: points[0], 11462 y: points[1], 11461 11463 }; 11462 11464 } 11463 varcp = dataArray[i];11464 varp = cp.points;11465 const cp = dataArray[i]; 11466 const p = cp.points; 11465 11467 switch (cp.command) { 11466 11468 case 'L': … … 11520 11522 return (1 - t) * (1 - t) * (1 - t); 11521 11523 } 11522 varx = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct);11523 vary = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct);11524 const x = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct); 11525 const y = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct); 11524 11526 return { 11525 11527 x: x, … … 11537 11539 return (1 - t) * (1 - t); 11538 11540 } 11539 varx = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct);11540 vary = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct);11541 const x = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct); 11542 const y = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct); 11541 11543 return { 11542 11544 x: x, … … 11545 11547 } 11546 11548 static getPointOnEllipticalArc(cx, cy, rx, ry, theta, psi) { 11547 varcosPsi = Math.cos(psi), sinPsi = Math.sin(psi);11548 varpt = {11549 const cosPsi = Math.cos(psi), sinPsi = Math.sin(psi); 11550 const pt = { 11549 11551 x: rx * Math.cos(theta), 11550 11552 y: ry * Math.sin(theta), … … 11588 11590 } 11589 11591 // command string 11590 varcs = data;11592 let cs = data; 11591 11593 // command chars 11592 varcc = [11594 const cc = [ 11593 11595 'm', 11594 11596 'M', … … 11619 11621 } 11620 11622 // create array 11621 vararr = cs.split('|');11622 varca = [];11623 varcoords = [];11623 const arr = cs.split('|'); 11624 const ca = []; 11625 const coords = []; 11624 11626 // init context point 11625 varcpx = 0;11626 varcpy = 0;11627 varre = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;11628 varmatch;11627 let cpx = 0; 11628 let cpy = 0; 11629 const re = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi; 11630 let match; 11629 11631 for (n = 1; n < arr.length; n++) { 11630 varstr = arr[n];11631 varc = str.charAt(0);11632 let str = arr[n]; 11633 let c = str.charAt(0); 11632 11634 str = str.slice(1); 11633 11635 coords.length = 0; … … 11638 11640 // coords.push(match[0]); 11639 11641 // } 11640 varp = [];11641 for ( varj = 0, jlen = coords.length; j < jlen; j++) {11642 const p = []; 11643 for (let j = 0, jlen = coords.length; j < jlen; j++) { 11642 11644 // extra case for merged flags 11643 11645 if (coords[j] === '00') { … … 11645 11647 continue; 11646 11648 } 11647 varparsed = parseFloat(coords[j]);11649 const parsed = parseFloat(coords[j]); 11648 11650 if (!isNaN(parsed)) { 11649 11651 p.push(parsed); … … 11658 11660 break; 11659 11661 } 11660 varcmd = '';11661 varpoints = [];11662 varstartX = cpx, startY = cpy;11662 let cmd = ''; 11663 let points = []; 11664 const startX = cpx, startY = cpy; 11663 11665 // Move var from within the switch to up here (jshint) 11664 11666 var prevCmd, ctlPtx, ctlPty; // Ss, Tt … … 11688 11690 // to the the first point of the path (if any). 11689 11691 if (ca.length > 2 && ca[ca.length - 1].command === 'z') { 11690 for ( varidx = ca.length - 2; idx >= 0; idx--) {11692 for (let idx = ca.length - 2; idx >= 0; idx--) { 11691 11693 if (ca[idx].command === 'M') { 11692 11694 cpx = ca[idx].points[0] + dx; … … 11857 11859 } 11858 11860 static calcLength(x, y, cmd, points) { 11859 varlen, p1, p2, t;11860 varpath = Path;11861 let len, p1, p2, t; 11862 const path = Path; 11861 11863 switch (cmd) { 11862 11864 case 'L': … … 11905 11907 static convertEndpointToCenterParameterization(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg) { 11906 11908 // Derived from: http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes 11907 varpsi = psiDeg * (Math.PI / 180.0);11908 varxp = (Math.cos(psi) * (x1 - x2)) / 2.0 + (Math.sin(psi) * (y1 - y2)) / 2.0;11909 varyp = (-1 * Math.sin(psi) * (x1 - x2)) / 2.0 +11909 const psi = psiDeg * (Math.PI / 180.0); 11910 const xp = (Math.cos(psi) * (x1 - x2)) / 2.0 + (Math.sin(psi) * (y1 - y2)) / 2.0; 11911 const yp = (-1 * Math.sin(psi) * (x1 - x2)) / 2.0 + 11910 11912 (Math.cos(psi) * (y1 - y2)) / 2.0; 11911 varlambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);11913 const lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry); 11912 11914 if (lambda > 1) { 11913 11915 rx *= Math.sqrt(lambda); 11914 11916 ry *= Math.sqrt(lambda); 11915 11917 } 11916 varf = Math.sqrt((rx * rx * (ry * ry) - rx * rx * (yp * yp) - ry * ry * (xp * xp)) /11918 let f = Math.sqrt((rx * rx * (ry * ry) - rx * rx * (yp * yp) - ry * ry * (xp * xp)) / 11917 11919 (rx * rx * (yp * yp) + ry * ry * (xp * xp))); 11918 11920 if (fa === fs) { … … 11922 11924 f = 0; 11923 11925 } 11924 varcxp = (f * rx * yp) / ry;11925 varcyp = (f * -ry * xp) / rx;11926 varcx = (x1 + x2) / 2.0 + Math.cos(psi) * cxp - Math.sin(psi) * cyp;11927 varcy = (y1 + y2) / 2.0 + Math.sin(psi) * cxp + Math.cos(psi) * cyp;11928 varvMag = function (v) {11926 const cxp = (f * rx * yp) / ry; 11927 const cyp = (f * -ry * xp) / rx; 11928 const cx = (x1 + x2) / 2.0 + Math.cos(psi) * cxp - Math.sin(psi) * cyp; 11929 const cy = (y1 + y2) / 2.0 + Math.sin(psi) * cxp + Math.cos(psi) * cyp; 11930 const vMag = function (v) { 11929 11931 return Math.sqrt(v[0] * v[0] + v[1] * v[1]); 11930 11932 }; 11931 varvRatio = function (u, v) {11933 const vRatio = function (u, v) { 11932 11934 return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v)); 11933 11935 }; 11934 varvAngle = function (u, v) {11936 const vAngle = function (u, v) { 11935 11937 return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v)); 11936 11938 }; 11937 vartheta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);11938 varu = [(xp - cxp) / rx, (yp - cyp) / ry];11939 varv = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];11940 vardTheta = vAngle(u, v);11939 const theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]); 11940 const u = [(xp - cxp) / rx, (yp - cyp) / ry]; 11941 const v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry]; 11942 let dTheta = vAngle(u, v); 11941 11943 if (vRatio(u, v) <= -1) { 11942 11944 dTheta = Math.PI; … … 12074 12076 _sceneFunc(ctx) { 12075 12077 super._sceneFunc(ctx); 12076 varPI2 = Math.PI * 2;12077 varpoints = this.points();12078 vartp = points;12079 varfromTension = this.tension() !== 0 && points.length > 4;12078 const PI2 = Math.PI * 2; 12079 const points = this.points(); 12080 let tp = points; 12081 const fromTension = this.tension() !== 0 && points.length > 4; 12080 12082 if (fromTension) { 12081 12083 tp = this.getTensionPoints(); 12082 12084 } 12083 varlength = this.pointerLength();12084 varn = points.length;12085 vardx, dy;12085 const length = this.pointerLength(); 12086 const n = points.length; 12087 let dx, dy; 12086 12088 if (fromTension) { 12087 12089 const lp = [ … … 12102 12104 dy = points[n - 1] - points[n - 3]; 12103 12105 } 12104 varradians = (Math.atan2(dy, dx) + PI2) % PI2;12105 varwidth = this.pointerWidth();12106 const radians = (Math.atan2(dy, dx) + PI2) % PI2; 12107 const width = this.pointerWidth(); 12106 12108 if (this.pointerAtEnding()) { 12107 12109 ctx.save(); … … 12140 12142 // here is a tricky part 12141 12143 // we need to disable dash for arrow pointers 12142 varisDashEnabled = this.dashEnabled();12144 const isDashEnabled = this.dashEnabled(); 12143 12145 if (isDashEnabled) { 12144 12146 // manually disable dash for head … … 12450 12452 class Ellipse extends Shape { 12451 12453 _sceneFunc(context) { 12452 varrx = this.radiusX(), ry = this.radiusY();12454 const rx = this.radiusX(), ry = this.radiusY(); 12453 12455 context.beginPath(); 12454 12456 context.save(); … … 12697 12699 } 12698 12700 _hitFunc(context) { 12699 varwidth = this.width(), height = this.height(), cornerRadius = this.cornerRadius();12701 const width = this.width(), height = this.height(), cornerRadius = this.cornerRadius(); 12700 12702 context.beginPath(); 12701 12703 if (!cornerRadius) { … … 12731 12733 */ 12732 12734 static fromURL(url, callback, onError = null) { 12733 varimg = Util.createImageElement();12735 const img = Util.createImageElement(); 12734 12736 img.onload = function () { 12735 varimage = new Image({12737 const image = new Image({ 12736 12738 image: img, 12737 12739 }); … … 12858 12860 12859 12861 // constants 12860 varATTR_CHANGE_LIST$2 = [12862 const ATTR_CHANGE_LIST$2 = [ 12861 12863 'fontFamily', 12862 12864 'fontSize', … … 12959 12961 } 12960 12962 _addListeners(text) { 12961 varthat = this, n;12962 varfunc = function () {12963 let that = this, n; 12964 const func = function () { 12963 12965 that._sync(); 12964 12966 }; … … 12975 12977 } 12976 12978 _sync() { 12977 vartext = this.getText(), tag = this.getTag(), width, height, pointerDirection, pointerWidth, x, y, pointerHeight;12979 let text = this.getText(), tag = this.getTag(), width, height, pointerDirection, pointerWidth, x, y, pointerHeight; 12978 12980 if (text && tag) { 12979 12981 width = text.width(); … … 13031 13033 class Tag extends Shape { 13032 13034 _sceneFunc(context) { 13033 varwidth = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius();13035 const width = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius(); 13034 13036 let topLeft = 0; 13035 13037 let topRight = 0; … … 13083 13085 } 13084 13086 getSelfRect() { 13085 varx = 0, y = 0, pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), direction = this.pointerDirection(), width = this.width(), height = this.height();13087 let x = 0, y = 0, pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), direction = this.pointerDirection(), width = this.width(), height = this.height(); 13086 13088 if (direction === UP) { 13087 13089 y -= pointerHeight; … … 13246 13248 class Rect extends Shape { 13247 13249 _sceneFunc(context) { 13248 varcornerRadius = this.cornerRadius(), width = this.width(), height = this.height();13250 const cornerRadius = this.cornerRadius(), width = this.width(), height = this.height(); 13249 13251 context.beginPath(); 13250 13252 if (!cornerRadius) { … … 13378 13380 context.beginPath(); 13379 13381 context.moveTo(points[0].x, points[0].y); 13380 for ( varn = 1; n < points.length; n++) {13382 for (let n = 1; n < points.length; n++) { 13381 13383 context.lineTo(points[n].x, points[n].y); 13382 13384 } … … 13388 13390 const radius = this.attrs.radius || 0; 13389 13391 const points = []; 13390 for ( varn = 0; n < sides; n++) {13392 for (let n = 0; n < sides; n++) { 13391 13393 points.push({ 13392 13394 x: radius * Math.sin((n * 2 * Math.PI) / sides), … … 13398 13400 getSelfRect() { 13399 13401 const points = this._getPoints(); 13400 varminX = points[0].x;13401 varmaxX = points[0].y;13402 varminY = points[0].x;13403 varmaxY = points[0].y;13402 let minX = points[0].x; 13403 let maxX = points[0].y; 13404 let minY = points[0].x; 13405 let maxY = points[0].y; 13404 13406 points.forEach((point) => { 13405 13407 minX = Math.min(minX, point.x); … … 13461 13463 Factory.addGetterSetter(RegularPolygon, 'sides', 0, getNumberValidator()); 13462 13464 13463 varPIx2 = Math.PI * 2;13465 const PIx2 = Math.PI * 2; 13464 13466 /** 13465 13467 * Ring constructor … … 13733 13735 this.anim = new Animation(() => { 13734 13736 // if we don't need to redraw layer we should return false 13735 varupdated = this._updated;13737 const updated = this._updated; 13736 13738 this._updated = false; 13737 13739 return updated; … … 13754 13756 } 13755 13757 _sceneFunc(context) { 13756 varanim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), x = set[ix4 + 0], y = set[ix4 + 1], width = set[ix4 + 2], height = set[ix4 + 3], image = this.image();13758 const anim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), x = set[ix4 + 0], y = set[ix4 + 1], width = set[ix4 + 2], height = set[ix4 + 3], image = this.image(); 13757 13759 if (this.hasFill() || this.hasStroke()) { 13758 13760 context.beginPath(); … … 13763 13765 if (image) { 13764 13766 if (offsets) { 13765 varoffset = offsets[anim], ix2 = index * 2;13767 const offset = offsets[anim], ix2 = index * 2; 13766 13768 context.drawImage(image, x, y, width, height, offset[ix2 + 0], offset[ix2 + 1], width, height); 13767 13769 } … … 13772 13774 } 13773 13775 _hitFunc(context) { 13774 varanim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), width = set[ix4 + 2], height = set[ix4 + 3];13776 const anim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), width = set[ix4 + 2], height = set[ix4 + 3]; 13775 13777 context.beginPath(); 13776 13778 if (offsets) { 13777 varoffset = offsets[anim];13778 varix2 = index * 2;13779 const offset = offsets[anim]; 13780 const ix2 = index * 2; 13779 13781 context.rect(offset[ix2 + 0], offset[ix2 + 1], width, height); 13780 13782 } … … 13789 13791 } 13790 13792 _setInterval() { 13791 varthat = this;13793 const that = this; 13792 13794 this.interval = setInterval(function () { 13793 13795 that._updateIndex(); … … 13803 13805 return; 13804 13806 } 13805 varlayer = this.getLayer();13807 const layer = this.getLayer(); 13806 13808 /* 13807 13809 * animation object has no executable function because … … 13833 13835 } 13834 13836 _updateIndex() { 13835 varindex = this.frameIndex(), animation = this.animation(), animations = this.animations(), anim = animations[animation], len = anim.length / 4;13837 const index = this.frameIndex(), animation = this.animation(), animations = this.animations(), anim = animations[animation], len = anim.length / 4; 13836 13838 if (index < len - 1) { 13837 13839 this.frameIndex(index + 1); … … 14072 14074 class Star extends Shape { 14073 14075 _sceneFunc(context) { 14074 varinnerRadius = this.innerRadius(), outerRadius = this.outerRadius(), numPoints = this.numPoints();14076 const innerRadius = this.innerRadius(), outerRadius = this.outerRadius(), numPoints = this.numPoints(); 14075 14077 context.beginPath(); 14076 14078 context.moveTo(0, 0 - outerRadius); 14077 for ( varn = 1; n < numPoints * 2; n++) {14078 varradius = n % 2 === 0 ? outerRadius : innerRadius;14079 varx = radius * Math.sin((n * Math.PI) / numPoints);14080 vary = -1 * radius * Math.cos((n * Math.PI) / numPoints);14079 for (let n = 1; n < numPoints * 2; n++) { 14080 const radius = n % 2 === 0 ? outerRadius : innerRadius; 14081 const x = radius * Math.sin((n * Math.PI) / numPoints); 14082 const y = -1 * radius * Math.cos((n * Math.PI) / numPoints); 14081 14083 context.lineTo(x, y); 14082 14084 } … … 14145 14147 14146 14148 function stringToArray(string) { 14147 // we need to use `Array.from` because it can split unicode string correctly 14148 // we also can use some regexp magic from lodash: 14149 // https://github.com/lodash/lodash/blob/fb1f99d9d90ad177560d771bc5953a435b2dc119/lodash.toarray/index.js#L256 14150 // but I decided it is too much code for that small fix 14151 return Array.from(string); 14149 // Use Unicode-aware splitting 14150 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); 14154 } 14155 // Handle regional indicator symbols (flags) 14156 else if (/\p{Regional_Indicator}{2}/u.test(char + (array[index + 1] || ''))) { 14157 acc.push(char + array[index + 1]); 14158 } 14159 // Handle Indic scripts and other combining characters 14160 else if (index > 0 && /\p{Mn}|\p{Me}|\p{Mc}/u.test(char)) { 14161 acc[acc.length - 1] += char; 14162 } 14163 // Handle other characters 14164 else { 14165 acc.push(char); 14166 } 14167 return acc; 14168 }, []); 14152 14169 } 14153 14170 // constants 14154 varAUTO = 'auto',14171 const AUTO = 'auto', 14155 14172 //CANVAS = 'canvas', 14156 14173 CENTER = 'center', INHERIT = 'inherit', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL$1 = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', RTL = 'rtl', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST$1 = [ … … 14187 14204 .join(', '); 14188 14205 } 14189 vardummyContext;14206 let dummyContext; 14190 14207 function getDummyContext() { 14191 14208 if (dummyContext) { … … 14321 14338 this._partialTextY = 0; 14322 14339 // update text data for certain attr changes 14323 for ( varn = 0; n < attrChangeListLen; n++) {14340 for (let n = 0; n < attrChangeListLen; n++) { 14324 14341 this.on(ATTR_CHANGE_LIST$1[n] + CHANGE_KONVA, this._setTextData); 14325 14342 } … … 14327 14344 } 14328 14345 _sceneFunc(context) { 14329 vartextArr = this.textArr, textArrLen = textArr.length;14346 const textArr = this.textArr, textArrLen = textArr.length; 14330 14347 if (!this.text()) { 14331 14348 return; 14332 14349 } 14333 varpadding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;14350 let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n; 14334 14351 direction = direction === INHERIT ? context.direction : direction; 14335 vartranslateY = lineHeightPx / 2;14336 varbaseline = MIDDLE;14352 let translateY = lineHeightPx / 2; 14353 let baseline = MIDDLE; 14337 14354 if (Konva$2._fixTextRendering) { 14338 varmetrics = this.measureSize('M'); // Use a sample character to get the ascent14355 const metrics = this.measureSize('M'); // Use a sample character to get the ascent 14339 14356 baseline = 'alphabetic'; 14340 14357 translateY = … … 14374 14391 context.save(); 14375 14392 context.beginPath(); 14376 let yOffset = Konva$2._fixTextRendering14393 const yOffset = Konva$2._fixTextRendering 14377 14394 ? Math.round(fontSize / 4) 14378 14395 : Math.round(fontSize / 2); … … 14396 14413 context.save(); 14397 14414 context.beginPath(); 14398 let yOffset = Konva$2._fixTextRendering ? -Math.round(fontSize / 4) : 0;14415 const yOffset = Konva$2._fixTextRendering ? -Math.round(fontSize / 4) : 0; 14399 14416 context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset); 14400 14417 spacesNumber = text.split(' ').length - 1; … … 14417 14434 // var words = text.split(' '); 14418 14435 spacesNumber = text.split(' ').length - 1; 14419 vararray = stringToArray(text);14420 for ( varli = 0; li < array.length; li++) {14421 varletter = array[li];14436 const array = stringToArray(text); 14437 for (let li = 0; li < array.length; li++) { 14438 const letter = array[li]; 14422 14439 // skip justify for the last line 14423 14440 if (letter === ' ' && !lastLine && align === JUSTIFY) { … … 14451 14468 } 14452 14469 _hitFunc(context) { 14453 varwidth = this.getWidth(), height = this.getHeight();14470 const width = this.getWidth(), height = this.getHeight(); 14454 14471 context.beginPath(); 14455 14472 context.rect(0, 0, width, height); … … 14458 14475 } 14459 14476 setText(text) { 14460 varstr = Util._isString(text)14477 const str = Util._isString(text) 14461 14478 ? text 14462 14479 : text === null || text === undefined … … 14467 14484 } 14468 14485 getWidth() { 14469 varisAuto = this.attrs.width === AUTO || this.attrs.width === undefined;14486 const isAuto = this.attrs.width === AUTO || this.attrs.width === undefined; 14470 14487 return isAuto ? this.getTextWidth() + this.padding() * 2 : this.attrs.width; 14471 14488 } 14472 14489 getHeight() { 14473 varisAuto = this.attrs.height === AUTO || this.attrs.height === undefined;14490 const isAuto = this.attrs.height === AUTO || this.attrs.height === undefined; 14474 14491 return isAuto 14475 14492 ? this.fontSize() * this.textArr.length * this.lineHeight() + … … 14495 14512 * @method 14496 14513 * @name Konva.Text#measureSize 14497 * @param {String} [text]text to measure14498 * @returns {Object} { width , height } of measured text14514 * @param {String} text text to measure 14515 * @returns {Object} { width , height } of measured text 14499 14516 */ 14500 14517 measureSize(text) { 14501 14518 var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; 14502 var_context = getDummyContext(), fontSize = this.fontSize(), metrics;14519 let _context = getDummyContext(), fontSize = this.fontSize(), metrics; 14503 14520 _context.save(); 14504 14521 _context.font = this._getContextFont(); … … 14538 14555 line = line.trim(); 14539 14556 } 14540 varwidth = this._getTextWidth(line);14557 const width = this._getTextWidth(line); 14541 14558 return this.textArr.push({ 14542 14559 text: line, … … 14546 14563 } 14547 14564 _getTextWidth(text) { 14548 varletterSpacing = this.letterSpacing();14549 varlength = text.length;14565 const letterSpacing = this.letterSpacing(); 14566 const length = text.length; 14550 14567 return (getDummyContext().measureText(text).width + 14551 14568 (length ? letterSpacing * (length - 1) : 0)); 14552 14569 } 14553 14570 _setTextData() { 14554 varlines = 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(),14571 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(), 14555 14572 // align = this.align(), 14556 14573 shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis(); 14557 14574 this.textArr = []; 14558 14575 getDummyContext().font = this._getContextFont(); 14559 varadditionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0;14560 for ( vari = 0, max = lines.length; i < max; ++i) {14561 varline = lines[i];14562 varlineWidth = this._getTextWidth(line);14576 const additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0; 14577 for (let i = 0, max = lines.length; i < max; ++i) { 14578 let line = lines[i]; 14579 let lineWidth = this._getTextWidth(line); 14563 14580 if (fixedWidth && lineWidth > maxWidth) { 14564 14581 /* … … 14571 14588 * that would fit in the specified width 14572 14589 */ 14573 varlow = 0, high = line.length, match = '', matchWidth = 0;14590 let low = 0, high = line.length, match = '', matchWidth = 0; 14574 14591 while (low < high) { 14575 varmid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth;14592 const mid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth; 14576 14593 if (substrWidth <= maxWidth) { 14577 14594 low = mid + 1; … … 14593 14610 // try to find a space or dash where wrapping could be done 14594 14611 var wrapIndex; 14595 varnextChar = line[match.length];14596 varnextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;14612 const nextChar = line[match.length]; 14613 const nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH; 14597 14614 if (nextIsSpaceOrDash && matchWidth <= maxWidth) { 14598 14615 wrapIndex = match.length; … … 14616 14633 textWidth = Math.max(textWidth, matchWidth); 14617 14634 currentHeightPx += lineHeightPx; 14618 varshouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);14635 const shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx); 14619 14636 if (shouldHandleEllipsis) { 14620 14637 this._tryToAddEllipsisToLastLine(); … … 14677 14694 */ 14678 14695 _shouldHandleEllipsis(currentHeightPx) { 14679 varfontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE;14696 const fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE; 14680 14697 return (!shouldWrap || 14681 14698 (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx)); 14682 14699 } 14683 14700 _tryToAddEllipsisToLastLine() { 14684 varwidth = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();14685 varlastLine = this.textArr[this.textArr.length - 1];14701 const width = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis(); 14702 const lastLine = this.textArr[this.textArr.length - 1]; 14686 14703 if (!lastLine || !shouldAddEllipsis) { 14687 14704 return; 14688 14705 } 14689 14706 if (fixedWidth) { 14690 varhaveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;14707 const haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth; 14691 14708 if (!haveSpace) { 14692 14709 lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3); … … 14962 14979 Factory.addGetterSetter(Text, 'textDecoration', ''); 14963 14980 14964 varEMPTY_STRING = '', NORMAL = 'normal';14981 const EMPTY_STRING = '', NORMAL = 'normal'; 14965 14982 function _fillFunc(context) { 14966 14983 context.fillText(this.partialText, 0, 0); … … 15124 15141 context.setAttr('textAlign', 'left'); 15125 15142 context.save(); 15126 vartextDecoration = this.textDecoration();15127 varfill = this.fill();15128 varfontSize = this.fontSize();15129 varglyphInfo = this.glyphInfo;15143 const textDecoration = this.textDecoration(); 15144 const fill = this.fill(); 15145 const fontSize = this.fontSize(); 15146 const glyphInfo = this.glyphInfo; 15130 15147 if (textDecoration === 'underline') { 15131 15148 context.beginPath(); 15132 15149 } 15133 for ( vari = 0; i < glyphInfo.length; i++) {15150 for (let i = 0; i < glyphInfo.length; i++) { 15134 15151 context.save(); 15135 varp0 = glyphInfo[i].p0;15152 const p0 = glyphInfo[i].p0; 15136 15153 context.translate(p0.x, p0.y); 15137 15154 context.rotate(glyphInfo[i].rotation); … … 15163 15180 _hitFunc(context) { 15164 15181 context.beginPath(); 15165 varglyphInfo = this.glyphInfo;15182 const glyphInfo = this.glyphInfo; 15166 15183 if (glyphInfo.length >= 1) { 15167 varp0 = glyphInfo[0].p0;15184 const p0 = glyphInfo[0].p0; 15168 15185 context.moveTo(p0.x, p0.y); 15169 15186 } 15170 for ( vari = 0; i < glyphInfo.length; i++) {15171 varp1 = glyphInfo[i].p1;15187 for (let i = 0; i < glyphInfo.length; i++) { 15188 const p1 = glyphInfo[i].p1; 15172 15189 context.lineTo(p1.x, p1.y); 15173 15190 } … … 15195 15212 } 15196 15213 _getTextSize(text) { 15197 vardummyCanvas = this.dummyCanvas;15198 var_context = dummyCanvas.getContext('2d');15214 const dummyCanvas = this.dummyCanvas; 15215 const _context = dummyCanvas.getContext('2d'); 15199 15216 _context.save(); 15200 15217 _context.font = this._getContextFont(); 15201 varmetrics = _context.measureText(text);15218 const metrics = _context.measureText(text); 15202 15219 _context.restore(); 15203 15220 return { … … 15233 15250 // 4. Add glyph width to the offsetToGlyph and repeat 15234 15251 let offsetToGlyph = offset; 15235 for ( vari = 0; i < charArr.length; i++) {15252 for (let i = 0; i < charArr.length; i++) { 15236 15253 const charStartPoint = this._getPointAtLength(offsetToGlyph); 15237 15254 if (!charStartPoint) … … 15281 15298 }; 15282 15299 } 15283 varpoints = [];15300 const points = []; 15284 15301 this.glyphInfo.forEach(function (info) { 15285 15302 points.push(info.p0.x); … … 15288 15305 points.push(info.p1.y); 15289 15306 }); 15290 varminX = points[0] || 0;15291 varmaxX = points[0] || 0;15292 varminY = points[1] || 0;15293 varmaxY = points[1] || 0;15294 varx, y;15295 for ( vari = 0; i < points.length / 2; i++) {15307 let minX = points[0] || 0; 15308 let maxX = points[0] || 0; 15309 let minY = points[1] || 0; 15310 let maxY = points[1] || 0; 15311 let x, y; 15312 for (let i = 0; i < points.length / 2; i++) { 15296 15313 x = points[i * 2]; 15297 15314 y = points[i * 2 + 1]; … … 15301 15318 maxY = Math.max(maxY, y); 15302 15319 } 15303 varfontSize = this.fontSize();15320 const fontSize = this.fontSize(); 15304 15321 return { 15305 15322 x: minX - fontSize / 2, … … 15484 15501 Factory.addGetterSetter(TextPath, 'kerningFunc', null); 15485 15502 15486 varEVENTS_NAME = 'tr-konva';15487 varATTR_CHANGE_LIST = [15503 const EVENTS_NAME = 'tr-konva'; 15504 const ATTR_CHANGE_LIST = [ 15488 15505 'resizeEnabledChange', 15489 15506 'rotateAnchorOffsetChange', … … 15504 15521 .map((e) => e + `.${EVENTS_NAME}`) 15505 15522 .join(' '); 15506 varNODES_RECT = 'nodesRect';15507 varTRANSFORM_CHANGE_STR = [15523 const NODES_RECT = 'nodesRect'; 15524 const TRANSFORM_CHANGE_STR = [ 15508 15525 'widthChange', 15509 15526 'heightChange', … … 15518 15535 'strokeWidthChange', 15519 15536 ]; 15520 varANGLES = {15537 const ANGLES = { 15521 15538 'top-left': -45, 15522 15539 'top-center': 0, … … 15534 15551 } 15535 15552 rad += Util.degToRad(ANGLES[anchorName] || 0); 15536 varangle = ((Util.radToDeg(rad) % 360) + 360) % 360;15553 const angle = ((Util.radToDeg(rad) % 360) + 360) % 360; 15537 15554 if (Util._inRange(angle, 315 + 22.5, 360) || Util._inRange(angle, 0, 22.5)) { 15538 15555 // TOP … … 15573 15590 } 15574 15591 } 15575 varANCHORS_NAMES = [15592 const ANCHORS_NAMES = [ 15576 15593 'top-left', 15577 15594 'top-center', … … 15583 15600 'bottom-right', 15584 15601 ]; 15585 varMAX_SAFE_INTEGER = 100000000;15602 const MAX_SAFE_INTEGER = 100000000; 15586 15603 function getCenter(shape) { 15587 15604 return { … … 15745 15762 // we may need it if we set node in initial props 15746 15763 // so elements are not defined yet 15747 varelementsCreated = !!this.findOne('.top-left');15764 const elementsCreated = !!this.findOne('.top-left'); 15748 15765 if (elementsCreated) { 15749 15766 this.update(); … … 15840 15857 // return absolute rotated bounding rectangle 15841 15858 __getNodeShape(node, rot = this.rotation(), relative) { 15842 varrect = node.getClientRect({15859 const rect = node.getClientRect({ 15843 15860 skipTransform: true, 15844 15861 skipShadow: true, 15845 15862 skipStroke: this.ignoreStroke(), 15846 15863 }); 15847 varabsScale = node.getAbsoluteScale(relative);15848 varabsPos = node.getAbsolutePosition(relative);15849 vardx = rect.x * absScale.x - node.offsetX() * absScale.x;15850 vardy = rect.y * absScale.y - node.offsetY() * absScale.y;15864 const absScale = node.getAbsoluteScale(relative); 15865 const absPos = node.getAbsolutePosition(relative); 15866 const dx = rect.x * absScale.x - node.offsetX() * absScale.x; 15867 const dy = rect.y * absScale.y - node.offsetY() * absScale.y; 15851 15868 const rotation = (Konva$2.getAngle(node.getAbsoluteRotation()) + Math.PI * 2) % 15852 15869 (Math.PI * 2); … … 15865 15882 // returns box + rotation of all shapes 15866 15883 __getNodeRect() { 15867 varnode = this.getNode();15884 const node = this.getNode(); 15868 15885 if (!node) { 15869 15886 return { … … 15882 15899 skipStroke: this.ignoreStroke(), 15883 15900 }); 15884 varpoints = [15901 const points = [ 15885 15902 { x: box.x, y: box.y }, 15886 15903 { x: box.x + box.width, y: box.y }, … … 15888 15905 { x: box.x, y: box.y + box.height }, 15889 15906 ]; 15890 vartrans = node.getAbsoluteTransform();15907 const trans = node.getAbsoluteTransform(); 15891 15908 points.forEach(function (point) { 15892 vartransformed = trans.point(point);15909 const transformed = trans.point(point); 15893 15910 totalPoints.push(transformed); 15894 15911 }); … … 15896 15913 const tr = new Transform(); 15897 15914 tr.rotate(-Konva$2.getAngle(this.rotation())); 15898 varminX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;15915 let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity; 15899 15916 totalPoints.forEach(function (point) { 15900 vartransformed = tr.point(point);15917 const transformed = tr.point(point); 15901 15918 if (minX === undefined) { 15902 15919 minX = maxX = transformed.x; … … 15946 15963 } 15947 15964 _createAnchor(name) { 15948 varanchor = new Rect({15965 const anchor = new Rect({ 15949 15966 stroke: 'rgb(0, 161, 255)', 15950 15967 fill: 'white', … … 15957 15974 hitStrokeWidth: TOUCH_DEVICE ? 10 : 'auto', 15958 15975 }); 15959 varself = this;15976 const self = this; 15960 15977 anchor.on('mousedown touchstart', function (e) { 15961 15978 self._handleMouseDown(e); … … 15970 15987 // add hover styling 15971 15988 anchor.on('mouseenter', () => { 15972 varrad = Konva$2.getAngle(this.rotation());15973 varrotateCursor = this.rotateAnchorCursor();15974 varcursor = getCursor(name, rad, rotateCursor);15989 const rad = Konva$2.getAngle(this.rotation()); 15990 const rotateCursor = this.rotateAnchorCursor(); 15991 const cursor = getCursor(name, rad, rotateCursor); 15975 15992 anchor.getStage().content && 15976 15993 (anchor.getStage().content.style.cursor = cursor); … … 15985 16002 } 15986 16003 _createBack() { 15987 varback = new Shape({16004 const back = new Shape({ 15988 16005 name: 'back', 15989 16006 width: 0, … … 15991 16008 draggable: true, 15992 16009 sceneFunc(ctx, shape) { 15993 vartr = shape.getParent();15994 varpadding = tr.padding();16010 const tr = shape.getParent(); 16011 const padding = tr.padding(); 15995 16012 ctx.beginPath(); 15996 16013 ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2); … … 16005 16022 return; 16006 16023 } 16007 varpadding = this.padding();16024 const padding = this.padding(); 16008 16025 ctx.beginPath(); 16009 16026 ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2); … … 16037 16054 } 16038 16055 this._movingAnchorName = e.target.name().split(' ')[0]; 16039 varattrs = this._getNodeRect();16040 varwidth = attrs.width;16041 varheight = attrs.height;16042 varhypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));16056 const attrs = this._getNodeRect(); 16057 const width = attrs.width; 16058 const height = attrs.height; 16059 const hypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)); 16043 16060 this.sin = Math.abs(height / hypotenuse); 16044 16061 this.cos = Math.abs(width / hypotenuse); … … 16050 16067 } 16051 16068 this._transforming = true; 16052 varap = e.target.getAbsolutePosition();16053 varpos = e.target.getStage().getPointerPosition();16069 const ap = e.target.getAbsolutePosition(); 16070 const pos = e.target.getStage().getPointerPosition(); 16054 16071 this._anchorDragOffset = { 16055 16072 x: pos.x - ap.x, … … 16063 16080 } 16064 16081 _handleMouseMove(e) { 16065 varx, y, newHypotenuse;16066 varanchorNode = this.findOne('.' + this._movingAnchorName);16067 varstage = anchorNode.getStage();16082 let x, y, newHypotenuse; 16083 const anchorNode = this.findOne('.' + this._movingAnchorName); 16084 const stage = anchorNode.getStage(); 16068 16085 stage.setPointersPositions(e); 16069 16086 const pp = stage.getPointerPosition(); … … 16084 16101 // rotater is working very differently, so do it first 16085 16102 if (this._movingAnchorName === 'rotater') { 16086 varattrs = this._getNodeRect();16103 const attrs = this._getNodeRect(); 16087 16104 x = anchorNode.x() - attrs.width / 2; 16088 16105 y = -anchorNode.y() + attrs.height / 2; … … 16092 16109 delta -= Math.PI; 16093 16110 } 16094 varoldRotation = Konva$2.getAngle(this.rotation());16111 const oldRotation = Konva$2.getAngle(this.rotation()); 16095 16112 const newRotation = oldRotation + delta; 16096 16113 const tol = Konva$2.getAngle(this.rotationSnapTolerance()); … … 16101 16118 return; 16102 16119 } 16103 varshiftBehavior = this.shiftBehavior();16104 varkeepProportion;16120 const shiftBehavior = this.shiftBehavior(); 16121 let keepProportion; 16105 16122 if (shiftBehavior === 'inverted') { 16106 16123 keepProportion = this.keepRatio() && !e.shiftKey; … … 16221 16238 var centeredScaling = this.centeredScaling() || e.altKey; 16222 16239 if (centeredScaling) { 16223 vartopLeft = this.findOne('.top-left');16224 varbottomRight = this.findOne('.bottom-right');16225 vartopOffsetX = topLeft.x();16226 vartopOffsetY = topLeft.y();16227 varbottomOffsetX = this.getWidth() - bottomRight.x();16228 varbottomOffsetY = this.getHeight() - bottomRight.y();16240 const topLeft = this.findOne('.top-left'); 16241 const bottomRight = this.findOne('.bottom-right'); 16242 const topOffsetX = topLeft.x(); 16243 const topOffsetY = topLeft.y(); 16244 const bottomOffsetX = this.getWidth() - bottomRight.x(); 16245 const bottomOffsetY = this.getHeight() - bottomRight.y(); 16229 16246 bottomRight.move({ 16230 16247 x: -topOffsetX, … … 16236 16253 }); 16237 16254 } 16238 varabsPos = this.findOne('.top-left').getAbsolutePosition();16255 const absPos = this.findOne('.top-left').getAbsolutePosition(); 16239 16256 x = absPos.x; 16240 16257 y = absPos.y; 16241 varwidth = this.findOne('.bottom-right').x() - this.findOne('.top-left').x();16242 varheight = this.findOne('.bottom-right').y() - this.findOne('.top-left').y();16258 const width = this.findOne('.bottom-right').x() - this.findOne('.top-left').x(); 16259 const height = this.findOne('.bottom-right').y() - this.findOne('.top-left').y(); 16243 16260 this._fitNodesInto({ 16244 16261 x: x, … … 16265 16282 window.removeEventListener('touchend', this._handleMouseUp, true); 16266 16283 } 16267 varnode = this.getNode();16284 const node = this.getNode(); 16268 16285 activeTransformersCount--; 16269 16286 this._fire('transformend', { evt: e, target: node }); … … 16282 16299 } 16283 16300 _fitNodesInto(newAttrs, evt) { 16284 varoldAttrs = this._getNodeRect();16301 const oldAttrs = this._getNodeRect(); 16285 16302 const minSize = 1; 16286 16303 if (Util._inRange(newAttrs.width, -this.padding() * 2 - minSize, minSize)) { … … 16292 16309 return; 16293 16310 } 16294 vart = new Transform();16311 const t = new Transform(); 16295 16312 t.rotate(Konva$2.getAngle(this.rotation())); 16296 16313 if (this._movingAnchorName && … … 16432 16449 update() { 16433 16450 var _a; 16434 varattrs = this._getNodeRect();16451 const attrs = this._getNodeRect(); 16435 16452 this.rotation(Util._getRotation(attrs.rotation)); 16436 varwidth = attrs.width;16437 varheight = attrs.height;16438 varenabledAnchors = this.enabledAnchors();16439 varresizeEnabled = this.resizeEnabled();16440 varpadding = this.padding();16441 varanchorSize = this.anchorSize();16453 const width = attrs.width; 16454 const height = attrs.height; 16455 const enabledAnchors = this.enabledAnchors(); 16456 const resizeEnabled = this.resizeEnabled(); 16457 const padding = this.padding(); 16458 const anchorSize = this.anchorSize(); 16442 16459 const anchors = this.find('._anchor'); 16443 16460 anchors.forEach((node) => { … … 16546 16563 if (this._transforming) { 16547 16564 this._removeEvents(); 16548 varanchorNode = this.findOne('.' + this._movingAnchorName);16565 const anchorNode = this.findOne('.' + this._movingAnchorName); 16549 16566 if (anchorNode) { 16550 16567 anchorNode.stopDrag(); … … 16568 16585 // overwrite clone to NOT use method from Container 16569 16586 clone(obj) { 16570 varnode = Node.prototype.clone.call(this, obj);16587 const node = Node.prototype.clone.call(this, obj); 16571 16588 return node; 16572 16589 } … … 17266 17283 this.next = null; 17267 17284 } 17268 varmul_table = [17285 const mul_table = [ 17269 17286 512, 512, 456, 512, 328, 456, 335, 512, 405, 328, 271, 456, 388, 335, 292, 17270 17287 512, 454, 405, 364, 328, 298, 271, 496, 456, 420, 388, 360, 335, 312, 292, … … 17285 17302 289, 287, 285, 282, 280, 278, 275, 273, 271, 269, 267, 265, 263, 261, 259, 17286 17303 ]; 17287 varshg_table = [17304 const shg_table = [ 17288 17305 9, 11, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17289 17306 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, … … 17302 17319 ]; 17303 17320 function filterGaussBlurRGBA(imageData, radius) { 17304 varpixels = imageData.data, width = imageData.width, height = imageData.height;17305 varx, 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;17306 vardiv = 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];17321 const pixels = imageData.data, width = imageData.width, height = imageData.height; 17322 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]; 17307 17324 for (i = 1; i < div; i++) { 17308 17325 stack = stack.next = new BlurStack(); … … 17495 17512 */ 17496 17513 const Blur = function Blur(imageData) { 17497 varradius = Math.round(this.blurRadius());17514 const radius = Math.round(this.blurRadius()); 17498 17515 if (radius > 0) { 17499 17516 filterGaussBlurRGBA(imageData, radius); … … 17520 17537 */ 17521 17538 const Brighten = function (imageData) { 17522 varbrightness = this.brightness() * 255, data = imageData.data, len = data.length, i;17539 let brightness = this.brightness() * 255, data = imageData.data, len = data.length, i; 17523 17540 for (i = 0; i < len; i += 4) { 17524 17541 // red … … 17552 17569 */ 17553 17570 const Contrast = function (imageData) { 17554 varadjust = Math.pow((this.contrast() + 100) / 100, 2);17555 vardata = imageData.data, nPixels = data.length, red = 150, green = 150, blue = 150, i;17571 const adjust = Math.pow((this.contrast() + 100) / 100, 2); 17572 let data = imageData.data, nPixels = data.length, red = 150, green = 150, blue = 150, i; 17556 17573 for (i = 0; i < nPixels; i += 4) { 17557 17574 red = data[i]; … … 17615 17632 // a max value of greyLevel yields a white emboss, and the min value yields a black 17616 17633 // emboss. Therefore, I changed greyLevel to whiteLevel 17617 varstrength = 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;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; 17618 17635 switch (direction) { 17619 17636 case 'top-left': … … 17653 17670 } 17654 17671 do { 17655 varoffsetY = (y - 1) * w4;17656 varotherY = dirY;17672 const offsetY = (y - 1) * w4; 17673 let otherY = dirY; 17657 17674 if (y + otherY < 1) { 17658 17675 otherY = 0; … … 17661 17678 otherY = 0; 17662 17679 } 17663 varoffsetYOther = (y - 1 + otherY) * w * 4;17664 varx = w;17680 const offsetYOther = (y - 1 + otherY) * w * 4; 17681 let x = w; 17665 17682 do { 17666 varoffset = offsetY + (x - 1) * 4;17667 varotherX = dirX;17683 const offset = offsetY + (x - 1) * 4; 17684 let otherX = dirX; 17668 17685 if (x + otherX < 1) { 17669 17686 otherX = 0; … … 17672 17689 otherX = 0; 17673 17690 } 17674 varoffsetOther = offsetYOther + (x - 1 + otherX) * 4;17675 vardR = data[offset] - data[offsetOther];17676 vardG = data[offset + 1] - data[offsetOther + 1];17677 vardB = data[offset + 2] - data[offsetOther + 2];17678 vardif = dR;17679 varabsDif = dif > 0 ? dif : -dif;17680 varabsG = dG > 0 ? dG : -dG;17681 varabsB = dB > 0 ? dB : -dB;17691 const offsetOther = offsetYOther + (x - 1 + otherX) * 4; 17692 const dR = data[offset] - data[offsetOther]; 17693 const dG = data[offset + 1] - data[offsetOther + 1]; 17694 const dB = data[offset + 2] - data[offsetOther + 2]; 17695 let dif = dR; 17696 const absDif = dif > 0 ? dif : -dif; 17697 const absG = dG > 0 ? dG : -dG; 17698 const absB = dB > 0 ? dB : -dB; 17682 17699 if (absG > absDif) { 17683 17700 dif = dG; … … 17688 17705 dif *= strength; 17689 17706 if (blend) { 17690 varr = data[offset] + dif;17691 varg = data[offset + 1] + dif;17692 varb = data[offset + 2] + dif;17707 const r = data[offset] + dif; 17708 const g = data[offset + 1] + dif; 17709 const b = data[offset + 2] + dif; 17693 17710 data[offset] = r > 255 ? 255 : r < 0 ? 0 : r; 17694 17711 data[offset + 1] = g > 255 ? 255 : g < 0 ? 0 : g; … … 17696 17713 } 17697 17714 else { 17698 vargrey = greyLevel - dif;17715 let grey = greyLevel - dif; 17699 17716 if (grey < 0) { 17700 17717 grey = 0; … … 17744 17761 function remap(fromValue, fromMin, fromMax, toMin, toMax) { 17745 17762 // Compute the range of the data 17746 varfromRange = fromMax - fromMin, toRange = toMax - toMin, toValue;17763 let fromRange = fromMax - fromMin, toRange = toMax - toMin, toValue; 17747 17764 // If either range is 0, then the value can only be mapped to 1 value 17748 17765 if (fromRange === 0) { … … 17772 17789 */ 17773 17790 const Enhance = function (imageData) { 17774 vardata = imageData.data, nSubPixels = data.length, rMin = data[0], rMax = rMin, r, gMin = data[1], gMax = gMin, g, bMin = data[2], bMax = bMin, b, i;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; 17775 17792 // If we are not enhancing anything - don't do any computation 17776 varenhanceAmount = this.enhance();17793 const enhanceAmount = this.enhance(); 17777 17794 if (enhanceAmount === 0) { 17778 17795 return; … … 17818 17835 bMin = 0; 17819 17836 } 17820 varrMid, rGoalMax, rGoalMin, gMid, gGoalMax, gGoalMin, bMid, bGoalMax, bGoalMin;17837 let rMid, rGoalMax, rGoalMin, gMid, gGoalMax, gGoalMin, bMid, bGoalMax, bGoalMin; 17821 17838 // If the enhancement is positive - stretch the histogram 17822 17839 if (enhanceAmount > 0) { … … 17867 17884 */ 17868 17885 const Grayscale = function (imageData) { 17869 vardata = imageData.data, len = data.length, i, brightness;17886 let data = imageData.data, len = data.length, i, brightness; 17870 17887 for (i = 0; i < len; i += 4) { 17871 17888 brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]; … … 17914 17931 */ 17915 17932 const HSL = function (imageData) { 17916 vardata = 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;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; 17917 17934 // Basis for the technique used: 17918 17935 // http://beesbuzz.biz/code/hsv_color_transforms.php … … 17926 17943 //[ .299V-.300vsu+1.25vsw .587V-.588vsu-1.05vsw .114V+.886vsu-.203vsw ] [B] 17927 17944 // Precompute the values in the matrix: 17928 varvsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);17945 const vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180); 17929 17946 // (result spot)(source spot) 17930 varrr = 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;17931 vargr = 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;17932 varbr = 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;17933 varr, g, b, a;17947 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; 17948 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 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 let r, g, b, a; 17934 17951 for (i = 0; i < nPixels; i += 4) { 17935 17952 r = data[i + 0]; … … 17956 17973 */ 17957 17974 const HSV = function (imageData) { 17958 var data = imageData.data, nPixels = data.length, v = Math.pow(2, this.value()), s = Math.pow(2, this.saturation()), h = Math.abs(this.hue() + 360) % 360, i;17975 const data = imageData.data, nPixels = data.length, v = Math.pow(2, this.value()), s = Math.pow(2, this.saturation()), h = Math.abs(this.hue() + 360) % 360; 17959 17976 // Basis for the technique used: 17960 17977 // http://beesbuzz.biz/code/hsv_color_transforms.php … … 17968 17985 //[ .299V-.300vsu+1.25vsw .587V-.588vsu-1.05vsw .114V+.886vsu-.203vsw ] [B] 17969 17986 // Precompute the values in the matrix: 17970 varvsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);17987 const vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180); 17971 17988 // (result spot)(source spot) 17972 varrr = 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;17973 vargr = 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;17974 varbr = 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;17975 varr, g, b, a;17976 for ( i = 0; i < nPixels; i += 4) {17989 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; 17990 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; 17991 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; 17992 let r, g, b, a; 17993 for (let i = 0; i < nPixels; i += 4) { 17977 17994 r = data[i + 0]; 17978 17995 g = data[i + 1]; … … 18020 18037 */ 18021 18038 const Invert = function (imageData) { 18022 vardata = imageData.data, len = data.length, i;18039 let data = imageData.data, len = data.length, i; 18023 18040 for (i = 0; i < len; i += 4) { 18024 18041 // red … … 18046 18063 * default is in the middle 18047 18064 */ 18048 varToPolar = function (src, dst, opt) {18049 varsrcPixels = 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;18065 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; 18050 18067 // Find the largest radius 18051 varrad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);18068 let rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid); 18052 18069 x = xSize - xMid; 18053 18070 y = ySize - yMid; … … 18055 18072 rMax = rad > rMax ? rad : rMax; 18056 18073 // We'll be uisng y as the radius, and x as the angle (theta=t) 18057 varrSize = ySize, tSize = xSize, radius, theta;18074 let rSize = ySize, tSize = xSize, radius, theta; 18058 18075 // We want to cover all angles (0-360) and we need to convert to 18059 18076 // radians (*PI/180) 18060 varconversion = ((360 / tSize) * Math.PI) / 180, sin, cos;18077 let conversion = ((360 / tSize) * Math.PI) / 180, sin, cos; 18061 18078 // var x1, x2, x1i, x2i, y1, y2, y1i, y2i, scale; 18062 18079 for (theta = 0; theta < tSize; theta += 1) { … … 18097 18114 * 0 is no rotation, 360 degrees is a full rotation 18098 18115 */ 18099 varFromPolar = function (src, dst, opt) {18100 varsrcPixels = 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;18116 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; 18101 18118 // Find the largest radius 18102 varrad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);18119 let rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid); 18103 18120 x = xSize - xMid; 18104 18121 y = ySize - yMid; … … 18106 18123 rMax = rad > rMax ? rad : rMax; 18107 18124 // We'll be uisng x as the radius, and y as the angle (theta=t) 18108 varrSize = ySize, tSize = xSize, radius, theta, phaseShift = 0;18125 let rSize = ySize, tSize = xSize, radius, theta, phaseShift = 0; 18109 18126 // We need to convert to degrees and we need to make sure 18110 18127 // it's between (0-360) 18111 18128 // var conversion = tSize/360*180/Math.PI; 18112 18129 //var conversion = tSize/360*180/Math.PI; 18113 varx1, y1;18130 let x1, y1; 18114 18131 for (x = 0; x < xSize; x += 1) { 18115 18132 for (y = 0; y < ySize; y += 1) { … … 18151 18168 */ 18152 18169 const Kaleidoscope = function (imageData) { 18153 varxSize = imageData.width, ySize = imageData.height;18154 varx, y, xoff, i, r, g, b, a, srcPos, dstPos;18155 varpower = Math.round(this.kaleidoscopePower());18156 varangle = Math.round(this.kaleidoscopeAngle());18157 varoffset = Math.floor((xSize * (angle % 360)) / 360);18170 const xSize = imageData.width, ySize = imageData.height; 18171 let x, y, xoff, i, r, g, b, a, srcPos, dstPos; 18172 let power = Math.round(this.kaleidoscopePower()); 18173 const angle = Math.round(this.kaleidoscopeAngle()); 18174 const offset = Math.floor((xSize * (angle % 360)) / 360); 18158 18175 if (power < 1) { 18159 18176 return; 18160 18177 } 18161 18178 // Work with our shared buffer canvas 18162 vartempCanvas = Util.createCanvasElement();18179 const tempCanvas = Util.createCanvasElement(); 18163 18180 tempCanvas.width = xSize; 18164 18181 tempCanvas.height = ySize; 18165 varscratchData = tempCanvas18182 const scratchData = tempCanvas 18166 18183 .getContext('2d') 18167 18184 .getImageData(0, 0, xSize, ySize); … … 18174 18191 // Determine how big each section will be, if it's too small 18175 18192 // make it bigger 18176 varminSectionSize = xSize / Math.pow(2, power);18193 let minSectionSize = xSize / Math.pow(2, power); 18177 18194 while (minSectionSize <= 8) { 18178 18195 minSectionSize = minSectionSize * 2; … … 18180 18197 } 18181 18198 minSectionSize = Math.ceil(minSectionSize); 18182 varsectionSize = minSectionSize;18199 let sectionSize = minSectionSize; 18183 18200 // Copy the offset region to 0 18184 18201 // Depending on the size of filter and location of the offset we may need 18185 18202 // to copy the section backwards to prevent it from rewriting itself 18186 varxStart = 0, xEnd = sectionSize, xDelta = 1;18203 let xStart = 0, xEnd = sectionSize, xDelta = 1; 18187 18204 if (offset + minSectionSize > xSize) { 18188 18205 xStart = sectionSize; … … 18245 18262 18246 18263 function pixelAt(idata, x, y) { 18247 varidx = (y * idata.width + x) * 4;18248 vard = [];18264 let idx = (y * idata.width + x) * 4; 18265 const d = []; 18249 18266 d.push(idata.data[idx++], idata.data[idx++], idata.data[idx++], idata.data[idx++]); 18250 18267 return d; … … 18256 18273 } 18257 18274 function rgbMean(pTab) { 18258 varm = [0, 0, 0];18259 for ( vari = 0; i < pTab.length; i++) {18275 const m = [0, 0, 0]; 18276 for (let i = 0; i < pTab.length; i++) { 18260 18277 m[0] += pTab[i][0]; 18261 18278 m[1] += pTab[i][1]; … … 18268 18285 } 18269 18286 function backgroundMask(idata, threshold) { 18270 varrgbv_no = pixelAt(idata, 0, 0);18271 varrgbv_ne = pixelAt(idata, idata.width - 1, 0);18272 varrgbv_so = pixelAt(idata, 0, idata.height - 1);18273 varrgbv_se = pixelAt(idata, idata.width - 1, idata.height - 1);18274 varthres = threshold || 10;18287 const rgbv_no = pixelAt(idata, 0, 0); 18288 const rgbv_ne = pixelAt(idata, idata.width - 1, 0); 18289 const rgbv_so = pixelAt(idata, 0, idata.height - 1); 18290 const rgbv_se = pixelAt(idata, idata.width - 1, idata.height - 1); 18291 const thres = threshold || 10; 18275 18292 if (rgbDistance(rgbv_no, rgbv_ne) < thres && 18276 18293 rgbDistance(rgbv_ne, rgbv_se) < thres && … … 18278 18295 rgbDistance(rgbv_so, rgbv_no) < thres) { 18279 18296 // Mean color 18280 varmean = rgbMean([rgbv_ne, rgbv_no, rgbv_se, rgbv_so]);18297 const mean = rgbMean([rgbv_ne, rgbv_no, rgbv_se, rgbv_so]); 18281 18298 // Mask based on color distance 18282 varmask = [];18283 for ( vari = 0; i < idata.width * idata.height; i++) {18284 vard = rgbDistance(mean, [18299 const mask = []; 18300 for (let i = 0; i < idata.width * idata.height; i++) { 18301 const d = rgbDistance(mean, [ 18285 18302 idata.data[i * 4], 18286 18303 idata.data[i * 4 + 1], … … 18293 18310 } 18294 18311 function applyMask(idata, mask) { 18295 for ( vari = 0; i < idata.width * idata.height; i++) {18312 for (let i = 0; i < idata.width * idata.height; i++) { 18296 18313 idata.data[4 * i + 3] = mask[i]; 18297 18314 } 18298 18315 } 18299 18316 function erodeMask(mask, sw, sh) { 18300 varweights = [1, 1, 1, 1, 0, 1, 1, 1, 1];18301 varside = Math.round(Math.sqrt(weights.length));18302 varhalfSide = Math.floor(side / 2);18303 varmaskResult = [];18304 for ( vary = 0; y < sh; y++) {18305 for ( varx = 0; x < sw; x++) {18306 varso = y * sw + x;18307 vara = 0;18308 for ( varcy = 0; cy < side; cy++) {18309 for ( varcx = 0; cx < side; cx++) {18310 varscy = y + cy - halfSide;18311 varscx = x + cx - halfSide;18317 const weights = [1, 1, 1, 1, 0, 1, 1, 1, 1]; 18318 const side = Math.round(Math.sqrt(weights.length)); 18319 const halfSide = Math.floor(side / 2); 18320 const maskResult = []; 18321 for (let y = 0; y < sh; y++) { 18322 for (let x = 0; x < sw; x++) { 18323 const so = y * sw + x; 18324 let a = 0; 18325 for (let cy = 0; cy < side; cy++) { 18326 for (let cx = 0; cx < side; cx++) { 18327 const scy = y + cy - halfSide; 18328 const scx = x + cx - halfSide; 18312 18329 if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) { 18313 varsrcOff = scy * sw + scx;18314 varwt = weights[cy * side + cx];18330 const srcOff = scy * sw + scx; 18331 const wt = weights[cy * side + cx]; 18315 18332 a += mask[srcOff] * wt; 18316 18333 } … … 18323 18340 } 18324 18341 function dilateMask(mask, sw, sh) { 18325 varweights = [1, 1, 1, 1, 1, 1, 1, 1, 1];18326 varside = Math.round(Math.sqrt(weights.length));18327 varhalfSide = Math.floor(side / 2);18328 varmaskResult = [];18329 for ( vary = 0; y < sh; y++) {18330 for ( varx = 0; x < sw; x++) {18331 varso = y * sw + x;18332 vara = 0;18333 for ( varcy = 0; cy < side; cy++) {18334 for ( varcx = 0; cx < side; cx++) {18335 varscy = y + cy - halfSide;18336 varscx = x + cx - halfSide;18342 const weights = [1, 1, 1, 1, 1, 1, 1, 1, 1]; 18343 const side = Math.round(Math.sqrt(weights.length)); 18344 const halfSide = Math.floor(side / 2); 18345 const maskResult = []; 18346 for (let y = 0; y < sh; y++) { 18347 for (let x = 0; x < sw; x++) { 18348 const so = y * sw + x; 18349 let a = 0; 18350 for (let cy = 0; cy < side; cy++) { 18351 for (let cx = 0; cx < side; cx++) { 18352 const scy = y + cy - halfSide; 18353 const scx = x + cx - halfSide; 18337 18354 if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) { 18338 varsrcOff = scy * sw + scx;18339 varwt = weights[cy * side + cx];18355 const srcOff = scy * sw + scx; 18356 const wt = weights[cy * side + cx]; 18340 18357 a += mask[srcOff] * wt; 18341 18358 } … … 18348 18365 } 18349 18366 function smoothEdgeMask(mask, sw, sh) { 18350 varweights = [1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9];18351 varside = Math.round(Math.sqrt(weights.length));18352 varhalfSide = Math.floor(side / 2);18353 varmaskResult = [];18354 for ( vary = 0; y < sh; y++) {18355 for ( varx = 0; x < sw; x++) {18356 varso = y * sw + x;18357 vara = 0;18358 for ( varcy = 0; cy < side; cy++) {18359 for ( varcx = 0; cx < side; cx++) {18360 varscy = y + cy - halfSide;18361 varscx = x + cx - halfSide;18367 const weights = [1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9]; 18368 const side = Math.round(Math.sqrt(weights.length)); 18369 const halfSide = Math.floor(side / 2); 18370 const maskResult = []; 18371 for (let y = 0; y < sh; y++) { 18372 for (let x = 0; x < sw; x++) { 18373 const so = y * sw + x; 18374 let a = 0; 18375 for (let cy = 0; cy < side; cy++) { 18376 for (let cx = 0; cx < side; cx++) { 18377 const scy = y + cy - halfSide; 18378 const scx = x + cx - halfSide; 18362 18379 if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) { 18363 varsrcOff = scy * sw + scx;18364 varwt = weights[cy * side + cx];18380 const srcOff = scy * sw + scx; 18381 const wt = weights[cy * side + cx]; 18365 18382 a += mask[srcOff] * wt; 18366 18383 } … … 18385 18402 const Mask = function (imageData) { 18386 18403 // Detect pixels close to the background color 18387 varthreshold = this.threshold(), mask = backgroundMask(imageData, threshold);18404 let threshold = this.threshold(), mask = backgroundMask(imageData, threshold); 18388 18405 if (mask) { 18389 18406 // Erode … … 18413 18430 */ 18414 18431 const Noise = function (imageData) { 18415 var amount = this.noise() * 255, data = imageData.data, nPixels = data.length, half = amount / 2, i;18416 for ( i = 0; i < nPixels; i += 4) {18432 const amount = this.noise() * 255, data = imageData.data, nPixels = data.length, half = amount / 2; 18433 for (let i = 0; i < nPixels; i += 4) { 18417 18434 data[i + 0] += half - 2 * half * Math.random(); 18418 18435 data[i + 1] += half - 2 * half * Math.random(); … … 18429 18446 */ 18430 18447 18431 /*eslint-disable max-depth */18432 18448 /** 18433 18449 * Pixelate Filter. Averages groups of pixels and redraws … … 18444 18460 */ 18445 18461 const Pixelate = function (imageData) { 18446 varpixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height, x, y, i,18462 let pixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height, x, y, i, 18447 18463 //pixelsPerBin = pixelSize * pixelSize, 18448 18464 red, green, blue, alpha, nBinsX = Math.ceil(width / pixelSize), nBinsY = Math.ceil(height / pixelSize), xBinStart, xBinEnd, yBinStart, yBinEnd, xBin, yBin, pixelsInBin, data = imageData.data; … … 18530 18546 const Posterize = function (imageData) { 18531 18547 // level must be between 1 and 255 18532 varlevels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels, i;18548 let levels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels, i; 18533 18549 for (i = 0; i < len; i += 1) { 18534 18550 data[i] = Math.floor(data[i] / scale) * scale; … … 18558 18574 */ 18559 18575 const RGB = function (imageData) { 18560 vardata = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), i, brightness;18576 let data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), i, brightness; 18561 18577 for (i = 0; i < nPixels; i += 4) { 18562 18578 brightness = … … 18633 18649 */ 18634 18650 const RGBA = function (imageData) { 18635 var data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), alpha = this.alpha(), i, ia;18636 for ( i = 0; i < nPixels; i += 4) {18637 ia = 1 - alpha;18651 const data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), alpha = this.alpha(); 18652 for (let i = 0; i < nPixels; i += 4) { 18653 const ia = 1 - alpha; 18638 18654 data[i] = red * alpha + data[i] * ia; // r 18639 18655 data[i + 1] = green * alpha + data[i + 1] * ia; // g … … 18722 18738 */ 18723 18739 const Sepia = function (imageData) { 18724 vardata = imageData.data, nPixels = data.length, i, r, g, b;18740 let data = imageData.data, nPixels = data.length, i, r, g, b; 18725 18741 for (i = 0; i < nPixels; i += 4) { 18726 18742 r = data[i + 0]; … … 18747 18763 */ 18748 18764 const Solarize = function (imageData) { 18749 var data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4, y = h; 18765 const data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4; 18766 let y = h; 18750 18767 do { 18751 varoffsetY = (y - 1) * w4;18752 varx = w;18768 const offsetY = (y - 1) * w4; 18769 let x = w; 18753 18770 do { 18754 varoffset = offsetY + (x - 1) * 4;18755 varr = data[offset];18756 varg = data[offset + 1];18757 varb = data[offset + 2];18771 const offset = offsetY + (x - 1) * 4; 18772 let r = data[offset]; 18773 let g = data[offset + 1]; 18774 let b = data[offset + 2]; 18758 18775 if (r > 127) { 18759 18776 r = 255 - r; … … 18787 18804 */ 18788 18805 const Threshold = function (imageData) { 18789 var level = this.threshold() * 255, data = imageData.data, len = data.length, i;18790 for ( i = 0; i < len; i += 1) {18806 const level = this.threshold() * 255, data = imageData.data, len = data.length; 18807 for (let i = 0; i < len; i += 1) { 18791 18808 data[i] = data[i] < level ? 0 : 255; 18792 18809 }
Note:
See TracChangeset
for help on using the changeset viewer.