@inditextech/weave-sdk 0.46.0 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sdk.cjs CHANGED
@@ -15688,13 +15688,13 @@ function containerOverCursor(instance) {
15688
15688
  function moveNodeToContainer(instance, node, containerToMove, invalidOriginsTypes = ["frame"]) {
15689
15689
  const stage = instance.getStage();
15690
15690
  const isLocked = instance.allNodesLocked([node]);
15691
- if (isLocked) return;
15691
+ if (isLocked) return false;
15692
15692
  let nodeActualContainer = node.getParent();
15693
15693
  if (nodeActualContainer.getAttrs().nodeId) {
15694
15694
  const realParent = stage.findOne(`#${nodeActualContainer.getAttrs().nodeId}`);
15695
15695
  if (realParent) nodeActualContainer = realParent;
15696
15696
  }
15697
- if (!nodeActualContainer) return void 0;
15697
+ if (!nodeActualContainer) return false;
15698
15698
  const actualContainerAttrs = nodeActualContainer.getAttrs();
15699
15699
  let layerToMove = void 0;
15700
15700
  if (actualContainerAttrs.id !== containerToMove.getAttrs().id && !invalidOriginsTypes.includes(node.getAttrs().nodeType)) layerToMove = containerToMove;
@@ -15713,10 +15713,10 @@ function moveNodeToContainer(instance, node, containerToMove, invalidOriginsType
15713
15713
  const actualNode = nodeHandler.serialize(node);
15714
15714
  instance.removeNode(actualNode);
15715
15715
  instance.addNode(actualNode, layerToMoveAttrs.id);
15716
- return layerToMove;
15716
+ return true;
15717
15717
  }
15718
15718
  }
15719
- return void 0;
15719
+ return false;
15720
15720
  }
