translime-sdk 1.0.1 → 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/dist/index.cjs CHANGED
@@ -1,98 +1,263 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const previewMock = require("./preview-mock.cjs");
4
- if (typeof window !== "undefined" && previewMock.isPreviewMode()) {
5
- previewMock.initPreviewMock();
2
+ const require_preview_mock = require("./preview-mock.cjs");
3
+ //#region src/electronNetAdapter.js
4
+ function createRequestId() {
5
+ if (typeof globalThis !== "undefined" && globalThis.crypto?.randomUUID) return globalThis.crypto.randomUUID();
6
+ return `ts-net-${Date.now()}-${Math.random().toString(16).slice(2)}`;
6
7
  }
8
+ function createRequestMeta(requestConfig) {
9
+ const url = new URL(requestConfig.url);
10
+ return {
11
+ _options: requestConfig,
12
+ method: requestConfig.method,
13
+ path: url.pathname,
14
+ protocol: url.protocol,
15
+ host: url.host,
16
+ hostname: url.hostname
17
+ };
18
+ }
19
+ function createNetworkError(message, config, requestConfig, cause) {
20
+ const error = new Error(message || "Network Error");
21
+ error.code = "ERR_NETWORK";
22
+ error.config = config;
23
+ error.request = createRequestMeta(requestConfig);
24
+ if (cause) error.cause = cause;
25
+ return error;
26
+ }
27
+ function normalizeHeaders(headers) {
28
+ if (!headers) return;
29
+ return Object.fromEntries(Object.entries(headers).filter(([, value]) => value != null));
30
+ }
31
+ function buildRequestConfig(config) {
32
+ const baseURL = config.baseURL ? config.baseURL.replace(/\/+$/, "") : "";
33
+ const url = new URL(config.url, baseURL || void 0).toString();
34
+ return {
35
+ method: config.method?.toUpperCase() || "GET",
36
+ url,
37
+ headers: normalizeHeaders(config.headers),
38
+ data: config.data,
39
+ responseType: config.responseType
40
+ };
41
+ }
42
+ function buildPreviewOptions(requestConfig) {
43
+ return {
44
+ method: requestConfig.method,
45
+ headers: requestConfig.headers,
46
+ body: requestConfig.data
47
+ };
48
+ }
49
+ async function electronNetAdapter(config) {
50
+ const net = typeof window !== "undefined" ? window.ts?.net : null;
51
+ if (!net?.request) throw createNetworkError("window.ts.net.request is not available", config, {
52
+ method: config.method?.toUpperCase() || "GET",
53
+ url: new URL(config.url, config.baseURL || void 0).toString()
54
+ });
55
+ const requestId = createRequestId();
56
+ const requestConfig = buildRequestConfig(config);
57
+ const requestMeta = createRequestMeta(requestConfig);
58
+ if (config.signal && typeof net.abort === "function") config.signal.addEventListener("abort", () => {
59
+ net.abort(requestId);
60
+ }, { once: true });
61
+ try {
62
+ let response;
63
+ try {
64
+ response = await net.request(requestId, requestConfig);
65
+ } catch (error) {
66
+ response = await net.request(requestConfig.url, buildPreviewOptions(requestConfig));
67
+ if (response?.ok === false && !response.status) throw error;
68
+ }
69
+ return {
70
+ data: response?.data,
71
+ status: response?.status,
72
+ statusText: response?.statusText || "",
73
+ headers: response?.headers || {},
74
+ config,
75
+ request: requestMeta
76
+ };
77
+ } catch (error) {
78
+ throw createNetworkError(error.message, config, requestConfig, error);
79
+ }
80
+ }
81
+ //#endregion
82
+ //#region src/index.js
83
+ /**
84
+ * Translime SDK
85
+ * 提供插件开发所需的标准 API 和类型提示。
86
+ * 包含主进程 (Main Process) 和渲染进程 (Renderer Process) 的通用接口。
87
+ */
88
+ var CLIPBOARD_IPC = {
89
+ readText: "read-clipboard-text",
90
+ writeText: "copy-text"
91
+ };
92
+ if (typeof window !== "undefined" && require_preview_mock.isPreviewMode()) require_preview_mock.initPreviewMock();
93
+ /**
94
+ * 检查当前是否为 Preview 模式
95
+ * @returns {boolean}
96
+ */
7
97
  function isPreviewMode() {
8
- return previewMock.isPreviewMode();
98
+ return require_preview_mock.isPreviewMode();
9
99
  }
100
+ /**
101
+ * @typedef {Object} MainStore
102
+ * @property {Object} config
103
+ * @property {function(string, *): *} config.get
104
+ * @property {function(string, *): void} config.set
105
+ * @property {Object} [logger]
106
+ */
107
+ /**
108
+ * 获取主程序 Store
109
+ * @description 仅在 **主进程 (Main Process)** 环境可用
110
+ * @returns {MainStore|null} 若在非主进程环境调用,返回 null
111
+ */
10
112
  function getMainStore() {
11
- if (typeof global !== "undefined" && global.mainStore) {
12
- return global.mainStore;
13
- }
14
- return null;
113
+ if (typeof global !== "undefined" && global.mainStore) return global.mainStore;
114
+ return null;
15
115
  }
116
+ /**
117
+ * 使用插件配置代理
118
+ * @description 获取针对特定插件的配置读写对象
119
+ * @param {string} pluginId 插件 ID (通常与 package.json 中的 name 一致)
120
+ * @returns {{ get: function(string, *): *, set: function(string, *): void }}
121
+ */
16
122
  function usePluginConfig(pluginId) {
17
- const store = getMainStore();
18
- return {
19
- get(key, defaultValue) {
20
- return store?.config?.get(`plugin.${pluginId}.settings.${key}`, defaultValue);
21
- },
22
- set(key, value) {
23
- store?.config?.set(`plugin.${pluginId}.settings.${key}`, value);
24
- }
25
- };
123
+ const store = getMainStore();
124
+ return {
125
+ get(key, defaultValue) {
126
+ return store?.config?.get(`plugin.${pluginId}.settings.${key}`, defaultValue);
127
+ },
128
+ set(key, value) {
129
+ store?.config?.set(`plugin.${pluginId}.settings.${key}`, value);
130
+ }
131
+ };
132
+ }
133
+ /**
134
+ * 获取插件间通信工具
135
+ * @description 仅在 **主进程 (Main Process)** 环境可用
136
+ * @returns {import('./index.d').PluginInterop|null}
137
+ */
138
+ function usePluginInterop() {
139
+ if (typeof global !== "undefined" && global.pluginInterop) return global.pluginInterop;
140
+ return null;
26
141
  }
142
+ /**
143
+ * 获取 IPC 通信工具
144
+ * @description 仅在 **渲染进程 (Renderer Process)** 环境可用
145
+ * @returns {Object|null} 包含 invoke, send, on 等方法的对象
146
+ */
27
147
  function useIpc() {
28
- if (typeof window !== "undefined" && window.electron?.useIpc) {
29
- return window.electron.useIpc();
30
- }
31
- return null;
148
+ if (typeof window !== "undefined" && window.electron?.useIpc) return window.electron.useIpc();
149
+ return null;
32
150
  }
151
+ /**
152
+ * 获取 Vuetify 实例
153
+ * @description 仅在 **渲染进程** 环境可用,用于访问 Vuetify 的全局配置
154
+ * @returns {Object} Vuetify 实例对象
155
+ */
33
156
  function useVuetify() {
34
- if (typeof window !== "undefined" && window.vuetify$) {
35
- return window.vuetify$;
36
- }
37
- return {};
157
+ if (typeof window !== "undefined" && window.vuetify$) return window.vuetify$;
158
+ return {};
38
159
  }
160
+ /**
161
+ * 获取全局注册的 Vuetify 组件
162
+ * @returns {Record<string, any>}
163
+ */
39
164
  function useVuetifyComponents() {
40
- return useVuetify().components || {};
165
+ return useVuetify().components || {};
41
166
  }
167
+ /**
168
+ * 获取全局注册的 Vuetify 指令
169
+ * @returns {Record<string, any>}
170
+ */
42
171
  function useVuetifyDirectives() {
43
- return useVuetify().directives || {};
172
+ return useVuetify().directives || {};
44
173
  }
174
+ /**
175
+ * 获取 Dialog API
176
+ * @description 类似于 Electron 的 dialog 模块 (showOpenDialog, showSaveDialog 等)
177
+ * @returns {Object|null}
178
+ */
45
179
  function useDialog() {
46
- if (typeof window !== "undefined" && window.electron?.dialog) {
47
- return window.electron.dialog;
48
- }
49
- return null;
180
+ if (typeof window !== "undefined" && window.electron?.dialog) return window.electron.dialog;
181
+ return null;
50
182
  }
183
+ /**
184
+ * 获取 Shell API
185
+ * @description 类似于 Electron 的 shell 模块 (openExternal, showItemInFolder 等)
186
+ * @returns {Object|null}
187
+ */
51
188
  function useShell() {
52
- if (typeof window !== "undefined" && window.electron?.shell) {
53
- return window.electron.shell;
54
- }
55
- return null;
189
+ if (typeof window !== "undefined" && window.electron?.shell) return window.electron.shell;
190
+ return null;
56
191
  }
192
+ /**
193
+ * 获取插件自身设置 (IPC 封装)
194
+ * @description 仅在 **渲染进程** 环境可用。这是 `plugin.settings` 的前端读取接口。
195
+ * @param {...any} args
196
+ * @returns {Promise<any>}
197
+ */
57
198
  async function getPluginSetting(...args) {
58
- if (typeof window !== "undefined" && window.ts?.getPluginSetting) {
59
- return window.ts.getPluginSetting(...args);
60
- }
61
- return null;
199
+ if (typeof window !== "undefined" && window.ts?.getPluginSetting) return window.ts.getPluginSetting(...args);
200
+ return null;
62
201
  }
202
+ /**
203
+ * 更新插件自身设置 (IPC 封装)
204
+ * @description 仅在 **渲染进程** 环境可用。
205
+ * @param {...any} args
206
+ * @returns {Promise<any>}
207
+ */
63
208
  async function setPluginSetting(...args) {
64
- if (typeof window !== "undefined" && window.ts?.setPluginSetting) {
65
- return window.ts.setPluginSetting(...args);
66
- }
67
- return null;
209
+ if (typeof window !== "undefined" && window.ts?.setPluginSetting) return window.ts.setPluginSetting(...args);
210
+ return null;
68
211
  }
212
+ /**
213
+ * 获取窗口控制工具
214
+ * @description 包含 minimize, maximize, close 等窗口操作
215
+ * @returns {Object|null}
216
+ */
69
217
  function useWindowControl() {
70
- if (typeof window !== "undefined" && window.ts?.windowControl) {
71
- return window.ts.windowControl;
72
- }
73
- return null;
218
+ if (typeof window !== "undefined" && window.ts?.windowControl) return window.ts.windowControl;
219
+ return null;
74
220
  }
221
+ /**
222
+ * 获取剪贴板工具
223
+ * @returns {Object|null}
224
+ */
75
225
  function useClipboard() {
76
- if (typeof window !== "undefined" && window.electron?.clipboard) {
77
- return window.electron.clipboard;
78
- }
79
- return null;
226
+ if (typeof window !== "undefined") return {
227
+ async readText() {
228
+ if (window.electron?.useIpc) return window.electron.useIpc().invoke(CLIPBOARD_IPC.readText);
229
+ if (navigator.clipboard?.readText) return navigator.clipboard.readText();
230
+ return null;
231
+ },
232
+ async writeText(text) {
233
+ if (window.electron?.useIpc) return window.electron.useIpc().invoke(CLIPBOARD_IPC.writeText, text);
234
+ if (navigator.clipboard?.writeText) return navigator.clipboard.writeText(text);
235
+ return null;
236
+ }
237
+ };
238
+ return null;
80
239
  }
240
+ /**
241
+ * 在默认浏览器中打开链接
242
+ * @param {string} url 要打开的链接
243
+ * @returns {Promise<void>}
244
+ */
81
245
  async function openLink(...args) {
82
- if (typeof window !== "undefined" && window.electron?.openLink) {
83
- return window.electron.openLink(...args);
84
- }
85
- return null;
246
+ if (typeof window !== "undefined" && window.electron?.openLink) return window.electron.openLink(...args);
247
+ return null;
86
248
  }
249
+ /**
250
+ * 获取日志工具
251
+ * @description 自动适配 Node.js 环境 (Main) 或浏览器环境 (Renderer)
252
+ * @returns {Record<'log'|'info'|'warn'|'error'|'debug', Function>} Console-like logger
253
+ */
87
254
  function useLogger() {
88
- if (typeof global !== "undefined" && global.mainStore) {
89
- return global.mainStore?.logger || console;
90
- }
91
- if (typeof window !== "undefined") {
92
- return window.ts?.logger || console;
93
- }
94
- return console;
255
+ if (typeof global !== "undefined" && global.mainStore) return global.mainStore?.logger || console;
256
+ if (typeof window !== "undefined") return window.ts?.logger || console;
257
+ return console;
95
258
  }
259
+ //#endregion
260
+ exports.electronNetAdapter = electronNetAdapter;
96
261
  exports.getMainStore = getMainStore;
97
262
  exports.getPluginSetting = getPluginSetting;
98
263
  exports.isPreviewMode = isPreviewMode;
@@ -103,9 +268,11 @@ exports.useDialog = useDialog;
103
268
  exports.useIpc = useIpc;
104
269
  exports.useLogger = useLogger;
105
270
  exports.usePluginConfig = usePluginConfig;
271
+ exports.usePluginInterop = usePluginInterop;
106
272
  exports.useShell = useShell;
107
273
  exports.useVuetify = useVuetify;
108
274
  exports.useVuetifyComponents = useVuetifyComponents;
109
275
  exports.useVuetifyDirectives = useVuetifyDirectives;
110
276
  exports.useWindowControl = useWindowControl;
111
- //# sourceMappingURL=index.cjs.map
277
+
278
+ //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["/**\n * Translime SDK\n * 提供插件开发所需的标准 API 和类型提示。\n * 包含主进程 (Main Process) 和渲染进程 (Renderer Process) 的通用接口。\n */\n\nimport {\n isPreviewMode as checkPreviewMode,\n initPreviewMock,\n} from './preview-mock.js';\n\n// ----------------------------------------------------------------------\n// Initialization (Side Effect)\n// ----------------------------------------------------------------------\n\n// 在模块加载时检测并初始化 Preview Mock 环境\n// 确保在 Preview 模式下直接导入 SDK 也能获得 Mock 支持\nif (typeof window !== 'undefined' && checkPreviewMode()) {\n initPreviewMock();\n}\n\n// ----------------------------------------------------------------------\n// Core / Store APIs (Main Process Only)\n// ----------------------------------------------------------------------\n\n/**\n * 检查当前是否为 Preview 模式\n * @returns {boolean}\n */\nexport function isPreviewMode() {\n return checkPreviewMode();\n}\n\n/**\n * @typedef {Object} MainStore\n * @property {Object} config\n * @property {function(string, *): *} config.get\n * @property {function(string, *): void} config.set\n * @property {Object} [logger]\n */\n\n/**\n * 获取主程序 Store\n * @description 仅在 **主进程 (Main Process)** 环境可用\n * @returns {MainStore|null} 若在非主进程环境调用,返回 null\n */\nexport function getMainStore() {\n if (typeof global !== 'undefined' && global.mainStore) {\n return global.mainStore;\n }\n return null;\n}\n\n/**\n * 使用插件配置代理\n * @description 获取针对特定插件的配置读写对象\n * @param {string} pluginId 插件 ID (通常与 package.json 中的 name 一致)\n * @returns {{ get: function(string, *): *, set: function(string, *): void }}\n */\nexport function usePluginConfig(pluginId) {\n const store = getMainStore();\n return {\n get(key, defaultValue) {\n return store?.config?.get(`plugin.${pluginId}.settings.${key}`, defaultValue);\n },\n set(key, value) {\n store?.config?.set(`plugin.${pluginId}.settings.${key}`, value);\n },\n };\n}\n\n// ----------------------------------------------------------------------\n// UI & Renderer APIs (Renderer Process Only)\n// ----------------------------------------------------------------------\n\n/**\n * 获取 IPC 通信工具\n * @description 仅在 **渲染进程 (Renderer Process)** 环境可用\n * @returns {Object|null} 包含 invoke, send, on 等方法的对象\n */\nexport function useIpc() {\n if (typeof window !== 'undefined' && window.electron?.useIpc) {\n return window.electron.useIpc();\n }\n return null;\n}\n\n/**\n * 获取 Vuetify 实例\n * @description 仅在 **渲染进程** 环境可用,用于访问 Vuetify 的全局配置\n * @returns {Object} Vuetify 实例对象\n */\nexport function useVuetify() {\n if (typeof window !== 'undefined' && window.vuetify$) {\n return window.vuetify$;\n }\n return {};\n}\n\n/**\n * 获取全局注册的 Vuetify 组件\n * @returns {Record<string, any>}\n */\nexport function useVuetifyComponents() {\n return useVuetify().components || {};\n}\n\n/**\n * 获取全局注册的 Vuetify 指令\n * @returns {Record<string, any>}\n */\nexport function useVuetifyDirectives() {\n return useVuetify().directives || {};\n}\n\n/**\n * 获取 Dialog API\n * @description 类似于 Electron 的 dialog 模块 (showOpenDialog, showSaveDialog 等)\n * @returns {Object|null}\n */\nexport function useDialog() {\n if (typeof window !== 'undefined' && window.electron?.dialog) {\n return window.electron.dialog;\n }\n return null;\n}\n\n/**\n * 获取 Shell API\n * @description 类似于 Electron 的 shell 模块 (openExternal, showItemInFolder 等)\n * @returns {Object|null}\n */\nexport function useShell() {\n if (typeof window !== 'undefined' && window.electron?.shell) {\n return window.electron.shell;\n }\n return null;\n}\n\n/**\n * 获取插件自身设置 (IPC 封装)\n * @description 仅在 **渲染进程** 环境可用。这是 `plugin.settings` 的前端读取接口。\n * @param {...any} args\n * @returns {Promise<any>}\n */\nexport async function getPluginSetting(...args) {\n if (typeof window !== 'undefined' && window.ts?.getPluginSetting) {\n return window.ts.getPluginSetting(...args);\n }\n return null;\n}\n\n/**\n * 更新插件自身设置 (IPC 封装)\n * @description 仅在 **渲染进程** 环境可用。\n * @param {...any} args\n * @returns {Promise<any>}\n */\nexport async function setPluginSetting(...args) {\n if (typeof window !== 'undefined' && window.ts?.setPluginSetting) {\n return window.ts.setPluginSetting(...args);\n }\n return null;\n}\n\n/**\n * 获取窗口控制工具\n * @description 包含 minimize, maximize, close 等窗口操作\n * @returns {Object|null}\n */\nexport function useWindowControl() {\n if (typeof window !== 'undefined' && window.ts?.windowControl) {\n return window.ts.windowControl;\n }\n return null;\n}\n\n// ----------------------------------------------------------------------\n// Utilities (Shared)\n// ----------------------------------------------------------------------\n\n/**\n * 获取剪贴板工具\n * @returns {Object|null}\n */\nexport function useClipboard() {\n if (typeof window !== 'undefined' && window.electron?.clipboard) {\n return window.electron.clipboard;\n }\n return null;\n}\n\n/**\n * 在默认浏览器中打开链接\n * @param {string} url 要打开的链接\n * @returns {Promise<void>}\n */\nexport async function openLink(...args) {\n if (typeof window !== 'undefined' && window.electron?.openLink) {\n return window.electron.openLink(...args);\n }\n return null;\n}\n\n/**\n * 获取日志工具\n * @description 自动适配 Node.js 环境 (Main) 或浏览器环境 (Renderer)\n * @returns {Record<'log'|'info'|'warn'|'error'|'debug', Function>} Console-like logger\n */\nexport function useLogger() {\n if (typeof global !== 'undefined' && global.mainStore) {\n return global.mainStore?.logger || console;\n }\n if (typeof window !== 'undefined') {\n return window.ts?.logger || console;\n }\n return console;\n}\n\n"],"names":["checkPreviewMode","initPreviewMock"],"mappings":";;;AAiBA,IAAI,OAAO,WAAW,eAAeA,YAAAA,iBAAoB;AACvDC,8BAAe;AACjB;AAUO,SAAS,gBAAgB;AAC9B,SAAOD,0BAAgB;AACzB;AAeO,SAAS,eAAe;AAC7B,MAAI,OAAO,WAAW,eAAe,OAAO,WAAW;AACrD,WAAO,OAAO;AAAA,EAChB;AACA,SAAO;AACT;AAQO,SAAS,gBAAgB,UAAU;AACxC,QAAM,QAAQ,aAAY;AAC1B,SAAO;AAAA,IACL,IAAI,KAAK,cAAc;AACrB,aAAO,OAAO,QAAQ,IAAI,UAAU,QAAQ,aAAa,GAAG,IAAI,YAAY;AAAA,IAC9E;AAAA,IACA,IAAI,KAAK,OAAO;AACd,aAAO,QAAQ,IAAI,UAAU,QAAQ,aAAa,GAAG,IAAI,KAAK;AAAA,IAChE;AAAA,EACJ;AACA;AAWO,SAAS,SAAS;AACvB,MAAI,OAAO,WAAW,eAAe,OAAO,UAAU,QAAQ;AAC5D,WAAO,OAAO,SAAS,OAAM;AAAA,EAC/B;AACA,SAAO;AACT;AAOO,SAAS,aAAa;AAC3B,MAAI,OAAO,WAAW,eAAe,OAAO,UAAU;AACpD,WAAO,OAAO;AAAA,EAChB;AACA,SAAO,CAAA;AACT;AAMO,SAAS,uBAAuB;AACrC,SAAO,WAAU,EAAG,cAAc,CAAA;AACpC;AAMO,SAAS,uBAAuB;AACrC,SAAO,WAAU,EAAG,cAAc,CAAA;AACpC;AAOO,SAAS,YAAY;AAC1B,MAAI,OAAO,WAAW,eAAe,OAAO,UAAU,QAAQ;AAC5D,WAAO,OAAO,SAAS;AAAA,EACzB;AACA,SAAO;AACT;AAOO,SAAS,WAAW;AACzB,MAAI,OAAO,WAAW,eAAe,OAAO,UAAU,OAAO;AAC3D,WAAO,OAAO,SAAS;AAAA,EACzB;AACA,SAAO;AACT;AAQO,eAAe,oBAAoB,MAAM;AAC9C,MAAI,OAAO,WAAW,eAAe,OAAO,IAAI,kBAAkB;AAChE,WAAO,OAAO,GAAG,iBAAiB,GAAG,IAAI;AAAA,EAC3C;AACA,SAAO;AACT;AAQO,eAAe,oBAAoB,MAAM;AAC9C,MAAI,OAAO,WAAW,eAAe,OAAO,IAAI,kBAAkB;AAChE,WAAO,OAAO,GAAG,iBAAiB,GAAG,IAAI;AAAA,EAC3C;AACA,SAAO;AACT;AAOO,SAAS,mBAAmB;AACjC,MAAI,OAAO,WAAW,eAAe,OAAO,IAAI,eAAe;AAC7D,WAAO,OAAO,GAAG;AAAA,EACnB;AACA,SAAO;AACT;AAUO,SAAS,eAAe;AAC7B,MAAI,OAAO,WAAW,eAAe,OAAO,UAAU,WAAW;AAC/D,WAAO,OAAO,SAAS;AAAA,EACzB;AACA,SAAO;AACT;AAOO,eAAe,YAAY,MAAM;AACtC,MAAI,OAAO,WAAW,eAAe,OAAO,UAAU,UAAU;AAC9D,WAAO,OAAO,SAAS,SAAS,GAAG,IAAI;AAAA,EACzC;AACA,SAAO;AACT;AAOO,SAAS,YAAY;AAC1B,MAAI,OAAO,WAAW,eAAe,OAAO,WAAW;AACrD,WAAO,OAAO,WAAW,UAAU;AAAA,EACrC;AACA,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO,OAAO,IAAI,UAAU;AAAA,EAC9B;AACA,SAAO;AACT;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","names":["checkPreviewMode"],"sources":["../src/electronNetAdapter.js","../src/index.js"],"sourcesContent":["function createRequestId() {\r\n if (typeof globalThis !== 'undefined' && globalThis.crypto?.randomUUID) {\r\n return globalThis.crypto.randomUUID();\r\n }\r\n\r\n return `ts-net-${Date.now()}-${Math.random().toString(16).slice(2)}`;\r\n}\r\n\r\nfunction createRequestMeta(requestConfig) {\r\n const url = new URL(requestConfig.url);\r\n return {\r\n _options: requestConfig,\r\n method: requestConfig.method,\r\n path: url.pathname,\r\n protocol: url.protocol,\r\n host: url.host,\r\n hostname: url.hostname,\r\n };\r\n}\r\n\r\nfunction createNetworkError(message, config, requestConfig, cause) {\r\n const error = new Error(message || 'Network Error');\r\n error.code = 'ERR_NETWORK';\r\n error.config = config;\r\n error.request = createRequestMeta(requestConfig);\r\n if (cause) {\r\n error.cause = cause;\r\n }\r\n return error;\r\n}\r\n\r\nfunction normalizeHeaders(headers) {\r\n if (!headers) {\r\n return undefined;\r\n }\r\n\r\n return Object.fromEntries(\r\n Object.entries(headers).filter(([, value]) => value != null),\r\n );\r\n}\r\n\r\nfunction buildRequestConfig(config) {\r\n const baseURL = config.baseURL ? config.baseURL.replace(/\\/+$/, '') : '';\r\n const url = new URL(config.url, baseURL || undefined).toString();\r\n\r\n return {\r\n method: config.method?.toUpperCase() || 'GET',\r\n url,\r\n headers: normalizeHeaders(config.headers),\r\n data: config.data,\r\n responseType: config.responseType,\r\n };\r\n}\r\n\r\nfunction buildPreviewOptions(requestConfig) {\r\n return {\r\n method: requestConfig.method,\r\n headers: requestConfig.headers,\r\n body: requestConfig.data,\r\n };\r\n}\r\n\r\nexport default async function electronNetAdapter(config) {\r\n const net = typeof window !== 'undefined' ? window.ts?.net : null;\r\n if (!net?.request) {\r\n throw createNetworkError('window.ts.net.request is not available', config, {\r\n method: config.method?.toUpperCase() || 'GET',\r\n url: new URL(config.url, config.baseURL || undefined).toString(),\r\n });\r\n }\r\n\r\n const requestId = createRequestId();\r\n const requestConfig = buildRequestConfig(config);\r\n const requestMeta = createRequestMeta(requestConfig);\r\n\r\n if (config.signal && typeof net.abort === 'function') {\r\n config.signal.addEventListener('abort', () => {\r\n net.abort(requestId);\r\n }, { once: true });\r\n }\r\n\r\n try {\r\n let response;\r\n try {\r\n response = await net.request(requestId, requestConfig);\r\n } catch (error) {\r\n response = await net.request(\r\n requestConfig.url,\r\n buildPreviewOptions(requestConfig),\r\n );\r\n if (response?.ok === false && !response.status) {\r\n throw error;\r\n }\r\n }\r\n\r\n return {\r\n data: response?.data,\r\n status: response?.status,\r\n statusText: response?.statusText || '',\r\n headers: response?.headers || {},\r\n config,\r\n request: requestMeta,\r\n };\r\n } catch (error) {\r\n throw createNetworkError(error.message, config, requestConfig, error);\r\n }\r\n}\r\n","/**\r\n * Translime SDK\r\n * 提供插件开发所需的标准 API 和类型提示。\r\n * 包含主进程 (Main Process) 和渲染进程 (Renderer Process) 的通用接口。\r\n */\r\n\r\nimport {\r\n isPreviewMode as checkPreviewMode,\r\n initPreviewMock,\r\n} from './preview-mock';\r\nimport electronNetAdapter from './electronNetAdapter';\r\n\r\nconst CLIPBOARD_IPC = {\r\n readText: 'read-clipboard-text',\r\n writeText: 'copy-text',\r\n};\r\n\r\n// ----------------------------------------------------------------------\r\n// Initialization (Side Effect)\r\n// ----------------------------------------------------------------------\r\n\r\n// 在模块加载时检测并初始化 Preview Mock 环境\r\n// 确保在 Preview 模式下直接导入 SDK 也能获得 Mock 支持\r\nif (typeof window !== 'undefined' && checkPreviewMode()) {\r\n initPreviewMock();\r\n}\r\n\r\n// ----------------------------------------------------------------------\r\n// Core / Store APIs (Main Process Only)\r\n// ----------------------------------------------------------------------\r\n\r\n/**\r\n * 检查当前是否为 Preview 模式\r\n * @returns {boolean}\r\n */\r\nexport function isPreviewMode() {\r\n return checkPreviewMode();\r\n}\r\n\r\n/**\r\n * @typedef {Object} MainStore\r\n * @property {Object} config\r\n * @property {function(string, *): *} config.get\r\n * @property {function(string, *): void} config.set\r\n * @property {Object} [logger]\r\n */\r\n\r\n/**\r\n * 获取主程序 Store\r\n * @description 仅在 **主进程 (Main Process)** 环境可用\r\n * @returns {MainStore|null} 若在非主进程环境调用,返回 null\r\n */\r\nexport function getMainStore() {\r\n if (typeof global !== 'undefined' && global.mainStore) {\r\n return global.mainStore;\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 使用插件配置代理\r\n * @description 获取针对特定插件的配置读写对象\r\n * @param {string} pluginId 插件 ID (通常与 package.json 中的 name 一致)\r\n * @returns {{ get: function(string, *): *, set: function(string, *): void }}\r\n */\r\nexport function usePluginConfig(pluginId) {\r\n const store = getMainStore();\r\n return {\r\n get(key, defaultValue) {\r\n return store?.config?.get(`plugin.${pluginId}.settings.${key}`, defaultValue);\r\n },\r\n set(key, value) {\r\n store?.config?.set(`plugin.${pluginId}.settings.${key}`, value);\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * 获取插件间通信工具\r\n * @description 仅在 **主进程 (Main Process)** 环境可用\r\n * @returns {import('./index.d').PluginInterop|null}\r\n */\r\nexport function usePluginInterop() {\r\n if (typeof global !== 'undefined' && global.pluginInterop) {\r\n return global.pluginInterop;\r\n }\r\n return null;\r\n}\r\n\r\n// ----------------------------------------------------------------------\r\n// UI & Renderer APIs (Renderer Process Only)\r\n// ----------------------------------------------------------------------\r\n\r\n/**\r\n * 获取 IPC 通信工具\r\n * @description 仅在 **渲染进程 (Renderer Process)** 环境可用\r\n * @returns {Object|null} 包含 invoke, send, on 等方法的对象\r\n */\r\nexport function useIpc() {\r\n if (typeof window !== 'undefined' && window.electron?.useIpc) {\r\n return window.electron.useIpc();\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 获取 Vuetify 实例\r\n * @description 仅在 **渲染进程** 环境可用,用于访问 Vuetify 的全局配置\r\n * @returns {Object} Vuetify 实例对象\r\n */\r\nexport function useVuetify() {\r\n if (typeof window !== 'undefined' && window.vuetify$) {\r\n return window.vuetify$;\r\n }\r\n return {};\r\n}\r\n\r\n/**\r\n * 获取全局注册的 Vuetify 组件\r\n * @returns {Record<string, any>}\r\n */\r\nexport function useVuetifyComponents() {\r\n return useVuetify().components || {};\r\n}\r\n\r\n/**\r\n * 获取全局注册的 Vuetify 指令\r\n * @returns {Record<string, any>}\r\n */\r\nexport function useVuetifyDirectives() {\r\n return useVuetify().directives || {};\r\n}\r\n\r\n/**\r\n * 获取 Dialog API\r\n * @description 类似于 Electron 的 dialog 模块 (showOpenDialog, showSaveDialog 等)\r\n * @returns {Object|null}\r\n */\r\nexport function useDialog() {\r\n if (typeof window !== 'undefined' && window.electron?.dialog) {\r\n return window.electron.dialog;\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 获取 Shell API\r\n * @description 类似于 Electron 的 shell 模块 (openExternal, showItemInFolder 等)\r\n * @returns {Object|null}\r\n */\r\nexport function useShell() {\r\n if (typeof window !== 'undefined' && window.electron?.shell) {\r\n return window.electron.shell;\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 获取插件自身设置 (IPC 封装)\r\n * @description 仅在 **渲染进程** 环境可用。这是 `plugin.settings` 的前端读取接口。\r\n * @param {...any} args\r\n * @returns {Promise<any>}\r\n */\r\nexport async function getPluginSetting(...args) {\r\n if (typeof window !== 'undefined' && window.ts?.getPluginSetting) {\r\n return window.ts.getPluginSetting(...args);\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 更新插件自身设置 (IPC 封装)\r\n * @description 仅在 **渲染进程** 环境可用。\r\n * @param {...any} args\r\n * @returns {Promise<any>}\r\n */\r\nexport async function setPluginSetting(...args) {\r\n if (typeof window !== 'undefined' && window.ts?.setPluginSetting) {\r\n return window.ts.setPluginSetting(...args);\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 获取窗口控制工具\r\n * @description 包含 minimize, maximize, close 等窗口操作\r\n * @returns {Object|null}\r\n */\r\nexport function useWindowControl() {\r\n if (typeof window !== 'undefined' && window.ts?.windowControl) {\r\n return window.ts.windowControl;\r\n }\r\n return null;\r\n}\r\n\r\n// ----------------------------------------------------------------------\r\n// Utilities (Shared)\r\n// ----------------------------------------------------------------------\r\n\r\n/**\r\n * 获取剪贴板工具\r\n * @returns {Object|null}\r\n */\r\nexport function useClipboard() {\r\n if (typeof window !== 'undefined') {\r\n return {\r\n async readText() {\r\n if (window.electron?.useIpc) {\r\n return window.electron.useIpc().invoke(CLIPBOARD_IPC.readText);\r\n }\r\n if (navigator.clipboard?.readText) {\r\n return navigator.clipboard.readText();\r\n }\r\n return null;\r\n },\r\n async writeText(text) {\r\n if (window.electron?.useIpc) {\r\n return window.electron.useIpc().invoke(CLIPBOARD_IPC.writeText, text);\r\n }\r\n if (navigator.clipboard?.writeText) {\r\n return navigator.clipboard.writeText(text);\r\n }\r\n return null;\r\n },\r\n };\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 在默认浏览器中打开链接\r\n * @param {string} url 要打开的链接\r\n * @returns {Promise<void>}\r\n */\r\nexport async function openLink(...args) {\r\n if (typeof window !== 'undefined' && window.electron?.openLink) {\r\n return window.electron.openLink(...args);\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 获取日志工具\r\n * @description 自动适配 Node.js 环境 (Main) 或浏览器环境 (Renderer)\r\n * @returns {Record<'log'|'info'|'warn'|'error'|'debug', Function>} Console-like logger\r\n */\r\nexport function useLogger() {\r\n if (typeof global !== 'undefined' && global.mainStore) {\r\n return global.mainStore?.logger || console;\r\n }\r\n if (typeof window !== 'undefined') {\r\n return window.ts?.logger || console;\r\n }\r\n return console;\r\n}\r\n\r\nexport { electronNetAdapter };\r\n"],"mappings":";;;AAAA,SAAS,kBAAkB;AACzB,KAAI,OAAO,eAAe,eAAe,WAAW,QAAQ,WAC1D,QAAO,WAAW,OAAO,YAAY;AAGvC,QAAO,UAAU,KAAK,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE;;AAGpE,SAAS,kBAAkB,eAAe;CACxC,MAAM,MAAM,IAAI,IAAI,cAAc,IAAI;AACtC,QAAO;EACL,UAAU;EACV,QAAQ,cAAc;EACtB,MAAM,IAAI;EACV,U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QAAO;;;;;;;AAQT,eAAsB,SAAS,GAAG,MAAM;AACtC,KAAI,OAAO,WAAW,eAAe,OAAO,UAAU,SACpD,QAAO,OAAO,SAAS,SAAS,GAAG,KAAK;AAE1C,QAAO;;;;;;;AAQT,SAAgB,YAAY;AAC1B,KAAI,OAAO,WAAW,eAAe,OAAO,UAC1C,QAAO,OAAO,WAAW,UAAU;AAErC,KAAI,OAAO,WAAW,YACpB,QAAO,OAAO,IAAI,UAAU;AAE9B,QAAO"}
package/dist/index.d.cts CHANGED
@@ -1,93 +1,127 @@
1
- export interface Config {
2
- get(key: string, defaultValue?: any): any;
3
- set(key: string, value: any): void;
4
- }
5
-
6
- export interface MainStore {
7
- config: Config;
8
- }
9
-
10
- /**
11
- * 检查当前是否为 Preview 模式
12
- */
13
- export function isPreviewMode(): boolean;
14
-
15
- /**
16
- * 获取主程序 Store (仅在主进程环境可用)
17
- */
18
- export function getMainStore(): MainStore | null;
19
-
20
- /**
21
- * 获取插件配置代理
22
- * @param pluginId 插件 ID
23
- */
24
- export function usePluginConfig(pluginId: string): Config;
25
-
26
- /**
27
- * 获取 IPC 工具 (仅在渲染进程环境可用)
28
- */
29
- export function useIpc(): any;
30
-
31
- /**
32
- * 获取 Vuetify 实例
33
- */
34
- export function useVuetify(): any;
35
-
36
- /**
37
- * 获取所有 Vuetify 组件
38
- */
39
- export function useVuetifyComponents(): Record<string, any>;
40
- export function useVuetifyDirectives(): Record<string, any>;
41
-
42
- /**
43
- * 助手函数:获取 Electron 提供的对话框 API
44
- */
45
- export function useDialog(): any;
46
-
47
- /**
48
- * 获取 Shell API
49
- */
50
- export function useShell(): any;
51
-
52
- /**
53
- * 获取插件设置 (仅在渲染进程环境可用)
54
- */
55
- export function getPluginSetting(...args: any[]): Promise<any>;
56
-
57
- /**
58
- * 设置插件设置 (仅在渲染进程环境可用)
59
- */
60
- export function setPluginSetting(...args: any[]): Promise<any>;
61
-
62
- /**
63
- * 获取窗口控制工具 (仅在渲染进程环境可用)
64
- */
65
- export function useWindowControl(): {
66
- devtools(win?: any): Promise<any>;
67
- maximize(win?: any): Promise<any>;
68
- unmaximize(win?: any): Promise<any>;
69
- minimize(win?: any): Promise<any>;
70
- close(win?: any): Promise<any>;
71
- } | null;
72
-
73
- /**
74
- * 获取剪贴板工具 (仅在渲染进程环境可用)
75
- */
76
- export function useClipboard(): any;
77
-
78
- /**
79
- * 在浏览器中打开链接 (仅在渲染进程环境可用)
80
- */
81
- export function openLink(...args: any[]): Promise<any>;
82
-
83
- /**
84
- * 获取日志工具
85
- */
86
- export function useLogger(): {
87
- log(...args: any[]): void;
88
- info(...args: any[]): void;
89
- warn(...args: any[]): void;
90
- error(...args: any[]): void;
91
- debug(...args: any[]): void;
92
- };
93
-
1
+ export interface Config {
2
+ get(key: string, defaultValue?: any): any;
3
+ set(key: string, value: any): void;
4
+ }
5
+
6
+ export interface MainStore {
7
+ config: Config;
8
+ }
9
+
10
+ /**
11
+ * 检查当前是否为 Preview 模式
12
+ */
13
+ export function isPreviewMode(): boolean;
14
+
15
+ /**
16
+ * 获取主程序 Store (仅在主进程环境可用)
17
+ */
18
+ export function getMainStore(): MainStore | null;
19
+
20
+ /**
21
+ * 获取插件配置代理
22
+ * @param pluginId 插件 ID
23
+ */
24
+ export function usePluginConfig(pluginId: string): Config;
25
+
26
+ export interface PluginInterop {
27
+ /**
28
+ * 获取目标插件的 API 引用
29
+ * @param pluginId 插件 ID
30
+ */
31
+ getExports<T = any>(pluginId: string): T | undefined;
32
+
33
+ /**
34
+ * 获取所有已注册公共 API 的插件列表
35
+ */
36
+ getRegisteredPlugins(): string[];
37
+
38
+ /**
39
+ * 等待目标插件被激活并获取其 API
40
+ * @param pluginId 目标插件 ID
41
+ * @param timeout 超时时间 (毫秒),默认 10000。0 表示永不超时
42
+ */
43
+ waitForPlugin<T = any>(pluginId: string, timeout?: number): Promise<T>;
44
+
45
+ on(event: 'activated', listener: (pluginId: string, exports: any) => void): this;
46
+ on(event: 'deactivated', listener: (pluginId: string) => void): this;
47
+ off(event: 'activated', listener: (pluginId: string, exports: any) => void): this;
48
+ off(event: 'deactivated', listener: (pluginId: string) => void): this;
49
+ }
50
+
51
+ /**
52
+ * 获取插件间通信工具 (仅在主进程环境可用)
53
+ */
54
+ export function usePluginInterop(): PluginInterop | null;
55
+
56
+ /**
57
+ * 获取 IPC 工具 (仅在渲染进程环境可用)
58
+ */
59
+ export function useIpc(): any;
60
+
61
+ /**
62
+ * 获取 Vuetify 实例
63
+ */
64
+ export function useVuetify(): any;
65
+
66
+ /**
67
+ * 获取所有 Vuetify 组件
68
+ */
69
+ export function useVuetifyComponents(): Record<string, any>;
70
+ export function useVuetifyDirectives(): Record<string, any>;
71
+
72
+ /**
73
+ * 助手函数:获取 Electron 提供的对话框 API
74
+ */
75
+ export function useDialog(): any;
76
+
77
+ /**
78
+ * 获取 Shell API
79
+ */
80
+ export function useShell(): any;
81
+
82
+ /**
83
+ * 获取插件设置 (仅在渲染进程环境可用)
84
+ */
85
+ export function getPluginSetting(...args: any[]): Promise<any>;
86
+
87
+ /**
88
+ * 设置插件设置 (仅在渲染进程环境可用)
89
+ */
90
+ export function setPluginSetting(...args: any[]): Promise<any>;
91
+
92
+ /**
93
+ * 获取窗口控制工具 (仅在渲染进程环境可用)
94
+ */
95
+ export function useWindowControl(): {
96
+ devtools(win?: any): Promise<any>;
97
+ maximize(win?: any): Promise<any>;
98
+ unmaximize(win?: any): Promise<any>;
99
+ minimize(win?: any): Promise<any>;
100
+ close(win?: any): Promise<any>;
101
+ } | null;
102
+
103
+ /**
104
+ * 获取剪贴板工具 (仅在渲染进程环境可用)
105
+ */
106
+ export function useClipboard(): any;
107
+
108
+ /**
109
+ * 在浏览器中打开链接 (仅在渲染进程环境可用)
110
+ */
111
+ export function openLink(...args: any[]): Promise<any>;
112
+
113
+ /**
114
+ * 获取日志工具
115
+ */
116
+ export function useLogger(): {
117
+ log(...args: any[]): void;
118
+ info(...args: any[]): void;
119
+ warn(...args: any[]): void;
120
+ error(...args: any[]): void;
121
+ debug(...args: any[]): void;
122
+ };
123
+
124
+ /**
125
+ * Axios adapter backed by `window.ts.net`.
126
+ */
127
+ export function electronNetAdapter(config: any): Promise<any>;