@binblink/wasmnest-plugin-sdk-desktop 0.0.0-stage → 0.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.
Files changed (271) hide show
  1. package/README.md +307 -2
  2. package/README_en.md +284 -0
  3. package/bin/cli.js +602 -0
  4. package/bin/manifest-gen.js +458 -0
  5. package/bin/manifest-validate.js +494 -0
  6. package/bin/permission-vocabulary.json +5 -0
  7. package/bin/plugin-watch.js +331 -0
  8. package/bin/wasm-hash.js +124 -0
  9. package/dev-shell/README.md +122 -0
  10. package/dev-shell/index.html +12 -0
  11. package/dev-shell/package.json +28 -0
  12. package/dev-shell/pnpm-workspace.yaml +9 -0
  13. package/dev-shell/postcss.config.js +6 -0
  14. package/dev-shell/src/App.vue +90 -0
  15. package/dev-shell/src/components/LogPanel.vue +90 -0
  16. package/dev-shell/src/loader.ts +104 -0
  17. package/dev-shell/src/locale.ts +29 -0
  18. package/dev-shell/src/locales.ts +50 -0
  19. package/dev-shell/src/main.ts +46 -0
  20. package/dev-shell/src/mock/app-env.ts +102 -0
  21. package/dev-shell/src/mock/commands.ts +54 -0
  22. package/dev-shell/src/mock/domain-context.ts +46 -0
  23. package/dev-shell/src/mock/events.ts +16 -0
  24. package/dev-shell/src/mock/file-transfer.ts +512 -0
  25. package/dev-shell/src/mock/tauri-ipc.ts +109 -0
  26. package/dev-shell/src/registry.ts +90 -0
  27. package/dev-shell/src/shell/components/AppMountSlot.vue +241 -0
  28. package/dev-shell/src/shell/components/ShellIcon.vue +141 -0
  29. package/dev-shell/src/shell/components/ShellStatusBar.vue +87 -0
  30. package/dev-shell/src/shell/components/ShellToolbar.vue +287 -0
  31. package/dev-shell/src/shell/mount/appSession.ts +45 -0
  32. package/dev-shell/src/shell/mount/devAppMount.ts +80 -0
  33. package/dev-shell/src/shell/types.ts +121 -0
  34. package/dev-shell/src/styles/dev.css +27 -0
  35. package/dev-shell/src/styles/shell.css +752 -0
  36. package/dev-shell/src/styles/style.css +1178 -0
  37. package/dev-shell/src/theme.ts +140 -0
  38. package/dev-shell/src/vite-env.d.ts +24 -0
  39. package/dev-shell/tailwind.config.js +98 -0
  40. package/dev-shell/vite.config.ts +174 -0
  41. package/dist/index.d.ts +150 -0
  42. package/dist/index.js +238 -0
  43. package/dist/types.d.ts +632 -0
  44. package/dist/types.js +0 -0
  45. package/dist/vite-plugin.d.ts +25 -0
  46. package/dist/vite-plugin.js +80 -0
  47. package/go/.gitignore +5 -0
  48. package/go/README.md +80 -0
  49. package/go/gen/wasmnest/api-call/host-api-call/empty.s +3 -0
  50. package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wasm.go +13 -0
  51. package/go/gen/wasmnest/api-call/host-api-call/host-api-call.wit.go +34 -0
  52. package/go/gen/wasmnest/app/host-app/empty.s +3 -0
  53. package/go/gen/wasmnest/app/host-app/host-app.wasm.go +29 -0
  54. package/go/gen/wasmnest/app/host-app/host-app.wit.go +108 -0
  55. package/go/gen/wasmnest/auth-center/host-auth-center/abi.go +14 -0
  56. package/go/gen/wasmnest/auth-center/host-auth-center/empty.s +3 -0
  57. package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wasm.go +49 -0
  58. package/go/gen/wasmnest/auth-center/host-auth-center/host-auth-center.wit.go +225 -0
  59. package/go/gen/wasmnest/clipboard/host-clipboard/abi.go +14 -0
  60. package/go/gen/wasmnest/clipboard/host-clipboard/empty.s +3 -0
  61. package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wasm.go +17 -0
  62. package/go/gen/wasmnest/clipboard/host-clipboard/host-clipboard.wit.go +68 -0
  63. package/go/gen/wasmnest/connection-registry/host-connection-registry/empty.s +3 -0
  64. package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wasm.go +13 -0
  65. package/go/gen/wasmnest/connection-registry/host-connection-registry/host-connection-registry.wit.go +50 -0
  66. package/go/gen/wasmnest/crypto/host-crypto/abi.go +18 -0
  67. package/go/gen/wasmnest/crypto/host-crypto/empty.s +3 -0
  68. package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wasm.go +37 -0
  69. package/go/gen/wasmnest/crypto/host-crypto/host-crypto.wit.go +139 -0
  70. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/abi.go +14 -0
  71. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/empty.s +3 -0
  72. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wasm.go +21 -0
  73. package/go/gen/wasmnest/fs-desktop/host-fs-desktop/host-fs-desktop.wit.go +62 -0
  74. package/go/gen/wasmnest/http/host-http/abi.go +14 -0
  75. package/go/gen/wasmnest/http/host-http/empty.s +3 -0
  76. package/go/gen/wasmnest/http/host-http/host-http.wasm.go +13 -0
  77. package/go/gen/wasmnest/http/host-http/host-http.wit.go +40 -0
  78. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/empty.s +3 -0
  79. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wasm.go +17 -0
  80. package/go/gen/wasmnest/http-endpoint/host-http-endpoint/host-http-endpoint.wit.go +69 -0
  81. package/go/gen/wasmnest/mdns/host-mdns/empty.s +3 -0
  82. package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wasm.go +29 -0
  83. package/go/gen/wasmnest/mdns/host-mdns/host-mdns.wit.go +101 -0
  84. package/go/gen/wasmnest/notify/host-notify/empty.s +3 -0
  85. package/go/gen/wasmnest/notify/host-notify/host-notify.wasm.go +13 -0
  86. package/go/gen/wasmnest/notify/host-notify/host-notify.wit.go +64 -0
  87. package/go/gen/wasmnest/peer/host-peer/abi.go +14 -0
  88. package/go/gen/wasmnest/peer/host-peer/empty.s +3 -0
  89. package/go/gen/wasmnest/peer/host-peer/host-peer.wasm.go +85 -0
  90. package/go/gen/wasmnest/peer/host-peer/host-peer.wit.go +357 -0
  91. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/empty.s +3 -0
  92. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wasm.go +21 -0
  93. package/go/gen/wasmnest/platform-desktop/host-platform-desktop/host-platform-desktop.wit.go +70 -0
  94. package/go/gen/wasmnest/plugin/abi-form/abi-form.exports.go +11 -0
  95. package/go/gen/wasmnest/plugin/abi-form/abi-form.wasm.go +13 -0
  96. package/go/gen/wasmnest/plugin/abi-form/abi-form.wit.go +7 -0
  97. package/go/gen/wasmnest/plugin/abi-form/empty.s +3 -0
  98. package/go/gen/wasmnest/plugin/command/command.exports.go +11 -0
  99. package/go/gen/wasmnest/plugin/command/command.wasm.go +19 -0
  100. package/go/gen/wasmnest/plugin/command/command.wit.go +6 -0
  101. package/go/gen/wasmnest/plugin/command/empty.s +3 -0
  102. package/go/gen/wasmnest/plugin/events/empty.s +3 -0
  103. package/go/gen/wasmnest/plugin/events/events.exports.go +52 -0
  104. package/go/gen/wasmnest/plugin/events/events.wasm.go +74 -0
  105. package/go/gen/wasmnest/plugin/events/events.wit.go +195 -0
  106. package/go/gen/wasmnest/plugin/host-bus/empty.s +3 -0
  107. package/go/gen/wasmnest/plugin/host-bus/host-bus.wasm.go +29 -0
  108. package/go/gen/wasmnest/plugin/host-bus/host-bus.wit.go +94 -0
  109. package/go/gen/wasmnest/plugin/host-config/abi.go +14 -0
  110. package/go/gen/wasmnest/plugin/host-config/empty.s +3 -0
  111. package/go/gen/wasmnest/plugin/host-config/host-config.wasm.go +13 -0
  112. package/go/gen/wasmnest/plugin/host-config/host-config.wit.go +21 -0
  113. package/go/gen/wasmnest/plugin/host-events/empty.s +3 -0
  114. package/go/gen/wasmnest/plugin/host-events/host-events.wasm.go +9 -0
  115. package/go/gen/wasmnest/plugin/host-events/host-events.wit.go +27 -0
  116. package/go/gen/wasmnest/plugin/host-fs/abi.go +14 -0
  117. package/go/gen/wasmnest/plugin/host-fs/empty.s +3 -0
  118. package/go/gen/wasmnest/plugin/host-fs/host-fs.wasm.go +33 -0
  119. package/go/gen/wasmnest/plugin/host-fs/host-fs.wit.go +86 -0
  120. package/go/gen/wasmnest/plugin/host-log/empty.s +3 -0
  121. package/go/gen/wasmnest/plugin/host-log/host-log.wasm.go +25 -0
  122. package/go/gen/wasmnest/plugin/host-log/host-log.wit.go +65 -0
  123. package/go/gen/wasmnest/plugin/host-metrics/empty.s +3 -0
  124. package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wasm.go +13 -0
  125. package/go/gen/wasmnest/plugin/host-metrics/host-metrics.wit.go +34 -0
  126. package/go/gen/wasmnest/plugin/host-platform/empty.s +3 -0
  127. package/go/gen/wasmnest/plugin/host-platform/host-platform.wasm.go +21 -0
  128. package/go/gen/wasmnest/plugin/host-platform/host-platform.wit.go +85 -0
  129. package/go/gen/wasmnest/plugin/host-plugin-database/abi.go +14 -0
  130. package/go/gen/wasmnest/plugin/host-plugin-database/empty.s +3 -0
  131. package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wasm.go +29 -0
  132. package/go/gen/wasmnest/plugin/host-plugin-database/host-plugin-database.wit.go +70 -0
  133. package/go/gen/wasmnest/plugin/host-storage/abi.go +14 -0
  134. package/go/gen/wasmnest/plugin/host-storage/empty.s +3 -0
  135. package/go/gen/wasmnest/plugin/host-storage/host-storage.wasm.go +21 -0
  136. package/go/gen/wasmnest/plugin/host-storage/host-storage.wit.go +44 -0
  137. package/go/gen/wasmnest/plugin/host-worker/empty.s +3 -0
  138. package/go/gen/wasmnest/plugin/host-worker/host-worker.wasm.go +17 -0
  139. package/go/gen/wasmnest/plugin/host-worker/host-worker.wit.go +50 -0
  140. package/go/gen/wasmnest/plugin/lifecycle/empty.s +3 -0
  141. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.exports.go +32 -0
  142. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wasm.go +41 -0
  143. package/go/gen/wasmnest/plugin/lifecycle/lifecycle.wit.go +9 -0
  144. package/go/gen/wasmnest/plugin/manifest/empty.s +3 -0
  145. package/go/gen/wasmnest/plugin/manifest/manifest.exports.go +11 -0
  146. package/go/gen/wasmnest/plugin/manifest/manifest.wasm.go +13 -0
  147. package/go/gen/wasmnest/plugin/manifest/manifest.wit.go +6 -0
  148. package/go/gen/wasmnest/plugin/plugin/plugin.wit.go +4 -0
  149. package/go/gen/wasmnest/process/host-process/empty.s +3 -0
  150. package/go/gen/wasmnest/process/host-process/host-process.wasm.go +21 -0
  151. package/go/gen/wasmnest/process/host-process/host-process.wit.go +56 -0
  152. package/go/gen/wasmnest/pty/host-pty/abi.go +14 -0
  153. package/go/gen/wasmnest/pty/host-pty/empty.s +3 -0
  154. package/go/gen/wasmnest/pty/host-pty/host-pty.wasm.go +33 -0
  155. package/go/gen/wasmnest/pty/host-pty/host-pty.wit.go +164 -0
  156. package/go/gen/wasmnest/task/host-task/abi.go +14 -0
  157. package/go/gen/wasmnest/task/host-task/empty.s +3 -0
  158. package/go/gen/wasmnest/task/host-task/host-task.wasm.go +29 -0
  159. package/go/gen/wasmnest/task/host-task/host-task.wit.go +110 -0
  160. package/go/gen/wasmnest/timer/host-timer/empty.s +3 -0
  161. package/go/gen/wasmnest/timer/host-timer/host-timer.wasm.go +13 -0
  162. package/go/gen/wasmnest/timer/host-timer/host-timer.wit.go +25 -0
  163. package/go/gen/wasmnest/ws/host-websocket/empty.s +3 -0
  164. package/go/gen/wasmnest/ws/host-websocket/host-websocket.wasm.go +29 -0
  165. package/go/gen/wasmnest/ws/host-websocket/host-websocket.wit.go +109 -0
  166. package/go/gen/wasmnest/ws-server/host-websocket-server/empty.s +3 -0
  167. package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wasm.go +49 -0
  168. package/go/gen/wasmnest/ws-server/host-websocket-server/host-websocket-server.wit.go +220 -0
  169. package/go/go.mod +14 -0
  170. package/go/go.sum +2 -0
  171. package/go/sdk/dispatch.go +49 -0
  172. package/go/sdk/dispatch_test.go +81 -0
  173. package/go/sdk/entry_native.go +13 -0
  174. package/go/sdk/entry_wasip2.go +188 -0
  175. package/go/sdk/host_http_wasip2.go +42 -0
  176. package/go/sdk/host_wasip2.go +251 -0
  177. package/go/sdk/plugin.go +103 -0
  178. package/go/testplugin/index.js +1 -0
  179. package/go/testplugin/main.go +67 -0
  180. package/go/testplugin/plugin.json +24 -0
  181. package/go/tools/assemble-wit.mjs +152 -0
  182. package/go/tools/gen-bindings.mjs +51 -0
  183. package/go/wit/core.wit +273 -0
  184. package/go/wit/deps/api-call/cap-api-call.wit +20 -0
  185. package/go/wit/deps/app/cap-app.wit +54 -0
  186. package/go/wit/deps/auth-center/cap-auth-center.wit +124 -0
  187. package/go/wit/deps/clipboard/clipboard.wit +48 -0
  188. package/go/wit/deps/clocks/monotonic-clock.wit +45 -0
  189. package/go/wit/deps/clocks/wall-clock.wit +42 -0
  190. package/go/wit/deps/clocks/world.wit +6 -0
  191. package/go/wit/deps/connection-registry/cap-connection-registry.wit +40 -0
  192. package/go/wit/deps/crypto/cap-crypto.wit +68 -0
  193. package/go/wit/deps/filesystem/preopens.wit +8 -0
  194. package/go/wit/deps/filesystem/types.wit +634 -0
  195. package/go/wit/deps/filesystem/world.wit +6 -0
  196. package/go/wit/deps/fs-desktop/cap-fs-desktop.wit +29 -0
  197. package/go/wit/deps/http/http.wit +28 -0
  198. package/go/wit/deps/http-endpoint/cap-http.wit +44 -0
  199. package/go/wit/deps/io/error.wit +34 -0
  200. package/go/wit/deps/io/poll.wit +41 -0
  201. package/go/wit/deps/io/streams.wit +262 -0
  202. package/go/wit/deps/io/world.wit +6 -0
  203. package/go/wit/deps/mdns/mdns.wit +45 -0
  204. package/go/wit/deps/notify/notify.wit +51 -0
  205. package/go/wit/deps/peer/peer.wit +126 -0
  206. package/go/wit/deps/platform-desktop/cap-platform-desktop.wit +38 -0
  207. package/go/wit/deps/process/cap-process.wit +25 -0
  208. package/go/wit/deps/pty/pty.wit +80 -0
  209. package/go/wit/deps/random/insecure-seed.wit +25 -0
  210. package/go/wit/deps/random/insecure.wit +22 -0
  211. package/go/wit/deps/random/random.wit +26 -0
  212. package/go/wit/deps/random/world.wit +7 -0
  213. package/go/wit/deps/sockets/instance-network.wit +9 -0
  214. package/go/wit/deps/sockets/ip-name-lookup.wit +51 -0
  215. package/go/wit/deps/sockets/network.wit +145 -0
  216. package/go/wit/deps/sockets/tcp-create-socket.wit +27 -0
  217. package/go/wit/deps/sockets/tcp.wit +353 -0
  218. package/go/wit/deps/sockets/udp-create-socket.wit +27 -0
  219. package/go/wit/deps/sockets/udp.wit +266 -0
  220. package/go/wit/deps/sockets/world.wit +11 -0
  221. package/go/wit/deps/task/cap-task.wit +56 -0
  222. package/go/wit/deps/timer/cap-timer.wit +14 -0
  223. package/go/wit/deps/wasi-cli/command.wit +7 -0
  224. package/go/wit/deps/wasi-cli/environment.wit +18 -0
  225. package/go/wit/deps/wasi-cli/exit.wit +4 -0
  226. package/go/wit/deps/wasi-cli/imports.wit +20 -0
  227. package/go/wit/deps/wasi-cli/run.wit +4 -0
  228. package/go/wit/deps/wasi-cli/stdio.wit +17 -0
  229. package/go/wit/deps/wasi-cli/terminal.wit +49 -0
  230. package/go/wit/deps/ws/ws.wit +50 -0
  231. package/go/wit/deps/ws-server/cap-ws.wit +99 -0
  232. package/go/wit/go-plugin.wit +28 -0
  233. package/go/wit/plugin-face.wit +355 -0
  234. package/go/wit/wasmnest.wit +25 -0
  235. package/package.json +100 -3
  236. package/src/config.ts +49 -0
  237. package/src/global-dialog.ts +169 -0
  238. package/src/index.ts +88 -0
  239. package/src/runtime.ts +54 -0
  240. package/src/types.ts +681 -0
  241. package/src/ui/AppUpdateSection.d.ts +44 -0
  242. package/src/ui/AppUpdateSection.vue +253 -0
  243. package/src/ui/MarkdownEditor.vue +520 -0
  244. package/src/ui/NumberField.d.ts +49 -0
  245. package/src/ui/NumberField.vue +390 -0
  246. package/src/ui/PluginGlobalDialog.vue +401 -0
  247. package/src/ui/Select.d.ts +36 -0
  248. package/src/ui/Select.vue +220 -0
  249. package/src/ui/TerminalInputRail.vue +184 -0
  250. package/src/ui/apply-select-position.ts +65 -0
  251. package/src/ui/markdown-editor-syntax.ts +234 -0
  252. package/src/ui/markdown-editor.d.ts +36 -0
  253. package/src/ui/plugin-global-dialog.d.ts +12 -0
  254. package/src/ui/select-position.ts +79 -0
  255. package/src/ui/terminal-input-rail.d.ts +30 -0
  256. package/src/ui/zoom-compensation.d.ts +9 -0
  257. package/src/ui/zoom-compensation.ts +52 -0
  258. package/src/update.ts +123 -0
  259. package/src/vite-plugin.ts +124 -0
  260. package/template/README.md +39 -0
  261. package/template/package.json +23 -0
  262. package/template/plugin.json +14 -0
  263. package/template/rust/Cargo.toml +21 -0
  264. package/template/rust/src/lib.rs +39 -0
  265. package/template/src/env.d.ts +24 -0
  266. package/template/src/index.ts +37 -0
  267. package/template/tsconfig.json +17 -0
  268. package/template/vite.config.ts +21 -0
  269. package/tools/componentize/Cargo.lock +299 -0
  270. package/tools/componentize/Cargo.toml +18 -0
  271. package/tools/componentize/src/main.rs +197 -0
