Changeset 0c6b92a for imaps-frontend/node_modules/konva/lib/Node.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/Node.js
rd565449 r0c6b92a 8 8 const DragAndDrop_1 = require("./DragAndDrop"); 9 9 const Validators_1 = require("./Validators"); 10 varABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER = 'mouseenter', MOUSELEAVE = 'mouseleave', NAME = 'name', SET = 'set', SHAPE = 'Shape', SPACE = ' ', STAGE = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR = [10 const ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER = 'mouseenter', MOUSELEAVE = 'mouseleave', NAME = 'name', SET = 'set', SHAPE = 'Shape', SPACE = ' ', STAGE = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR = [ 11 11 'xChange.konva', 12 12 'yChange.konva', … … 57 57 } 58 58 _getCache(attr, privateGetter) { 59 varcache = this._cache.get(attr);60 varisTransform = attr === TRANSFORM || attr === ABSOLUTE_TRANSFORM;61 varinvalid = cache === undefined || (isTransform && cache.dirty === true);59 let cache = this._cache.get(attr); 60 const isTransform = attr === TRANSFORM || attr === ABSOLUTE_TRANSFORM; 61 const invalid = cache === undefined || (isTransform && cache.dirty === true); 62 62 if (invalid) { 63 63 cache = privateGetter.call(this); … … 96 96 } 97 97 cache(config) { 98 varconf = config || {};99 varrect = {};98 const conf = config || {}; 99 let rect = {}; 100 100 if (conf.x === undefined || 101 101 conf.y === undefined || … … 107 107 }); 108 108 } 109 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;109 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; 110 110 if (!width || !height) { 111 111 Util_1.Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.'); … … 118 118 x -= offset; 119 119 y -= offset; 120 varcachedSceneCanvas = new Canvas_1.SceneCanvas({120 const cachedSceneCanvas = new Canvas_1.SceneCanvas({ 121 121 pixelRatio: pixelRatio, 122 122 width: width, … … 179 179 } 180 180 _transformedRect(rect, top) { 181 varpoints = [181 const points = [ 182 182 { x: rect.x, y: rect.y }, 183 183 { x: rect.x + rect.width, y: rect.y }, … … 185 185 { x: rect.x, y: rect.y + rect.height }, 186 186 ]; 187 varminX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;188 vartrans = this.getAbsoluteTransform(top);187 let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity; 188 const trans = this.getAbsoluteTransform(top); 189 189 points.forEach(function (point) { 190 vartransformed = trans.point(point);190 const transformed = trans.point(point); 191 191 if (minX === undefined) { 192 192 minX = maxX = transformed.x; … … 211 211 const canvasCache = this._getCanvasCache(); 212 212 context.translate(canvasCache.x, canvasCache.y); 213 varcacheCanvas = this._getCachedSceneCanvas();214 varratio = cacheCanvas.pixelRatio;213 const cacheCanvas = this._getCachedSceneCanvas(); 214 const ratio = cacheCanvas.pixelRatio; 215 215 context.drawImage(cacheCanvas._canvas, 0, 0, cacheCanvas.width / ratio, cacheCanvas.height / ratio); 216 216 context.restore(); 217 217 } 218 218 _drawCachedHitCanvas(context) { 219 varcanvasCache = this._getCanvasCache(), hitCanvas = canvasCache.hit;219 const canvasCache = this._getCanvasCache(), hitCanvas = canvasCache.hit; 220 220 context.save(); 221 221 context.translate(canvasCache.x, canvasCache.y); … … 224 224 } 225 225 _getCachedSceneCanvas() { 226 varfilters = this.filters(), cachedCanvas = this._getCanvasCache(), sceneCanvas = cachedCanvas.scene, filterCanvas = cachedCanvas.filter, filterContext = filterCanvas.getContext(), len, imageData, n, filter;226 let filters = this.filters(), cachedCanvas = this._getCanvasCache(), sceneCanvas = cachedCanvas.scene, filterCanvas = cachedCanvas.filter, filterContext = filterCanvas.getContext(), len, imageData, n, filter; 227 227 if (filters) { 228 228 if (!this._filterUpToDate) { 229 varratio = sceneCanvas.pixelRatio;229 const ratio = sceneCanvas.pixelRatio; 230 230 filterCanvas.setSize(sceneCanvas.width / sceneCanvas.pixelRatio, sceneCanvas.height / sceneCanvas.pixelRatio); 231 231 try { … … 262 262 return this._delegate.apply(this, arguments); 263 263 } 264 varevents = evtStr.split(SPACE), len = events.length, n, event, parts, baseEvent, name;264 let events = evtStr.split(SPACE), len = events.length, n, event, parts, baseEvent, name; 265 265 for (n = 0; n < len; n++) { 266 266 event = events[n]; … … 279 279 } 280 280 off(evtStr, callback) { 281 varevents = (evtStr || '').split(SPACE), len = events.length, n, t, event, parts, baseEvent, name;281 let events = (evtStr || '').split(SPACE), len = events.length, n, t, event, parts, baseEvent, name; 282 282 this._cache && this._cache.delete(ALL_LISTENERS); 283 283 if (!evtStr) { … … 305 305 } 306 306 dispatchEvent(evt) { 307 vare = {307 const e = { 308 308 target: this, 309 309 type: evt.type, … … 324 324 } 325 325 _delegate(event, selector, handler) { 326 varstopNode = this;326 const stopNode = this; 327 327 this.on(event, function (evt) { 328 vartargets = evt.target.findAncestors(selector, true, stopNode);329 for ( vari = 0; i < targets.length; i++) {328 const targets = evt.target.findAncestors(selector, true, stopNode); 329 for (let i = 0; i < targets.length; i++) { 330 330 evt = Util_1.Util.cloneObject(evt); 331 331 evt.currentTarget = targets[i]; … … 352 352 _remove() { 353 353 this._clearCaches(); 354 varparent = this.getParent();354 const parent = this.getParent(); 355 355 if (parent && parent.children) { 356 356 parent.children.splice(this.index, 1); … … 365 365 } 366 366 getAttr(attr) { 367 varmethod = 'get' + Util_1.Util._capitalize(attr);367 const method = 'get' + Util_1.Util._capitalize(attr); 368 368 if (Util_1.Util._isFunction(this[method])) { 369 369 return this[method](); … … 372 372 } 373 373 getAncestors() { 374 varparent = this.getParent(), ancestors = [];374 let parent = this.getParent(), ancestors = []; 375 375 while (parent) { 376 376 ancestors.push(parent); … … 384 384 setAttrs(config) { 385 385 this._batchTransformChanges(() => { 386 varkey, method;386 let key, method; 387 387 if (!config) { 388 388 return this; … … 439 439 return this._isVisible(top) && this._isListening(top); 440 440 } 441 varlayer = this.getLayer();442 varlayerUnderDrag = false;441 const layer = this.getLayer(); 442 let layerUnderDrag = false; 443 443 DragAndDrop_1.DD._dragElements.forEach((elem) => { 444 444 if (elem.dragStatus !== 'dragging') { … … 452 452 } 453 453 }); 454 vardragSkip = !skipDragCheck &&454 const dragSkip = !skipDragCheck && 455 455 !Global_1.Konva.hitOnDragEnabled && 456 456 (layerUnderDrag || Global_1.Konva.isTransforming()); … … 469 469 } 470 470 getAbsoluteZIndex() { 471 vardepth = this.getDepth(), that = this, index = 0, nodes, len, n, child;471 let depth = this.getDepth(), that = this, index = 0, nodes, len, n, child; 472 472 function addChildren(children) { 473 473 nodes = []; … … 494 494 } 495 495 getDepth() { 496 vardepth = 0, parent = this.parent;496 let depth = 0, parent = this.parent; 497 497 while (parent) { 498 498 depth++; … … 529 529 return null; 530 530 } 531 varpos = stage.getPointerPosition();531 const pos = stage.getPointerPosition(); 532 532 if (!pos) { 533 533 return null; 534 534 } 535 vartransform = this.getAbsoluteTransform().copy();535 const transform = this.getAbsoluteTransform().copy(); 536 536 transform.invert(); 537 537 return transform.point(pos); … … 550 550 top = true; 551 551 } 552 varabsoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Util_1.Transform(), offset = this.offset();552 const absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Util_1.Transform(), offset = this.offset(); 553 553 absoluteTransform.m = absoluteMatrix.slice(); 554 554 absoluteTransform.translate(offset.x, offset.y); … … 560 560 this.attrs.y = y; 561 561 this._clearCache(TRANSFORM); 562 varit = this._getAbsoluteTransform().copy();562 const it = this._getAbsoluteTransform().copy(); 563 563 it.invert(); 564 564 it.translate(pos.x, pos.y); … … 574 574 } 575 575 _setTransform(trans) { 576 varkey;576 let key; 577 577 for (key in trans) { 578 578 this.attrs[key] = trans[key]; … … 580 580 } 581 581 _clearTransform() { 582 vartrans = {582 const trans = { 583 583 x: this.x(), 584 584 y: this.y(), … … 603 603 } 604 604 move(change) { 605 varchangeX = change.x, changeY = change.y, x = this.x(), y = this.y();605 let changeX = change.x, changeY = change.y, x = this.x(), y = this.y(); 606 606 if (changeX !== undefined) { 607 607 x += changeX; … … 614 614 } 615 615 _eachAncestorReverse(func, top) { 616 varfamily = [], parent = this.getParent(), len, n;616 let family = [], parent = this.getParent(), len, n; 617 617 if (top && top._id === this._id) { 618 618 return; … … 637 637 return false; 638 638 } 639 varindex = this.index, len = this.parent.getChildren().length;639 const index = this.index, len = this.parent.getChildren().length; 640 640 if (index < len - 1) { 641 641 this.parent.children.splice(index, 1); … … 651 651 return false; 652 652 } 653 varindex = this.index, len = this.parent.getChildren().length;653 const index = this.index, len = this.parent.getChildren().length; 654 654 if (index < len - 1) { 655 655 this.parent.children.splice(index, 1); … … 665 665 return false; 666 666 } 667 varindex = this.index;667 const index = this.index; 668 668 if (index > 0) { 669 669 this.parent.children.splice(index, 1); … … 679 679 return false; 680 680 } 681 varindex = this.index;681 const index = this.index; 682 682 if (index > 0) { 683 683 this.parent.children.splice(index, 1); … … 700 700 '.'); 701 701 } 702 varindex = this.index;702 const index = this.index; 703 703 this.parent.children.splice(index, 1); 704 704 this.parent.children.splice(zIndex, 0, this); … … 710 710 } 711 711 _getAbsoluteOpacity() { 712 varabsOpacity = this.opacity();713 varparent = this.getParent();712 let absOpacity = this.opacity(); 713 const parent = this.getParent(); 714 714 if (parent && !parent._isUnderCache) { 715 715 absOpacity *= parent.getAbsoluteOpacity(); … … 725 725 } 726 726 toObject() { 727 varattrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject;727 let attrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject; 728 728 const obj = { 729 729 attrs: {}, … … 754 754 } 755 755 findAncestors(selector, includeSelf, stopNode) { 756 varres = [];756 const res = []; 757 757 if (includeSelf && this._isMatch(selector)) { 758 758 res.push(this); 759 759 } 760 varancestor = this.parent;760 let ancestor = this.parent; 761 761 while (ancestor) { 762 762 if (ancestor === stopNode) { … … 783 783 return selector(this); 784 784 } 785 varselectorArr = selector.replace(/ /g, '').split(','), len = selectorArr.length, n, sel;785 let selectorArr = selector.replace(/ /g, '').split(','), len = selectorArr.length, n, sel; 786 786 for (n = 0; n < len; n++) { 787 787 sel = selectorArr[n]; … … 810 810 } 811 811 getLayer() { 812 varparent = this.getParent();812 const parent = this.getParent(); 813 813 return parent ? parent.getLayer() : null; 814 814 } … … 817 817 } 818 818 _getStage() { 819 varparent = this.getParent();819 const parent = this.getParent(); 820 820 if (parent) { 821 821 return parent.getStage(); … … 844 844 } 845 845 _getAbsoluteTransform(top) { 846 varat;846 let at; 847 847 if (top) { 848 848 at = new Util_1.Transform(); 849 849 this._eachAncestorReverse(function (node) { 850 vartransformsEnabled = node.transformsEnabled();850 const transformsEnabled = node.transformsEnabled(); 851 851 if (transformsEnabled === 'all') { 852 852 at.multiply(node.getTransform()); … … 866 866 at.reset(); 867 867 } 868 vartransformsEnabled = this.transformsEnabled();868 const transformsEnabled = this.transformsEnabled(); 869 869 if (transformsEnabled === 'all') { 870 870 at.multiply(this.getTransform()); … … 882 882 } 883 883 getAbsoluteScale(top) { 884 varparent = this;884 let parent = this; 885 885 while (parent) { 886 886 if (parent._isUnderCache) { … … 904 904 _getTransform() { 905 905 var _a, _b; 906 varm = this._cache.get(TRANSFORM) || new Util_1.Transform();906 const m = this._cache.get(TRANSFORM) || new Util_1.Transform(); 907 907 m.reset(); 908 varx = this.x(), y = this.y(), rotation = Global_1.Konva.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;908 const x = this.x(), y = this.y(), rotation = Global_1.Konva.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; 909 909 if (x !== 0 || y !== 0) { 910 910 m.translate(x, y); … … 926 926 } 927 927 clone(obj) { 928 varattrs = Util_1.Util.cloneObject(this.attrs), key, allListeners, len, n, listener;928 let attrs = Util_1.Util.cloneObject(this.attrs), key, allListeners, len, n, listener; 929 929 for (key in obj) { 930 930 attrs[key] = obj[key]; 931 931 } 932 varnode = new this.constructor(attrs);932 const node = new this.constructor(attrs); 933 933 for (key in this.eventListeners) { 934 934 allListeners = this.eventListeners[key]; … … 948 948 _toKonvaCanvas(config) { 949 949 config = config || {}; 950 varbox = this.getClientRect();951 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 Canvas_1.SceneCanvas({950 const box = this.getClientRect(); 951 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 Canvas_1.SceneCanvas({ 952 952 width: config.width || Math.ceil(box.width) || (stage ? stage.width() : 0), 953 953 height: config.height || … … 977 977 toDataURL(config) { 978 978 config = config || {}; 979 varmimeType = config.mimeType || null, quality = config.quality || null;980 varurl = this._toKonvaCanvas(config).toDataURL(mimeType, quality);979 const mimeType = config.mimeType || null, quality = config.quality || null; 980 const url = this._toKonvaCanvas(config).toDataURL(mimeType, quality); 981 981 if (config.callback) { 982 982 config.callback(url); … … 1045 1045 } 1046 1046 _off(type, name, callback) { 1047 varevtListeners = this.eventListeners[type], i, evtName, handler;1047 let evtListeners = this.eventListeners[type], i, evtName, handler; 1048 1048 for (i = 0; i < evtListeners.length; i++) { 1049 1049 evtName = evtListeners[i].name; … … 1069 1069 addName(name) { 1070 1070 if (!this.hasName(name)) { 1071 varoldName = this.name();1072 varnewName = oldName ? oldName + ' ' + name : name;1071 const oldName = this.name(); 1072 const newName = oldName ? oldName + ' ' + name : name; 1073 1073 this.name(newName); 1074 1074 } … … 1083 1083 return false; 1084 1084 } 1085 varnames = (fullName || '').split(/\s/g);1085 const names = (fullName || '').split(/\s/g); 1086 1086 return names.indexOf(name) !== -1; 1087 1087 } 1088 1088 removeName(name) { 1089 varnames = (this.name() || '').split(/\s/g);1090 varindex = names.indexOf(name);1089 const names = (this.name() || '').split(/\s/g); 1090 const index = names.indexOf(name); 1091 1091 if (index !== -1) { 1092 1092 names.splice(index, 1); … … 1096 1096 } 1097 1097 setAttr(attr, val) { 1098 varfunc = this[SET + Util_1.Util._capitalize(attr)];1098 const func = this[SET + Util_1.Util._capitalize(attr)]; 1099 1099 if (Util_1.Util._isFunction(func)) { 1100 1100 func.call(this, val); … … 1112 1112 } 1113 1113 _setAttr(key, val) { 1114 varoldVal = this.attrs[key];1114 const oldVal = this.attrs[key]; 1115 1115 if (oldVal === val && !Util_1.Util.isObject(val)) { 1116 1116 return; … … 1128 1128 } 1129 1129 _setComponentAttr(key, component, val) { 1130 varoldVal;1130 let oldVal; 1131 1131 if (val !== undefined) { 1132 1132 oldVal = this.attrs[key]; … … 1142 1142 evt.target = this; 1143 1143 } 1144 varshouldStop = (eventType === MOUSEENTER || eventType === MOUSELEAVE) &&1144 const shouldStop = (eventType === MOUSEENTER || eventType === MOUSELEAVE) && 1145 1145 ((compareShape && 1146 1146 (this === compareShape || … … 1149 1149 if (!shouldStop) { 1150 1150 this._fire(eventType, evt); 1151 varstopBubble = (eventType === MOUSEENTER || eventType === MOUSELEAVE) &&1151 const stopBubble = (eventType === MOUSEENTER || eventType === MOUSELEAVE) && 1152 1152 compareShape && 1153 1153 compareShape.isAncestorOf && … … 1207 1207 } 1208 1208 _createDragElement(evt) { 1209 varpointerId = evt ? evt.pointerId : undefined;1210 varstage = this.getStage();1211 varap = this.getAbsolutePosition();1209 const pointerId = evt ? evt.pointerId : undefined; 1210 const stage = this.getStage(); 1211 const ap = this.getAbsolutePosition(); 1212 1212 if (!stage) { 1213 1213 return; 1214 1214 } 1215 varpos = stage._getPointerById(pointerId) ||1215 const pos = stage._getPointerById(pointerId) || 1216 1216 stage._changedPointerPositions[0] || 1217 1217 ap; … … 1244 1244 return; 1245 1245 } 1246 varnewNodePos = {1246 let newNodePos = { 1247 1247 x: pos.x - elem.offset.x, 1248 1248 y: pos.y - elem.offset.y, 1249 1249 }; 1250 vardbf = this.dragBoundFunc();1250 const dbf = this.dragBoundFunc(); 1251 1251 if (dbf !== undefined) { 1252 1252 const bounded = dbf.call(this, newNodePos, evt); … … 1285 1285 this._dragCleanup(); 1286 1286 this.on('mousedown.konva touchstart.konva', function (evt) { 1287 varshouldCheckButton = evt.evt['button'] !== undefined;1288 varcanDrag = !shouldCheckButton || Global_1.Konva.dragButtons.indexOf(evt.evt['button']) >= 0;1287 const shouldCheckButton = evt.evt['button'] !== undefined; 1288 const canDrag = !shouldCheckButton || Global_1.Konva.dragButtons.indexOf(evt.evt['button']) >= 0; 1289 1289 if (!canDrag) { 1290 1290 return; … … 1293 1293 return; 1294 1294 } 1295 varhasDraggingChild = false;1295 let hasDraggingChild = false; 1296 1296 DragAndDrop_1.DD._dragElements.forEach((elem) => { 1297 1297 if (this.isAncestorOf(elem.node)) { … … 1310 1310 else { 1311 1311 this._dragCleanup(); 1312 varstage = this.getStage();1312 const stage = this.getStage(); 1313 1313 if (!stage) { 1314 1314 return; … … 1349 1349 } 1350 1350 static _createNode(obj, container) { 1351 varclassName = Node.prototype.getClassName.call(obj), children = obj.children, no, len, n;1351 let className = Node.prototype.getClassName.call(obj), children = obj.children, no, len, n; 1352 1352 if (container) { 1353 1353 obj.attrs.container = container;
Note:
See TracChangeset
for help on using the changeset viewer.