UNPKG

1.92 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3function arrayMove(array, from, to) {
4 array = array.slice();
5 array.splice(to < 0 ? array.length + to : to, 0, array.splice(from, 1)[0]);
6 return array;
7}
8exports.arrayMove = arrayMove;
9function arrayRemove(array, index) {
10 array = array.slice();
11 array.splice(index, 1);
12 return array;
13}
14exports.arrayRemove = arrayRemove;
15function getTranslateOffset(element) {
16 var style = window.getComputedStyle(element);
17 return (Math.max(parseInt(style['margin-top'], 10), parseInt(style['margin-bottom'], 10)) + element.getBoundingClientRect().height);
18}
19exports.getTranslateOffset = getTranslateOffset;
20function transformItem(element, offsetY, offsetX) {
21 if (offsetY === void 0) { offsetY = 0; }
22 if (offsetX === void 0) { offsetX = 0; }
23 if (offsetY === null || offsetX === null) {
24 element.style.transform = null;
25 return;
26 }
27 element.style.transform = "translate3d(" + offsetX + "px, " + offsetY + "px, 0px)";
28}
29exports.transformItem = transformItem;
30function isItemTransformed(element) {
31 return !!element.style.transform;
32}
33exports.isItemTransformed = isItemTransformed;
34function setItemTransition(element, duration) {
35 element.style['transition-duration'] = duration + "ms";
36}
37exports.setItemTransition = setItemTransition;
38function binarySearch(array, targetValue) {
39 var min = 0;
40 var max = array.length - 1;
41 var guess;
42 while (min <= max) {
43 guess = Math.floor((max + min) / 2);
44 if (!array[guess + 1] ||
45 (array[guess] <= targetValue && array[guess + 1] >= targetValue)) {
46 return guess;
47 }
48 else if (array[guess] < targetValue && array[guess + 1] < targetValue) {
49 min = guess + 1;
50 }
51 else {
52 max = guess - 1;
53 }
54 }
55 return -1;
56}
57exports.binarySearch = binarySearch;