@@ -0,0 +1,52 @@
1
+ /**
2
+ * fixed 定位覆盖层在根元素 CSS zoom 下的坐标换算(自校准,无 zoom 时自动退回 F=1)
3
+ *
4
+ * 背景:曾因 Linux 桌面端 style.css 给 html.platform-linux 加 zoom: 1.15(修正
5
+ * WebKitGTK 字号观感)而引入本补偿。issue 06 已移除该 zoom(改 font-size +
6
+ * --ui-scale 体系,避免破坏 xterm 鼠标坐标系);此后探针实测 F=1、补偿自动成为
7
+ * no-op,本机制保留作防御(未来若根级 zoom 回归,调用方无需改动即可自愈)。
8
+ * WebKitGTK 2.52 采用标准化 zoom 语义(对齐 Chrome 128+):
9
+ * - getBoundingClientRect() 返回视觉坐标(已含 zoom 放大);
10
+ * - 而给 fixed 元素赋 top/left/width 等长度值时,渲染会再次乘以祖先链 zoom。
11
+ * 两者叠加:把 gBCR 读数直接赋给 fixed 面板,会向右下漂移 (zoom-1)×坐标、
12
+ * 尺寸放大 zoom 倍(WebKitGTK 2.52.6 实测:F=1.15,左缘漂 20.7px、宽 +15%,
13
+ * 贴底场景面板下溢窗口底约 39px——用户视角即"没贴住触发器、上拉判定失效")。
14
+ *
15
+ * 解法:自校准换算因子 F。放一个 set 宽 100px 的 fixed 探针读回 gBCR 宽度,
16
+ * F = 读回值 / 100。核心不变式:视觉坐标 = 赋值 px × F = 设计坐标 × F——
17
+ * gBCR 读数 ÷ F 得设计坐标;赋值用设计坐标(赋值 px 渲染时 ×F,与触发器
18
+ * 同一坐标系)。若选择全程在视觉空间计算(如 Tooltip),则最终赋值 = 视觉值 ÷ F。
19
+ * 两端引擎下都自洽:
20
+ * - 标准化 zoom 引擎:F = zoom,gBCR(视觉)/F → 设计 px,赋值渲染 ×zoom 落回视觉位置;
21
+ * - 旧式 zoom 引擎(used-value 乘法、gBCR 报本地坐标):F = 1,读数本就是设计 px;
22
+ * - 无 zoom 环境(macOS/Windows):F = 1,行为与历史实现完全一致。
23
+ * 页面缩放(Ctrl+=/-)对读数与赋值同比例缩放,不影响 F;根 zoom 每次打开时
24
+ * 重新实测一次,开销量级为单次 gBCR 调用,可忽略。
25
+ */
26
+
27
+ let probeEl: HTMLDivElement | null = null
28
+
29
+ /**
30
+ * 获取当前文档下 fixed 赋值坐标 → 视觉坐标的换算因子(赋值 px = 设计 px / F)
31
+ *
32
+ * 探针元素常驻 body(不可见、不可交互);测试框架清空 body 后下次调用自动重挂载。
33
+ */
34
+ export function getFixedZoomCompensation(): number {
35
+ if (!probeEl) {
36
+ probeEl = document.createElement('div')
37
+ probeEl.setAttribute('aria-hidden', 'true')
38
+ probeEl.style.cssText =
39
+ 'position:fixed;top:0;left:0;width:100px;height:0;visibility:hidden;pointer-events:none;'
40
+ }
41
+ if (!probeEl.isConnected) {
42
+ document.body.appendChild(probeEl)
43
+ }
44
+ const width = probeEl.getBoundingClientRect().width
45
+ // 无布局引擎的环境(happy-dom/jsdom 测试)gBCR 恒为 0 → 退回 1,保持无缩放行为
46
+ return Number.isFinite(width) && width > 0 ? width / 100 : 1
47
+ }
48
+
49
+ /** 重置探针缓存(测试隔离用;生产代码无需调用) */
50
+ export function resetFixedZoomProbe(): void {
51
+ probeEl = null
52
+ }
package/src/update.ts ADDED
@@ -0,0 +1,123 @@
1
+ /**
2
+ * 应用更新检查(SDK 默认实现;宿主统一提供 GitHub Release 判定)
3
+ *
4
+ * 数据面由宿主给出(`PluginContext.appUpdate.check`):宿主负责查 Release、校验
5
+ * 身份 / 完整性、做平台兼容裁决;本模块只做状态机与展示口径,供应用设置页复用。
6
+ *
7
+ * 应用可以选择:
8
+ * - **默认实现**:`useAppUpdate()` / `<AppUpdateSection />`(宿主能力 + 本模块状态);
9
+ * - **自实现**:自己查更新 / 自己画界面,不消费本模块。
10
+ *
11
+ * 失败口径:检查是被动动作,不向用户抛技术错误——状态落 `error`,技术详情由宿主
12
+ * 日志承载(应用可自行决定是否提示)。
13
+ */
14
+ import { computed, getCurrentInstance, inject, ref, type ComputedRef, type Ref } from 'vue'
15
+ import type { AppUpdateAPI, AppUpdateCheckResult, AppUpdateReason, PluginContext } from './types'
16
+
17
+ /** 状态机的展示态(与宿主返回的 status 子集一致) */
18
+ export type AppUpdateStatus =
19
+ 'idle' | 'checking' | 'up-to-date' | 'available' | 'incompatible' | 'error'
20
+
21
+ export interface UseAppUpdateOptions {
22
+ /**
23
+ * 自定义检查器(缺省 = 宿主 `PluginContext.appUpdate.check`)
24
+ *
25
+ * 应用自实现更新检查时传入;返回形状与宿主默认实现一致,SDK 默认卡片即可复用。
26
+ */
27
+ check?: () => Promise<AppUpdateCheckResult>
28
+ }
29
+
30
+ export interface UseAppUpdate {
31
+ status: Ref<AppUpdateStatus>
32
+ latestVersion: Ref<string | undefined>
33
+ currentVersion: Ref<string | undefined>
34
+ reason: Ref<AppUpdateReason | undefined>
35
+ checking: ComputedRef<boolean>
36
+ /** 当前平台是否提供更新检查能力(旧宿主 / dev-shell 可能没有) */
37
+ supported: ComputedRef<boolean>
38
+ /** 执行一次检查;并发调用复用同一在途请求 */
39
+ check: () => Promise<void>
40
+ }
41
+
42
+ /**
43
+ * 取宿主注入的更新能力(composable 必须在 setup 期间调用;inject 只在 setup 有上下文)
44
+ *
45
+ * 不经 SDK `getPluginContext()`:桌面挂载包没有 `__WASMNEST_SHARED__`,移动端虽有
46
+ * 共享运行时但取 context 的路径也不同;`inject('pluginContext')` 是双端应用都已
47
+ * 提供的唯一入口(桌面 appContext / 移动 PluginViewHost 同键)。
48
+ */
49
+ function resolveHostApi(): AppUpdateAPI | undefined {
50
+ if (!getCurrentInstance()) return undefined
51
+ return inject<PluginContext | undefined>('pluginContext', undefined)?.appUpdate
52
+ }
53
+
54
+ /**
55
+ * 应用更新状态机(模块内无全局单例:每个设置页实例各自持状态,避免跨应用串状态)
56
+ */
57
+ export function useAppUpdate(options: UseAppUpdateOptions = {}): UseAppUpdate {
58
+ const hostApi = options.check ? undefined : resolveHostApi()
59
+ const checker =
60
+ options.check ??
61
+ (() => {
62
+ if (!hostApi) {
63
+ return Promise.reject(
64
+ new Error('[PluginSDK] app update capability is not provided by this host'),
65
+ )
66
+ }
67
+ return hostApi.check()
68
+ })
69
+ const status = ref<AppUpdateStatus>('idle')
70
+ const latestVersion = ref<string | undefined>()
71
+ const currentVersion = ref<string | undefined>()
72
+ const reason = ref<AppUpdateReason | undefined>()
73
+ let inFlight: Promise<void> | null = null
74
+
75
+ const supported = computed(() => Boolean(options.check || hostApi))
76
+
77
+ async function run(): Promise<void> {
78
+ status.value = 'checking'
79
+ reason.value = undefined
80
+ try {
81
+ const result = await checker()
82
+ currentVersion.value = result.currentVersion
83
+ latestVersion.value = result.latestVersion
84
+ reason.value = result.reason
85
+ switch (result.status) {
86
+ case 'up-to-date':
87
+ case 'available':
88
+ case 'incompatible':
89
+ status.value = result.status
90
+ break
91
+ case 'idle':
92
+ case 'checking':
93
+ // 宿主返回中间态没有意义(调用已返回)→ 按失败处理,不把界面钉在「检查中」
94
+ status.value = 'error'
95
+ break
96
+ default:
97
+ status.value = 'error'
98
+ }
99
+ } catch {
100
+ status.value = 'error'
101
+ }
102
+ }
103
+
104
+ function check(): Promise<void> {
105
+ if (!inFlight) {
106
+ const pending = run().finally(() => {
107
+ if (inFlight === pending) inFlight = null
108
+ })
109
+ inFlight = pending
110
+ }
111
+ return inFlight
112
+ }
113
+
114
+ return {
115
+ status,
116
+ latestVersion,
117
+ currentVersion,
118
+ reason,
119
+ checking: computed(() => status.value === 'checking'),
120
+ supported,
121
+ check,
122
+ }
123
+ }
@@ -0,0 +1,124 @@
1
+ /**
2
+ * @binblink/wasmnest-plugin-sdk-desktop Vite 插件
3
+ *
4
+ * 处理插件构建时的共享模块外部化:
5
+ * 1. 将 vue/vue-i18n/pinia 标记为 rollup external
6
+ * 2. 构建后将 import 语句替换为 window.__WASMNEST_SHARED__ 读取
7
+ */
8
+ import type { Plugin, UserConfig } from 'vite'
9
+ import MagicString from 'magic-string'
10
+
11
+ /**
12
+ * 共享模块映射:模块名 → 全局变量访问表达式
13
+ *
14
+ * 收录标准:模块内部持有进程级单例状态,第二份实例导致状态错位——
15
+ * vue / vue-i18n / pinia 为运行时本体;`vue-sonner` 为 toast 队列本体
16
+ * (插件自带第二份 → toast 入自家队列,宿主 `<Toaster>` 收不到;票 13)。
17
+ * 宿主 `shared-runtime.ts` 必须同步收录同名条目,否则插件构建期外部化后
18
+ * 运行时取到 undefined。
19
+ */
20
+ const SHARED_MODULES: Record<string, string> = {
21
+ vue: 'window.__WASMNEST_SHARED__["vue"]',
22
+ 'vue-i18n': 'window.__WASMNEST_SHARED__["vue-i18n"]',
23
+ pinia: 'window.__WASMNEST_SHARED__["pinia"]',
24
+ 'vue-sonner': 'window.__WASMNEST_SHARED__["vue-sonner"]',
25
+ }
26
+
27
+ /**
28
+ * WasmNest 插件构建 Vite 插件
29
+ *
30
+ * 在插件 vite.config.ts 中使用:
31
+ * ```ts
32
+ * import { wasmnestPlugin } from '@binblink/wasmnest-plugin-sdk-desktop/vite'
33
+ * export default defineConfig({
34
+ * plugins: [vue(), wasmnestPlugin()],
35
+ * build: { ... }
36
+ * })
37
+ * ```
38
+ */
39
+ export function wasmnestPlugin(): Plugin {
40
+ const externalModules = Object.keys(SHARED_MODULES)
41
+
42
+ return {
43
+ name: 'wasmnest-shared-modules',
44
+ enforce: 'pre',
45
+
46
+ // 注入 rollup external 配置
47
+ config(config: UserConfig) {
48
+ const existingExternal = config.build?.rollupOptions?.external
49
+ const externalArray = Array.isArray(existingExternal)
50
+ ? existingExternal
51
+ : typeof existingExternal === 'string'
52
+ ? [existingExternal]
53
+ : []
54
+
55
+ return {
56
+ build: {
57
+ rollupOptions: {
58
+ external: [...externalArray, ...externalModules],
59
+ },
60
+ },
61
+ }
62
+ },
63
+
64
+ // 构建后替换 import 为全局变量读取
65
+ renderChunk(code, chunk) {
66
+ let modified = false
67
+ const s = new MagicString(code)
68
+
69
+ for (const [modName, globalExpr] of Object.entries(SHARED_MODULES)) {
70
+ const escapedName = modName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
71
+
72
+ // import X from 'vue' → const X = window.__WASMNEST_SHARED__["vue"]
73
+ const defaultRe = new RegExp(`import\\s+(\\w+)\\s+from\\s+['"]${escapedName}['"]`, 'gm')
74
+ let match: RegExpExecArray | null
75
+ while ((match = defaultRe.exec(code)) !== null) {
76
+ const varName = match[1]
77
+ s.overwrite(
78
+ match.index,
79
+ match.index + match[0].length,
80
+ `const ${varName} = ${globalExpr}`,
81
+ )
82
+ modified = true
83
+ }
84
+
85
+ // import { X, Y } from 'vue' → const { X, Y } = window.__WASMNEST_SHARED__["vue"]
86
+ const namedRe = new RegExp(
87
+ `import\\s*\\{([^}]+)\\}\\s*from\\s+['"]${escapedName}['"]`,
88
+ 'gm',
89
+ )
90
+ while ((match = namedRe.exec(code)) !== null) {
91
+ const imports = match[1]
92
+ s.overwrite(
93
+ match.index,
94
+ match.index + match[0].length,
95
+ `const { ${imports} } = ${globalExpr}`,
96
+ )
97
+ modified = true
98
+ }
99
+
100
+ // import * as X from 'vue' → const X = window.__WASMNEST_SHARED__["vue"]
101
+ const namespaceRe = new RegExp(
102
+ `import\\s+\\*\\s+as\\s+(\\w+)\\s+from\\s+['"]${escapedName}['"]`,
103
+ 'gm',
104
+ )
105
+ while ((match = namespaceRe.exec(code)) !== null) {
106
+ const varName = match[1]
107
+ s.overwrite(
108
+ match.index,
109
+ match.index + match[0].length,
110
+ `const ${varName} = ${globalExpr}`,
111
+ )
112
+ modified = true
113
+ }
114
+ }
115
+
116
+ if (!modified) return null
117
+
118
+ return {
119
+ code: s.toString(),
120
+ map: s.generateMap({ hires: true }),
121
+ }
122
+ },
123
+ }
124
+ }
@@ -0,0 +1,39 @@
1
+ # {{NAME}}
2
+
3
+ {{NAME}} wasm 应用 — WasmNest Desktop wasm 应用工程(由 `wasmnest-plugin-desktop create` 生成)。
4
+
5
+ > 术语:本仓把「插件」称为 wasm 应用;`plugin.json` / CLI 命令 / SDK 包名仍用 `plugin` 原词。
6
+
7
+ ## 快速开始
8
+
9
+ ```bash
10
+ pnpm install # 安装依赖(含 SDK、vite、vue)
11
+ pnpm run dev # 浏览器开发环境(Dev Shell:空壳宿主 + 桌面端骨架,HMR)
12
+ pnpm run build # 构建:vite(前端)+ cargo(WASM,仅 full 形态插件)
13
+ pnpm run manifest # 按源码自动填充 plugin.json 的 contributes/permissions
14
+ ```
15
+
16
+ ## 目录结构
17
+
18
+ ```
19
+ ├── plugin.json # 应用清单(id/name/权限/扩展点声明)
20
+ ├── package.json # 工程脚本:dev / build / manifest
21
+ ├── vite.config.ts # 前端构建配置(产物 dist/index.js,vue 等外部化到宿主)
22
+ ├── tsconfig.json
23
+ ├── src/
24
+ │ ├── index.ts # 前端入口:activate(context) / deactivate()
25
+ │ └── env.d.ts # 环境类型声明
26
+ └── rust/ # WASM 后端(--rust 创建;纯前端应用无此目录)
27
+ ├── Cargo.toml
28
+ └── src/lib.rs # WasmPlugin 实现(含 manifest 声明)
29
+ ```
30
+
31
+ ## 安装到 WasmNest Desktop
32
+
33
+ `pnpm run build -- --resources-dir <宿主资源父目录>` 把产物复制到
34
+ `<父目录>/{id}/`(内置应用随安装包分发);用户安装走宿主应用管理。
35
+
36
+ > 权限提醒:桌面端**无默认授予**——`storage` 等权限均需写入 `plugin.json` 的 `permissions`,
37
+ > 未声明即被拒(内置应用均显式声明了 `storage`)。
38
+
39
+ 完整开发指南见仓库文档 `../../../docs/wasm-app-dev-desktop.md`。
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "{{PKG_NAME}}",
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "private": true,
6
+ "type": "module",
7
+ "scripts": {
8
+ "dev": "wasmnest-plugin-desktop dev",
9
+ "build": "wasmnest-plugin-desktop build",
10
+ "manifest": "wasmnest-plugin-desktop manifest"
11
+ },
12
+ "dependencies": {
13
+ "@binblink/wasmnest-plugin-sdk-desktop": "{{SDK_JS}}"
14
+ },
15
+ "devDependencies": {
16
+ "@vitejs/plugin-vue": "^6.0.0",
17
+ "vite": "^8.0.0",
18
+ "vue": "^3.4.0",
19
+ "vue-i18n": "^9.0.0",
20
+ "typescript": "^5.0.0",
21
+ "terser": "^5.0.0"
22
+ }
23
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "id": "{{ID}}",
3
+ "name": "{{NAME}}",
4
+ "version": "0.0.1",
5
+ "platform": "desktop",
6
+ "description": "",
7
+ "author": "{{AUTHOR}}",
8
+ "main": "index.js",
9
+ "sandbox": "inline",
10
+ "pluginType": "{{PLUGIN_TYPE}}",
11
+ {{RUST_LIBRARY_LINE}} "icon": "",
12
+ "permissions": ["storage"],
13
+ "contributes": {}
14
+ }
@@ -0,0 +1,21 @@
1
+ [package]
2
+ name = "{{CRATE}}"
3
+ version = "0.0.1"
4
+ license = "MIT"
5
+ description = "{{NAME}} 插件 WASM 后端"
6
+ authors = ["{{AUTHOR}}"]
7
+ edition = "2021"
8
+
9
+ [features]
10
+ default = []
11
+ # wasm:启用 WasmPlugin trait / wasm_entry! 宏(WASM 插件必开)
12
+ wasm = []
13
+
14
+ [lib]
15
+ crate-type = ["cdylib"]
16
+
17
+ [dependencies]
18
+ wasmnest-plugin-api = {{SDK_RUST}}
19
+ serde = { version = "1", features = ["derive"] }
20
+ serde_json = "1"
21
+ anyhow = "1"
@@ -0,0 +1,39 @@
1
+ //! {{NAME}} 插件后端(WASM)
2
+ //!
3
+ //! 最小可编译实现:激活/停用日志,命令返回未知命令错误。
4
+ //! 通过 wasmnest-plugin-api 的 WasmPlugin trait 实现,wasm_entry! 宏生成 ABI 导出。
5
+
6
+ use wasmnest_plugin_api::types::PluginManifest;
7
+ use wasmnest_plugin_api::{WasmHost, WasmPlugin};
8
+
9
+ struct {{STRUCT}};
10
+
11
+ impl WasmPlugin for {{STRUCT}} {
12
+ const ID: &'static str = "{{ID}}";
13
+
14
+ fn manifest() -> PluginManifest {
15
+ // plugin.json 为 manifest 单一事实来源(wasmnest-plugin-desktop build 时自动填充)
16
+ serde_json::from_str(include_str!("../../plugin.json"))
17
+ .expect("plugin.json must be valid PluginManifest")
18
+ }
19
+
20
+ fn activate() -> anyhow::Result<()> {
21
+ WasmHost.log_info("{{NAME}} plugin activated (wasm)");
22
+ Ok(())
23
+ }
24
+
25
+ fn deactivate() -> anyhow::Result<()> {
26
+ WasmHost.log_info("{{NAME}} plugin deactivated (wasm)");
27
+ Ok(())
28
+ }
29
+
30
+ fn invoke_command(_name: &str, _args: serde_json::Value) -> anyhow::Result<serde_json::Value> {
31
+ // 业务失败请携带业务语义码(ADR 0030 决定 6,零 ABI)——用户看到的是友好文案,
32
+ // 详情只进日志;code = 插件 i18n 注册后的完整 key:
33
+ // bail_with_code!("{{ID}}.errors.unknownCommand");
34
+ // bail_with_code!("{{ID}}.errors.throttled", serde_json::json!({ "waitSecs": 5 }));
35
+ Err(anyhow::anyhow!("No commands implemented"))
36
+ }
37
+ }
38
+
39
+ wasmnest_plugin_api::wasm_entry!({{STRUCT}});
@@ -0,0 +1,24 @@
1
+ /**
2
+ * SDK 类型环境声明(模板自身用)
3
+ *
4
+ * 模板是 create 命令生成的样板工程,生成前不依赖 node_modules——本声明让
5
+ * tsserver 在模板目录内可解析 SDK 包名(避免 Cannot find module 假阳性)。
6
+ * 生成的插件工程 `pnpm install` 后以真实 SDK 类型为准(ambient 声明优先级
7
+ * 低于实际模块解析,自动被覆盖),此文件仅作模板开发期的类型兜底。
8
+ */
9
+ declare module '@binblink/wasmnest-plugin-sdk-desktop' {
10
+ /** 插件上下文(最小可编译形状;生成工程以 SDK 真实类型为准) */
11
+ export interface PluginContext {
12
+ [key: string]: unknown
13
+ }
14
+ }
15
+
16
+ declare module '@binblink/wasmnest-plugin-sdk-desktop/ui' {
17
+ import type { DefineComponent } from 'vue'
18
+ const component: DefineComponent<Record<string, unknown>, Record<string, unknown>, unknown>
19
+ export default component
20
+ }
21
+
22
+ declare module '@binblink/wasmnest-plugin-sdk-desktop/vite' {
23
+ export function wasmnestPlugin(options?: Record<string, unknown>): unknown
24
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * {{NAME}} 插件入口 (Desktop)
3
+ *
4
+ * 最小可编译模板:注册一个侧边栏面板(内联渲染函数组件,
5
+ * 面板 UI 较大时建议拆成独立 .vue 组件引入)。
6
+ */
7
+ import { defineComponent, h } from 'vue'
8
+ import type { PluginContext } from '@binblink/wasmnest-plugin-sdk-desktop'
9
+
10
+ let _ctx: PluginContext
11
+
12
+ export async function activate(context: PluginContext): Promise<void> {
13
+ _ctx = context
14
+
15
+ // 注册侧边栏面板(宿主经 PluginViewHost provide pluginContext,组件内可 inject)
16
+ context.ui.registerSidebarPanel({
17
+ id: '{{ID}}.sidebar',
18
+ title: '{{NAME}}',
19
+ icon: 'M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z',
20
+ order: 600,
21
+ component: defineComponent({
22
+ name: '{{STRUCT}}Panel',
23
+ render: () =>
24
+ h(
25
+ 'div',
26
+ { style: 'padding: 16px; color: var(--text-secondary); font-size: 13px' },
27
+ '{{NAME}} 面板内容 — 在这里编写你的插件 UI',
28
+ ),
29
+ }),
30
+ })
31
+
32
+ console.log('[{{ID}}] Plugin activated')
33
+ }
34
+
35
+ export async function deactivate(): Promise<void> {
36
+ console.log('[{{ID}}] Plugin deactivated')
37
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "jsx": "preserve",
8
+ "resolveJsonModule": true,
9
+ "isolatedModules": true,
10
+ "esModuleInterop": true,
11
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
12
+ "skipLibCheck": true,
13
+ "noEmit": true
14
+ },
15
+ "include": ["src/**/*.ts", "src/**/*.vue"],
16
+ "exclude": ["node_modules", "rust"]
17
+ }
@@ -0,0 +1,21 @@
1
+ import { defineConfig } from 'vite'
2
+ import vue from '@vitejs/plugin-vue'
3
+ import { resolve } from 'node:path'
4
+ import { wasmnestPlugin } from '@binblink/wasmnest-plugin-sdk-desktop/vite'
5
+
6
+ export default defineConfig({
7
+ plugins: [vue(), wasmnestPlugin()],
8
+ define: {
9
+ 'process.env.NODE_ENV': JSON.stringify('production'),
10
+ },
11
+ build: {
12
+ lib: {
13
+ entry: resolve(__dirname, 'src/index.ts'),
14
+ formats: ['es'],
15
+ fileName: () => 'index.js',
16
+ },
17
+ outDir: resolve(__dirname, 'dist'),
18
+ emptyOutDir: true,
19
+ minify: 'terser',
20
+ },
21
+ })