@shiqianjiang/ceru-plugin-cli 0.3.15 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/README.md +26 -7
  2. package/assets/compatibility.json +18 -0
  3. package/dist/compatibility.d.ts +24 -0
  4. package/dist/compatibility.js +119 -0
  5. package/dist/component.d.ts +6 -0
  6. package/dist/component.js +60 -0
  7. package/dist/dev-music.d.ts +19 -0
  8. package/dist/dev-music.js +81 -0
  9. package/dist/dev-plugin-services.d.ts +10 -0
  10. package/dist/dev-plugin-services.js +67 -0
  11. package/dist/dev.d.ts +1 -9
  12. package/dist/dev.js +53 -713
  13. package/dist/frameworks.d.ts +5 -2
  14. package/dist/frameworks.js +43 -6
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +54 -23
  17. package/dist/init.js +3 -3
  18. package/dist/migrate.d.ts +3 -0
  19. package/dist/migrate.js +109 -0
  20. package/dist/project.d.ts +5 -2
  21. package/dist/project.js +131 -43
  22. package/dist/test-hooks.d.ts +1 -0
  23. package/dist/test-hooks.js +209 -0
  24. package/dist/test-services.d.ts +4 -0
  25. package/dist/test-services.js +54 -0
  26. package/dist/watch-vue-types.d.ts +17 -0
  27. package/dist/watch-vue-types.js +145 -0
  28. package/package.json +10 -6
  29. package/schemas/config.schema.json +954 -452
  30. package/templates/account-qrcode/js/.vscode/extensions.json +3 -0
  31. package/templates/account-qrcode/js/.vscode/launch.json +19 -0
  32. package/templates/account-qrcode/js/.vscode/settings.json +20 -0
  33. package/templates/account-qrcode/js/.vscode/tasks.json +43 -0
  34. package/templates/account-qrcode/js/README.md +15 -0
  35. package/templates/account-qrcode/js/_gitignore +6 -0
  36. package/templates/account-qrcode/js/ceru-plugin.code-workspace +8 -0
  37. package/templates/account-qrcode/js/ceru.plugin.json +62 -0
  38. package/templates/account-qrcode/js/package.json +24 -0
  39. package/templates/account-qrcode/js/src/Login.vue +25 -0
  40. package/templates/account-qrcode/js/src/index.js +25 -0
  41. package/templates/account-qrcode/js/src/login-html.js +23 -0
  42. package/templates/account-qrcode/js/tsconfig.json +17 -0
  43. package/templates/account-qrcode/ts/.vscode/extensions.json +3 -0
  44. package/templates/account-qrcode/ts/.vscode/launch.json +19 -0
  45. package/templates/account-qrcode/ts/.vscode/settings.json +20 -0
  46. package/templates/account-qrcode/ts/.vscode/tasks.json +43 -0
  47. package/templates/account-qrcode/ts/README.md +15 -0
  48. package/templates/account-qrcode/ts/_gitignore +6 -0
  49. package/templates/account-qrcode/ts/ceru-plugin.code-workspace +8 -0
  50. package/templates/account-qrcode/ts/ceru.plugin.json +62 -0
  51. package/templates/account-qrcode/ts/package.json +24 -0
  52. package/templates/account-qrcode/ts/src/Login.vue +25 -0
  53. package/templates/account-qrcode/ts/src/index.ts +25 -0
  54. package/templates/account-qrcode/ts/src/login-html.ts +23 -0
  55. package/templates/account-qrcode/ts/tsconfig.json +17 -0
  56. package/templates/connected-library/js/.vscode/launch.json +12 -29
  57. package/templates/connected-library/js/.vscode/tasks.json +2 -3
  58. package/templates/connected-library/js/README.md +26 -12
  59. package/templates/connected-library/js/ceru.plugin.json +122 -50
  60. package/templates/connected-library/js/package.json +5 -5
  61. package/templates/connected-library/js/src/index.js +46 -5
  62. package/templates/connected-library/js/src/settings.js +28 -0
  63. package/templates/connected-library/ts/.vscode/launch.json +12 -29
  64. package/templates/connected-library/ts/.vscode/tasks.json +2 -3
  65. package/templates/connected-library/ts/README.md +26 -12
  66. package/templates/connected-library/ts/ceru.plugin.json +122 -50
  67. package/templates/connected-library/ts/package.json +5 -5
  68. package/templates/connected-library/ts/src/index.ts +46 -5
  69. package/templates/connected-library/ts/src/settings.ts +28 -0
  70. package/templates/encrypted-source/README.md +86 -0
  71. package/templates/encrypted-source/js/.prettierrc.json +5 -0
  72. package/templates/encrypted-source/js/.vscode/ceru.code-snippets +55 -0
  73. package/templates/encrypted-source/js/.vscode/extensions.json +3 -0
  74. package/templates/encrypted-source/js/.vscode/launch.json +15 -0
  75. package/templates/encrypted-source/js/.vscode/settings.json +20 -0
  76. package/templates/encrypted-source/js/.vscode/tasks.json +40 -0
  77. package/templates/encrypted-source/js/DEMO.md +77 -0
  78. package/templates/encrypted-source/js/README.md +13 -0
  79. package/templates/encrypted-source/js/_gitignore +6 -0
  80. package/templates/encrypted-source/js/ceru-plugin.code-workspace +8 -0
  81. package/templates/encrypted-source/js/ceru.plugin.json +95 -0
  82. package/templates/encrypted-source/js/package.json +26 -0
  83. package/templates/encrypted-source/js/resources/xor-byte.wasm +0 -0
  84. package/templates/encrypted-source/js/resources/xor-byte.wat +5 -0
  85. package/templates/encrypted-source/js/src/demo.js +200 -0
  86. package/templates/encrypted-source/js/src/fixtures.js +118 -0
  87. package/templates/encrypted-source/js/src/index.js +4 -0
  88. package/templates/encrypted-source/js/tests/demo.test.mjs +357 -0
  89. package/templates/encrypted-source/js/tsconfig.json +16 -0
  90. package/templates/encrypted-source/ts/.prettierrc.json +5 -0
  91. package/templates/encrypted-source/ts/.vscode/ceru.code-snippets +55 -0
  92. package/templates/encrypted-source/ts/.vscode/extensions.json +3 -0
  93. package/templates/encrypted-source/ts/.vscode/launch.json +15 -0
  94. package/templates/encrypted-source/ts/.vscode/settings.json +20 -0
  95. package/templates/encrypted-source/ts/.vscode/tasks.json +40 -0
  96. package/templates/encrypted-source/ts/DEMO.md +77 -0
  97. package/templates/encrypted-source/ts/README.md +13 -0
  98. package/templates/encrypted-source/ts/_gitignore +6 -0
  99. package/templates/encrypted-source/ts/ceru-plugin.code-workspace +8 -0
  100. package/templates/encrypted-source/ts/ceru.plugin.json +95 -0
  101. package/templates/encrypted-source/ts/package.json +26 -0
  102. package/templates/encrypted-source/ts/resources/xor-byte.wasm +0 -0
  103. package/templates/encrypted-source/ts/resources/xor-byte.wat +5 -0
  104. package/templates/encrypted-source/ts/src/demo.ts +212 -0
  105. package/templates/encrypted-source/ts/src/fixtures.ts +125 -0
  106. package/templates/encrypted-source/ts/src/index.ts +4 -0
  107. package/templates/encrypted-source/ts/tests/demo.test.mjs +357 -0
  108. package/templates/encrypted-source/ts/tsconfig.json +17 -0
  109. package/templates/guest-adapter/js/.vscode/launch.json +12 -29
  110. package/templates/guest-adapter/js/.vscode/tasks.json +2 -3
  111. package/templates/guest-adapter/js/README.md +10 -10
  112. package/templates/guest-adapter/js/ceru.plugin.json +67 -62
  113. package/templates/guest-adapter/js/package.json +5 -5
  114. package/templates/guest-adapter/js/src/index.js +1 -1
  115. package/templates/guest-adapter/js/src/settings.js +8 -0
  116. package/templates/guest-adapter/ts/.vscode/launch.json +12 -29
  117. package/templates/guest-adapter/ts/.vscode/tasks.json +2 -3
  118. package/templates/guest-adapter/ts/README.md +10 -10
  119. package/templates/guest-adapter/ts/ceru.plugin.json +67 -62
  120. package/templates/guest-adapter/ts/package.json +5 -5
  121. package/templates/guest-adapter/ts/src/index.ts +1 -1
  122. package/templates/guest-adapter/ts/src/settings.ts +8 -0
  123. package/templates/importer/js/.vscode/launch.json +12 -29
  124. package/templates/importer/js/.vscode/tasks.json +2 -3
  125. package/templates/importer/js/README.md +10 -10
  126. package/templates/importer/js/ceru.plugin.json +23 -21
  127. package/templates/importer/js/package.json +5 -5
  128. package/templates/importer/ts/.vscode/launch.json +12 -29
  129. package/templates/importer/ts/.vscode/tasks.json +2 -3
  130. package/templates/importer/ts/README.md +10 -10
  131. package/templates/importer/ts/ceru.plugin.json +23 -21
  132. package/templates/importer/ts/package.json +5 -5
  133. package/templates/page-extension/js/.vscode/extensions.json +3 -0
  134. package/templates/page-extension/js/.vscode/launch.json +19 -0
  135. package/templates/page-extension/js/.vscode/settings.json +20 -0
  136. package/templates/page-extension/js/.vscode/tasks.json +43 -0
  137. package/templates/page-extension/js/README.md +9 -0
  138. package/templates/page-extension/js/_gitignore +6 -0
  139. package/templates/page-extension/js/ceru-plugin.code-workspace +8 -0
  140. package/templates/page-extension/js/ceru.plugin.json +94 -0
  141. package/templates/page-extension/js/package.json +24 -0
  142. package/templates/page-extension/js/src/Open.vue +6 -0
  143. package/templates/page-extension/js/src/Search.vue +62 -0
  144. package/templates/page-extension/js/src/index.js +54 -0
  145. package/templates/page-extension/js/tsconfig.json +17 -0
  146. package/templates/page-extension/ts/.vscode/extensions.json +3 -0
  147. package/templates/page-extension/ts/.vscode/launch.json +19 -0
  148. package/templates/page-extension/ts/.vscode/settings.json +20 -0
  149. package/templates/page-extension/ts/.vscode/tasks.json +43 -0
  150. package/templates/page-extension/ts/README.md +9 -0
  151. package/templates/page-extension/ts/_gitignore +6 -0
  152. package/templates/page-extension/ts/ceru-plugin.code-workspace +8 -0
  153. package/templates/page-extension/ts/ceru.plugin.json +94 -0
  154. package/templates/page-extension/ts/package.json +24 -0
  155. package/templates/page-extension/ts/src/Open.vue +6 -0
  156. package/templates/page-extension/ts/src/Search.vue +62 -0
  157. package/templates/page-extension/ts/src/index.ts +54 -0
  158. package/templates/page-extension/ts/tsconfig.json +17 -0
  159. package/templates/playback-hook/js/.prettierrc.json +5 -0
  160. package/templates/playback-hook/js/.vscode/extensions.json +3 -0
  161. package/templates/playback-hook/js/.vscode/launch.json +19 -0
  162. package/templates/playback-hook/js/.vscode/settings.json +20 -0
  163. package/templates/playback-hook/js/.vscode/tasks.json +50 -0
  164. package/templates/playback-hook/js/README.md +24 -0
  165. package/templates/playback-hook/js/_gitignore +6 -0
  166. package/templates/playback-hook/js/ceru-plugin.code-workspace +8 -0
  167. package/templates/playback-hook/js/ceru.plugin.json +36 -0
  168. package/templates/playback-hook/js/package.json +23 -0
  169. package/templates/playback-hook/js/src/index.js +25 -0
  170. package/templates/playback-hook/js/tests/hooks.json +316 -0
  171. package/templates/playback-hook/js/tsconfig.json +16 -0
  172. package/templates/playback-hook/ts/.prettierrc.json +5 -0
  173. package/templates/playback-hook/ts/.vscode/extensions.json +3 -0
  174. package/templates/playback-hook/ts/.vscode/launch.json +19 -0
  175. package/templates/playback-hook/ts/.vscode/settings.json +20 -0
  176. package/templates/playback-hook/ts/.vscode/tasks.json +50 -0
  177. package/templates/playback-hook/ts/README.md +24 -0
  178. package/templates/playback-hook/ts/_gitignore +6 -0
  179. package/templates/playback-hook/ts/ceru-plugin.code-workspace +8 -0
  180. package/templates/playback-hook/ts/ceru.plugin.json +36 -0
  181. package/templates/playback-hook/ts/package.json +23 -0
  182. package/templates/playback-hook/ts/src/index.ts +25 -0
  183. package/templates/playback-hook/ts/tests/hooks.json +316 -0
  184. package/templates/playback-hook/ts/tsconfig.json +16 -0
  185. package/templates/player-skin/js/.vscode/extensions.json +3 -0
  186. package/templates/player-skin/js/.vscode/launch.json +19 -0
  187. package/templates/player-skin/js/.vscode/settings.json +20 -0
  188. package/templates/player-skin/js/.vscode/tasks.json +43 -0
  189. package/templates/player-skin/js/README.md +11 -0
  190. package/templates/player-skin/js/_gitignore +6 -0
  191. package/templates/player-skin/js/assets/studio-preview.svg +15 -0
  192. package/templates/player-skin/js/ceru-plugin.code-workspace +8 -0
  193. package/templates/player-skin/js/ceru.plugin.json +77 -0
  194. package/templates/player-skin/js/package.json +24 -0
  195. package/templates/player-skin/js/src/Artwork.vue +9 -0
  196. package/templates/player-skin/js/src/Background.vue +15 -0
  197. package/templates/player-skin/js/src/BuiltinLyrics.vue +15 -0
  198. package/templates/player-skin/js/src/Lyrics.vue +28 -0
  199. package/templates/player-skin/js/tsconfig.json +17 -0
  200. package/templates/player-skin/ts/.vscode/extensions.json +3 -0
  201. package/templates/player-skin/ts/.vscode/launch.json +19 -0
  202. package/templates/player-skin/ts/.vscode/settings.json +20 -0
  203. package/templates/player-skin/ts/.vscode/tasks.json +43 -0
  204. package/templates/player-skin/ts/README.md +11 -0
  205. package/templates/player-skin/ts/_gitignore +6 -0
  206. package/templates/player-skin/ts/assets/studio-preview.svg +15 -0
  207. package/templates/player-skin/ts/ceru-plugin.code-workspace +8 -0
  208. package/templates/player-skin/ts/ceru.plugin.json +77 -0
  209. package/templates/player-skin/ts/package.json +24 -0
  210. package/templates/player-skin/ts/src/Artwork.vue +9 -0
  211. package/templates/player-skin/ts/src/Background.vue +15 -0
  212. package/templates/player-skin/ts/src/BuiltinLyrics.vue +15 -0
  213. package/templates/player-skin/ts/src/Lyrics.vue +28 -0
  214. package/templates/player-skin/ts/tsconfig.json +17 -0
  215. package/templates/react/js/.vscode/launch.json +12 -29
  216. package/templates/react/js/.vscode/tasks.json +2 -3
  217. package/templates/react/js/README.md +10 -10
  218. package/templates/react/js/ceru.plugin.json +27 -22
  219. package/templates/react/js/package.json +5 -5
  220. package/templates/react/js/src/index.js +1 -1
  221. package/templates/react/ts/.vscode/launch.json +12 -29
  222. package/templates/react/ts/.vscode/tasks.json +2 -3
  223. package/templates/react/ts/README.md +10 -10
  224. package/templates/react/ts/ceru.plugin.json +27 -22
  225. package/templates/react/ts/package.json +5 -5
  226. package/templates/react/ts/src/index.ts +1 -1
  227. package/templates/snapshot.json +152 -6
  228. package/templates/source/js/.vscode/launch.json +12 -29
  229. package/templates/source/js/.vscode/tasks.json +2 -3
  230. package/templates/source/js/README.md +12 -10
  231. package/templates/source/js/ceru.plugin.json +44 -26
  232. package/templates/source/js/package.json +5 -5
  233. package/templates/source/js/src/index.js +10 -8
  234. package/templates/source/ts/.vscode/launch.json +12 -29
  235. package/templates/source/ts/.vscode/tasks.json +2 -3
  236. package/templates/source/ts/README.md +12 -10
  237. package/templates/source/ts/ceru.plugin.json +44 -26
  238. package/templates/source/ts/package.json +5 -5
  239. package/templates/source/ts/src/index.ts +10 -8
  240. package/templates/vue/js/.vscode/launch.json +12 -29
  241. package/templates/vue/js/.vscode/tasks.json +2 -3
  242. package/templates/vue/js/README.md +10 -10
  243. package/templates/vue/js/ceru.plugin.json +27 -22
  244. package/templates/vue/js/package.json +5 -5
  245. package/templates/vue/js/src/index.js +1 -1
  246. package/templates/vue/ts/.vscode/launch.json +12 -29
  247. package/templates/vue/ts/.vscode/tasks.json +2 -3
  248. package/templates/vue/ts/README.md +10 -10
  249. package/templates/vue/ts/ceru.plugin.json +27 -22
  250. package/templates/vue/ts/package.json +5 -5
  251. package/templates/vue/ts/src/index.ts +1 -1
  252. package/templates/vue-tsx/js/.vscode/launch.json +12 -29
  253. package/templates/vue-tsx/js/.vscode/tasks.json +2 -3
  254. package/templates/vue-tsx/js/README.md +10 -10
  255. package/templates/vue-tsx/js/ceru.plugin.json +27 -22
  256. package/templates/vue-tsx/js/package.json +5 -5
  257. package/templates/vue-tsx/js/src/index.js +1 -1
  258. package/templates/vue-tsx/ts/.vscode/launch.json +12 -29
  259. package/templates/vue-tsx/ts/.vscode/tasks.json +2 -3
  260. package/templates/vue-tsx/ts/README.md +10 -10
  261. package/templates/vue-tsx/ts/ceru.plugin.json +27 -22
  262. package/templates/vue-tsx/ts/package.json +5 -5
  263. package/templates/vue-tsx/ts/src/index.ts +1 -1
  264. package/templates/web-dist/js/.vscode/launch.json +12 -29
  265. package/templates/web-dist/js/.vscode/tasks.json +2 -3
  266. package/templates/web-dist/js/README.md +10 -10
  267. package/templates/web-dist/js/ceru.plugin.json +27 -22
  268. package/templates/web-dist/js/package.json +5 -5
  269. package/templates/web-dist/js/src/index.js +1 -1
  270. package/templates/web-dist/ts/.vscode/launch.json +12 -29
  271. package/templates/web-dist/ts/.vscode/tasks.json +2 -3
  272. package/templates/web-dist/ts/README.md +10 -10
  273. package/templates/web-dist/ts/ceru.plugin.json +27 -22
  274. package/templates/web-dist/ts/package.json +5 -5
  275. package/templates/web-dist/ts/src/index.ts +1 -1
  276. package/templates/web-surface/js/.vscode/launch.json +12 -29
  277. package/templates/web-surface/js/.vscode/tasks.json +2 -3
  278. package/templates/web-surface/js/README.md +10 -10
  279. package/templates/web-surface/js/ceru.plugin.json +35 -35
  280. package/templates/web-surface/js/package.json +5 -5
  281. package/templates/web-surface/js/src/index.js +1 -1
  282. package/templates/web-surface/ts/.vscode/launch.json +12 -29
  283. package/templates/web-surface/ts/.vscode/tasks.json +2 -3
  284. package/templates/web-surface/ts/README.md +10 -10
  285. package/templates/web-surface/ts/ceru.plugin.json +35 -35
  286. package/templates/web-surface/ts/package.json +5 -5
  287. package/templates/web-surface/ts/src/index.ts +1 -1
  288. package/assets/core-contracts.js +0 -1
  289. package/assets/electron-app/main.cjs +0 -1
  290. package/assets/electron-app/package.json +0 -8
  291. package/assets/electron.cjs +0 -42
  292. package/assets/index.html +0 -94
  293. package/assets/native-view.js +0 -197
  294. package/assets/playground.js +0 -883
  295. package/assets/sandbox.js +0 -67
  296. package/assets/style.css +0 -337
  297. package/dist/socket-broker.d.ts +0 -23
  298. package/dist/socket-broker.js +0 -229
  299. package/templates/connected-library/js/ui/settings.json +0 -24
  300. package/templates/connected-library/ts/ui/settings.json +0 -24
  301. package/templates/guest-adapter/js/ui/settings.json +0 -14
  302. package/templates/guest-adapter/ts/ui/settings.json +0 -14