15721
15721
  function getContrastTextColor(hex) {
15722
15722
  const cleaned = hex.replace(/^#/, "");
@@ -15768,12 +15768,8 @@ function getTargetedNode(instance) {
15768
15768
  let selectedGroup = void 0;
15769
15769
  const mousePos = stage.getPointerPosition();
15770
15770
  if (mousePos) {
15771
- const allInter = stage.getAllIntersections(mousePos).reverse();
15772
- if (allInter.length === 1) selectedGroup = instance.getInstanceRecursive(allInter[0]);
15773
- else {
15774
- const allInterContainersFiltered = allInter.filter((ele) => typeof ele.getAttrs().containerElement === "undefined");
15775
- if (allInterContainersFiltered.length > 0) selectedGroup = instance.getInstanceRecursive(allInterContainersFiltered[0]);
15776
- }
15771
+ const inter = stage.getIntersection(mousePos);
15772
+ if (inter) selectedGroup = instance.getInstanceRecursive(inter);
15777
15773
  }
15778
15774
  return selectedGroup;
15779
15775
  }
@@ -16269,8 +16265,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16269
16265
  const newSelectedNodes = selectedNodes.filter((actNode) => {
16270
16266
  return actNode.getAttrs().id !== node.id;
16271
16267
  });
16272
- this.tr.nodes(newSelectedNodes);
16273
- this.triggerSelectedNodesEvent();
16268
+ this.setSelectedNodes(newSelectedNodes);
16274
16269
  stage.container().tabIndex = 1;
16275
16270
  stage.container().focus();
16276
16271
  stage.container().style.cursor = "default";
@@ -16373,11 +16368,11 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16373
16368
  stage.on("pointerdown", (e) => {
16374
16369
  this.setTapStart(e);
16375
16370
  this.pointers[e.evt.pointerId] = e.evt;
16376
- if (!this.initialized) return;
16377
- if (!this.active) return;
16371
+ if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
16378
16372
  if (e.evt.pointerType === "mouse" && e.evt.button !== 0) return;
16379
16373
  if (e.evt.pointerType === "pen" && e.evt.pressure <= .05) return;
16380
- if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
16374
+ if (!this.initialized) return;
16375
+ if (!this.active) return;
16381
16376
  if (stage.mode() !== WEAVE_STAGE_DEFAULT_MODE) return;
16382
16377
  const selectedGroup = getTargetedNode(this.instance);
16383
16378
  if (selectedGroup?.getParent() instanceof konva.default.Transformer) {
@@ -16412,9 +16407,9 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16412
16407
  const handleMouseMove = (e) => {
16413
16408
  const moved = this.checkMoved(e);
16414
16409
  if (e.evt.buttons === 0) return;
16410
+ if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
16415
16411
  if (!this.initialized) return;
16416
16412
  if (!this.active) return;
16417
- if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
16418
16413
  const contextMenuPlugin = this.getContextMenuPlugin();
16419
16414
  if (moved) contextMenuPlugin?.cancelLongPressTimer();
16420
16415
  else this.hideSelectorArea();
@@ -16641,10 +16636,7 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16641
16636
  ...this.selectionOriginalConfig,
16642
16637
  enabledAnchors: intersectArrays(anchorsArrays)
16643
16638
  };
16644
- if (this.tr) {
16645
- this.tr.setAttrs(transformerAttrs);
16646
- this.tr.forceUpdate();
16647
- }
16639
+ this.tr.setAttrs(transformerAttrs);
16648
16640
  }
16649
16641
  setSelectedNodes(nodes) {
16650
16642
  this.tr.setNodes(nodes);
@@ -17129,8 +17121,9 @@ var WeaveNode = class {
17129
17121
  containerToMove = layerToMove;
17130
17122
  containerToMove.fire(__inditextech_weave_types.WEAVE_NODE_CUSTOM_EVENTS.onTargetLeave, { bubbles: true });
17131
17123
  }
17132
- if (containerToMove) moveNodeToContainer(this.instance, e.target, containerToMove);
17133
- this.instance.updateNode(this.serialize(node));
17124
+ let moved = false;
17125
+ if (containerToMove) moved = moveNodeToContainer(this.instance, e.target, containerToMove);
17126
+ if (!moved) this.instance.updateNode(this.serialize(node));
17134
17127
  }
17135
17128
  });
17136
17129
  node.on("pointerover", (e) => {
@@ -18826,7 +18819,7 @@ var WeaveRegisterManager = class {
18826
18819
 
18827
18820
  //#endregion
18828
18821
  //#region package.json
18829
- var version = "0.46.0";
18822
+ var version = "0.47.0";
18830
18823
 
18831
18824
  //#endregion
18832
18825
  //#region src/managers/setup.ts
@@ -21884,25 +21877,21 @@ var WeaveStrokeNode = class extends WeaveNode {
21884
21877
  const { config } = params ?? {};
21885
21878
  this.config = { transform: { ...config?.transform } };
21886
21879
  }
21887
- drawStroke(strokeElements, context, shape) {
21888
- context.strokeStyle = shape.getAttrs().stroke ?? "black";
21889
- context.lineCap = "round";
21890
- context.lineJoin = "round";
21880
+ drawStroke(strokeElements, prevLineWidth, context, shape) {
21881
+ const strokeWidth = shape.getAttrs().strokeWidth ?? 1;
21891
21882
  const l = strokeElements.length - 1;
21892
21883
  if (strokeElements.length >= 3) {
21893
- const xc = (strokeElements[l].x + strokeElements[l - 1].x) / 2;
21894
- const yc = (strokeElements[l].y + strokeElements[l - 1].y) / 2;
21895
- context.lineWidth = strokeElements[l - 1].lineWidth;
21884
+ const prevPoint = strokeElements[l - 1];
21885
+ const actualPoint = strokeElements[l];
21886
+ const xc = (actualPoint.x + prevPoint.x) / 2;
21887
+ const yc = (actualPoint.y + prevPoint.y) / 2;
21888
+ context.lineWidth = Math.log(actualPoint.pressure + 1) * strokeWidth + prevLineWidth * .8;
21896
21889
  context.quadraticCurveTo(strokeElements[l - 1].x, strokeElements[l - 1].y, xc, yc);
21897
- context.stroke();
21898
- context.beginPath();
21899
- context.moveTo(xc, yc);
21890
+ return context.lineWidth;
21900
21891
  } else {
21901
21892
  const point = strokeElements[l];
21902
- context.lineWidth = point.lineWidth;
21903
- context.beginPath();
21904
- context.moveTo(point.x, point.y);
21905
- context.stroke();
21893
+ context.lineWidth = Math.log(point.pressure + 1) * strokeWidth;
21894
+ return context.lineWidth;
21906
21895
  }
21907
21896
  }
21908
21897
  onRender(props) {
@@ -21911,13 +21900,22 @@ var WeaveStrokeNode = class extends WeaveNode {
21911
21900
  name: "node",
21912
21901
  sceneFunc: (context, shape) => {
21913
21902
  context.beginPath();
21903
+ context.strokeStyle = shape.getAttrs().stroke ?? "black";
21904
+ context.setLineDash(shape.getAttrs().dash || []);
21905
+ context.lineCap = shape.getAttrs().lineCap ?? "round";
21906
+ context.lineJoin = shape.getAttrs().lineJoin ?? "round";
21914
21907
  const strokeElements = shape.getAttrs().strokeElements;
21908
+ if (strokeElements.length === 0) return;
21909
+ context.moveTo(strokeElements[0].x, strokeElements[0].y);
21910
+ let prevLineWidth = 0;
21915
21911
  const strokePath = [];
21916
21912
  strokeElements.forEach((point) => {
21917
21913
  strokePath.push(point);
21918
- this.drawStroke(strokePath, context, shape);
21914
+ prevLineWidth = this.drawStroke(strokePath, prevLineWidth, context, shape);
21919
21915
  });
21916
+ context.strokeShape(shape);
21920
21917
  },
21918
+ dashEnabled: false,
21921
21919
  hitFunc: (context, shape) => {
21922
21920
  context.beginPath();
21923
21921
  context.rect(0, 0, shape.width(), shape.height());
@@ -22021,1672 +22019,6 @@ const WEAVE_STAGE_ZOOM_DEFAULT_CONFIG = {
22021
22019
  fitToSelection: { padding: 40 }
22022
22020
  };
22023
22021
 
22024
- //#endregion
22025
- //#region ../../node_modules/hammerjs/hammer.js
22026
- var require_hammer = __commonJS({ "../../node_modules/hammerjs/hammer.js"(exports, module) {
22027
- /*! Hammer.JS - v2.0.7 - 2016-04-22
22028
- * http://hammerjs.github.io/
22029
- *
22030
- * Copyright (c) 2016 Jorik Tangelder;
22031
- * Licensed under the MIT license */
22032
- (function(window$1, document$1, exportName, undefined$1) {
22033
- "use strict";
22034
- var VENDOR_PREFIXES = [
22035
- "",
22036
- "webkit",
22037
- "Moz",
22038
- "MS",
22039
- "ms",
22040
- "o"
22041
- ];
22042
- var TEST_ELEMENT = document$1.createElement("div");
22043
- var TYPE_FUNCTION = "function";
22044
- var round = Math.round;
22045
- var abs = Math.abs;
22046
- var now = Date.now;
22047
- /**
22048
- * set a timeout with a given scope
22049
- * @param {Function} fn
22050
- * @param {Number} timeout
22051
- * @param {Object} context
22052
- * @returns {number}
22053
- */
22054
- function setTimeoutContext(fn, timeout, context) {
22055
- return setTimeout(bindFn(fn, context), timeout);
22056
- }
22057
- /**
22058
- * if the argument is an array, we want to execute the fn on each entry
22059
- * if it aint an array we don't want to do a thing.
22060
- * this is used by all the methods that accept a single and array argument.
22061
- * @param {*|Array} arg
22062
- * @param {String} fn
22063
- * @param {Object} [context]
22064
- * @returns {Boolean}
22065
- */
22066
- function invokeArrayArg(arg, fn, context) {
22067
- if (Array.isArray(arg)) {
22068
- each(arg, context[fn], context);
22069
- return true;
22070
- }
22071
- return false;
22072
- }
22073
- /**
22074
- * walk objects and arrays
22075
- * @param {Object} obj
22076
- * @param {Function} iterator
22077
- * @param {Object} context
22078
- */
22079
- function each(obj, iterator$1, context) {
22080
- var i;
22081
- if (!obj) return;
22082
- if (obj.forEach) obj.forEach(iterator$1, context);
22083
- else if (obj.length !== undefined$1) {
22084
- i = 0;
22085
- while (i < obj.length) {
22086
- iterator$1.call(context, obj[i], i, obj);
22087
- i++;
22088
- }
22089
- } else for (i in obj) obj.hasOwnProperty(i) && iterator$1.call(context, obj[i], i, obj);
22090
- }
22091
- /**
22092
- * wrap a method with a deprecation warning and stack trace
22093
- * @param {Function} method
22094
- * @param {String} name
22095
- * @param {String} message
22096
- * @returns {Function} A new function wrapping the supplied method.
22097
- */
22098
- function deprecate(method, name, message) {
22099
- var deprecationMessage = "DEPRECATED METHOD: " + name + "\n" + message + " AT \n";
22100
- return function() {
22101
- var e = new Error("get-stack-trace");
22102
- var stack = e && e.stack ? e.stack.replace(/^[^\(]+?[\n$]/gm, "").replace(/^\s+at\s+/gm, "").replace(/^Object.<anonymous>\s*\(/gm, "{anonymous}()@") : "Unknown Stack Trace";
22103
- var log = window$1.console && (window$1.console.warn || window$1.console.log);
22104
- if (log) log.call(window$1.console, deprecationMessage, stack);
22105
- return method.apply(this, arguments);
22106
- };
22107
- }
22108
- /**
22109
- * extend object.
22110
- * means that properties in dest will be overwritten by the ones in src.
22111
- * @param {Object} target
22112
- * @param {...Object} objects_to_assign
22113
- * @returns {Object} target
22114
- */
22115
- var assign;
22116
- if (typeof Object.assign !== "function") assign = function assign$1(target) {
22117
- if (target === undefined$1 || target === null) throw new TypeError("Cannot convert undefined or null to object");
22118
- var output = Object(target);
22119
- for (var index = 1; index < arguments.length; index++) {
22120
- var source = arguments[index];
22121
- if (source !== undefined$1 && source !== null) {
22122
- for (var nextKey in source) if (source.hasOwnProperty(nextKey)) output[nextKey] = source[nextKey];
22123
- }
22124
- }
22125
- return output;
22126
- };
22127
- else assign = Object.assign;
22128
- /**
22129
- * extend object.
22130
- * means that properties in dest will be overwritten by the ones in src.
22131
- * @param {Object} dest
22132
- * @param {Object} src
22133
- * @param {Boolean} [merge=false]
22134
- * @returns {Object} dest
22135
- */
22136
- var extend = deprecate(function extend$1(dest, src, merge$1) {
22137
- var keys = Object.keys(src);
22138
- var i = 0;
22139
- while (i < keys.length) {
22140
- if (!merge$1 || merge$1 && dest[keys[i]] === undefined$1) dest[keys[i]] = src[keys[i]];
22141
- i++;
22142
- }
22143
- return dest;
22144
- }, "extend", "Use `assign`.");
22145
- /**
22146
- * merge the values from src in the dest.
22147
- * means that properties that exist in dest will not be overwritten by src
22148
- * @param {Object} dest
22149
- * @param {Object} src
22150
- * @returns {Object} dest
22151
- */
22152
- var merge = deprecate(function merge$1(dest, src) {
22153
- return extend(dest, src, true);
22154
- }, "merge", "Use `assign`.");
22155
- /**
22156
- * simple class inheritance
22157
- * @param {Function} child
22158
- * @param {Function} base
22159
- * @param {Object} [properties]
22160
- */
22161
- function inherit(child, base, properties) {
22162
- var baseP = base.prototype, childP;
22163
- childP = child.prototype = Object.create(baseP);
22164
- childP.constructor = child;
22165
- childP._super = baseP;
22166
- if (properties) assign(childP, properties);
22167
- }
22168
- /**
22169
- * simple function bind
22170
- * @param {Function} fn
22171
- * @param {Object} context
22172
- * @returns {Function}
22173
- */
22174
- function bindFn(fn, context) {
22175
- return function boundFn() {
22176
- return fn.apply(context, arguments);
22177
- };
22178
- }
22179
- /**
22180
- * let a boolean value also be a function that must return a boolean
22181
- * this first item in args will be used as the context
22182
- * @param {Boolean|Function} val
22183
- * @param {Array} [args]
22184
- * @returns {Boolean}
22185
- */
22186
- function boolOrFn(val, args) {
22187
- if (typeof val == TYPE_FUNCTION) return val.apply(args ? args[0] || undefined$1 : undefined$1, args);
22188
- return val;
22189
- }
22190
- /**
22191
- * use the val2 when val1 is undefined
22192
- * @param {*} val1
22193
- * @param {*} val2
22194
- * @returns {*}
22195
- */
22196
- function ifUndefined(val1, val2) {
22197
- return val1 === undefined$1 ? val2 : val1;
22198
- }
22199
- /**
22200
- * addEventListener with multiple events at once
22201
- * @param {EventTarget} target
22202
- * @param {String} types
22203
- * @param {Function} handler
22204
- */
22205
- function addEventListeners(target, types, handler) {
22206
- each(splitStr(types), function(type) {
22207
- target.addEventListener(type, handler, false);
22208
- });
22209
- }
22210
- /**
22211
- * removeEventListener with multiple events at once
22212
- * @param {EventTarget} target
22213
- * @param {String} types
22214
- * @param {Function} handler
22215
- */
22216
- function removeEventListeners(target, types, handler) {
22217
- each(splitStr(types), function(type) {
22218
- target.removeEventListener(type, handler, false);
22219
- });
22220
- }
22221
- /**
22222
- * find if a node is in the given parent
22223
- * @method hasParent
22224
- * @param {HTMLElement} node
22225
- * @param {HTMLElement} parent
22226
- * @return {Boolean} found
22227
- */
22228
- function hasParent(node, parent) {
22229
- while (node) {
22230
- if (node == parent) return true;
22231
- node = node.parentNode;
22232
- }
22233
- return false;
22234
- }
22235
- /**
22236
- * small indexOf wrapper
22237
- * @param {String} str
22238
- * @param {String} find
22239
- * @returns {Boolean} found
22240
- */
22241
- function inStr(str, find) {
22242
- return str.indexOf(find) > -1;
22243
- }
22244
- /**
22245
- * split string on whitespace
22246
- * @param {String} str
22247
- * @returns {Array} words
22248
- */
22249
- function splitStr(str) {
22250
- return str.trim().split(/\s+/g);
22251
- }
22252
- /**
22253
- * find if a array contains the object using indexOf or a simple polyFill
22254
- * @param {Array} src
22255
- * @param {String} find
22256
- * @param {String} [findByKey]
22257
- * @return {Boolean|Number} false when not found, or the index
22258
- */
22259
- function inArray(src, find, findByKey) {
22260
- if (src.indexOf && !findByKey) return src.indexOf(find);
22261
- else {
22262
- var i = 0;
22263
- while (i < src.length) {
22264
- if (findByKey && src[i][findByKey] == find || !findByKey && src[i] === find) return i;
22265
- i++;
22266
- }
22267
- return -1;
22268
- }
22269
- }
22270
- /**
22271
- * convert array-like objects to real arrays
22272
- * @param {Object} obj
22273
- * @returns {Array}
22274
- */
22275
- function toArray(obj) {
22276
- return Array.prototype.slice.call(obj, 0);
22277
- }
22278
- /**
22279
- * unique array with objects based on a key (like 'id') or just by the array's value
22280
- * @param {Array} src [{id:1},{id:2},{id:1}]
22281
- * @param {String} [key]
22282
- * @param {Boolean} [sort=False]
22283
- * @returns {Array} [{id:1},{id:2}]
22284
- */
22285
- function uniqueArray(src, key, sort) {
22286
- var results = [];
22287
- var values = [];
22288
- var i = 0;
22289
- while (i < src.length) {
22290
- var val = key ? src[i][key] : src[i];
22291
- if (inArray(values, val) < 0) results.push(src[i]);
22292
- values[i] = val;
22293
- i++;
22294
- }
22295
- if (sort) if (!key) results = results.sort();
22296
- else results = results.sort(function sortUniqueArray(a, b) {
22297
- return a[key] > b[key];
22298
- });
22299
- return results;
22300
- }
22301
- /**
22302
- * get the prefixed property
22303
- * @param {Object} obj
22304
- * @param {String} property
22305
- * @returns {String|Undefined} prefixed
22306
- */
22307
- function prefixed(obj, property) {
22308
- var prefix, prop;
22309
- var camelProp = property[0].toUpperCase() + property.slice(1);
22310
- var i = 0;
22311
- while (i < VENDOR_PREFIXES.length) {
22312
- prefix = VENDOR_PREFIXES[i];
22313
- prop = prefix ? prefix + camelProp : property;
22314
- if (prop in obj) return prop;
22315
- i++;
22316
- }
22317
- return undefined$1;
22318
- }
22319
- /**
22320
- * get a unique id
22321
- * @returns {number} uniqueId
22322
- */
22323
- var _uniqueId = 1;
22324
- function uniqueId() {
22325
- return _uniqueId++;
22326
- }
22327
- /**
22328
- * get the window object of an element
22329
- * @param {HTMLElement} element
22330
- * @returns {DocumentView|Window}
22331
- */
22332
- function getWindowForElement(element) {
22333
- var doc = element.ownerDocument || element;
22334
- return doc.defaultView || doc.parentWindow || window$1;
22335
- }
22336
- var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
22337
- var SUPPORT_TOUCH = "ontouchstart" in window$1;
22338
- var SUPPORT_POINTER_EVENTS = prefixed(window$1, "PointerEvent") !== undefined$1;
22339
- var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);
22340
- var INPUT_TYPE_TOUCH = "touch";
22341
- var INPUT_TYPE_PEN = "pen";
22342
- var INPUT_TYPE_MOUSE = "mouse";
22343
- var INPUT_TYPE_KINECT = "kinect";
22344
- var COMPUTE_INTERVAL = 25;
22345
- var INPUT_START = 1;
22346
- var INPUT_MOVE = 2;
22347
- var INPUT_END = 4;
22348
- var INPUT_CANCEL = 8;
22349
- var DIRECTION_NONE = 1;
22350
- var DIRECTION_LEFT = 2;
22351
- var DIRECTION_RIGHT = 4;
22352
- var DIRECTION_UP = 8;
22353
- var DIRECTION_DOWN = 16;
22354
- var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
22355
- var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
22356
- var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
22357
- var PROPS_XY = ["x", "y"];
22358
- var PROPS_CLIENT_XY = ["clientX", "clientY"];
22359
- /**
22360
- * create new input type manager
22361
- * @param {Manager} manager
22362
- * @param {Function} callback
22363
- * @returns {Input}
22364
- * @constructor
22365
- */
22366
- function Input(manager, callback) {
22367
- var self$1 = this;
22368
- this.manager = manager;
22369
- this.callback = callback;
22370
- this.element = manager.element;
22371
- this.target = manager.options.inputTarget;
22372
- this.domHandler = function(ev) {
22373
- if (boolOrFn(manager.options.enable, [manager])) self$1.handler(ev);
22374
- };
22375
- this.init();
22376
- }
22377
- Input.prototype = {
22378
- handler: function() {},
22379
- init: function() {
22380
- this.evEl && addEventListeners(this.element, this.evEl, this.domHandler);
22381
- this.evTarget && addEventListeners(this.target, this.evTarget, this.domHandler);
22382
- this.evWin && addEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
22383
- },
22384
- destroy: function() {
22385
- this.evEl && removeEventListeners(this.element, this.evEl, this.domHandler);
22386
- this.evTarget && removeEventListeners(this.target, this.evTarget, this.domHandler);
22387
- this.evWin && removeEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
22388
- }
22389
- };
22390
- /**
22391
- * create new input type manager
22392
- * called by the Manager constructor
22393
- * @param {Hammer} manager
22394
- * @returns {Input}
22395
- */
22396
- function createInputInstance(manager) {
22397
- var Type;
22398
- var inputClass = manager.options.inputClass;
22399
- if (inputClass) Type = inputClass;
22400
- else if (SUPPORT_POINTER_EVENTS) Type = PointerEventInput;
22401
- else if (SUPPORT_ONLY_TOUCH) Type = TouchInput;
22402
- else if (!SUPPORT_TOUCH) Type = MouseInput;
22403
- else Type = TouchMouseInput;
22404
- return new Type(manager, inputHandler);
22405
- }
22406
- /**
22407
- * handle input events
22408
- * @param {Manager} manager
22409
- * @param {String} eventType
22410
- * @param {Object} input
22411
- */
22412
- function inputHandler(manager, eventType, input) {
22413
- var pointersLen = input.pointers.length;
22414
- var changedPointersLen = input.changedPointers.length;
22415
- var isFirst = eventType & INPUT_START && pointersLen - changedPointersLen === 0;
22416
- var isFinal = eventType & (INPUT_END | INPUT_CANCEL) && pointersLen - changedPointersLen === 0;
22417
- input.isFirst = !!isFirst;
22418
- input.isFinal = !!isFinal;
22419
- if (isFirst) manager.session = {};
22420
- input.eventType = eventType;
22421
- computeInputData(manager, input);
22422
- manager.emit("hammer.input", input);
22423
- manager.recognize(input);
22424
- manager.session.prevInput = input;
22425
- }
22426
- /**
22427
- * extend the data with some usable properties like scale, rotate, velocity etc
22428
- * @param {Object} manager
22429
- * @param {Object} input
22430
- */
22431
- function computeInputData(manager, input) {
22432
- var session = manager.session;
22433
- var pointers = input.pointers;
22434
- var pointersLength = pointers.length;
22435
- if (!session.firstInput) session.firstInput = simpleCloneInputData(input);
22436
- if (pointersLength > 1 && !session.firstMultiple) session.firstMultiple = simpleCloneInputData(input);
22437
- else if (pointersLength === 1) session.firstMultiple = false;
22438
- var firstInput = session.firstInput;
22439
- var firstMultiple = session.firstMultiple;
22440
- var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
22441
- var center = input.center = getCenter(pointers);
22442
- input.timeStamp = now();
22443
- input.deltaTime = input.timeStamp - firstInput.timeStamp;
22444
- input.angle = getAngle(offsetCenter, center);
22445
- input.distance = getDistance(offsetCenter, center);
22446
- computeDeltaXY(session, input);
22447
- input.offsetDirection = getDirection(input.deltaX, input.deltaY);
22448
- var overallVelocity = getVelocity(input.deltaTime, input.deltaX, input.deltaY);
22449
- input.overallVelocityX = overallVelocity.x;
22450
- input.overallVelocityY = overallVelocity.y;
22451
- input.overallVelocity = abs(overallVelocity.x) > abs(overallVelocity.y) ? overallVelocity.x : overallVelocity.y;
22452
- input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
22453
- input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
22454
- input.maxPointers = !session.prevInput ? input.pointers.length : input.pointers.length > session.prevInput.maxPointers ? input.pointers.length : session.prevInput.maxPointers;
22455
- computeIntervalInputData(session, input);
22456
- var target = manager.element;
22457
- if (hasParent(input.srcEvent.target, target)) target = input.srcEvent.target;
22458
- input.target = target;
22459
- }
22460
- function computeDeltaXY(session, input) {
22461
- var center = input.center;
22462
- var offset = session.offsetDelta || {};
22463
- var prevDelta = session.prevDelta || {};
22464
- var prevInput = session.prevInput || {};
22465
- if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) {
22466
- prevDelta = session.prevDelta = {
22467
- x: prevInput.deltaX || 0,
22468
- y: prevInput.deltaY || 0
22469
- };
22470
- offset = session.offsetDelta = {
22471
- x: center.x,
22472
- y: center.y
22473
- };
22474
- }
22475
- input.deltaX = prevDelta.x + (center.x - offset.x);
22476
- input.deltaY = prevDelta.y + (center.y - offset.y);
22477
- }
22478
- /**
22479
- * velocity is calculated every x ms
22480
- * @param {Object} session
22481
- * @param {Object} input
22482
- */
22483
- function computeIntervalInputData(session, input) {
22484
- var last = session.lastInterval || input, deltaTime = input.timeStamp - last.timeStamp, velocity, velocityX, velocityY, direction;
22485
- if (input.eventType != INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined$1)) {
22486
- var deltaX = input.deltaX - last.deltaX;
22487
- var deltaY = input.deltaY - last.deltaY;
22488
- var v = getVelocity(deltaTime, deltaX, deltaY);
22489
- velocityX = v.x;
22490
- velocityY = v.y;
22491
- velocity = abs(v.x) > abs(v.y) ? v.x : v.y;
22492
- direction = getDirection(deltaX, deltaY);
22493
- session.lastInterval = input;
22494
- } else {
22495
- velocity = last.velocity;
22496
- velocityX = last.velocityX;
22497
- velocityY = last.velocityY;
22498
- direction = last.direction;
22499
- }
22500
- input.velocity = velocity;
22501
- input.velocityX = velocityX;
22502
- input.velocityY = velocityY;
22503
- input.direction = direction;
22504
- }
22505
- /**
22506
- * create a simple clone from the input used for storage of firstInput and firstMultiple
22507
- * @param {Object} input
22508
- * @returns {Object} clonedInputData
22509
- */
22510
- function simpleCloneInputData(input) {
22511
- var pointers = [];
22512
- var i = 0;
22513
- while (i < input.pointers.length) {
22514
- pointers[i] = {
22515
- clientX: round(input.pointers[i].clientX),
22516
- clientY: round(input.pointers[i].clientY)
22517
- };
22518
- i++;
22519
- }
22520
- return {
22521
- timeStamp: now(),
22522
- pointers,
22523
- center: getCenter(pointers),
22524
- deltaX: input.deltaX,
22525
- deltaY: input.deltaY
22526
- };
22527
- }
22528
- /**
22529
- * get the center of all the pointers
22530
- * @param {Array} pointers
22531
- * @return {Object} center contains `x` and `y` properties
22532
- */
22533
- function getCenter(pointers) {
22534
- var pointersLength = pointers.length;
22535
- if (pointersLength === 1) return {
22536
- x: round(pointers[0].clientX),
22537
- y: round(pointers[0].clientY)
22538
- };
22539
- var x = 0, y = 0, i = 0;
22540
- while (i < pointersLength) {
22541
- x += pointers[i].clientX;
22542
- y += pointers[i].clientY;
22543
- i++;
22544
- }
22545
- return {
22546
- x: round(x / pointersLength),
22547
- y: round(y / pointersLength)
22548
- };
22549
- }
22550
- /**
22551
- * calculate the velocity between two points. unit is in px per ms.
22552
- * @param {Number} deltaTime
22553
- * @param {Number} x
22554
- * @param {Number} y
22555
- * @return {Object} velocity `x` and `y`
22556
- */
22557
- function getVelocity(deltaTime, x, y) {
22558
- return {
22559
- x: x / deltaTime || 0,
22560
- y: y / deltaTime || 0
22561
- };
22562
- }
22563
- /**
22564
- * get the direction between two points
22565
- * @param {Number} x
22566
- * @param {Number} y
22567
- * @return {Number} direction
22568
- */
22569
- function getDirection(x, y) {
22570
- if (x === y) return DIRECTION_NONE;
22571
- if (abs(x) >= abs(y)) return x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
22572
- return y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
22573
- }
22574
- /**
22575
- * calculate the absolute distance between two points
22576
- * @param {Object} p1 {x, y}
22577
- * @param {Object} p2 {x, y}
22578
- * @param {Array} [props] containing x and y keys
22579
- * @return {Number} distance
22580
- */
22581
- function getDistance(p1, p2, props) {
22582
- if (!props) props = PROPS_XY;
22583
- var x = p2[props[0]] - p1[props[0]], y = p2[props[1]] - p1[props[1]];
22584
- return Math.sqrt(x * x + y * y);
22585
- }
22586
- /**
22587
- * calculate the angle between two coordinates
22588
- * @param {Object} p1
22589
- * @param {Object} p2
22590
- * @param {Array} [props] containing x and y keys
22591
- * @return {Number} angle
22592
- */
22593
- function getAngle(p1, p2, props) {
22594
- if (!props) props = PROPS_XY;
22595
- var x = p2[props[0]] - p1[props[0]], y = p2[props[1]] - p1[props[1]];
22596
- return Math.atan2(y, x) * 180 / Math.PI;
22597
- }
22598
- /**
22599
- * calculate the rotation degrees between two pointersets
22600
- * @param {Array} start array of pointers
22601
- * @param {Array} end array of pointers
22602
- * @return {Number} rotation
22603
- */
22604
- function getRotation(start, end) {
22605
- return getAngle(end[1], end[0], PROPS_CLIENT_XY) + getAngle(start[1], start[0], PROPS_CLIENT_XY);
22606
- }
22607
- /**
22608
- * calculate the scale factor between two pointersets
22609
- * no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out
22610
- * @param {Array} start array of pointers
22611
- * @param {Array} end array of pointers
22612
- * @return {Number} scale
22613
- */
22614
- function getScale(start, end) {
22615
- return getDistance(end[0], end[1], PROPS_CLIENT_XY) / getDistance(start[0], start[1], PROPS_CLIENT_XY);
22616
- }
22617
- var MOUSE_INPUT_MAP = {
22618
- mousedown: INPUT_START,
22619
- mousemove: INPUT_MOVE,
22620
- mouseup: INPUT_END
22621
- };
22622
- var MOUSE_ELEMENT_EVENTS = "mousedown";
22623
- var MOUSE_WINDOW_EVENTS = "mousemove mouseup";
22624
- /**
22625
- * Mouse events input
22626
- * @constructor
22627
- * @extends Input
22628
- */
22629
- function MouseInput() {
22630
- this.evEl = MOUSE_ELEMENT_EVENTS;
22631
- this.evWin = MOUSE_WINDOW_EVENTS;
22632
- this.pressed = false;
22633
- Input.apply(this, arguments);
22634
- }
22635
- inherit(MouseInput, Input, { handler: function MEhandler(ev) {
22636
- var eventType = MOUSE_INPUT_MAP[ev.type];
22637
- if (eventType & INPUT_START && ev.button === 0) this.pressed = true;
22638
- if (eventType & INPUT_MOVE && ev.which !== 1) eventType = INPUT_END;
22639
- if (!this.pressed) return;
22640
- if (eventType & INPUT_END) this.pressed = false;
22641
- this.callback(this.manager, eventType, {
22642
- pointers: [ev],
22643
- changedPointers: [ev],
22644
- pointerType: INPUT_TYPE_MOUSE,
22645
- srcEvent: ev
22646
- });
22647
- } });
22648
- var POINTER_INPUT_MAP = {
22649
- pointerdown: INPUT_START,
22650
- pointermove: INPUT_MOVE,
22651
- pointerup: INPUT_END,
22652
- pointercancel: INPUT_CANCEL,
22653
- pointerout: INPUT_CANCEL
22654
- };
22655
- var IE10_POINTER_TYPE_ENUM = {
22656
- 2: INPUT_TYPE_TOUCH,
22657
- 3: INPUT_TYPE_PEN,
22658
- 4: INPUT_TYPE_MOUSE,
22659
- 5: INPUT_TYPE_KINECT
22660
- };
22661
- var POINTER_ELEMENT_EVENTS = "pointerdown";
22662
- var POINTER_WINDOW_EVENTS = "pointermove pointerup pointercancel";
22663
- if (window$1.MSPointerEvent && !window$1.PointerEvent) {
22664
- POINTER_ELEMENT_EVENTS = "MSPointerDown";
22665
- POINTER_WINDOW_EVENTS = "MSPointerMove MSPointerUp MSPointerCancel";
22666
- }
22667
- /**
22668
- * Pointer events input
22669
- * @constructor
22670
- * @extends Input
22671
- */
22672
- function PointerEventInput() {
22673
- this.evEl = POINTER_ELEMENT_EVENTS;
22674
- this.evWin = POINTER_WINDOW_EVENTS;
22675
- Input.apply(this, arguments);
22676
- this.store = this.manager.session.pointerEvents = [];
22677
- }
22678
- inherit(PointerEventInput, Input, { handler: function PEhandler(ev) {
22679
- var store = this.store;
22680
- var removePointer = false;
22681
- var eventTypeNormalized = ev.type.toLowerCase().replace("ms", "");
22682
- var eventType = POINTER_INPUT_MAP[eventTypeNormalized];
22683
- var pointerType = IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType;
22684
- var isTouch = pointerType == INPUT_TYPE_TOUCH;
22685
- var storeIndex = inArray(store, ev.pointerId, "pointerId");
22686
- if (eventType & INPUT_START && (ev.button === 0 || isTouch)) {
22687
- if (storeIndex < 0) {
22688
- store.push(ev);
22689
- storeIndex = store.length - 1;
22690
- }
22691
- } else if (eventType & (INPUT_END | INPUT_CANCEL)) removePointer = true;
22692
- if (storeIndex < 0) return;
22693
- store[storeIndex] = ev;
22694
- this.callback(this.manager, eventType, {
22695
- pointers: store,
22696
- changedPointers: [ev],
22697
- pointerType,
22698
- srcEvent: ev
22699
- });
22700
- if (removePointer) store.splice(storeIndex, 1);
22701
- } });
22702
- var SINGLE_TOUCH_INPUT_MAP = {
22703
- touchstart: INPUT_START,
22704
- touchmove: INPUT_MOVE,
22705
- touchend: INPUT_END,
22706
- touchcancel: INPUT_CANCEL
22707
- };
22708
- var SINGLE_TOUCH_TARGET_EVENTS = "touchstart";
22709
- var SINGLE_TOUCH_WINDOW_EVENTS = "touchstart touchmove touchend touchcancel";
22710
- /**
22711
- * Touch events input
22712
- * @constructor
22713
- * @extends Input
22714
- */
22715
- function SingleTouchInput() {
22716
- this.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
22717
- this.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
22718
- this.started = false;
22719
- Input.apply(this, arguments);
22720
- }
22721
- inherit(SingleTouchInput, Input, { handler: function TEhandler(ev) {
22722
- var type = SINGLE_TOUCH_INPUT_MAP[ev.type];
22723
- if (type === INPUT_START) this.started = true;
22724
- if (!this.started) return;
22725
- var touches = normalizeSingleTouches.call(this, ev, type);
22726
- if (type & (INPUT_END | INPUT_CANCEL) && touches[0].length - touches[1].length === 0) this.started = false;
22727
- this.callback(this.manager, type, {
22728
- pointers: touches[0],
22729
- changedPointers: touches[1],
22730
- pointerType: INPUT_TYPE_TOUCH,
22731
- srcEvent: ev
22732
- });
22733
- } });
22734
- /**
22735
- * @this {TouchInput}
22736
- * @param {Object} ev
22737
- * @param {Number} type flag
22738
- * @returns {undefined|Array} [all, changed]
22739
- */
22740
- function normalizeSingleTouches(ev, type) {
22741
- var all = toArray(ev.touches);
22742
- var changed = toArray(ev.changedTouches);
22743
- if (type & (INPUT_END | INPUT_CANCEL)) all = uniqueArray(all.concat(changed), "identifier", true);
22744
- return [all, changed];
22745
- }
22746
- var TOUCH_INPUT_MAP = {
22747
- touchstart: INPUT_START,
22748
- touchmove: INPUT_MOVE,
22749
- touchend: INPUT_END,
22750
- touchcancel: INPUT_CANCEL
22751
- };
22752
- var TOUCH_TARGET_EVENTS = "touchstart touchmove touchend touchcancel";
22753
- /**
22754
- * Multi-user touch events input
22755
- * @constructor
22756
- * @extends Input
22757
- */
22758
- function TouchInput() {
22759
- this.evTarget = TOUCH_TARGET_EVENTS;
22760
- this.targetIds = {};
22761
- Input.apply(this, arguments);
22762
- }
22763
- inherit(TouchInput, Input, { handler: function MTEhandler(ev) {
22764
- var type = TOUCH_INPUT_MAP[ev.type];
22765
- var touches = getTouches.call(this, ev, type);
22766
- if (!touches) return;
22767
- this.callback(this.manager, type, {
22768
- pointers: touches[0],
22769
- changedPointers: touches[1],
22770
- pointerType: INPUT_TYPE_TOUCH,
22771
- srcEvent: ev
22772
- });
22773
- } });
22774
- /**
22775
- * @this {TouchInput}
22776
- * @param {Object} ev
22777
- * @param {Number} type flag
22778
- * @returns {undefined|Array} [all, changed]
22779
- */
22780
- function getTouches(ev, type) {
22781
- var allTouches = toArray(ev.touches);
22782
- var targetIds = this.targetIds;
22783
- if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) {
22784
- targetIds[allTouches[0].identifier] = true;
22785
- return [allTouches, allTouches];
22786
- }
22787
- var i, targetTouches, changedTouches = toArray(ev.changedTouches), changedTargetTouches = [], target = this.target;
22788
- targetTouches = allTouches.filter(function(touch) {
22789
- return hasParent(touch.target, target);
22790
- });
22791
- if (type === INPUT_START) {
22792
- i = 0;
22793
- while (i < targetTouches.length) {
22794
- targetIds[targetTouches[i].identifier] = true;
22795
- i++;
22796
- }
22797
- }
22798
- i = 0;
22799
- while (i < changedTouches.length) {
22800
- if (targetIds[changedTouches[i].identifier]) changedTargetTouches.push(changedTouches[i]);
22801
- if (type & (INPUT_END | INPUT_CANCEL)) delete targetIds[changedTouches[i].identifier];
22802
- i++;
22803
- }
22804
- if (!changedTargetTouches.length) return;
22805
- return [uniqueArray(targetTouches.concat(changedTargetTouches), "identifier", true), changedTargetTouches];
22806
- }
22807
- /**
22808
- * Combined touch and mouse input
22809
- *
22810
- * Touch has a higher priority then mouse, and while touching no mouse events are allowed.
22811
- * This because touch devices also emit mouse events while doing a touch.
22812
- *
22813
- * @constructor
22814
- * @extends Input
22815
- */
22816
- var DEDUP_TIMEOUT = 2500;
22817
- var DEDUP_DISTANCE = 25;
22818
- function TouchMouseInput() {
22819
- Input.apply(this, arguments);
22820
- var handler = bindFn(this.handler, this);
22821
- this.touch = new TouchInput(this.manager, handler);
22822
- this.mouse = new MouseInput(this.manager, handler);
22823
- this.primaryTouch = null;
22824
- this.lastTouches = [];
22825
- }
22826
- inherit(TouchMouseInput, Input, {
22827
- handler: function TMEhandler(manager, inputEvent, inputData) {
22828
- var isTouch = inputData.pointerType == INPUT_TYPE_TOUCH, isMouse = inputData.pointerType == INPUT_TYPE_MOUSE;
22829
- if (isMouse && inputData.sourceCapabilities && inputData.sourceCapabilities.firesTouchEvents) return;
22830
- if (isTouch) recordTouches.call(this, inputEvent, inputData);
22831
- else if (isMouse && isSyntheticEvent.call(this, inputData)) return;
22832
- this.callback(manager, inputEvent, inputData);
22833
- },
22834
- destroy: function destroy() {
22835
- this.touch.destroy();
22836
- this.mouse.destroy();
22837
- }
22838
- });
22839
- function recordTouches(eventType, eventData) {
22840
- if (eventType & INPUT_START) {
22841
- this.primaryTouch = eventData.changedPointers[0].identifier;
22842
- setLastTouch.call(this, eventData);
22843
- } else if (eventType & (INPUT_END | INPUT_CANCEL)) setLastTouch.call(this, eventData);
22844
- }
22845
- function setLastTouch(eventData) {
22846
- var touch = eventData.changedPointers[0];
22847
- if (touch.identifier === this.primaryTouch) {
22848
- var lastTouch = {
22849
- x: touch.clientX,
22850
- y: touch.clientY
22851
- };
22852
- this.lastTouches.push(lastTouch);
22853
- var lts = this.lastTouches;
22854
- var removeLastTouch = function() {
22855
- var i = lts.indexOf(lastTouch);
22856
- if (i > -1) lts.splice(i, 1);
22857
- };
22858
- setTimeout(removeLastTouch, DEDUP_TIMEOUT);
22859
- }
22860
- }
22861
- function isSyntheticEvent(eventData) {
22862
- var x = eventData.srcEvent.clientX, y = eventData.srcEvent.clientY;
22863
- for (var i = 0; i < this.lastTouches.length; i++) {
22864
- var t = this.lastTouches[i];
22865
- var dx = Math.abs(x - t.x), dy = Math.abs(y - t.y);
22866
- if (dx <= DEDUP_DISTANCE && dy <= DEDUP_DISTANCE) return true;
22867
- }
22868
- return false;
22869
- }
22870
- var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, "touchAction");
22871
- var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined$1;
22872
- var TOUCH_ACTION_COMPUTE = "compute";
22873
- var TOUCH_ACTION_AUTO = "auto";
22874
- var TOUCH_ACTION_MANIPULATION = "manipulation";
22875
- var TOUCH_ACTION_NONE = "none";
22876
- var TOUCH_ACTION_PAN_X = "pan-x";
22877
- var TOUCH_ACTION_PAN_Y = "pan-y";
22878
- var TOUCH_ACTION_MAP = getTouchActionProps();
22879
- /**
22880
- * Touch Action
22881
- * sets the touchAction property or uses the js alternative
22882
- * @param {Manager} manager
22883
- * @param {String} value
22884
- * @constructor
22885
- */
22886
- function TouchAction(manager, value) {
22887
- this.manager = manager;
22888
- this.set(value);
22889
- }
22890
- TouchAction.prototype = {
22891
- set: function(value) {
22892
- if (value == TOUCH_ACTION_COMPUTE) value = this.compute();
22893
- if (NATIVE_TOUCH_ACTION && this.manager.element.style && TOUCH_ACTION_MAP[value]) this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
22894
- this.actions = value.toLowerCase().trim();
22895
- },
22896
- update: function() {
22897
- this.set(this.manager.options.touchAction);
22898
- },
22899
- compute: function() {
22900
- var actions = [];
22901
- each(this.manager.recognizers, function(recognizer) {
22902
- if (boolOrFn(recognizer.options.enable, [recognizer])) actions = actions.concat(recognizer.getTouchAction());
22903
- });
22904
- return cleanTouchActions(actions.join(" "));
22905
- },
22906
- preventDefaults: function(input) {
22907
- var srcEvent = input.srcEvent;
22908
- var direction = input.offsetDirection;
22909
- if (this.manager.session.prevented) {
22910
- srcEvent.preventDefault();
22911
- return;
22912
- }
22913
- var actions = this.actions;
22914
- var hasNone = inStr(actions, TOUCH_ACTION_NONE) && !TOUCH_ACTION_MAP[TOUCH_ACTION_NONE];
22915
- var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_Y];
22916
- var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_X];
22917
- if (hasNone) {
22918
- var isTapPointer = input.pointers.length === 1;
22919
- var isTapMovement = input.distance < 2;
22920
- var isTapTouchTime = input.deltaTime < 250;
22921
- if (isTapPointer && isTapMovement && isTapTouchTime) return;
22922
- }
22923
- if (hasPanX && hasPanY) return;
22924
- if (hasNone || hasPanY && direction & DIRECTION_HORIZONTAL || hasPanX && direction & DIRECTION_VERTICAL) return this.preventSrc(srcEvent);
22925
- },
22926
- preventSrc: function(srcEvent) {
22927
- this.manager.session.prevented = true;
22928
- srcEvent.preventDefault();
22929
- }
22930
- };
22931
- /**
22932
- * when the touchActions are collected they are not a valid value, so we need to clean things up. *
22933
- * @param {String} actions
22934
- * @returns {*}
22935
- */
22936
- function cleanTouchActions(actions) {
22937
- if (inStr(actions, TOUCH_ACTION_NONE)) return TOUCH_ACTION_NONE;
22938
- var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
22939
- var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
22940
- if (hasPanX && hasPanY) return TOUCH_ACTION_NONE;
22941
- if (hasPanX || hasPanY) return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y;
22942
- if (inStr(actions, TOUCH_ACTION_MANIPULATION)) return TOUCH_ACTION_MANIPULATION;
22943
- return TOUCH_ACTION_AUTO;
22944
- }
22945
- function getTouchActionProps() {
22946
- if (!NATIVE_TOUCH_ACTION) return false;
22947
- var touchMap = {};
22948
- var cssSupports = window$1.CSS && window$1.CSS.supports;
22949
- [
22950
- "auto",
22951
- "manipulation",
22952
- "pan-y",
22953
- "pan-x",
22954
- "pan-x pan-y",
22955
- "none"
22956
- ].forEach(function(val) {
22957
- touchMap[val] = cssSupports ? window$1.CSS.supports("touch-action", val) : true;
22958
- });
22959
- return touchMap;
22960
- }
22961
- /**
22962
- * Recognizer flow explained; *
22963
- * All recognizers have the initial state of POSSIBLE when a input session starts.
22964
- * The definition of a input session is from the first input until the last input, with all it's movement in it. *
22965
- * Example session for mouse-input: mousedown -> mousemove -> mouseup
22966
- *
22967
- * On each recognizing cycle (see Manager.recognize) the .recognize() method is executed
22968
- * which determines with state it should be.
22969
- *
22970
- * If the recognizer has the state FAILED, CANCELLED or RECOGNIZED (equals ENDED), it is reset to
22971
- * POSSIBLE to give it another change on the next cycle.
22972
- *
22973
- * Possible
22974
- * |
22975
- * +-----+---------------+
22976
- * | |
22977
- * +-----+-----+ |
22978
- * | | |
22979
- * Failed Cancelled |
22980
- * +-------+------+
22981
- * | |
22982
- * Recognized Began
22983
- * |
22984
- * Changed
22985
- * |
22986
- * Ended/Recognized
22987
- */
22988
- var STATE_POSSIBLE = 1;
22989
- var STATE_BEGAN = 2;
22990
- var STATE_CHANGED = 4;
22991
- var STATE_ENDED = 8;
22992
- var STATE_RECOGNIZED = STATE_ENDED;
22993
- var STATE_CANCELLED = 16;
22994
- var STATE_FAILED = 32;
22995
- /**
22996
- * Recognizer
22997
- * Every recognizer needs to extend from this class.
22998
- * @constructor
22999
- * @param {Object} options
23000
- */
23001
- function Recognizer(options) {
23002
- this.options = assign({}, this.defaults, options || {});
23003
- this.id = uniqueId();
23004
- this.manager = null;
23005
- this.options.enable = ifUndefined(this.options.enable, true);
23006
- this.state = STATE_POSSIBLE;
23007
- this.simultaneous = {};
23008
- this.requireFail = [];
23009
- }
23010
- Recognizer.prototype = {
23011
- defaults: {},
23012
- set: function(options) {
23013
- assign(this.options, options);
23014
- this.manager && this.manager.touchAction.update();
23015
- return this;
23016
- },
23017
- recognizeWith: function(otherRecognizer) {
23018
- if (invokeArrayArg(otherRecognizer, "recognizeWith", this)) return this;
23019
- var simultaneous = this.simultaneous;
23020
- otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
23021
- if (!simultaneous[otherRecognizer.id]) {
23022
- simultaneous[otherRecognizer.id] = otherRecognizer;
23023
- otherRecognizer.recognizeWith(this);
23024
- }
23025
- return this;
23026
- },
23027
- dropRecognizeWith: function(otherRecognizer) {
23028
- if (invokeArrayArg(otherRecognizer, "dropRecognizeWith", this)) return this;
23029
- otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
23030
- delete this.simultaneous[otherRecognizer.id];
23031
- return this;
23032
- },
23033
- requireFailure: function(otherRecognizer) {
23034
- if (invokeArrayArg(otherRecognizer, "requireFailure", this)) return this;
23035
- var requireFail = this.requireFail;
23036
- otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
23037
- if (inArray(requireFail, otherRecognizer) === -1) {
23038
- requireFail.push(otherRecognizer);
23039
- otherRecognizer.requireFailure(this);
23040
- }
23041
- return this;
23042
- },
23043
- dropRequireFailure: function(otherRecognizer) {
23044
- if (invokeArrayArg(otherRecognizer, "dropRequireFailure", this)) return this;
23045
- otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
23046
- var index = inArray(this.requireFail, otherRecognizer);
23047
- if (index > -1) this.requireFail.splice(index, 1);
23048
- return this;
23049
- },
23050
- hasRequireFailures: function() {
23051
- return this.requireFail.length > 0;
23052
- },
23053
- canRecognizeWith: function(otherRecognizer) {
23054
- return !!this.simultaneous[otherRecognizer.id];
23055
- },
23056
- emit: function(input) {
23057
- var self$1 = this;
23058
- var state = this.state;
23059
- function emit(event) {
23060
- self$1.manager.emit(event, input);
23061
- }
23062
- if (state < STATE_ENDED) emit(self$1.options.event + stateStr(state));
23063
- emit(self$1.options.event);
23064
- if (input.additionalEvent) emit(input.additionalEvent);
23065
- if (state >= STATE_ENDED) emit(self$1.options.event + stateStr(state));
23066
- },
23067
- tryEmit: function(input) {
23068
- if (this.canEmit()) return this.emit(input);
23069
- this.state = STATE_FAILED;
23070
- },
23071
- canEmit: function() {
23072
- var i = 0;
23073
- while (i < this.requireFail.length) {
23074
- if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) return false;
23075
- i++;
23076
- }
23077
- return true;
23078
- },
23079
- recognize: function(inputData) {
23080
- var inputDataClone = assign({}, inputData);
23081
- if (!boolOrFn(this.options.enable, [this, inputDataClone])) {
23082
- this.reset();
23083
- this.state = STATE_FAILED;
23084
- return;
23085
- }
23086
- if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) this.state = STATE_POSSIBLE;
23087
- this.state = this.process(inputDataClone);
23088
- if (this.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED)) this.tryEmit(inputDataClone);
23089
- },
23090
- process: function(inputData) {},
23091
- getTouchAction: function() {},
23092
- reset: function() {}
23093
- };
23094
- /**
23095
- * get a usable string, used as event postfix
23096
- * @param {Const} state
23097
- * @returns {String} state
23098
- */
23099
- function stateStr(state) {
23100
- if (state & STATE_CANCELLED) return "cancel";
23101
- else if (state & STATE_ENDED) return "end";
23102
- else if (state & STATE_CHANGED) return "move";
23103
- else if (state & STATE_BEGAN) return "start";
23104
- return "";
23105
- }
23106
- /**
23107
- * direction cons to string
23108
- * @param {Const} direction
23109
- * @returns {String}
23110
- */
23111
- function directionStr(direction) {
23112
- if (direction == DIRECTION_DOWN) return "down";
23113
- else if (direction == DIRECTION_UP) return "up";
23114
- else if (direction == DIRECTION_LEFT) return "left";
23115
- else if (direction == DIRECTION_RIGHT) return "right";
23116
- return "";
23117
- }
23118
- /**
23119
- * get a recognizer by name if it is bound to a manager
23120
- * @param {Recognizer|String} otherRecognizer
23121
- * @param {Recognizer} recognizer
23122
- * @returns {Recognizer}
23123
- */
23124
- function getRecognizerByNameIfManager(otherRecognizer, recognizer) {
23125
- var manager = recognizer.manager;
23126
- if (manager) return manager.get(otherRecognizer);
23127
- return otherRecognizer;
23128
- }
23129
- /**
23130
- * This recognizer is just used as a base for the simple attribute recognizers.
23131
- * @constructor
23132
- * @extends Recognizer
23133
- */
23134
- function AttrRecognizer() {
23135
- Recognizer.apply(this, arguments);
23136
- }
23137
- inherit(AttrRecognizer, Recognizer, {
23138
- defaults: { pointers: 1 },
23139
- attrTest: function(input) {
23140
- var optionPointers = this.options.pointers;
23141
- return optionPointers === 0 || input.pointers.length === optionPointers;
23142
- },
23143
- process: function(input) {
23144
- var state = this.state;
23145
- var eventType = input.eventType;
23146
- var isRecognized = state & (STATE_BEGAN | STATE_CHANGED);
23147
- var isValid = this.attrTest(input);
23148
- if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) return state | STATE_CANCELLED;
23149
- else if (isRecognized || isValid) {
23150
- if (eventType & INPUT_END) return state | STATE_ENDED;
23151
- else if (!(state & STATE_BEGAN)) return STATE_BEGAN;
23152
- return state | STATE_CHANGED;
23153
- }
23154
- return STATE_FAILED;
23155
- }
23156
- });
23157
- /**
23158
- * Pan
23159
- * Recognized when the pointer is down and moved in the allowed direction.
23160
- * @constructor
23161
- * @extends AttrRecognizer
23162
- */
23163
- function PanRecognizer() {
23164
- AttrRecognizer.apply(this, arguments);
23165
- this.pX = null;
23166
- this.pY = null;
23167
- }
23168
- inherit(PanRecognizer, AttrRecognizer, {
23169
- defaults: {
23170
- event: "pan",
23171
- threshold: 10,
23172
- pointers: 1,
23173
- direction: DIRECTION_ALL
23174
- },
23175
- getTouchAction: function() {
23176
- var direction = this.options.direction;
23177
- var actions = [];
23178
- if (direction & DIRECTION_HORIZONTAL) actions.push(TOUCH_ACTION_PAN_Y);
23179
- if (direction & DIRECTION_VERTICAL) actions.push(TOUCH_ACTION_PAN_X);
23180
- return actions;
23181
- },
23182
- directionTest: function(input) {
23183
- var options = this.options;
23184
- var hasMoved = true;
23185
- var distance = input.distance;
23186
- var direction = input.direction;
23187
- var x = input.deltaX;
23188
- var y = input.deltaY;
23189
- if (!(direction & options.direction)) if (options.direction & DIRECTION_HORIZONTAL) {
23190
- direction = x === 0 ? DIRECTION_NONE : x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
23191
- hasMoved = x != this.pX;
23192
- distance = Math.abs(input.deltaX);
23193
- } else {
23194
- direction = y === 0 ? DIRECTION_NONE : y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
23195
- hasMoved = y != this.pY;
23196
- distance = Math.abs(input.deltaY);
23197
- }
23198
- input.direction = direction;
23199
- return hasMoved && distance > options.threshold && direction & options.direction;
23200
- },
23201
- attrTest: function(input) {
23202
- return AttrRecognizer.prototype.attrTest.call(this, input) && (this.state & STATE_BEGAN || !(this.state & STATE_BEGAN) && this.directionTest(input));
23203
- },
23204
- emit: function(input) {
23205
- this.pX = input.deltaX;
23206
- this.pY = input.deltaY;
23207
- var direction = directionStr(input.direction);
23208
- if (direction) input.additionalEvent = this.options.event + direction;
23209
- this._super.emit.call(this, input);
23210
- }
23211
- });
23212
- /**
23213
- * Pinch
23214
- * Recognized when two or more pointers are moving toward (zoom-in) or away from each other (zoom-out).
23215
- * @constructor
23216
- * @extends AttrRecognizer
23217
- */
23218
- function PinchRecognizer() {
23219
- AttrRecognizer.apply(this, arguments);
23220
- }
23221
- inherit(PinchRecognizer, AttrRecognizer, {
23222
- defaults: {
23223
- event: "pinch",
23224
- threshold: 0,
23225
- pointers: 2
23226
- },
23227
- getTouchAction: function() {
23228
- return [TOUCH_ACTION_NONE];
23229
- },
23230
- attrTest: function(input) {
23231
- return this._super.attrTest.call(this, input) && (Math.abs(input.scale - 1) > this.options.threshold || this.state & STATE_BEGAN);
23232
- },
23233
- emit: function(input) {
23234
- if (input.scale !== 1) {
23235
- var inOut = input.scale < 1 ? "in" : "out";
23236
- input.additionalEvent = this.options.event + inOut;
23237
- }
23238
- this._super.emit.call(this, input);
23239
- }
23240
- });
23241
- /**
23242
- * Press
23243
- * Recognized when the pointer is down for x ms without any movement.
23244
- * @constructor
23245
- * @extends Recognizer
23246
- */
23247
- function PressRecognizer() {
23248
- Recognizer.apply(this, arguments);
23249
- this._timer = null;
23250
- this._input = null;
23251
- }
23252
- inherit(PressRecognizer, Recognizer, {
23253
- defaults: {
23254
- event: "press",
23255
- pointers: 1,
23256
- time: 251,
23257
- threshold: 9
23258
- },
23259
- getTouchAction: function() {
23260
- return [TOUCH_ACTION_AUTO];
23261
- },
23262
- process: function(input) {
23263
- var options = this.options;
23264
- var validPointers = input.pointers.length === options.pointers;
23265
- var validMovement = input.distance < options.threshold;
23266
- var validTime = input.deltaTime > options.time;
23267
- this._input = input;
23268
- if (!validMovement || !validPointers || input.eventType & (INPUT_END | INPUT_CANCEL) && !validTime) this.reset();
23269
- else if (input.eventType & INPUT_START) {
23270
- this.reset();
23271
- this._timer = setTimeoutContext(function() {
23272
- this.state = STATE_RECOGNIZED;
23273
- this.tryEmit();
23274
- }, options.time, this);
23275
- } else if (input.eventType & INPUT_END) return STATE_RECOGNIZED;
23276
- return STATE_FAILED;
23277
- },
23278
- reset: function() {
23279
- clearTimeout(this._timer);
23280
- },
23281
- emit: function(input) {
23282
- if (this.state !== STATE_RECOGNIZED) return;
23283
- if (input && input.eventType & INPUT_END) this.manager.emit(this.options.event + "up", input);
23284
- else {
23285
- this._input.timeStamp = now();
23286
- this.manager.emit(this.options.event, this._input);
23287
- }
23288
- }
23289
- });
23290
- /**
23291
- * Rotate
23292
- * Recognized when two or more pointer are moving in a circular motion.
23293
- * @constructor
23294
- * @extends AttrRecognizer
23295
- */
23296
- function RotateRecognizer() {
23297
- AttrRecognizer.apply(this, arguments);
23298
- }
23299
- inherit(RotateRecognizer, AttrRecognizer, {
23300
- defaults: {
23301
- event: "rotate",
23302
- threshold: 0,
23303
- pointers: 2
23304
- },
23305
- getTouchAction: function() {
23306
- return [TOUCH_ACTION_NONE];
23307
- },
23308
- attrTest: function(input) {
23309
- return this._super.attrTest.call(this, input) && (Math.abs(input.rotation) > this.options.threshold || this.state & STATE_BEGAN);
23310
- }
23311
- });
23312
- /**
23313
- * Swipe
23314
- * Recognized when the pointer is moving fast (velocity), with enough distance in the allowed direction.
23315
- * @constructor
23316
- * @extends AttrRecognizer
23317
- */
23318
- function SwipeRecognizer() {
23319
- AttrRecognizer.apply(this, arguments);
23320
- }
23321
- inherit(SwipeRecognizer, AttrRecognizer, {
23322
- defaults: {
23323
- event: "swipe",
23324
- threshold: 10,
23325
- velocity: .3,
23326
- direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL,
23327
- pointers: 1
23328
- },
23329
- getTouchAction: function() {
23330
- return PanRecognizer.prototype.getTouchAction.call(this);
23331
- },
23332
- attrTest: function(input) {
23333
- var direction = this.options.direction;
23334
- var velocity;
23335
- if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) velocity = input.overallVelocity;
23336
- else if (direction & DIRECTION_HORIZONTAL) velocity = input.overallVelocityX;
23337
- else if (direction & DIRECTION_VERTICAL) velocity = input.overallVelocityY;
23338
- return this._super.attrTest.call(this, input) && direction & input.offsetDirection && input.distance > this.options.threshold && input.maxPointers == this.options.pointers && abs(velocity) > this.options.velocity && input.eventType & INPUT_END;
23339
- },
23340
- emit: function(input) {
23341
- var direction = directionStr(input.offsetDirection);
23342
- if (direction) this.manager.emit(this.options.event + direction, input);
23343
- this.manager.emit(this.options.event, input);
23344
- }
23345
- });
23346
- /**
23347
- * A tap is ecognized when the pointer is doing a small tap/click. Multiple taps are recognized if they occur
23348
- * between the given interval and position. The delay option can be used to recognize multi-taps without firing
23349
- * a single tap.
23350
- *
23351
- * The eventData from the emitted event contains the property `tapCount`, which contains the amount of
23352
- * multi-taps being recognized.
23353
- * @constructor
23354
- * @extends Recognizer
23355
- */
23356
- function TapRecognizer() {
23357
- Recognizer.apply(this, arguments);
23358
- this.pTime = false;
23359
- this.pCenter = false;
23360
- this._timer = null;
23361
- this._input = null;
23362
- this.count = 0;
23363
- }
23364
- inherit(TapRecognizer, Recognizer, {
23365
- defaults: {
23366
- event: "tap",
23367
- pointers: 1,
23368
- taps: 1,
23369
- interval: 300,
23370
- time: 250,
23371
- threshold: 9,
23372
- posThreshold: 10
23373
- },
23374
- getTouchAction: function() {
23375
- return [TOUCH_ACTION_MANIPULATION];
23376
- },
23377
- process: function(input) {
23378
- var options = this.options;
23379
- var validPointers = input.pointers.length === options.pointers;
23380
- var validMovement = input.distance < options.threshold;
23381
- var validTouchTime = input.deltaTime < options.time;
23382
- this.reset();
23383
- if (input.eventType & INPUT_START && this.count === 0) return this.failTimeout();
23384
- if (validMovement && validTouchTime && validPointers) {
23385
- if (input.eventType != INPUT_END) return this.failTimeout();
23386
- var validInterval = this.pTime ? input.timeStamp - this.pTime < options.interval : true;
23387
- var validMultiTap = !this.pCenter || getDistance(this.pCenter, input.center) < options.posThreshold;
23388
- this.pTime = input.timeStamp;
23389
- this.pCenter = input.center;
23390
- if (!validMultiTap || !validInterval) this.count = 1;
23391
- else this.count += 1;
23392
- this._input = input;
23393
- var tapCount = this.count % options.taps;
23394
- if (tapCount === 0) if (!this.hasRequireFailures()) return STATE_RECOGNIZED;
23395
- else {
23396
- this._timer = setTimeoutContext(function() {
23397
- this.state = STATE_RECOGNIZED;
23398
- this.tryEmit();
23399
- }, options.interval, this);
23400
- return STATE_BEGAN;
23401
- }
23402
- }
23403
- return STATE_FAILED;
23404
- },
23405
- failTimeout: function() {
23406
- this._timer = setTimeoutContext(function() {
23407
- this.state = STATE_FAILED;
23408
- }, this.options.interval, this);
23409
- return STATE_FAILED;
23410
- },
23411
- reset: function() {
23412
- clearTimeout(this._timer);
23413
- },
23414
- emit: function() {
23415
- if (this.state == STATE_RECOGNIZED) {
23416
- this._input.tapCount = this.count;
23417
- this.manager.emit(this.options.event, this._input);
23418
- }
23419
- }
23420
- });
23421
- /**
23422
- * Simple way to create a manager with a default set of recognizers.
23423
- * @param {HTMLElement} element
23424
- * @param {Object} [options]
23425
- * @constructor
23426
- */
23427
- function Hammer(element, options) {
23428
- options = options || {};
23429
- options.recognizers = ifUndefined(options.recognizers, Hammer.defaults.preset);
23430
- return new Manager(element, options);
23431
- }
23432
- /**
23433
- * @const {string}
23434
- */
23435
- Hammer.VERSION = "2.0.7";
23436
- /**
23437
- * default settings
23438
- * @namespace
23439
- */
23440
- Hammer.defaults = {
23441
- domEvents: false,
23442
- touchAction: TOUCH_ACTION_COMPUTE,
23443
- enable: true,
23444
- inputTarget: null,
23445
- inputClass: null,
23446
- preset: [
23447
- [RotateRecognizer, { enable: false }],
23448
- [
23449
- PinchRecognizer,
23450
- { enable: false },
23451
- ["rotate"]
23452
- ],
23453
- [SwipeRecognizer, { direction: DIRECTION_HORIZONTAL }],
23454
- [
23455
- PanRecognizer,
23456
- { direction: DIRECTION_HORIZONTAL },
23457
- ["swipe"]
23458
- ],
23459
- [TapRecognizer],
23460
- [
23461
- TapRecognizer,
23462
- {
23463
- event: "doubletap",
23464
- taps: 2
23465
- },
23466
- ["tap"]
23467
- ],
23468
- [PressRecognizer]
23469
- ],
23470
- cssProps: {
23471
- userSelect: "none",
23472
- touchSelect: "none",
23473
- touchCallout: "none",
23474
- contentZooming: "none",
23475
- userDrag: "none",
23476
- tapHighlightColor: "rgba(0,0,0,0)"
23477
- }
23478
- };
23479
- var STOP = 1;
23480
- var FORCED_STOP = 2;
23481
- /**
23482
- * Manager
23483
- * @param {HTMLElement} element
23484
- * @param {Object} [options]
23485
- * @constructor
23486
- */
23487
- function Manager(element, options) {
23488
- this.options = assign({}, Hammer.defaults, options || {});
23489
- this.options.inputTarget = this.options.inputTarget || element;
23490
- this.handlers = {};
23491
- this.session = {};
23492
- this.recognizers = [];
23493
- this.oldCssProps = {};
23494
- this.element = element;
23495
- this.input = createInputInstance(this);
23496
- this.touchAction = new TouchAction(this, this.options.touchAction);
23497
- toggleCssProps(this, true);
23498
- each(this.options.recognizers, function(item) {
23499
- var recognizer = this.add(new item[0](item[1]));
23500
- item[2] && recognizer.recognizeWith(item[2]);
23501
- item[3] && recognizer.requireFailure(item[3]);
23502
- }, this);
23503
- }
23504
- Manager.prototype = {
23505
- set: function(options) {
23506
- assign(this.options, options);
23507
- if (options.touchAction) this.touchAction.update();
23508
- if (options.inputTarget) {
23509
- this.input.destroy();
23510
- this.input.target = options.inputTarget;
23511
- this.input.init();
23512
- }
23513
- return this;
23514
- },
23515
- stop: function(force) {
23516
- this.session.stopped = force ? FORCED_STOP : STOP;
23517
- },
23518
- recognize: function(inputData) {
23519
- var session = this.session;
23520
- if (session.stopped) return;
23521
- this.touchAction.preventDefaults(inputData);
23522
- var recognizer;
23523
- var recognizers = this.recognizers;
23524
- var curRecognizer = session.curRecognizer;
23525
- if (!curRecognizer || curRecognizer && curRecognizer.state & STATE_RECOGNIZED) curRecognizer = session.curRecognizer = null;
23526
- var i = 0;
23527
- while (i < recognizers.length) {
23528
- recognizer = recognizers[i];
23529
- if (session.stopped !== FORCED_STOP && (!curRecognizer || recognizer == curRecognizer || recognizer.canRecognizeWith(curRecognizer))) recognizer.recognize(inputData);
23530
- else recognizer.reset();
23531
- if (!curRecognizer && recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED)) curRecognizer = session.curRecognizer = recognizer;
23532
- i++;
23533
- }
23534
- },
23535
- get: function(recognizer) {
23536
- if (recognizer instanceof Recognizer) return recognizer;
23537
- var recognizers = this.recognizers;
23538
- for (var i = 0; i < recognizers.length; i++) if (recognizers[i].options.event == recognizer) return recognizers[i];
23539
- return null;
23540
- },
23541
- add: function(recognizer) {
23542
- if (invokeArrayArg(recognizer, "add", this)) return this;
23543
- var existing = this.get(recognizer.options.event);
23544
- if (existing) this.remove(existing);
23545
- this.recognizers.push(recognizer);
23546
- recognizer.manager = this;
23547
- this.touchAction.update();
23548
- return recognizer;
23549
- },
23550
- remove: function(recognizer) {
23551
- if (invokeArrayArg(recognizer, "remove", this)) return this;
23552
- recognizer = this.get(recognizer);
23553
- if (recognizer) {
23554
- var recognizers = this.recognizers;
23555
- var index = inArray(recognizers, recognizer);
23556
- if (index !== -1) {
23557
- recognizers.splice(index, 1);
23558
- this.touchAction.update();
23559
- }
23560
- }
23561
- return this;
23562
- },
23563
- on: function(events, handler) {
23564
- if (events === undefined$1) return;
23565
- if (handler === undefined$1) return;
23566
- var handlers = this.handlers;
23567
- each(splitStr(events), function(event) {
23568
- handlers[event] = handlers[event] || [];
23569
- handlers[event].push(handler);
23570
- });
23571
- return this;
23572
- },
23573
- off: function(events, handler) {
23574
- if (events === undefined$1) return;
23575
- var handlers = this.handlers;
23576
- each(splitStr(events), function(event) {
23577
- if (!handler) delete handlers[event];
23578
- else handlers[event] && handlers[event].splice(inArray(handlers[event], handler), 1);
23579
- });
23580
- return this;
23581
- },
23582
- emit: function(event, data) {
23583
- if (this.options.domEvents) triggerDomEvent(event, data);
23584
- var handlers = this.handlers[event] && this.handlers[event].slice();
23585
- if (!handlers || !handlers.length) return;
23586
- data.type = event;
23587
- data.preventDefault = function() {
23588
- data.srcEvent.preventDefault();
23589
- };
23590
- var i = 0;
23591
- while (i < handlers.length) {
23592
- handlers[i](data);
23593
- i++;
23594
- }
23595
- },
23596
- destroy: function() {
23597
- this.element && toggleCssProps(this, false);
23598
- this.handlers = {};
23599
- this.session = {};
23600
- this.input.destroy();
23601
- this.element = null;
23602
- }
23603
- };
23604
- /**
23605
- * add/remove the css properties as defined in manager.options.cssProps
23606
- * @param {Manager} manager
23607
- * @param {Boolean} add
23608
- */
23609
- function toggleCssProps(manager, add) {
23610
- var element = manager.element;
23611
- if (!element.style) return;
23612
- var prop;
23613
- each(manager.options.cssProps, function(value, name) {
23614
- prop = prefixed(element.style, name);
23615
- if (add) {
23616
- manager.oldCssProps[prop] = element.style[prop];
23617
- element.style[prop] = value;
23618
- } else element.style[prop] = manager.oldCssProps[prop] || "";
23619
- });
23620
- if (!add) manager.oldCssProps = {};
23621
- }
23622
- /**
23623
- * trigger dom event
23624
- * @param {String} event
23625
- * @param {Object} data
23626
- */
23627
- function triggerDomEvent(event, data) {
23628
- var gestureEvent = document$1.createEvent("Event");
23629
- gestureEvent.initEvent(event, true, true);
23630
- gestureEvent.gesture = data;
23631
- data.target.dispatchEvent(gestureEvent);
23632
- }
23633
- assign(Hammer, {
23634
- INPUT_START,
23635
- INPUT_MOVE,
23636
- INPUT_END,
23637
- INPUT_CANCEL,
23638
- STATE_POSSIBLE,
23639
- STATE_BEGAN,
23640
- STATE_CHANGED,
23641
- STATE_ENDED,
23642
- STATE_RECOGNIZED,
23643
- STATE_CANCELLED,
23644
- STATE_FAILED,
23645
- DIRECTION_NONE,
23646
- DIRECTION_LEFT,
23647
- DIRECTION_RIGHT,
23648
- DIRECTION_UP,
23649
- DIRECTION_DOWN,
23650
- DIRECTION_HORIZONTAL,
23651
- DIRECTION_VERTICAL,
23652
- DIRECTION_ALL,
23653
- Manager,
23654
- Input,
23655
- TouchAction,
23656
- TouchInput,
23657
- MouseInput,
23658
- PointerEventInput,
23659
- TouchMouseInput,
23660
- SingleTouchInput,
23661
- Recognizer,
23662
- AttrRecognizer,
23663
- Tap: TapRecognizer,
23664
- Pan: PanRecognizer,
23665
- Swipe: SwipeRecognizer,
23666
- Pinch: PinchRecognizer,
23667
- Rotate: RotateRecognizer,
23668
- Press: PressRecognizer,
23669
- on: addEventListeners,
23670
- off: removeEventListeners,
23671
- each,
23672
- merge,
23673
- extend,
23674
- assign,
23675
- inherit,
23676
- bindFn,
23677
- prefixed
23678
- });
23679
- var freeGlobal = typeof window$1 !== "undefined" ? window$1 : typeof self !== "undefined" ? self : {};
23680
- freeGlobal.Hammer = Hammer;
23681
- if (typeof define === "function" && define.amd) define(function() {
23682
- return Hammer;
23683
- });
23684
- else if (typeof module != "undefined" && module.exports) module.exports = Hammer;
23685
- else window$1[exportName] = Hammer;
23686
- })(window, document, "Hammer");
23687
- } });
23688
- var import_hammer = __toESM(require_hammer(), 1);
23689
-
23690
22022
  //#endregion
