@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,390 @@
1
+ <template>
2
+ <!--
3
+ 数字步进输入(token 皮肤 + reka-ui Primitive 原语)
4
+ 右侧竖排两个大按钮取代浏览器原生 spinner(原生上下箭头只有 6px 左右,点不中也不吃 token)。
5
+ -->
6
+ <div
7
+ class="wb-nf"
8
+ :class="[sizeCls, { 'wb-nf-disabled': disabled, 'wb-nf-readonly': readonly }]"
9
+ :style="width ? { width } : undefined"
10
+ >
11
+ <Primitive
12
+ as="input"
13
+ :id="inputId"
14
+ class="wb-nf-input"
15
+ :class="[{ 'wb-nf-input-right': align === 'right' }, mono && 'wb-mono']"
16
+ type="text"
17
+ role="spinbutton"
18
+ inputmode="numeric"
19
+ autocomplete="off"
20
+ spellcheck="false"
21
+ :value="text"
22
+ :disabled="disabled"
23
+ :readonly="readonly"
24
+ :aria-label="ariaLabel"
25
+ :aria-valuenow="modelValue ?? undefined"
26
+ :aria-valuemin="min"
27
+ :aria-valuemax="max"
28
+ :aria-valuetext="text || undefined"
29
+ :data-testid="testid"
30
+ @input="onInput"
31
+ @keydown="onKeydown"
32
+ @blur="onBlur"
33
+ />
34
+ <span class="wb-nf-steppers">
35
+ <button
36
+ type="button"
37
+ class="wb-nf-btn"
38
+ tabindex="-1"
39
+ :aria-label="labelIncrease"
40
+ :disabled="disabled || readonly || atMax"
41
+ @click="stepBy(1)"
42
+ >
43
+ <svg viewBox="0 0 12 12" aria-hidden="true" fill="none" stroke="currentColor">
44
+ <path
45
+ stroke-linecap="round"
46
+ stroke-linejoin="round"
47
+ stroke-width="2"
48
+ d="M3 7.5 6 4.5l3 3"
49
+ />
50
+ </svg>
51
+ </button>
52
+ <button
53
+ type="button"
54
+ class="wb-nf-btn"
55
+ tabindex="-1"
56
+ :aria-label="labelDecrease"
57
+ :disabled="disabled || readonly || atMin"
58
+ @click="stepBy(-1)"
59
+ >
60
+ <svg viewBox="0 0 12 12" aria-hidden="true" fill="none" stroke="currentColor">
61
+ <path
62
+ stroke-linecap="round"
63
+ stroke-linejoin="round"
64
+ stroke-width="2"
65
+ d="M3 4.5 6 7.5l3-3"
66
+ />
67
+ </svg>
68
+ </button>
69
+ </span>
70
+ </div>
71
+ </template>
72
+
73
+ <script setup lang="ts">
74
+ /**
75
+ * NumberField — 数字输入(含步进按钮)共享组件
76
+ *
77
+ * 为什么取代原生 `<input type="number">`:原生 spinner 由浏览器绘制,箭头只有 6px 左右、
78
+ * 不吃 token 也不吃 `--ui-scale`,在设置页里既点不中也难看(「原生 UI 禁令」同口径)。
79
+ *
80
+ * 实现路线:reka-ui 的 `Primitive` 原语(开源 headless,Radix UI 的 Vue 版,也是
81
+ * shadcn-vue 的底层)+ 本组件的受控状态。**没有**直接用 reka-ui 的 `NumberField` 成套
82
+ * 组件,原因是它把输入框渲染成受控 `value`,用户键入后内部 `inputValue` 与 `textValue`
83
+ * 不同步,失焦时会把已输入的合法值回退成旧值(实测键入 600、失焦后框里变回 300)。
84
+ * 这里只借原语的元素下发与属性转发,值、解析、钳制、提交时机全部在本组件内闭合。
85
+ *
86
+ * 取值口径:
87
+ * - 手动输入不做「吸附到步进网格」(端口 8765、超时 45 这类值不该被悄悄改掉),
88
+ * 只按 `min`/`max` 硬钳制,并按整数取整。
89
+ * - `update:modelValue`:合法键入即时上抛(受控:调用方回写即生效)。
90
+ * - `commit`:失焦 / 回车时上抛**钳制后**的最终值——落盘用它,不要在 `@blur` 里读事件值。
91
+ * - 清空输入不提交(调用方保留原值),避免「清空即写 0」。
92
+ */
93
+ import { Primitive } from 'reka-ui'
94
+ import { computed, ref, watch } from 'vue'
95
+
96
+ interface Props {
97
+ /** 当前值;清空后以 null 回抛 */
98
+ modelValue: number | null
99
+ min?: number
100
+ /** 不传 = 不设上限 */
101
+ max?: number
102
+ /** 每次点击 / 方向键的变化量,默认 1 */
103
+ step?: number
104
+ /** 框体尺寸:sm = 插件紧凑行(32px / 12px),md = 宿主表单默认(--input-height) */
105
+ size?: 'sm' | 'md'
106
+ /** 文本对齐:设置页右侧控件用 right,表单字段用 left */
107
+ align?: 'left' | 'right'
108
+ /** 宽度(CSS 长度);不传则铺满父容器 */
109
+ width?: string
110
+ /** 等宽字体(端口 / 秒数这类纯数字更整齐),默认 true */
111
+ mono?: boolean
112
+ disabled?: boolean
113
+ readonly?: boolean
114
+ /** 无障碍名称(没有外置 label 时必须给) */
115
+ ariaLabel?: string
116
+ /** 输入框 id;与外部 `<label for>` 配对时必传(否则标签点不到输入框) */
117
+ inputId?: string
118
+ /** 增/减按钮的无障碍名称,默认 "增加"/"减少" */
119
+ labelIncrease?: string
120
+ labelDecrease?: string
121
+ testid?: string
122
+ }
123
+
124
+ const props = withDefaults(defineProps<Props>(), {
125
+ min: undefined,
126
+ max: undefined,
127
+ step: 1,
128
+ size: 'sm',
129
+ align: 'right',
130
+ width: undefined,
131
+ mono: true,
132
+ disabled: false,
133
+ readonly: false,
134
+ ariaLabel: undefined,
135
+ inputId: undefined,
136
+ labelIncrease: '增加',
137
+ labelDecrease: '减少',
138
+ testid: undefined,
139
+ })
140
+
141
+ const emit = defineEmits<{
142
+ /** 合法键入 / 步进后的值;清空为 null */
143
+ (e: 'update:modelValue', value: number | null): void
144
+ /** 输入结束,携带钳制后的最终值——落盘时机 */
145
+ (e: 'commit', value: number): void
146
+ }>()
147
+
148
+ /** 尺寸类:模板 `:class` 直接引用;**必须**有定义,缺了它框体只剩内容高度
149
+ * (12.5px 字 + 行高 ≈ 17px),步进箭头跟着被压成一条,设置页里就是「输入框和
150
+ * 上下箭头都小得不成比例」(2026-11-06 修复:此前 sizeCls 悬空,sm/md 两档样式从未生效)。 */
151
+ const sizeCls = computed(() => `wb-nf-${props.size}`)
152
+
153
+ /** 用户正在编辑的原始文本;非编辑态跟随 modelValue 格式化回显 */
154
+ const draft = ref<string>(props.modelValue === null ? '' : String(props.modelValue))
155
+ const editing = ref(false)
156
+
157
+ watch(
158
+ () => props.modelValue,
159
+ (next) => {
160
+ // 编辑中不打断用户键入(受控回写由文本本身体现);非编辑态同步外部改动
161
+ if (editing.value) return
162
+ draft.value = next === null ? '' : String(next)
163
+ },
164
+ )
165
+
166
+ const text = computed(() => draft.value)
167
+
168
+ /** 收敛到 [min, max] 并取整 */
169
+ function clampValue(value: number): number {
170
+ let next = Math.round(value)
171
+ if (props.min !== undefined) next = Math.max(props.min, next)
172
+ if (props.max !== undefined) next = Math.min(props.max, next)
173
+ return next
174
+ }
175
+
176
+ /** 解析文本框内容:空 / 非数字返回 null */
177
+ function parseDraft(): number | null {
178
+ const raw = draft.value.trim()
179
+ if (raw === '') return null
180
+ // 只接受可选负号 + 数字,避免 "12abc" / "1e5" 这类被 Number 宽松接受
181
+ if (!/^-?\d+$/.test(raw)) return null
182
+ const parsed = Number(raw)
183
+ return Number.isFinite(parsed) ? parsed : null
184
+ }
185
+
186
+ const atMin = computed(() => props.min !== undefined && (props.modelValue ?? 0) <= props.min)
187
+ const atMax = computed(() => props.max !== undefined && (props.modelValue ?? 0) >= props.max)
188
+
189
+ function onInput(e: Event) {
190
+ const el = e.target as HTMLInputElement
191
+ editing.value = true
192
+ // 过滤掉数字与负号以外的键入,光标位置不受影响(只挡非法字符,不改合法输入)
193
+ const cleaned = el.value.replace(/[^\d-]/g, '')
194
+ if (cleaned !== el.value) el.value = cleaned
195
+ draft.value = cleaned
196
+ const parsed = parseDraft()
197
+ emit('update:modelValue', parsed)
198
+ }
199
+
200
+ /** 按 step 增减:以当前生效值(文本框解析值优先)为基准 */
201
+ function stepBy(direction: 1 | -1) {
202
+ if (props.disabled || props.readonly) return
203
+ const base = parseDraft() ?? props.modelValue ?? props.min ?? 0
204
+ const next = clampValue(base + direction * props.step)
205
+ editing.value = false
206
+ draft.value = String(next)
207
+ emit('update:modelValue', next)
208
+ emit('commit', next)
209
+ }
210
+
211
+ function onKeydown(e: KeyboardEvent) {
212
+ if (e.isComposing) return
213
+ // 方向键单步;PageUp/PageDown 十倍步进(与原生 number 一致)
214
+ const multiplier = e.key === 'PageUp' || e.key === 'PageDown' ? 10 : 1
215
+ if (e.key === 'ArrowUp' || e.key === 'PageUp') {
216
+ e.preventDefault()
217
+ stepTimes(multiplier)
218
+ } else if (e.key === 'ArrowDown' || e.key === 'PageDown') {
219
+ e.preventDefault()
220
+ stepTimes(-multiplier)
221
+ } else if (e.key === 'Home' && props.min !== undefined) {
222
+ e.preventDefault()
223
+ setValue(props.min)
224
+ } else if (e.key === 'End' && props.max !== undefined) {
225
+ e.preventDefault()
226
+ setValue(props.max)
227
+ } else if (e.key === 'Enter') {
228
+ // 回车:与失焦同口径(原生 number 输入也是回车即提交)
229
+ e.preventDefault()
230
+ commitInput()
231
+ ;(e.target as HTMLInputElement).blur()
232
+ }
233
+ }
234
+
235
+ function stepTimes(multiplier: number) {
236
+ if (props.disabled || props.readonly) return
237
+ const base = parseDraft() ?? props.modelValue ?? props.min ?? 0
238
+ const next = clampValue(base + Math.sign(multiplier) * props.step * Math.abs(multiplier))
239
+ editing.value = false
240
+ draft.value = String(next)
241
+ emit('update:modelValue', next)
242
+ emit('commit', next)
243
+ }
244
+
245
+ function setValue(value: number) {
246
+ editing.value = false
247
+ draft.value = String(value)
248
+ emit('update:modelValue', value)
249
+ emit('commit', value)
250
+ }
251
+
252
+ /**
253
+ * 失焦:把键入值收敛后落盘,并把框内文本改成收敛结果。
254
+ * 收敛在本组件里算,不依赖任何三方库的回写时序。
255
+ */
256
+ function commitInput() {
257
+ const parsed = parseDraft()
258
+ editing.value = false
259
+ if (parsed === null) {
260
+ // 非法 / 清空:回到当前受控值,不提交
261
+ draft.value = props.modelValue === null ? '' : String(props.modelValue)
262
+ return
263
+ }
264
+ const next = clampValue(parsed)
265
+ draft.value = String(next)
266
+ if (next !== props.modelValue) emit('update:modelValue', next)
267
+ emit('commit', next)
268
+ }
269
+
270
+ function onBlur() {
271
+ commitInput()
272
+ }
273
+ </script>
274
+
275
+ <style>
276
+ /**
277
+ * 样式刻意不加 scoped:Tailwind 由宿主 / 各插件 app 自编译,SDK 组件的 class 也要在
278
+ * 全局样式表里生效;副作用面由 `wb-nf` 前缀收敛。颜色全部绑定 token,随主题与
279
+ * `--ui-scale` 一起变。
280
+ */
281
+ .wb-nf {
282
+ display: inline-flex;
283
+ align-items: stretch;
284
+ box-sizing: border-box;
285
+ overflow: hidden;
286
+ border: 1px solid var(--border-input);
287
+ border-radius: var(--radius-input, 8px);
288
+ background: var(--bg-input);
289
+ transition:
290
+ border-color 0.15s ease,
291
+ box-shadow 0.15s ease;
292
+ }
293
+
294
+ /* 焦点环挂在容器上(真正聚焦的是里面的 input) */
295
+ .wb-nf:focus-within {
296
+ border-color: var(--color-primary);
297
+ box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary) 18%, transparent);
298
+ }
299
+
300
+ .wb-nf-disabled,
301
+ .wb-nf-readonly {
302
+ opacity: 0.5;
303
+ }
304
+
305
+ /* 尺寸:sm = 插件设置页紧凑行(与既有 h-8 / 12.5px 控件同高) */
306
+ .wb-nf-sm {
307
+ height: 32px;
308
+ }
309
+
310
+ /* md = 宿主表单默认高度,字号与 Select(md) 对齐 */
311
+ .wb-nf-md {
312
+ height: var(--input-height, 36px);
313
+ }
314
+
315
+ .wb-nf-md .wb-nf-input {
316
+ padding: 0 12px;
317
+ font-size: 14px;
318
+ }
319
+
320
+ .wb-nf-md .wb-nf-steppers {
321
+ width: 28px;
322
+ }
323
+
324
+ .wb-nf-md .wb-nf-btn svg {
325
+ width: 13px;
326
+ height: 13px;
327
+ }
328
+
329
+ .wb-nf-input {
330
+ flex: 1 1 auto;
331
+ min-width: 0;
332
+ padding: 0 10px;
333
+ border: 0;
334
+ outline: none;
335
+ background: transparent;
336
+ color: var(--text-primary);
337
+ font-size: 12.5px;
338
+ line-height: 1.2;
339
+ }
340
+
341
+ .wb-nf-input-right {
342
+ text-align: right;
343
+ }
344
+
345
+ /* 右侧竖排步进按钮:各占半高,可点区域远大于原生 spinner 的 6px 小箭头
346
+ (24px 列宽是下限:20px 时 12px 字形只剩 4px 内边距,箭头看起来像装饰而不是控件) */
347
+ .wb-nf-steppers {
348
+ display: flex;
349
+ flex: 0 0 auto;
350
+ flex-direction: column;
351
+ width: 24px;
352
+ border-left: 1px solid var(--border-input);
353
+ }
354
+
355
+ .wb-nf-btn {
356
+ display: flex;
357
+ flex: 1 1 0;
358
+ align-items: center;
359
+ justify-content: center;
360
+ border: 0;
361
+ padding: 0;
362
+ background: transparent;
363
+ /* 用 secondary 而不是 tertiary:12px 字形下 tertiary 太淡,看不清是可点的箭头 */
364
+ color: var(--text-secondary);
365
+ cursor: pointer;
366
+ transition:
367
+ background-color 0.12s ease,
368
+ color 0.12s ease;
369
+ }
370
+
371
+ .wb-nf-btn svg {
372
+ width: 12px;
373
+ height: 12px;
374
+ }
375
+
376
+ .wb-nf-btn:hover:not(:disabled) {
377
+ background: var(--color-primary-light);
378
+ color: var(--color-primary);
379
+ }
380
+
381
+ .wb-nf-btn:disabled {
382
+ cursor: not-allowed;
383
+ opacity: 0.3;
384
+ }
385
+
386
+ /* 上下两格之间的细分隔线,视觉上分成两个可点区域 */
387
+ .wb-nf-btn + .wb-nf-btn {
388
+ border-top: 1px solid var(--border-input);
389
+ }
390
+ </style>