Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/konva/lib/shapes/Transformer.js
rd565449 r0c6b92a 11 11 const Validators_1 = require("../Validators"); 12 12 const Global_2 = require("../Global"); 13 varEVENTS_NAME = 'tr-konva';14 varATTR_CHANGE_LIST = [13 const EVENTS_NAME = 'tr-konva'; 14 const ATTR_CHANGE_LIST = [ 15 15 'resizeEnabledChange', 16 16 'rotateAnchorOffsetChange', … … 31 31 .map((e) => e + `.${EVENTS_NAME}`) 32 32 .join(' '); 33 varNODES_RECT = 'nodesRect';34 varTRANSFORM_CHANGE_STR = [33 const NODES_RECT = 'nodesRect'; 34 const TRANSFORM_CHANGE_STR = [ 35 35 'widthChange', 36 36 'heightChange', … … 45 45 'strokeWidthChange', 46 46 ]; 47 varANGLES = {47 const ANGLES = { 48 48 'top-left': -45, 49 49 'top-center': 0, … … 61 61 } 62 62 rad += Util_1.Util.degToRad(ANGLES[anchorName] || 0); 63 varangle = ((Util_1.Util.radToDeg(rad) % 360) + 360) % 360;63 const angle = ((Util_1.Util.radToDeg(rad) % 360) + 360) % 360; 64 64 if (Util_1.Util._inRange(angle, 315 + 22.5, 360) || Util_1.Util._inRange(angle, 0, 22.5)) { 65 65 return 'ns-resize'; … … 91 91 } 92 92 } 93 varANCHORS_NAMES = [93 const ANCHORS_NAMES = [ 94 94 'top-left', 95 95 'top-center', … … 101 101 'bottom-right', 102 102 ]; 103 varMAX_SAFE_INTEGER = 100000000;103 const MAX_SAFE_INTEGER = 100000000; 104 104 function getCenter(shape) { 105 105 return { … … 208 208 }); 209 209 this._resetTransformCache(); 210 varelementsCreated = !!this.findOne('.top-left');210 const elementsCreated = !!this.findOne('.top-left'); 211 211 if (elementsCreated) { 212 212 this.update(); … … 270 270 } 271 271 __getNodeShape(node, rot = this.rotation(), relative) { 272 varrect = node.getClientRect({272 const rect = node.getClientRect({ 273 273 skipTransform: true, 274 274 skipShadow: true, 275 275 skipStroke: this.ignoreStroke(), 276 276 }); 277 varabsScale = node.getAbsoluteScale(relative);278 varabsPos = node.getAbsolutePosition(relative);279 vardx = rect.x * absScale.x - node.offsetX() * absScale.x;280 vardy = rect.y * absScale.y - node.offsetY() * absScale.y;277 const absScale = node.getAbsoluteScale(relative); 278 const absPos = node.getAbsolutePosition(relative); 279 const dx = rect.x * absScale.x - node.offsetX() * absScale.x; 280 const dy = rect.y * absScale.y - node.offsetY() * absScale.y; 281 281 const rotation = (Global_1.Konva.getAngle(node.getAbsoluteRotation()) + Math.PI * 2) % 282 282 (Math.PI * 2); … … 294 294 } 295 295 __getNodeRect() { 296 varnode = this.getNode();296 const node = this.getNode(); 297 297 if (!node) { 298 298 return { … … 311 311 skipStroke: this.ignoreStroke(), 312 312 }); 313 varpoints = [313 const points = [ 314 314 { x: box.x, y: box.y }, 315 315 { x: box.x + box.width, y: box.y }, … … 317 317 { x: box.x, y: box.y + box.height }, 318 318 ]; 319 vartrans = node.getAbsoluteTransform();319 const trans = node.getAbsoluteTransform(); 320 320 points.forEach(function (point) { 321 vartransformed = trans.point(point);321 const transformed = trans.point(point); 322 322 totalPoints.push(transformed); 323 323 }); … … 325 325 const tr = new Util_1.Transform(); 326 326 tr.rotate(-Global_1.Konva.getAngle(this.rotation())); 327 varminX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;327 let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity; 328 328 totalPoints.forEach(function (point) { 329 vartransformed = tr.point(point);329 const transformed = tr.point(point); 330 330 if (minX === undefined) { 331 331 minX = maxX = transformed.x; … … 367 367 } 368 368 _createAnchor(name) { 369 varanchor = new Rect_1.Rect({369 const anchor = new Rect_1.Rect({ 370 370 stroke: 'rgb(0, 161, 255)', 371 371 fill: 'white', … … 376 376 hitStrokeWidth: TOUCH_DEVICE ? 10 : 'auto', 377 377 }); 378 varself = this;378 const self = this; 379 379 anchor.on('mousedown touchstart', function (e) { 380 380 self._handleMouseDown(e); … … 388 388 }); 389 389 anchor.on('mouseenter', () => { 390 varrad = Global_1.Konva.getAngle(this.rotation());391 varrotateCursor = this.rotateAnchorCursor();392 varcursor = getCursor(name, rad, rotateCursor);390 const rad = Global_1.Konva.getAngle(this.rotation()); 391 const rotateCursor = this.rotateAnchorCursor(); 392 const cursor = getCursor(name, rad, rotateCursor); 393 393 anchor.getStage().content && 394 394 (anchor.getStage().content.style.cursor = cursor); … … 403 403 } 404 404 _createBack() { 405 varback = new Shape_1.Shape({405 const back = new Shape_1.Shape({ 406 406 name: 'back', 407 407 width: 0, … … 409 409 draggable: true, 410 410 sceneFunc(ctx, shape) { 411 vartr = shape.getParent();412 varpadding = tr.padding();411 const tr = shape.getParent(); 412 const padding = tr.padding(); 413 413 ctx.beginPath(); 414 414 ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2); … … 423 423 return; 424 424 } 425 varpadding = this.padding();425 const padding = this.padding(); 426 426 ctx.beginPath(); 427 427 ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2); … … 449 449 } 450 450 this._movingAnchorName = e.target.name().split(' ')[0]; 451 varattrs = this._getNodeRect();452 varwidth = attrs.width;453 varheight = attrs.height;454 varhypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));451 const attrs = this._getNodeRect(); 452 const width = attrs.width; 453 const height = attrs.height; 454 const hypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)); 455 455 this.sin = Math.abs(height / hypotenuse); 456 456 this.cos = Math.abs(width / hypotenuse); … … 462 462 } 463 463 this._transforming = true; 464 varap = e.target.getAbsolutePosition();465 varpos = e.target.getStage().getPointerPosition();464 const ap = e.target.getAbsolutePosition(); 465 const pos = e.target.getStage().getPointerPosition(); 466 466 this._anchorDragOffset = { 467 467 x: pos.x - ap.x, … … 475 475 } 476 476 _handleMouseMove(e) { 477 varx, y, newHypotenuse;478 varanchorNode = this.findOne('.' + this._movingAnchorName);479 varstage = anchorNode.getStage();477 let x, y, newHypotenuse; 478 const anchorNode = this.findOne('.' + this._movingAnchorName); 479 const stage = anchorNode.getStage(); 480 480 stage.setPointersPositions(e); 481 481 const pp = stage.getPointerPosition(); … … 494 494 } 495 495 if (this._movingAnchorName === 'rotater') { 496 varattrs = this._getNodeRect();496 const attrs = this._getNodeRect(); 497 497 x = anchorNode.x() - attrs.width / 2; 498 498 y = -anchorNode.y() + attrs.height / 2; … … 501 501 delta -= Math.PI; 502 502 } 503 varoldRotation = Global_1.Konva.getAngle(this.rotation());503 const oldRotation = Global_1.Konva.getAngle(this.rotation()); 504 504 const newRotation = oldRotation + delta; 505 505 const tol = Global_1.Konva.getAngle(this.rotationSnapTolerance()); … … 510 510 return; 511 511 } 512 varshiftBehavior = this.shiftBehavior();513 varkeepProportion;512 const shiftBehavior = this.shiftBehavior(); 513 let keepProportion; 514 514 if (shiftBehavior === 'inverted') { 515 515 keepProportion = this.keepRatio() && !e.shiftKey; … … 630 630 var centeredScaling = this.centeredScaling() || e.altKey; 631 631 if (centeredScaling) { 632 vartopLeft = this.findOne('.top-left');633 varbottomRight = this.findOne('.bottom-right');634 vartopOffsetX = topLeft.x();635 vartopOffsetY = topLeft.y();636 varbottomOffsetX = this.getWidth() - bottomRight.x();637 varbottomOffsetY = this.getHeight() - bottomRight.y();632 const topLeft = this.findOne('.top-left'); 633 const bottomRight = this.findOne('.bottom-right'); 634 const topOffsetX = topLeft.x(); 635 const topOffsetY = topLeft.y(); 636 const bottomOffsetX = this.getWidth() - bottomRight.x(); 637 const bottomOffsetY = this.getHeight() - bottomRight.y(); 638 638 bottomRight.move({ 639 639 x: -topOffsetX, … … 645 645 }); 646 646 } 647 varabsPos = this.findOne('.top-left').getAbsolutePosition();647 const absPos = this.findOne('.top-left').getAbsolutePosition(); 648 648 x = absPos.x; 649 649 y = absPos.y; 650 varwidth = this.findOne('.bottom-right').x() - this.findOne('.top-left').x();651 varheight = this.findOne('.bottom-right').y() - this.findOne('.top-left').y();650 const width = this.findOne('.bottom-right').x() - this.findOne('.top-left').x(); 651 const height = this.findOne('.bottom-right').y() - this.findOne('.top-left').y(); 652 652 this._fitNodesInto({ 653 653 x: x, … … 674 674 window.removeEventListener('touchend', this._handleMouseUp, true); 675 675 } 676 varnode = this.getNode();676 const node = this.getNode(); 677 677 activeTransformersCount--; 678 678 this._fire('transformend', { evt: e, target: node }); … … 689 689 } 690 690 _fitNodesInto(newAttrs, evt) { 691 varoldAttrs = this._getNodeRect();691 const oldAttrs = this._getNodeRect(); 692 692 const minSize = 1; 693 693 if (Util_1.Util._inRange(newAttrs.width, -this.padding() * 2 - minSize, minSize)) { … … 699 699 return; 700 700 } 701 vart = new Util_1.Transform();701 const t = new Util_1.Transform(); 702 702 t.rotate(Global_1.Konva.getAngle(this.rotation())); 703 703 if (this._movingAnchorName && … … 816 816 update() { 817 817 var _a; 818 varattrs = this._getNodeRect();818 const attrs = this._getNodeRect(); 819 819 this.rotation(Util_1.Util._getRotation(attrs.rotation)); 820 varwidth = attrs.width;821 varheight = attrs.height;822 varenabledAnchors = this.enabledAnchors();823 varresizeEnabled = this.resizeEnabled();824 varpadding = this.padding();825 varanchorSize = this.anchorSize();820 const width = attrs.width; 821 const height = attrs.height; 822 const enabledAnchors = this.enabledAnchors(); 823 const resizeEnabled = this.resizeEnabled(); 824 const padding = this.padding(); 825 const anchorSize = this.anchorSize(); 826 826 const anchors = this.find('._anchor'); 827 827 anchors.forEach((node) => { … … 918 918 if (this._transforming) { 919 919 this._removeEvents(); 920 varanchorNode = this.findOne('.' + this._movingAnchorName);920 const anchorNode = this.findOne('.' + this._movingAnchorName); 921 921 if (anchorNode) { 922 922 anchorNode.stopDrag(); … … 937 937 } 938 938 clone(obj) { 939 varnode = Node_1.Node.prototype.clone.call(this, obj);939 const node = Node_1.Node.prototype.clone.call(this, obj); 940 940 return node; 941 941 }
Note:
See TracChangeset
for help on using the changeset viewer.