light-bounds
Advanced tools
Comparing version 0.0.6 to 0.0.7
export declare type LightBoundsTarget = HTMLElement; | ||
export declare type LightBoundsOnChange = (rect: LightBoundsBoundingRect) => void; | ||
export interface LightBoundsOptions { | ||
onChange: undefined | LightBoundsOnChange; | ||
throttleWait: false | number; | ||
} | ||
export interface LightBoundsBoundingRect { | ||
@@ -12,2 +16,2 @@ top: number; | ||
export declare function forceUpdate(): void; | ||
export declare function lightBounds(target: LightBoundsTarget, onChange?: LightBoundsOnChange): LightBoundsBoundingRect; | ||
export declare function lightBounds(target: LightBoundsTarget, { onChange, throttleWait }?: Partial<LightBoundsOptions>): LightBoundsBoundingRect; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var throttleit_1 = __importDefault(require("throttleit")); | ||
var watchedElements = new Map(); | ||
@@ -19,5 +23,6 @@ var lastResizeRefresh = 0; | ||
exports.forceUpdate = forceUpdate; | ||
function initializeWatcher() { | ||
//@TODO debounce resize | ||
window.addEventListener('resize', triggerHardUpdate, { passive: true }); | ||
function initializeWatcher(throttleWait) { | ||
window.addEventListener('resize', throttleWait | ||
? throttleit_1.default(triggerHardUpdate, throttleWait) | ||
: triggerHardUpdate, { passive: true }); | ||
window.addEventListener('scroll', triggerSoftUpdate, { passive: true }); | ||
@@ -62,5 +67,10 @@ } | ||
} | ||
function lightBounds(target, onChange) { | ||
function lightBounds(target, | ||
// @TODO: don't define throttleWait localy like here - this makes it hard to set it only once if you call lightBounds on multiple places | ||
_a) { | ||
var | ||
// @TODO: don't define throttleWait localy like here - this makes it hard to set it only once if you call lightBounds on multiple places | ||
_b = _a === void 0 ? {} : _a, _c = _b.onChange, onChange = _c === void 0 ? undefined : _c, _d = _b.throttleWait, throttleWait = _d === void 0 ? 200 : _d; | ||
if (watchedElements.size === 0) { | ||
initializeWatcher(); | ||
initializeWatcher(throttleWait); | ||
} | ||
@@ -67,0 +77,0 @@ if (!watchedElements.has(target)) { |
{ | ||
"name": "light-bounds", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Another getBoundingClientRect", | ||
@@ -35,3 +35,7 @@ "main": "dist/index.js", | ||
"arrowParens": "always" | ||
}, | ||
"dependencies": { | ||
"@types/throttleit": "^1.0.0", | ||
"throttleit": "^1.0.0" | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
import throttle from 'throttleit' | ||
export type LightBoundsTarget = HTMLElement | ||
@@ -5,2 +7,7 @@ | ||
export interface LightBoundsOptions { | ||
onChange: undefined | LightBoundsOnChange | ||
throttleWait: false | number | ||
} | ||
export interface LightBoundsBoundingRect { | ||
@@ -47,5 +54,10 @@ top: number | ||
function initializeWatcher() { | ||
//@TODO debounce resize | ||
window.addEventListener('resize', triggerHardUpdate, { passive: true }) | ||
function initializeWatcher(throttleWait: LightBoundsOptions['throttleWait']) { | ||
window.addEventListener( | ||
'resize', | ||
throttleWait | ||
? throttle(triggerHardUpdate, throttleWait) | ||
: triggerHardUpdate, | ||
{ passive: true } | ||
) | ||
window.addEventListener('scroll', triggerSoftUpdate, { passive: true }) | ||
@@ -104,6 +116,7 @@ } | ||
target: LightBoundsTarget, | ||
onChange?: LightBoundsOnChange | ||
// @TODO: don't define throttleWait localy like here - this makes it hard to set it only once if you call lightBounds on multiple places | ||
{ onChange = undefined, throttleWait = 200 }: Partial<LightBoundsOptions> = {} | ||
): LightBoundsBoundingRect { | ||
if (watchedElements.size === 0) { | ||
initializeWatcher() | ||
initializeWatcher(throttleWait) | ||
} | ||
@@ -110,0 +123,0 @@ |
9542
265
2
+ Added@types/throttleit@^1.0.0
+ Addedthrottleit@^1.0.0
+ Added@types/throttleit@1.0.2(transitive)
+ Addedthrottleit@1.0.1(transitive)