@proteus-vue/render-backend 0.1.0
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/README.md +75 -0
- package/dist/basic-containers.d.ts +87 -0
- package/dist/borrow-checker.d.ts +21 -0
- package/dist/conformance-component.d.ts +32 -0
- package/dist/conformance.d.ts +18 -0
- package/dist/container-conformance.d.ts +53 -0
- package/dist/container-spi.d.ts +169 -0
- package/dist/dispatcher.d.ts +98 -0
- package/dist/flutter.d.ts +16 -0
- package/dist/headless.d.ts +12 -0
- package/dist/host-conformance.d.ts +71 -0
- package/dist/host-matrix.d.ts +74 -0
- package/dist/hot-switch.d.ts +24 -0
- package/dist/hybrid.d.ts +60 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +4291 -0
- package/dist/native.d.ts +42 -0
- package/dist/ownership-observability.d.ts +99 -0
- package/dist/ownership.d.ts +206 -0
- package/dist/page-ownership.d.ts +55 -0
- package/dist/pss.d.ts +54 -0
- package/dist/spi.d.ts +73 -0
- package/dist/stack-container.d.ts +43 -0
- package/dist/superapp-container.d.ts +47 -0
- package/dist/vue-bridge.d.ts +22 -0
- package/dist/vue-dom.d.ts +6 -0
- package/dist/web-host.d.ts +35 -0
- package/package.json +30 -0
package/dist/native.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ProteusRenderBackend } from './spi';
|
|
2
|
+
/** 原生视图描述(G-27 语义节点在原生后端的表示) */
|
|
3
|
+
export interface NativeViewDescriptor {
|
|
4
|
+
id: number;
|
|
5
|
+
/** 语义标签(view/text/button/...——宿主映射到 UIView/View/ArkUI 组件) */
|
|
6
|
+
type: string;
|
|
7
|
+
props: Record<string, unknown>;
|
|
8
|
+
children: NativeViewDescriptor[];
|
|
9
|
+
parent: NativeViewDescriptor | null;
|
|
10
|
+
text: string;
|
|
11
|
+
/** 宿主句柄(adapter.createView 返回值;无宿主 = 自身) */
|
|
12
|
+
handle: unknown;
|
|
13
|
+
}
|
|
14
|
+
/** 宿主适配器(iOS/Android/鸿蒙 SDK 桥实现本接口;mock 见 createMockNativeAdapter) */
|
|
15
|
+
export interface NativeViewAdapter {
|
|
16
|
+
/** 创建宿主视图(返回宿主句柄——UIView / View / ArkUI Node) */
|
|
17
|
+
createView(descriptor: NativeViewDescriptor): unknown;
|
|
18
|
+
/** 属性/样式/事件同步到宿主(key=onXxx 为事件 → 原生手势桥) */
|
|
19
|
+
updateView(handle: unknown, key: string, prev: unknown, next: unknown): void;
|
|
20
|
+
/** 插入子视图(anchor 可选) */
|
|
21
|
+
insertView(child: unknown, parent: unknown, anchor?: unknown): void;
|
|
22
|
+
/** 移除视图 */
|
|
23
|
+
removeView(child: unknown): void;
|
|
24
|
+
/** 文本同步 */
|
|
25
|
+
setViewText(handle: unknown, text: string): void;
|
|
26
|
+
}
|
|
27
|
+
export interface MockNativeAdapter extends NativeViewAdapter {
|
|
28
|
+
/** 操作日志(断言 create/insert/update/remove/setText 顺序) */
|
|
29
|
+
ops: string[];
|
|
30
|
+
}
|
|
31
|
+
/** 内置 mock 适配器(无宿主环境验证接线;真实平台 B4 后接 SDK 实现替换) */
|
|
32
|
+
export declare function createMockNativeAdapter(): MockNativeAdapter;
|
|
33
|
+
/** 原生平台(iOS UIKit / Android Jetpack / 鸿蒙 ArkUI) */
|
|
34
|
+
export type NativePlatform = 'ios' | 'android' | 'harmony';
|
|
35
|
+
/**
|
|
36
|
+
* NativeBackend:nodeOps → 原生视图(B4——验证「nodeOps → UIView」抽象层;G-31 B3 三平台语义映射)
|
|
37
|
+
* - 维护 NativeViewDescriptor 树(nodeOps 层句柄,唯一 id)
|
|
38
|
+
* - 所有变更同步宿主 adapter(createView/updateView/insertView/removeView/setViewText)
|
|
39
|
+
* - adapter 缺省 mock(ops 日志);真实平台注入 SDK 桥
|
|
40
|
+
* - platform:ios(UIKit 基准)/ android(Jetpack)/ harmony(ArkUI)——决定 id + semantic 映射表
|
|
41
|
+
*/
|
|
42
|
+
export declare function createNativeBackend(adapter?: NativeViewAdapter, platform?: NativePlatform): ProteusRenderBackend;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { GraphEdge, GraphNode, LeakInfo, OwnershipGraph } from './ownership';
|
|
2
|
+
export type OwnershipRecordKind = 'alloc' | 'drop' | 'moved' | 'borrow' | 'weak' | 'strong';
|
|
3
|
+
export interface OwnershipRecord {
|
|
4
|
+
readonly ts: number;
|
|
5
|
+
readonly kind: OwnershipRecordKind;
|
|
6
|
+
readonly id?: string;
|
|
7
|
+
readonly owner?: string | null;
|
|
8
|
+
readonly type?: string;
|
|
9
|
+
readonly byteSize?: number;
|
|
10
|
+
readonly sourceLocation?: string | null;
|
|
11
|
+
/** borrow/weak/strong 的引用方(edge.from) */
|
|
12
|
+
readonly from?: string;
|
|
13
|
+
/** edge.to(borrow/weak/strong 的目标资源) */
|
|
14
|
+
readonly to?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface OwnershipHistoryOptions {
|
|
17
|
+
/** 环形缓冲上限(缺省 2000——V-06 时间线消费,超限丢最旧) */
|
|
18
|
+
readonly limit?: number;
|
|
19
|
+
/** 缺省 true;生产期可关(setEnabled(false)——仅计数仍开) */
|
|
20
|
+
readonly enabled?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface OwnershipHistory {
|
|
23
|
+
readonly records: readonly OwnershipRecord[];
|
|
24
|
+
enabled: boolean;
|
|
25
|
+
setEnabled(v: boolean): void;
|
|
26
|
+
clear(): void;
|
|
27
|
+
/** 解绑图订阅并清空(面板/诊断生命周期结束) */
|
|
28
|
+
dispose(): void;
|
|
29
|
+
}
|
|
30
|
+
/** ★G-43 B4:历史时间线——订阅 graph mutation 记录 alloc/drop/borrow/weak/strong(面板/诊断消费) */
|
|
31
|
+
export declare function createOwnershipHistory(graph: OwnershipGraph, opts?: OwnershipHistoryOptions): OwnershipHistory;
|
|
32
|
+
export interface TypeCounter {
|
|
33
|
+
readonly allocated: number;
|
|
34
|
+
readonly alive: number;
|
|
35
|
+
}
|
|
36
|
+
export interface OwnershipCounters {
|
|
37
|
+
readonly alive: number;
|
|
38
|
+
readonly total: number;
|
|
39
|
+
readonly bytesAlive: number;
|
|
40
|
+
readonly byType: Readonly<Record<string, TypeCounter>>;
|
|
41
|
+
/** V-01 一致性:计数器与图 stats 同步(counter 模式下的自证) */
|
|
42
|
+
consistent(): boolean;
|
|
43
|
+
}
|
|
44
|
+
/** ★G-43 B4:计数器采样(V-07——生产期开销 O(1) 每资源;完整历史可单独关闭) */
|
|
45
|
+
export declare function createOwnershipCounters(graph: OwnershipGraph): OwnershipCounters;
|
|
46
|
+
export interface LongBorrow {
|
|
47
|
+
readonly resourceId: string;
|
|
48
|
+
readonly type: string;
|
|
49
|
+
readonly owner: string | null;
|
|
50
|
+
readonly borrowedBy: string;
|
|
51
|
+
readonly sinceMs: number;
|
|
52
|
+
}
|
|
53
|
+
export interface CrossPageRef {
|
|
54
|
+
readonly resourceId: string;
|
|
55
|
+
readonly type: string;
|
|
56
|
+
readonly owner: string | null;
|
|
57
|
+
/** 跨页强持有的引用方(strong edge.from——显式登记,见 GraphEdge.kind 'strong') */
|
|
58
|
+
readonly heldBy: string;
|
|
59
|
+
}
|
|
60
|
+
export interface OwnershipDiagnosisOptions {
|
|
61
|
+
/** 已销毁页面 scope(V-02 泄漏路径输入——该域资源预期已释放) */
|
|
62
|
+
readonly destroyedScopes?: readonly string[];
|
|
63
|
+
/** 长期借用阈值(缺省 1000ms——V-03) */
|
|
64
|
+
readonly longBorrowMs?: number;
|
|
65
|
+
/** 时钟注入(测试用——缺省 Date.now) */
|
|
66
|
+
readonly now?: () => number;
|
|
67
|
+
}
|
|
68
|
+
export interface OwnershipDiagnosis {
|
|
69
|
+
/** V-01:图中存活节点数(与 stats 一致性在计数器模块自证) */
|
|
70
|
+
readonly aliveNodes: number;
|
|
71
|
+
readonly totalNodes: number;
|
|
72
|
+
/** V-05:无主资源(owner === null 的存活节点——必然泄漏) */
|
|
73
|
+
readonly orphans: GraphNode[];
|
|
74
|
+
/** V-02:泄漏路径(destroyedScopes 内仍存活资源 + 反向引用链 + 源码行) */
|
|
75
|
+
readonly leaks: LeakInfo[];
|
|
76
|
+
/** V-03:长期借用(借用持续时间 > longBorrowMs——借用的运行时逃逸表现) */
|
|
77
|
+
readonly longBorrows: LongBorrow[];
|
|
78
|
+
/** V-04:跨页面强引用(资源 owner=A 被 B 强持有——销毁时无法释放,应 transferTo/weak) */
|
|
79
|
+
readonly crossPageRefs: CrossPageRef[];
|
|
80
|
+
}
|
|
81
|
+
/** ★G-43 B4:四类检测一次跑齐(V-01~V-05——DevTools 面板/远程诊断的公共输入) */
|
|
82
|
+
export declare function diagnoseOwnershipIssues(graph: OwnershipGraph, opts?: OwnershipDiagnosisOptions): OwnershipDiagnosis;
|
|
83
|
+
export interface TimelineEvent extends OwnershipRecord {
|
|
84
|
+
/** 该 drop/moved 对应的 alloc 记录(V-06:每条升降可点到源码行;无 = 历史裁剪或前置分配) */
|
|
85
|
+
readonly matchedAlloc?: OwnershipRecord;
|
|
86
|
+
}
|
|
87
|
+
export interface OwnershipTimeline {
|
|
88
|
+
readonly events: readonly TimelineEvent[];
|
|
89
|
+
/** 未配对 alloc(历史内有 alloc 无 drop 且图节点仍 alive——可疑高亮;页面销毁 force-drop 后消失) */
|
|
90
|
+
readonly unpairedAllocs: readonly OwnershipRecord[];
|
|
91
|
+
}
|
|
92
|
+
/** ★G-43 B4:alloc/drop 配对时间线(V-06——输入记录序列,输出可渲染事件序列 + 可疑未配对) */
|
|
93
|
+
export declare function buildOwnershipTimeline(history: Pick<OwnershipHistory, 'records'>, graph: OwnershipGraph): OwnershipTimeline;
|
|
94
|
+
export interface FormatOptions {
|
|
95
|
+
readonly sourceLabel?: string;
|
|
96
|
+
}
|
|
97
|
+
/** ★G-43 B4:诊断文本报告(对齐 devtools-ownership-graph.md §2.1 主视图叙事) */
|
|
98
|
+
export declare function formatOwnershipDiagnosis(d: OwnershipDiagnosis, opts?: FormatOptions): string;
|
|
99
|
+
export type { GraphEdge, GraphNode };
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
export type OwnershipErrorCode = 'use_after_move' | 'use_after_drop' | 'double_move' | 'has_active_borrows' | 'already_dropped' | 'resource_not_transferable';
|
|
2
|
+
export declare class OwnershipError extends Error {
|
|
3
|
+
readonly code: OwnershipErrorCode;
|
|
4
|
+
readonly resourceId: string;
|
|
5
|
+
constructor(code: OwnershipErrorCode, message: string, extra: {
|
|
6
|
+
resourceId: string;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
export declare const OWNERSHIP_ERRORS: {
|
|
10
|
+
useAfterMove: (id: string, movedTo: string) => OwnershipError;
|
|
11
|
+
useAfterDrop: (id: string) => OwnershipError;
|
|
12
|
+
doubleMove: (id: string) => OwnershipError;
|
|
13
|
+
hasActiveBorrows: (id: string, count: number) => OwnershipError;
|
|
14
|
+
alreadyDropped: (id: string) => OwnershipError;
|
|
15
|
+
notTransferable: (id: string, reason: string) => OwnershipError;
|
|
16
|
+
};
|
|
17
|
+
export interface GraphNode {
|
|
18
|
+
id: string;
|
|
19
|
+
type: string;
|
|
20
|
+
byteSize: number;
|
|
21
|
+
owner: string | null;
|
|
22
|
+
state: 'alive' | 'moved' | 'dropped';
|
|
23
|
+
createdAt: number;
|
|
24
|
+
sourceLocation: string | null;
|
|
25
|
+
}
|
|
26
|
+
export interface GraphEdge {
|
|
27
|
+
kind: 'owns' | 'borrows' | 'weak' | 'moved-from' | 'strong';
|
|
28
|
+
from: string;
|
|
29
|
+
to: string;
|
|
30
|
+
since?: number;
|
|
31
|
+
}
|
|
32
|
+
/** ★G-43 B4:所有权图 mutation 事件(图变化通知——history/计数器/诊断的订阅源) */
|
|
33
|
+
export type OwnershipMutation = {
|
|
34
|
+
kind: 'register';
|
|
35
|
+
id: string;
|
|
36
|
+
owner: string | null;
|
|
37
|
+
type: string;
|
|
38
|
+
byteSize: number;
|
|
39
|
+
sourceLocation: string | null;
|
|
40
|
+
ts: number;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'state';
|
|
43
|
+
id: string;
|
|
44
|
+
state: 'alive' | 'moved' | 'dropped';
|
|
45
|
+
ts: number;
|
|
46
|
+
} | {
|
|
47
|
+
kind: 'edge';
|
|
48
|
+
edge: GraphEdge;
|
|
49
|
+
ts: number;
|
|
50
|
+
};
|
|
51
|
+
export interface OwnershipGraphOptions {
|
|
52
|
+
/** ★G-43 B4:图变化订阅(history/counters/诊断的单一事件源;不提供则零开销) */
|
|
53
|
+
onMutate?: (m: OwnershipMutation) => void;
|
|
54
|
+
}
|
|
55
|
+
type MutateListener = (m: OwnershipMutation) => void;
|
|
56
|
+
export interface LeakInfo {
|
|
57
|
+
resourceId: string;
|
|
58
|
+
type: string;
|
|
59
|
+
byteSize: number;
|
|
60
|
+
sourceLocation: string | null;
|
|
61
|
+
referenceChain: string[];
|
|
62
|
+
}
|
|
63
|
+
export declare class OwnershipGraph {
|
|
64
|
+
readonly nodes: Map<string, GraphNode>;
|
|
65
|
+
readonly edges: GraphEdge[];
|
|
66
|
+
private _nextId;
|
|
67
|
+
private readonly _listeners;
|
|
68
|
+
constructor(opts?: OwnershipGraphOptions);
|
|
69
|
+
nextId(): string;
|
|
70
|
+
/** ★G-43 B4:动态订阅图 mutation(可任意时刻挂接;返回解绑) */
|
|
71
|
+
subscribe(cb: MutateListener): () => void;
|
|
72
|
+
private _emit;
|
|
73
|
+
register(opts: {
|
|
74
|
+
id: string;
|
|
75
|
+
type: string;
|
|
76
|
+
byteSize: number;
|
|
77
|
+
owner?: string | null;
|
|
78
|
+
sourceLocation?: string | null;
|
|
79
|
+
}): GraphNode;
|
|
80
|
+
addEdge(edge: GraphEdge): void;
|
|
81
|
+
setState(id: string, state: GraphNode['state']): void;
|
|
82
|
+
resourcesOf(owner: string): GraphNode[];
|
|
83
|
+
/** 无主资源检测(G-43.1——owner === null 的存活节点数为 0) */
|
|
84
|
+
findOrphans(): GraphNode[];
|
|
85
|
+
/** 泄漏检测:页面销毁后仍存活的资源 + 反向引用链(谁还持有它——DevTools 泄漏定位) */
|
|
86
|
+
detectLeaks(destroyedScope: string): LeakInfo[];
|
|
87
|
+
/** 反向引用链(资源 ← 谁持有 ← 谁又持有……) */
|
|
88
|
+
backTrace(resourceId: string): string[];
|
|
89
|
+
stats(): {
|
|
90
|
+
total: number;
|
|
91
|
+
alive: number;
|
|
92
|
+
moved: number;
|
|
93
|
+
dropped: number;
|
|
94
|
+
totalBytes: number;
|
|
95
|
+
edges: number;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export declare function createQuotaTracker(): {
|
|
99
|
+
request(owner: string, bytes: number): number;
|
|
100
|
+
release(owner: string, bytes: number): number;
|
|
101
|
+
usageOf(owner: string): number;
|
|
102
|
+
};
|
|
103
|
+
export type OwnedState = 'alive' | 'moved' | 'dropped';
|
|
104
|
+
/** ★G-43 B5:Owned 状态变化订阅(useOwned/useBorrow 响应式元信息的底座) */
|
|
105
|
+
export type OwnedStateListener = (state: OwnedState) => void;
|
|
106
|
+
export declare class Owned<T> {
|
|
107
|
+
readonly id: string;
|
|
108
|
+
readonly resourceType: string;
|
|
109
|
+
readonly byteSize: number;
|
|
110
|
+
readonly owner: string;
|
|
111
|
+
private _state;
|
|
112
|
+
private _movedTo;
|
|
113
|
+
private _activeBorrows;
|
|
114
|
+
private _borrows;
|
|
115
|
+
private _transferable;
|
|
116
|
+
private _releaseHook;
|
|
117
|
+
private readonly _graph;
|
|
118
|
+
private readonly _value;
|
|
119
|
+
private readonly _sourceLocation;
|
|
120
|
+
private readonly _listeners;
|
|
121
|
+
constructor(opts: {
|
|
122
|
+
id: string;
|
|
123
|
+
resourceType: string;
|
|
124
|
+
byteSize: number;
|
|
125
|
+
owner: string;
|
|
126
|
+
value: T;
|
|
127
|
+
graph: OwnershipGraph;
|
|
128
|
+
transferable?: boolean;
|
|
129
|
+
releaseHook?: (value: T) => void;
|
|
130
|
+
sourceLocation?: string | null;
|
|
131
|
+
});
|
|
132
|
+
get state(): OwnedState;
|
|
133
|
+
get activeBorrows(): number;
|
|
134
|
+
/** ★G-43 B5:订阅状态变化(moved/dropped 时通知——返回解绑) */
|
|
135
|
+
subscribe(cb: OwnedStateListener): () => void;
|
|
136
|
+
private _notify;
|
|
137
|
+
/** 存活断言(G-43.2/43.6:Move/Drop 后禁访问) */
|
|
138
|
+
private _assertAlive;
|
|
139
|
+
/** 读取(G-43.2:Move/Drop 后禁访问——use-after-move 拦截) */
|
|
140
|
+
read(): T;
|
|
141
|
+
/** ★Move 语义:转移所有权后原所有者不可再访问 */
|
|
142
|
+
transferTo(targetOwner: string): Owned<T>;
|
|
143
|
+
/** ★Borrow:临时借用(G-43.3 不逃逸作用域——drop 后失效) */
|
|
144
|
+
borrow(scopeName?: string): Borrow<T>;
|
|
145
|
+
/** ★Weak:弱引用(打破循环) */
|
|
146
|
+
weak(): Weak<T>;
|
|
147
|
+
/** ★确定性 Drop(五阶段协议) */
|
|
148
|
+
drop(opts?: {
|
|
149
|
+
force?: boolean;
|
|
150
|
+
}): {
|
|
151
|
+
ok: boolean;
|
|
152
|
+
freedBytes: number;
|
|
153
|
+
freedHandles: number;
|
|
154
|
+
invalidatedBorrows: number;
|
|
155
|
+
error?: OwnershipError;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
export declare class Borrow<T> {
|
|
159
|
+
readonly borrowedAt: number;
|
|
160
|
+
private _valid;
|
|
161
|
+
private readonly _source;
|
|
162
|
+
private readonly _scopeName;
|
|
163
|
+
private readonly _graph;
|
|
164
|
+
constructor(source: Owned<T>, scopeName: string, graph: OwnershipGraph);
|
|
165
|
+
get valid(): boolean;
|
|
166
|
+
get durationMs(): number;
|
|
167
|
+
get(): T | undefined;
|
|
168
|
+
release(): void;
|
|
169
|
+
invalidate(): void;
|
|
170
|
+
}
|
|
171
|
+
export declare class Weak<T> {
|
|
172
|
+
private readonly _source;
|
|
173
|
+
constructor(source: Owned<T>);
|
|
174
|
+
get alive(): boolean;
|
|
175
|
+
/** 升级为借用(弱引用仅在持有者存活时可用) */
|
|
176
|
+
upgrade(): Borrow<T> | undefined;
|
|
177
|
+
}
|
|
178
|
+
export declare class Managed {
|
|
179
|
+
readonly value: unknown;
|
|
180
|
+
readonly owner: string;
|
|
181
|
+
disposed: boolean;
|
|
182
|
+
private readonly _disposeFn;
|
|
183
|
+
constructor(opts: {
|
|
184
|
+
value: unknown;
|
|
185
|
+
owner: string;
|
|
186
|
+
disposeFn?: () => void;
|
|
187
|
+
registry?: ManagedRegistry;
|
|
188
|
+
});
|
|
189
|
+
/** 释放(框架在页面销毁时自动调用——业务零心智负担) */
|
|
190
|
+
dispose(): boolean;
|
|
191
|
+
}
|
|
192
|
+
/** 框架代管注册表(页面销毁 → disposeAll——G-42.3 releaseResources 的所有权对应) */
|
|
193
|
+
export declare class ManagedRegistry {
|
|
194
|
+
private readonly _items;
|
|
195
|
+
add(m: Managed): void;
|
|
196
|
+
/** 全部释放(返回释放数) */
|
|
197
|
+
disposeAll(): number;
|
|
198
|
+
get size(): number;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* ★G-43 B4:全局默认所有权图(惰性单例)——业务/容器零配置挂接的面板数据源。
|
|
202
|
+
* 宿主也可显式建图传给容器(StackContainerOptions.ownership)或 installProteusDevtools({ ownership: { graph } });
|
|
203
|
+
* 未显式建图时容器/面板默认消费本单例。
|
|
204
|
+
*/
|
|
205
|
+
export declare function getProteusOwnershipGraph(): OwnershipGraph;
|
|
206
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Owned, ManagedRegistry, OwnershipGraph } from './ownership';
|
|
2
|
+
export interface PageOwnershipOptions {
|
|
3
|
+
readonly graph: OwnershipGraph;
|
|
4
|
+
/** 页面配额上限(bytes;缺省不限额——⑤ reclaim 记账对象仍生效,销毁兜底归零) */
|
|
5
|
+
readonly quotaBytes?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface PageAllocOptions<T> {
|
|
8
|
+
/** 缺省 'shared-buffer'(对齐 ownership-reference.cjs PageContext.alloc) */
|
|
9
|
+
readonly type?: string;
|
|
10
|
+
readonly byteSize: number;
|
|
11
|
+
/** 缺省 new ArrayBuffer(byteSize) */
|
|
12
|
+
readonly value?: T;
|
|
13
|
+
readonly transferable?: boolean;
|
|
14
|
+
readonly sourceLocation?: string | null;
|
|
15
|
+
readonly releaseHook?: (value: T) => void;
|
|
16
|
+
}
|
|
17
|
+
export interface PageOwnershipDestroyReport {
|
|
18
|
+
/** 成功强制释放的资源数 */
|
|
19
|
+
readonly freedCount: number;
|
|
20
|
+
/** 释放字节合计(⑤ reclaim——与 G-42 releaseQuota 合并) */
|
|
21
|
+
readonly freedBytes: number;
|
|
22
|
+
/** forceDrop 过程中被强制失效的活跃借用数 */
|
|
23
|
+
readonly invalidatedBorrows: number;
|
|
24
|
+
/** 框架代管资源释放数(G-42.3) */
|
|
25
|
+
readonly managedDisposed: number;
|
|
26
|
+
/** 销毁后页面配额剩余(验收:= 0——配额完全归还) */
|
|
27
|
+
readonly quotaRemaining: number;
|
|
28
|
+
/** force:false 时因活跃借用未能释放的资源(页面销毁场景默认 force 全清,此清单为空) */
|
|
29
|
+
readonly leaked: Array<{
|
|
30
|
+
resourceId: string;
|
|
31
|
+
reason: string;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
/** ★G-43 B3:页面所有权上下文——业务在该页分配的资源随页面销毁确定性回收(G-42 五原子第 3 步的委托方) */
|
|
35
|
+
export interface PageOwnership {
|
|
36
|
+
readonly owner: string;
|
|
37
|
+
/** 分配唯一所有权资源(登记进页面 scope + 所有权图 + 配额记账) */
|
|
38
|
+
alloc<T = ArrayBuffer>(opts: PageAllocOptions<T>): Owned<T>;
|
|
39
|
+
/** 登记页面已有 Owned(业务自建、owner 为本页的资源——销毁时一并 forceDrop) */
|
|
40
|
+
register<T>(owned: Owned<T>): void;
|
|
41
|
+
/** 页面框架代管资源注册表(new Managed({ registry })——页面销毁自动 disposeAll) */
|
|
42
|
+
readonly managed: ManagedRegistry;
|
|
43
|
+
/** 本页存活资源(所有权图快照——验收「销毁后资源计数 = 0」的数据源) */
|
|
44
|
+
resourcesOf(): ReturnType<OwnershipGraph['resourcesOf']>;
|
|
45
|
+
/**
|
|
46
|
+
* ★页面销毁回收(drop-protocol §3.2:releaseResources → 遍历本页资源逐个 Drop 五阶段):
|
|
47
|
+
* force=true(默认)= forceDrop——忽略活跃借用强制释放(drop ② invalidate 阶段自动失效全部借用)
|
|
48
|
+
* force=false = drop 语义——存在活跃借用的资源跳过并列入 leaked
|
|
49
|
+
*/
|
|
50
|
+
destroy(opts?: {
|
|
51
|
+
force?: boolean;
|
|
52
|
+
}): PageOwnershipDestroyReport;
|
|
53
|
+
}
|
|
54
|
+
/** ★G-43 B3:创建页面所有权上下文(页面 = 所有权 scope——G-42 createPage 的伴随物) */
|
|
55
|
+
export declare function createPageOwnership(owner: string, opts: PageOwnershipOptions): PageOwnership;
|
package/dist/pss.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { BorrowDiagnostic, BorrowSeverity, PssMode } from './borrow-checker';
|
|
2
|
+
export type PssRule = 'P1' | 'P2' | 'P3' | 'P4' | 'P5' | 'P6' | 'P7' | 'P8' | 'P9' | 'CMP071';
|
|
3
|
+
export interface PssDiagnostic {
|
|
4
|
+
rule: PssRule;
|
|
5
|
+
severity: BorrowSeverity;
|
|
6
|
+
line: number;
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
9
|
+
export interface PssAnalysisResult {
|
|
10
|
+
diagnostics: PssDiagnostic[];
|
|
11
|
+
/** 声明的 PSS 模式(pragma 覆盖后) */
|
|
12
|
+
mode: PssMode;
|
|
13
|
+
}
|
|
14
|
+
/** ★G-43 B5:解析模块级 PSS 声明(文件头 pragma `@proteus-pss: strict`;未声明 → fallback) */
|
|
15
|
+
export declare function resolvePssMode(source: string, fallback?: PssMode): PssMode;
|
|
16
|
+
export interface PssAnalysisOptions {
|
|
17
|
+
mode?: PssMode;
|
|
18
|
+
/** 已分析的 Owned 变量(缺省内部调 analyzeOwnershipSource 获取) */
|
|
19
|
+
ownedVars?: string[];
|
|
20
|
+
}
|
|
21
|
+
/** ★G-43 B5:P1~P9 限制检测 + CMP071 ref(Owned) 拦截 */
|
|
22
|
+
export declare function analyzePss(source: string, opts?: PssAnalysisOptions): PssAnalysisResult;
|
|
23
|
+
export interface ScopeDropInsertion {
|
|
24
|
+
readonly varName: string;
|
|
25
|
+
/** drop 语句插入后所在行号(1-based) */
|
|
26
|
+
readonly line: number;
|
|
27
|
+
}
|
|
28
|
+
export interface ScopeDropResult {
|
|
29
|
+
/** 插入后的源码(无插入 = 原样) */
|
|
30
|
+
readonly code: string;
|
|
31
|
+
readonly insertions: ScopeDropInsertion[];
|
|
32
|
+
}
|
|
33
|
+
/** ★G-43 B5:作用域级自动 drop 插入——函数内未处置的 Owned 在函数闭合前插入 `<var>.drop()` */
|
|
34
|
+
export declare function insertScopeDrops(source: string): ScopeDropResult;
|
|
35
|
+
export interface PssPipelineOptions {
|
|
36
|
+
/** 全局缺省模式(文件头 pragma 可覆盖;缺省 off——渐进采用 §7.1 存量默认) */
|
|
37
|
+
mode?: PssMode;
|
|
38
|
+
/** strict 自动 drop 插入(缺省 true——「业务不写 drop 也能正确释放」) */
|
|
39
|
+
autoDrop?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface PssPipelineResult {
|
|
42
|
+
/** 生效模式(pragma 覆盖后) */
|
|
43
|
+
mode: PssMode;
|
|
44
|
+
/** B 规则(B-01~B-08)+ P 限制(P1~P9/CMP071)诊断合集 */
|
|
45
|
+
diagnostics: Array<BorrowDiagnostic | PssDiagnostic>;
|
|
46
|
+
/** strict + 有 error → 阻断构建 */
|
|
47
|
+
blocksBuild: boolean;
|
|
48
|
+
ownedVars: string[];
|
|
49
|
+
/** autoDrop 后的源码(无插入 = 原样;off 模式 = 原样) */
|
|
50
|
+
code: string;
|
|
51
|
+
insertions: ScopeDropInsertion[];
|
|
52
|
+
}
|
|
53
|
+
/** ★G-43 B5:PSS 管线——B 规则 + P 限制 + 自动 drop 一次跑齐(编译管线在 parse 前调用的独立步骤) */
|
|
54
|
+
export declare function runPss(source: string, opts?: PssPipelineOptions): PssPipelineResult;
|
package/dist/spi.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type BackendId = 'vue-dom' | 'flutter' | 'native-ios' | 'native-android' | 'native-harmony' | 'skyline' | 'skia' | 'canvas2d' | 'headless';
|
|
2
|
+
/** 节点句柄(后端自己的节点表示——DOM 元素 / Flutter Element / 内存树节点……) */
|
|
3
|
+
export type NodeHandle = unknown;
|
|
4
|
+
/** 语义节点描述(IR 层:后端消费的中间表示,不绑定任何平台) */
|
|
5
|
+
export interface IRNode {
|
|
6
|
+
type: string;
|
|
7
|
+
/** ★G-31:语义类型(layout.grid/ui.button/...)——Backend 映射 semantic 而非 tag 字符串;缺省用 type */
|
|
8
|
+
semantic?: string;
|
|
9
|
+
props: Record<string, unknown>;
|
|
10
|
+
children: IRNode[];
|
|
11
|
+
ref?: unknown;
|
|
12
|
+
}
|
|
13
|
+
/** 布局约束(后端可自带布局器,否则走框架 IR 求解) */
|
|
14
|
+
export interface LayoutConstraints {
|
|
15
|
+
width?: number;
|
|
16
|
+
height?: number;
|
|
17
|
+
minWidth?: number;
|
|
18
|
+
maxWidth?: number;
|
|
19
|
+
minHeight?: number;
|
|
20
|
+
maxHeight?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface Size {
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
}
|
|
26
|
+
/** 归一化输入事件(后端把平台事件归一化为 Proteus 标准事件) */
|
|
27
|
+
export interface NormalizedInputEvent {
|
|
28
|
+
kind: 'tap' | 'longPress' | 'scroll' | 'focus' | 'key' | 'pointer';
|
|
29
|
+
pointerType: 'touch' | 'mouse' | 'pen' | 'remote' | 'dial';
|
|
30
|
+
x?: number;
|
|
31
|
+
y?: number;
|
|
32
|
+
key?: string;
|
|
33
|
+
target: NodeHandle;
|
|
34
|
+
}
|
|
35
|
+
/** 外部纹理(混合渲染 Texture Sharing——原生视图混入自绘场景) */
|
|
36
|
+
export interface ExternalTexture {
|
|
37
|
+
id: string;
|
|
38
|
+
nativeView?: unknown;
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
}
|
|
42
|
+
/** 能力声明(对齐 G-22 CapabilityRegistry:框架按能力降级,不按 if/else 判断平台) */
|
|
43
|
+
export interface BackendCapabilities {
|
|
44
|
+
layout: 'yoga' | 'native' | 'none';
|
|
45
|
+
glass: 'L3' | 'L2' | 'L1' | 'none';
|
|
46
|
+
blur: 'true' | 'approximate' | 'none';
|
|
47
|
+
animation: 'native' | 'js' | 'none';
|
|
48
|
+
textureSharing: boolean;
|
|
49
|
+
remoteRendering: boolean;
|
|
50
|
+
ssr: boolean;
|
|
51
|
+
input: Array<'touch' | 'cursor' | 'remote' | 'dial' | 'voice'>;
|
|
52
|
+
}
|
|
53
|
+
/** ★G-27 核心:可插拔渲染后端接口(后端只需实现本接口即可接入任意渲染引擎) */
|
|
54
|
+
export interface ProteusRenderBackend {
|
|
55
|
+
readonly id: BackendId;
|
|
56
|
+
readonly version: string;
|
|
57
|
+
readonly capabilities: BackendCapabilities;
|
|
58
|
+
createElement(node: IRNode): NodeHandle;
|
|
59
|
+
insert(child: NodeHandle, parent: NodeHandle, anchor?: NodeHandle): void;
|
|
60
|
+
remove(child: NodeHandle): void;
|
|
61
|
+
patchProp(el: NodeHandle, key: string, prev: unknown, next: unknown): void;
|
|
62
|
+
setText(el: NodeHandle, text: string): void;
|
|
63
|
+
querySelector?(selector: string): NodeHandle | null;
|
|
64
|
+
measure?(node: NodeHandle, constraints: LayoutConstraints): Size;
|
|
65
|
+
layout?(root: NodeHandle, constraints: LayoutConstraints): void;
|
|
66
|
+
scheduleFrame?(task: () => void): void;
|
|
67
|
+
flush?(): void;
|
|
68
|
+
dispatchInput?(event: NormalizedInputEvent): void;
|
|
69
|
+
onMount?(root: NodeHandle): void;
|
|
70
|
+
onUnmount?(root: NodeHandle): void;
|
|
71
|
+
registerExternalTexture?(id: string, texture: ExternalTexture): void;
|
|
72
|
+
unregisterExternalTexture?(id: string): void;
|
|
73
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { PageOwnership } from './page-ownership';
|
|
2
|
+
import type { OwnershipGraph } from './ownership';
|
|
3
|
+
import type { PageConfig, PageHandle, ProteusHostContainer, QuotaHandle, QuotaManager, ResourcePool, StackPolicy } from './container-spi';
|
|
4
|
+
export interface PoolTimer {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly label: string;
|
|
7
|
+
cleared: boolean;
|
|
8
|
+
cancel(): void;
|
|
9
|
+
}
|
|
10
|
+
export interface ManagedResource {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
released: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** ★G-42.3:框架代管资源池——业务不再裸用 setTimeout/addEventListener */
|
|
15
|
+
export declare function createResourcePool(ownerLabel: string): ResourcePool & {
|
|
16
|
+
readonly total: number;
|
|
17
|
+
};
|
|
18
|
+
export declare function createQuotaManager(limitBytes: number): QuotaManager & {
|
|
19
|
+
attach(scope: string, bytes: number): QuotaHandle | null;
|
|
20
|
+
};
|
|
21
|
+
export interface StackContainerOptions {
|
|
22
|
+
policy?: StackPolicy;
|
|
23
|
+
quotaLimitBytes?: number;
|
|
24
|
+
/** 页面 IR 工厂(config.irId → IR 实例;容器持有但不解析内容——G-42.4) */
|
|
25
|
+
createIR?: (config: PageConfig) => unknown;
|
|
26
|
+
/** ★G-43 B3:所有权图接入——启用后每页创建所有权上下文(G-42 五原子第 3 步委托 G-43 Drop 协议) */
|
|
27
|
+
ownership?: {
|
|
28
|
+
graph: OwnershipGraph;
|
|
29
|
+
/** 页面所有权配额上限(bytes;缺省不限额——destroy 兜底归零仍生效) */
|
|
30
|
+
quotaBytes?: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface StackContainer extends ProteusHostContainer {
|
|
34
|
+
readonly id: 'stack';
|
|
35
|
+
/** 当前栈(不修改只读视图) */
|
|
36
|
+
readonly stackView: readonly PageHandle[];
|
|
37
|
+
/** 内部事件('overflow-destroyed'/'page-destroyed' 等——CMP060 显式事件) */
|
|
38
|
+
events: Record<string, Array<(payload: unknown) => void>>;
|
|
39
|
+
/** ★G-43 B3:页面所有权上下文(ownership 选项启用时可用——业务经它 alloc/登记该页 Owned 资源) */
|
|
40
|
+
ownershipOf(pageId: string): PageOwnership | null;
|
|
41
|
+
}
|
|
42
|
+
/** ★G-42 B2:StackContainer 参考实现(页面栈 + 五原子销毁 + 资源代管 + 深度治理 + keep-alive 配额) */
|
|
43
|
+
export declare function createStackContainer(opts?: StackContainerOptions): StackContainer;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { OwnershipGraph } from './ownership';
|
|
2
|
+
import type { PageOwnership } from './page-ownership';
|
|
3
|
+
import type { BusinessSandbox, ProteusHostContainer, SuperAppPolicy } from './container-spi';
|
|
4
|
+
export interface SandboxExecutionResult<T = unknown> {
|
|
5
|
+
ok: boolean;
|
|
6
|
+
bizId?: string;
|
|
7
|
+
hostAlive?: boolean;
|
|
8
|
+
otherSandboxesAlive?: number;
|
|
9
|
+
error?: string;
|
|
10
|
+
result?: T;
|
|
11
|
+
}
|
|
12
|
+
export interface SuperSandbox extends BusinessSandbox {
|
|
13
|
+
scope: {
|
|
14
|
+
bizId: string;
|
|
15
|
+
values: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
crashCount: number;
|
|
18
|
+
run<T>(fn: () => T): {
|
|
19
|
+
ok: boolean;
|
|
20
|
+
error?: unknown;
|
|
21
|
+
result?: T;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface SuperAppOptions {
|
|
25
|
+
policy?: Partial<SuperAppPolicy>;
|
|
26
|
+
quotaLimitBytes?: number;
|
|
27
|
+
/** ★G-43 B3:所有权图接入 pass-through(页面销毁时该页 Owned 资源 forceDrop——委托内部 StackContainer) */
|
|
28
|
+
ownership?: {
|
|
29
|
+
graph: OwnershipGraph;
|
|
30
|
+
quotaBytes?: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface SuperAppContainer extends ProteusHostContainer {
|
|
34
|
+
readonly id: 'superapp';
|
|
35
|
+
crashLog: Array<{
|
|
36
|
+
bizId: string;
|
|
37
|
+
error: string;
|
|
38
|
+
at: number;
|
|
39
|
+
}>;
|
|
40
|
+
/** 崩溃隔离执行器:业务 fn 抛错 → 捕获 + 事件 + 自动重启,宿主与其他业务不受影响 */
|
|
41
|
+
executeInSandbox<T>(bizId: string, fn: () => T): SandboxExecutionResult<T>;
|
|
42
|
+
readonly sandboxView: readonly SuperSandbox[];
|
|
43
|
+
/** ★G-43 B3:页面所有权上下文(ownership 选项启用时——委托内部 StackContainer) */
|
|
44
|
+
ownershipOf(pageId: string): PageOwnership | null;
|
|
45
|
+
}
|
|
46
|
+
/** ★G-42 B4:SuperAppContainer(业务沙箱 + 崩溃隔离 L1-L3 + 配额 + 安全网关;页面栈委托 StackContainer) */
|
|
47
|
+
export declare function createSuperAppContainer(opts?: SuperAppOptions): SuperAppContainer;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createRenderer } from '@vue/runtime-core';
|
|
2
|
+
import type { RendererOptions } from '@vue/runtime-core';
|
|
3
|
+
import type { NodeHandle } from './spi';
|
|
4
|
+
import { createNodeOpsDispatcher } from './dispatcher';
|
|
5
|
+
import type { ProteusNodeOpsDispatcher } from './dispatcher';
|
|
6
|
+
/** B3 bridge:Dispatcher → Vue RendererOptions(HostNode=HostElement=NodeHandle——后端句柄即 Vue 的"节点") */
|
|
7
|
+
export declare function createVueRendererOptions(dispatch: ProteusNodeOpsDispatcher): RendererOptions<NodeHandle, NodeHandle>;
|
|
8
|
+
export interface ProteusRenderer {
|
|
9
|
+
/** 底层 Dispatcher(换引擎/查 trace/热切换) */
|
|
10
|
+
dispatch: ProteusNodeOpsDispatcher;
|
|
11
|
+
/** 标准 Vue renderer(createRenderer(nodeOps) 产物——createApp/render 均可用) */
|
|
12
|
+
renderer: ReturnType<typeof createRenderer<NodeHandle, NodeHandle>>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 创建 Proteus 渲染器:Dispatcher → Vue RendererOptions → createRenderer
|
|
16
|
+
* const { renderer } = createProteusRenderer(createNodeOpsDispatcher(headlessBackend))
|
|
17
|
+
* renderer.render(h('p-text', { content: '商品 A' }), containerNode) // containerNode = 后端容器句柄
|
|
18
|
+
* 或 renderer.createApp(App).mount(containerNode) // 标准 App 入口
|
|
19
|
+
*/
|
|
20
|
+
export declare function createProteusRenderer(dispatch: ProteusNodeOpsDispatcher): ProteusRenderer;
|
|
21
|
+
/** 便捷:直接给后端就建好 Dispatcher + renderer(省一步 createNodeOpsDispatcher) */
|
|
22
|
+
export declare function createProteusRendererForBackend(backend: Parameters<typeof createNodeOpsDispatcher>[0]): ProteusRenderer;
|