New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dji-dev/us-web-util

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dji-dev/us-web-util - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

.eslintrc.js

5

CHANGELOG.md

@@ -0,1 +1,6 @@

# 1.2.0
- Fix TypeScript errors for `invariant`.
- Add `scrollToBottom`, `scrollToTop`
# 1.1.0

@@ -2,0 +7,0 @@

@@ -21,3 +21,29 @@ import Cookies from 'js-cookie';

export declare function isScrolledToBottom(el: Element, threshold?: number): boolean;
interface ScrollOptions {
animated?: boolean;
duration?: number;
}
/**
* Scrolls element to top, optionally animated if { animated: true } is specified
* in {@param options}.
*
* If { animated: true } and no duration is provided in {@param options}, then 500ms
* will be used.
*
* @param el
* @param options
*/
export declare function scrollToTop(el: Element, { animated, duration }?: ScrollOptions): void;
/**
* Scrolls element to bottom, optionally animated if { animated: true } is specified
* in {@param options}.
*
* If { animated: true } and no duration is provided in {@param options}, then 500ms
* will be used.
*
* @param el
* @param options
*/
export declare function scrollToBottom(el: Element, { animated, duration }?: ScrollOptions): void;
/**
* Returns true if {@param el}'s scroll height is larger

@@ -24,0 +50,0 @@ * than the client height.

7

dist/index.d.ts

@@ -47,3 +47,8 @@ import debounce from 'lodash.debounce';

*/
export declare function invariant(condition: boolean, message: string): void;
interface Invariant {
(condition: false, message: string): never;
(condition: boolean, message: string): asserts condition;
}
declare const invariant: Invariant;
export { invariant };
/**

@@ -50,0 +55,0 @@ * Resolves the Promise after {@param duration}.

@@ -7,2 +7,481 @@ export { default as debounce } from 'lodash.debounce';

var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
function createCommonjsModule(fn, basedir, module) {
return module = {
path: basedir,
exports: {},
require: function (path, base) {
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
}
}, fn(module, module.exports), module.exports;
}
function commonjsRequire () {
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
}
var root;
// Browser window
if (typeof window !== 'undefined') {
root = window;
// Web Worker
} else if (typeof self !== 'undefined') {
root = self;
// Other environments
} else {
root = commonjsGlobal;
}
var root_1 = root;
var native_1 = createCommonjsModule(function (module, exports) {
var root = root_1;
// Test if we are within a foreign domain. Use raf from the top if possible.
try {
// Accessing .name will throw SecurityError within a foreign domain.
root.top.name;
root = root.top;
} catch(e) {}
exports.request = root.requestAnimationFrame;
exports.cancel = root.cancelAnimationFrame || root.cancelRequestAnimationFrame;
exports.supported = false;
var vendors = ['Webkit', 'Moz', 'ms', 'O'];
// Grab the native implementation.
for (var i = 0; i < vendors.length && !exports.request; i++) {
exports.request = root[vendors[i] + 'RequestAnimationFrame'];
exports.cancel = root[vendors[i] + 'CancelAnimationFrame'] ||
root[vendors[i] + 'CancelRequestAnimationFrame'];
}
// Test if native implementation works.
// There are some issues on ios6
// http://shitwebkitdoes.tumblr.com/post/47186945856/native-requestanimationframe-broken-on-ios-6
// https://gist.github.com/KrofDrakula/5318048
if (exports.request) {
exports.request.call(null, function() {
exports.supported = true;
});
}
});
/**
* Crossplatform Date.now()
*
* @return {Number} time in ms
* @api private
*/
var now = Date.now || function() {
return (new Date).getTime()
};
/**
* Replacement for PerformanceTiming.navigationStart for the case when
* performance.now is not implemented.
*
* https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming.navigationStart
*
* @type {Number}
* @api private
*/
var navigationStart = now();
var performanceTiming = {
navigationStart: navigationStart
};
/**
* Crossplatform performance.now()
*
* https://developer.mozilla.org/en-US/docs/Web/API/Performance.now()
*
* @return {Number} relative time in ms
* @api public
*/
var now_1 = function () {
if (root_1.performance && root_1.performance.now) return root_1.performance.now()
return now() - performanceTiming.navigationStart
};
var performance = {
now: now_1
};
// Weird native implementation doesn't work if context is defined.
var nativeRequest = native_1.request;
var nativeCancel = native_1.cancel;
/**
* Animation frame constructor.
*
* Options:
* - `useNative` use the native animation frame if possible, defaults to true
* - `frameRate` pass a custom frame rate
*
* @param {Object|Number} options
*/
function AnimationFrame(options) {
if (!(this instanceof AnimationFrame)) return new AnimationFrame(options)
options || (options = {});
// Its a frame rate.
if (typeof options == 'number') options = {frameRate: options};
options.useNative != null || (options.useNative = true);
this.options = options;
this.frameRate = options.frameRate || AnimationFrame.FRAME_RATE;
this._frameLength = 1000 / this.frameRate;
this._isCustomFrameRate = this.frameRate !== AnimationFrame.FRAME_RATE;
this._timeoutId = null;
this._callbacks = {};
this._lastTickTime = 0;
this._tickCounter = 0;
}
var animationFrame = AnimationFrame;
/**
* Default frame rate used for shim implementation. Native implementation
* will use the screen frame rate, but js have no way to detect it.
*
* If you know your target device, define it manually.
*
* @type {Number}
* @api public
*/
AnimationFrame.FRAME_RATE = 60;
/**
* Replace the globally defined implementation or define it globally.
*
* @param {Object|Number} [options]
* @api public
*/
AnimationFrame.shim = function(options) {
var animationFrame = new AnimationFrame(options);
root_1.requestAnimationFrame = function(callback) {
return animationFrame.request(callback)
};
root_1.cancelAnimationFrame = function(id) {
return animationFrame.cancel(id)
};
return animationFrame
};
/**
* Request animation frame.
* We will use the native RAF as soon as we know it does works.
*
* @param {Function} callback
* @return {Number} timeout id or requested animation frame id
* @api public
*/
AnimationFrame.prototype.request = function(callback) {
var self = this;
// Alawys inc counter to ensure it never has a conflict with the native counter.
// After the feature test phase we don't know exactly which implementation has been used.
// Therefore on #cancel we do it for both.
++this._tickCounter;
if (native_1.supported && this.options.useNative && !this._isCustomFrameRate) {
return nativeRequest(callback)
}
if (!callback) throw new TypeError('Not enough arguments')
if (this._timeoutId == null) {
// Much faster than Math.max
// http://jsperf.com/math-max-vs-comparison/3
// http://jsperf.com/date-now-vs-date-gettime/11
var delay = this._frameLength + this._lastTickTime - now();
if (delay < 0) delay = 0;
this._timeoutId = setTimeout(function() {
self._lastTickTime = now();
self._timeoutId = null;
++self._tickCounter;
var callbacks = self._callbacks;
self._callbacks = {};
for (var id in callbacks) {
if (callbacks[id]) {
if (native_1.supported && self.options.useNative) {
nativeRequest(callbacks[id]);
} else {
callbacks[id](performance.now());
}
}
}
}, delay);
}
this._callbacks[this._tickCounter] = callback;
return this._tickCounter
};
/**
* Cancel animation frame.
*
* @param {Number} timeout id or requested animation frame id
*
* @api public
*/
AnimationFrame.prototype.cancel = function(id) {
if (native_1.supported && this.options.useNative) nativeCancel(id);
delete this._callbacks[id];
};
/**
* An even better animation frame.
*
* @copyright Oleg Slobodskoi 2016
* @website https://github.com/kof/animationFrame
* @license MIT
*/
var animationFrame$1 = animationFrame;
var easings = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = {
linearTween: function linearTween(t, b, c, d) {
return c * t / d + b;
},
easeInQuad: function easeInQuad(t, b, c, d) {
t /= d;
return c * t * t + b;
},
easeOutQuad: function easeOutQuad(t, b, c, d) {
t /= d;
return -c * t * (t - 2) + b;
},
easeInOutQuad: function easeInOutQuad(t, b, c, d) {
t /= d / 2;
if (t < 1) return c / 2 * t * t + b;
t--;
return -c / 2 * (t * (t - 2) - 1) + b;
},
easeInCubic: function easeInCubic(t, b, c, d) {
t /= d;
return c * t * t * t + b;
},
easeOutCubic: function easeOutCubic(t, b, c, d) {
t /= d;
t--;
return c * (t * t * t + 1) + b;
},
easeInOutCubic: function easeInOutCubic(t, b, c, d) {
t /= d / 2;
if (t < 1) return c / 2 * t * t * t + b;
t -= 2;
return c / 2 * (t * t * t + 2) + b;
},
easeInQuart: function easeInQuart(t, b, c, d) {
t /= d;
return c * t * t * t * t + b;
},
easeOutQuart: function easeOutQuart(t, b, c, d) {
t /= d;
t--;
return -c * (t * t * t * t - 1) + b;
},
easeInOutQuart: function easeInOutQuart(t, b, c, d) {
t /= d / 2;
if (t < 1) return c / 2 * t * t * t * t + b;
t -= 2;
return -c / 2 * (t * t * t * t - 2) + b;
},
easeInQuint: function easeInQuint(t, b, c, d) {
t /= d;
return c * t * t * t * t * t + b;
},
easeOutQuint: function easeOutQuint(t, b, c, d) {
t /= d;
t--;
return c * (t * t * t * t * t + 1) + b;
},
easeInOutQuint: function easeInOutQuint(t, b, c, d) {
t /= d / 2;
if (t < 1) return c / 2 * t * t * t * t * t + b;
t -= 2;
return c / 2 * (t * t * t * t * t + 2) + b;
},
easeInSine: function easeInSine(t, b, c, d) {
return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
},
easeOutSine: function easeOutSine(t, b, c, d) {
return c * Math.sin(t / d * (Math.PI / 2)) + b;
},
easeInOutSine: function easeInOutSine(t, b, c, d) {
return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
},
easeInExpo: function easeInExpo(t, b, c, d) {
return c * Math.pow(2, 10 * (t / d - 1)) + b;
},
easeOutExpo: function easeOutExpo(t, b, c, d) {
return c * (-Math.pow(2, -10 * t / d) + 1) + b;
},
easeInOutExpo: function easeInOutExpo(t, b, c, d) {
t /= d / 2;
if (t < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
t--;
return c / 2 * (-Math.pow(2, -10 * t) + 2) + b;
},
easeInCirc: function easeInCirc(t, b, c, d) {
t /= d;
return -c * (Math.sqrt(1 - t * t) - 1) + b;
},
easeOutCirc: function easeOutCirc(t, b, c, d) {
t /= d;
t--;
return c * Math.sqrt(1 - t * t) + b;
},
easeInOutCirc: function easeInOutCirc(t, b, c, d) {
t /= d / 2;
if (t < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
t -= 2;
return c / 2 * (Math.sqrt(1 - t * t) + 1) + b;
}
};
});
var lib = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.rAF = undefined;
var _animationFrame2 = _interopRequireDefault(animationFrame$1);
var _easings2 = _interopRequireDefault(easings);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var packageInfo = {
name: 'scrollto-with-animation',
url: 'https://github.com/davesnx/scrollto-with-animation'
};
var rAF = new _animationFrame2.default();
var DEBUG = process.env.NODE_ENV || true;
var DEFAULT_ANIMATION = 'easeInQuad';
var LIB_NAME = '' + packageInfo.name;
var TRANSITION_NOT_FOUND = LIB_NAME + ': Transition not found - ' + packageInfo.url;
var ANIMATION_NOT_VALID = LIB_NAME + ': callback transition don\'t look like a valid equation - ' + packageInfo.url;
var TRANSITION_NOT_VALID = LIB_NAME + ': Transition isn\'t string or Function - ' + packageInfo.url;
var ANIMATION_CANCEL = 'animation-cancel';
var ANIMATION_END = 'animation-end';
var _document = typeof document !== 'undefined' ? document : {};
var _window = typeof window !== 'undefined' ? window : {};
var findAnimation = function findAnimation() {
var transition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_ANIMATION;
var animation = _easings2.default[transition];
if (animation === undefined && DEBUG) {
throw new Error(TRANSITION_NOT_FOUND);
}
return animation;
};
var defineAnimation = function defineAnimation(transition) {
if (transition.length !== 4 && DEBUG) {
throw new Error(ANIMATION_NOT_VALID);
}
return transition;
};
var scrollToWithAnimation = function scrollToWithAnimation(element) {
var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'scrollTop';
var to = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var duration = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 100;
var transition = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : DEFAULT_ANIMATION;
var callback = arguments[5];
var id = void 0;
var start = direction === 'scrollTop' ? element.scrollTop : element.scrollLeft;
var distance = to - start;
var animationStartTime = +new Date();
var isAnimating = true;
var lastScrolledPosition = void 0;
var transitionFunction = void 0;
if (!element) {
element = _document.documentElement;
}
if (typeof transition === 'string' || transition === null) {
transitionFunction = findAnimation(transition);
} else if (typeof transition === 'function') {
transitionFunction = defineAnimation(transition);
} else {
throw new Error(TRANSITION_NOT_VALID);
}
var animateScroll = function animateScroll() {
var now = +new Date();
var newScrollPosition = Math.floor(transitionFunction(now - animationStartTime, start, distance, duration));
if (!lastScrolledPosition || to !== element[direction]) {
lastScrolledPosition = newScrollPosition;
element[direction] = newScrollPosition;
} else {
isAnimating = false;
if (callback) {
callback(ANIMATION_CANCEL);
rAF.cancel(id);
}
}
if (now > animationStartTime + duration) {
element[direction] = to;
isAnimating = false;
if (callback) {
callback(ANIMATION_END);
rAF.cancel(id);
}
}
if (isAnimating) {
id = rAF.request(animateScroll);
}
};
id = rAF.request(animateScroll);
};
// Publish fn in window
if (_window !== {}) {
_window.scrollToWithAnimation = scrollToWithAnimation;
}
exports.default = scrollToWithAnimation;
exports.rAF = rAF;
});
var scrollToWithAnimation = /*@__PURE__*/getDefaultExportFromCjs(lib);
var MAXIMUM_AGE_MINUTES = 30;