23691
22023
  //#region src/plugins/stage-zoom/stage-zoom.ts
23692
22024
  var WeaveStageZoomPlugin = class extends WeavePlugin {
@@ -23697,19 +22029,12 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
23697
22029
  isTrackpad = false;
23698
22030
  zoomVelocity = 0;
23699
22031
  zoomInertiaType = WEAVE_STAGE_ZOOM_TYPE.MOUSE_WHEEL;
23700
- initialScale = 0;
23701
- lastTime = 0;
23702
- center = {
23703
- x: 0,
23704
- y: 0
23705
- };
23706
22032
  defaultStep = 3;
23707
22033
  constructor(params) {
23708
22034
  super();
23709
22035
  const { config } = params ?? {};
23710
22036
  this.config = (0, import_lodash.merge)(WEAVE_STAGE_ZOOM_DEFAULT_CONFIG, config);
23711
22037
  if (!this.config.zoomSteps.includes(this.config.defaultZoom)) throw new Error(`Default zoom ${this.config.defaultZoom} is not in zoom steps`);
23712
- this.threshold = .2;
23713
22038
  this.pinching = false;
23714
22039
  this.isTrackpad = false;
23715
22040
  this.isCtrlOrMetaPressed = false;
@@ -23950,6 +22275,15 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
23950
22275
  disable() {
23951
22276
  this.enabled = false;
23952
22277
  }
22278
+ getDistance(p1, p2) {
22279
+ return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
22280
+ }
22281
+ getCenter(p1, p2) {
22282
+ return {
22283
+ x: (p1.x + p2.x) / 2,
22284
+ y: (p1.y + p2.y) / 2
22285
+ };
22286
+ }
23953
22287
  initEvents() {
23954
22288
  window.addEventListener("keydown", (e) => {
23955
22289
  if (e.ctrlKey || e.metaKey) this.isCtrlOrMetaPressed = true;
@@ -23958,57 +22292,80 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
23958
22292
  if (!(e.ctrlKey || e.metaKey)) this.isCtrlOrMetaPressed = false;
23959
22293
  });
23960
22294
  const stage = this.instance.getStage();
23961
- const stageContainer = this.instance.getStage().container();
23962
- const sc = new import_hammer.default.Manager(stageContainer);
23963
- sc.add(new import_hammer.default.Pinch({
23964
- threshold: this.threshold,
23965
- pointers: 2
23966
- }));
23967
- sc.on("pinchstart", (e) => {
23968
- if (this.getPanPlugin()?.isPanning()) {
23969
- this.pinching = false;
23970
- return;
23971
- }
23972
- this.getNodesSelectionPlugin()?.disable();
23973
- this.initialScale = this.instance.getStage().scaleX();
23974
- this.center = {
23975
- x: e.center.x,
23976
- y: e.center.y
23977
- };
23978
- this.lastTime = performance.now();
23979
- });
23980
- sc.on("pinchmove", (e) => {
23981
- if (this.getPanPlugin()?.isPanning()) {
23982
- this.pinching = false;
23983
- return;
22295
+ let lastCenter = null;
22296
+ let lastDist = 0;
22297
+ stage.getContent().addEventListener("touchstart", (e) => {
22298
+ e.preventDefault();
22299
+ if (e.touches.length === 2) {
22300
+ e.preventDefault();
22301
+ e.stopPropagation();
22302
+ this.pinching = true;
22303
+ const touch1 = e.touches[0];
22304
+ const touch2 = e.touches[1];
22305
+ const p1 = {
22306
+ x: touch1.clientX,
22307
+ y: touch1.clientY
22308
+ };
22309
+ const p2 = {
22310
+ x: touch2.clientX,
22311
+ y: touch2.clientY
22312
+ };
22313
+ if (!lastCenter) {
22314
+ lastCenter = this.getCenter(p1, p2);
22315
+ return;
22316
+ }
23984
22317
  }
23985
- this.pinching = true;
23986
- const now = performance.now();
23987
- this.getContextMenuPlugin()?.cancelLongPressTimer();
23988
- const newScale = Math.max(this.config.zoomSteps[0], Math.min(this.config.zoomSteps[this.config.zoomSteps.length - 1], this.initialScale * e.scale));
23989
- this.setZoom(newScale, false, this.center);
23990
- const dt = now - this.lastTime;
23991
- this.zoomVelocity = (newScale - 1) / (dt * 16.6);
23992
- this.lastTime = now;
23993
- });
23994
- sc.on("pinchend", () => {
23995
- if (this.getPanPlugin()?.isPanning()) {
23996
- this.pinching = false;
23997
- this.zooming = false;
23998
- return;
22318
+ }, { passive: false });
22319
+ stage.getContent().addEventListener("touchmove", (e) => {
22320
+ e.preventDefault();
22321
+ if (e.touches.length === 2) {
22322
+ e.preventDefault();
22323
+ e.stopPropagation();
22324
+ this.getContextMenuPlugin()?.cancelLongPressTimer();
22325
+ const touch1 = e.touches[0];
22326
+ const touch2 = e.touches[1];
22327
+ const p1 = {
22328
+ x: touch1.clientX,
22329
+ y: touch1.clientY
22330
+ };
22331
+ const p2 = {
22332
+ x: touch2.clientX,
22333
+ y: touch2.clientY
22334
+ };
22335
+ if (!lastCenter) {
22336
+ lastCenter = this.getCenter(p1, p2);
22337
+ return;
22338
+ }
22339
+ const newCenter = this.getCenter(p1, p2);
22340
+ const dist = this.getDistance(p1, p2);
22341
+ if (!lastDist) lastDist = dist;
22342
+ const pointTo = {
22343
+ x: (newCenter.x - stage.x()) / stage.scaleX(),
22344
+ y: (newCenter.y - stage.y()) / stage.scaleX()
22345
+ };
22346
+ const newScale = Math.max(this.config.zoomSteps[0], Math.min(this.config.zoomSteps[this.config.zoomSteps.length - 1], stage.scaleX() * (dist / lastDist)));
22347
+ this.setZoom(newScale, false, newCenter);
22348
+ const dx = newCenter.x - lastCenter.x;
22349
+ const dy = newCenter.y - lastCenter.y;
22350
+ const newPos = {
22351
+ x: newCenter.x - pointTo.x * newScale + dx,
22352
+ y: newCenter.y - pointTo.y * newScale + dy
22353
+ };
22354
+ stage.position(newPos);
22355
+ lastDist = dist;
22356
+ lastCenter = newCenter;
23999
22357
  }
24000
- this.getNodesSelectionPlugin()?.enable();
22358
+ }, { passive: false });
22359
+ stage.getContent().addEventListener("touchend", () => {
24001
22360
  this.pinching = false;
24002
- this.zooming = true;
24003
- this.zoomInertiaType = WEAVE_STAGE_ZOOM_TYPE.PINCH_ZOOM;
24004
- requestAnimationFrame(this.zoomTick.bind(this));
24005
- });
22361
+ lastDist = 0;
22362
+ lastCenter = null;
22363
+ }, { passive: false });
24006
22364
  const handleWheel = (e) => {
24007
22365
  e.evt.preventDefault();
24008
22366
  const stage$1 = this.instance.getStage();
24009
22367
  const performZoom = this.isCtrlOrMetaPressed || !this.isCtrlOrMetaPressed && e.evt.ctrlKey && e.evt.deltaMode === 0;
24010
22368
  if (!this.enabled || !stage$1.isFocused() || !performZoom) return;
24011
- this.getNodesSelectionPlugin()?.disable();
24012
22369
  const delta = e.evt.deltaY > 0 ? 1 : -1;
24013
22370
  this.zoomVelocity += delta;
24014
22371
  this.isTrackpad = Math.abs(e.evt.deltaY) < 15 && e.evt.deltaMode === 0;
@@ -24035,13 +22392,12 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
24035
22392
  this.zooming = false;
24036
22393
  return;
24037
22394
  }
24038
- let pointer = this.center;
22395
+ let pointer = null;
24039
22396
  if (this.zoomInertiaType === WEAVE_STAGE_ZOOM_TYPE.MOUSE_WHEEL) {
24040
22397
  const stage = this.instance.getStage();
24041
22398
  pointer = stage.getPointerPosition();
24042
22399
  }
24043
22400
  if (!pointer) return;
24044
- this.getNodesSelectionPlugin()?.enable();
24045
22401
  this.setZoom(this.getInertiaScale(), false, pointer);
24046
22402
  this.zoomVelocity *= this.config.zoomInertia.friction;
24047
22403
  this.getStageGridPlugin()?.onRender();
@@ -24058,10 +22414,6 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
24058
22414
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
24059
22415
  return selectionPlugin;
24060
22416
  }
24061
- getPanPlugin() {
24062
- const panPlugin = this.instance.getPlugin("stagePanning");
24063
- return panPlugin;
24064
- }
24065
22417
  getContextMenuPlugin() {
24066
22418
  const contextMenuPlugin = this.instance.getPlugin("contextMenu");
24067
22419
  return contextMenuPlugin;
@@ -25064,13 +23416,11 @@ const BRUSH_TOOL_STATE = {
25064
23416
  //#region src/actions/brush-tool/brush-tool.ts
25065
23417
  var WeaveBrushToolAction = class extends WeaveAction {
25066
23418
  initialized = false;
25067
- lineWidth = 0;
25068
23419
  onPropsChange = void 0;
25069
23420
  onInit = void 0;
25070
23421
  constructor() {
25071
23422
  super();
25072
23423
  this.initialized = false;
25073
- this.lineWidth = 0;
25074
23424
  this.state = BRUSH_TOOL_STATE.INACTIVE;
25075
23425
  this.strokeId = null;
25076
23426
  this.clickPoint = null;
@@ -25110,16 +23460,14 @@ var WeaveBrushToolAction = class extends WeaveAction {
25110
23460
  const handlePointerDown = (e) => {
25111
23461
  if (this.state !== BRUSH_TOOL_STATE.IDLE) return;
25112
23462
  const pointPressure = this.getPointPressure(e);
25113
- this.lineWidth = Math.log(pointPressure + 1) * this.props.strokeWidth;
25114
- this.handleStartStroke();
23463
+ this.handleStartStroke(pointPressure);
25115
23464
  e.evt.stopPropagation();
25116
23465
  };
25117
23466
  stage.on("pointerdown touchstart", handlePointerDown);
25118
23467
  const handlePointerMove = (e) => {
25119
23468
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
25120
23469
  const pointPressure = this.getPointPressure(e);
25121
- this.lineWidth = Math.log(pointPressure + 1) * this.props.strokeWidth * .2 + this.lineWidth * .8;
25122
- this.handleMovement();
23470
+ this.handleMovement(pointPressure);
25123
23471
  e.evt.stopPropagation();
25124
23472
  };
25125
23473
  stage.on("pointermove touchmove", handlePointerMove);
@@ -25158,14 +23506,20 @@ var WeaveBrushToolAction = class extends WeaveAction {
25158
23506
  height: maxY - minY
25159
23507
  };
25160
23508
  }
25161
- handleStartStroke() {
23509
+ handleStartStroke(pressure) {
25162
23510
  const { mousePoint, container, measureContainer } = this.instance.getMousePointer();
25163
23511
  this.clickPoint = mousePoint;
25164
23512
  this.container = container;
25165
23513
  this.measureContainer = measureContainer;
25166
23514
  this.strokeId = v4_default();
25167
23515
  const nodeHandler = this.instance.getNodeHandler("stroke");
25168
- if (nodeHandler) {
23516
+ if (nodeHandler && mousePoint && this.measureContainer) {
23517
+ const newStrokeElements = [];
23518
+ newStrokeElements.push({
23519
+ x: mousePoint.x,
23520
+ y: mousePoint.y,
23521
+ pressure
23522
+ });
25169
23523
  const node = nodeHandler.create(this.strokeId, {
25170
23524
  ...this.props,
25171
23525
  strokeScaleEnabled: false,
@@ -25173,14 +23527,14 @@ var WeaveBrushToolAction = class extends WeaveAction {
25173
23527
  y: 0,
25174
23528
  width: 0,
25175
23529
  height: 0,
25176
- strokeElements: []
23530
+ strokeElements: newStrokeElements
25177
23531
  });
25178
23532
  const nodeInstance = nodeHandler.onRender(node.props);
25179
23533
  this.measureContainer?.add(nodeInstance);
25180
23534
  }
25181
23535
  this.setState(BRUSH_TOOL_STATE.DEFINE_STROKE);
25182
23536
  }
25183
- handleMovement() {
23537
+ handleMovement(pressure) {
25184
23538
  if (this.state !== BRUSH_TOOL_STATE.DEFINE_STROKE) return;
25185
23539
  const tempStroke = this.instance.getStage().findOne(`#${this.strokeId}`);
25186
23540
  if (this.measureContainer && tempStroke) {
@@ -25189,7 +23543,7 @@ var WeaveBrushToolAction = class extends WeaveAction {
25189
23543
  newStrokeElements.push({
25190
23544
  x: mousePoint.x - tempStroke.x(),
25191
23545
  y: mousePoint.y - tempStroke.y(),
25192
- lineWidth: this.lineWidth
23546
+ pressure
25193
23547
  });
25194
23548
  const box = this.getBoundingBox(newStrokeElements);
25195
23549
  tempStroke.setAttrs({
@@ -26778,18 +25132,13 @@ const WEAVE_STAGE_PANNING_KEY = "stagePanning";
26778
25132
  //#endregion
26779
25133
  //#region src/plugins/stage-panning/stage-panning.ts
26780
25134
  var WeaveStagePanningPlugin = class extends WeavePlugin {
26781
- pinching = false;
26782
25135
  panning = false;
26783
25136
  getLayerName = void 0;
26784
25137
  initLayer = void 0;
26785
25138
  constructor() {
26786
25139
  super();
26787
25140
  this.pointers = new Map();
26788
- this.lastCenter = null;
26789
- this.pinching = false;
26790
25141
  this.panning = false;
26791
- this.threshold = 5;
26792
- this.pointersDistanceDiffThreshold = 10;
26793
25142
  this.enabled = true;
26794
25143
  this.moveToolActive = false;
26795
25144
  this.isMouseMiddleButtonPressed = false;
@@ -26833,20 +25182,14 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
26833
25182
  this.disableMove();
26834
25183
  }
26835
25184
  });
26836
- let startPointersDistance = null;
26837
- let startCenter = null;
26838
25185
  let lastPos = null;
26839
25186
  let isDragging = false;
26840
- let velocity = {
26841
- x: 0,
26842
- y: 0
26843
- };
26844
- let lastTime = 0;
26845
25187
  stage.on("pointerdown", (e) => {
26846
25188
  this.pointers.set(e.evt.pointerId, {
26847
25189
  x: e.evt.clientX,
26848
25190
  y: e.evt.clientY
26849
25191
  });
25192
+ if (this.pointers.size > 1) return;
26850
25193
  const activeAction = this.instance.getActiveAction();
26851
25194
  let enableMove = false;
26852
25195
  if (e && (e.evt.pointerType !== "mouse" || e.evt.pointerType === "mouse" && e.evt.buttons === 1) && activeAction === "moveTool") {
@@ -26857,142 +25200,40 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
26857
25200
  this.isMouseMiddleButtonPressed = true;
26858
25201
  enableMove = true;
26859
25202
  }
26860
- if (e.evt.pointerType !== "mouse" && this.pointers.size === 2 && !this.pinching && !this.panning) {
26861
- const center = this.getTouchCenter();
26862
- const [p1, p2] = Array.from(this.pointers.values());
26863
- const pointersDistance = this.getDistance(p1, p2);
26864
- if (!startCenter) {
26865
- startPointersDistance = pointersDistance;
26866
- startCenter = center;
26867
- this.lastCenter = center;
26868
- this.pinching = false;
26869
- this.panning = false;
26870
- velocity = {
26871
- x: 0,
26872
- y: 0
26873
- };
26874
- }
26875
- isDragging = true;
26876
- lastPos = stage.getPointerPosition();
26877
- lastTime = performance.now();
26878
- this.enableMove();
26879
- return;
26880
- }
26881
25203
  if (enableMove) {
26882
25204
  isDragging = true;
26883
25205
  lastPos = stage.getPointerPosition();
26884
- lastTime = performance.now();
26885
- velocity = {
26886
- x: 0,
26887
- y: 0
26888
- };
26889
25206
  this.enableMove();
26890
25207
  }
26891
25208
  });
26892
25209
  stage.on("pointercancel", (e) => {
26893
25210
  this.pointers.delete(e.evt.pointerId);
26894
25211
  lastPos = null;
26895
- this.lastCenter = null;
26896
25212
  });
26897
25213
  const handleMouseMove = (e) => {
26898
25214
  this.pointers.set(e.evt.pointerId, {
26899
25215
  x: e.evt.clientX,
26900
25216
  y: e.evt.clientY
26901
25217
  });
25218
+ if (this.pointers.size > 1) return;
26902
25219
  if (!isDragging) return;
26903
- const center = this.getTouchCenter();
26904
- if (e.evt.pointerType !== "mouse" && this.pointers.size !== 2) {
26905
- startCenter = null;
26906
- startPointersDistance = null;
26907
- this.pinching = false;
26908
- this.panning = false;
26909
- }
26910
- if (e.evt.pointerType !== "mouse" && this.pointers.size === 2) {
26911
- this.getContextMenuPlugin()?.cancelLongPressTimer();
26912
- const [p1, p2] = Array.from(this.pointers.values());
26913
- const pointersDistance = this.getDistance(p1, p2);
26914
- if (!startCenter) {
26915
- startPointersDistance = pointersDistance;
26916
- startCenter = center;
26917
- this.lastCenter = center;
26918
- this.pinching = false;
26919
- this.panning = false;
26920
- }
26921
- if (center && startCenter && startPointersDistance && this.lastCenter) {
26922
- const now$1 = performance.now();
26923
- const dt$1 = now$1 - lastTime;
26924
- const dx = center.x - startCenter.x;
26925
- const dy = center.y - startCenter.y;
26926
- const distanceCenters = Math.hypot(dx, dy);
26927
- const distanceChange = Math.abs(pointersDistance - startPointersDistance);
26928
- if (!this.pinching && distanceCenters > this.threshold && distanceChange <= this.pointersDistanceDiffThreshold) this.panning = true;
26929
- if (!this.panning && distanceCenters <= this.threshold && distanceChange > this.pointersDistanceDiffThreshold) this.pinching = true;
26930
- if (this.panning) {
26931
- this.getNodesSelectionPlugin()?.disable();
26932
- const dx$1 = center.x - this.lastCenter.x;
26933
- const dy$1 = center.y - this.lastCenter.y;
26934
- velocity = {
26935
- x: dx$1 / dt$1,
26936
- y: dy$1 / dt$1
26937
- };
26938
- stage.x(stage.x() + dx$1);
26939
- stage.y(stage.y() + dy$1);
26940
- this.instance.emitEvent("onStageMove");
26941
- }
26942
- this.lastCenter = center;
26943
- lastTime = now$1;
26944
- return;
26945
- }
26946
- }
26947
- this.lastCenter = center;
26948
25220
  if (!this.enabled || !(this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed || this.moveToolActive)) return;
26949
25221
  this.getContextMenuPlugin()?.cancelLongPressTimer();
26950
- this.getNodesSelectionPlugin()?.disable();
26951
25222
  const pos = stage.getPointerPosition();
26952
- const now = performance.now();
26953
- const dt = now - lastTime;
26954
25223
  if (pos && lastPos) {
26955
25224
  const dx = pos.x - lastPos.x;
26956
25225
  const dy = pos.y - lastPos.y;
26957
- velocity = {
26958
- x: dx / dt,
26959
- y: dy / dt
26960
- };
26961
25226
  stage.x(stage.x() + dx);
26962
25227
  stage.y(stage.y() + dy);
26963
25228
  }
26964
25229
  lastPos = pos;
26965
- lastTime = now;
26966
25230
  this.instance.emitEvent("onStageMove");
26967
25231
  };
26968
25232
  stage.on("pointermove", handleMouseMove);
26969
- const decay = .95;
26970
- const animateInertia = () => {
26971
- velocity.x *= decay;
26972
- velocity.y *= decay;
26973
- if (Math.abs(velocity.x) < .01 && Math.abs(velocity.y) < .01) return;
26974
- stage.x(stage.x() + velocity.x);
26975
- stage.y(stage.y() + velocity.y);
26976
- this.instance.emitEvent("onStageMove");
26977
- requestAnimationFrame(animateInertia);
26978
- };
26979
25233
  stage.on("pointerup", (e) => {
26980
25234
  this.pointers.delete(e.evt.pointerId);
26981
- if (e.evt.pointerType !== "mouse" && this.pointers.size < 2) {
26982
- this.getNodesSelectionPlugin()?.enable();
26983
- isDragging = false;
26984
- startCenter = null;
26985
- startPointersDistance = null;
26986
- this.lastCenter = null;
26987
- this.pinching = false;
26988
- this.panning = false;
26989
- requestAnimationFrame(animateInertia);
26990
- return;
26991
- }
26992
25235
  isDragging = false;
26993
- this.pinching = false;
26994
25236
  this.panning = false;
26995
- requestAnimationFrame(animateInertia);
26996
25237
  });
26997
25238
  const handleWheel = (e) => {
26998
25239
  e.evt.preventDefault();