@@ -0,0 +1,94 @@
1
+ {
2
+ "manifest": {
3
+ "manifestVersion": 3,
4
+ "id": "local.page-extension",
5
+ "name": "页面扩展",
6
+ "version": "0.1.0",
7
+ "engines": {
8
+ "hostApi": "^3.0.0",
9
+ "logicRuntime": "ceru-js@1"
10
+ },
11
+ "entry": {
12
+ "logic": {
13
+ "module": "logic.main"
14
+ },
15
+ "views": [
16
+ {
17
+ "id": "search",
18
+ "kind": "component",
19
+ "module": "view.search",
20
+ "presentation": { "kind": "drawer", "size": 680 }
21
+ },
22
+ {
23
+ "id": "button",
24
+ "kind": "component",
25
+ "module": "view.button"
26
+ }
27
+ ]
28
+ },
29
+ "provides": {
30
+ "actions": [
31
+ {
32
+ "id": "search",
33
+ "title": "搜索音源"
34
+ },
35
+ {
36
+ "id": "play",
37
+ "title": "播放"
38
+ },
39
+ { "id": "enqueue", "title": "加入队列" },
40
+ {
41
+ "id": "open",
42
+ "title": "打开搜索页面"
43
+ }
44
+ ]
45
+ },
46
+ "uses": {
47
+ "permissions": [
48
+ {
49
+ "key": "catalog",
50
+ "name": "music.read",
51
+ "reason": "搜索用户选择的音源"
52
+ },
53
+ {
54
+ "key": "listen",
55
+ "name": "music.control",
56
+ "reason": "播放用户选择的歌曲或加入播放队列"
57
+ }
58
+ ]
59
+ },
60
+ "ui": {
61
+ "pages": [
62
+ {
63
+ "id": "search",
64
+ "title": "音源搜索",
65
+ "mount": "sidebar",
66
+ "icon": { "kind": "host", "name": "search" },
67
+ "group": "library",
68
+ "view": "search"
69
+ },
70
+ {
71
+ "id": "settings",
72
+ "title": "音源搜索",
73
+ "mount": "settings",
74
+ "view": "search"
75
+ }
76
+ ],
77
+ "slots": [
78
+ {
79
+ "id": "search-button",
80
+ "slot": "playlist.header.actions",
81
+ "mode": "append",
82
+ "view": "button"
83
+ }
84
+ ]
85
+ }
86
+ },
87
+ "framework": "vue",
88
+ "entries": {
89
+ "logic.main": "src/index.ts",
90
+ "view.search": "src/Search.vue",
91
+ "view.button": "src/Open.vue"
92
+ },
93
+ "output": "dist/plugin.js"
94
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "ceru-page-extension",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "ceru-plugin dev",
8
+ "build": "ceru-plugin build",
9
+ "typecheck": "ceru-plugin typecheck",
10
+ "validate": "ceru-plugin validate dist/plugin.js",
11
+ "preview": "ceru-plugin preview dist/plugin.js",
12
+ "check:compat": "ceru-plugin check-compat"
13
+ },
14
+ "dependencies": {
15
+ "@shiqianjiang/ceru-plugin-sdk": "^3.0.0"
16
+ },
17
+ "devDependencies": {
18
+ "@shiqianjiang/ceru-plugin-cli": "^3.0.0",
19
+ "typescript": "~5.9.3",
20
+ "prettier": "^3.6.2",
21
+ "vue": "^3.5.21",
22
+ "tdesign-vue-next": "1.15.4"
23
+ }
24
+ }
@@ -0,0 +1,6 @@
1
+ <script setup lang="ts">
2
+ import {Button} from 'tdesign-vue-next'
3
+ import {useAction} from '@shiqianjiang/ceru-plugin-sdk/vue'
4
+ const open=useAction('open')
5
+ </script>
6
+ <template><Button @click="open()">音源搜索</Button></template>
@@ -0,0 +1,62 @@
1
+ <script setup lang="ts">
2
+ import { ref } from 'vue'
3
+ import { Button, Input } from 'tdesign-vue-next'
4
+ import { useAction, useHostComponents, useViewState } from '@shiqianjiang/ceru-plugin-sdk/vue'
5
+ const query = ref(''),
6
+ pending = ref(false),
7
+ error = ref('')
8
+ const search = useAction('search')
9
+ const state = useViewState<{ items: { key: string; title: string }[]; searched: boolean }>()
10
+ const { SongList, PageHeader, EmptyState, LoadingState } = useHostComponents()
11
+ const actions = { play: 'play', enqueue: 'enqueue' }
12
+ async function submit() {
13
+ if (pending.value) return
14
+ pending.value = true
15
+ error.value = ''
16
+ try {
17
+ await search(query.value)
18
+ } catch (reason) {
19
+ error.value = String(reason)
20
+ } finally {
21
+ pending.value = false
22
+ }
23
+ }
24
+ </script>
25
+ <template>
26
+ <section>
27
+ <PageHeader title="音源搜索" description="搜索歌曲,或把结果加入播放队列。" />
28
+ <div class="search-bar" role="search">
29
+ <Input v-model="query" aria-label="歌曲名称" placeholder="输入歌曲名称" @enter="submit" />
30
+ <Button type="button" :disabled="pending" @click="submit">搜索</Button>
31
+ </div>
32
+ <p v-if="error" role="alert">{{ error }}</p>
33
+ <LoadingState v-if="pending" title="正在搜索…" />
34
+ <SongList v-else-if="state.items?.length" :items="state.items" :actions="actions" />
35
+ <EmptyState
36
+ v-else
37
+ :title="state.searched ? '没有找到歌曲' : '搜索你的第一首歌'"
38
+ :description="
39
+ state.searched ? '换个关键词,或检查音源是否已启用。' : '启用的音源和本地曲库均可用于搜索。'
40
+ "
41
+ />
42
+ </section>
43
+ </template>
44
+ <style scoped>
45
+ section {
46
+ padding: 16px;
47
+ display: grid;
48
+ gap: 12px;
49
+ }
50
+ .search-bar {
51
+ display: flex;
52
+ align-items: center;
53
+ gap: 8px;
54
+ }
55
+ .search-bar > :first-child {
56
+ flex: 1;
57
+ min-width: 0;
58
+ }
59
+ [role='alert'] {
60
+ color: var(--td-error-color);
61
+ }
62
+ </style>
@@ -0,0 +1,54 @@
1
+ import { definePlugin, type ResourceRef } from '@shiqianjiang/ceru-plugin-sdk'
2
+ export default definePlugin((ctx) => {
3
+ const refs = new Map<string, ResourceRef>()
4
+ let generation = 0
5
+ ctx.actions.register('search', async (input, operation) => {
6
+ const request = ++generation
7
+ const sources = await ctx.music.sources()
8
+ const source = sources.find((item) => item.available)
9
+ const result = source
10
+ ? await ctx.music.search(
11
+ source.id,
12
+ {
13
+ query: typeof input === 'string' ? input : '',
14
+ kinds: ['track'],
15
+ limit: 30,
16
+ filters: {},
17
+ },
18
+ { permissionKey: 'catalog', operation },
19
+ )
20
+ : { items: [] }
21
+ if (request !== generation) return { count: 0 }
22
+ refs.clear()
23
+ const items = result.items.map((item, index) => {
24
+ const key = request + ':' + index
25
+ const durationMs = item.durationMs ?? item.metadata?.durationMs
26
+ refs.set(key, item.ref)
27
+ return {
28
+ key,
29
+ title: item.title,
30
+ source: item.ref.providerId,
31
+ playable: item.playable !== false,
32
+ metadata: {
33
+ artists: item.metadata?.artists ?? [],
34
+ qualities: item.metadata?.qualities ?? [],
35
+ },
36
+ ...(durationMs !== undefined ? { durationMs } : {}),
37
+ }
38
+ })
39
+ await ctx.ui.views.setState('search', { items, searched: true })
40
+ return { count: items.length }
41
+ })
42
+ function resolveKey(key: unknown) {
43
+ const ref = typeof key === 'string' && refs.get(key)
44
+ if (!ref) throw Error('搜索结果已更新,请重新选择歌曲')
45
+ return ref
46
+ }
47
+ ctx.actions.register('play', async (key, operation) => {
48
+ await ctx.music.play(resolveKey(key), { permissionKey: 'listen', operation })
49
+ })
50
+ ctx.actions.register('enqueue', async (key, operation) => {
51
+ await ctx.music.enqueue([resolveKey(key)], 'end', { permissionKey: 'listen', operation })
52
+ })
53
+ ctx.actions.register('open', () => ctx.ui.pages.open('search'))
54
+ })
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "strict": true,
7
+ "noEmit": true,
8
+ "skipLibCheck": true,
9
+ "allowJs": true,
10
+ "checkJs": false,
11
+ "lib": ["ES2022", "DOM"],
12
+ "types": [],
13
+ "jsx": "preserve",
14
+ "jsxImportSource": "vue"
15
+ },
16
+ "include": ["src", ".ceru-dev/types/**/*.d.ts"]
17
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "singleQuote": true,
3
+ "semi": false,
4
+ "printWidth": 100
5
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "recommendations": ["esbenp.prettier-vscode"]
3
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "name": "Watch Ceru plugin",
6
+ "type": "node",
7
+ "request": "launch",
8
+ "program": "${workspaceFolder}/node_modules/@shiqianjiang/ceru-plugin-cli/dist/bin.js",
9
+ "args": [
10
+ "dev"
11
+ ],
12
+ "cwd": "${workspaceFolder}",
13
+ "console": "integratedTerminal",
14
+ "skipFiles": [
15
+ "<node_internals>/**"
16
+ ]
17
+ }
18
+ ]
19
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "typescript.tsdk": "node_modules/typescript/lib",
3
+ "typescript.enablePromptUseWorkspaceTsdk": true,
4
+ "editor.formatOnSave": true,
5
+ "[typescript]": {
6
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
7
+ },
8
+ "[javascript]": {
9
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
10
+ },
11
+ "json.schemas": [
12
+ {
13
+ "fileMatch": ["/ceru.plugin.json"],
14
+ "url": "./node_modules/@shiqianjiang/ceru-plugin-cli/schemas/config.schema.json"
15
+ }
16
+ ],
17
+ "files.exclude": {
18
+ "**/*.tsbuildinfo": true
19
+ }
20
+ }
@@ -0,0 +1,50 @@
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "label": "Ceru: dev",
6
+ "type": "process",
7
+ "isBackground": true,
8
+ "problemMatcher": {
9
+ "owner": "ceru",
10
+ "pattern": {
11
+ "regexp": "^CERU_ERROR (.*)$",
12
+ "message": 1
13
+ },
14
+ "background": {
15
+ "activeOnStart": true,
16
+ "beginsPattern": "^.*$",
17
+ "endsPattern": "^CERU_BUILD_READY "
18
+ }
19
+ },
20
+ "command": "node",
21
+ "args": [
22
+ "${workspaceFolder}/node_modules/@shiqianjiang/ceru-plugin-cli/dist/bin.js",
23
+ "dev"
24
+ ],
25
+ "options": {
26
+ "cwd": "${workspaceFolder}"
27
+ }
28
+ },
29
+ {
30
+ "label": "Ceru: typecheck",
31
+ "type": "npm",
32
+ "script": "typecheck",
33
+ "problemMatcher": "$tsc",
34
+ "group": "build"
35
+ },
36
+ {
37
+ "label": "Ceru: build",
38
+ "type": "npm",
39
+ "script": "build",
40
+ "problemMatcher": []
41
+ },
42
+ {
43
+ "label": "Ceru: test playback hooks",
44
+ "type": "npm",
45
+ "script": "test",
46
+ "group": "test",
47
+ "problemMatcher": []
48
+ }
49
+ ]
50
+ }
@@ -0,0 +1,24 @@
1
+ # 播放拦截示例
2
+
3
+ 这是一个纯逻辑插件,不需要账号、网络、音源或 Electron 即可测试。编辑 src/index,把规则换成自己的。默认只处理演示前缀:点播以「[拦截示例]」开头的歌曲时取消操作;加入以「[优先示例]」开头的歌曲时改为下一首,其他歌曲不变。 定向移除带「[保护示例]」前缀的歌曲时取消该请求;这条规则不拦截清空整个队列。
4
+
5
+ 1. 安装项目依赖:`npm install`。
6
+ 2. 执行 `npm test`。命令先构建,再在独立 worker 中对 `tests/hooks.json` 的每个场景启动新插件,检查取消、未授权直通、一次性默认执行和队列位置。断言失败会给出场景名称并以非零状态退出。场景文件不会打入分发产物。
7
+ 3. 启动 `npm run dev`,复制它打印的产物路径。在兼容 v3 的澜音中打开「设置 → 插件管理 → 管理设置 → 插件开发者模式」,添加该文件,启用插件,并在其权限设置中允许播放拦截。修改源码后自动重建;关闭权限可验证原有行为。此步骤才会接入真实播放器。
8
+ 4. 发给别人前运行 `npm run build` 和 `npm run validate`。只分发 `dist/plugin.js`。
9
+
10
+ 点播和入队输入只含公开歌曲摘要,暂停和继续的输入为 `{}`。场景可用 `source.kind` 区分 `ui`、`system` 和 `plugin`;插件来源还须填写 `pluginId` 与 `runtime`(2 或 3)。省略来源时按界面点击测试。普通播放钩子最多调用一次 `next`。每个处理器有 800 ms 执行预算,等待下游解析不计入预算。
11
+
12
+ ### 测试失败换源
13
+
14
+ `player.resolve` 示例仅处理 `demo-primary` 的 `morning`:首次 `await next()` 成功就结束;失败时,改用 `demo-backup` 的 `morning-alt`,保留原音质。两个 ID 是测试数据,不假设不同平台共用歌曲 ID,也不会改写其他歌曲。真实插件应提供自己的公开歌曲映射,或在获得 `music.read` 授权后查询备用音源。
15
+
16
+ `tests/hooks.json` 中的 `resolveResults` 按顺序指定每次宿主解析是否成功。如 `[false, true]` 表示主源失败、备用源成功。`expect.input` 是最后一次解析的输入。钩子只能看到 `{ ok }`,不能读取播放地址;只有失败后才能用不同输入再试一次。`npm test` 不连接真实音源或音频设备。
17
+
18
+ ### 观察操作与读取现场
19
+
20
+ `op.state` 提供冻结的 `player`、`route`、`account` 快照,分别需要声明和授予 `player.read`、`route.read`、`account.profile`。未授权时对应字段为 `null`;离线测试默认三项为空。
21
+
22
+ 只想取消操作时,可以使用现有 `player.intercept` 权限注册 `ctx.events.on('player.pause', event => event.preventDefault())`,输入与来源只读。希望观察最终结果时,在清单 `manifest.uses.permissions` 添加 `player.read`,再注册 `ctx.events.on('player.pause:done', event => console.log(event.prevented, event.handledBy))`。完成事件不改变操作,在暂停全部拦截时仍然投递。`events.on` 返回的函数用于注销。
23
+
24
+ `ctx.app.operations.list()` 返回当前可主动调用的工具及输入/输出 Schema、执行权限。调用时使用 `ctx.app.call(name, input, {operation, permissionKey})`;例如清空队列为 `queue.clear`,需要 `player.control`。不要把拦截权限用于执行权限,也不要把钩子的临时私有歌曲句柄传给工具。
@@ -0,0 +1,6 @@
1
+ node_modules/
2
+ dist/
3
+ .keys/
4
+ .ceru-dev/
5
+ *.private.pem
6
+ *.tsbuildinfo
@@ -0,0 +1,8 @@
1
+ {
2
+ "folders": [
3
+ {
4
+ "path": ".",
5
+ },
6
+ ],
7
+ "settings": {},
8
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "manifest": {
3
+ "manifestVersion": 3,
4
+ "id": "local.js",
5
+ "name": "js",
6
+ "version": "0.1.0",
7
+ "description": "本地播放拦截与队列改写示例",
8
+ "dataSchemas": {
9
+ "config": 1,
10
+ "state": 1
11
+ },
12
+ "engines": {
13
+ "hostApi": "^3.0.0",
14
+ "logicRuntime": "ceru-js@1"
15
+ },
16
+ "entry": {
17
+ "logic": {
18
+ "module": "logic.main"
19
+ }
20
+ },
21
+ "uses": {
22
+ "permissions": [
23
+ {
24
+ "key": "intercept",
25
+ "name": "player.intercept",
26
+ "reason": "处理带演示前缀的点播和队列操作,并在指定演示歌曲解析失败时尝试备用音源"
27
+ }
28
+ ]
29
+ }
30
+ },
31
+ "entries": {
32
+ "logic.main": "src/index.js"
33
+ },
34
+ "resources": {},
35
+ "output": "dist/plugin.js"
36
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "js",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "ceru-plugin dev",
8
+ "build": "ceru-plugin build",
9
+ "typecheck": "ceru-plugin typecheck",
10
+ "validate": "ceru-plugin validate dist/plugin.js",
11
+ "preview": "ceru-plugin preview dist/plugin.js",
12
+ "test": "ceru-plugin test-hooks",
13
+ "check:compat": "ceru-plugin check-compat"
14
+ },
15
+ "dependencies": {
16
+ "@shiqianjiang/ceru-plugin-sdk": "^3.0.0"
17
+ },
18
+ "devDependencies": {
19
+ "@shiqianjiang/ceru-plugin-cli": "^3.0.0",
20
+ "typescript": "~5.9.3",
21
+ "prettier": "^3.6.2"
22
+ }
23
+ }
@@ -0,0 +1,25 @@
1
+ import { definePlugin } from '@shiqianjiang/ceru-plugin-sdk'
2
+
3
+ export default definePlugin(async (ctx) => {
4
+ ctx.hooks.on('player.resolve', async (op, next) => {
5
+ const { ref } = op.input.track
6
+ if (ref.providerId !== 'demo-primary' || ref.id !== 'morning') return
7
+ const result = await next()
8
+ if (result.ok) return result
9
+ return next({
10
+ ...op.input,
11
+ track: { ...op.input.track, ref: { kind: 'track', providerId: 'demo-backup', id: 'morning-alt' } },
12
+ })
13
+ })
14
+ ctx.hooks.on('player.play', (op) => {
15
+ if (op.input.track.title.startsWith('[拦截示例]')) op.preventDefault()
16
+ })
17
+ ctx.hooks.on('queue.remove', op => {
18
+ if (op.input.tracks.some(track => track.title.startsWith('[保护示例]'))) op.preventDefault()
19
+ })
20
+ ctx.hooks.on('queue.add', async (op, next) => {
21
+ if (op.input.tracks.some((track) => track.title.startsWith('[优先示例]'))) {
22
+ await next({ ...op.input, position: 'next' })
23
+ }
24
+ })
25
+ })