2026-05-14 17:12:01 +08:00
|
|
|
|
// src/index.js
|
|
|
|
|
|
export { NewState } from './observer.js';
|
|
|
|
|
|
export { Component } from './component.js';
|
2026-06-06 22:30:12 +08:00
|
|
|
|
export { $, $$, ____RefreshState_Internal_Force_Full_Scan_Only_In_Extreme_Performance_Scenarios, SetTranslator, _scanTree, _unbindTree } from './dom.js';
|
2026-05-14 17:12:01 +08:00
|
|
|
|
export { Util } from './utils.js';
|
2026-06-05 19:03:52 +08:00
|
|
|
|
export { Hash, LocalStorage, State } from './globals.js';
|
2026-05-14 17:12:01 +08:00
|
|
|
|
|
|
|
|
|
|
import { Component } from './component.js';
|
2026-06-06 22:30:12 +08:00
|
|
|
|
import { _scanTree, _unbindTree, $, $$, ____RefreshState_Internal_Force_Full_Scan_Only_In_Extreme_Performance_Scenarios, SetTranslator } from './dom.js';
|
2026-06-06 11:45:52 +08:00
|
|
|
|
import { LocalStorage, Hash, State } from './globals.js';
|
|
|
|
|
|
import { NewState, onNotifyUpdate, setActiveBinding } from './observer.js';
|
2026-06-05 19:03:52 +08:00
|
|
|
|
import { Util } from './utils.js';
|
2026-06-06 11:45:52 +08:00
|
|
|
|
import { _runCode, _returnCode } from './core.js';
|
2026-06-05 19:03:52 +08:00
|
|
|
|
|
|
|
|
|
|
const ApigoState = {
|
2026-06-06 22:30:12 +08:00
|
|
|
|
NewState, Component, $, $$, ____RefreshState_Internal_Force_Full_Scan_Only_In_Extreme_Performance_Scenarios, SetTranslator, _scanTree, _unbindTree, Util, Hash, LocalStorage, State,
|
2026-06-06 11:45:52 +08:00
|
|
|
|
_runCode, _returnCode, onNotifyUpdate, setActiveBinding
|
2026-06-05 19:03:52 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2026-06-06 11:45:52 +08:00
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
|
|
window.ApigoState = ApigoState;
|
2026-06-05 19:03:52 +08:00
|
|
|
|
}
|
2026-05-14 17:12:01 +08:00
|
|
|
|
|
|
|
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
|
|
const init = () => {
|
2026-06-06 22:30:12 +08:00
|
|
|
|
// 关键修复:在启动观察器和首次扫描前,务必将所有等待中的组件模板注入 DOM!
|
|
|
|
|
|
Component._initPending();
|
|
|
|
|
|
|
2026-06-06 11:45:52 +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'");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 灵魂逻辑:MutationObserver 捕获所有异步 DOM 变化
|
2026-05-14 17:12:01 +08:00
|
|
|
|
new MutationObserver(mutations => {
|
|
|
|
|
|
mutations.forEach(mutation => {
|
|
|
|
|
|
mutation.addedNodes.forEach(newNode => {
|
2026-06-06 11:45:52 +08:00
|
|
|
|
if (newNode.isConnected) _scanTree(newNode);
|
2026-05-14 17:12:01 +08:00
|
|
|
|
});
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|