@openuverse/uvapi 0.0.0-stage → 1.1.3
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 +17 -2
- package/dist/_virtual/_commonjsHelpers.js +6 -0
- package/dist/_virtual/index.js +4 -0
- package/dist/api/RestAPIClient.d.ts +191 -0
- package/dist/api/RestAPIClient.js +328 -0
- package/dist/api/WebSocketClient.d.ts +174 -0
- package/dist/api/WebSocketClient.js +277 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/modules/index.d.ts +2 -0
- package/dist/api/modules/task.d.ts +124 -0
- package/dist/api/modules/task.js +121 -0
- package/dist/api/modules/user.d.ts +114 -0
- package/dist/api/modules/user.js +113 -0
- package/dist/config/index.d.ts +120 -0
- package/dist/config/index.js +112 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useAttributeMonitor.d.ts +45 -0
- package/dist/hooks/useAttributeMonitor.js +115 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +93 -0
- package/dist/locale/de-DE.d.ts +18 -0
- package/dist/locale/de-DE.js +20 -0
- package/dist/locale/en-US.d.ts +18 -0
- package/dist/locale/en-US.js +20 -0
- package/dist/locale/es-ES.d.ts +18 -0
- package/dist/locale/es-ES.js +20 -0
- package/dist/locale/fr-FR.d.ts +18 -0
- package/dist/locale/fr-FR.js +20 -0
- package/dist/locale/id-ID.d.ts +18 -0
- package/dist/locale/id-ID.js +20 -0
- package/dist/locale/index.d.ts +19 -0
- package/dist/locale/index.js +70 -0
- package/dist/locale/ja-JP.d.ts +18 -0
- package/dist/locale/ja-JP.js +20 -0
- package/dist/locale/ko-KR.d.ts +18 -0
- package/dist/locale/ko-KR.js +20 -0
- package/dist/locale/pl-PL.d.ts +18 -0
- package/dist/locale/pl-PL.js +20 -0
- package/dist/locale/pt-BR.d.ts +18 -0
- package/dist/locale/pt-BR.js +20 -0
- package/dist/locale/ru-RU.d.ts +18 -0
- package/dist/locale/ru-RU.js +20 -0
- package/dist/locale/th-TH.d.ts +18 -0
- package/dist/locale/th-TH.js +20 -0
- package/dist/locale/zh-CN.d.ts +18 -0
- package/dist/locale/zh-CN.js +20 -0
- package/dist/locale/zh-TW.d.ts +18 -0
- package/dist/locale/zh-TW.js +20 -0
- package/dist/node_modules/@msgpack/msgpack/dist.esm/CachedKeyDecoder.js +38 -0
- package/dist/node_modules/@msgpack/msgpack/dist.esm/DecodeError.js +14 -0
- package/dist/node_modules/@msgpack/msgpack/dist.esm/Decoder.js +474 -0
- package/dist/node_modules/@msgpack/msgpack/dist.esm/Encoder.js +232 -0
- package/dist/node_modules/@msgpack/msgpack/dist.esm/ExtData.js +8 -0
- package/dist/node_modules/@msgpack/msgpack/dist.esm/ExtensionCodec.js +46 -0
- package/dist/node_modules/@msgpack/msgpack/dist.esm/decode.js +7 -0
- package/dist/node_modules/@msgpack/msgpack/dist.esm/encode.js +7 -0
- package/dist/node_modules/@msgpack/msgpack/dist.esm/timestamp.js +66 -0
- package/dist/node_modules/@msgpack/msgpack/dist.esm/utils/int.js +24 -0
- package/dist/node_modules/@msgpack/msgpack/dist.esm/utils/prettyByte.js +6 -0
- package/dist/node_modules/@msgpack/msgpack/dist.esm/utils/typedArrays.js +9 -0
- package/dist/node_modules/@msgpack/msgpack/dist.esm/utils/utf8.js +93 -0
- package/dist/node_modules/axios/index.js +38 -0
- package/dist/node_modules/axios/lib/adapters/adapters.js +55 -0
- package/dist/node_modules/axios/lib/adapters/fetch.js +169 -0
- package/dist/node_modules/axios/lib/adapters/xhr.js +72 -0
- package/dist/node_modules/axios/lib/axios.js +46 -0
- package/dist/node_modules/axios/lib/cancel/CancelToken.js +77 -0
- package/dist/node_modules/axios/lib/cancel/CanceledError.js +11 -0
- package/dist/node_modules/axios/lib/cancel/isCancel.js +6 -0
- package/dist/node_modules/axios/lib/core/Axios.js +136 -0
- package/dist/node_modules/axios/lib/core/AxiosError.js +56 -0
- package/dist/node_modules/axios/lib/core/AxiosHeaders.js +181 -0
- package/dist/node_modules/axios/lib/core/InterceptorManager.js +58 -0
- package/dist/node_modules/axios/lib/core/buildFullPath.js +9 -0
- package/dist/node_modules/axios/lib/core/dispatchRequest.js +31 -0
- package/dist/node_modules/axios/lib/core/mergeConfig.js +70 -0
- package/dist/node_modules/axios/lib/core/settle.js +14 -0
- package/dist/node_modules/axios/lib/core/transformData.js +13 -0
- package/dist/node_modules/axios/lib/defaults/index.js +89 -0
- package/dist/node_modules/axios/lib/defaults/transitional.js +8 -0
- package/dist/node_modules/axios/lib/env/data.js +4 -0
- package/dist/node_modules/axios/lib/helpers/AxiosURLSearchParams.js +33 -0
- package/dist/node_modules/axios/lib/helpers/HttpStatusCode.js +71 -0
- package/dist/node_modules/axios/lib/helpers/bind.js +8 -0
- package/dist/node_modules/axios/lib/helpers/buildURL.js +23 -0
- package/dist/node_modules/axios/lib/helpers/combineURLs.js +6 -0
- package/dist/node_modules/axios/lib/helpers/composeSignals.js +30 -0
- package/dist/node_modules/axios/lib/helpers/cookies.js +32 -0
- package/dist/node_modules/axios/lib/helpers/formDataToJSON.js +31 -0
- package/dist/node_modules/axios/lib/helpers/isAbsoluteURL.js +6 -0
- package/dist/node_modules/axios/lib/helpers/isAxiosError.js +7 -0
- package/dist/node_modules/axios/lib/helpers/isURLSameOrigin.js +8 -0
- package/dist/node_modules/axios/lib/helpers/null.js +4 -0
- package/dist/node_modules/axios/lib/helpers/parseHeaders.js +30 -0
- package/dist/node_modules/axios/lib/helpers/parseProtocol.js +7 -0
- package/dist/node_modules/axios/lib/helpers/progressEventReducer.js +35 -0
- package/dist/node_modules/axios/lib/helpers/resolveConfig.js +33 -0
- package/dist/node_modules/axios/lib/helpers/speedometer.js +19 -0
- package/dist/node_modules/axios/lib/helpers/spread.js +8 -0
- package/dist/node_modules/axios/lib/helpers/throttle.js +15 -0
- package/dist/node_modules/axios/lib/helpers/toFormData.js +85 -0
- package/dist/node_modules/axios/lib/helpers/toURLEncodedForm.js +14 -0
- package/dist/node_modules/axios/lib/helpers/trackStream.js +63 -0
- package/dist/node_modules/axios/lib/helpers/validator.js +54 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/Blob.js +4 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/FormData.js +4 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/URLSearchParams.js +5 -0
- package/dist/node_modules/axios/lib/platform/browser/index.js +15 -0
- package/dist/node_modules/axios/lib/platform/common/utils.js +9 -0
- package/dist/node_modules/axios/lib/platform/index.js +9 -0
- package/dist/node_modules/axios/lib/utils.js +237 -0
- package/dist/node_modules/postcss-pxtorem/index.js +109 -0
- package/dist/node_modules/postcss-pxtorem/lib/filter-prop-list.js +13 -0
- package/dist/node_modules/postcss-pxtorem/lib/pixel-unit-regex.js +7 -0
- package/dist/node_modules/postcss-pxtorem/lib/type.js +14 -0
- package/dist/preload/index.d.ts +125 -0
- package/dist/preload/index.js +79 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/storeFactory.d.ts +584 -0
- package/dist/store/storeFactory.js +216 -0
- package/dist/theme/index.d.ts +1 -0
- package/dist/theme/index.js +14 -0
- package/dist/types/index.d.ts +57 -0
- package/dist/types/uVerseAPI.d.ts +67 -0
- package/dist/utils/_internal.d.ts +14 -0
- package/dist/utils/_internal.js +72 -0
- package/dist/utils/constance.d.ts +16 -0
- package/dist/utils/constance.js +7 -0
- package/dist/utils/index.d.ts +79 -0
- package/dist/utils/index.js +96 -0
- package/dist/utils/logger.d.ts +118 -0
- package/dist/utils/logger.js +170 -0
- package/dist/utils/px2rem/remAdapter.d.ts +17 -0
- package/dist/utils/px2rem/remAdapter.js +62 -0
- package/dist/utils/px2rem/vite.d.ts +14 -0
- package/dist/utils/px2rem/vite.js +33 -0
- package/package.json +102 -4
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { reactive as M, watch as $, toRefs as A } from "vue";
|
|
2
|
+
import { deepClone as n, deepMerge as C } from "../utils/index.js";
|
|
3
|
+
import { logger as i } from "../utils/logger.js";
|
|
4
|
+
function I(o) {
|
|
5
|
+
if (!o)
|
|
6
|
+
return;
|
|
7
|
+
const t = o.lastIndexOf(":");
|
|
8
|
+
return t === -1 ? o : o.substring(t + 1);
|
|
9
|
+
}
|
|
10
|
+
function O(o, t = {}, f) {
|
|
11
|
+
const { onChange: r, deep: a = !0 } = t, u = I(f);
|
|
12
|
+
let h = 0;
|
|
13
|
+
const p = n(o), c = M(n(o)), S = [];
|
|
14
|
+
let y = n(c);
|
|
15
|
+
$(
|
|
16
|
+
() => c,
|
|
17
|
+
(e) => {
|
|
18
|
+
const s = n(e), g = y;
|
|
19
|
+
r == null || r(s, g), S.forEach((w) => {
|
|
20
|
+
try {
|
|
21
|
+
w(s, g);
|
|
22
|
+
} catch (D) {
|
|
23
|
+
i.debug("[uv-api] [Store Factory] 订阅回调执行失败:", D);
|
|
24
|
+
}
|
|
25
|
+
}), y = s;
|
|
26
|
+
},
|
|
27
|
+
{ deep: a }
|
|
28
|
+
);
|
|
29
|
+
const b = () => n(c), l = (e, s) => {
|
|
30
|
+
const g = typeof e == "function" ? e(b()) : e;
|
|
31
|
+
C(c, g), s !== void 0 && (h = s);
|
|
32
|
+
}, m = (e) => {
|
|
33
|
+
e(c);
|
|
34
|
+
}, d = () => {
|
|
35
|
+
Object.keys(p).forEach((e) => {
|
|
36
|
+
c[e] = n(p[e]);
|
|
37
|
+
});
|
|
38
|
+
}, v = (e) => (S.push(e), () => {
|
|
39
|
+
const s = S.indexOf(e);
|
|
40
|
+
s > -1 && S.splice(s, 1);
|
|
41
|
+
}), x = () => h, F = (e) => {
|
|
42
|
+
h = e;
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
id: f,
|
|
46
|
+
attributeGroup: u,
|
|
47
|
+
state: c,
|
|
48
|
+
refs: A(c),
|
|
49
|
+
getState: b,
|
|
50
|
+
setState: l,
|
|
51
|
+
batchUpdate: m,
|
|
52
|
+
reset: d,
|
|
53
|
+
subscribe: v,
|
|
54
|
+
getTimestamp: x,
|
|
55
|
+
setTimestamp: F
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
class _ {
|
|
59
|
+
constructor() {
|
|
60
|
+
this.stores = /* @__PURE__ */ new Map();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 注册一个新的 Store
|
|
64
|
+
*
|
|
65
|
+
* @template T - Store 状态类型
|
|
66
|
+
* @param id - Store 的唯一标识符,支持格式:`${workerId}:${attributeGroup}` 或单独的 `attributeGroup`
|
|
67
|
+
* @param initialState - 初始状态
|
|
68
|
+
* @param options - Store 配置选项(不包含 id)
|
|
69
|
+
* @returns Store 实例
|
|
70
|
+
*
|
|
71
|
+
* @description
|
|
72
|
+
* 创建并注册一个新的 Store 实例。
|
|
73
|
+
* 如果指定的 ID 已存在,会返回已有实例并输出警告。
|
|
74
|
+
* 如果配置了 syncData 函数,会在注册后自动调用一次以获取初始数据。
|
|
75
|
+
*
|
|
76
|
+
* id 格式约定:
|
|
77
|
+
* - 格式 `${workerId}:${attributeGroup}`:用于区分不同 app 的同名属性组
|
|
78
|
+
* - 格式 `${attributeGroup}`:向后兼容,直接使用属性组名称
|
|
79
|
+
*
|
|
80
|
+
* Store 实例会自动解析 attributeGroup:
|
|
81
|
+
* - 如果 id 包含 `:`,则 `store.attributeGroup` 为 `:` 后面的部分
|
|
82
|
+
* - 如果 id 不包含 `:`,则 `store.attributeGroup` 等于 id
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* // 示例1:基础用法(向后兼容)
|
|
87
|
+
* const userStore = manager.register('user', {
|
|
88
|
+
* name: 'John',
|
|
89
|
+
* age: 25
|
|
90
|
+
* }, {
|
|
91
|
+
* onChange: (newState, oldState) => {
|
|
92
|
+
* console.log('用户状态变化')
|
|
93
|
+
* }
|
|
94
|
+
* })
|
|
95
|
+
* // userStore.id = 'user'
|
|
96
|
+
* // userStore.attributeGroup = 'user'
|
|
97
|
+
*
|
|
98
|
+
* // 示例2:区分不同 app 的同名 Store
|
|
99
|
+
* const store = manager.register(
|
|
100
|
+
* `${workerId}:DemoTaskAttributes`, // id 格式:workerId:attributeGroup
|
|
101
|
+
* initialState,
|
|
102
|
+
* {}
|
|
103
|
+
* )
|
|
104
|
+
* // store.id = 'app1:DemoTaskAttributes'
|
|
105
|
+
* // store.attributeGroup = 'DemoTaskAttributes'(用于 API 调用)
|
|
106
|
+
*
|
|
107
|
+
* // 示例3:带数据同步功能
|
|
108
|
+
* const configStore = manager.register('config', {
|
|
109
|
+
* theme: 'light',
|
|
110
|
+
* language: 'zh-CN'
|
|
111
|
+
* }, {
|
|
112
|
+
* syncData: async () => {
|
|
113
|
+
* // 注册时会自动调用此函数获取初始数据
|
|
114
|
+
* const response = await api.action('getConfig')
|
|
115
|
+
* return response.data
|
|
116
|
+
* }
|
|
117
|
+
* })
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
register(t, f, r) {
|
|
121
|
+
if (this.stores.has(t))
|
|
122
|
+
return i.debug(`[uv-api] [Store Factory] Store [${t}] 已存在,将返回已有实例`), this.stores.get(t);
|
|
123
|
+
const a = O(f, r, t);
|
|
124
|
+
return this.stores.set(t, a), i.debug(`[uv-api] [Store Factory] Store [${t}] 注册成功`), r != null && r.syncData && r.syncData().then((u) => {
|
|
125
|
+
a.setState(u), i.debug(`[uv-api] [Store Factory] Store [${t}] syncData 完成`);
|
|
126
|
+
}).catch((u) => {
|
|
127
|
+
i.debug(`[uv-api] [Store Factory] Store [${t}] syncData 失败:`, u);
|
|
128
|
+
}), a;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 根据 ID 获取 Store 实例
|
|
132
|
+
*
|
|
133
|
+
* @template T - Store 状态类型
|
|
134
|
+
* @param id - Store 的唯一标识符
|
|
135
|
+
* @returns Store 实例,如果不存在则返回 undefined
|
|
136
|
+
*
|
|
137
|
+
* @description
|
|
138
|
+
* 通过 ID 查找并返回对应的 Store 实例。
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* // 基础用法
|
|
143
|
+
* const userStore = manager.get<UserState>('user')
|
|
144
|
+
* if (userStore) {
|
|
145
|
+
* console.log(userStore.state.name)
|
|
146
|
+
* }
|
|
147
|
+
*
|
|
148
|
+
* // 获取带 workerId 前缀的 Store
|
|
149
|
+
* const store = manager.get<DemoTaskAttributes>(`${workerId}:DemoTaskAttributes`)
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
get(t) {
|
|
153
|
+
return this.stores.get(t);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* 移除指定 ID 的 Store
|
|
157
|
+
*
|
|
158
|
+
* @param id - Store 的唯一标识符
|
|
159
|
+
* @returns 如果移除成功返回 true,否则返回 false
|
|
160
|
+
*
|
|
161
|
+
* @description
|
|
162
|
+
* 从管理器中移除指定的 Store 实例。
|
|
163
|
+
* 注意:移除后 Store 实例本身仍然可用,只是不再被管理器追踪。
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* // 基础用法
|
|
168
|
+
* const removed = manager.remove('user')
|
|
169
|
+
* console.log(removed) // true 或 false
|
|
170
|
+
*
|
|
171
|
+
* // 移除带 workerId 前缀的 Store
|
|
172
|
+
* manager.remove(`${workerId}:DemoTaskAttributes`)
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
remove(t) {
|
|
176
|
+
return this.stores.delete(t);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* 清空所有已注册的 Store
|
|
180
|
+
*
|
|
181
|
+
* @description
|
|
182
|
+
* 移除管理器中的所有 Store 实例。
|
|
183
|
+
* 注意:已创建的 Store 实例本身仍然可用,只是不再被管理器追踪。
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* manager.clear()
|
|
188
|
+
* console.log(manager.getAllIds()) // []
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
clear() {
|
|
192
|
+
this.stores.clear();
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* 获取所有已注册的 Store ID 列表
|
|
196
|
+
*
|
|
197
|
+
* @returns 所有 Store ID 的数组
|
|
198
|
+
*
|
|
199
|
+
* @description
|
|
200
|
+
* 返回当前管理器中所有已注册 Store 的 ID。
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const ids = manager.getAllIds()
|
|
205
|
+
* console.log(ids) // ['user', 'settings', 'theme']
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
getAllIds() {
|
|
209
|
+
return Array.from(this.stores.keys());
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const j = new _();
|
|
213
|
+
export {
|
|
214
|
+
O as createStore,
|
|
215
|
+
j as storeManager
|
|
216
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const registerThemeEvent: () => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { themeAndI18n4BrowserManager as o } from "../utils/_internal.js";
|
|
2
|
+
const d = () => {
|
|
3
|
+
var t, e, n;
|
|
4
|
+
if (!window.uVerseAPI) {
|
|
5
|
+
o.connectDocumentTheme(document.documentElement);
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
(((t = window.uVerseAPI) == null ? void 0 : t.initialConfig) || {}).theme === "light" ? document.documentElement.setAttribute("theme-mode", "light") : document.documentElement.setAttribute("theme-mode", "dark"), (n = (e = window.uVerseAPI) == null ? void 0 : e.registerThemeChangeEvent) == null || n.call(e, (m) => {
|
|
9
|
+
m === "light" ? document.documentElement.setAttribute("theme-mode", "light") : document.documentElement.setAttribute("theme-mode", "dark");
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
d as registerThemeEvent
|
|
14
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { RequestMetadata, RestAPIConfig } from '../api/RestAPIClient';
|
|
2
|
+
import { WebSocketConfig } from '../api/WebSocketClient';
|
|
3
|
+
import { RemAdapterOptions } from '../utils/px2rem/remAdapter';
|
|
4
|
+
export * from './uVerseAPI';
|
|
5
|
+
export interface PluginOptions {
|
|
6
|
+
appId: string;
|
|
7
|
+
restAPI?: RestAPIConfig;
|
|
8
|
+
websocket?: WebSocketConfig;
|
|
9
|
+
remAdapter?: RemAdapterOptions & {
|
|
10
|
+
enable?: boolean;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface AppBaseConfig {
|
|
14
|
+
appId: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 深度 Partial 类型,递归地将所有属性变为可选
|
|
18
|
+
*
|
|
19
|
+
* @template T - 需要转换的类型
|
|
20
|
+
*
|
|
21
|
+
* @description
|
|
22
|
+
* 该类型工具会递归地将对象的所有嵌套属性变为可选属性。
|
|
23
|
+
* 对于数组类型,会递归处理数组元素的类型。
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* interface User {
|
|
28
|
+
* name: string
|
|
29
|
+
* profile: {
|
|
30
|
+
* age: number
|
|
31
|
+
* address: {
|
|
32
|
+
* city: string
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* // 所有属性都是可选的
|
|
38
|
+
* const partial: DeepPartial<User> = {
|
|
39
|
+
* profile: {
|
|
40
|
+
* address: {
|
|
41
|
+
* city: 'Beijing'
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export type DeepPartial<T> = {
|
|
48
|
+
[P in keyof T]?: T[P] extends object ? T[P] extends Array<infer U> ? Array<DeepPartial<U>> : DeepPartial<T[P]> : T[P];
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* 扩展 Axios 请求配置,添加 metadata 字段
|
|
52
|
+
*/
|
|
53
|
+
declare module 'axios' {
|
|
54
|
+
interface AxiosRequestConfig {
|
|
55
|
+
metadata?: RequestMetadata;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export interface UVerseFileFilter {
|
|
2
|
+
name: string;
|
|
3
|
+
extensions: string[];
|
|
4
|
+
}
|
|
5
|
+
export type UVerseOpenDialogProperty = 'openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles' | 'createDirectory' | 'promptToCreate' | 'dontAddToRecent' | 'noResolveAliases' | 'treatPackageAsDirectory';
|
|
6
|
+
export interface UVerseOpenDialogOptions {
|
|
7
|
+
title?: string;
|
|
8
|
+
defaultPath?: string;
|
|
9
|
+
buttonLabel?: string;
|
|
10
|
+
message?: string;
|
|
11
|
+
filters?: UVerseFileFilter[];
|
|
12
|
+
properties?: UVerseOpenDialogProperty[];
|
|
13
|
+
securityScopedBookmarks?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export type UVerseSaveDialogProperty = 'showHiddenFiles' | 'createDirectory' | 'treatPackageAsDirectory' | 'showOverwriteConfirmation' | 'dontAddToRecent';
|
|
16
|
+
export interface UVerseSaveDialogOptions {
|
|
17
|
+
title?: string;
|
|
18
|
+
defaultPath?: string;
|
|
19
|
+
buttonLabel?: string;
|
|
20
|
+
message?: string;
|
|
21
|
+
nameFieldLabel?: string;
|
|
22
|
+
showsTagField?: boolean;
|
|
23
|
+
filters?: UVerseFileFilter[];
|
|
24
|
+
properties?: UVerseSaveDialogProperty[];
|
|
25
|
+
securityScopedBookmarks?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface UVerseOpenDialogResult {
|
|
28
|
+
canceled: boolean;
|
|
29
|
+
filePaths: string[];
|
|
30
|
+
bookmarks?: string[];
|
|
31
|
+
}
|
|
32
|
+
export interface UVerseSaveDialogResult {
|
|
33
|
+
canceled: boolean;
|
|
34
|
+
filePath?: string;
|
|
35
|
+
bookmark?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface UVerseAPI {
|
|
38
|
+
viewType: 'ELECTRON_BROWSERWINDOW' | 'ELECTRON_WEBCONTENTSVIEW' | 'STANDALONE';
|
|
39
|
+
runningEnvironment: 'UVerse';
|
|
40
|
+
initialConfig: {
|
|
41
|
+
language: string;
|
|
42
|
+
theme: string;
|
|
43
|
+
supported_languages?: Array<{
|
|
44
|
+
name: string;
|
|
45
|
+
key: string;
|
|
46
|
+
}>;
|
|
47
|
+
};
|
|
48
|
+
serverConfig: {
|
|
49
|
+
hostname: string;
|
|
50
|
+
port: string;
|
|
51
|
+
protocol: string;
|
|
52
|
+
mcp_port: string;
|
|
53
|
+
};
|
|
54
|
+
registerLanguageChangeEvent: (callback: (language: string) => void) => () => void;
|
|
55
|
+
registerThemeChangeEvent: (callback: (theme: string) => void) => () => void;
|
|
56
|
+
navTo: (appId: string, url: string) => Promise<{
|
|
57
|
+
success: boolean;
|
|
58
|
+
error?: string;
|
|
59
|
+
errorType?: 'backend-error' | 'start-timeout' | 'unknown-error';
|
|
60
|
+
}>;
|
|
61
|
+
registerAppEvent: (event: string, callback: (...args: any[]) => void) => () => void;
|
|
62
|
+
emitAppEvent: (targetAppId: string, event: string, ...args: any[]) => void;
|
|
63
|
+
sendLog: (level: string, message: string, args: any[], source?: string) => void;
|
|
64
|
+
update: () => void;
|
|
65
|
+
showOpenDialog: (options: UVerseOpenDialogOptions) => Promise<UVerseOpenDialogResult>;
|
|
66
|
+
showSaveDialog: (options: UVerseSaveDialogOptions) => Promise<UVerseSaveDialogResult>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { App } from 'vue';
|
|
2
|
+
import { I18n } from 'vue-i18n';
|
|
3
|
+
export declare class ThemeAndI18n4BrowserManager {
|
|
4
|
+
private i18n;
|
|
5
|
+
private documentElement;
|
|
6
|
+
private theme;
|
|
7
|
+
private locale;
|
|
8
|
+
connectI18nInstance(i18n: I18n): void;
|
|
9
|
+
connectDocumentTheme(documentElement: HTMLElement): void;
|
|
10
|
+
setTheme(theme: string): void;
|
|
11
|
+
setLocale(locale: string): void;
|
|
12
|
+
}
|
|
13
|
+
export declare const themeAndI18n4BrowserManager: ThemeAndI18n4BrowserManager;
|
|
14
|
+
export declare const initBehaviorInBrowser: (app: App) => void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { PLATFORM_INTERNAL_APPIDS as f } from "../config/index.js";
|
|
2
|
+
import { logger as e } from "./logger.js";
|
|
3
|
+
import { WebSocketClient as w } from "../api/WebSocketClient.js";
|
|
4
|
+
import { RestAPIClient as v } from "../api/RestAPIClient.js";
|
|
5
|
+
class M {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.i18n = null, this.documentElement = null, this.theme = "dark", this.locale = "zh-CN";
|
|
8
|
+
}
|
|
9
|
+
connectI18nInstance(o) {
|
|
10
|
+
this.i18n = o, this.i18n.global.locale.value = this.locale;
|
|
11
|
+
}
|
|
12
|
+
connectDocumentTheme(o) {
|
|
13
|
+
this.documentElement = o;
|
|
14
|
+
}
|
|
15
|
+
setTheme(o) {
|
|
16
|
+
this.theme = o, this.documentElement && this.documentElement.setAttribute("theme-mode", this.theme);
|
|
17
|
+
}
|
|
18
|
+
setLocale(o) {
|
|
19
|
+
this.locale = o, this.i18n && (this.i18n.global.locale.value = this.locale);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const d = new M(), k = (i) => {
|
|
23
|
+
if (window.uVerseAPI) {
|
|
24
|
+
e.info("[uv-api] [Browser Mode] 检测到 uVerseAPI,跳过浏览器模式初始化");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
e.info("[uv-api] [Browser Mode] 开始初始化浏览器模式...");
|
|
28
|
+
let o, s = !1;
|
|
29
|
+
const g = new Promise((t) => {
|
|
30
|
+
o = t;
|
|
31
|
+
}), b = i.mount.bind(i);
|
|
32
|
+
i.mount = (...t) => (e.info("[uv-api] [Browser Mode] app.mount 被调用,等待 WebSocket 初始化完成..."), g.then(() => {
|
|
33
|
+
e.info("[uv-api] [Browser Mode] WebSocket 初始化完成,执行实际挂载"), b(...t);
|
|
34
|
+
}), {});
|
|
35
|
+
const a = localStorage.getItem("_uverse-websocket-protocol") || "ws", c = localStorage.getItem("_uverse-websocket-hostname") || "localhost", u = localStorage.getItem("_uverse-websocket-port") || "9898", m = `${a}://${c}:${u}`;
|
|
36
|
+
e.info("[uv-api] [Browser Mode] WebSocket 配置:", { protocol: a, hostname: c, port: u, baseUrl: m });
|
|
37
|
+
const l = new w(f.UVAPP_SRV_DAEMONWORKER, {
|
|
38
|
+
baseURL: m,
|
|
39
|
+
reconnectInterval: 3e3,
|
|
40
|
+
maxReconnectAttempts: 1 / 0
|
|
41
|
+
}), h = (t = 1e3) => {
|
|
42
|
+
if (s) {
|
|
43
|
+
e.debug("[uv-api] [Browser Mode] 已初始化,跳过触发快照");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
e.debug("[uv-api] [Browser Mode] 触发属性快照请求..."), new v({
|
|
47
|
+
baseURL: `${a === "ws" ? "http://" : "https://"}${c}:${u}`,
|
|
48
|
+
workerId: f.UVAPP_SRV_DAEMONWORKER
|
|
49
|
+
}).action("trig_attributes_snapshot", { group_name: "DaemonWorkerAttributes" }).then(() => {
|
|
50
|
+
e.info("[uv-api] [Browser Mode] 触发属性快照请求成功");
|
|
51
|
+
}).catch((n) => {
|
|
52
|
+
s || (e.debug(`[uv-api] [Browser Mode] 触发属性快照失败,将在 ${t}ms 后重试:`, n), setTimeout(() => h(t), t));
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
l.on("open", () => {
|
|
56
|
+
e.info("[uv-api] [Browser Mode] WebSocket 连接成功"), h();
|
|
57
|
+
}), l.on("message", (t) => {
|
|
58
|
+
var p;
|
|
59
|
+
const n = t == null ? void 0 : t.data;
|
|
60
|
+
if (!n || n.group !== "DaemonWorkerAttributes")
|
|
61
|
+
return;
|
|
62
|
+
let r = {};
|
|
63
|
+
n.type === "attribute_snapshot" ? r = ((p = n.attributes) == null ? void 0 : p.platform_config) || {} : n.type === "attribute_change" && n.attribute === "platform_config" && (r = n.value || {}), r.theme && (d.setTheme(r.theme), e.debug(`[uv-api] [Browser Mode] 平台主题已更新: ${r.theme}`)), r.language && (d.setLocale(r.language), e.debug(`[uv-api] [Browser Mode] 平台语言已更新: ${r.language}`)), !s && n.type === "attribute_snapshot" && (s = !0, e.info("[uv-api] [Browser Mode] 初始化完成,解除 app.mount 阻塞"), o());
|
|
64
|
+
}), e.info("[uv-api] [Browser Mode] 开始连接 WebSocket..."), l.connect().catch((t) => {
|
|
65
|
+
e.info("[uv-api] [Browser Mode] 连接 WebSocket 失败:", t);
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
export {
|
|
69
|
+
M as ThemeAndI18n4BrowserManager,
|
|
70
|
+
k as initBehaviorInBrowser,
|
|
71
|
+
d as themeAndI18n4BrowserManager
|
|
72
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const TOKEN_KEY = "rigol_token";
|
|
2
|
+
/**
|
|
3
|
+
* 运行场景枚举
|
|
4
|
+
*/
|
|
5
|
+
export declare enum SceneType {
|
|
6
|
+
/** 独立运行(在浏览器中直接打开) */
|
|
7
|
+
STANDALONE = "STANDALONE",
|
|
8
|
+
/** 在Electron环境中独立的BrowserWindow运行 */
|
|
9
|
+
ELECTRON_BROWSERWINDOW = "ELECTRON_BROWSERWINDOW",
|
|
10
|
+
/** 在Electron环境中WebContentsView运行 */
|
|
11
|
+
ELECTRON_WEBCONTENTSVIEW = "ELECTRON_WEBCONTENTSVIEW"
|
|
12
|
+
}
|
|
13
|
+
export declare enum WsMessageType {
|
|
14
|
+
SNAPSHOT = "attribute_snapshot",
|
|
15
|
+
CHANGE = "attribute_change"
|
|
16
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const t = "rigol_token";
|
|
2
|
+
var N = /* @__PURE__ */ ((E) => (E.STANDALONE = "STANDALONE", E.ELECTRON_BROWSERWINDOW = "ELECTRON_BROWSERWINDOW", E.ELECTRON_WEBCONTENTSVIEW = "ELECTRON_WEBCONTENTSVIEW", E))(N || {}), O = /* @__PURE__ */ ((E) => (E.SNAPSHOT = "attribute_snapshot", E.CHANGE = "attribute_change", E))(O || {});
|
|
3
|
+
export {
|
|
4
|
+
N as SceneType,
|
|
5
|
+
t as TOKEN_KEY,
|
|
6
|
+
O as WsMessageType
|
|
7
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { SceneType } from './constance';
|
|
2
|
+
export { SceneType, WsMessageType, TOKEN_KEY } from './constance';
|
|
3
|
+
export { logger, setLogSource, getLogSource, setLogLevel, getLogLevel, LogLevel } from './logger';
|
|
4
|
+
/**
|
|
5
|
+
* 设置 localStorage 项
|
|
6
|
+
* @param key 键名
|
|
7
|
+
* @param value 值
|
|
8
|
+
*/
|
|
9
|
+
export declare function setLocalStorage(key: string, value: string): void;
|
|
10
|
+
/**
|
|
11
|
+
* 获取 localStorage 项
|
|
12
|
+
* @param key 键名
|
|
13
|
+
* @param defaultValue 默认值
|
|
14
|
+
* @returns 字符串值或默认值
|
|
15
|
+
*/
|
|
16
|
+
export declare function getLocalStorage(key: string, defaultValue?: string): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* 删除 localStorage 项
|
|
19
|
+
* @param key 键名
|
|
20
|
+
*/
|
|
21
|
+
export declare function removeLocalStorage(key: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* 清空 localStorage
|
|
24
|
+
*/
|
|
25
|
+
export declare function clearLocalStorage(): void;
|
|
26
|
+
/**
|
|
27
|
+
* 设置 sessionStorage 项
|
|
28
|
+
* @param key 键名
|
|
29
|
+
* @param value 值
|
|
30
|
+
*/
|
|
31
|
+
export declare function setSessionStorage(key: string, value: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* 获取 sessionStorage 项
|
|
34
|
+
* @param key 键名
|
|
35
|
+
* @param defaultValue 默认值
|
|
36
|
+
* @returns 字符串值或默认值
|
|
37
|
+
*/
|
|
38
|
+
export declare function getSessionStorage(key: string, defaultValue?: string): string | null;
|
|
39
|
+
/**
|
|
40
|
+
* 删除 sessionStorage 项
|
|
41
|
+
* @param key 键名
|
|
42
|
+
*/
|
|
43
|
+
export declare function removeSessionStorage(key: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* 清空 sessionStorage
|
|
46
|
+
*/
|
|
47
|
+
export declare function clearSessionStorage(): void;
|
|
48
|
+
/**
|
|
49
|
+
* 获取当前运行环境所在场景
|
|
50
|
+
* @returns 返回当前场景类型
|
|
51
|
+
*/
|
|
52
|
+
export declare function getCurrentScene(): SceneType;
|
|
53
|
+
/**
|
|
54
|
+
* 深拷贝对象
|
|
55
|
+
* @param obj 需要深拷贝的对象
|
|
56
|
+
* @returns 深拷贝后的新对象
|
|
57
|
+
*/
|
|
58
|
+
export declare function deepClone<T>(obj: T): T;
|
|
59
|
+
/**
|
|
60
|
+
* 深度合并对象
|
|
61
|
+
*
|
|
62
|
+
* @param target - 目标对象(会被修改)
|
|
63
|
+
* @param source - 源对象(提供新值)
|
|
64
|
+
*
|
|
65
|
+
* @description
|
|
66
|
+
* 递归地将源对象的属性合并到目标对象中:
|
|
67
|
+
* - 对于嵌套对象:递归合并,不会覆盖未指定的属性
|
|
68
|
+
* - 对于数组和基本类型:直接替换
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const target = { a: 1, b: { c: 2, d: 3 } }
|
|
73
|
+
* const source = { b: { c: 4 } }
|
|
74
|
+
* deepMerge(target, source)
|
|
75
|
+
* // 结果: { a: 1, b: { c: 4, d: 3 } }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function deepMerge(target: any, source: any): void;
|
|
79
|
+
export declare function getDisplayValue(key: string, language: string, app: Record<string, any>): string;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { SceneType as a } from "./constance.js";
|
|
2
|
+
import { TOKEN_KEY as A, WsMessageType as C } from "./constance.js";
|
|
3
|
+
function S(e, t) {
|
|
4
|
+
try {
|
|
5
|
+
window.localStorage.setItem(e, t);
|
|
6
|
+
} catch {
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function w(e, t) {
|
|
10
|
+
try {
|
|
11
|
+
return window.localStorage.getItem(e);
|
|
12
|
+
} catch {
|
|
13
|
+
return t || null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function f(e) {
|
|
17
|
+
try {
|
|
18
|
+
window.localStorage.removeItem(e);
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function E() {
|
|
23
|
+
try {
|
|
24
|
+
window.localStorage.clear();
|
|
25
|
+
} catch {
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function p(e, t) {
|
|
29
|
+
try {
|
|
30
|
+
window.sessionStorage.setItem(e, t);
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function y(e, t) {
|
|
35
|
+
try {
|
|
36
|
+
return window.sessionStorage.getItem(e);
|
|
37
|
+
} catch {
|
|
38
|
+
return t || null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function d(e) {
|
|
42
|
+
try {
|
|
43
|
+
window.sessionStorage.removeItem(e);
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function O() {
|
|
48
|
+
try {
|
|
49
|
+
window.sessionStorage.clear();
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function m() {
|
|
54
|
+
var t, r, o, n;
|
|
55
|
+
if (!!(window.navigator.userAgent.includes("Electron") || (r = (t = window.process) == null ? void 0 : t.versions) != null && r.electron)) {
|
|
56
|
+
if (((o = window.uVerseAPI) == null ? void 0 : o.viewType) === a.ELECTRON_BROWSERWINDOW)
|
|
57
|
+
return a.ELECTRON_BROWSERWINDOW;
|
|
58
|
+
if (((n = window.uVerseAPI) == null ? void 0 : n.viewType) === a.ELECTRON_WEBCONTENTSVIEW)
|
|
59
|
+
return a.ELECTRON_WEBCONTENTSVIEW;
|
|
60
|
+
}
|
|
61
|
+
return a.STANDALONE;
|
|
62
|
+
}
|
|
63
|
+
function N(e) {
|
|
64
|
+
return JSON.parse(JSON.stringify(e));
|
|
65
|
+
}
|
|
66
|
+
function g(e, t) {
|
|
67
|
+
Object.keys(t).forEach((r) => {
|
|
68
|
+
const o = t[r], n = e[r];
|
|
69
|
+
o && typeof o == "object" && !Array.isArray(o) && n && typeof n == "object" && !Array.isArray(n) ? g(n, o) : e[r] = o;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function T(e, t, r) {
|
|
73
|
+
var s;
|
|
74
|
+
const o = r.appconfig || {}, n = t.replace(/[^a-zA-Z]/g, "").toLowerCase(), c = {};
|
|
75
|
+
return Object.keys(o.display || {}).forEach((i) => {
|
|
76
|
+
const l = i.replace(/[^a-zA-Z]/g, "").toLowerCase();
|
|
77
|
+
c[l] = o.display[i];
|
|
78
|
+
}), ((s = c[n]) == null ? void 0 : s[e]) || o[e] || r[e] || "";
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
a as SceneType,
|
|
82
|
+
A as TOKEN_KEY,
|
|
83
|
+
C as WsMessageType,
|
|
84
|
+
E as clearLocalStorage,
|
|
85
|
+
O as clearSessionStorage,
|
|
86
|
+
N as deepClone,
|
|
87
|
+
g as deepMerge,
|
|
88
|
+
m as getCurrentScene,
|
|
89
|
+
T as getDisplayValue,
|
|
90
|
+
w as getLocalStorage,
|
|
91
|
+
y as getSessionStorage,
|
|
92
|
+
f as removeLocalStorage,
|
|
93
|
+
d as removeSessionStorage,
|
|
94
|
+
S as setLocalStorage,
|
|
95
|
+
p as setSessionStorage
|
|
96
|
+
};
|