{"version":3,"sources":["../../../src/helpers/AreScheduler.helper.ts"],"names":[],"mappings":";;AAaO,MAAM,kBAAA,CAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB5B,OAAO,GAAA,GAAc;AACjB,IAAA,OAAQ,OAAO,WAAA,KAAgB,WAAA,IAAe,OAAO,WAAA,CAAY,GAAA,KAAQ,UAAA,GACnE,WAAA,CAAY,GAAA,EAAI,GAChB,IAAA,CAAK,GAAA,EAAI;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,kBAAkB,EAAA,EAAsB;AAC3C,IAAA,IAAI,OAAO,mBAAmB,WAAA,EAAa;AACvC,MAAA,UAAA,CAAW,IAAI,CAAC,CAAA;AAChB,MAAA;AAAA,IACJ;AAEA,IAAA,IAAI,CAAC,KAAK,QAAA,EAAU;AAChB,MAAA,IAAA,CAAK,QAAA,GAAW,IAAI,cAAA,EAAe;AACnC,MAAA,IAAA,CAAK,QAAA,CAAS,KAAA,CAAM,SAAA,GAAY,MAAM;AAClC,QAAA,MAAM,IAAA,GAAO,IAAA,CAAK,MAAA,CAAO,KAAA,EAAM;AAC/B,QAAA,IAAI,MAAM,IAAA,EAAK;AAAA,MACnB,CAAA;AAAA,IACJ;AAEA,IAAA,IAAA,CAAK,MAAA,CAAO,KAAK,EAAE,CAAA;AACnB,IAAA,IAAA,CAAK,QAAA,CAAS,KAAA,CAAM,WAAA,CAAY,IAAI,CAAA;AAAA,EACxC;AACJ;AAAA;AA/Ca,kBAAA,CAUe,SAA4B,EAAC","file":"AreScheduler.helper.mjs","sourcesContent":["/**\n * AreSchedulerHelper\n *\n * Cooperative time-slicing primitives shared by the chunked (async) render\n * paths — the initial whole-page mount walk and the `$for` directive. Both need\n * the SAME two capabilities:\n *   1. a high-resolution clock to measure how long the current chunk has run, and\n *   2. a zero-delay macrotask scheduler to yield to the browser between chunks\n *      so it can paint and process input before resuming work.\n *\n * Keeping these in one helper avoids duplicating the `MessageChannel` plumbing\n * across directives/lifecycle and gives a single place to tune the strategy.\n */\nexport class AreSchedulerHelper {\n\n    /**\n     * Lazily-created `MessageChannel` used to post zero-delay macrotasks.\n     * Created on first use so non-DOM environments (tests / SSR) that never\n     * schedule a chunk pay nothing.\n     */\n    private static _channel?: MessageChannel;\n\n    /** FIFO queue of callbacks waiting for their posted macrotask to fire. */\n    private static readonly _queue: Array<() => void> = [];\n\n    /**\n     * High-resolution wall-clock time in milliseconds. Uses `performance.now()`\n     * when available (monotonic, sub-millisecond), falling back to `Date.now()`.\n     */\n    static now(): number {\n        return (typeof performance !== 'undefined' && typeof performance.now === 'function')\n            ? performance.now()\n            : Date.now();\n    }\n\n    /**\n     * Schedule `fn` to run on the next macrotask.\n     *\n     * `MessageChannel` yields a true macrotask without the ~4ms clamp that nested\n     * `setTimeout(0)` calls incur, so the browser can paint between chunks with\n     * minimal scheduling overhead. Falls back to `setTimeout` in non-DOM\n     * environments (e.g. tests / SSR).\n     */\n    static scheduleMacrotask(fn: () => void): void {\n        if (typeof MessageChannel === 'undefined') {\n            setTimeout(fn, 0);\n            return;\n        }\n\n        if (!this._channel) {\n            this._channel = new MessageChannel();\n            this._channel.port1.onmessage = () => {\n                const next = this._queue.shift();\n                if (next) next();\n            };\n        }\n\n        this._queue.push(fn);\n        this._channel.port2.postMessage(null);\n    }\n}\n"]}