2026-05-14 17:12:01 +08:00
|
|
|
// src/index.js
|
|
|
|
|
export { NewState } from './observer.js';
|
|
|
|
|
export { Component } from './component.js';
|
|
|
|
|
export { $, $$, RefreshState, SetTranslator, _scanTree, _unbindTree } from './dom.js';
|
|
|
|
|
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
|
|
|
|
2026-06-05 19:03:52 +08:00
|
|
|
import { NewState } from './observer.js';
|
2026-05-14 17:12:01 +08:00
|
|
|
import { Component } from './component.js';
|
2026-06-05 19:03:52 +08:00
|
|
|
import { $, $$, RefreshState, SetTranslator } from './dom.js';
|
|
|
|
|
import { Util } from './utils.js';
|
|
|
|
|
import { Hash, LocalStorage, State } from './globals.js';
|
2026-05-14 17:12:01 +08:00
|
|
|
import { _scanTree, _unbindTree } from './dom.js';
|
2026-06-05 19:03:52 +08:00
|
|
|
|
|
|
|
|
const ApigoState = {
|
|
|
|
|
NewState, Component, $, $$, RefreshState, SetTranslator, Util, Hash, LocalStorage, State
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 挂载到全局,支持 UMD 直接访问
|
|
|
|
|
if (typeof globalThis !== 'undefined') {
|
|
|
|
|
Object.assign(globalThis, ApigoState);
|
|
|
|
|
globalThis.ApigoState = ApigoState;
|
|
|
|
|
}
|
2026-05-14 17:12:01 +08:00
|
|
|
|
|
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
|
const init = () => {
|
|
|
|
|
Component._initPending();
|
|
|
|
|
new MutationObserver(mutations => {
|
|
|
|
|
mutations.forEach(mutation => {
|
|
|
|
|
mutation.addedNodes.forEach(newNode => {
|
2026-06-05 19:16:52 +08:00
|
|
|
if (newNode.isConnected && newNode.nodeType === 1 && !newNode._stScanned) {
|
2026-06-05 20:07:18 +08:00
|
|
|
newNode._stScanned = true;
|
2026-06-05 19:16:52 +08:00
|
|
|
_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);
|
|
|
|
|
}
|