@inditextech/weave-sdk 0.46.0 → 0.46.1

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
@@ -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
  }
@@ -16373,11 +16369,11 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16373
16369
  stage.on("pointerdown", (e) => {
16374
16370
  this.setTapStart(e);
16375
16371
  this.pointers[e.evt.pointerId] = e.evt;
16376
- if (!this.initialized) return;
16377
- if (!this.active) return;
16372
+ if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
16378
16373
  if (e.evt.pointerType === "mouse" && e.evt.button !== 0) return;
16379
16374
  if (e.evt.pointerType === "pen" && e.evt.pressure <= .05) return;
16380
- if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
16375
+ if (!this.initialized) return;
16376
+ if (!this.active) return;
16381
16377
  if (stage.mode() !== WEAVE_STAGE_DEFAULT_MODE) return;
16382
16378
  const selectedGroup = getTargetedNode(this.instance);
16383
16379
  if (selectedGroup?.getParent() instanceof konva.default.Transformer) {
@@ -16412,9 +16408,9 @@ var WeaveNodesSelectionPlugin = class extends WeavePlugin {
16412
16408
  const handleMouseMove = (e) => {
16413
16409
  const moved = this.checkMoved(e);
16414
16410
  if (e.evt.buttons === 0) return;
16411
+ if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
16415
16412
  if (!this.initialized) return;
16416
16413
  if (!this.active) return;
16417
- if (e.evt.pointerType === "touch" && Object.keys(this.pointers).length > 1) return;
16418
16414
  const contextMenuPlugin = this.getContextMenuPlugin();
16419
16415
  if (moved) contextMenuPlugin?.cancelLongPressTimer();
16420
16416
  else this.hideSelectorArea();
@@ -18826,7 +18822,7 @@ var WeaveRegisterManager = class {
18826
18822
 
18827
18823
  //#endregion
18828
18824
  //#region package.json
18829
- var version = "0.46.0";
18825
+ var version = "0.46.1";
18830
18826
 
18831
18827
  //#endregion
18832
18828
  //#region src/managers/setup.ts
@@ -22021,1672 +22017,6 @@ const WEAVE_STAGE_ZOOM_DEFAULT_CONFIG = {
22021
22017
  fitToSelection: { padding: 40 }
22022
22018
  };
22023
22019
 
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
22020
  //#endregion
23691
22021
  //#region src/plugins/stage-zoom/stage-zoom.ts
23692
22022
  var WeaveStageZoomPlugin = class extends WeavePlugin {
@@ -23697,19 +22027,12 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
23697
22027
  isTrackpad = false;
23698
22028
  zoomVelocity = 0;
23699
22029
  zoomInertiaType = WEAVE_STAGE_ZOOM_TYPE.MOUSE_WHEEL;
23700
- initialScale = 0;
23701
- lastTime = 0;
23702
- center = {
23703
- x: 0,
23704
- y: 0
23705
- };
23706
22030
  defaultStep = 3;
23707
22031
  constructor(params) {
23708
22032
  super();
23709
22033
  const { config } = params ?? {};
23710
22034
  this.config = (0, import_lodash.merge)(WEAVE_STAGE_ZOOM_DEFAULT_CONFIG, config);
23711
22035
  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
22036
  this.pinching = false;
23714
22037
  this.isTrackpad = false;
23715
22038
  this.isCtrlOrMetaPressed = false;
@@ -23950,6 +22273,15 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
23950
22273
  disable() {
23951
22274
  this.enabled = false;
23952
22275
  }
22276
+ getDistance(p1, p2) {
22277
+ return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
22278
+ }
22279
+ getCenter(p1, p2) {
22280
+ return {
22281
+ x: (p1.x + p2.x) / 2,
22282
+ y: (p1.y + p2.y) / 2
22283
+ };
22284
+ }
23953
22285
  initEvents() {
23954
22286
  window.addEventListener("keydown", (e) => {
23955
22287
  if (e.ctrlKey || e.metaKey) this.isCtrlOrMetaPressed = true;
@@ -23958,57 +22290,80 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
23958
22290
  if (!(e.ctrlKey || e.metaKey)) this.isCtrlOrMetaPressed = false;
23959
22291
  });
23960
22292
  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;
22293
+ let lastCenter = null;
22294
+ let lastDist = 0;
22295
+ stage.getContent().addEventListener("touchstart", (e) => {
22296
+ e.preventDefault();
22297
+ if (e.touches.length === 2) {
22298
+ e.preventDefault();
22299
+ e.stopPropagation();
22300
+ this.pinching = true;
22301
+ const touch1 = e.touches[0];
22302
+ const touch2 = e.touches[1];
22303
+ const p1 = {
22304
+ x: touch1.clientX,
22305
+ y: touch1.clientY
22306
+ };
22307
+ const p2 = {
22308
+ x: touch2.clientX,
22309
+ y: touch2.clientY
22310
+ };
22311
+ if (!lastCenter) {
22312
+ lastCenter = this.getCenter(p1, p2);
22313
+ return;
22314
+ }
23984
22315
  }
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;
22316
+ }, { passive: false });
22317
+ stage.getContent().addEventListener("touchmove", (e) => {
22318
+ e.preventDefault();
22319
+ if (e.touches.length === 2) {
22320
+ e.preventDefault();
22321
+ e.stopPropagation();
22322
+ this.getContextMenuPlugin()?.cancelLongPressTimer();
22323
+ const touch1 = e.touches[0];
22324
+ const touch2 = e.touches[1];
22325
+ const p1 = {
22326
+ x: touch1.clientX,
22327
+ y: touch1.clientY
22328
+ };
22329
+ const p2 = {
22330
+ x: touch2.clientX,
22331
+ y: touch2.clientY
22332
+ };
22333
+ if (!lastCenter) {
22334
+ lastCenter = this.getCenter(p1, p2);
22335
+ return;
22336
+ }
22337
+ const newCenter = this.getCenter(p1, p2);
22338
+ const dist = this.getDistance(p1, p2);
22339
+ if (!lastDist) lastDist = dist;
22340
+ const pointTo = {
22341
+ x: (newCenter.x - stage.x()) / stage.scaleX(),
22342
+ y: (newCenter.y - stage.y()) / stage.scaleX()
22343
+ };
22344
+ const newScale = Math.max(this.config.zoomSteps[0], Math.min(this.config.zoomSteps[this.config.zoomSteps.length - 1], stage.scaleX() * (dist / lastDist)));
22345
+ this.setZoom(newScale, false, newCenter);
22346
+ const dx = newCenter.x - lastCenter.x;
22347
+ const dy = newCenter.y - lastCenter.y;
22348
+ const newPos = {
22349
+ x: newCenter.x - pointTo.x * newScale + dx,
22350
+ y: newCenter.y - pointTo.y * newScale + dy
22351
+ };
22352
+ stage.position(newPos);
22353
+ lastDist = dist;
22354
+ lastCenter = newCenter;
23999
22355
  }
24000
- this.getNodesSelectionPlugin()?.enable();
22356
+ }, { passive: false });
22357
+ stage.getContent().addEventListener("touchend", () => {
24001
22358
  this.pinching = false;
24002
- this.zooming = true;
24003
- this.zoomInertiaType = WEAVE_STAGE_ZOOM_TYPE.PINCH_ZOOM;
24004
- requestAnimationFrame(this.zoomTick.bind(this));
24005
- });
22359
+ lastDist = 0;
22360
+ lastCenter = null;
22361
+ }, { passive: false });
24006
22362
  const handleWheel = (e) => {
24007
22363
  e.evt.preventDefault();
24008
22364
  const stage$1 = this.instance.getStage();
24009
22365
  const performZoom = this.isCtrlOrMetaPressed || !this.isCtrlOrMetaPressed && e.evt.ctrlKey && e.evt.deltaMode === 0;
24010
22366
  if (!this.enabled || !stage$1.isFocused() || !performZoom) return;
24011
- this.getNodesSelectionPlugin()?.disable();
24012
22367
  const delta = e.evt.deltaY > 0 ? 1 : -1;
24013
22368
  this.zoomVelocity += delta;
24014
22369
  this.isTrackpad = Math.abs(e.evt.deltaY) < 15 && e.evt.deltaMode === 0;
@@ -24035,13 +22390,12 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
24035
22390
  this.zooming = false;
24036
22391
  return;
24037
22392
  }
24038
- let pointer = this.center;
22393
+ let pointer = null;
24039
22394
  if (this.zoomInertiaType === WEAVE_STAGE_ZOOM_TYPE.MOUSE_WHEEL) {
24040
22395
  const stage = this.instance.getStage();
24041
22396
  pointer = stage.getPointerPosition();
24042
22397
  }
24043
22398
  if (!pointer) return;
24044
- this.getNodesSelectionPlugin()?.enable();
24045
22399
  this.setZoom(this.getInertiaScale(), false, pointer);
24046
22400
  this.zoomVelocity *= this.config.zoomInertia.friction;
24047
22401
  this.getStageGridPlugin()?.onRender();
@@ -24058,10 +22412,6 @@ var WeaveStageZoomPlugin = class extends WeavePlugin {
24058
22412
  const selectionPlugin = this.instance.getPlugin("nodesSelection");
24059
22413
  return selectionPlugin;
24060
22414
  }
24061
- getPanPlugin() {
24062
- const panPlugin = this.instance.getPlugin("stagePanning");
24063
- return panPlugin;
24064
- }
24065
22415
  getContextMenuPlugin() {
24066
22416
  const contextMenuPlugin = this.instance.getPlugin("contextMenu");
24067
22417
  return contextMenuPlugin;
@@ -26778,18 +25128,13 @@ const WEAVE_STAGE_PANNING_KEY = "stagePanning";
26778
25128
  //#endregion
26779
25129
  //#region src/plugins/stage-panning/stage-panning.ts
26780
25130
  var WeaveStagePanningPlugin = class extends WeavePlugin {
26781
- pinching = false;
26782
25131
  panning = false;
26783
25132
  getLayerName = void 0;
26784
25133
  initLayer = void 0;
26785
25134
  constructor() {
26786
25135
  super();
26787
25136
  this.pointers = new Map();
26788
- this.lastCenter = null;
26789
- this.pinching = false;
26790
25137
  this.panning = false;
26791
- this.threshold = 5;
26792
- this.pointersDistanceDiffThreshold = 10;
26793
25138
  this.enabled = true;
26794
25139
  this.moveToolActive = false;
26795
25140
  this.isMouseMiddleButtonPressed = false;
@@ -26833,20 +25178,14 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
26833
25178
  this.disableMove();
26834
25179
  }
26835
25180
  });
26836
- let startPointersDistance = null;
26837
- let startCenter = null;
26838
25181
  let lastPos = null;
26839
25182
  let isDragging = false;
26840
- let velocity = {
26841
- x: 0,
26842
- y: 0
26843
- };
26844
- let lastTime = 0;
26845
25183
  stage.on("pointerdown", (e) => {
26846
25184
  this.pointers.set(e.evt.pointerId, {
26847
25185
  x: e.evt.clientX,
26848
25186
  y: e.evt.clientY
26849
25187
  });
25188
+ if (this.pointers.size > 1) return;
26850
25189
  const activeAction = this.instance.getActiveAction();
26851
25190
  let enableMove = false;
26852
25191
  if (e && (e.evt.pointerType !== "mouse" || e.evt.pointerType === "mouse" && e.evt.buttons === 1) && activeAction === "moveTool") {
@@ -26857,142 +25196,40 @@ var WeaveStagePanningPlugin = class extends WeavePlugin {
26857
25196
  this.isMouseMiddleButtonPressed = true;
26858
25197
  enableMove = true;
26859
25198
  }
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
25199
  if (enableMove) {
26882
25200
  isDragging = true;
26883
25201
  lastPos = stage.getPointerPosition();
26884
- lastTime = performance.now();
26885
- velocity = {
26886
- x: 0,
26887
- y: 0
26888
- };
26889
25202
  this.enableMove();
26890
25203
  }
26891
25204
  });
26892
25205
  stage.on("pointercancel", (e) => {
26893
25206
  this.pointers.delete(e.evt.pointerId);
26894
25207
  lastPos = null;
26895
- this.lastCenter = null;
26896
25208
  });
26897
25209
  const handleMouseMove = (e) => {
26898
25210
  this.pointers.set(e.evt.pointerId, {
26899
25211
  x: e.evt.clientX,
26900
25212
  y: e.evt.clientY
26901
25213
  });
25214
+ if (this.pointers.size > 1) return;
26902
25215
  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
25216
  if (!this.enabled || !(this.isSpaceKeyPressed || this.isMouseMiddleButtonPressed || this.moveToolActive)) return;
26949
25217
  this.getContextMenuPlugin()?.cancelLongPressTimer();
26950
- this.getNodesSelectionPlugin()?.disable();
26951
25218
  const pos = stage.getPointerPosition();
26952
- const now = performance.now();
26953
- const dt = now - lastTime;
26954
25219
  if (pos && lastPos) {
26955
25220
  const dx = pos.x - lastPos.x;
26956
25221
  const dy = pos.y - lastPos.y;
26957
- velocity = {
26958
- x: dx / dt,
26959
- y: dy / dt
26960
- };
26961
25222
  stage.x(stage.x() + dx);
26962
25223
  stage.y(stage.y() + dy);
26963
25224
  }
26964
25225
  lastPos = pos;
26965
- lastTime = now;
26966
25226
  this.instance.emitEvent("onStageMove");
26967
25227
  };
26968
25228
  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
25229
  stage.on("pointerup", (e) => {
26980
25230
  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
25231
  isDragging = false;
26993
- this.pinching = false;
26994
25232
  this.panning = false;
26995
- requestAnimationFrame(animateInertia);
26996
25233
  });
26997
25234
  const handleWheel = (e) => {
26998
25235
  e.evt.preventDefault();