soma-core 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/SomaPageClient.tsx +336 -0
- package/app/api/[...path]/route.ts +77 -0
- package/app/api/page/route.ts +18 -16
- package/app/api/soma-manifest/route.ts +39 -0
- package/app/components/SomaHydrationShell.tsx +23 -0
- package/app/layout.tsx +2 -2
- package/app/loading.tsx +5 -0
- package/app/page.tsx +19 -128
- package/bin/soma-lsp.cjs +195 -0
- package/bin/soma-sync.cjs +3 -0
- package/bin/soma.cjs +13 -1
- package/core/api/IService.ts +29 -0
- package/core/api/load-host-service.ts +72 -0
- package/core/api/service-path.ts +39 -0
- package/core/base/SomaEntity.ts +3 -10
- package/core/base/SomaLocaleOnlyPageRoot.ts +3 -4
- package/core/base/SomaPageRootBase.ts +20 -3
- package/core/base/decorators/Event.ts +23 -0
- package/core/base/decorators/Locale.ts +35 -0
- package/core/base/decorators/Page.ts +16 -0
- package/core/base/decorators/Show.ts +20 -0
- package/core/base/decorators/ShowList.ts +34 -0
- package/core/base/decorators/index.ts +5 -0
- package/core/base/index.ts +2 -0
- package/core/base/runAsync.ts +32 -0
- package/core/compiler/full-manifest-builder.ts +33 -7
- package/core/compiler/host-config-sync.cjs +38 -0
- package/core/compiler/manifest-compiler.ts +3 -2
- package/core/compiler/page-base-resolver.ts +23 -0
- package/core/compiler/precompiled-manifest-loader.ts +34 -0
- package/core/compiler/rollup-plugin-soma.ts +45 -0
- package/core/compiler/rspack-plugin-soma.js +33 -0
- package/core/compiler/soma-manifest-webpack-plugin.js +72 -0
- package/core/compiler/soma-precompile.js +3513 -0
- package/core/compiler/soma-precompile.ts +52 -6
- package/core/compiler/soma-rspack-yaml-loader.js +22 -0
- package/core/compiler/soma-webpack-loader.js +7 -1
- package/core/compiler/vite-plugin-soma.ts +11 -1
- package/core/container/IContainerAdapter.ts +36 -0
- package/core/container/MiniProgramContainerAdapter.ts +190 -0
- package/core/container/ReactNativeContainerAdapter.ts +189 -0
- package/core/container/SomaContainerAdapter.ts +17 -6
- package/core/diagnostics/SomaDiagnostics.ts +1 -1
- package/core/diagnostics/SomaTelemetry.ts +100 -0
- package/core/diagnostics/telemetry-context.ts +15 -0
- package/core/engine/asset-resolver.ts +39 -4
- package/core/engine/dom-renderer.ts +9 -11
- package/core/engine/event-engine.ts +110 -41
- package/core/engine/on-change-engine.ts +71 -0
- package/core/engine/property-watcher.ts +117 -0
- package/core/engine/reactive-proxy.ts +11 -5
- package/core/engine/render-engine.ts +97 -11
- package/core/engine/runtime-builder.ts +88 -11
- package/core/engine/scope-resolver.ts +65 -9
- package/core/engine/soma-bootstrap.ts +448 -244
- package/core/engine/style-binder.ts +423 -0
- package/core/engine/theme-variables.ts +37 -0
- package/core/engine/timer-engine.ts +92 -0
- package/core/engine/trigger-engine.ts +55 -0
- package/core/host/resolve-host-bootstrap.ts +28 -0
- package/core/host/soma-bootstrap-host.stub.ts +4 -0
- package/core/index.ts +40 -6
- package/core/infra/auth/TokenAuthService.ts +17 -3
- package/core/infra/http/IHttpClient.ts +11 -1
- package/core/infra/http/SomaHttpService.ts +89 -31
- package/core/infra/i18n/DefaultI18n.ts +6 -18
- package/core/infra/i18n/II18n.ts +2 -3
- package/core/infra/notify/DomNotifyService.ts +98 -0
- package/core/infra/notify/INotifyTheme.ts +22 -0
- package/core/infra/realtime/IRealtimeService.ts +23 -0
- package/core/infra/realtime/IRealtimeTransport.ts +9 -0
- package/core/infra/realtime/SomaRealtimeService.ts +95 -0
- package/core/infra/realtime/SseRealtimeTransport.ts +36 -0
- package/core/infra/realtime/WebSocketRealtimeTransport.ts +102 -0
- package/core/infra/router/router-path.ts +28 -0
- package/core/infra/storage/SessionStorageService.ts +59 -0
- package/core/lsp/cross-file-diagnostics.cjs +160 -0
- package/core/lsp/event-yaml-completion.cjs +106 -0
- package/core/lsp/extra-completion.cjs +64 -0
- package/core/lsp/lsp-navigation.cjs +191 -0
- package/core/lsp/ui-yaml-completion.cjs +170 -0
- package/core/manifest/manifest-contract.ts +12 -0
- package/core/middleware/createPermissionMiddleware.ts +37 -0
- package/core/parser/annotation-extractor.ts +113 -0
- package/core/parser/pipeline-parser.ts +344 -276
- package/core/parser/style-config-parser.ts +340 -0
- package/core/parser/timer-parser.ts +70 -0
- package/core/parser/trigger-parser.ts +90 -0
- package/core/parser/ui-config-parser.ts +73 -1
- package/core/quality/SomaQualityRegistry.ts +68 -0
- package/core/runtime/SomaRuntimeServices.ts +100 -0
- package/core/runtime/SomaSnapshotStore.ts +5 -3
- package/core/types/domain.types.ts +5 -2
- package/core/types/event.types.ts +82 -57
- package/core/types/manifest.types.ts +2 -0
- package/core/types/style-config.types.ts +76 -0
- package/core/types/timer.types.ts +23 -0
- package/core/types/trigger.types.ts +14 -0
- package/core/types/ui-config.types.ts +9 -0
- package/core/types/watcher.types.ts +29 -0
- package/core/validation/contract-validator.ts +465 -465
- package/dist/cli/soma.js +23 -23
- package/dist/core/index.cjs +8968 -0
- package/dist/diagnostics/telemetry.cjs +105 -0
- package/dist/preview-export.cjs +3401 -0
- package/dist/tsconfig.types.tsbuildinfo +1 -0
- package/dist/types/api/IService.d.ts +28 -0
- package/dist/types/api/load-host-service.d.ts +5 -0
- package/dist/types/api/service-path.d.ts +13 -0
- package/dist/types/base/SomaApi.d.ts +5 -0
- package/dist/types/base/SomaDict.d.ts +89 -0
- package/dist/types/base/SomaEntity.d.ts +15 -0
- package/dist/types/base/SomaHttpClient.d.ts +66 -0
- package/dist/types/base/SomaLocaleOnlyPageRoot.d.ts +3 -0
- package/dist/types/base/SomaPageRootBase.d.ts +49 -0
- package/dist/types/base/SomaValidator.d.ts +55 -0
- package/dist/types/base/decorators/Event.d.ts +10 -0
- package/dist/types/base/decorators/Locale.d.ts +9 -0
- package/dist/types/base/decorators/Page.d.ts +4 -0
- package/dist/types/base/decorators/Show.d.ts +7 -0
- package/dist/types/base/decorators/ShowList.d.ts +12 -0
- package/dist/types/base/decorators/index.d.ts +5 -0
- package/dist/types/base/index.d.ts +9 -0
- package/dist/types/base/runAsync.d.ts +12 -0
- package/dist/types/compiler/full-manifest-builder.d.ts +35 -0
- package/dist/types/compiler/manifest-compiler.d.ts +29 -0
- package/dist/types/compiler/page-base-resolver.d.ts +6 -0
- package/dist/types/compiler/precompiled-manifest-loader.d.ts +5 -0
- package/dist/types/compiler/rollup-plugin-soma.d.ts +14 -0
- package/dist/types/compiler/route-builder.d.ts +12 -0
- package/dist/types/compiler/soma-precompile.d.ts +40 -0
- package/dist/types/compiler/vite-plugin-soma.d.ts +34 -0
- package/dist/types/container/IContainerAdapter.d.ts +30 -0
- package/dist/types/container/MiniProgramContainerAdapter.d.ts +52 -0
- package/dist/types/container/ReactNativeContainerAdapter.d.ts +47 -0
- package/dist/types/container/SomaContainerAdapter.d.ts +30 -0
- package/dist/types/diagnostics/SomaDiagnostics.d.ts +64 -0
- package/dist/types/diagnostics/SomaTelemetry.d.ts +32 -0
- package/dist/types/diagnostics/telemetry-context.d.ts +4 -0
- package/dist/types/engine/asset-resolver.d.ts +17 -0
- package/dist/types/engine/dom-renderer.d.ts +35 -0
- package/dist/types/engine/event-engine.d.ts +64 -0
- package/dist/types/engine/lis.d.ts +10 -0
- package/dist/types/engine/on-change-engine.d.ts +16 -0
- package/dist/types/engine/property-watcher.d.ts +18 -0
- package/dist/types/engine/reactive-proxy.d.ts +58 -0
- package/dist/types/engine/render-engine.d.ts +73 -0
- package/dist/types/engine/runtime-builder.d.ts +58 -0
- package/dist/types/engine/scope-resolver.d.ts +90 -0
- package/dist/types/engine/soma-bootstrap.d.ts +112 -0
- package/dist/types/engine/style-binder.d.ts +81 -0
- package/dist/types/engine/theme-variables.d.ts +3 -0
- package/dist/types/engine/timer-engine.d.ts +19 -0
- package/dist/types/engine/trigger-engine.d.ts +16 -0
- package/dist/types/host/resolve-host-bootstrap.d.ts +11 -0
- package/dist/types/host/soma-bootstrap-host.stub.d.ts +3 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/infra/auth/IAuthService.d.ts +12 -0
- package/dist/types/infra/auth/TokenAuthService.d.ts +26 -0
- package/dist/types/infra/cache/ICache.d.ts +12 -0
- package/dist/types/infra/cache/MemoryCache.d.ts +14 -0
- package/dist/types/infra/cache/ServerFileCache.d.ts +37 -0
- package/dist/types/infra/config/IConfig.d.ts +9 -0
- package/dist/types/infra/config/SomaConfig.d.ts +21 -0
- package/dist/types/infra/event-bus/IEventBus.d.ts +8 -0
- package/dist/types/infra/event-bus/SomaEventBus.d.ts +9 -0
- package/dist/types/infra/http/IHttpClient.d.ts +28 -0
- package/dist/types/infra/http/SomaHttpService.d.ts +27 -0
- package/dist/types/infra/i18n/DefaultI18n.d.ts +7 -0
- package/dist/types/infra/i18n/II18n.d.ts +6 -0
- package/dist/types/infra/logger/ConsoleLogger.d.ts +14 -0
- package/dist/types/infra/logger/ILogger.d.ts +17 -0
- package/dist/types/infra/notify/DefaultNotifyService.d.ts +16 -0
- package/dist/types/infra/notify/DomNotifyService.d.ts +16 -0
- package/dist/types/infra/notify/INotifyService.d.ts +12 -0
- package/dist/types/infra/notify/INotifyTheme.d.ts +12 -0
- package/dist/types/infra/permission/IPermission.d.ts +10 -0
- package/dist/types/infra/permission/SomaPermission.d.ts +19 -0
- package/dist/types/infra/realtime/IRealtimeService.d.ts +13 -0
- package/dist/types/infra/realtime/IRealtimeTransport.d.ts +8 -0
- package/dist/types/infra/realtime/SomaRealtimeService.d.ts +20 -0
- package/dist/types/infra/realtime/SseRealtimeTransport.d.ts +11 -0
- package/dist/types/infra/realtime/WebSocketRealtimeTransport.d.ts +30 -0
- package/dist/types/infra/router/IRouter.d.ts +16 -0
- package/dist/types/infra/router/SomaRouter.d.ts +18 -0
- package/dist/types/infra/router/router-path.d.ts +6 -0
- package/dist/types/infra/storage/IStorageService.d.ts +7 -0
- package/dist/types/infra/storage/MemoryStorageService.d.ts +15 -0
- package/dist/types/infra/storage/SessionStorageService.d.ts +14 -0
- package/dist/types/infra/timer/ITimer.d.ts +13 -0
- package/dist/types/infra/timer/SomaTimer.d.ts +21 -0
- package/dist/types/manifest/manifest-contract.d.ts +4 -0
- package/dist/types/middleware/SomaMiddlewareChain.d.ts +6 -0
- package/dist/types/middleware/createPermissionMiddleware.d.ts +14 -0
- package/dist/types/parser/annotation-extractor.d.ts +12 -0
- package/dist/types/parser/pipeline-parser.d.ts +62 -0
- package/dist/types/parser/style-config-parser.d.ts +20 -0
- package/dist/types/parser/timer-parser.d.ts +6 -0
- package/dist/types/parser/trigger-parser.d.ts +13 -0
- package/dist/types/parser/ui-config-parser.d.ts +34 -0
- package/dist/types/parser/yaml-loader.d.ts +21 -0
- package/dist/types/quality/SomaQualityRegistry.d.ts +31 -0
- package/dist/types/runtime/SomaRuntimeServices.d.ts +35 -0
- package/dist/types/runtime/SomaSnapshotStore.d.ts +13 -0
- package/dist/types/scheduler/SomaScheduler.d.ts +25 -0
- package/dist/types/types/domain.types.d.ts +82 -0
- package/dist/types/types/engine.types.d.ts +22 -0
- package/dist/types/types/event.types.d.ts +61 -0
- package/dist/types/types/keyboard.types.d.ts +4 -0
- package/dist/types/types/manifest.types.d.ts +29 -0
- package/dist/types/types/scheduler.types.d.ts +8 -0
- package/dist/types/types/style-config.types.d.ts +62 -0
- package/dist/types/types/timer.types.d.ts +19 -0
- package/dist/types/types/trigger.types.d.ts +12 -0
- package/dist/types/types/ui-config.types.d.ts +85 -0
- package/dist/types/types/watcher.types.d.ts +24 -0
- package/dist/types/validation/contract-validator.d.ts +40 -0
- package/editor/vscode/extension.js +39 -0
- package/editor/vscode/language-configuration.json +17 -0
- package/editor/vscode/package.json +98 -0
- package/editor/vscode/syntaxes/soma-event-yaml.tmLanguage.json +30 -0
- package/editor/vscode/syntaxes/soma-ui-yaml.tmLanguage.json +42 -0
- package/global.d.ts +19 -0
- package/next.config.js +9 -4
- package/package.json +53 -16
- package/tailwind.config.ts +26 -7
- package/tsconfig.json +6 -2
- package/core/router/RouteHandler.ts +0 -93
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
2
|
+
import type { SomaCompiledBinding } from '../types/manifest.types';
|
|
3
|
+
import type { BindingEntry } from '../types/engine.types';
|
|
4
|
+
import type { SomaScopeResolver } from './scope-resolver';
|
|
5
|
+
export type ModelWriteBack = (path: string, value: string) => void;
|
|
6
|
+
export declare class SomaDomRenderer {
|
|
7
|
+
private adapter;
|
|
8
|
+
private resolver;
|
|
9
|
+
private scopeTracker;
|
|
10
|
+
private modelWriteBack;
|
|
11
|
+
private modelListeners;
|
|
12
|
+
private modelAbort;
|
|
13
|
+
init(adapter: IContainerAdapter, resolver: SomaScopeResolver, scopeTracker: WeakMap<HTMLElement, any>): void;
|
|
14
|
+
setModelWriteBack(fn: ModelWriteBack): void;
|
|
15
|
+
bindEntry(binding: SomaCompiledBinding, container: HTMLElement): BindingEntry | null;
|
|
16
|
+
/**
|
|
17
|
+
* 为 binding 编译专用的渲染闭包。
|
|
18
|
+
*
|
|
19
|
+
* 类似 C++ 编译器将 switch/case 消除为直接函数指针调用:
|
|
20
|
+
* - text 绑定编译为 (v) => el.textContent = String(v)
|
|
21
|
+
* - attr 绑定编译为 (v) => el.setAttribute('src', String(v))
|
|
22
|
+
* - when 绑定编译为 (v) => el.style.display = v ? '' : 'none'
|
|
23
|
+
*
|
|
24
|
+
* 运行时路径:compiledRender(value) → 1 次函数调用 → 1 次 DOM 操作
|
|
25
|
+
* 之前路径:renderEntry(entry, value) → switch 7 分支 → 类型判断 → DOM 操作
|
|
26
|
+
*/
|
|
27
|
+
private compileRenderFn;
|
|
28
|
+
destroy(): void;
|
|
29
|
+
renderEntry(entry: BindingEntry, value: any): void;
|
|
30
|
+
private renderList;
|
|
31
|
+
private appendListItem;
|
|
32
|
+
private renderObj;
|
|
33
|
+
private applyShowConfig;
|
|
34
|
+
private resolveShowValue;
|
|
35
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
2
|
+
import type { SomaDiagnostics } from '../diagnostics/SomaDiagnostics';
|
|
3
|
+
import { SomaMiddlewareChain } from '../middleware/SomaMiddlewareChain';
|
|
4
|
+
import { SomaScheduler } from '../scheduler/SomaScheduler';
|
|
5
|
+
import type { SomaCompiledEvent, SomaRuntimeManifest } from '../types/manifest.types';
|
|
6
|
+
import type { SomaScopeResolver } from './scope-resolver';
|
|
7
|
+
export interface SomaEventMiddlewareContext {
|
|
8
|
+
config: SomaCompiledEvent;
|
|
9
|
+
element: HTMLElement;
|
|
10
|
+
originalEvent: Event;
|
|
11
|
+
currentVar: any;
|
|
12
|
+
status: 'success' | 'blocked' | 'error';
|
|
13
|
+
message?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface SomaEventEngineOptions<TContext extends Record<string, unknown> = Record<string, never>> {
|
|
16
|
+
manifest: SomaRuntimeManifest;
|
|
17
|
+
container: HTMLElement;
|
|
18
|
+
adapter: IContainerAdapter;
|
|
19
|
+
resolver: SomaScopeResolver;
|
|
20
|
+
scopeTracker: WeakMap<HTMLElement, any>;
|
|
21
|
+
callbacks: {
|
|
22
|
+
onRefresh: () => void | Promise<void>;
|
|
23
|
+
/** @deprecated 使用 onCommit */
|
|
24
|
+
onFlush?: () => void | Promise<void>;
|
|
25
|
+
onCommit?: () => void | Promise<void>;
|
|
26
|
+
onBeginTransaction?: () => void;
|
|
27
|
+
onEndTransaction?: () => void;
|
|
28
|
+
onDiscardPending?: () => void;
|
|
29
|
+
onSyncModels?: () => void;
|
|
30
|
+
};
|
|
31
|
+
diagnostics?: SomaDiagnostics;
|
|
32
|
+
scheduler?: SomaScheduler;
|
|
33
|
+
middleware?: SomaMiddlewareChain<any>;
|
|
34
|
+
eventContextFactory?: (config: SomaCompiledEvent, element: HTMLElement, originalEvent: Event) => TContext;
|
|
35
|
+
}
|
|
36
|
+
export declare class SomaEventEngine<TContext extends Record<string, unknown> = Record<string, never>> {
|
|
37
|
+
private readonly manifest;
|
|
38
|
+
private readonly container;
|
|
39
|
+
private readonly adapter;
|
|
40
|
+
private readonly resolver;
|
|
41
|
+
private readonly scopeTracker;
|
|
42
|
+
private readonly callbacks;
|
|
43
|
+
private readonly diagnostics;
|
|
44
|
+
private readonly scheduler;
|
|
45
|
+
private readonly middleware;
|
|
46
|
+
private readonly eventContextFactory?;
|
|
47
|
+
private readonly pendingSet;
|
|
48
|
+
private readonly abortController;
|
|
49
|
+
constructor(options: SomaEventEngineOptions<TContext>);
|
|
50
|
+
init(): void;
|
|
51
|
+
/**
|
|
52
|
+
* 从内层锚点向上查找第一个已注册事件的 data-soma-id。
|
|
53
|
+
* 避免点击 product_name 等子节点时,closest 停在无事件的子 id 上。
|
|
54
|
+
*/
|
|
55
|
+
private resolveEventBinding;
|
|
56
|
+
execute(config: SomaCompiledEvent, element: HTMLElement, originalEvent: Event): Promise<void>;
|
|
57
|
+
destroy(): void;
|
|
58
|
+
private executeNow;
|
|
59
|
+
private getContext;
|
|
60
|
+
private preCheck;
|
|
61
|
+
private postAction;
|
|
62
|
+
private handleInteraction;
|
|
63
|
+
private resolveFunction;
|
|
64
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 计算 source 数组中值 >= 0 的最长严格递增子序列。
|
|
3
|
+
* 返回值为这些元素在 source 中的索引数组。
|
|
4
|
+
*
|
|
5
|
+
* source 中值为 -1 的位置被跳过(表示新增项,无旧位置)。
|
|
6
|
+
*
|
|
7
|
+
* @param source - 新列表中每个元素在旧列表中的位置,-1 表示新增
|
|
8
|
+
* @returns 构成 LIS 的索引数组(在 source 中的位置)
|
|
9
|
+
*/
|
|
10
|
+
export declare function longestIncreasingSubsequence(source: number[]): number[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SomaScopeResolver } from './scope-resolver';
|
|
2
|
+
import type { SomaPropertyWatcher } from './property-watcher';
|
|
3
|
+
import type { UiConfig } from '../types/ui-config.types';
|
|
4
|
+
export interface SomaOnChangeEngineOptions {
|
|
5
|
+
propertyWatcher: SomaPropertyWatcher;
|
|
6
|
+
resolver: SomaScopeResolver;
|
|
7
|
+
uiConfig: UiConfig;
|
|
8
|
+
proxiedInstance: object;
|
|
9
|
+
onRefresh?: () => void | Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare class SomaOnChangeEngine {
|
|
12
|
+
private readonly unwatchers;
|
|
13
|
+
init(options: SomaOnChangeEngineOptions): void;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
private registerRule;
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { WatchCallback, WatcherOptions } from '../types/watcher.types';
|
|
2
|
+
export declare class SomaPropertyWatcher {
|
|
3
|
+
private entries;
|
|
4
|
+
private root;
|
|
5
|
+
setRoot(root: object): void;
|
|
6
|
+
/**
|
|
7
|
+
* 注册属性监听器。
|
|
8
|
+
* @returns 取消监听的函数
|
|
9
|
+
*/
|
|
10
|
+
watch(watchPath: string, callback: WatchCallback, options?: WatcherOptions): () => void;
|
|
11
|
+
/** Proxy set trap 驱动:通知所有匹配的 watcher */
|
|
12
|
+
notify(changedPath: string, newValue: unknown, oldValue: unknown): void;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
private matches;
|
|
15
|
+
private invoke;
|
|
16
|
+
}
|
|
17
|
+
/** 通配符路径匹配:`*` 匹配单段(如 a.*.c 匹配 a.b.c) */
|
|
18
|
+
export declare function matchGlobPath(pattern: string, path: string): boolean;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { SomaDiagnostics } from '../diagnostics/SomaDiagnostics';
|
|
2
|
+
/**
|
|
3
|
+
* SOMA 响应式代理
|
|
4
|
+
*
|
|
5
|
+
* 封装 ES6 Proxy 深度劫持,对外暴露唯一接口 wrap()。
|
|
6
|
+
* - 使用 WeakMap 缓存,同一对象只创建一个 Proxy
|
|
7
|
+
* - 跳过内置类型(Set/Map/Date 等);数组通过引用替换触发更新
|
|
8
|
+
* - 函数绑定到 Proxy receiver,确保 this 正确
|
|
9
|
+
* - devMode 开启时,数组变异方法调用会发出 warn(提示改用引用替换)
|
|
10
|
+
*/
|
|
11
|
+
export declare class SomaReactiveProxy {
|
|
12
|
+
/** 原始对象 → Proxy 实例的缓存(仅用于顶层 wrap 调用) */
|
|
13
|
+
private cache;
|
|
14
|
+
/** 子对象 Proxy 缓存:避免每次 get 嵌套对象都 new Proxy() */
|
|
15
|
+
private childProxyCache;
|
|
16
|
+
/** 变更回调(可延迟设置) */
|
|
17
|
+
private onChange;
|
|
18
|
+
private diagnostics;
|
|
19
|
+
private readonly devMode;
|
|
20
|
+
constructor(onChange?: (path: string, value: any, oldValue: any) => void, diagnostics?: SomaDiagnostics, devMode?: boolean);
|
|
21
|
+
/** 延迟设置变更回调 */
|
|
22
|
+
setOnChange(fn: ((path: string, value: any, oldValue: any) => void) | null): void;
|
|
23
|
+
private batchDepth;
|
|
24
|
+
private batchedPaths;
|
|
25
|
+
/**
|
|
26
|
+
* 开始批量变更事务。
|
|
27
|
+
* batch 期间,onChange 回调暂停,所有变更路径被收集。
|
|
28
|
+
* 支持嵌套调用。
|
|
29
|
+
*/
|
|
30
|
+
beginBatch(): void;
|
|
31
|
+
/**
|
|
32
|
+
* 结束批量变更事务。
|
|
33
|
+
* 最外层 endBatch 时,一次性触发所有收集的变更路径的 onChange 回调。
|
|
34
|
+
*/
|
|
35
|
+
endBatch(): void;
|
|
36
|
+
setDiagnostics(diagnostics: SomaDiagnostics | null): void;
|
|
37
|
+
/** 销毁:断开回调,清空缓存 */
|
|
38
|
+
dispose(): void;
|
|
39
|
+
/**
|
|
40
|
+
* 将对象包装为深度响应式代理。
|
|
41
|
+
* 对象的任何属性赋值(包括嵌套对象)都会触发 onChange 回调。
|
|
42
|
+
* 仅缓存顶层 wrap() 调用创建的 Proxy,避免 basePath 污染。
|
|
43
|
+
*/
|
|
44
|
+
wrap<T extends object>(obj: T, basePath?: string): T;
|
|
45
|
+
/**
|
|
46
|
+
* 创建 Proxy handler(get/set trap)。
|
|
47
|
+
* 子对象在 get trap 中每次创建新 Proxy(不缓存),确保 basePath 正确。
|
|
48
|
+
*/
|
|
49
|
+
private createHandler;
|
|
50
|
+
/**
|
|
51
|
+
* 为数组创建一个轻量 Proxy,仅在 dev 模式下拦截变异方法。
|
|
52
|
+
* 纯读方法(map/filter/length 等)直接透传,不影响性能。
|
|
53
|
+
* 不缓存,每次 get 都创建新 Proxy,保证 arrayPath 路径准确。
|
|
54
|
+
*/
|
|
55
|
+
private wrapArrayDevGuard;
|
|
56
|
+
/** 判断对象是否应跳过代理 */
|
|
57
|
+
private shouldSkip;
|
|
58
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { SomaDiagnostics } from '../diagnostics/SomaDiagnostics';
|
|
2
|
+
import type { BindingEntry } from '../types/engine.types';
|
|
3
|
+
import type { SomaRuntimeManifest } from '../types/manifest.types';
|
|
4
|
+
import { SomaScheduler } from '../scheduler/SomaScheduler';
|
|
5
|
+
import { SomaMiddlewareChain } from '../middleware/SomaMiddlewareChain';
|
|
6
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
7
|
+
import { SomaScopeResolver } from './scope-resolver';
|
|
8
|
+
import { SomaPropertyWatcher } from './property-watcher';
|
|
9
|
+
import type { WatchCallback, WatcherOptions } from '../types/watcher.types';
|
|
10
|
+
export interface SomaRenderEngineOptions {
|
|
11
|
+
container: HTMLElement;
|
|
12
|
+
adapter: IContainerAdapter;
|
|
13
|
+
manifest: SomaRuntimeManifest;
|
|
14
|
+
proxiedInstance: any;
|
|
15
|
+
resolver: SomaScopeResolver;
|
|
16
|
+
scheduler?: SomaScheduler;
|
|
17
|
+
diagnostics?: SomaDiagnostics;
|
|
18
|
+
middleware?: SomaMiddlewareChain<SomaRenderMiddlewareContext>;
|
|
19
|
+
propertyWatcher?: SomaPropertyWatcher;
|
|
20
|
+
}
|
|
21
|
+
export interface SomaRenderMiddlewareContext {
|
|
22
|
+
phase: 'full-render' | 'patch' | 'commit';
|
|
23
|
+
path?: string;
|
|
24
|
+
changedPaths: string[];
|
|
25
|
+
bindings: BindingEntry[];
|
|
26
|
+
}
|
|
27
|
+
export declare class SomaRenderEngine {
|
|
28
|
+
private readonly container;
|
|
29
|
+
private readonly adapter;
|
|
30
|
+
private readonly resolver;
|
|
31
|
+
private readonly renderer;
|
|
32
|
+
private readonly scheduler;
|
|
33
|
+
private readonly diagnostics;
|
|
34
|
+
private readonly middleware;
|
|
35
|
+
private bindingTable;
|
|
36
|
+
private bindingIndex;
|
|
37
|
+
private scopeTracker;
|
|
38
|
+
private pendingPatches;
|
|
39
|
+
private flushScheduled;
|
|
40
|
+
private transactionDepth;
|
|
41
|
+
private destroyed;
|
|
42
|
+
private proxiedInstance;
|
|
43
|
+
private readonly propertyWatcher;
|
|
44
|
+
private initProps;
|
|
45
|
+
constructor(options: SomaRenderEngineOptions);
|
|
46
|
+
getScopeTracker(): WeakMap<HTMLElement, any>;
|
|
47
|
+
/** 注册属性监听器(文档 §10.2 watch API) */
|
|
48
|
+
watch(path: string, callback: WatchCallback, options?: WatcherOptions): () => void;
|
|
49
|
+
getPropertyWatcher(): SomaPropertyWatcher;
|
|
50
|
+
setInitProps(props: Record<string, unknown>): void;
|
|
51
|
+
getInitProps(): Record<string, unknown>;
|
|
52
|
+
render(): void;
|
|
53
|
+
flush(): Promise<void>;
|
|
54
|
+
/** 事件事务开始:defer 数据 patch flush,仅收集 dirty path */
|
|
55
|
+
beginTransaction(): void;
|
|
56
|
+
/** 事件事务结束:不应再额外 flush(commit 已在 handler 后完成) */
|
|
57
|
+
endTransaction(): void;
|
|
58
|
+
/** 一次性提交事务内积累的 dirty path(Phase 2 commit 点) */
|
|
59
|
+
commit(): Promise<void>;
|
|
60
|
+
/** force 全量 render 前丢弃 pending patch(避免 commit + render 双写) */
|
|
61
|
+
discardPendingPatches(): void;
|
|
62
|
+
isInTransaction(): boolean;
|
|
63
|
+
/** 将 DOM 表单控件的当前值写回代理实例(点击提交前同步) */
|
|
64
|
+
syncModels(): void;
|
|
65
|
+
destroy(): void;
|
|
66
|
+
schedulePatch(path: string, value: any): void;
|
|
67
|
+
private ensureFlushScheduled;
|
|
68
|
+
private buildIndex;
|
|
69
|
+
private findAffectedEntries;
|
|
70
|
+
private flushPatches;
|
|
71
|
+
private executeRender;
|
|
72
|
+
private writeToProxy;
|
|
73
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
2
|
+
import type { SomaDiagnostics } from '../diagnostics/SomaDiagnostics';
|
|
3
|
+
import type { SomaMiddlewareChain } from '../middleware/SomaMiddlewareChain';
|
|
4
|
+
import type { SomaScheduler } from '../scheduler/SomaScheduler';
|
|
5
|
+
import type { ParsedEvent } from '../types/event.types';
|
|
6
|
+
import type { PropertyTrigger } from '../types/trigger.types';
|
|
7
|
+
import type { ParsedTimer } from '../types/timer.types';
|
|
8
|
+
import type { ITimer } from '../infra/timer/ITimer';
|
|
9
|
+
import type { StyleConfig } from '../types/style-config.types';
|
|
10
|
+
import type { UiConfig } from '../types/ui-config.types';
|
|
11
|
+
import { SomaEventEngine, type SomaEventMiddlewareContext } from './event-engine';
|
|
12
|
+
import { SomaOnChangeEngine } from './on-change-engine';
|
|
13
|
+
import type { SomaRenderMiddlewareContext } from './render-engine';
|
|
14
|
+
import { SomaRenderEngine } from './render-engine';
|
|
15
|
+
import { SomaPropertyWatcher } from './property-watcher';
|
|
16
|
+
import { SomaScopeResolver } from './scope-resolver';
|
|
17
|
+
import { SomaStyleBinder } from './style-binder';
|
|
18
|
+
import { SomaTriggerEngine } from './trigger-engine';
|
|
19
|
+
import { SomaTimerEngine } from './timer-engine';
|
|
20
|
+
export interface RuntimeBuildInput {
|
|
21
|
+
container: HTMLElement;
|
|
22
|
+
adapter: IContainerAdapter;
|
|
23
|
+
uiConfig: UiConfig;
|
|
24
|
+
eventConfig: ParsedEvent[];
|
|
25
|
+
triggers?: PropertyTrigger[];
|
|
26
|
+
timers?: ParsedTimer[];
|
|
27
|
+
timerService?: ITimer;
|
|
28
|
+
styleConfig?: StyleConfig;
|
|
29
|
+
proxiedInstance: any;
|
|
30
|
+
scheduler: SomaScheduler;
|
|
31
|
+
diagnostics: SomaDiagnostics;
|
|
32
|
+
renderMiddleware?: SomaMiddlewareChain<SomaRenderMiddlewareContext>;
|
|
33
|
+
eventMiddleware?: SomaMiddlewareChain<SomaEventMiddlewareContext>;
|
|
34
|
+
}
|
|
35
|
+
export interface SomaRuntime {
|
|
36
|
+
renderEngine: SomaRenderEngine;
|
|
37
|
+
eventEngine: SomaEventEngine;
|
|
38
|
+
styleBinder: SomaStyleBinder | null;
|
|
39
|
+
propertyWatcher: SomaPropertyWatcher;
|
|
40
|
+
onChangeEngine: SomaOnChangeEngine;
|
|
41
|
+
triggerEngine: SomaTriggerEngine;
|
|
42
|
+
timerEngine: SomaTimerEngine;
|
|
43
|
+
resolver: SomaScopeResolver;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 运行时构建器:将配置 + 实例 + DOM 组装为可运行的引擎组。
|
|
47
|
+
*/
|
|
48
|
+
export declare class SomaRuntimeBuilder {
|
|
49
|
+
private readonly manifestCompiler;
|
|
50
|
+
build(input: RuntimeBuildInput): SomaRuntime;
|
|
51
|
+
/** onMount 之后启动声明式定时器 */
|
|
52
|
+
startTimers(runtime: Pick<SomaRuntime, 'eventEngine' | 'timerEngine'>, options: {
|
|
53
|
+
container: HTMLElement;
|
|
54
|
+
adapter: IContainerAdapter;
|
|
55
|
+
timers: ParsedTimer[];
|
|
56
|
+
timerService: ITimer;
|
|
57
|
+
}): void;
|
|
58
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { UiConfig } from '../types/ui-config.types';
|
|
2
|
+
/**
|
|
3
|
+
* SOMA 作用域解析器
|
|
4
|
+
*
|
|
5
|
+
* 统一管理 var 别名的注册和解析。
|
|
6
|
+
* 渲染引擎和事件引擎共用同一个实例,确保路径解析一致。
|
|
7
|
+
*/
|
|
8
|
+
export declare class SomaScopeResolver {
|
|
9
|
+
/** var 别名 → 属性路径(用于渲染引擎的绑定表编译) */
|
|
10
|
+
private varMap;
|
|
11
|
+
/** var 别名 → 实际对象引用(用于事件引擎的函数调用) */
|
|
12
|
+
private scopeChain;
|
|
13
|
+
/** 根实例引用 */
|
|
14
|
+
private rootInstance;
|
|
15
|
+
/**
|
|
16
|
+
* 从 UiConfig 构建 var 映射和作用域链。
|
|
17
|
+
*
|
|
18
|
+
* 规则:
|
|
19
|
+
* - 顶级 bind:var 指向根实例本身(obj 是 Class 标识符,非属性路径)
|
|
20
|
+
* - 嵌套 bind:var 指向 obj 路径对应的子对象
|
|
21
|
+
*/
|
|
22
|
+
build(config: UiConfig, rootInstance: object): void;
|
|
23
|
+
/**
|
|
24
|
+
* 将含 var 别名的路径解析为实际属性路径。
|
|
25
|
+
* 如 "page.boardCard.name" → "boardCard.name"(page 映射到空路径)
|
|
26
|
+
* 如 "s.name" → "s.name"(如果 s 是列表迭代变量,不在 varMap 中时原样返回)
|
|
27
|
+
*/
|
|
28
|
+
resolvePath(path: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* 从实例上读取属性路径对应的值。
|
|
31
|
+
*/
|
|
32
|
+
readValue(instance: object, path: string): any;
|
|
33
|
+
/**
|
|
34
|
+
* 从根实例读取已解析路径的值。
|
|
35
|
+
*/
|
|
36
|
+
readFromRoot(path: string): any;
|
|
37
|
+
/**
|
|
38
|
+
* 将值写入根实例上的路径(支持 var 别名)。
|
|
39
|
+
*/
|
|
40
|
+
writeToRoot(path: string, value: unknown): void;
|
|
41
|
+
/**
|
|
42
|
+
* 将值写入对象上的属性路径,中间缺失的对象会自动创建。
|
|
43
|
+
*/
|
|
44
|
+
writeValue(obj: object, path: string, value: unknown): void;
|
|
45
|
+
/** 编译缓存:path → compiled getter */
|
|
46
|
+
private getterCache;
|
|
47
|
+
/**
|
|
48
|
+
* 将属性路径编译为直接访问函数。
|
|
49
|
+
*
|
|
50
|
+
* 消除运行时的 path.split('.') + 循环读取,
|
|
51
|
+
* 编译为 (root) => root?.seg0?.seg1?.seg2 形式的直接属性链。
|
|
52
|
+
*
|
|
53
|
+
* 等价于 C++ 编译器将 obj.a.b.c 编译为连续的偏移量寻址。
|
|
54
|
+
*/
|
|
55
|
+
compileGetter(path: string): (root: any) => any;
|
|
56
|
+
/**
|
|
57
|
+
* 使用编译后的 getter 从根实例读取值。
|
|
58
|
+
* 比 readFromRoot 快:无 split,无动态循环。
|
|
59
|
+
*/
|
|
60
|
+
readFromRootCompiled(path: string): any;
|
|
61
|
+
/**
|
|
62
|
+
* 解析函数路径并返回 bound function。
|
|
63
|
+
* 函数通过 .bind(owner) 绑定到方法所属的对象。
|
|
64
|
+
*
|
|
65
|
+
* @throws Error 如果路径无法解析或结果不是函数
|
|
66
|
+
*/
|
|
67
|
+
resolveFunction(funcPath: string): Function;
|
|
68
|
+
/**
|
|
69
|
+
* 获取 var 别名对应的路径(供绑定编译器使用)。
|
|
70
|
+
*/
|
|
71
|
+
getVarPath(varName: string): string | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* 检查是否有指定的 var 别名。
|
|
74
|
+
*/
|
|
75
|
+
hasVar(varName: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* 判断某个 var 别名是否指向集合元素(即路径非空,而非顶级根实例)。
|
|
78
|
+
* 用于事件引擎区分"列表项上下文"和"根实例上下文"。
|
|
79
|
+
*/
|
|
80
|
+
isListVar(varName: string): boolean;
|
|
81
|
+
private walkConfig;
|
|
82
|
+
/** 递归扫描 show 树,注册 when/show 条件块内的嵌套 bind */
|
|
83
|
+
private walkShowMappings;
|
|
84
|
+
private isNestedShowMapping;
|
|
85
|
+
private isExtendedShowValue;
|
|
86
|
+
/**
|
|
87
|
+
* 通过 obj 路径从 scopeChain 或 parentInstance 解析到对象。
|
|
88
|
+
*/
|
|
89
|
+
private resolveObjFromChain;
|
|
90
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
2
|
+
import { SomaDiagnostics, type SomaDiagnosticsSnapshot } from '../diagnostics/SomaDiagnostics';
|
|
3
|
+
import { SomaTelemetry } from '../diagnostics/SomaTelemetry';
|
|
4
|
+
import { SomaMiddlewareChain } from '../middleware/SomaMiddlewareChain';
|
|
5
|
+
import { SomaScheduler } from '../scheduler/SomaScheduler';
|
|
6
|
+
import type { ParsedEvent } from '../types/event.types';
|
|
7
|
+
import type { PropertyTrigger } from '../types/trigger.types';
|
|
8
|
+
import type { ParsedTimer } from '../types/timer.types';
|
|
9
|
+
import type { StyleConfig } from '../types/style-config.types';
|
|
10
|
+
import type { UiConfig } from '../types/ui-config.types';
|
|
11
|
+
import type { SomaPageRoot } from '../types/domain.types';
|
|
12
|
+
import { SomaAssetResolver } from './asset-resolver';
|
|
13
|
+
import type { SomaEventMiddlewareContext } from './event-engine';
|
|
14
|
+
import type { SomaRenderEngine, SomaRenderMiddlewareContext } from './render-engine';
|
|
15
|
+
import type { SomaStyleBinder } from './style-binder';
|
|
16
|
+
import type { WatchCallback, WatcherOptions } from '../types/watcher.types';
|
|
17
|
+
export interface SomaPageAssets {
|
|
18
|
+
html: string;
|
|
19
|
+
includes?: Record<string, string>;
|
|
20
|
+
DomainClass: new () => SomaPageRoot;
|
|
21
|
+
uiYaml?: string;
|
|
22
|
+
eventYaml?: string;
|
|
23
|
+
styleYaml?: string;
|
|
24
|
+
localeYaml?: string;
|
|
25
|
+
appConfigYaml?: string;
|
|
26
|
+
uiConfig?: UiConfig;
|
|
27
|
+
eventConfig?: ParsedEvent[];
|
|
28
|
+
triggerConfig?: PropertyTrigger[];
|
|
29
|
+
timerConfig?: ParsedTimer[];
|
|
30
|
+
styleConfig?: StyleConfig;
|
|
31
|
+
locale?: Record<string, unknown>;
|
|
32
|
+
appConfig?: unknown;
|
|
33
|
+
/** Full router path including query string (e.g. /items/detail?id=1) */
|
|
34
|
+
routerPath?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface SomaBootstrapOptions {
|
|
37
|
+
adapter?: IContainerAdapter;
|
|
38
|
+
scheduler?: SomaScheduler;
|
|
39
|
+
diagnostics?: SomaDiagnostics;
|
|
40
|
+
telemetry?: SomaTelemetry;
|
|
41
|
+
assetResolver?: SomaAssetResolver;
|
|
42
|
+
/** Render-engine middleware chain (opt-in) */
|
|
43
|
+
renderMiddleware?: SomaMiddlewareChain<SomaRenderMiddlewareContext>;
|
|
44
|
+
/**
|
|
45
|
+
* Event-engine middleware chain (opt-in).
|
|
46
|
+
* Use `createPermissionMiddleware` when events declare `permission:code` in pipeline.
|
|
47
|
+
*/
|
|
48
|
+
eventMiddleware?: SomaMiddlewareChain<SomaEventMiddlewareContext>;
|
|
49
|
+
}
|
|
50
|
+
export interface ParsedRuntimeAssets {
|
|
51
|
+
uiConfig: UiConfig;
|
|
52
|
+
eventConfig: ParsedEvent[];
|
|
53
|
+
triggers: PropertyTrigger[];
|
|
54
|
+
timers: ParsedTimer[];
|
|
55
|
+
styleConfig?: StyleConfig;
|
|
56
|
+
locale: Record<string, unknown>;
|
|
57
|
+
appConfig: unknown;
|
|
58
|
+
}
|
|
59
|
+
export declare class SomaBootstrap {
|
|
60
|
+
private readonly adapter;
|
|
61
|
+
private readonly scheduler;
|
|
62
|
+
private readonly assetResolver;
|
|
63
|
+
private readonly runtimeBuilder;
|
|
64
|
+
private readonly snapshotStore;
|
|
65
|
+
private readonly renderMiddleware;
|
|
66
|
+
private readonly eventMiddleware;
|
|
67
|
+
private routerUnsubscribe;
|
|
68
|
+
private renderEngine;
|
|
69
|
+
private eventEngine;
|
|
70
|
+
private styleBinder;
|
|
71
|
+
private propertyWatcher;
|
|
72
|
+
private onChangeEngine;
|
|
73
|
+
private triggerEngine;
|
|
74
|
+
private timerEngine;
|
|
75
|
+
private parsedTimers;
|
|
76
|
+
private proxy;
|
|
77
|
+
private domainInstance;
|
|
78
|
+
private mounted;
|
|
79
|
+
private diagnostics;
|
|
80
|
+
private readonly telemetry;
|
|
81
|
+
private container;
|
|
82
|
+
private assets;
|
|
83
|
+
constructor(options?: SomaBootstrapOptions);
|
|
84
|
+
mount(container: HTMLElement, assets: SomaPageAssets): Promise<void>;
|
|
85
|
+
hotSwap(overrides: Partial<SomaPageAssets>, options?: {
|
|
86
|
+
resetDiagnostics?: boolean;
|
|
87
|
+
preserveState?: boolean;
|
|
88
|
+
}): Promise<void>;
|
|
89
|
+
captureSnapshot(options?: {
|
|
90
|
+
exclude?: string[];
|
|
91
|
+
}): number;
|
|
92
|
+
restoreSnapshot(snapshotId: number): void;
|
|
93
|
+
batch(fn: () => void): void;
|
|
94
|
+
unmount(): Promise<void>;
|
|
95
|
+
getDiagnosticsSnapshot(): SomaDiagnosticsSnapshot;
|
|
96
|
+
getTelemetrySnapshot(): ReturnType<SomaTelemetry['snapshot']>;
|
|
97
|
+
getAvailableThemes(): string[];
|
|
98
|
+
getStyleBinder(): SomaStyleBinder | null;
|
|
99
|
+
switchTheme(themeName: string | null): void;
|
|
100
|
+
/** 获取当前挂载的业务实例(测试 / 调试) */
|
|
101
|
+
getDomainInstance(): SomaPageRoot | null;
|
|
102
|
+
/** 获取渲染引擎(测试 / 调试) */
|
|
103
|
+
getRenderEngine(): SomaRenderEngine | null;
|
|
104
|
+
/** 监听属性变更(委托 RenderEngine.watch) */
|
|
105
|
+
watch(path: string, callback: WatchCallback, options?: WatcherOptions): () => void;
|
|
106
|
+
private createDomainInstance;
|
|
107
|
+
private buildRuntime;
|
|
108
|
+
private startDeclarativeTimers;
|
|
109
|
+
private stopDeclarativeTimers;
|
|
110
|
+
private wireRouter;
|
|
111
|
+
private cleanup;
|
|
112
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
2
|
+
import type { StyleConfig } from '../types/style-config.types';
|
|
3
|
+
interface LeaveAnimation {
|
|
4
|
+
element: HTMLElement;
|
|
5
|
+
classes: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface SomaStyleBinderOptions {
|
|
8
|
+
container: HTMLElement;
|
|
9
|
+
adapter: IContainerAdapter;
|
|
10
|
+
styleConfig: StyleConfig;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* SOMA 样式事件绑定器
|
|
14
|
+
*
|
|
15
|
+
* 将 _style.yaml 的声明式配置转化为运行时的事件注册与执行:
|
|
16
|
+
* - base:初始化时一次性附加固定类名
|
|
17
|
+
* - states:监听属性路径变化,正交切换匹配类名
|
|
18
|
+
* - transitions:绑定 DOM 原生事件(hover/focus/active)或状态驱动动画
|
|
19
|
+
* - themes:主题切换时覆盖 base 和 states 类名
|
|
20
|
+
*/
|
|
21
|
+
export declare class SomaStyleBinder {
|
|
22
|
+
private readonly container;
|
|
23
|
+
private readonly adapter;
|
|
24
|
+
private readonly styleConfig;
|
|
25
|
+
private readonly abortController;
|
|
26
|
+
/** 属性路径 → StateBinding[]:states 块的事件索引 */
|
|
27
|
+
private stateIndex;
|
|
28
|
+
/** 属性路径 → ActiveStateBinding[]:transitions active_state 的事件索引 */
|
|
29
|
+
private activeStateIndex;
|
|
30
|
+
/** somaId → base 类名数组:用于主题切换时回退 */
|
|
31
|
+
private baseClasses;
|
|
32
|
+
/** somaId → 当前主题附加的 base 类名:主题切换时清理 */
|
|
33
|
+
private themeBaseClasses;
|
|
34
|
+
/** somaId → leave 动画配置 */
|
|
35
|
+
private leaveAnimations;
|
|
36
|
+
/** 当前激活的主题名称 */
|
|
37
|
+
private currentTheme;
|
|
38
|
+
constructor(options: SomaStyleBinderOptions);
|
|
39
|
+
/**
|
|
40
|
+
* 初始化:解析 StyleConfig,注册所有事件
|
|
41
|
+
*
|
|
42
|
+
* 1. 应用 base 类名
|
|
43
|
+
* 2. 建立 states 属性事件索引
|
|
44
|
+
* 3. 建立 transitions active_state 索引
|
|
45
|
+
* 4. 绑定 transitions DOM 事件
|
|
46
|
+
*/
|
|
47
|
+
init(): void;
|
|
48
|
+
/**
|
|
49
|
+
* 属性变更事件入口 — 由 ReactiveProxy.onChange 驱动
|
|
50
|
+
*
|
|
51
|
+
* 查询 stateIndex 和 activeStateIndex,对匹配的绑定执行类名切换
|
|
52
|
+
*/
|
|
53
|
+
onPropertyChange(path: string, newValue: any): void;
|
|
54
|
+
/**
|
|
55
|
+
* 切换主题
|
|
56
|
+
*
|
|
57
|
+
* @param themeName - 目标主题名,null 表示回退到默认
|
|
58
|
+
*/
|
|
59
|
+
/** 返回 _style.yaml themes 块中声明的主题名 */
|
|
60
|
+
getAvailableThemes(): string[];
|
|
61
|
+
switchTheme(themeName: string | null): void;
|
|
62
|
+
/**
|
|
63
|
+
* 获取 leave 动画配置(供外部在隐藏节点前调用)
|
|
64
|
+
*/
|
|
65
|
+
getLeaveAnimation(somaId: string): LeaveAnimation | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* 销毁:移除所有事件监听,清空索引
|
|
68
|
+
*/
|
|
69
|
+
destroy(): void;
|
|
70
|
+
/** 应用 base 类名到 DOM */
|
|
71
|
+
private applyBase;
|
|
72
|
+
/** 从 states 配置构建属性事件索引 */
|
|
73
|
+
private buildStateIndex;
|
|
74
|
+
/** 从 transitions active_state 配置构建属性事件索引 */
|
|
75
|
+
private buildActiveStateIndex;
|
|
76
|
+
/** 绑定 transitions 中非 active_state 的 DOM 事件 */
|
|
77
|
+
private bindTransitionEvents;
|
|
78
|
+
/** 合并主题 states 覆盖后重建索引 */
|
|
79
|
+
private rebuildStateIndexWithTheme;
|
|
80
|
+
}
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ITimer } from '../infra/timer/ITimer';
|
|
2
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
3
|
+
import type { ParsedTimer } from '../types/timer.types';
|
|
4
|
+
import type { SomaEventEngine } from './event-engine';
|
|
5
|
+
export interface SomaTimerEngineOptions {
|
|
6
|
+
container: HTMLElement;
|
|
7
|
+
adapter: IContainerAdapter;
|
|
8
|
+
timer: ITimer;
|
|
9
|
+
eventEngine: SomaEventEngine;
|
|
10
|
+
timers: ParsedTimer[];
|
|
11
|
+
}
|
|
12
|
+
export declare class SomaTimerEngine {
|
|
13
|
+
private readonly handles;
|
|
14
|
+
private anchorEl;
|
|
15
|
+
/** 在 onMount 之后调用,开始注册定时器 */
|
|
16
|
+
start(options: SomaTimerEngineOptions): void;
|
|
17
|
+
stop(timer: ITimer): void;
|
|
18
|
+
private toCompiledEvent;
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IContainerAdapter } from '../container/IContainerAdapter';
|
|
2
|
+
import type { PropertyTrigger } from '../types/trigger.types';
|
|
3
|
+
import type { SomaScopeResolver } from './scope-resolver';
|
|
4
|
+
import type { SomaPropertyWatcher } from './property-watcher';
|
|
5
|
+
export interface SomaTriggerEngineOptions {
|
|
6
|
+
propertyWatcher: SomaPropertyWatcher;
|
|
7
|
+
resolver: SomaScopeResolver;
|
|
8
|
+
container: HTMLElement;
|
|
9
|
+
adapter: IContainerAdapter;
|
|
10
|
+
triggers: PropertyTrigger[];
|
|
11
|
+
}
|
|
12
|
+
export declare class SomaTriggerEngine {
|
|
13
|
+
private readonly unwatchers;
|
|
14
|
+
init(options: SomaTriggerEngineOptions): void;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
}
|