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