state/src/index.js

43 lines
1.5 KiB
JavaScript
Raw Normal View History

import './utils.js';
import './observer.js';
import { _unbindTree, _scanTree } from './engine.js';
import './core.js';
2026-06-11 11:19:59 +08:00
/**
* Entry Point
* Orchestrates initialization and MutationObserver.
*/
2026-06-11 11:19:59 +08:00
if (typeof document !== 'undefined') {
const init = () => {
if (globalThis.Component && globalThis.Component._initPending) {
globalThis.Component._initPending();
}
2026-06-11 11:19:59 +08:00
const htmlNode = document.documentElement;
if (!htmlNode.hasAttribute('$data-bs-theme') && !htmlNode.hasAttribute('data-bs-theme')) {
htmlNode.setAttribute('$data-bs-theme', "LocalStorage.darkMode?'dark':'light'");
}
new MutationObserver(mutations => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(newNode => {
if (newNode.isConnected) _scanTree(newNode);
});
mutation.removedNodes.forEach(oldNode => _unbindTree(oldNode));
});
}).observe(document.documentElement, { childList: true, subtree: true });
_scanTree(document.documentElement);
};
if (document.readyState !== 'loading') init();
else document.addEventListener('DOMContentLoaded', init, true);
}
export { NewState, _setActiveBinding as setActiveBinding, _onNotifyUpdate as onNotifyUpdate } from './observer.js';
export { Component, SetTranslator } from './engine.js';
export { $, $$, Util } from './utils.js';
export { Hash, LocalStorage, State, _runCode, _returnCode } from './core.js';
export const __unsafeRefreshState = _scanTree;