@@ -64,3 +543,42 @@ var MINUTES_TO_SECONDS = 60;

}
var DEFAULT_SCROLL_DURATION = 500;
/**
* Scrolls element to top, optionally animated if { animated: true } is specified
* in {@param options}.
*
* If { animated: true } and no duration is provided in {@param options}, then 500ms
* will be used.
*
* @param el
* @param options
*/
function scrollToTop(el, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.animated, animated = _c === void 0 ? false : _c, _d = _b.duration, duration = _d === void 0 ? DEFAULT_SCROLL_DURATION : _d;
if (!animated) {
el.scrollTop = 0;
return;
}
// https://github.com/davesnx/scrollto-with-animation
scrollToWithAnimation(el, 'scrollTop', 0, duration, 'easeInOutCirc');
}
/**
* Scrolls element to bottom, optionally animated if { animated: true } is specified
* in {@param options}.
*
* If { animated: true } and no duration is provided in {@param options}, then 500ms
* will be used.
*
* @param el
* @param options
*/
function scrollToBottom(el, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.animated, animated = _c === void 0 ? false : _c, _d = _b.duration, duration = _d === void 0 ? DEFAULT_SCROLL_DURATION : _d;
if (!animated) {
el.scrollTop = el.scrollHeight;
return;
}
// https://github.com/davesnx/scrollto-with-animation
scrollToWithAnimation(el, 'scrollTop', el.scrollHeight, duration, 'easeInOutCirc');
}
/**
* Returns true if {@param el}'s scroll height is larger

@@ -174,6 +692,3 @@ * than the client height.

}
/**
* Simple implementation of the invariant pattern (used by Facebook).
*/
function invariant(condition, message) {
var invariant = (function (condition, message) {
if (!condition) {

@@ -187,3 +702,3 @@ if (__DEV__) {

}
}
});
/**

@@ -206,2 +721,2 @@ * Resolves the Promise after {@param duration}.

export { compareFunc, constrain, createSVGViewBox, getAllStyles, getIsJest, getRootHostname, hasScrollBar, injectScript, invariant, isMobileSafari, isScrolledToBottom, jsonClone, requestUserLocation, resolveIdleCallback, resolveTimeout, roundFixed };
export { compareFunc, constrain, createSVGViewBox, getAllStyles, getIsJest, getRootHostname, hasScrollBar, injectScript, invariant, isMobileSafari, isScrolledToBottom, jsonClone, requestUserLocation, resolveIdleCallback, resolveTimeout, roundFixed, scrollToBottom, scrollToTop };
import Cookies from 'js-cookie'
// @ts-ignore
import scrollToWithAnimation from 'scrollto-with-animation'

@@ -68,3 +70,56 @@ import { LngLat } from './types'

interface ScrollOptions {
animated?: boolean
duration?: number
}
const DEFAULT_SCROLL_DURATION = 500
/**
* Scrolls element to top, optionally animated if { animated: true } is specified
* in {@param options}.
*
* If { animated: true } and no duration is provided in {@param options}, then 500ms
* will be used.
*
* @param el
* @param options
*/
export function scrollToTop(
el: Element,
{ animated = false, duration = DEFAULT_SCROLL_DURATION }: ScrollOptions = {}
): void {
if (!animated) {
el.scrollTop = 0
return
}
// https://github.com/davesnx/scrollto-with-animation
scrollToWithAnimation(el, 'scrollTop', 0, duration, 'easeInOutCirc')
}
/**
* Scrolls element to bottom, optionally animated if { animated: true } is specified
* in {@param options}.
*
* If { animated: true } and no duration is provided in {@param options}, then 500ms
* will be used.
*
* @param el
* @param options
*/
export function scrollToBottom(
el: Element,
{ animated = false, duration = DEFAULT_SCROLL_DURATION }: ScrollOptions = {}
): void {
if (!animated) {
el.scrollTop = el.scrollHeight
return
}
// https://github.com/davesnx/scrollto-with-animation
scrollToWithAnimation(el, 'scrollTop', el.scrollHeight, duration, 'easeInOutCirc')
}
/**
* Returns true if {@param el}'s scroll height is larger

@@ -71,0 +126,0 @@ * than the client height.

@@ -96,3 +96,9 @@ import debounce from 'lodash.debounce'

*/
export function invariant(condition: boolean, message: string) {
interface Invariant {
(condition: false, message: string): never
(condition: boolean, message: string): asserts condition
}
const invariant: Invariant = ((condition: boolean, message: string) => {
if (!condition) {

@@ -105,4 +111,6 @@ if (__DEV__) {

}
}
}) as any
export { invariant }
/**

@@ -109,0 +117,0 @@ * Resolves the Promise after {@param duration}.

12

package.json
{
"name": "@dji-dev/us-web-util",
"version": "1.1.0",
"version": "1.2.0",
"main": "dist/index.js",
"license": "All rights reserved.",
"license": "MIT",
"module": "./dist/index.js",

@@ -28,3 +28,4 @@ "types": "./dist/index.d.ts",

"lodash.debounce": "^4.0.8",
"lodash.throttle": "^4.1.1"
"lodash.throttle": "^4.1.1",
"scrollto-with-animation": "^3.0.4"
},

@@ -34,3 +35,4 @@ "devDependencies": {

"@dji-dev/us-web-config": "1.0.0",
"@rollup/plugin-typescript": "^5.0.1",
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-typescript": "^6.1.0",
"@types/jest": "^26.0.13",

@@ -42,3 +44,3 @@ "@types/requestidlecallback": "^0.3.1",

"promise-any-polyfill": "^0.1.2",
"rollup": "^2.20.0",
"rollup": "^2.33.3",
"ts-jest": "^26.3.0",

@@ -45,0 +47,0 @@ "typescript": "^3.9.6"

import typescript from '@rollup/plugin-typescript'
import commonjs from '@rollup/plugin-commonjs'

@@ -9,3 +10,3 @@ export default {

},
plugins: [typescript()],
plugins: [commonjs(), typescript()],
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc