hostlet 0.0.0-stage → 0.1.0-alpha.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 (512) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +233 -2
  3. package/bin/hostlet.js +61 -0
  4. package/console/app/api.js +1223 -0
  5. package/console/app/boot.js +165 -0
  6. package/console/app/cards.js +222 -0
  7. package/console/app/compose-quote.js +127 -0
  8. package/console/app/config-form.js +727 -0
  9. package/console/app/document-drafts.js +62 -0
  10. package/console/app/document-tools.mjs +67 -0
  11. package/console/app/documents.js +106 -0
  12. package/console/app/pages.js +6483 -0
  13. package/console/app/plugins.js +509 -0
  14. package/console/app/preview-tools.js +172 -0
  15. package/console/app/reference-labels.js +118 -0
  16. package/console/app/selection.js +372 -0
  17. package/console/app/store.js +57 -0
  18. package/console/app/text-anchor.js +26 -0
  19. package/console/app/topic-local.js +322 -0
  20. package/console/app/topic-nav.js +414 -0
  21. package/console/app/topic-status.js +109 -0
  22. package/console/app/views.js +43 -0
  23. package/console/apple-touch-icon.png +0 -0
  24. package/console/avatars/agy.svg +34 -0
  25. package/console/avatars/alhena.svg +36 -0
  26. package/console/avatars/castor.svg +38 -0
  27. package/console/avatars/claude.svg +34 -0
  28. package/console/avatars/codex.svg +34 -0
  29. package/console/avatars/devin.svg +34 -0
  30. package/console/avatars/echo.svg +34 -0
  31. package/console/avatars/kimi.svg +33 -0
  32. package/console/avatars/opencode.svg +33 -0
  33. package/console/avatars/pinion.svg +34 -0
  34. package/console/avatars/sprocket.svg +34 -0
  35. package/console/avatars/vela.svg +44 -0
  36. package/console/avatars/wasat.svg +38 -0
  37. package/console/clients/agy.svg +1 -0
  38. package/console/clients/claude.svg +1 -0
  39. package/console/clients/codex.svg +1 -0
  40. package/console/clients/devin.svg +1 -0
  41. package/console/clients/kimi.svg +1 -0
  42. package/console/clients/opencode.svg +1 -0
  43. package/console/favicon.ico +0 -0
  44. package/console/favicon.svg +16 -0
  45. package/console/index.html +99 -0
  46. package/console/pdl/engine/README.md +13 -0
  47. package/console/pdl/engine/anchor.js +195 -0
  48. package/console/pdl/engine/core.js +1340 -0
  49. package/console/pdl/engine/frame.js +1252 -0
  50. package/console/pdl/engine/i18n.js +67 -0
  51. package/console/pdl/engine/pdl-check.js +102 -0
  52. package/console/pdl/engine/pdl-doc.js +353 -0
  53. package/console/pdl/engine/pdl-view.js +280 -0
  54. package/console/pdl/engine/pdl.js +1064 -0
  55. package/console/pdl/engine/platform.js +18 -0
  56. package/console/pdl/engine/proj.js +279 -0
  57. package/console/pdl/engine/theme.js +176 -0
  58. package/console/pdl/engine/tree.js +171 -0
  59. package/console/pdl/engine/units.js +546 -0
  60. package/console/pdl/library/README.md +28 -0
  61. package/console/pdl/library/blocks.js +1512 -0
  62. package/console/pdl/library/buttons.js +86 -0
  63. package/console/pdl/library/capsules.js +130 -0
  64. package/console/pdl/library/charts.js +287 -0
  65. package/console/pdl/library/code.js +98 -0
  66. package/console/pdl/library/css/base.css +12 -0
  67. package/console/pdl/library/css/blocks.css +98 -0
  68. package/console/pdl/library/css/capsules.css +42 -0
  69. package/console/pdl/library/css/catalog-page.css +24 -0
  70. package/console/pdl/library/css/chat.css +100 -0
  71. package/console/pdl/library/css/composer-top.css +145 -0
  72. package/console/pdl/library/css/controls.css +195 -0
  73. package/console/pdl/library/css/drag.css +29 -0
  74. package/console/pdl/library/css/edit-layout.css +93 -0
  75. package/console/pdl/library/css/floating-window.css +30 -0
  76. package/console/pdl/library/css/hover.css +50 -0
  77. package/console/pdl/library/css/label-search.css +37 -0
  78. package/console/pdl/library/css/layers.css +43 -0
  79. package/console/pdl/library/css/library-parts.css +33 -0
  80. package/console/pdl/library/css/library.css +117 -0
  81. package/console/pdl/library/css/member-select.css +34 -0
  82. package/console/pdl/library/css/message.css +72 -0
  83. package/console/pdl/library/css/page.css +104 -0
  84. package/console/pdl/library/css/parts.css +338 -0
  85. package/console/pdl/library/css/responsive.css +40 -0
  86. package/console/pdl/library/css/roles.css +28 -0
  87. package/console/pdl/library/css/rows.css +231 -0
  88. package/console/pdl/library/css/settings-rows.css +37 -0
  89. package/console/pdl/library/css/shell.css +59 -0
  90. package/console/pdl/library/css/stream.css +296 -0
  91. package/console/pdl/library/css/theme-calculator.css +18 -0
  92. package/console/pdl/library/css/thumb-choice.css +69 -0
  93. package/console/pdl/library/css/tweaks.css +16 -0
  94. package/console/pdl/library/css/widgets.css +211 -0
  95. package/console/pdl/library/css/workbench.css +59 -0
  96. package/console/pdl/library/feedback.js +83 -0
  97. package/console/pdl/library/floating-window.mjs +100 -0
  98. package/console/pdl/library/fold.js +238 -0
  99. package/console/pdl/library/format.js +53 -0
  100. package/console/pdl/library/frames.js +123 -0
  101. package/console/pdl/library/icons.js +165 -0
  102. package/console/pdl/library/identity.js +149 -0
  103. package/console/pdl/library/inputs.js +801 -0
  104. package/console/pdl/library/label-search.js +214 -0
  105. package/console/pdl/library/markdown-text.js +115 -0
  106. package/console/pdl/library/markdown.js +150 -0
  107. package/console/pdl/library/media-viewer.js +293 -0
  108. package/console/pdl/library/member-select.mjs +32 -0
  109. package/console/pdl/library/message.js +105 -0
  110. package/console/pdl/library/motion.js +56 -0
  111. package/console/pdl/library/overlays.js +165 -0
  112. package/console/pdl/library/page.js +142 -0
  113. package/console/pdl/library/plugin-form.js +154 -0
  114. package/console/pdl/library/registry.js +198 -0
  115. package/console/pdl/library/rows.js +523 -0
  116. package/console/pdl/library/shell.js +151 -0
  117. package/console/pdl/library/stream.js +58 -0
  118. package/console/pdl/library/tabs.js +259 -0
  119. package/console/pdl/library/theme-calculator.js +300 -0
  120. package/console/pdl/library/widgets.js +114 -0
  121. package/console/pdl/load-order.json +74 -0
  122. package/console/pdl/platform/README.md +3 -0
  123. package/console/pdl/platform/rich-markdown.mjs +17 -0
  124. package/console/pdl/platform/web-links.js +26 -0
  125. package/console/pdl/platform/web.js +80 -0
  126. package/console/sdk-browser/mentions.d.mts +16 -0
  127. package/console/sdk-browser/mentions.mjs +84 -0
  128. package/console/theme/assets.js +21 -0
  129. package/console/theme/theme.json +9417 -0
  130. package/console/theme/tokens.json +444 -0
  131. package/dist/core/a2a.d.ts +288 -0
  132. package/dist/core/a2a.js +2197 -0
  133. package/dist/core/address.d.ts +34 -0
  134. package/dist/core/address.js +33 -0
  135. package/dist/core/approval-inputs.d.ts +17 -0
  136. package/dist/core/approval-inputs.js +70 -0
  137. package/dist/core/archive.d.ts +19 -0
  138. package/dist/core/archive.js +135 -0
  139. package/dist/core/attachments.d.ts +17 -0
  140. package/dist/core/attachments.js +143 -0
  141. package/dist/core/blocked-handoffs.d.ts +132 -0
  142. package/dist/core/blocked-handoffs.js +349 -0
  143. package/dist/core/config-schema.d.ts +124 -0
  144. package/dist/core/config-schema.js +192 -0
  145. package/dist/core/config.d.ts +117 -0
  146. package/dist/core/config.js +638 -0
  147. package/dist/core/disk-usage.d.ts +26 -0
  148. package/dist/core/disk-usage.js +83 -0
  149. package/dist/core/documents.d.ts +9 -0
  150. package/dist/core/documents.js +48 -0
  151. package/dist/core/entry.d.ts +316 -0
  152. package/dist/core/entry.js +711 -0
  153. package/dist/core/home.d.ts +76 -0
  154. package/dist/core/home.js +449 -0
  155. package/dist/core/i18n.d.ts +36 -0
  156. package/dist/core/i18n.js +458 -0
  157. package/dist/core/instances.d.ts +224 -0
  158. package/dist/core/instances.js +1272 -0
  159. package/dist/core/members.d.ts +190 -0
  160. package/dist/core/members.js +358 -0
  161. package/dist/core/mentions.d.ts +12 -0
  162. package/dist/core/mentions.js +49 -0
  163. package/dist/core/messages.d.ts +876 -0
  164. package/dist/core/messages.js +916 -0
  165. package/dist/core/notices.d.ts +88 -0
  166. package/dist/core/notices.js +54 -0
  167. package/dist/core/ops.d.ts +117 -0
  168. package/dist/core/ops.js +146 -0
  169. package/dist/core/package.d.ts +2 -0
  170. package/dist/core/package.js +14 -0
  171. package/dist/core/parts.d.ts +25 -0
  172. package/dist/core/parts.js +119 -0
  173. package/dist/core/plugins/catalog.d.ts +14 -0
  174. package/dist/core/plugins/catalog.js +54 -0
  175. package/dist/core/plugins/external.d.ts +7 -0
  176. package/dist/core/plugins/external.js +921 -0
  177. package/dist/core/plugins/index.d.ts +5 -0
  178. package/dist/core/plugins/index.js +51 -0
  179. package/dist/core/plugins/npm.d.ts +12 -0
  180. package/dist/core/plugins/npm.js +99 -0
  181. package/dist/core/plugins/plugin-manifest.d.ts +12 -0
  182. package/dist/core/plugins/plugin-manifest.js +231 -0
  183. package/dist/core/push.d.ts +22 -0
  184. package/dist/core/push.js +63 -0
  185. package/dist/core/resource.d.ts +77 -0
  186. package/dist/core/resource.js +48 -0
  187. package/dist/core/spawn.d.ts +12 -0
  188. package/dist/core/spawn.js +30 -0
  189. package/dist/core/storage-inventory.d.ts +118 -0
  190. package/dist/core/storage-inventory.js +279 -0
  191. package/dist/core/storage.d.ts +45 -0
  192. package/dist/core/storage.js +602 -0
  193. package/dist/core/store.d.ts +15 -0
  194. package/dist/core/store.js +33 -0
  195. package/dist/core/topic-index.d.ts +19 -0
  196. package/dist/core/topic-index.js +70 -0
  197. package/dist/core/topic-ops.d.ts +139 -0
  198. package/dist/core/topic-ops.js +507 -0
  199. package/dist/core/topic-status.d.ts +32 -0
  200. package/dist/core/topic-status.js +105 -0
  201. package/dist/core/topics.d.ts +327 -0
  202. package/dist/core/topics.js +786 -0
  203. package/dist/core/turn-clients.d.ts +1 -0
  204. package/dist/core/turn-clients.js +5 -0
  205. package/dist/core/types.d.ts +2866 -0
  206. package/dist/core/types.js +166 -0
  207. package/dist/core/util.d.ts +10 -0
  208. package/dist/core/util.js +47 -0
  209. package/dist/main.d.ts +12 -0
  210. package/dist/main.js +82 -0
  211. package/dist/plugins/adapter-acp/index.d.ts +3 -0
  212. package/dist/plugins/adapter-acp/index.js +57 -0
  213. package/dist/plugins/adapter-acp/plugin.yaml +100 -0
  214. package/dist/plugins/adapter-agy/command.d.ts +9 -0
  215. package/dist/plugins/adapter-agy/command.js +34 -0
  216. package/dist/plugins/adapter-agy/index.d.ts +5 -0
  217. package/dist/plugins/adapter-agy/index.js +65 -0
  218. package/dist/plugins/adapter-agy/quota.d.ts +2 -0
  219. package/dist/plugins/adapter-agy/quota.js +155 -0
  220. package/dist/plugins/adapter-agy/terminal.d.ts +6 -0
  221. package/dist/plugins/adapter-agy/terminal.js +132 -0
  222. package/dist/plugins/adapter-agy/version.d.ts +9 -0
  223. package/dist/plugins/adapter-agy/version.js +17 -0
  224. package/dist/plugins/adapter-claude/index.d.ts +43 -0
  225. package/dist/plugins/adapter-claude/index.js +412 -0
  226. package/dist/plugins/adapter-claude/quota.d.ts +14 -0
  227. package/dist/plugins/adapter-claude/quota.js +103 -0
  228. package/dist/plugins/adapter-codex/index.d.ts +4 -0
  229. package/dist/plugins/adapter-codex/index.js +688 -0
  230. package/dist/plugins/adapter-codex/responses-model.d.ts +9 -0
  231. package/dist/plugins/adapter-codex/responses-model.js +82 -0
  232. package/dist/plugins/adapter-kimi/index.d.ts +4 -0
  233. package/dist/plugins/adapter-kimi/index.js +51 -0
  234. package/dist/plugins/adapter-kimi/quota.d.ts +3 -0
  235. package/dist/plugins/adapter-kimi/quota.js +171 -0
  236. package/dist/plugins/adapter-opencode/index.d.ts +12 -0
  237. package/dist/plugins/adapter-opencode/index.js +64 -0
  238. package/dist/plugins/annotations/console/cards.css +189 -0
  239. package/dist/plugins/annotations/console/cards.mjs +439 -0
  240. package/dist/plugins/annotations/console/pdl.json +52 -0
  241. package/dist/plugins/annotations/console/view.mjs +241 -0
  242. package/dist/plugins/annotations/console/window.mjs +219 -0
  243. package/dist/plugins/annotations/followups.d.ts +51 -0
  244. package/dist/plugins/annotations/followups.js +112 -0
  245. package/dist/plugins/annotations/index.d.ts +3 -0
  246. package/dist/plugins/annotations/index.js +298 -0
  247. package/dist/plugins/annotations/plugin.yaml +3 -0
  248. package/dist/plugins/ask-choice/index.d.ts +9 -0
  249. package/dist/plugins/ask-choice/index.js +24 -0
  250. package/dist/plugins/ask-choice/plugin.yaml +2 -0
  251. package/dist/plugins/background/index.d.ts +2 -0
  252. package/dist/plugins/background/index.js +398 -0
  253. package/dist/plugins/background/plugin.yaml +7 -0
  254. package/dist/plugins/builtin.json +37 -0
  255. package/dist/plugins/cards/console/pdl.json +516 -0
  256. package/dist/plugins/cards/console/view.mjs +67 -0
  257. package/dist/plugins/cards/index.d.ts +8 -0
  258. package/dist/plugins/cards/index.js +627 -0
  259. package/dist/plugins/cards/plugin.yaml +3 -0
  260. package/dist/plugins/console/browser.d.ts +2 -0
  261. package/dist/plugins/console/browser.js +115 -0
  262. package/dist/plugins/console/console/pdl.json +38 -0
  263. package/dist/plugins/console/console/view.mjs +26 -0
  264. package/dist/plugins/console/index.d.ts +4 -0
  265. package/dist/plugins/console/index.js +94 -0
  266. package/dist/plugins/console/picker.d.ts +2 -0
  267. package/dist/plugins/console/picker.js +48 -0
  268. package/dist/plugins/console/plugin.yaml +3 -0
  269. package/dist/plugins/console/topic-view.d.ts +3 -0
  270. package/dist/plugins/console/topic-view.js +388 -0
  271. package/dist/plugins/handoff/index.d.ts +2 -0
  272. package/dist/plugins/handoff/index.js +147 -0
  273. package/dist/plugins/handoff/plugin.yaml +8 -0
  274. package/dist/plugins/host-api/index.d.ts +7 -0
  275. package/dist/plugins/host-api/index.js +310 -0
  276. package/dist/plugins/host-api/plugin.yaml +2 -0
  277. package/dist/plugins/host-api/signing.d.ts +63 -0
  278. package/dist/plugins/host-api/signing.js +427 -0
  279. package/dist/plugins/host-api/skills/host-ops/SKILL.md +28 -0
  280. package/dist/plugins/host-api/skills/hostlet-plugin-dev/SKILL.md +38 -0
  281. package/dist/plugins/inbox/index.d.ts +15 -0
  282. package/dist/plugins/inbox/index.js +161 -0
  283. package/dist/plugins/inbox/plugin.yaml +2 -0
  284. package/dist/plugins/keys/account-directories.d.ts +18 -0
  285. package/dist/plugins/keys/account-directories.js +86 -0
  286. package/dist/plugins/keys/account-storage.d.ts +18 -0
  287. package/dist/plugins/keys/account-storage.js +112 -0
  288. package/dist/plugins/keys/console/pdl.json +710 -0
  289. package/dist/plugins/keys/console/view.mjs +619 -0
  290. package/dist/plugins/keys/index.d.ts +7 -0
  291. package/dist/plugins/keys/index.js +842 -0
  292. package/dist/plugins/keys/login-link.d.ts +2 -0
  293. package/dist/plugins/keys/login-link.js +15 -0
  294. package/dist/plugins/keys/plugin.yaml +3 -0
  295. package/dist/plugins/keys/quota-history.d.ts +91 -0
  296. package/dist/plugins/keys/quota-history.js +420 -0
  297. package/dist/plugins/mcp/console/pdl.json +412 -0
  298. package/dist/plugins/mcp/console/view.mjs +207 -0
  299. package/dist/plugins/mcp/index.d.ts +7 -0
  300. package/dist/plugins/mcp/index.js +494 -0
  301. package/dist/plugins/mcp/plugin.yaml +3 -0
  302. package/dist/plugins/member-health/index.d.ts +2 -0
  303. package/dist/plugins/member-health/index.js +478 -0
  304. package/dist/plugins/member-health/plugin.yaml +2 -0
  305. package/dist/plugins/memory/capabilities.d.ts +10 -0
  306. package/dist/plugins/memory/capabilities.js +70 -0
  307. package/dist/plugins/memory/console/pdl.json +459 -0
  308. package/dist/plugins/memory/console/view.mjs +254 -0
  309. package/dist/plugins/memory/corpus.d.ts +60 -0
  310. package/dist/plugins/memory/corpus.js +521 -0
  311. package/dist/plugins/memory/engines/fts-tree-diversity.d.ts +8 -0
  312. package/dist/plugins/memory/engines/fts-tree-diversity.js +49 -0
  313. package/dist/plugins/memory/engines/fts-tree-text.d.ts +12 -0
  314. package/dist/plugins/memory/engines/fts-tree-text.js +93 -0
  315. package/dist/plugins/memory/engines/fts-tree.d.ts +4 -0
  316. package/dist/plugins/memory/engines/fts-tree.js +387 -0
  317. package/dist/plugins/memory/engines/search.d.ts +9 -0
  318. package/dist/plugins/memory/engines/search.js +35 -0
  319. package/dist/plugins/memory/index.d.ts +3 -0
  320. package/dist/plugins/memory/index.js +465 -0
  321. package/dist/plugins/memory/notes.d.ts +22 -0
  322. package/dist/plugins/memory/notes.js +140 -0
  323. package/dist/plugins/memory/plugin.yaml +23 -0
  324. package/dist/plugins/model-profiles/index.d.ts +2 -0
  325. package/dist/plugins/model-profiles/index.js +919 -0
  326. package/dist/plugins/model-profiles/plugin.yaml +13 -0
  327. package/dist/plugins/model-profiles/review-source.d.ts +11 -0
  328. package/dist/plugins/model-profiles/review-source.js +640 -0
  329. package/dist/plugins/model-profiles/rules.d.ts +132 -0
  330. package/dist/plugins/model-profiles/rules.js +767 -0
  331. package/dist/plugins/model-profiles/skills/model-profile/SKILL.md +60 -0
  332. package/dist/plugins/model-profiles/sources.d.ts +61 -0
  333. package/dist/plugins/model-profiles/sources.js +375 -0
  334. package/dist/plugins/model-profiles/storage.d.ts +104 -0
  335. package/dist/plugins/model-profiles/storage.js +352 -0
  336. package/dist/plugins/model-profiles/types.d.ts +187 -0
  337. package/dist/plugins/model-profiles/types.js +12 -0
  338. package/dist/plugins/model-profiles/wakeup.d.ts +29 -0
  339. package/dist/plugins/model-profiles/wakeup.js +390 -0
  340. package/dist/plugins/models/index.d.ts +2 -0
  341. package/dist/plugins/models/index.js +63 -0
  342. package/dist/plugins/models/plugin.yaml +8 -0
  343. package/dist/plugins/ops/collector.d.ts +22 -0
  344. package/dist/plugins/ops/collector.js +48 -0
  345. package/dist/plugins/ops/config.d.ts +11 -0
  346. package/dist/plugins/ops/config.js +13 -0
  347. package/dist/plugins/ops/console/pdl.json +676 -0
  348. package/dist/plugins/ops/console/view.mjs +700 -0
  349. package/dist/plugins/ops/index.d.ts +3 -0
  350. package/dist/plugins/ops/index.js +20 -0
  351. package/dist/plugins/ops/journal.d.ts +7 -0
  352. package/dist/plugins/ops/journal.js +109 -0
  353. package/dist/plugins/ops/metrics.d.ts +3 -0
  354. package/dist/plugins/ops/metrics.js +81 -0
  355. package/dist/plugins/ops/plugin.yaml +63 -0
  356. package/dist/plugins/ops/samples.d.ts +54 -0
  357. package/dist/plugins/ops/samples.js +100 -0
  358. package/dist/plugins/ops/trace.d.ts +3 -0
  359. package/dist/plugins/ops/trace.js +104 -0
  360. package/dist/plugins/ops/usage.d.ts +2 -0
  361. package/dist/plugins/ops/usage.js +152 -0
  362. package/dist/plugins/plans/acceptance.d.ts +284 -0
  363. package/dist/plugins/plans/acceptance.js +247 -0
  364. package/dist/plugins/plans/blocked.d.ts +25 -0
  365. package/dist/plugins/plans/blocked.js +66 -0
  366. package/dist/plugins/plans/console/pdl.json +639 -0
  367. package/dist/plugins/plans/console/view.d.mts +2 -0
  368. package/dist/plugins/plans/console/view.mjs +855 -0
  369. package/dist/plugins/plans/dependencies.d.ts +5 -0
  370. package/dist/plugins/plans/dependencies.js +21 -0
  371. package/dist/plugins/plans/index.d.ts +72 -0
  372. package/dist/plugins/plans/index.js +2057 -0
  373. package/dist/plugins/plans/plugin.yaml +44 -0
  374. package/dist/plugins/plans/progress.d.ts +82 -0
  375. package/dist/plugins/plans/progress.js +516 -0
  376. package/dist/plugins/prompt/index.d.ts +8 -0
  377. package/dist/plugins/prompt/index.js +361 -0
  378. package/dist/plugins/prompt/plugin.yaml +2 -0
  379. package/dist/plugins/recovery/console/pdl.json +50 -0
  380. package/dist/plugins/recovery/console/view.mjs +46 -0
  381. package/dist/plugins/recovery/index.d.ts +9 -0
  382. package/dist/plugins/recovery/index.js +454 -0
  383. package/dist/plugins/recovery/plugin.yaml +9 -0
  384. package/dist/plugins/recovery/probe.d.ts +11 -0
  385. package/dist/plugins/recovery/probe.js +128 -0
  386. package/dist/plugins/restart/console/pdl.json +112 -0
  387. package/dist/plugins/restart/console/view.mjs +85 -0
  388. package/dist/plugins/restart/index.d.ts +10 -0
  389. package/dist/plugins/restart/index.js +669 -0
  390. package/dist/plugins/restart/plugin.yaml +9 -0
  391. package/dist/plugins/restart/scope.d.ts +6 -0
  392. package/dist/plugins/restart/scope.js +44 -0
  393. package/dist/plugins/schedule/console/pdl.json +696 -0
  394. package/dist/plugins/schedule/console/view.mjs +398 -0
  395. package/dist/plugins/schedule/events.d.ts +76 -0
  396. package/dist/plugins/schedule/events.js +158 -0
  397. package/dist/plugins/schedule/index.d.ts +32 -0
  398. package/dist/plugins/schedule/index.js +1199 -0
  399. package/dist/plugins/schedule/plugin.yaml +26 -0
  400. package/dist/plugins/schedule/when.d.ts +14 -0
  401. package/dist/plugins/schedule/when.js +83 -0
  402. package/dist/plugins/sessions/console/pdl.json +259 -0
  403. package/dist/plugins/sessions/console/view.mjs +355 -0
  404. package/dist/plugins/sessions/index.d.ts +3 -0
  405. package/dist/plugins/sessions/index.js +126 -0
  406. package/dist/plugins/sessions/participants.d.ts +28 -0
  407. package/dist/plugins/sessions/participants.js +83 -0
  408. package/dist/plugins/sessions/plugin.yaml +3 -0
  409. package/dist/plugins/signals/console/pdl.json +802 -0
  410. package/dist/plugins/signals/console/view.mjs +284 -0
  411. package/dist/plugins/signals/content.d.ts +31 -0
  412. package/dist/plugins/signals/content.js +151 -0
  413. package/dist/plugins/signals/index.d.ts +2 -0
  414. package/dist/plugins/signals/index.js +601 -0
  415. package/dist/plugins/signals/plugin.yaml +32 -0
  416. package/dist/plugins/signals/skills/signal-sources/SKILL.md +27 -0
  417. package/dist/plugins/skills/console/pdl.json +254 -0
  418. package/dist/plugins/skills/console/view.mjs +204 -0
  419. package/dist/plugins/skills/index.d.ts +11 -0
  420. package/dist/plugins/skills/index.js +567 -0
  421. package/dist/plugins/skills/install.d.ts +69 -0
  422. package/dist/plugins/skills/install.js +265 -0
  423. package/dist/plugins/skills/plugin.yaml +24 -0
  424. package/dist/plugins/skills/safety-scan.d.ts +17 -0
  425. package/dist/plugins/skills/safety-scan.js +78 -0
  426. package/dist/plugins/skills/skills/skill-ops/SKILL.md +29 -0
  427. package/dist/plugins/terminal/console/pdl.json +115 -0
  428. package/dist/plugins/terminal/console/view.mjs +178 -0
  429. package/dist/plugins/terminal/index.d.ts +3 -0
  430. package/dist/plugins/terminal/index.js +204 -0
  431. package/dist/plugins/terminal/plugin.yaml +2 -0
  432. package/dist/plugins/tools/index.d.ts +3 -0
  433. package/dist/plugins/tools/index.js +458 -0
  434. package/dist/plugins/tools/plugin.yaml +2 -0
  435. package/dist/plugins/tools/token.d.ts +61 -0
  436. package/dist/plugins/tools/token.js +179 -0
  437. package/dist/plugins/topic-tools/index.d.ts +9 -0
  438. package/dist/plugins/topic-tools/index.js +29 -0
  439. package/dist/plugins/topic-tools/plugin.yaml +2 -0
  440. package/dist/plugins/topic-tools/skills/topic-tidy/SKILL.md +108 -0
  441. package/dist/plugins/works/console/pdl.json +120 -0
  442. package/dist/plugins/works/console/view.mjs +91 -0
  443. package/dist/plugins/works/document-words.d.ts +50 -0
  444. package/dist/plugins/works/document-words.js +27 -0
  445. package/dist/plugins/works/editors.d.ts +3 -0
  446. package/dist/plugins/works/editors.js +162 -0
  447. package/dist/plugins/works/events.d.ts +58 -0
  448. package/dist/plugins/works/events.js +82 -0
  449. package/dist/plugins/works/files.d.ts +23 -0
  450. package/dist/plugins/works/files.js +53 -0
  451. package/dist/plugins/works/index.d.ts +9 -0
  452. package/dist/plugins/works/index.js +1088 -0
  453. package/dist/plugins/works/plugin.yaml +9 -0
  454. package/dist/plugins/works/preview.d.ts +10 -0
  455. package/dist/plugins/works/preview.js +30 -0
  456. package/dist/plugins/works/project.d.ts +3 -0
  457. package/dist/plugins/works/project.js +245 -0
  458. package/dist/plugins/works/resource.d.ts +28 -0
  459. package/dist/plugins/works/resource.js +71 -0
  460. package/dist/plugins/works/retention.d.ts +36 -0
  461. package/dist/plugins/works/retention.js +295 -0
  462. package/dist/plugins/works/skills/works-ops/SKILL.md +14 -0
  463. package/dist/plugins/works/viewers.d.ts +13 -0
  464. package/dist/plugins/works/viewers.js +87 -0
  465. package/dist/plugins/works/web/anchors.js +94 -0
  466. package/dist/plugins/works/web/document-edit.js +245 -0
  467. package/dist/plugins/works/web/preview-bridge.js +142 -0
  468. package/dist/plugins/works/web/reading-position.js +74 -0
  469. package/dist/plugins/works/web/view.html +1118 -0
  470. package/dist/runtime/runtime.d.ts +210 -0
  471. package/dist/runtime/runtime.js +338 -0
  472. package/dist/sdk/adapter-kit.d.ts +1 -0
  473. package/dist/sdk/adapter-kit.js +1 -0
  474. package/dist/sdk/client.d.ts +163 -0
  475. package/dist/sdk/client.js +43 -0
  476. package/dist/sdk/contracts.d.ts +1263 -0
  477. package/dist/sdk/contracts.js +1 -0
  478. package/dist/sdk/index.d.ts +57 -0
  479. package/dist/sdk/index.js +27 -0
  480. package/dist/sdk/source-choice.d.ts +40 -0
  481. package/dist/sdk/source-choice.js +217 -0
  482. package/dist/sdk/topic-text.d.ts +5 -0
  483. package/dist/sdk/topic-text.js +26 -0
  484. package/dist/sdk/transport.d.ts +12 -0
  485. package/dist/sdk/transport.js +34 -0
  486. package/node_modules/@hostlet/adapter-kit/dist/acp.d.ts +88 -0
  487. package/node_modules/@hostlet/adapter-kit/dist/acp.js +674 -0
  488. package/node_modules/@hostlet/adapter-kit/dist/command.d.ts +18 -0
  489. package/node_modules/@hostlet/adapter-kit/dist/command.js +39 -0
  490. package/node_modules/@hostlet/adapter-kit/dist/index.d.ts +8 -0
  491. package/node_modules/@hostlet/adapter-kit/dist/index.js +6 -0
  492. package/node_modules/@hostlet/adapter-kit/dist/models.d.ts +29 -0
  493. package/node_modules/@hostlet/adapter-kit/dist/models.js +108 -0
  494. package/node_modules/@hostlet/adapter-kit/dist/quota.d.ts +3 -0
  495. package/node_modules/@hostlet/adapter-kit/dist/quota.js +4 -0
  496. package/node_modules/@hostlet/adapter-kit/dist/rpc.d.ts +29 -0
  497. package/node_modules/@hostlet/adapter-kit/dist/rpc.js +84 -0
  498. package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.d.ts +5 -0
  499. package/node_modules/@hostlet/adapter-kit/dist/upstream-failure.js +37 -0
  500. package/node_modules/@hostlet/adapter-kit/package.json +16 -0
  501. package/node_modules/@hostlet/platform/dist/desktop.d.ts +16 -0
  502. package/node_modules/@hostlet/platform/dist/desktop.js +276 -0
  503. package/node_modules/@hostlet/platform/dist/files.d.ts +24 -0
  504. package/node_modules/@hostlet/platform/dist/files.js +113 -0
  505. package/node_modules/@hostlet/platform/dist/index.d.ts +6 -0
  506. package/node_modules/@hostlet/platform/dist/index.js +4 -0
  507. package/node_modules/@hostlet/platform/dist/paths.d.ts +4 -0
  508. package/node_modules/@hostlet/platform/dist/paths.js +9 -0
  509. package/node_modules/@hostlet/platform/dist/process.d.ts +45 -0
  510. package/node_modules/@hostlet/platform/dist/process.js +297 -0
  511. package/node_modules/@hostlet/platform/package.json +14 -0
  512. package/package.json +60 -4
@@ -0,0 +1,67 @@
1
+ /* 边界:引擎只放机制与时机,不认任何具体名字、不为单个位置打补丁 */
2
+ /* 文案:界面上所有给人看的字都在主题的 i18n 文件里(theme/<主题>/i18n/<语言>/<区域>.json,构建时合成加载脚本 i18n.js,全量加载)。
3
+ 每个文件的形状:{ 包: { 键: 文字 } }(包名在所有文件里唯一),可以分组嵌套;带数字、名字的句子写占位 {0}、{1}…(按参数的顺序);枚举的显示文字以枚举值作下一级键(取用 tcOf)。
4
+ 中文是形状,en 同键、同占位;某个键缺了当前语言就退回 zh。
5
+ 取用:tc('包.键', 参数…);PDL 里写 't:包.键'(或 { t: '包.键', args: ['$.n'] }),引擎在取值时换成当前语言的文字。
6
+ 运行时登记的文案(插件带来的)用 defineI18nPack(包, { zh, en }),和文件里的包合在一起。
7
+ 不进文案的:人和猫写的内容、文件内容、真实 id、模型和工具名(这些是数据)。 */
8
+ 'use strict';
9
+ const I18N = {};
10
+ function defineI18nPack(ns, packs) { /* 同一个包可以分几处定义(视图文案、视图模型文案),按语言合并 */
11
+ const cur = I18N[ns] || (I18N[ns] = {});
12
+ Object.keys(packs).forEach(function (l) { cur[l] = i18nMerge(cur[l] || {}, packs[l]); });
13
+ return cur;
14
+ }
15
+ /* 主题的 i18n 文件:一种语言一棵树,按包合进 I18N */
16
+ function defineI18n(lang, tree) { Object.keys(tree).forEach(function (ns) { const cur = I18N[ns] || (I18N[ns] = {}); cur[lang] = i18nMerge(cur[lang] || {}, tree[ns]); }); }
17
+ /* 同一个包分几处定义时逐层合并(同名分组里的键合在一起,不互相覆盖) */
18
+ function i18nMerge(a, b) { Object.keys(b).forEach(function (k) { const x = a[k], y = b[k]; a[k] = x && y && typeof x === 'object' && typeof y === 'object' ? i18nMerge(x, y) : y; }); return a; }
19
+ function i18nLang() { try { return (S && S.lang) || 'zh'; } catch (e) { return 'zh'; } } /* 加载早期(S 还没建好)就用 zh */
20
+ function i18nLeaf(pack, path) { return path.split('.').reduce(function (o, k) { return o == null ? o : o[k]; }, pack); }
21
+ function i18nIsLText(v) { return !!v && typeof v === 'object' && (typeof v.key === 'string' || Array.isArray(v.join)); }
22
+ function i18nFormat(str, args) {
23
+ if (!args) return str;
24
+ if (args.length === 1 && args[0] && typeof args[0] === 'object' && !Array.isArray(args[0]) && !i18nIsLText(args[0])) {
25
+ const map = args[0];
26
+ return str.replace(/\{([a-zA-Z0-9_]+)\}/g, function (m, name) {
27
+ const v = map[name];
28
+ if (v == null) return '';
29
+ return i18nIsLText(v) ? tcText(v, '') : String(v);
30
+ });
31
+ }
32
+ return str.replace(/\{(\d+)\}/g, function (m, i) {
33
+ const v = args[+i];
34
+ if (v == null) return '';
35
+ return i18nIsLText(v) ? tcText(v, '') : String(v);
36
+ });
37
+ }
38
+ function tc(key) {
39
+ const i = key.indexOf('.'), pack = I18N[key.slice(0, i)], path = key.slice(i + 1);
40
+ if (!pack) return key;
41
+ let leaf = i18nLeaf(pack[i18nLang()] || {}, path);
42
+ if (leaf == null) leaf = i18nLeaf(pack.zh || {}, path);
43
+ if (typeof leaf === 'function') return leaf.apply(null, Array.prototype.slice.call(arguments, 1));
44
+ if (leaf == null) return key;
45
+ let args = Array.prototype.slice.call(arguments, 1);
46
+ if (leaf && typeof leaf === 'object' && args.length) { const v = leaf[String(args[0])]; if (v == null) return args[0] == null ? '' : String(args[0]); leaf = v; args = args.slice(1); } /* 枚举:第一个参数按值取下一级,其余参数填占位;没有这个值就显示值本身;还没有值(数据没到)又没写这一项("undefined")就什么都不显示 */
47
+ return typeof leaf === 'string' && args.length ? i18nFormat(leaf, args) : leaf;
48
+ }
49
+ /* 渲染结构化本地化文本({ key, args } / { join, sep })或 t:键;缺失时退回 fallback */
50
+ function tcText(value, fallback) {
51
+ if (value == null) return fallback == null ? '' : String(fallback);
52
+ if (typeof value === 'string') return value.indexOf('t:') === 0 ? tc(value.slice(2)) : value;
53
+ if (Array.isArray(value.join)) {
54
+ const sep = value.sep == null ? '' : tcText(value.sep, '');
55
+ return value.join.map(function (part) { return tcText(part, ''); }).filter(Boolean).join(sep);
56
+ }
57
+ if (typeof value.key === 'string') {
58
+ const a = value.args;
59
+ const out = Array.isArray(a) ? tc.apply(null, [value.key].concat(a)) : a && typeof a === 'object' ? tc(value.key, a) : tc(value.key);
60
+ return out === value.key && fallback != null ? String(fallback) : out;
61
+ }
62
+ return fallback == null ? '' : String(fallback);
63
+ }
64
+ /* 枚举的显示文字:tcOf('包.分组', 枚举值)——分组键是静态的(可检查),枚举值来自数据 */
65
+ function tcOf(key, code) { return tc(key + '.' + code); }
66
+ /* 状态这类按数据取键的字:键不存在时用兜底键 */
67
+ function tcOr(key, fallback) { const v = tc(key); return v === key ? tc(fallback) : v; }
@@ -0,0 +1,102 @@
1
+ /* 边界:引擎只放机制与时机,不认任何具体名字、不为单个位置打补丁 */
2
+ // 结构检查 pdl-schema 的一部分:主题的 PDL 数据(theme/<主题>/pdl/*.yaml)里每个块 / 控件只用 PDL_SCHEMA 声明过的属性,枚举属性只取声明的值。
3
+ // 用法:node engine/pdl-check.js(lint.py 调用;输出 JSON:{ count, problems })
4
+ const fs = require('fs'), vm = require('vm'), path = require('path'), ROOT = path.join(__dirname, '..');
5
+ /* 源文件按层目录找:契约(PDL_SCHEMA、PDL_ROLES、PDL_POPUPS、ICON_RESERVED)在哪个文件里按定义找,不按文件名 */
6
+ const LAYERS = ['engine', 'platform', 'library', 'theme', 'app', 'mock', 'proto'];
7
+ function jsUnder(d) { const out = []; if (!fs.existsSync(d)) return out; for (const e of fs.readdirSync(d, { withFileTypes: true })) { const f = path.join(d, e.name); if (e.isDirectory()) out.push(...jsUnder(f)); else if (e.name.endsWith('.js') && !e.name.includes('.local.') && e.name !== 'pdl-check.js') out.push(f); } return out.sort(); }
8
+ const ALL = [].concat(...LAYERS.map(l => jsUnder(path.join(ROOT, l)))), rel = f => path.relative(ROOT, f), read = f => fs.readFileSync(f, 'utf8');
9
+ const NOCOPY = ALL.filter(f => !/\/copy\//.test(rel(f)));
10
+ function defOf(re) { for (const f of NOCOPY) { const m = read(f).match(re); if (m) return m; } return null; }
11
+ const ctx = { PDL_VIEWS: {}, PDL_ROWS: {}, PDL_NODES: {}, PDL_COMPONENTS: {}, PDL_FRAGS: {}, console };
12
+ vm.createContext(ctx);
13
+ const m = defOf(/const PDL_SCHEMA = \{[\s\S]*?\n\};\n/), mr = defOf(/const PDL_ROLES = \{[\s\S]*?\n\};\nfunction R\(k\) \{[^\n]*\n/);
14
+ vm.runInContext(mr[0].replace('const PDL_ROLES', 'this.PDL_ROLES').replace('function R(k)', 'this.R = function (k)'), ctx); /* 角色变体:契约的变体枚举从这里来 */
15
+ vm.runInContext(m[0].replace('const PDL_SCHEMA', 'this.PDL_SCHEMA'), ctx);
16
+ vm.runInContext(defOf(/Object\.assign\(PDL_SCHEMA, \{[\s\S]*?\n\}\);\n/)[0], ctx); /* 每个块 / 控件的属性:组件库登记进同一张表 */
17
+ /* 文案:视图里用 tr() 取的字在这里换成 't:键' 记号,这样能看出哪些字是文案键、哪些还是写死的字面量 */
18
+ vm.runInContext("this.I18N = {}; this.defineI18nPack = function (ns, p) { this.I18N[ns] = p; return p; }; this.tc = function (k) { return 't:' + k; };", ctx);
19
+ /* 主题的页面定义:每个主题的数据(构建从 pdl/*.yaml 合成的 pdl.js)里的视图、行模板、节点模板;片段引用($frag)照加载时一样换成片段 */
20
+ ctx.pdlThemeLoad = function (pdl) {
21
+ const expand = x => Array.isArray(x) ? x.flatMap(y => (y && y.$frag && Array.isArray(pdl.frags[y.$frag]) ? expand(pdl.frags[y.$frag]) : [expand(y)])) : !x || typeof x !== 'object' ? x : x.$frag ? expand(pdl.frags[x.$frag]) : Object.fromEntries(Object.entries(x).map(([k, v]) => [k, expand(v)]));
22
+ ctx.PDL_POPUPS = Object.assign(ctx.PDL_POPUPS || {}, expand(pdl.popups || {}));
23
+ Object.assign(ctx.PDL_VIEWS, expand(pdl.views || {})); Object.assign(ctx.PDL_ROWS, expand(pdl.rows || {})); Object.assign(ctx.PDL_NODES, expand(pdl.nodes || {}));
24
+ };
25
+ for (const f of ALL.filter(f => /^theme\/[^/]+\/pdl\.js$/.test(rel(f)))) vm.runInContext(read(f), ctx, { filename: rel(f) });
26
+ const S = ctx.PDL_SCHEMA, problems = [];
27
+ const isBind = v => typeof v === 'string' && /^[$@!{]/.test(v);
28
+ /* 行模板:layout 必填且是组件库的一种行布局;只用 _row 声明过的字段;这种布局不接受的字段(_rowNo)算失败 */
29
+ function rowCheck(r, where) {
30
+ if (!r || typeof r !== 'object' || Array.isArray(r)) return;
31
+ if (S._row.layout.indexOf(r.layout) < 0) { problems.push(where + ': 行模板的 layout = ' + JSON.stringify(r.layout) + ' 不是组件库的行布局'); return; }
32
+ for (const k of Object.keys(r)) {
33
+ if (!(k in S._row)) problems.push(where + ': 行模板的字段 ' + k + ' 没有声明');
34
+ else if (S._rowNo[r.layout].indexOf(k) >= 0) problems.push(where + ': ' + r.layout + ' 布局不接受 ' + k);
35
+ }
36
+ }
37
+ function walk(o, where) {
38
+ if (Array.isArray(o)) return o.forEach((x, i) => walk(x, where));
39
+ if (!o || typeof o !== 'object') return;
40
+ if (o.type === 'list' && o.row && typeof o.row === 'object') rowCheck(o.row, where + ' list.row');
41
+ if (o.type === 'list' && typeof o.row === 'string' && !ctx.PDL_ROWS[o.row]) problems.push(where + ': 行模板 ' + o.row + ' 不存在');
42
+ if (typeof o.type === 'string' && S[o.type]) {
43
+ const decl = S[o.type];
44
+ for (const k of Object.keys(o)) {
45
+ if (k === 'type') continue;
46
+ if (!(k in decl) && !(k in S._node)) { problems.push(where + ': ' + o.type + '.' + k + ' 没有声明'); continue; }
47
+ const d = k in decl ? decl[k] : S._node[k];
48
+ if (Array.isArray(d) && !isBind(o[k]) && d.indexOf(String(o[k])) < 0 && !(d.indexOf('$') >= 0 && typeof o[k] !== 'string')) problems.push(where + ': ' + o.type + '.' + k + ' = ' + JSON.stringify(o[k]) + ' 不在声明的取值里');
49
+ }
50
+ } else if (typeof o.type === 'string' && o.type.length < 20 && /^[a-z]\w*$/.test(o.type)) problems.push(where + ': 块 / 控件 ' + o.type + ' 没有声明属性');
51
+ else if (!o.type && 'variant' in o && ctx.PDL_ROLES.part.indexOf(o.variant) < 0) problems.push(where + ': 片段的 variant = ' + JSON.stringify(o.variant) + ' 不是片段的角色(PDL_ROLES.part)');
52
+ for (const k of Object.keys(o)) walk(o[k], where);
53
+ }
54
+ /* 弹窗的声明(PDL_POPUPS):只用 _popup 声明过的属性,枚举取声明的值(exit 的每一项都要在枚举里),at / exit / drag 必填 */
55
+ const pp = Object.keys(ctx.PDL_POPUPS || {}).length; /* 主题数据里的弹窗声明(登记表在引擎) */
56
+ if (!pp) problems.push('找不到 PDL_POPUPS 的声明');
57
+ else {
58
+ const D = S._popup;
59
+ for (const [k, d] of Object.entries(ctx.PDL_POPUPS)) {
60
+ for (const need of ['at', 'exit', 'drag']) if (!(need in d)) problems.push('popup ' + k + ': 缺少 ' + need);
61
+ for (const [a, v] of Object.entries(d)) {
62
+ if (!(a in D)) { problems.push('popup ' + k + '.' + a + ' 没有声明'); continue; }
63
+ if (Array.isArray(D[a])) [].concat(v).forEach(x => { if (D[a].indexOf(String(x)) < 0) problems.push('popup ' + k + '.' + a + ' = ' + JSON.stringify(x) + ' 不在声明的取值里'); });
64
+ }
65
+ }
66
+ }
67
+ /* 给人看的字只能是文案键('t:包.键')或数据绑定:文字类属性里出现写死的中文就报错 */
68
+ const TEXT = new Set(['label', 'text', 'title', 'tip', 'placeholder', 'empty', 'help', 'sub', 'desc', 'aria']);
69
+ function walkText(o, where) {
70
+ if (Array.isArray(o)) return o.forEach(x => walkText(x, where));
71
+ if (!o || typeof o !== 'object') return;
72
+ for (const k of Object.keys(o)) {
73
+ const v = o[k];
74
+ if (TEXT.has(k) && typeof v === 'string' && /[\u3400-\u9fff]/.test(v) && !/^t:/.test(v)) problems.push(where + ': ' + k + ' 是写死的文字 ' + JSON.stringify(v.slice(0, 20)) + '(改成文案键 t:…)');
75
+ else walkText(v, where);
76
+ }
77
+ }
78
+ for (const [n, v] of Object.entries(ctx.PDL_VIEWS)) walkText(v, 'view ' + n);
79
+ for (const [n, v] of Object.entries(ctx.PDL_NODES)) walkText(v, 'node ' + n);
80
+ for (const [n, v] of Object.entries(ctx.PDL_ROWS)) walkText(v, 'row ' + n);
81
+ /* 对话框视图(dlg.*)上的 fields / doc / panes / foot / ack / sync 是引擎对话框的描述(字段的 type 是输入框类型,比如 number),不是 PDL 节点,不按块 / 控件查 */
82
+ const DLG_DESC = new Set(['fields', 'doc', 'panes', 'foot', 'ack', 'sync']);
83
+ for (const [n, v] of Object.entries(ctx.PDL_VIEWS)) walk(n.indexOf('dlg.') === 0 ? Object.fromEntries(Object.entries(v).filter(([k]) => !DLG_DESC.has(k))) : v, 'view ' + n);
84
+ for (const [n, v] of Object.entries(ctx.PDL_NODES)) walk(v, 'node ' + n);
85
+ for (const [n, v] of Object.entries(ctx.PDL_ROWS)) { rowCheck(v, 'row ' + n); walk(v, 'row ' + n); }
86
+ /* 操作引用:PDL 和视图模型里写死的 act 名必须是登记过的动作(A.x / Object.assign(A, {…}) / CHANGES / INPUTS / 组件库内置),否则按钮是哑的 */
87
+ const ACTS = new Set();
88
+ const srcs = NOCOPY.map(read);
89
+ for (const t of srcs) {
90
+ for (const m of t.matchAll(/\b(?:A|CHANGES|INPUTS|MOCK_ACTS)\.(\w+)\s*=/g)) ACTS.add(m[1]);
91
+ for (const blk of t.matchAll(/const (?:A|CHANGES|INPUTS|MOCK_ACTS) = \{([^\n]*)\};/g)) for (const m of blk[1].matchAll(/(?:^|,)\s*(\w+):/g)) ACTS.add(m[1]);
92
+ for (const m of t.matchAll(/(?:\bA\[|\bCHANGES\[|\bINPUTS\[|\bMOCK_ACTS\[)'(\w+)'\]\s*=/g)) ACTS.add(m[1]);
93
+ for (const blk of t.matchAll(/(?:Object\.assign\(\s*(?:A|CHANGES|INPUTS|MOCK_ACTS)\s*,|const (?:A|CHANGES|INPUTS|MOCK_ACTS) =)\s*\{([\s\S]*?)\n\}\)?;/g)) for (const m of blk[1].matchAll(/(?:^|\n)\s{2}(\w+):\s*(?:function|\w+\()/g)) ACTS.add(m[1]);
94
+ }
95
+ for (const t of srcs) for (const m of t.matchAll(/\b(?:act|change|input)\s*:\s*'(\w+)'/g)) if (!ACTS.has(m[1])) problems.push('act ' + m[1] + ' 没有登记成动作(按钮会是哑的)');
96
+ /* 图标按含义引用:保留字形(同一个字形只能表达一个含义)只能通过含义名用(frame.js 的 ICON_MEANING / ICON_RESERVED) */
97
+ const RES = JSON.parse((defOf(/const ICON_RESERVED = (\[[^\]]*\]);/) || [, '[]'])[1].replace(/'/g, '"'));
98
+ for (const t of srcs) for (const m of t.matchAll(/\bicon(?:\(|\s*:\s*)'([\w-]+)'/g)) if (RES.indexOf(m[1]) >= 0) problems.push('图标 ' + m[1] + ' 是保留字形,要用含义名(send / close / delete / prev / next / collapse…)');
99
+ /* 角色变体只来自契约:视图模型和组件代码里写死的 variant 也必须是登记过的角色,不能在数据里挑样子 */
100
+ const ROLE_NAMES = new Set([].concat.apply([], Object.keys(ctx.PDL_ROLES).map(k => ctx.PDL_ROLES[k])));
101
+ for (const f of NOCOPY.filter(f => !/^mock\//.test(rel(f)))) for (const mm of read(f).matchAll(/\bvariant: '([^']*)'/g)) if (!ROLE_NAMES.has(mm[1])) problems.push(rel(f) + ': variant ' + JSON.stringify(mm[1]) + ' 不是登记过的角色(PDL_ROLES)');
102
+ console.log(JSON.stringify({ count: problems.length, problems: problems.slice(0, 40), acts: ACTS.size }));
@@ -0,0 +1,353 @@
1
+ /* 边界:引擎只放机制与时机,不认任何具体名字、不为单个位置打补丁 */
2
+ /* ═════════════ 自定义主题的文档:一棵树(引擎,纯函数) ═════════════
3
+ full = { layout: { tree(整棵容器树), open }, slots: { 内容容器 id: 改过的那份 }, views: { 视图 id: 改过的那份 }, tokens, style }:
4
+ 没改过的内容容器、视图直接用主题声明的(tree.js pdlEffectiveSync)。旁边存着基线快照 base = { v, tree, slots, views }——
5
+ 只记被改过的那几个根原来的样子。升级(主题的基线版本变了):每个改过的根算一遍差异(按节点 id:拿掉 / 加上 / 挪动 / 改属性),
6
+ 套到新版本的同一个根上;找不到目标的改动作废(记进 dropped),套不上就把文档存档、直接用新基线。
7
+ 之前那种按插槽存键列表的文档(有 place)不再读:作废(都是测试数据)。 */
8
+ 'use strict';
9
+
10
+ const PDL_BASE_VERSION = 5;
11
+
12
+ /* 旧主题的结构标识在读取时归一。文案、HTML、组件源码和数据仍是作者的原值。 */
13
+ const PDL_PREVIOUS_IDS = new Map([
14
+ ['nav.cafe', 'nav.workspace'],
15
+ ['nav.hl', 'nav.workspace.shell'],
16
+ ['nav.cafe.shell', 'nav.workspace.shell'],
17
+ ['chat.node/cat', 'chat.node/peer']
18
+ ]);
19
+ const PDL_ID_REFS = new Set(['id', 'key', 'ref', 'slot', 'topSlot', 'slots', 'anchor', 'from', 'view', 'node', 'move', 'keep', 'routesFrom']);
20
+ function pdlReadThemeNames(pdl) {
21
+ const renamed = function (id) { return PDL_PREVIOUS_IDS.get(id) || id; };
22
+ const rekey = function (entries, from, to) {
23
+ if (!entries || !Object.hasOwn(entries, from)) return;
24
+ if (!Object.hasOwn(entries, to)) entries[to] = entries[from];
25
+ delete entries[from];
26
+ };
27
+ ['slots', 'views', 'nodes'].forEach(function (kind) {
28
+ PDL_PREVIOUS_IDS.forEach(function (to, from) { rekey(pdl[kind], from, to); });
29
+ });
30
+ rekey(pdl.spaces, 'cafe', 'workspace');
31
+ rekey(pdl.nav, 'cafe', 'workspace');
32
+ Object.keys(pdl.nav || {}).forEach(function (space) { pdl.nav[space] = renamed(pdl.nav[space]); });
33
+ const visit = function (node) {
34
+ if (!node || typeof node !== 'object') return;
35
+ if (Array.isArray(node)) { node.forEach(visit); return; }
36
+ if (node.space === 'cafe') node.space = 'workspace';
37
+ if (node.slot === 'chat.node' && node.of === 'cat') node.of = 'peer';
38
+ Object.keys(node).forEach(function (key) {
39
+ if (key === 'data' || key === 'args' || key === 'message') return;
40
+ const value = node[key];
41
+ if (PDL_ID_REFS.has(key)) node[key] = Array.isArray(value) ? value.map(renamed) : renamed(value);
42
+ visit(node[key]);
43
+ });
44
+ };
45
+ ['tree', 'layout', 'slots', 'views', 'nodes', 'frags', 'spaces', 'popups', 'contributions'].forEach(function (key) { visit(pdl[key]); });
46
+ return pdl;
47
+ }
48
+ /* 一个根当前在主题里的样子(升级、新建快照都从这里取;插件插进来的不算) */
49
+ function pdlRootNow(kind, rid) { if (kind === 'tree') return PDL_LAYOUT.tree; const r = (PDL_BASE[kind] || {})[rid]; return r ? JSON.parse(JSON.stringify(r, function (k, v) { return Array.isArray(v) ? v.filter(function (x) { return !(x && x.ins); }) : v; })) : null; } /* 只有主题自己的:插件插进去的节点不算(它们落在生效的那份上) */
50
+ /* 文档里改过的根都在快照里有一份原样(第一次改它时记下) */
51
+ function pdlBaseFill(full, base) {
52
+ base.slots = base.slots || {}; base.views = base.views || {};
53
+ if (full.layout && full.layout.tree && !base.tree) base.tree = pdlClone(PDL_LAYOUT.tree);
54
+ ['slots', 'views'].forEach(function (kind) { Object.keys(full[kind] || {}).forEach(function (rid) { if (!(rid in base[kind])) { const r = pdlRootNow(kind, rid); base[kind][rid] = r ? pdlClone(r) : null; } }); });
55
+ }
56
+ /* ── 一个根里的节点:id → { node, parent(所在容器的 id), prev(前一个兄弟的 id) } ── */
57
+ function pdlTreeFlat(root) {
58
+ const out = {};
59
+ const walk = function (x, parent) {
60
+ if (!x || typeof x !== 'object') return;
61
+ PDL_INS_LISTS.forEach(function (k) {
62
+ if (!Array.isArray(x[k])) return;
63
+ let prev = null;
64
+ x[k].forEach(function (y) { if (!y || typeof y !== 'object') return; const id = pdlNodeId(y); if (id) { out[id] = { node: y, parent: parent, list: k, prev: prev }; prev = id; } walk(y, id || parent); });
65
+ });
66
+ Object.keys(x).forEach(function (k) { const v = x[k]; if (v && typeof v === 'object' && !Array.isArray(v)) walk(v, parent); });
67
+ };
68
+ walk(root, '#root');
69
+ return out;
70
+ }
71
+ function pdlOwnProps(n) { const o = {}; Object.keys(n).forEach(function (k) { if (!Array.isArray(n[k]) && !(n[k] && typeof n[k] === 'object' && pdlTreeFlatHas(n[k]))) o[k] = n[k]; }); return o; }
72
+ function pdlTreeFlatHas(x) { return Object.keys(pdlTreeFlat(x)).length > 0; }
73
+ /* ── 差异:user 相对 base 的改动(一个根)── */
74
+ function pdlTreeDiff(user, base) {
75
+ const u = pdlTreeFlat(user), b = pdlTreeFlat(base), ops = [];
76
+ Object.keys(b).forEach(function (id) { if (!u[id]) ops.push({ op: 'remove', id: id }); });
77
+ Object.keys(u).forEach(function (id) {
78
+ const x = u[id], y = b[id];
79
+ if (!y) { ops.push({ op: 'add', id: id, node: pdlClone(x.node), parent: x.parent, list: x.list, after: x.prev }); return; }
80
+ if (x.parent !== y.parent || x.prev !== y.prev) ops.push({ op: 'move', id: id, parent: x.parent, list: x.list, after: x.prev });
81
+ const pu = pdlOwnProps(x.node), pb = pdlOwnProps(y.node), set = {};
82
+ Object.keys(pu).concat(Object.keys(pb)).forEach(function (k) { if (JSON.stringify(pu[k]) !== JSON.stringify(pb[k])) set[k] = k in pu ? pu[k] : null; });
83
+ if (Object.keys(set).length) ops.push({ op: 'set', id: id, props: set });
84
+ });
85
+ return ops;
86
+ }
87
+ /* ── 套用:把改动逐条套到一个根的拷贝上;目标已不存在的作废(记进 dropped) ── */
88
+ function pdlTreeApply(ops, root) {
89
+ const r = pdlClone(root), dropped = [];
90
+ const listOf = function (parent, k) { if (parent === '#root') return r[k] || (r[k] = []); const f = pdlTreeFlat(r)[parent]; return f ? f.node[k] || (f.node[k] = []) : null; };
91
+ const take = function (id) { const f = pdlTreeFlat(r)[id]; if (!f) return null; const list = f.parent === '#root' ? r[f.list] : pdlTreeFlat(r)[f.parent].node[f.list]; return list.splice(list.indexOf(f.node), 1)[0]; };
92
+ const put = function (op, n) { const list = listOf(op.parent, op.list); if (!list) return false; pdlKidsPlace(list, n, op.after === null ? null : op.after); return true; };
93
+ ops.forEach(function (op) {
94
+ if (op.op === 'remove') { if (!take(op.id)) dropped.push(op); return; }
95
+ if (op.op === 'add') { if (pdlTreeFlat(r)[op.id] || !put(op, pdlClone(op.node))) dropped.push(op); return; }
96
+ if (op.op === 'move') { const n = take(op.id); if (!n || !put(op, n)) dropped.push(op); return; }
97
+ if (op.op === 'set') { const f = pdlTreeFlat(r)[op.id]; if (!f) { dropped.push(op); return; } Object.keys(op.props).forEach(function (k) { if (op.props[k] == null) delete f.node[k]; else f.node[k] = op.props[k]; }); }
98
+ });
99
+ return { root: r, dropped: dropped };
100
+ }
101
+ /* ── 升级:每个改过的根按差异套到新版本上 ── */
102
+ /* 一份基线快照里有、现在的主题里哪都没有的节点:主题删掉了它,用户对它的改动(包括跨容器挪过去的那份)一起作废 */
103
+ function pdlGoneIds(base) {
104
+ const ids = function (roots) { const out = {}; roots.forEach(function (r) { if (r) Object.assign(out, pdlTreeFlat(r)); }); return out; };
105
+ const kinds = ['slots', 'views'], was = ids([base.tree].concat([].concat.apply([], kinds.map(function (k) { return Object.values(base[k] || {}); }))));
106
+ const now = ids([PDL_LAYOUT.tree].concat([].concat.apply([], kinds.map(function (k) { return Object.keys(PDL_BASE[k] || {}).map(function (rid) { return pdlRootNow(k, rid); }); }))));
107
+ return Object.keys(was).filter(function (id) { return !now[id]; });
108
+ }
109
+ /* 快照和现在的主题一样(同一版、内容没变):不用升级 */
110
+ function pdlBaseSame(base) {
111
+ const same = function (a, b) { return JSON.stringify(a) === JSON.stringify(b); };
112
+ return base.v === PDL_BASE_VERSION && (!base.tree || same(base.tree, PDL_LAYOUT.tree)) && ['slots', 'views'].every(function (k) { return Object.keys(base[k] || {}).every(function (rid) { return base[k][rid] === null || same(base[k][rid], pdlRootNow(k, rid)); }); });
113
+ }
114
+ function pdlUpgrade(user) {
115
+ /* 两份结构一起改名,再算用户的差异,入口的挪动和隐藏才找得到原来的节点。 */
116
+ const full = pdlReadThemeNames(pdlClone(user.full)), base = pdlReadThemeNames(pdlClone(user.base));
117
+ const nb = { v: PDL_BASE_VERSION, slots: {}, views: {} }, dropped = [], gone = pdlGoneIds(base);
118
+ const diff = function (u, b) { return pdlTreeDiff(u, b).filter(function (op) { if (op.op === 'add' && gone.indexOf(op.id) >= 0) { dropped.push(op); return false; } return true; }); };
119
+ if (full.layout && full.layout.tree) { const r = pdlTreeApply(diff(full.layout.tree, base.tree || PDL_LAYOUT.tree), PDL_LAYOUT.tree); full.layout.tree = r.root; nb.tree = pdlClone(PDL_LAYOUT.tree); dropped.push.apply(dropped, r.dropped); }
120
+ ['slots', 'views'].forEach(function (kind) {
121
+ Object.keys(full[kind] || {}).forEach(function (rid) {
122
+ const now = pdlRootNow(kind, rid), was = (base[kind] || {})[rid];
123
+ if (!was) { nb[kind][rid] = null; return; } /* 用户自己加的根(自己的容器):原样留着 */
124
+ if (!now) { delete full[kind][rid]; return; } /* 这一版主题里没有了 */
125
+ const r = pdlTreeApply(diff(full[kind][rid], was), now); full[kind][rid] = r.root; nb[kind][rid] = pdlClone(now); dropped.push.apply(dropped, r.dropped);
126
+ });
127
+ });
128
+ return { full: full, base: nb, dropped: dropped };
129
+ }
130
+ /* 上限(spec 主题文档):只在导入主题、登记插件片段时校验一次 */
131
+ const PDL_LIMIT = { depth: 256, nodes: 65536 };
132
+ function pdlLimitWhy(x) {
133
+ let nodes = 0, deep = 0;
134
+ const walk = function (v, d) { if (!v || typeof v !== 'object') return; if (d > deep) deep = d; if (Array.isArray(v)) { v.forEach(function (y) { walk(y, d); }); return; } nodes += 1; if (v.type === 'frame') return; Object.keys(v).forEach(function (k) { walk(v[k], d + 1); }); };
135
+ walk(x, 0);
136
+ return deep > PDL_LIMIT.depth ? 'depth' : nodes > PDL_LIMIT.nodes ? 'nodes' : '';
137
+ }
138
+
139
+ /* ═════════════ 主题:系统主题 + 自定义主题 ═════════════
140
+ 系统主题(系统主题 1 / 2)不可改:就是基线(加各自的皮肤),随基线一起更新。
141
+ 自定义主题 = 一份完整文档 + 它派生自的基线快照。在系统主题上做任何调整(编辑布局、显示 / 隐藏、主题计算器)
142
+ 都会自动复制出一份(名字同原主题,重名加序号),改动落在它上面(不打断,给一条可撤销的提示);在自定义主题上就直接改它。
143
+ 恢复 = 切回某个系统主题;自定义主题一直留在列表里,什么都不会丢。 */
144
+ /* 每套主题只有一套配色(palette:浅色、深色两个变体由它推出)和一个强调色(在配色的值里,主题计算器改它)。
145
+ 明暗模式是用户偏好。内置主题色共用一套布局和素材;主题插件也可以提供只读配色(id 'pack:…')。 */
146
+ const PDL_SYS_THEMES = []; /* 系统主题描述由当前主题的数据登记。 */
147
+ function pdlPackThemes() { return THEME_SRC.packs().map(function (t) { return { id: 'pack:' + t.id, name: t.name, src: t.src, skin: 'default', palette: t.id }; }); }
148
+ /* 主题文档放在哪:应用登记 THEME_DOCS = { read() → Promise<主题|null>, write(主题) }(宿主保存,清缓存也还在);没登记时存在浏览器里。启动时先读回来(theme 阶段:最先,读完主题文档再读主题包) */
149
+ let THEME_DOCS = null, THEMES_HELD = null, THEMES_WRITE = Promise.resolve();
150
+ function pdlThemes() { return (THEME_DOCS ? THEMES_HELD && pdlClone(THEMES_HELD) : store.get('pdl-themes-v1', null)) || { active: PDL_SYS_THEMES[0].id, customs: [] }; } /* 每次给一份副本(和读存储一样):改了要 pdlThemesSave 才算数 */
151
+ function pdlThemesSave(t) { if (THEME_DOCS) { const j = JSON.stringify(t); if (j === JSON.stringify(pdlThemes())) return; THEMES_HELD = JSON.parse(j); THEMES_WRITE = Promise.resolve(THEME_DOCS.write(t)); } /* 没变就不写宿主(启动时的整理多半什么都没改) */ else store.set('pdl-themes-v1', t); }
152
+ /* 主题包(spec 主题包):所有主题都是主题包,一套加载规则。包在两处:内置的随代码发布(只读),导入的由后端解开、按主题 id 存成目录;后端两处一起列出(builtin 标出内置)。
153
+ 应用登记 THEME_PACKS = { list() → Promise<[{ id, name, version, contractVersion, builtin }]>,
154
+ read(id) → Promise<包:pdl、uses 用到的组件包代码 components、文案 i18n、素材 assets(地址)>, install(文件) → Promise<{ id } | { custom: 自定义主题 }>,
155
+ remove(id), export(id), exportCustom(自定义主题) }。主题存储只记当前主题和自定义主题(自定义主题的 theme 是它基于的包)。
156
+ 启动时先读内置的底包 default,当前主题是别的包再读它盖在上面(依次是它用到的组件包、文案、素材、pdl;同 id 盖过底包,缺的回落底包);当前主题的包读不到就只用底包。
157
+ 底包在主题页里就是系统主题(它的几套配色),不另列一行。
158
+ 同一包内切换外观时同步当前文档;换包时等选择存好,再重新启动页面以加载组件。 */
159
+ let THEME_PACKS = null, PACK_LIST = [], PACK_LOADED = null;
160
+ const PACK_BASE = 'default';
161
+ function pdlThemePacks() { return PACK_LIST.map(function (p) { return { id: 'pkg:' + p.id, name: p.name, src: p.version, skin: 'default', palette: defaultPalette(), theme: p.id, builtin: !!p.builtin }; }); }
162
+ function pdlActivePack(t) { const x = t.customs.find(function (c) { return c.id === t.active; }) || pdlSysTheme(t.active) || {}; return PACK_LIST.some(function (p) { return p.id === x.theme; }) ? x.theme : null; }
163
+ function pdlPackApply(p) {
164
+ const add = function (tag, text) { const el = document.createElement(tag); el.textContent = text; document.head.appendChild(el); };
165
+ Object.keys(p.components).forEach(function (u) { p.components[u].css.forEach(function (x) { add('style', x); }); p.components[u].js.forEach(function (x) { add('script', x); }); });
166
+ Object.keys(p.i18n).forEach(function (l) { defineI18n(l, p.i18n[l]); });
167
+ Object.assign(ASSETS, p.assets);
168
+ pdlThemeLoad(pdlReadThemeNames(p.pdl), { id: p.id, name: p.name, version: p.version, contractVersion: p.contractVersion }); pdlBaseTake();
169
+ }
170
+ function pdlPackBoot() {
171
+ return THEME_PACKS.list().then(function (list) {
172
+ PACK_LIST = list.filter(function (p) { return p.id !== PACK_BASE; });
173
+ return THEME_PACKS.read(PACK_BASE).then(pdlPackApply).then(function () {
174
+ const id = pdlActivePack(pdlThemes()); if (!id) return;
175
+ return THEME_PACKS.read(id).then(function (p) { pdlPackApply(p); PACK_LOADED = id; }, function () { /* 当前主题的包不在了:只用底包 */ });
176
+ });
177
+ });
178
+ }
179
+ function pdlThemeGo(t) {
180
+ pdlThemesSave(t);
181
+ if (pdlThemeSync()) render(true);
182
+ }
183
+ onStart('theme', function () { if (!THEME_DOCS) return pdlPackBoot(); return THEME_DOCS.read().then(function (t) { THEMES_HELD = t; return pdlPackBoot(); }); });
184
+ function pdlSysTheme(id) { return PDL_SYS_THEMES.concat(pdlPackThemes(), pdlThemePacks()).find(function (x) { return x.id === id; }) || null; } /* 只读主题:系统主题 + 主题插件带来的主题 + 装好的主题包 */
185
+ /* 当前主题的名字(主题页、主题计算器标题都用它) */
186
+ function pdlRoName(d) { return d.name || pdlText(BUILTIN_PALETTES.find(function (p) { return p.id === d.palette; })?.name) || tc('pdlDoc.sysName', d.n); }
187
+ /* 主题名字不重复:用户的主题(复制、导入、改名、存档)用给的名字,和列表里已有的重名就加序号(“简约经典 2”) */
188
+ function pdlUniqueName(t, name, self) {
189
+ const taken = t.customs.filter(function (c) { return c.id !== self; }).map(function (c) { return c.name; }).concat(PDL_SYS_THEMES.concat(pdlPackThemes(), pdlThemePacks()).map(pdlRoName));
190
+ let n = 2, v = name; while (taken.indexOf(v) >= 0) { v = name + ' ' + n; n += 1; } return v;
191
+ }
192
+ function pdlArchive() { return store.get('pdl-archive-v1', []) || []; }
193
+ /* 启动:每个自定义主题的基线版本落后就升级;失败 → 那份文档存档(出现在 主题 › 入口布局 里,选中就重试),它原来是当前主题就退回系统主题 1。
194
+ 系统主题不用升级:它就是基线 */
195
+ function pdlDocBoot() {
196
+ const t = pdlThemes(), keep = [];
197
+ t.customs.forEach(function (c) {
198
+ if (!c.base || !c.full || c.full.place) { if (c.id === t.active) t.active = PDL_SYS_THEMES[0].id; return; } /* 旧格式(按插槽存键列表):作废 */
199
+ if (pdlBaseSame(c.base)) { keep.push(c); return; } /* 主题变了(换了版本,或者同一版里删了内置节点)才升级 */
200
+ try {
201
+ const up = pdlUpgrade(c);
202
+ keep.push(Object.assign({}, c, { full: up.full, base: up.base }));
203
+ if (c.id === t.active) S.pdlUpgrade = { from: c.base.v, dropped: up.dropped.length };
204
+ } catch (e) {
205
+ const arch = pdlArchive(); arch.push({ key: 'a' + Date.now() + c.id, name: c.name, full: c.full, base: c.base, error: String(e && e.message || e) });
206
+ store.set('pdl-archive-v1', arch);
207
+ if (c.id === t.active) { t.active = PDL_SYS_THEMES[0].id; S.pdlUpgradeFailed = { from: c.base.v }; }
208
+ }
209
+ });
210
+ t.customs = keep; pdlThemesSave(t);
211
+ pdlThemeSync();
212
+ }
213
+ /* 生效:当前主题是自定义主题时,它的文档按 id 覆盖主题声明的那几个根(tree.js pdlEffectiveSync);系统主题就是基线 */
214
+ function pdlThemeSync() {
215
+ const t = pdlThemes(), c = t.customs.find(function (theme) { return theme.id === t.active; });
216
+ if (pdlActivePack(t) !== PACK_LOADED) { THEMES_WRITE.then(function () { location.reload(); }); return false; }
217
+ const previous = S.pdlDoc;
218
+ S.pdlDoc = c ? { full: c.full, base: c.base } : null;
219
+ const active = c || pdlSysTheme(t.active) || PDL_SYS_THEMES[0];
220
+ S.pdlSkin = active.skin || 'default';
221
+ S.pdlPalette = active.palette || defaultPalette();
222
+ PDL_THEME_SYNC.forEach(function (f) { f(); });
223
+ /* 内置主题色共享布局文档。只在文档变化时重建布局和被盖住的视图。 */
224
+ if (S.pdlDoc !== previous) {
225
+ pdlTreeChanged(previous?.full);
226
+ navStale();
227
+ }
228
+ return true;
229
+ }
230
+ function pdlBaseNew() { return { v: PDL_BASE_VERSION, slots: {}, views: {} }; }
231
+ /* 编辑:界面上的每次调整都改当前自定义主题的文档(fn(full)),第一次改到的根在基线快照里记下原样。
232
+ 当前是系统主题:先复制出一个自定义主题,改动落在它上面,并给一条可撤销的提示 */
233
+ function pdlDocEdit(fn) {
234
+ const t = pdlThemes();
235
+ let c = t.customs.find(function (x) { return x.id === t.active; });
236
+ /* 一份自定义主题一直被改下去;只有当前主题是只读主题(系统主题)时改它才复制出新的一份,或者用户明确“复制为新主题” */
237
+ if (!c) {
238
+ const from = t.active, ro = pdlSysTheme(from) || PDL_SYS_THEMES[0];
239
+ c = { id: 'c' + Date.now(), name: pdlUniqueName(t, pdlRoName(ro)), skin: ro.skin, palette: ro.palette, theme: ro.theme, full: {}, base: pdlBaseNew(), from: from };
240
+ t.customs.push(c); t.active = c.id;
241
+ S.pdlCopied = { id: c.id, from: from, name: c.name };
242
+ }
243
+ const full = pdlClone(c.full);
244
+ fn(full);
245
+ pdlBaseFill(full, c.base);
246
+ c.full = full; pdlThemesSave(t); pdlThemeSync();
247
+ if (S.pdlCopied && S.pdlCopied.id === c.id && !S.pdlCopied.told) { S.pdlCopied.told = true; const cid = c.id; undoShow({ text: tc('pdlDoc.copiedTheme', c.name), undo: function () { pdlThemeUndoCopy(cid); } }); } /* 第一次修改系统主题时自动复制:能撤回 */
248
+ }
249
+ /* 撤销自动复制:删掉这份副本,回到原来的系统主题 */
250
+ function pdlThemeUndoCopy(id) {
251
+ const t = pdlThemes(), c = t.customs.find(function (x) { return x.id === id; }); if (!c) return;
252
+ t.customs = t.customs.filter(function (x) { return x.id !== id; }); t.active = c.from || PDL_SYS_THEMES[0].id; S.pdlCopied = null; pdlThemeGo(t);
253
+ }
254
+ A.pdlThemeUse = function (d) { const t = pdlThemes(); if (t.active === d.id) return; t.active = d.id; pdlThemeGo(t); };
255
+ A.pdlThemeDup = function (d) { /* 复制为新主题(系统主题也能复制) */
256
+ const t = pdlThemes(), src = t.customs.find(function (x) { return x.id === d.id; }), sys = pdlSysTheme(d.id);
257
+ const c = { id: 'c' + Date.now(), name: pdlUniqueName(t, src ? src.name : pdlRoName(sys || PDL_SYS_THEMES[0])), skin: src ? src.skin : sys ? sys.skin : 'default', palette: src ? src.palette : sys ? sys.palette : defaultPalette(), theme: (src || sys || {}).theme, full: src ? pdlClone(src.full) : {}, base: src ? pdlClone(src.base) : pdlBaseNew() };
258
+ t.customs.push(c); t.active = c.id; pdlThemeGo(t);
259
+ };
260
+ /* 自定义主题:改名(只有自定义主题能改名)、删除(能撤回:回到列表里原来的位置,正在用的话再用回它) */
261
+ ENT.theme = {
262
+ coll: function () { return pdlThemes().customs; }, inlineEdit: 'theme', title: function () { return tc('common.rename'); },
263
+ rename: function (c, v) { const t = pdlThemes(), x = t.customs.find(function (y) { return y.id === c.id; }); if (x) { x.name = pdlUniqueName(t, v, x.id); pdlThemesSave(t); } },
264
+ undo: true, undoText: function (op, c) { return tc('pdlDoc.themeDropped', c.name); },
265
+ remove: function (c) {
266
+ const t = pdlThemes(), i = t.customs.findIndex(function (x) { return x.id === c.id; }), was = t.active;
267
+ t.customs.splice(i, 1);
268
+ if (t.active === c.id) t.active = PDL_SYS_THEMES[0].id;
269
+ pdlThemesSave(t); pdlThemeSync();
270
+ return function () { const t2 = pdlThemes(); t2.customs.splice(Math.min(i, t2.customs.length), 0, c); t2.active = was; pdlThemesSave(t2); pdlThemeSync(); };
271
+ }
272
+ };
273
+ ENT.themePack = { /* 卸载主题包(后端删它的目录):正在用它就回到系统主题 1 */
274
+ coll: function () { return PACK_LIST; },
275
+ remove: function (p) {
276
+ return THEME_PACKS.remove(p.id).then(function () {
277
+ const t = pdlThemes(), on = pdlActivePack(t) === p.id;
278
+ PACK_LIST = PACK_LIST.filter(function (x) { return x.id !== p.id; });
279
+ if (on) { t.active = PDL_SYS_THEMES[0].id; pdlThemeGo(t); } else render(true);
280
+ });
281
+ }
282
+ };
283
+ /* ───────── 导入 / 导出─────────
284
+ 自定义主题的 theme.yaml:身份字段(id、name、version、contractVersion;extends 是它基于的主题)+ pdl 段
285
+ (palette、skin、doc(完整的主题文档:摆放 / 结构、配色的值、背景、样式)、base(基线快照,升级用))。用户背景和个人照片不属于主题 */
286
+ /* 用户对插件节点的调整(摆放、顺序、隐藏)按 plugin:<插件>/<节点> 记,读的时候插件在才生效;导出的主题包不带它们 */
287
+ function pdlDropPluginRefs(doc) {
288
+ const strip = function (x) {
289
+ if (!x || typeof x !== 'object') return;
290
+ if (Array.isArray(x)) { for (let i = x.length - 1; i >= 0; i--) { if (x[i] && /^plugin:/.test(x[i].ref || '')) x.splice(i, 1); else strip(x[i]); } return; }
291
+ Object.keys(x).forEach(function (k) { strip(x[k]); });
292
+ };
293
+ strip(doc);
294
+ }
295
+ function pdlThemePack(id) {
296
+ const t = pdlThemes(), c = t.customs.find(function (x) { return x.id === id; }), ro = c ? null : pdlSysTheme(id) || PDL_SYS_THEMES[0];
297
+ const doc = c ? pdlClone(c.full) : {};
298
+ pdlDropPluginRefs(doc);
299
+ return { id: c ? c.id : ro.id, name: c ? c.name : pdlRoName(ro), version: '1', contractVersion: PDL_THEME.contractVersion, extends: (c || ro).theme || PDL_THEME.id,
300
+ pdl: { palette: c ? c.palette : ro.palette, skin: c ? c.skin : ro.skin, doc: doc, base: c ? pdlClone(c.base) : pdlBaseNew() } };
301
+ }
302
+ /* 导出(文件落到下载文件夹,保留提示;最近一次记在 S.lastExport):装好的主题包由后端把目录打回 zip;系统主题、自定义主题导出成自定义主题的 zip */
303
+ A.pdlThemeExport = function (d) {
304
+ const ro = pdlSysTheme(d.id);
305
+ if (ro && ro.theme) return Promise.resolve(THEME_PACKS.export(ro.theme)).then(function (name) { toast(tc('pdlDoc.exported', name)); });
306
+ const pack = pdlThemePack(d.id); S.lastExport = { pack: pack };
307
+ return Promise.resolve(THEME_PACKS.exportCustom(pack)).then(function (name) { S.lastExport.name = name; toast(tc('pdlDoc.exported', name)); });
308
+ };
309
+ /* 导入(一个入口):zip 交给后端。主题包:后端存好,列表多一行(正在用的包换了新版就重新载入);自定义主题(pdl.doc:文档 + 基线快照,extends 是它基于的包):
310
+ 后端解开交回,校验后加成一份自定义主题。校验不过:对话框留着,显示错误 */
311
+ function pdlThemePackWhy(o) {
312
+ const x = o && typeof o === 'object' && o.pdl;
313
+ if (!x || typeof x !== 'object' || typeof x.doc !== 'object' || x.doc.place || !x.base || typeof x.base !== 'object' || !x.palette) return tc('pdlDoc.importIncomplete');
314
+ const big = pdlLimitWhy(x.doc); if (big) return tc('pdlDoc.importTooLarge.' + big); /* 上限只在这里校验一次 */
315
+ return '';
316
+ }
317
+ function pdlThemeAdd(o) {
318
+ const t = pdlThemes();
319
+ const base = PACK_LIST.some(function (p) { return p.id === o.extends; }) ? o.extends : undefined;
320
+ const c = { id: 'c' + Date.now(), name: pdlUniqueName(t, o.name ? String(o.name) : pdlRoName(PDL_SYS_THEMES[0])), skin: o.pdl.skin || 'default', palette: o.pdl.palette, theme: base,
321
+ full: pdlReadThemeNames(pdlClone(o.pdl.doc)), base: pdlReadThemeNames(pdlClone(o.pdl.base)) };
322
+ t.customs.push(c); pdlThemesSave(t); return c;
323
+ }
324
+ A.pdlThemeImport = function () {
325
+ dialog({ title: tc('pdlDoc.importTitle'), fields: [{ id: 'theme-file', label: tc('pdlDoc.importFile'), file: { accept: '.zip' } }], ok: tc('common.import'), on: function () {
326
+ const el = document.getElementById('theme-file'), f = el && el.files && el.files[0];
327
+ if (!f) return Promise.resolve({ error: tc('pdlDoc.importNoFile') });
328
+ return THEME_PACKS.install(f).then(function (r) {
329
+ if (r.custom) { const why = pdlThemePackWhy(r.custom); if (why) return { error: why }; pdlThemeAdd(r.custom); return; }
330
+ return THEME_PACKS.list().then(function (list) { PACK_LIST = list; if (PACK_LOADED === r.id) location.reload(); else render(true); });
331
+ }, function () { return { error: tc('pdlDoc.importBad') }; });
332
+ } });
333
+ };
334
+ /* 恢复默认 = 切回系统主题 1(自定义主题留在列表里) */
335
+ onStart('doc', pdlDocBoot);
336
+
337
+ /* 存档的布局:选中就用当前基线重新合并一次;成功就成为当前布局,仍失败就留在列表里并标出原因 */
338
+ A.pdlArchiveApply = function (d) {
339
+ const arch = pdlArchive(), i = arch.findIndex(function (a) { return a.key === d.k; }); if (i < 0) return;
340
+ try {
341
+ const up = pdlUpgrade(arch[i]);
342
+ const t = pdlThemes(), c = { id: 'c' + Date.now(), name: pdlUniqueName(t, arch[i].name || pdlRoName(PDL_SYS_THEMES[0])), skin: 'default', full: up.full, base: up.base };
343
+ t.customs.push(c); t.active = c.id; pdlThemesSave(t); pdlThemeSync();
344
+ arch.splice(i, 1); store.set('pdl-archive-v1', arch); S.pdlUpgradeFailed = null;
345
+ } catch (e) { arch[i].error = String(e && e.message || e); arch[i].tried = true; store.set('pdl-archive-v1', arch); } /* 合并成功:这一行消失、布局已变;仍失败:原因写在这一行上 */
346
+ render(true);
347
+ };
348
+ ENT.archive = { coll: function () { return pdlArchive(); }, get: function (k) { return pdlArchive().find(function (a) { return a.key === k; }); }, remove: function (x) { store.set('pdl-archive-v1', pdlArchive().filter(function (a) { return a.key !== x.key; })); } };
349
+ /* 升级结果的提示(不打断操作):主题文档升级完(doc 阶段,可能等异步读)之后、画第一屏时说一次 */
350
+ onStart('boot', function () {
351
+ if (S.pdlUpgradeFailed) toast(tc('pdlDoc.upgradeFailed'), { label: tc('pdlDoc.upgradeFailedGo'), act: 'open', data: argAttrs({ page: 'appearance' }) });
352
+ else if (S.pdlUpgrade && S.pdlUpgrade.dropped) toast(tc('pdlDoc.upgraded', S.pdlUpgrade.dropped));
353
+ });