// Copyright 2026 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.
import { options } from 'preact';
import { RENDER_COMPONENT, ROOT } from '../../shared/render-constants.js';
import { hook, lynxQueueMicrotask } from '../../utils.js';
let installed = false;
let elementTemplateRendering = false;
let renderGeneration = 0;
export function isElementTemplateRendering() {
    return elementTemplateRendering;
}
export function clearElementTemplateRenderScope() {
    elementTemplateRendering = false;
    renderGeneration++;
}
export function resetElementTemplateRenderScope() {
    clearElementTemplateRenderScope();
}
export function installElementTemplateRenderScopeHooks() {
    if (installed) {
        return;
    }
    installed = true;
    hook(options, RENDER_COMPONENT, onPreactRenderHook);
    hook(options, ROOT, onPreactRenderHook);
}
function onPreactRenderHook(old, ...args) {
    old?.(...args);
    if (__BACKGROUND__) {
        markPreactRenderInProgress();
    }
}
function markPreactRenderInProgress() {
    elementTemplateRendering = true;
    const generation = ++renderGeneration;
    lynxQueueMicrotask(() => {
        if (generation === renderGeneration) {
            elementTemplateRendering = false;
        }
    });
}
//# sourceMappingURL=render-scope.js.map