@interactjs/utils
Advanced tools
Comparing version 1.10.23 to 1.10.24
@@ -1,2 +0,2 @@ | ||
declare type Filter<T> = (element: T, index: number, array: T[]) => boolean; | ||
type Filter<T> = (element: T, index: number, array: T[]) => boolean; | ||
export declare const contains: <T>(array: T[], target: T) => boolean; | ||
@@ -3,0 +3,0 @@ export declare const remove: <T>(array: T[], target: T) => T[]; |
@@ -7,3 +7,2 @@ export const contains = (array, target) => array.indexOf(target) !== -1; | ||
} | ||
return target; | ||
@@ -18,3 +17,2 @@ }; | ||
} | ||
return -1; | ||
@@ -21,0 +19,0 @@ }; |
@@ -15,18 +15,22 @@ import domObjects from './domObjects'; | ||
}; | ||
function init(window) { | ||
const Element = domObjects.Element; | ||
const navigator = window.navigator || {}; // Does the browser support touch input? | ||
const navigator = window.navigator || {}; | ||
browser.supportsTouch = 'ontouchstart' in window || is.func(window.DocumentTouch) && domObjects.document instanceof window.DocumentTouch; // Does the browser support PointerEvents | ||
// Does the browser support touch input? | ||
browser.supportsTouch = 'ontouchstart' in window || is.func(window.DocumentTouch) && domObjects.document instanceof window.DocumentTouch; | ||
// Does the browser support PointerEvents | ||
// https://github.com/taye/interact.js/issues/703#issuecomment-471570492 | ||
browser.supportsPointerEvent = navigator.pointerEnabled !== false && !!domObjects.PointerEvent; | ||
browser.isIOS = /iP(hone|od|ad)/.test(navigator.platform); // scrolling doesn't change the result of getClientRects on iOS 7 | ||
browser.isIOS = /iP(hone|od|ad)/.test(navigator.platform); | ||
// scrolling doesn't change the result of getClientRects on iOS 7 | ||
browser.isIOS7 = /iP(hone|od|ad)/.test(navigator.platform) && /OS 7[^\d]/.test(navigator.appVersion); | ||
browser.isIe9 = /MSIE 9/.test(navigator.userAgent); // Opera Mobile must be handled differently | ||
browser.isIe9 = /MSIE 9/.test(navigator.userAgent); | ||
browser.isOperaMobile = navigator.appName === 'Opera' && browser.supportsTouch && /Presto/.test(navigator.userAgent); // prefix matchesSelector | ||
// Opera Mobile must be handled differently | ||
browser.isOperaMobile = navigator.appName === 'Opera' && browser.supportsTouch && /Presto/.test(navigator.userAgent); | ||
// prefix matchesSelector | ||
browser.prefixedMatchesSelector = 'matches' in Element.prototype ? 'matches' : 'webkitMatchesSelector' in Element.prototype ? 'webkitMatchesSelector' : 'mozMatchesSelector' in Element.prototype ? 'mozMatchesSelector' : 'oMatchesSelector' in Element.prototype ? 'oMatchesSelector' : 'msMatchesSelector'; | ||
@@ -47,8 +51,8 @@ browser.pEventTypes = browser.supportsPointerEvent ? domObjects.PointerEvent === window.MSPointerEvent ? { | ||
cancel: 'pointercancel' | ||
} : null; // because Webkit and Opera still use 'mousewheel' event type | ||
} : null; | ||
// because Webkit and Opera still use 'mousewheel' event type | ||
browser.wheelEvent = domObjects.document && 'onmousewheel' in domObjects.document ? 'mousewheel' : 'wheel'; | ||
} | ||
export default browser; | ||
//# sourceMappingURL=browser.js.map |
import * as arr from './arr'; | ||
import is from './is'; // tslint:disable-next-line ban-types | ||
import is from './is'; | ||
// tslint:disable-next-line ban-types | ||
export default function clone(source) { | ||
const dest = {}; | ||
for (const prop in source) { | ||
const value = source[prop]; | ||
if (is.plainObject(value)) { | ||
@@ -18,5 +17,4 @@ dest[prop] = clone(value); | ||
} | ||
return dest; | ||
} | ||
//# sourceMappingURL=clone.js.map |
@@ -14,7 +14,4 @@ const domObjects = { | ||
}; | ||
function blank() {} | ||
export default domObjects; | ||
function init(window) { | ||
@@ -21,0 +18,0 @@ const win = window; |
@@ -9,3 +9,2 @@ import browser from './browser'; | ||
} | ||
while (child) { | ||
@@ -15,6 +14,4 @@ if (child === parent) { | ||
} | ||
child = child.parentNode; | ||
} | ||
return false; | ||
@@ -27,6 +24,4 @@ } | ||
} | ||
element = parentNode(element); | ||
} | ||
return null; | ||
@@ -36,3 +31,2 @@ } | ||
let parent = node.parentNode; | ||
if (is.docFrag(parent)) { | ||
@@ -44,6 +38,4 @@ // skip past #shado-root fragments | ||
} | ||
return parent; | ||
} | ||
return parent; | ||
@@ -56,21 +48,18 @@ } | ||
} | ||
return element[browser.prefixedMatchesSelector](selector); | ||
} | ||
const getParent = el => el.parentNode || el.host; | ||
const getParent = el => el.parentNode || el.host; // Test for the element that's "above" all other qualifiers | ||
// Test for the element that's "above" all other qualifiers | ||
export function indexOfDeepestElement(elements) { | ||
let deepestNodeParents = []; | ||
let deepestNodeIndex; | ||
for (let i = 0; i < elements.length; i++) { | ||
const currentNode = elements[i]; | ||
const deepestNode = elements[deepestNodeIndex]; // node may appear in elements array multiple times | ||
const deepestNode = elements[deepestNodeIndex]; | ||
// node may appear in elements array multiple times | ||
if (!currentNode || i === deepestNodeIndex) { | ||
continue; | ||
} | ||
if (!deepestNode) { | ||
@@ -80,16 +69,17 @@ deepestNodeIndex = i; | ||
} | ||
const currentNodeParent = getParent(currentNode); | ||
const deepestNodeParent = getParent(deepestNode); | ||
const currentNodeParent = getParent(currentNode); | ||
const deepestNodeParent = getParent(deepestNode); // check if the deepest or current are document.documentElement/rootElement | ||
// check if the deepest or current are document.documentElement/rootElement | ||
// - if the current node is, do nothing and continue | ||
if (currentNodeParent === currentNode.ownerDocument) { | ||
continue; | ||
} // - if deepest is, update with the current node and continue to next | ||
} | ||
// - if deepest is, update with the current node and continue to next | ||
else if (deepestNodeParent === currentNode.ownerDocument) { | ||
deepestNodeIndex = i; | ||
continue; | ||
} // compare zIndex of siblings | ||
} | ||
// compare zIndex of siblings | ||
if (currentNodeParent === deepestNodeParent) { | ||
@@ -99,10 +89,10 @@ if (zIndexIsHigherThan(currentNode, deepestNode)) { | ||
} | ||
continue; | ||
} // populate the ancestry array for the latest deepest node | ||
} | ||
// populate the ancestry array for the latest deepest node | ||
deepestNodeParents = deepestNodeParents.length ? deepestNodeParents : getNodeParents(deepestNode); | ||
let ancestryStart; // if the deepest node is an HTMLElement and the current node is a non root svg element | ||
let ancestryStart; | ||
// if the deepest node is an HTMLElement and the current node is a non root svg element | ||
if (deepestNode instanceof domObjects.HTMLElement && currentNode instanceof domObjects.SVGElement && !(currentNode instanceof domObjects.SVGSVGElement)) { | ||
@@ -113,3 +103,2 @@ // TODO: is this check necessary? Was this for HTML elements embedded in SVG? | ||
} | ||
ancestryStart = currentNode.ownerSVGElement; | ||
@@ -119,15 +108,12 @@ } else { | ||
} | ||
const currentNodeParents = getNodeParents(ancestryStart, deepestNode.ownerDocument); | ||
let commonIndex = 0; // get (position of closest common ancestor) + 1 | ||
let commonIndex = 0; | ||
// get (position of closest common ancestor) + 1 | ||
while (currentNodeParents[commonIndex] && currentNodeParents[commonIndex] === deepestNodeParents[commonIndex]) { | ||
commonIndex++; | ||
} | ||
const parents = [currentNodeParents[commonIndex - 1], currentNodeParents[commonIndex], deepestNodeParents[commonIndex]]; | ||
if (parents[0]) { | ||
let child = parents[0].lastChild; | ||
while (child) { | ||
@@ -141,3 +127,2 @@ if (child === parents[1]) { | ||
} | ||
child = child.previousSibling; | ||
@@ -147,6 +132,4 @@ } | ||
} | ||
return deepestNodeIndex; | ||
} | ||
function getNodeParents(node, limit) { | ||
@@ -156,3 +139,2 @@ const parents = []; | ||
let parentParent; | ||
while ((parentParent = getParent(parent)) && parent !== limit && parentParent !== parent.ownerDocument) { | ||
@@ -162,6 +144,4 @@ parents.unshift(parent); | ||
} | ||
return parents; | ||
} | ||
function zIndexIsHigherThan(higherNode, lowerNode) { | ||
@@ -172,3 +152,2 @@ const higherIndex = parseInt(win.getWindow(higherNode).getComputedStyle(higherNode).zIndex, 10) || 0; | ||
} | ||
export function matchesUpTo(element, selector, limit) { | ||
@@ -179,5 +158,3 @@ while (is.element(element)) { | ||
} | ||
element = parentNode(element); | ||
if (element === limit) { | ||
@@ -187,3 +164,2 @@ return matchesSelector(element, selector); | ||
} | ||
return false; | ||
@@ -214,3 +190,2 @@ } | ||
const clientRect = getElementClientRect(element); | ||
if (!browser.isIOS7 && clientRect) { | ||
@@ -223,3 +198,2 @@ const scroll = getScrollXY(win.getWindow(element)); | ||
} | ||
return clientRect; | ||
@@ -229,3 +203,2 @@ } | ||
const path = []; | ||
while (node) { | ||
@@ -235,3 +208,2 @@ path.push(node); | ||
} | ||
return path; | ||
@@ -242,5 +214,5 @@ } | ||
return false; | ||
} // an exception will be raised if it is invalid | ||
} | ||
// an exception will be raised if it is invalid | ||
domObjects.document.querySelector(value); | ||
@@ -247,0 +219,0 @@ return true; |
@@ -6,3 +6,2 @@ export default function extend(dest, source) { | ||
} | ||
const ret = dest; | ||
@@ -9,0 +8,0 @@ return ret; |
13
is.js
import isWindow from './isWindow'; | ||
import * as win from './window'; | ||
const window = thing => thing === win.window || isWindow(thing); | ||
const docFrag = thing => object(thing) && thing.nodeType === 11; | ||
const object = thing => !!thing && typeof thing === 'object'; | ||
const func = thing => typeof thing === 'function'; | ||
const number = thing => typeof thing === 'number'; | ||
const bool = thing => typeof thing === 'boolean'; | ||
const string = thing => typeof thing === 'string'; | ||
const element = thing => { | ||
@@ -22,12 +14,7 @@ if (!thing || typeof thing !== 'object') { | ||
} | ||
const _window = win.getWindow(thing) || win.window; | ||
return /object|function/.test(typeof Element) ? thing instanceof Element || thing instanceof _window.Element : thing.nodeType === 1 && typeof thing.nodeName === 'string'; | ||
}; | ||
const plainObject = thing => object(thing) && !!thing.constructor && /function Object\b/.test(thing.constructor.toString()); | ||
const array = thing => object(thing) && typeof thing.length !== 'undefined' && func(thing.splice); | ||
export default { | ||
@@ -34,0 +21,0 @@ window, |
@@ -5,3 +5,2 @@ export default function isNonNativeEvent(type, actions) { | ||
} | ||
for (const name in actions.map) { | ||
@@ -12,5 +11,4 @@ if (type.indexOf(name) === 0 && type.substr(name.length) in actions.phases) { | ||
} | ||
return false; | ||
} | ||
//# sourceMappingURL=isNonNativeEvent.js.map |
@@ -10,3 +10,2 @@ import { window } from './window'; | ||
} | ||
return method.apply(this, arguments); | ||
@@ -13,0 +12,0 @@ }; |
import is from './is'; | ||
export default function normalize(type, listeners, filter = _typeOrPrefix => true, result) { | ||
result = result || {}; | ||
if (is.string(type) && type.search(' ') !== -1) { | ||
type = split(type); | ||
} | ||
if (is.array(type)) { | ||
type.forEach(t => normalize(t, listeners, filter, result)); | ||
return result; | ||
} // before: type = [{ drag: () => {} }], listeners = undefined | ||
} | ||
// before: type = [{ drag: () => {} }], listeners = undefined | ||
// after: type = '' , listeners = [{ drag: () => {} }] | ||
if (is.object(type)) { | ||
@@ -20,3 +18,2 @@ listeners = type; | ||
} | ||
if (is.func(listeners) && filter(type)) { | ||
@@ -35,6 +32,4 @@ result[type] = result[type] || []; | ||
} | ||
return result; | ||
} | ||
function split(type) { | ||
@@ -41,0 +36,0 @@ return type.trim().split(/ +/); |
{ | ||
"name": "@interactjs/utils", | ||
"version": "1.10.23", | ||
"version": "1.10.24", | ||
"type": "module", | ||
@@ -16,3 +16,3 @@ "repository": { | ||
"license": "MIT", | ||
"gitHead": "9ba48631" | ||
"gitHead": "86c64a3f" | ||
} |
const VENDOR_PREFIXES = ['webkit', 'moz']; | ||
export default function pointerExtend(dest, source) { | ||
dest.__set ||= {}; | ||
for (const prop in source) { | ||
// skip deprecated prefixed properties | ||
if (VENDOR_PREFIXES.some(prefix => prop.indexOf(prefix) === 0)) continue; | ||
if (typeof dest[prop] !== 'function' && prop !== '__set') { | ||
@@ -15,7 +13,5 @@ Object.defineProperty(dest, prop, { | ||
}, | ||
set(value) { | ||
dest.__set[prop] = value; | ||
}, | ||
configurable: true | ||
@@ -25,5 +21,4 @@ }); | ||
} | ||
return dest; | ||
} | ||
//# sourceMappingURL=pointerExtend.js.map |
@@ -39,4 +39,5 @@ import browser from './browser'; | ||
return pointer instanceof dom.Event || pointer instanceof dom.Touch; | ||
} // Get specified X/Y coords for mouse or event.touches[0] | ||
} | ||
// Get specified X/Y coords for mouse or event.touches[0] | ||
export function getXY(type, pointer, xy) { | ||
@@ -53,4 +54,5 @@ xy = xy || {}; | ||
y: 0 | ||
}; // Opera Mobile handles the viewport and scrolling oddly | ||
}; | ||
// Opera Mobile handles the viewport and scrolling oddly | ||
if (browser.isOperaMobile && isNativePointer(pointer)) { | ||
@@ -63,3 +65,2 @@ getXY('screen', pointer, page); | ||
} | ||
return page; | ||
@@ -69,3 +70,2 @@ } | ||
client = client || {}; | ||
if (browser.isOperaMobile && isNativePointer(pointer)) { | ||
@@ -77,3 +77,2 @@ // Opera Mobile handles the viewport and scrolling oddly | ||
} | ||
return client; | ||
@@ -91,8 +90,10 @@ } | ||
export function getTouchPair(event) { | ||
const touches = []; // array of touches is supplied | ||
const touches = []; | ||
// array of touches is supplied | ||
if (is.array(event)) { | ||
touches[0] = event[0]; | ||
touches[1] = event[1]; | ||
} // an event | ||
} | ||
// an event | ||
else { | ||
@@ -112,3 +113,2 @@ if (event.type === 'touchend') { | ||
} | ||
return touches; | ||
@@ -125,3 +125,2 @@ } | ||
}; | ||
for (const pointer of pointers) { | ||
@@ -132,7 +131,5 @@ for (const prop in average) { | ||
} | ||
for (const prop in average) { | ||
average[prop] /= pointers.length; | ||
} | ||
return average; | ||
@@ -144,3 +141,2 @@ } | ||
} | ||
const touches = getTouchPair(event); | ||
@@ -180,7 +176,9 @@ const minX = Math.min(touches[0].pageX, touches[1].pageX); | ||
export function getPointerType(pointer) { | ||
return is.string(pointer.pointerType) ? pointer.pointerType : is.number(pointer.pointerType) ? [undefined, undefined, 'touch', 'pen', 'mouse'][pointer.pointerType] : // if the PointerEvent API isn't available, then the "pointer" must | ||
return is.string(pointer.pointerType) ? pointer.pointerType : is.number(pointer.pointerType) ? [undefined, undefined, 'touch', 'pen', 'mouse'][pointer.pointerType] : | ||
// if the PointerEvent API isn't available, then the "pointer" must | ||
// be either a MouseEvent, TouchEvent, or Touch object | ||
/touch/.test(pointer.type || '') || pointer instanceof dom.Touch ? 'touch' : 'mouse'; | ||
} // [ event.target, event.currentTarget ] | ||
} | ||
// [ event.target, event.currentTarget ] | ||
export function getEventTargets(event) { | ||
@@ -206,53 +204,39 @@ const path = is.func(event.composedPath) ? event.composedPath() : event.path; | ||
coords, | ||
get page() { | ||
return this.coords.page; | ||
}, | ||
get client() { | ||
return this.coords.client; | ||
}, | ||
get timeStamp() { | ||
return this.coords.timeStamp; | ||
}, | ||
get pageX() { | ||
return this.coords.page.x; | ||
}, | ||
get pageY() { | ||
return this.coords.page.y; | ||
}, | ||
get clientX() { | ||
return this.coords.client.x; | ||
}, | ||
get clientY() { | ||
return this.coords.client.y; | ||
}, | ||
get pointerId() { | ||
return this.coords.pointerId; | ||
}, | ||
get target() { | ||
return this.coords.target; | ||
}, | ||
get type() { | ||
return this.coords.type; | ||
}, | ||
get pointerType() { | ||
return this.coords.pointerType; | ||
}, | ||
get buttons() { | ||
return this.coords.buttons; | ||
}, | ||
preventDefault() {} | ||
}; | ||
@@ -259,0 +243,0 @@ return event; |
let lastTime = 0; | ||
let request; | ||
let cancel; | ||
function init(global) { | ||
request = global.requestAnimationFrame; | ||
cancel = global.cancelAnimationFrame; | ||
if (!request) { | ||
const vendors = ['ms', 'moz', 'webkit', 'o']; | ||
for (const vendor of vendors) { | ||
@@ -17,6 +14,4 @@ request = global[`${vendor}RequestAnimationFrame`]; | ||
} | ||
request = request && request.bind(global); | ||
cancel = cancel && cancel.bind(global); | ||
if (!request) { | ||
@@ -33,7 +28,5 @@ request = callback => { | ||
}; | ||
cancel = token => clearTimeout(token); | ||
} | ||
} | ||
export default { | ||
@@ -40,0 +33,0 @@ request: callback => request(callback), |
11
rect.js
@@ -8,7 +8,5 @@ import { closest, getElementRect, parentNode } from './domUtils'; | ||
} | ||
if (value === 'self') { | ||
return target.getRect(element); | ||
} | ||
return closest(element, value); | ||
@@ -18,3 +16,2 @@ } | ||
let returnValue = value; | ||
if (is.string(returnValue)) { | ||
@@ -25,7 +22,5 @@ returnValue = getStringOptionResult(returnValue, target, element); | ||
} | ||
if (is.element(returnValue)) { | ||
returnValue = getElementRect(returnValue); | ||
} | ||
return returnValue; | ||
@@ -65,3 +60,2 @@ } | ||
} | ||
return rect; | ||
@@ -77,3 +71,2 @@ } | ||
} | ||
return rect; | ||
@@ -85,15 +78,11 @@ } | ||
} | ||
if (edges.right) { | ||
rect.right += delta.x; | ||
} | ||
if (edges.top) { | ||
rect.top += delta.y; | ||
} | ||
if (edges.bottom) { | ||
rect.bottom += delta.y; | ||
} | ||
rect.width = rect.right - rect.left; | ||
@@ -100,0 +89,0 @@ rect.height = rect.bottom - rect.top; |
@@ -5,13 +5,9 @@ export default function shallowEqual(left, right) { | ||
} | ||
if (!left || !right) { | ||
return false; | ||
} | ||
const leftKeys = Object.keys(left); | ||
if (leftKeys.length !== Object.keys(right).length) { | ||
return false; | ||
} | ||
for (const key of leftKeys) { | ||
@@ -22,5 +18,4 @@ if (left[key] !== right[key]) { | ||
} | ||
return true; | ||
} | ||
//# sourceMappingURL=shallowEqual.js.map |
@@ -7,6 +7,9 @@ import isWindow from './isWindow'; | ||
// get wrapped window if using Shadow DOM polyfill | ||
realWindow = window; // create a TextNode | ||
const el = window.document.createTextNode(''); // check if it's wrapped by a polyfill | ||
realWindow = window; | ||
// create a TextNode | ||
const el = window.document.createTextNode(''); | ||
// check if it's wrapped by a polyfill | ||
if (el.ownerDocument !== window.document && typeof window.wrap === 'function' && window.wrap(el) === el) { | ||
@@ -16,10 +19,7 @@ // use wrapped window | ||
} | ||
win = window; | ||
} | ||
if (typeof window !== 'undefined' && !!window) { | ||
init(window); | ||
} | ||
export function getWindow(node) { | ||
@@ -29,3 +29,2 @@ if (isWindow(node)) { | ||
} | ||
const rootNode = node.ownerDocument || node; | ||
@@ -32,0 +31,0 @@ return rootNode.defaultView || win.window; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
175690
1122