Changeset 0c6b92a for imaps-frontend/node_modules/konva/lib/Util.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/lib/Util.js
rd565449 r0c6b92a 28 28 } 29 29 point(point) { 30 varm = this.m;30 const m = this.m; 31 31 return { 32 32 x: m[0] * point.x + m[2] * point.y + m[4], … … 47 47 } 48 48 rotate(rad) { 49 varc = Math.cos(rad);50 vars = Math.sin(rad);51 varm11 = this.m[0] * c + this.m[2] * s;52 varm12 = this.m[1] * c + this.m[3] * s;53 varm21 = this.m[0] * -s + this.m[2] * c;54 varm22 = this.m[1] * -s + this.m[3] * c;49 const c = Math.cos(rad); 50 const s = Math.sin(rad); 51 const m11 = this.m[0] * c + this.m[2] * s; 52 const m12 = this.m[1] * c + this.m[3] * s; 53 const m21 = this.m[0] * -s + this.m[2] * c; 54 const m22 = this.m[1] * -s + this.m[3] * c; 55 55 this.m[0] = m11; 56 56 this.m[1] = m12; … … 66 66 } 67 67 skew(sx, sy) { 68 varm11 = this.m[0] + this.m[2] * sy;69 varm12 = this.m[1] + this.m[3] * sy;70 varm21 = this.m[2] + this.m[0] * sx;71 varm22 = this.m[3] + this.m[1] * sx;68 const m11 = this.m[0] + this.m[2] * sy; 69 const m12 = this.m[1] + this.m[3] * sy; 70 const m21 = this.m[2] + this.m[0] * sx; 71 const m22 = this.m[3] + this.m[1] * sx; 72 72 this.m[0] = m11; 73 73 this.m[1] = m12; … … 77 77 } 78 78 multiply(matrix) { 79 varm11 = this.m[0] * matrix.m[0] + this.m[2] * matrix.m[1];80 varm12 = this.m[1] * matrix.m[0] + this.m[3] * matrix.m[1];81 varm21 = this.m[0] * matrix.m[2] + this.m[2] * matrix.m[3];82 varm22 = this.m[1] * matrix.m[2] + this.m[3] * matrix.m[3];83 vardx = this.m[0] * matrix.m[4] + this.m[2] * matrix.m[5] + this.m[4];84 vardy = this.m[1] * matrix.m[4] + this.m[3] * matrix.m[5] + this.m[5];79 const m11 = this.m[0] * matrix.m[0] + this.m[2] * matrix.m[1]; 80 const m12 = this.m[1] * matrix.m[0] + this.m[3] * matrix.m[1]; 81 const m21 = this.m[0] * matrix.m[2] + this.m[2] * matrix.m[3]; 82 const m22 = this.m[1] * matrix.m[2] + this.m[3] * matrix.m[3]; 83 const dx = this.m[0] * matrix.m[4] + this.m[2] * matrix.m[5] + this.m[4]; 84 const dy = this.m[1] * matrix.m[4] + this.m[3] * matrix.m[5] + this.m[5]; 85 85 this.m[0] = m11; 86 86 this.m[1] = m12; … … 92 92 } 93 93 invert() { 94 vard = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]);95 varm0 = this.m[3] * d;96 varm1 = -this.m[1] * d;97 varm2 = -this.m[2] * d;98 varm3 = this.m[0] * d;99 varm4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]);100 varm5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]);94 const d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]); 95 const m0 = this.m[3] * d; 96 const m1 = -this.m[1] * d; 97 const m2 = -this.m[2] * d; 98 const m3 = this.m[0] * d; 99 const m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]); 100 const m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]); 101 101 this.m[0] = m0; 102 102 this.m[1] = m1; … … 111 111 } 112 112 decompose() { 113 vara = this.m[0];114 varb = this.m[1];115 varc = this.m[2];116 vard = this.m[3];117 vare = this.m[4];118 varf = this.m[5];119 vardelta = a * d - b * c;120 let result = {113 const a = this.m[0]; 114 const b = this.m[1]; 115 const c = this.m[2]; 116 const d = this.m[3]; 117 const e = this.m[4]; 118 const f = this.m[5]; 119 const delta = a * d - b * c; 120 const result = { 121 121 x: e, 122 122 y: f, … … 128 128 }; 129 129 if (a != 0 || b != 0) { 130 varr = Math.sqrt(a * a + b * b);130 const r = Math.sqrt(a * a + b * b); 131 131 result.rotation = b > 0 ? Math.acos(a / r) : -Math.acos(a / r); 132 132 result.scaleX = r; … … 136 136 } 137 137 else if (c != 0 || d != 0) { 138 vars = Math.sqrt(c * c + d * d);138 const s = Math.sqrt(c * c + d * d); 139 139 result.rotation = 140 140 Math.PI / 2 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s)); … … 151 151 } 152 152 exports.Transform = Transform; 153 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 = '#', EMPTY_STRING = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ', RGB_PAREN = 'rgb(', COLORS = {153 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 = '#', EMPTY_STRING = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ', RGB_PAREN = 'rgb(', COLORS = { 154 154 aliceblue: [240, 248, 255], 155 155 antiquewhite: [250, 235, 215], … … 337 337 return false; 338 338 } 339 varfirstChar = selector[0];339 const firstChar = selector[0]; 340 340 return (firstChar === '#' || 341 341 firstChar === '.' || … … 366 366 }, 367 367 createCanvasElement() { 368 varcanvas = document.createElement('canvas');368 const canvas = document.createElement('canvas'); 369 369 try { 370 370 canvas.style = canvas.style || {}; … … 385 385 }, 386 386 _urlToImage(url, callback) { 387 varimageObj = exports.Util.createImageElement();387 const imageObj = exports.Util.createImageElement(); 388 388 imageObj.onload = function () { 389 389 callback(imageObj); … … 396 396 _hexToRgb(hex) { 397 397 hex = hex.replace(HASH, EMPTY_STRING); 398 varbigint = parseInt(hex, 16);398 const bigint = parseInt(hex, 16); 399 399 return { 400 400 r: (bigint >> 16) & 255, … … 404 404 }, 405 405 getRandomColor() { 406 varrandColor = ((Math.random() * 0xffffff) << 0).toString(16);406 let randColor = ((Math.random() * 0xffffff) << 0).toString(16); 407 407 while (randColor.length < 6) { 408 408 randColor = ZERO + randColor; … … 411 411 }, 412 412 getRGB(color) { 413 varrgb;413 let rgb; 414 414 if (color in COLORS) { 415 415 rgb = COLORS[color]; … … 451 451 }, 452 452 _namedColorToRBA(str) { 453 varc = COLORS[str.toLowerCase()];453 const c = COLORS[str.toLowerCase()]; 454 454 if (!c) { 455 455 return null; … … 465 465 if (str.indexOf('rgb(') === 0) { 466 466 str = str.match(/rgb\(([^)]+)\)/)[1]; 467 varparts = str.split(/ *, */).map(Number);467 const parts = str.split(/ *, */).map(Number); 468 468 return { 469 469 r: parts[0], … … 477 477 if (str.indexOf('rgba(') === 0) { 478 478 str = str.match(/rgba\(([^)]+)\)/)[1]; 479 varparts = str.split(/ *, */).map((n, index) => {479 const parts = str.split(/ *, */).map((n, index) => { 480 480 if (n.slice(-1) === '%') { 481 481 return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255; … … 594 594 }, 595 595 cloneObject(obj) { 596 varretObj = {};597 for ( varkey in obj) {596 const retObj = {}; 597 for (const key in obj) { 598 598 if (this._isPlainObject(obj[key])) { 599 599 retObj[key] = this.cloneObject(obj[key]); … … 644 644 }, 645 645 each(obj, func) { 646 for ( varkey in obj) {646 for (const key in obj) { 647 647 func(key, obj[key]); 648 648 } … … 652 652 }, 653 653 _getProjectionToSegment(x1, y1, x2, y2, x3, y3) { 654 varx, y, dist;655 varpd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);654 let x, y, dist; 655 const pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); 656 656 if (pd2 == 0) { 657 657 x = x1; … … 660 660 } 661 661 else { 662 varu = ((x3 - x1) * (x2 - x1) + (y3 - y1) * (y2 - y1)) / pd2;662 const u = ((x3 - x1) * (x2 - x1) + (y3 - y1) * (y2 - y1)) / pd2; 663 663 if (u < 0) { 664 664 x = x1; … … 680 680 }, 681 681 _getProjectionToLine(pt, line, isClosed) { 682 varpc = exports.Util.cloneObject(pt);683 vardist = Number.MAX_VALUE;682 const pc = exports.Util.cloneObject(pt); 683 let dist = Number.MAX_VALUE; 684 684 line.forEach(function (p1, i) { 685 685 if (!isClosed && i === line.length - 1) { 686 686 return; 687 687 } 688 varp2 = line[(i + 1) % line.length];689 varproj = exports.Util._getProjectionToSegment(p1.x, p1.y, p2.x, p2.y, pt.x, pt.y);690 varpx = proj[0], py = proj[1], pdist = proj[2];688 const p2 = line[(i + 1) % line.length]; 689 const proj = exports.Util._getProjectionToSegment(p1.x, p1.y, p2.x, p2.y, pt.x, pt.y); 690 const px = proj[0], py = proj[1], pdist = proj[2]; 691 691 if (pdist < dist) { 692 692 pc.x = px; … … 698 698 }, 699 699 _prepareArrayForTween(startArray, endArray, isClosed) { 700 varn, start = [], end = [];700 let n, start = [], end = []; 701 701 if (startArray.length > endArray.length) { 702 vartemp = endArray;702 const temp = endArray; 703 703 endArray = startArray; 704 704 startArray = temp; … … 716 716 }); 717 717 } 718 varnewStart = [];718 const newStart = []; 719 719 end.forEach(function (point) { 720 varpr = exports.Util._getProjectionToLine(point, start, isClosed);720 const pr = exports.Util._getProjectionToLine(point, start, isClosed); 721 721 newStart.push(pr.x); 722 722 newStart.push(pr.y); … … 725 725 }, 726 726 _prepareToStringify(obj) { 727 vardesc;727 let desc; 728 728 obj.visitedByCircularReferenceRemoval = true; 729 for ( varkey in obj) {729 for (const key in obj) { 730 730 if (!(obj.hasOwnProperty(key) && obj[key] && typeof obj[key] == 'object')) { 731 731 continue; … … 754 754 }, 755 755 _assign(target, source) { 756 for ( varkey in source) {756 for (const key in source) { 757 757 target[key] = source[key]; 758 758 }
Note:
See TracChangeset
for help on using the changeset viewer.