UNPKG

@juggle/resize-observer

Version:

Polyfills the ResizeObserver API and supports box size options from the latest spec

34 lines (33 loc) 1.35 kB
import { resizeObservers } from '../utils/resizeObservers'; import { ResizeObserverEntry } from '../ResizeObserverEntry'; import { calculateDepthForNode } from './calculateDepthForNode'; import { calculateBoxSize } from './calculateBoxSize'; var broadcastActiveObservations = function () { var shallowestDepth = Infinity; var callbacks = []; resizeObservers.forEach(function processObserver(ro) { if (ro.activeTargets.length === 0) { return; } var entries = []; ro.activeTargets.forEach(function processTarget(ot) { var entry = new ResizeObserverEntry(ot.target); var targetDepth = calculateDepthForNode(ot.target); entries.push(entry); ot.lastReportedSize = calculateBoxSize(ot.target, ot.observedBox); if (targetDepth < shallowestDepth) { shallowestDepth = targetDepth; } }); callbacks.push(function resizeObserverCallback() { ro.callback.call(ro.observer, entries, ro.observer); }); ro.activeTargets.splice(0, ro.activeTargets.length); }); for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) { var callback = callbacks_1[_i]; callback(); } return shallowestDepth; }; export { broadcastActiveObservations };