{"version":3,"sources":["utils.js","metal/window-proxy.js","metal/engine.js","metal/scheduler.js","metal/events.js","intersection-observer.js","spaniel-observer.js","watcher.js","index.js","metal/queue.js"],"names":["calculateIsIntersecting","_a","intersectionRect","width","height","getBoundingClientRect","element","e","number","top","bottom","left","right","x","y","calculateDuration","end","start","Math","round","invalidate","W","version","hasDomSetup","se","document","scrollingElement","getScrollTop","scrollTop","window","scrollY","getScrollLeft","scrollLeft","scrollX","setGlobalEngine","engine","globalEngine","getGlobalEngine","Engine","generateToken","tokenCounter","TOKEN_SEED","getGlobalScheduler","globalScheduler","Scheduler","getEventStore","eventStore","scroll","RAFEventRecord","frame","this","state","resize","destroy","GenericEventRecord","beforeunload","hide","show","on","eventName","callback","evt","listen","off","unlisten","trigger","value","scheduleWork","scheduleRead","marginToRect","margin","rootMarginToDOMMargin","rootMargin","c","split","map","n","parseInt","length","addRatio","entryInit","unixTime","highResTime","rootBounds","boundingClientRect","target","boundingArea","time","intersectionRatio","isIntersecting","pojoToToDOMRectReadOnly","pojo","emptyRect","generateEntry","clientRect","el","style","display","dateNow","intersectX","max","intersectY","min","interLeft","interTop","DOMMarginToRootMargin","d","onEntry","entries","forEach","entry","label","duration","opts","visibleTime","entering","payload","queryElement","elementSatisfiesRatio","ratio","__extends","extendStatics","b","Object","setPrototypeOf","__proto__","Array","p","prototype","hasOwnProperty","call","__","constructor","create","BaseQueue","items","remove","identifier","len","i","removePredicate","splice","clear","push","isEmpty","Queue","_super","apply","arguments","id","FunctionQueue","DOMQueue","nop","hasDOM","hasRAF","requestAnimationFrame","getHeight","getWidth","rAF","bind","meta","lastVersion","updateMeta","isDirty","undefined","IntersectionObserver","performance","innerHeight","innerWidth","readyState","addEventListener","reads","work","running","unshift","run","_this","rlen","pop","wlen","replace","r","random","toString","Frame","generate","root","rootMeta","revalidateRootMeta","Date","now","_clientRect","_rootMeta","BaseScheduler","customEngine","isTicking","toRemove","tick","queue","applyQueue","unwatch","unwatchAll","startTicking","watch","PredicatedScheduler","predicate","ElementScheduler","ALLOW_CACHED_SCHEDULER","defineProperty","get","enumerable","configurable","scheduler","cb","w","visibilityState","SpanielIntersectionObserver","options","records","threshold","rootMarginObj","isArray","thresholds","observe","trackedTarget","__spanielId","onTick","generateEntryEvent","numSatisfiedThresholds","record","unobserve","disconnect","takeRecords","count","SpanielObserver","paused","queuedEntries","recordStore","_b","BACKGROUND_TAB_FIX","USE_NATIVE_IO","convertedRootMargin","sort","t","o","usingNativeIo","observer","internalCallback","onTabHidden","_onTabHidden","onWindowClosed","_onWindowClosed","onTabShown","_onTabShown","setAllHidden","ids","keys","handleRecordExiting","flushQueuedEntries","generateObserverTimestamp","floor","lastSeenEntry","handleObserverEntry","generateSpanielEntry","timeOrigin","timing","navigationStart","Error","perfTime","thresholdStates","handleThresholdExiting","lastVisible","lastSatisfied","visible","lastEntry","spanielEntry","hasTimeThreshold","clearTimeout","timeoutId","ratioSatisfied","isSatisfied","timerId","Number","setTimeout","Watcher","config"],"mappings":"yLAAO,SAASA,GAAwBC,GACpC,GAAIC,GAAmBD,EAAGC,gBAC1B,OAAOA,GAAiBC,OAAS,GAAKD,EAAiBE,QAAU,EAE9D,QAASC,GAAsBC,GAClC,IACI,MAAOA,GAAQD,wBAEnB,MAAOE,GACH,GAAiB,gBAANA,IAAwB,OAANA,GAAsC,QAAZ,MAAXA,EAAEC,QAC1C,OAASC,IAAK,EAAGC,OAAQ,EAAGC,KAAM,EAAGR,MAAO,EAAGC,OAAQ,EAAGQ,MAAO,EAAGC,EAAG,EAAGC,EAAG,EAG7E,MAAMP,IAmBX,QAASQ,GAAkBC,EAAKC,GACnC,MAAOC,MAAKC,MAAMH,EAAMC,GCYrB,QAASG,OACVC,EAAEC,QAGR,QAASC,KACL,GAAIC,GAAkC,MAA7BC,SAASC,gBAClBL,GAAEM,aAAeH,EAAK,WAAc,MAAOC,UAASC,iBAAiBE,WAAe,WAAc,MAAOC,QAAOC,SAChHT,EAAEU,cAAgBP,EAAK,WAAc,MAAOC,U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zB,QAASA,GAAQC,OACE,KAAXA,IAAqBA,KACzB,IAAItM,GAAOsM,EAAOtM,KAAMgC,EAAQsK,EAAOtK,MAAO/C,EAAaqN,EAAOrN,WAAYkH,EAAOmG,EAAOnG,KAAMqB,EAAyB8E,EAAO9E,uBAAwBgC,EAAqB8C,EAAO9C,mBAAoBC,EAAgB6C,EAAO7C,cAC7NrB,IAEI5G,MAAO,UACPxB,KAAM,EACNgC,MAAO,GAGH,OAARhC,GACAoI,EAAU5E,MACNhC,MAAO,YACPxB,KAAMA,EACNgC,MAAOA,GAAS,IAGpBA,GACAoG,EAAU5E,MACNhC,MAAO,UACPxB,KAAM,EACNgC,MAAOA,IAGfrE,KAAKoM,SAAW,GAAIZ,GAAgB/H,GAChCnC,WAAYA,EACZmJ,UAAWA,EACXjC,KAAMA,EACNqB,uBAAwBA,EACxBgC,mBAAoBA,EACpBC,cAAeA,IAqBvB,MAlBA4C,GAAQ5J,UAAU2E,MAAQ,SAAU5G,EAAInC,GACpCV,KAAKoM,SAASvB,QAAQhI,GAClBnC,SAAUA,KAGlBgO,EAAQ5J,UAAUwE,QAAU,SAAUzG,GAClC7C,KAAKoM,SAAShB,UAAUvI,IAE5B6L,EAAQ5J,UAAUuG,WAAa,WAC3BrL,KAAKoM,SAASf,cAMlBqD,EAAQ5J,UAAU3E,QAAU,WACxBH,KAAKoM,SAASjM,WAEXuO,KC/DPvH,EAAyBiD,EAAEjD,qBACzBiD,EAAEjD,qBACFmD","file":"spaniel.js","sourcesContent":["export function calculateIsIntersecting(_a) {\n    var intersectionRect = _a.intersectionRect;\n    return intersectionRect.width >= 0 && intersectionRect.height >= 0;\n}\nexport function getBoundingClientRect(element) {\n    try {\n        return element.getBoundingClientRect();\n    }\n    catch (e) {\n        if (typeof e === 'object' && e !== null && (e.number & 0xffff) === 16389) {\n            return { top: 0, bottom: 0, left: 0, width: 0, height: 0, right: 0, x: 0, y: 0 };\n        }\n        else {\n            throw e;\n        }\n    }\n}\nexport function throttle(cb, thottleDelay, scope) {\n    if (thottleDelay === void 0) { thottleDelay = 5; }\n    if (scope === void 0) { scope = window; }\n    var cookie;\n    return function () {\n        scope.clearTimeout(cookie);\n        cookie = scope.setTimeout(cb, thottleDelay);\n    };\n}\n/**\n * Calculate duration from end/start timestamps, round to nearest integer\n *\n * @param end - end timestamp for calculating the duration\n * @param start - start timestamp for calculating the duration\n */\nexport function calculateDuration(end, start) {\n    return Math.round(end - start);\n}\n//# sourceMappingURL=utils.js.map","/*\nCopyright 2017 LinkedIn Corp. Licensed under the Apache License,\nVersion 2.0 (the \"License\"); you may not use this file except in\ncompliance with the License. You may obtain a copy of the License\nat http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n*/\nvar nop = function () { return 0; };\nvar hasDOM = !!(typeof window !== 'undefined' && window && typeof document !== 'undefined' && document);\nvar hasRAF = hasDOM && !!window.requestAnimationFrame;\nvar W = {\n    hasDOM: hasDOM,\n    hasRAF: hasRAF,\n    getScrollTop: nop,\n    getScrollLeft: nop,\n    getHeight: nop,\n    getWidth: nop,\n    rAF: hasRAF\n        ? window.requestAnimationFrame.bind(window)\n        : function (callback) {\n            callback();\n        },\n    meta: {\n        width: 0,\n        height: 0,\n        scrollTop: 0,\n        scrollLeft: 0,\n        x: 0,\n        y: 0,\n        top: 0,\n        left: 0\n    },\n    version: 0,\n    lastVersion: 0,\n    updateMeta: nop,\n    get isDirty() {\n        return W.version !== W.lastVersion;\n    },\n    document: hasDOM ? window.document : undefined,\n    IntersectionObserver: hasDOM && window.IntersectionObserver,\n    performance: hasDOM && window.performance\n};\nexport function invalidate() {\n    ++W.version;\n}\n// Init after DOM Content has loaded\nfunction hasDomSetup() {\n    var se = document.scrollingElement != null;\n    W.getScrollTop = se ? function () { return document.scrollingElement.scrollTop; } : function () { return window.scrollY; };\n    W.getScrollLeft = se ? function () { return document.scrollingElement.scrollLeft; } : function () { return window.scrollX; };\n}\nif (hasDOM) {\n    // Set the height and width immediately because they will be available at this point\n    W.getHeight = function () { return window.innerHeight; };\n    W.getWidth = function () { return window.innerWidth; };\n    W.updateMeta = function () {\n        W.meta.height = W.getHeight();\n        W.meta.width = W.getWidth();\n        W.meta.scrollLeft = W.getScrollLeft();\n        W.meta.scrollTop = W.getScrollTop();\n        W.lastVersion = W.version;\n    };\n    W.updateMeta();\n    if (document.readyState !== 'loading') {\n        hasDomSetup();\n    }\n    else {\n        document.addEventListener('DOMContentLoaded', hasDomSetup);\n    }\n    window.addEventListener('resize', invalidate, false);\n    window.addEventListener('scroll', invalidate, false);\n}\nexport default W;\n//# sourceMappingURL=window-proxy.js.map","/*\nCopyright 2017 LinkedIn Corp. Licensed under the Apache License,\nVersion 2.0 (the \"License\"); you may not use this file except in\ncompliance with the License. You may obtain a copy of the License\nat http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n*/\nimport W from './window-proxy';\nvar Engine = /** @class */ (function () {\n    function Engine() {\n        this.reads = [];\n        this.work = [];\n        this.running = false;\n    }\n    Engine.prototype.scheduleRead = function (callback) {\n        this.reads.unshift(callback);\n        this.run();\n    };\n    Engine.prototype.scheduleWork = function (callback) {\n        this.work.unshift(callback);\n        this.run();\n    };\n    Engine.prototype.run = function () {\n        var _this = this;\n        if (!this.running) {\n            this.running = true;\n            W.rAF(function () {\n                _this.running = false;\n                for (var i = 0, rlen = _this.reads.length; i < rlen; i++) {\n                    _this.reads.pop()();\n                }\n                for (var i = 0, wlen = _this.work.length; i < wlen; i++) {\n                    _this.work.pop()();\n                }\n                if (_this.work.length > 0 || _this.reads.length > 0) {\n                    _this.run();\n                }\n            });\n        }\n    };\n    return Engine;\n}());\nexport { Engine };\nvar globalEngine = null;\nexport function setGlobalEngine(engine) {\n    if (!!globalEngine) {\n        return false;\n    }\n    globalEngine = engine;\n    return true;\n}\nexport function getGlobalEngine() {\n    return globalEngine || (globalEngine = new Engine());\n}\n//# sourceMappingURL=engine.js.map","/*\nCopyright 2017 LinkedIn Corp. Licensed under the Apache License,\nVersion 2.0 (the \"License\"); you may not use this file except in\ncompliance with the License. You may obtain a copy of the License\nat http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n*/\nvar __extends = (this && this.__extends) || (function () {\n    var extendStatics = function (d, b) {\n        extendStatics = Object.setPrototypeOf ||\n            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n        return extendStatics(d, b);\n    };\n    return function (d, b) {\n        extendStatics(d, b);\n        function __() { this.constructor = d; }\n        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n    };\n})();\nimport W from './window-proxy';\nimport { default as Queue, DOMQueue } from './queue';\nimport { getGlobalEngine } from './engine';\nimport { getBoundingClientRect } from '../utils';\nvar TOKEN_SEED = 'xxxx'.replace(/[xy]/g, function (c) {\n    var r = (Math.random() * 16) | 0, v = c === 'x' ? r : (r & 0x3) | 0x8;\n    return v.toString(16);\n});\nvar tokenCounter = 0;\nvar Frame = /** @class */ (function () {\n    function Frame(dateNow, highResTime, scrollTop, scrollLeft, width, height, x, y, top, left) {\n        this.dateNow = dateNow;\n        this.highResTime = highResTime;\n        this.scrollTop = scrollTop;\n        this.scrollLeft = scrollLeft;\n        this.width = width;\n        this.height = height;\n        this.x = x;\n        this.y = y;\n        this.top = top;\n        this.left = left;\n    }\n    Frame.generate = function (root) {\n        if (root === void 0) { root = window; }\n        var rootMeta = this.revalidateRootMeta(root);\n        return new Frame(Date.now(), performance.now(), rootMeta.scrollTop, rootMeta.scrollLeft, rootMeta.width, rootMeta.height, rootMeta.x, rootMeta.y, rootMeta.top, rootMeta.left);\n    };\n    Frame.revalidateRootMeta = function (root) {\n        if (root === void 0) { root = document; }\n        var _clientRect = null;\n        var _rootMeta = {\n            width: 0,\n            height: 0,\n            scrollTop: 0,\n            scrollLeft: 0,\n            x: 0,\n            y: 0,\n            top: 0,\n            left: 0\n        };\n        // if root is dirty update the cached values\n        if (W.isDirty) {\n            W.updateMeta();\n        }\n        if (root === window || root === document) {\n            _rootMeta.height = W.meta.height;\n            _rootMeta.width = W.meta.width;\n            _rootMeta.scrollLeft = W.meta.scrollLeft;\n            _rootMeta.scrollTop = W.meta.scrollTop;\n            return _rootMeta;\n        }\n        _clientRect = getBoundingClientRect(root);\n        _rootMeta.scrollTop = root.scrollTop;\n        _rootMeta.scrollLeft = root.scrollLeft;\n        _rootMeta.width = _clientRect.width;\n        _rootMeta.height = _clientRect.height;\n        _rootMeta.x = _clientRect.x;\n        _rootMeta.y = _clientRect.y;\n        _rootMeta.top = _clientRect.top;\n        _rootMeta.left = _clientRect.left;\n        return _rootMeta;\n    };\n    return Frame;\n}());\nexport { Frame };\nexport function generateToken() {\n    return tokenCounter++ + TOKEN_SEED;\n}\nvar BaseScheduler = /** @class */ (function () {\n    function BaseScheduler(customEngine, root) {\n        this.isTicking = false;\n        this.toRemove = [];\n        if (customEngine) {\n            this.engine = customEngine;\n        }\n        else {\n            this.engine = getGlobalEngine();\n        }\n        this.root = root || window;\n    }\n    BaseScheduler.prototype.tick = function () {\n        if (this.queue.isEmpty()) {\n            this.isTicking = false;\n        }\n        else {\n            if (this.toRemove.length > 0) {\n                for (var i = 0; i < this.toRemove.length; i++) {\n                    this.queue.remove(this.toRemove[i]);\n                }\n                this.toRemove = [];\n            }\n            this.applyQueue(Frame.generate(this.root));\n            this.engine.scheduleRead(this.tick.bind(this));\n        }\n    };\n    BaseScheduler.prototype.scheduleWork = function (callback) {\n        this.engine.scheduleWork(callback);\n    };\n    BaseScheduler.prototype.scheduleRead = function (callback) {\n        this.engine.scheduleRead(callback);\n    };\n    BaseScheduler.prototype.queryElement = function (el, callback) {\n        var _this = this;\n        var clientRect;\n        var frame;\n        this.engine.scheduleRead(function () {\n            clientRect = getBoundingClientRect(el);\n            frame = Frame.generate(_this.root);\n        });\n        this.engine.scheduleWork(function () {\n            callback(clientRect, frame);\n        });\n    };\n    BaseScheduler.prototype.unwatch = function (id) {\n        this.toRemove.push(id);\n    };\n    BaseScheduler.prototype.unwatchAll = function () {\n        this.queue.clear();\n    };\n    BaseScheduler.prototype.startTicking = function () {\n        if (!this.isTicking) {\n            this.isTicking = true;\n            this.engine.scheduleRead(this.tick.bind(this));\n        }\n    };\n    return BaseScheduler;\n}());\nexport { BaseScheduler };\nvar Scheduler = /** @class */ (function (_super) {\n    __extends(Scheduler, _super);\n    function Scheduler() {\n        var _this = _super !== null && _super.apply(this, arguments) || this;\n        _this.queue = new Queue();\n        return _this;\n    }\n    Scheduler.prototype.applyQueue = function (frame) {\n        for (var i = 0; i < this.queue.items.length; i++) {\n            var _a = this.queue.items[i], id = _a.id, callback = _a.callback;\n            callback(frame, id);\n        }\n    };\n    Scheduler.prototype.watch = function (callback) {\n        this.startTicking();\n        var id = generateToken();\n        this.queue.push({\n            callback: callback,\n            id: id\n        });\n        return id;\n    };\n    return Scheduler;\n}(BaseScheduler));\nexport { Scheduler };\nvar PredicatedScheduler = /** @class */ (function (_super) {\n    __extends(PredicatedScheduler, _super);\n    function PredicatedScheduler(predicate) {\n        var _this = _super.call(this, undefined, window) || this;\n        _this.predicate = predicate;\n        return _this;\n    }\n    PredicatedScheduler.prototype.applyQueue = function (frame) {\n        if (this.predicate(frame)) {\n            _super.prototype.applyQueue.call(this, frame);\n        }\n    };\n    return PredicatedScheduler;\n}(Scheduler));\nexport { PredicatedScheduler };\nvar ElementScheduler = /** @class */ (function (_super) {\n    __extends(ElementScheduler, _super);\n    function ElementScheduler(customEngine, root, ALLOW_CACHED_SCHEDULER) {\n        if (ALLOW_CACHED_SCHEDULER === void 0) { ALLOW_CACHED_SCHEDULER = false; }\n        var _this = _super.call(this, customEngine, root) || this;\n        _this.lastVersion = W.version;\n        _this.queue = new DOMQueue();\n        _this.ALLOW_CACHED_SCHEDULER = ALLOW_CACHED_SCHEDULER;\n        return _this;\n    }\n    Object.defineProperty(ElementScheduler.prototype, \"isDirty\", {\n        get: function () {\n            return W.version !== this.lastVersion;\n        },\n        enumerable: false,\n        configurable: true\n    });\n    ElementScheduler.prototype.applyQueue = function (frame) {\n        for (var i = 0; i < this.queue.items.length; i++) {\n            var _a = this.queue.items[i], callback = _a.callback, el = _a.el, id = _a.id, clientRect = _a.clientRect;\n            if (this.isDirty || !clientRect || !this.ALLOW_CACHED_SCHEDULER) {\n                clientRect = this.queue.items[i].clientRect = getBoundingClientRect(el);\n            }\n            callback(frame, id, clientRect);\n        }\n        this.lastVersion = W.version;\n    };\n    ElementScheduler.prototype.watch = function (el, callback, id) {\n        this.startTicking();\n        id = id || generateToken();\n        var clientRect = null;\n        this.queue.push({\n            el: el,\n            callback: callback,\n            id: id,\n            clientRect: clientRect\n        });\n        return id;\n    };\n    return ElementScheduler;\n}(BaseScheduler));\nexport { ElementScheduler };\nvar globalScheduler = null;\nexport function getGlobalScheduler() {\n    return globalScheduler || (globalScheduler = new Scheduler());\n}\n//# sourceMappingURL=scheduler.js.map","/*\nCopyright 2017 LinkedIn Corp. Licensed under the Apache License,\nVersion 2.0 (the \"License\"); you may not use this file except in\ncompliance with the License. You may obtain a copy of the License\nat http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n*/\nimport { Frame, PredicatedScheduler, FunctionQueue, getGlobalScheduler } from './index';\nimport w from './window-proxy';\nvar GenericEventRecord = /** @class */ (function () {\n    function GenericEventRecord() {\n        this.queue = new FunctionQueue();\n    }\n    GenericEventRecord.prototype.listen = function (callback) {\n        this.queue.push(callback);\n    };\n    GenericEventRecord.prototype.unlisten = function (callback) {\n        this.queue.remove(callback);\n    };\n    GenericEventRecord.prototype.trigger = function (value) {\n        for (var i = 0; i < this.queue.items.length; i++) {\n            this.queue.items[i](value);\n        }\n    };\n    return GenericEventRecord;\n}());\nvar RAFEventRecord = /** @class */ (function () {\n    function RAFEventRecord(predicate) {\n        this.scheduler = new PredicatedScheduler(predicate.bind(this));\n    }\n    RAFEventRecord.prototype.trigger = function () { };\n    RAFEventRecord.prototype.listen = function (callback) {\n        this.state = Frame.generate();\n        this.scheduler.watch(callback);\n    };\n    RAFEventRecord.prototype.unlisten = function (cb) {\n        this.scheduler.unwatch(cb);\n    };\n    return RAFEventRecord;\n}());\nvar eventStore = null;\nfunction getEventStore() {\n    return (eventStore ||\n        (eventStore = {\n            scroll: new RAFEventRecord(function (frame) {\n                var _a = this.state, scrollTop = _a.scrollTop, scrollLeft = _a.scrollLeft;\n                this.state = frame;\n                return scrollTop !== frame.scrollTop || scrollLeft !== frame.scrollLeft;\n            }),\n            resize: new RAFEventRecord(function (frame) {\n                var _a = this.state, width = _a.width, height = _a.height;\n                this.state = frame;\n                return height !== frame.height || width !== frame.width;\n            }),\n            destroy: new GenericEventRecord(),\n            beforeunload: new GenericEventRecord(),\n            hide: new GenericEventRecord(),\n            show: new GenericEventRecord()\n        }));\n}\nif (w.hasDOM) {\n    window.addEventListener('beforeunload', function () {\n        // First fire internal event to fire any observer callbacks\n        trigger('beforeunload');\n        // Then fire external event to allow flushing of any beacons\n        trigger('destroy');\n    });\n    document.addEventListener('visibilitychange', function onVisibilityChange() {\n        if (document.visibilityState === 'visible') {\n            trigger('show');\n        }\n        else {\n            trigger('hide');\n        }\n    });\n}\nexport function on(eventName, callback) {\n    var evt = getEventStore()[eventName];\n    if (evt) {\n        evt.listen(callback);\n    }\n}\nexport function off(eventName, callback) {\n    if (eventStore) {\n        var evt = eventStore[eventName];\n        if (evt) {\n            evt.unlisten(callback);\n        }\n    }\n}\nexport function trigger(eventName, value) {\n    if (eventStore) {\n        var evt = eventStore[eventName];\n        if (evt) {\n            evt.trigger(value);\n        }\n    }\n}\n/**\n * Schedule a callback to be batched along with other DOM read/query work.\n * Use to schedule any DOM reads. Doing so will avoid DOM thrashing.\n */\nexport function scheduleWork(callback) {\n    getGlobalScheduler().scheduleWork(callback);\n}\n/**\n * Schedule a callback to be batched along with other DOM write/mutation\n * work. Use to schedule any DOM changes. Doing so will avoid DOM thrashing.\n */\nexport function scheduleRead(callback) {\n    getGlobalScheduler().scheduleRead(callback);\n}\n//# sourceMappingURL=events.js.map","/*\nCopyright 2017 LinkedIn Corp. Licensed under the Apache License,\nVersion 2.0 (the \"License\"); you may not use this file except in\ncompliance with the License. You may obtain a copy of the License\nat http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n*/\nimport { calculateIsIntersecting } from './utils';\nimport { ElementScheduler, generateToken } from './metal/index';\nfunction marginToRect(margin) {\n    var left = margin.left, right = margin.right, top = margin.top, bottom = margin.bottom;\n    return {\n        left: left,\n        x: left,\n        top: top,\n        y: top,\n        bottom: bottom,\n        right: right,\n        width: right - left,\n        height: bottom - top,\n    };\n}\nfunction rootMarginToDOMMargin(rootMargin) {\n    var c = rootMargin.split(' ').map(function (n) { return parseInt(n, 10); });\n    switch (c.length) {\n        case 2:\n            return { top: c[0], left: c[1], bottom: c[0], right: c[1] };\n        case 3:\n            return { top: c[0], left: c[1], bottom: c[2], right: c[1] };\n        case 4:\n            return { top: c[0], left: c[1], bottom: c[2], right: c[3] };\n        default:\n            return { top: 0, left: 0, bottom: 0, right: 0 };\n    }\n}\nvar SpanielIntersectionObserver = /** @class */ (function () {\n    function SpanielIntersectionObserver(callback, options) {\n        if (options === void 0) { options = {}; }\n        this.records = {};\n        this.callback = callback;\n        options.threshold = options.threshold || 0;\n        this.rootMarginObj = rootMarginToDOMMargin(options.rootMargin || '0px');\n        this.root = options.root || null;\n        if (Array.isArray(options.threshold)) {\n            this.thresholds = options.threshold;\n        }\n        else {\n            this.thresholds = [options.threshold];\n        }\n        this.scheduler = new ElementScheduler(undefined, this.root, options.ALLOW_CACHED_SCHEDULER);\n    }\n    SpanielIntersectionObserver.prototype.observe = function (target) {\n        var _this = this;\n        var trackedTarget = target;\n        var id = (trackedTarget.__spanielId = trackedTarget.__spanielId || generateToken());\n        this.scheduler.watch(target, function (frame, id, clientRect) {\n            _this.onTick(frame, id, clientRect, trackedTarget);\n        }, trackedTarget.__spanielId);\n        return id;\n    };\n    SpanielIntersectionObserver.prototype.onTick = function (frame, id, clientRect, el) {\n        var _this = this;\n        var _a = this.generateEntryEvent(frame, clientRect, el), numSatisfiedThresholds = _a.numSatisfiedThresholds, entry = _a.entry;\n        var record = this.records[id] ||\n            (this.records[id] = {\n                entry: entry,\n                numSatisfiedThresholds: 0\n            });\n        if (numSatisfiedThresholds !== record.numSatisfiedThresholds ||\n            entry.isIntersecting !== record.entry.isIntersecting) {\n            record.numSatisfiedThresholds = numSatisfiedThresholds;\n            record.entry = entry;\n            this.scheduler.scheduleWork(function () {\n                _this.callback([entry]);\n            });\n        }\n    };\n    SpanielIntersectionObserver.prototype.unobserve = function (target) {\n        this.scheduler.unwatch(target.__spanielId);\n        delete this.records[target.__spanielId];\n    };\n    SpanielIntersectionObserver.prototype.disconnect = function () {\n        this.scheduler.unwatchAll();\n        this.records = {};\n    };\n    SpanielIntersectionObserver.prototype.takeRecords = function () {\n        return [];\n    };\n    SpanielIntersectionObserver.prototype.generateEntryEvent = function (frame, clientRect, el) {\n        var count = 0;\n        var entry = generateEntry(frame, clientRect, el, this.rootMarginObj);\n        for (var i = 0; i < this.thresholds.length; i++) {\n            var threshold = this.thresholds[i];\n            if (entry.intersectionRatio >= threshold) {\n                count++;\n            }\n        }\n        return {\n            numSatisfiedThresholds: count,\n            entry: entry\n        };\n    };\n    return SpanielIntersectionObserver;\n}());\nexport { SpanielIntersectionObserver };\nfunction addRatio(entryInit) {\n    var unixTime = entryInit.unixTime, highResTime = entryInit.highResTime, rootBounds = entryInit.rootBounds, boundingClientRect = entryInit.boundingClientRect, intersectionRect = entryInit.intersectionRect, target = entryInit.target;\n    var boundingArea = boundingClientRect.height * boundingClientRect.width;\n    var intersectionRatio = boundingArea > 0 ? (intersectionRect.width * intersectionRect.height) / boundingArea : 0;\n    return {\n        time: unixTime,\n        highResTime: highResTime,\n        rootBounds: rootBounds,\n        boundingClientRect: boundingClientRect,\n        intersectionRect: intersectionRect,\n        target: target,\n        intersectionRatio: intersectionRatio,\n        isIntersecting: calculateIsIntersecting({ intersectionRect: intersectionRect })\n    };\n}\n// Casting to ignore that we are not returning toJSON property of DOMRectReadOnly\n// TODO: Either drop support for browser that do not support natively creating DOMRectReadOnly\n// or figure out way to performantly crate DOMReactReadOnly objects\nfunction pojoToToDOMRectReadOnly(pojo) {\n    return pojo;\n}\nfunction emptyRect() {\n    return pojoToToDOMRectReadOnly({\n        bottom: 0,\n        height: 0,\n        left: 0,\n        right: 0,\n        top: 0,\n        width: 0,\n        x: 0,\n        y: 0\n    });\n}\nexport function generateEntry(frame, clientRect, el, rootMargin) {\n    if (el.style.display === 'none') {\n        return {\n            time: frame.dateNow,\n            highResTime: frame.highResTime,\n            boundingClientRect: emptyRect(),\n            intersectionRatio: 0,\n            intersectionRect: emptyRect(),\n            isIntersecting: false,\n            rootBounds: emptyRect(),\n            target: el\n        };\n    }\n    var bottom = clientRect.bottom, right = clientRect.right;\n    var left = frame.left + rootMargin.left;\n    var top = frame.top + rootMargin.top;\n    var rootBounds = {\n        left: left,\n        top: top,\n        bottom: rootMargin.bottom,\n        right: rootMargin.right,\n        width: frame.width - (rootMargin.right + rootMargin.left),\n        height: frame.height - (rootMargin.bottom + rootMargin.top),\n        y: top,\n        x: left\n    };\n    var intersectX = Math.max(rootBounds.left, clientRect.left);\n    var intersectY = Math.max(rootBounds.top, clientRect.top);\n    var width = Math.min(rootBounds.left + rootBounds.width, clientRect.right) - intersectX;\n    var height = Math.min(rootBounds.top + rootBounds.height, clientRect.bottom) - intersectY;\n    var interLeft = width >= 0 ? intersectX : 0;\n    var interTop = intersectY >= 0 ? intersectY : 0;\n    var intersectionRect = {\n        left: interLeft,\n        top: interTop,\n        x: interLeft,\n        y: interTop,\n        width: width,\n        height: height,\n        right: right,\n        bottom: bottom\n    };\n    return addRatio({\n        unixTime: frame.dateNow,\n        highResTime: frame.highResTime,\n        rootBounds: rootBounds,\n        target: el,\n        boundingClientRect: pojoToToDOMRectReadOnly(marginToRect(clientRect)),\n        intersectionRect: pojoToToDOMRectReadOnly(intersectionRect)\n    });\n}\n//# sourceMappingURL=intersection-observer.js.map","/*\nCopyright 2017 LinkedIn Corp. Licensed under the Apache License,\nVersion 2.0 (the \"License\"); you may not use this file except in\ncompliance with the License. You may obtain a copy of the License\nat http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n*/\nimport { SpanielIntersectionObserver } from './intersection-observer';\nimport { generateToken, off, on, scheduleWork } from './metal/index';\nimport w from './metal/window-proxy';\nimport { calculateDuration, calculateIsIntersecting } from './utils';\nvar emptyRect = { x: 0, y: 0, width: 0, height: 0, bottom: 0, left: 0, top: 0, right: 0 };\nexport function DOMMarginToRootMargin(d) {\n    return d.top + \"px \" + d.right + \"px \" + d.bottom + \"px \" + d.left + \"px\";\n}\nvar SpanielObserver = /** @class */ (function () {\n    function SpanielObserver(callback, options) {\n        var _this = this;\n        var _a;\n        this.paused = false;\n        this.queuedEntries = [];\n        this.recordStore = {};\n        this.callback = callback;\n        var _b = options ||\n            {\n                threshold: []\n            }, root = _b.root, rootMargin = _b.rootMargin, threshold = _b.threshold, ALLOW_CACHED_SCHEDULER = _b.ALLOW_CACHED_SCHEDULER, BACKGROUND_TAB_FIX = _b.BACKGROUND_TAB_FIX, USE_NATIVE_IO = _b.USE_NATIVE_IO;\n        rootMargin = rootMargin || '0px';\n        var convertedRootMargin = typeof rootMargin !== 'string' ? DOMMarginToRootMargin(rootMargin) : rootMargin;\n        this.thresholds = threshold.sort(function (t) { return t.ratio; });\n        var o = {\n            root: root,\n            rootMargin: convertedRootMargin,\n            threshold: this.thresholds.map(function (t) { return t.ratio; }),\n            ALLOW_CACHED_SCHEDULER: ALLOW_CACHED_SCHEDULER\n        };\n        this.usingNativeIo = !!USE_NATIVE_IO && !!w.IntersectionObserver;\n        var IntersectionObserver = this.usingNativeIo ? w.IntersectionObserver : SpanielIntersectionObserver;\n        this.observer = new IntersectionObserver(function (records) { return _this.internalCallback(records); }, o);\n        this.onTabHidden = this._onTabHidden.bind(this);\n        this.onWindowClosed = this._onWindowClosed.bind(this);\n        this.onTabShown = this._onTabShown.bind(this);\n        if (w.hasDOM) {\n            on('beforeunload', this.onWindowClosed);\n            on('hide', this.onTabHidden);\n            on('show', this.onTabShown);\n            if (BACKGROUND_TAB_FIX) {\n                this.paused = ((_a = w.document) === null || _a === void 0 ? void 0 : _a.visibilityState) !== 'visible';\n            }\n        }\n    }\n    SpanielObserver.prototype._onWindowClosed = function () {\n        this.onTabHidden();\n    };\n    SpanielObserver.prototype.setAllHidden = function () {\n        var ids = Object.keys(this.recordStore);\n        for (var i = 0; i < ids.length; i++) {\n            this.handleRecordExiting(this.recordStore[ids[i]]);\n        }\n        this.flushQueuedEntries();\n    };\n    SpanielObserver.prototype._onTabHidden = function () {\n        this.paused = true;\n        this.setAllHidden();\n    };\n    // Generate a timestamp using the same relative origin time as the backing intersection observer\n    // native IO timestamps are relative to navigation start, whereas the spaniel polyfill uses unix\n    // timestamps, relative to 00:00:00 UTC on 1 January 1970\n    SpanielObserver.prototype.generateObserverTimestamp = function () {\n        return this.usingNativeIo ? Math.floor(performance.now()) : Date.now();\n    };\n    SpanielObserver.prototype._onTabShown = function () {\n        this.paused = false;\n        var ids = Object.keys(this.recordStore);\n        var highResTime = performance.now();\n        var time = this.generateObserverTimestamp();\n        for (var i = 0; i < ids.length; i++) {\n            var entry = this.recordStore[ids[i]].lastSeenEntry;\n            if (entry) {\n                var intersectionRatio = entry.intersectionRatio, boundingClientRect = entry.boundingClientRect, rootBounds = entry.rootBounds, intersectionRect = entry.intersectionRect, isIntersecting = entry.isIntersecting, target = entry.target;\n                this.handleObserverEntry({\n                    intersectionRatio: intersectionRatio,\n                    boundingClientRect: boundingClientRect,\n                    time: time,\n                    highResTime: highResTime,\n                    isIntersecting: isIntersecting,\n                    rootBounds: rootBounds,\n                    intersectionRect: intersectionRect,\n                    target: target\n                });\n            }\n        }\n    };\n    SpanielObserver.prototype.internalCallback = function (records) {\n        records.forEach(this.handleObserverEntry.bind(this));\n    };\n    SpanielObserver.prototype.flushQueuedEntries = function () {\n        if (this.queuedEntries.length > 0) {\n            this.callback(this.queuedEntries);\n            this.queuedEntries = [];\n        }\n    };\n    SpanielObserver.prototype.generateSpanielEntry = function (entry, state) {\n        var intersectionRatio = entry.intersectionRatio, rootBounds = entry.rootBounds, boundingClientRect = entry.boundingClientRect, intersectionRect = entry.intersectionRect, isIntersecting = entry.isIntersecting, time = entry.time, target = entry.target;\n        var record = this.recordStore[target.__spanielId];\n        var unixTime = this.usingNativeIo\n            ? Math.floor((w.performance.timeOrigin || w.performance.timing.navigationStart) + time)\n            : time;\n        var highResTime = this.usingNativeIo ? time : entry.highResTime;\n        if (!highResTime) {\n            throw new Error('Missing intersection entry timestamp');\n        }\n        return {\n            intersectionRatio: intersectionRatio,\n            isIntersecting: isIntersecting,\n            unixTime: unixTime,\n            time: unixTime,\n            highResTime: highResTime,\n            rootBounds: rootBounds,\n            boundingClientRect: boundingClientRect,\n            intersectionRect: intersectionRect,\n            target: target,\n            duration: 0,\n            visibleTime: isIntersecting ? unixTime : -1,\n            entering: false,\n            payload: record.payload,\n            label: state.threshold.label,\n            threshold: state.threshold\n        };\n    };\n    SpanielObserver.prototype.handleRecordExiting = function (record) {\n        var _this = this;\n        var time = Date.now();\n        var perfTime = performance.now();\n        record.thresholdStates.forEach(function (state) {\n            var boundingClientRect = record.lastSeenEntry && record.lastSeenEntry.boundingClientRect;\n            _this.handleThresholdExiting({\n                intersectionRatio: -1,\n                isIntersecting: false,\n                unixTime: time,\n                time: time,\n                highResTime: perfTime,\n                payload: record.payload,\n                label: state.threshold.label,\n                threshold: state.threshold,\n                entering: false,\n                rootBounds: emptyRect,\n                boundingClientRect: boundingClientRect || emptyRect,\n                intersectionRect: emptyRect,\n                visibleTime: state.lastVisible.unixTime,\n                // Next line (duration) is always overwritten if the record becomes a callback event\n                duration: calculateDuration(perfTime, state.lastVisible.highResTime),\n                target: record.target\n            }, state);\n            state.lastSatisfied = false;\n            state.visible = false;\n            state.lastEntry = null;\n        });\n    };\n    SpanielObserver.prototype.handleThresholdExiting = function (spanielEntry, state) {\n        var highResTime = spanielEntry.highResTime;\n        var hasTimeThreshold = !!state.threshold.time;\n        if (state.lastSatisfied && (!hasTimeThreshold || (hasTimeThreshold && state.visible))) {\n            spanielEntry.duration = calculateDuration(highResTime, state.lastVisible.highResTime);\n            spanielEntry.visibleTime = state.lastVisible.unixTime;\n            spanielEntry.entering = false;\n            state.visible = false;\n            this.queuedEntries.push(spanielEntry);\n        }\n        clearTimeout(state.timeoutId);\n    };\n    SpanielObserver.prototype.handleObserverEntry = function (entry) {\n        var _this = this;\n        var target = entry.target;\n        var record = this.recordStore[target.__spanielId];\n        if (record) {\n            record.lastSeenEntry = entry;\n            if (!this.paused) {\n                record.thresholdStates.forEach(function (state) {\n                    // Find the thresholds that were crossed. Since you can have multiple thresholds\n                    // for the same ratio, could be multiple thresholds\n                    var hasTimeThreshold = !!state.threshold.time;\n                    var spanielEntry = _this.generateSpanielEntry(entry, state);\n                    var ratioSatisfied = entry.intersectionRatio >= state.threshold.ratio;\n                    // The spaniel polyfill doesn't have isIntersecting, so only calculate if it doesn't exist, i.e. we aren't using\n                    // the native intersectionobserver\n                    var isIntersecting = typeof spanielEntry.isIntersecting === 'boolean'\n                        ? spanielEntry.isIntersecting\n                        : calculateIsIntersecting(entry);\n                    var isSatisfied = ratioSatisfied && isIntersecting;\n                    if (isSatisfied != state.lastSatisfied) {\n                        if (isSatisfied) {\n                            spanielEntry.entering = true;\n                            state.lastVisible = {\n                                highResTime: spanielEntry.highResTime,\n                                unixTime: spanielEntry.unixTime\n                            };\n                            if (hasTimeThreshold) {\n                                var timerId = Number(setTimeout(function () {\n                                    state.visible = true;\n                                    spanielEntry.duration = calculateDuration(performance.now(), state.lastVisible.highResTime);\n                                    spanielEntry.visibleTime = state.lastVisible.unixTime;\n                                    _this.callback([spanielEntry]);\n                                }, state.threshold.time));\n                                state.timeoutId = timerId;\n                            }\n                            else {\n                                state.visible = true;\n                                // TODO: Remove setting duration here, as it's irrelevant and should be very close to 0.\n                                // It doesn't make sense to calculate duration when the entry represents entering, not\n                                // exiting the viewport.\n                                spanielEntry.duration = Date.now() - state.lastVisible.unixTime;\n                                _this.queuedEntries.push(spanielEntry);\n                            }\n                        }\n                        else {\n                            _this.handleThresholdExiting(spanielEntry, state);\n                        }\n                        state.lastEntry = entry;\n                        state.lastSatisfied = isSatisfied;\n                    }\n                });\n                this.flushQueuedEntries();\n            }\n        }\n    };\n    SpanielObserver.prototype.disconnect = function () {\n        this.setAllHidden();\n        this.observer.disconnect();\n        this.recordStore = {};\n    };\n    /*\n     * Must be called when the SpanielObserver is done being used.\n     * This will prevent memory leaks.\n     */\n    SpanielObserver.prototype.destroy = function () {\n        this.disconnect();\n        if (w.hasDOM) {\n            off('beforeunload', this.onWindowClosed);\n            off('hide', this.onTabHidden);\n            off('show', this.onTabShown);\n        }\n    };\n    SpanielObserver.prototype.unobserve = function (element) {\n        var _this = this;\n        var record = this.recordStore[element.__spanielId];\n        if (record) {\n            delete this.recordStore[element.__spanielId];\n            this.observer.unobserve(element);\n            scheduleWork(function () {\n                _this.handleRecordExiting(record);\n                _this.flushQueuedEntries();\n            });\n        }\n    };\n    SpanielObserver.prototype.observe = function (target, payload) {\n        var trackedTarget = target;\n        var id = (trackedTarget.__spanielId = trackedTarget.__spanielId || generateToken());\n        this.recordStore[id] = {\n            target: trackedTarget,\n            payload: payload,\n            lastSeenEntry: null,\n            thresholdStates: this.thresholds.map(function (threshold) { return ({\n                lastSatisfied: false,\n                lastEntry: null,\n                threshold: threshold,\n                visible: false,\n                lastVisible: {\n                    unixTime: 0,\n                    highResTime: -1\n                }\n            }); })\n        };\n        this.observer.observe(trackedTarget);\n        return id;\n    };\n    return SpanielObserver;\n}());\nexport { SpanielObserver };\n//# sourceMappingURL=spaniel-observer.js.map","/*\nCopyright 2016 LinkedIn Corp. Licensed under the Apache License,\nVersion 2.0 (the \"License\"); you may not use this file except in\ncompliance with the License. You may obtain a copy of the License\nat http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n*/\nimport { SpanielObserver } from './spaniel-observer';\nfunction onEntry(entries) {\n    entries.forEach(function (entry) {\n        var label = entry.label, duration = entry.duration, boundingClientRect = entry.boundingClientRect, intersectionRect = entry.intersectionRect;\n        var opts = {\n            duration: duration,\n            boundingClientRect: boundingClientRect,\n            visibleTime: entry.visibleTime,\n            intersectionRect: intersectionRect\n        };\n        if (entry.entering) {\n            entry.payload.callback(label, opts);\n        }\n        else if (entry.label === 'impressed') {\n            entry.payload.callback('impression-complete', opts);\n        }\n    });\n}\nvar Watcher = /** @class */ (function () {\n    function Watcher(config) {\n        if (config === void 0) { config = {}; }\n        var time = config.time, ratio = config.ratio, rootMargin = config.rootMargin, root = config.root, ALLOW_CACHED_SCHEDULER = config.ALLOW_CACHED_SCHEDULER, BACKGROUND_TAB_FIX = config.BACKGROUND_TAB_FIX, USE_NATIVE_IO = config.USE_NATIVE_IO;\n        var threshold = [\n            {\n                label: 'exposed',\n                time: 0,\n                ratio: 0\n            }\n        ];\n        if (time != null) {\n            threshold.push({\n                label: 'impressed',\n                time: time,\n                ratio: ratio || 0\n            });\n        }\n        if (ratio) {\n            threshold.push({\n                label: 'visible',\n                time: 0,\n                ratio: ratio\n            });\n        }\n        this.observer = new SpanielObserver(onEntry, {\n            rootMargin: rootMargin,\n            threshold: threshold,\n            root: root,\n            ALLOW_CACHED_SCHEDULER: ALLOW_CACHED_SCHEDULER,\n            BACKGROUND_TAB_FIX: BACKGROUND_TAB_FIX,\n            USE_NATIVE_IO: USE_NATIVE_IO\n        });\n    }\n    Watcher.prototype.watch = function (el, callback) {\n        this.observer.observe(el, {\n            callback: callback\n        });\n    };\n    Watcher.prototype.unwatch = function (el) {\n        this.observer.unobserve(el);\n    };\n    Watcher.prototype.disconnect = function () {\n        this.observer.disconnect();\n    };\n    /*\n     * Must be called when the Watcher is done being used.\n     * This will prevent memory leaks.\n     */\n    Watcher.prototype.destroy = function () {\n        this.observer.destroy();\n    };\n    return Watcher;\n}());\nexport { Watcher };\n//# sourceMappingURL=watcher.js.map","/*\nCopyright 2017 LinkedIn Corp. Licensed under the Apache License,\nVersion 2.0 (the \"License\"); you may not use this file except in\ncompliance with the License. You may obtain a copy of the License\nat http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n*/\nimport { SpanielIntersectionObserver, generateEntry } from './intersection-observer';\nexport { Watcher } from './watcher';\nimport { SpanielObserver } from './spaniel-observer';\nimport { setGlobalEngine, getGlobalEngine } from './metal/engine';\nimport { getGlobalScheduler, on, off, scheduleWork, scheduleRead } from './metal/index';\nimport w from './metal/window-proxy';\nimport { invalidate } from './metal/window-proxy';\nvar IntersectionObserver = !!w.IntersectionObserver\n    ? w.IntersectionObserver\n    : SpanielIntersectionObserver;\nexport { on, off, scheduleRead, scheduleWork, IntersectionObserver, SpanielObserver, setGlobalEngine, getGlobalEngine, w as __w__, invalidate };\nexport function queryElement(el, callback) {\n    getGlobalScheduler().queryElement(el, callback);\n}\nexport function elementSatisfiesRatio(el, ratio, callback, rootMargin) {\n    if (ratio === void 0) { ratio = 0; }\n    if (rootMargin === void 0) { rootMargin = { top: 0, bottom: 0, left: 0, right: 0 }; }\n    queryElement(el, function (clientRect, frame) {\n        var entry = generateEntry(frame, clientRect, el, rootMargin);\n        callback(entry.isIntersecting && entry.intersectionRatio >= ratio);\n    });\n}\n//# sourceMappingURL=index.js.map","/*\nCopyright 2017 LinkedIn Corp. Licensed under the Apache License,\nVersion 2.0 (the \"License\"); you may not use this file except in\ncompliance with the License. You may obtain a copy of the License\nat http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n*/\nvar __extends = (this && this.__extends) || (function () {\n    var extendStatics = function (d, b) {\n        extendStatics = Object.setPrototypeOf ||\n            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\n        return extendStatics(d, b);\n    };\n    return function (d, b) {\n        extendStatics(d, b);\n        function __() { this.constructor = d; }\n        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n    };\n})();\nvar BaseQueue = /** @class */ (function () {\n    function BaseQueue() {\n        this.items = [];\n    }\n    BaseQueue.prototype.remove = function (identifier) {\n        var len = this.items.length;\n        for (var i = 0; i < len; i++) {\n            if (this.removePredicate(identifier, this.items[i])) {\n                this.items.splice(i, 1);\n                i--;\n                len--;\n            }\n        }\n    };\n    BaseQueue.prototype.clear = function () {\n        this.items = [];\n    };\n    BaseQueue.prototype.push = function (element) {\n        this.items.push(element);\n    };\n    BaseQueue.prototype.isEmpty = function () {\n        return this.items.length === 0;\n    };\n    return BaseQueue;\n}());\nexport { BaseQueue };\nvar Queue = /** @class */ (function (_super) {\n    __extends(Queue, _super);\n    function Queue() {\n        return _super !== null && _super.apply(this, arguments) || this;\n    }\n    Queue.prototype.removePredicate = function (identifier, element) {\n        if (typeof identifier === 'string') {\n            return element.id === identifier;\n        }\n        else {\n            return element.callback === identifier;\n        }\n    };\n    return Queue;\n}(BaseQueue));\nexport default Queue;\nvar FunctionQueue = /** @class */ (function (_super) {\n    __extends(FunctionQueue, _super);\n    function FunctionQueue() {\n        return _super !== null && _super.apply(this, arguments) || this;\n    }\n    FunctionQueue.prototype.removePredicate = function (identifier, element) {\n        return element === identifier;\n    };\n    return FunctionQueue;\n}(BaseQueue));\nexport { FunctionQueue };\nvar DOMQueue = /** @class */ (function (_super) {\n    __extends(DOMQueue, _super);\n    function DOMQueue() {\n        return _super !== null && _super.apply(this, arguments) || this;\n    }\n    DOMQueue.prototype.removePredicate = function (identifier, element) {\n        if (typeof identifier === 'string') {\n            return element.id === identifier;\n        }\n        else if (typeof identifier === 'function') {\n            return element.callback === identifier;\n        }\n        else {\n            return element.el === identifier;\n        }\n    };\n    return DOMQueue;\n}(BaseQueue));\nexport { DOMQueue };\n//# sourceMappingURL=queue.js.map"]}