@skillcdn/console 0.4.7 → 0.5.1

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 (599) hide show
  1. package/README.md +74 -14
  2. package/SKILLCDN.md +5 -3
  3. package/dist/agent-page.d.ts +44 -0
  4. package/dist/agent-page.d.ts.map +1 -0
  5. package/dist/agent-page.js +415 -0
  6. package/dist/agent-page.js.map +1 -0
  7. package/dist/agent-stream.d.ts +52 -0
  8. package/dist/agent-stream.d.ts.map +1 -0
  9. package/dist/agent-stream.js +155 -0
  10. package/dist/agent-stream.js.map +1 -0
  11. package/dist/api.d.ts +12 -6
  12. package/dist/api.d.ts.map +1 -1
  13. package/dist/api.js +11 -5
  14. package/dist/api.js.map +1 -1
  15. package/dist/avatar.d.ts +137 -0
  16. package/dist/avatar.d.ts.map +1 -0
  17. package/dist/avatar.js +1216 -0
  18. package/dist/avatar.js.map +1 -0
  19. package/dist/charts.d.ts +103 -0
  20. package/dist/charts.d.ts.map +1 -0
  21. package/dist/charts.js +182 -0
  22. package/dist/charts.js.map +1 -0
  23. package/dist/cli/cli.d.ts +39 -1
  24. package/dist/cli/cli.d.ts.map +1 -1
  25. package/dist/cli/cli.js +2424 -296
  26. package/dist/cli/cli.js.map +1 -1
  27. package/dist/cli/command-words.d.ts +20 -0
  28. package/dist/cli/command-words.d.ts.map +1 -0
  29. package/dist/cli/command-words.js +51 -0
  30. package/dist/cli/command-words.js.map +1 -0
  31. package/dist/cli/credentials.d.ts +59 -5
  32. package/dist/cli/credentials.d.ts.map +1 -1
  33. package/dist/cli/credentials.js +128 -16
  34. package/dist/cli/credentials.js.map +1 -1
  35. package/dist/cli/directory.d.ts +19 -4
  36. package/dist/cli/directory.d.ts.map +1 -1
  37. package/dist/cli/directory.js +16 -8
  38. package/dist/cli/directory.js.map +1 -1
  39. package/dist/cli/format.d.ts +91 -8
  40. package/dist/cli/format.d.ts.map +1 -1
  41. package/dist/cli/format.js +386 -57
  42. package/dist/cli/format.js.map +1 -1
  43. package/dist/cli/help.d.ts +13 -4
  44. package/dist/cli/help.d.ts.map +1 -1
  45. package/dist/cli/help.js +202 -62
  46. package/dist/cli/help.js.map +1 -1
  47. package/dist/cli/main.js +94 -0
  48. package/dist/cli/main.js.map +1 -1
  49. package/dist/cli/pack.d.ts +69 -36
  50. package/dist/cli/pack.d.ts.map +1 -1
  51. package/dist/cli/pack.js +241 -188
  52. package/dist/cli/pack.js.map +1 -1
  53. package/dist/cli/plugin-check.d.ts +42 -0
  54. package/dist/cli/plugin-check.d.ts.map +1 -1
  55. package/dist/cli/plugin-check.js +221 -36
  56. package/dist/cli/plugin-check.js.map +1 -1
  57. package/dist/cli/plugin-cli.d.ts +6 -1
  58. package/dist/cli/plugin-cli.d.ts.map +1 -1
  59. package/dist/cli/plugin-cli.js +21 -4
  60. package/dist/cli/plugin-cli.js.map +1 -1
  61. package/dist/cli/plugin-main.js +1 -0
  62. package/dist/cli/plugin-main.js.map +1 -1
  63. package/dist/cli/runner-host.d.ts +36 -0
  64. package/dist/cli/runner-host.d.ts.map +1 -0
  65. package/dist/cli/runner-host.js +154 -0
  66. package/dist/cli/runner-host.js.map +1 -0
  67. package/dist/cli/serve.d.ts +33 -1
  68. package/dist/cli/serve.d.ts.map +1 -1
  69. package/dist/cli/serve.js +275 -6
  70. package/dist/cli/serve.js.map +1 -1
  71. package/dist/cli/setup-machine.d.ts +36 -0
  72. package/dist/cli/setup-machine.d.ts.map +1 -0
  73. package/dist/cli/setup-machine.js +109 -0
  74. package/dist/cli/setup-machine.js.map +1 -0
  75. package/dist/client.d.ts +189 -10
  76. package/dist/client.d.ts.map +1 -1
  77. package/dist/client.js +192 -57
  78. package/dist/client.js.map +1 -1
  79. package/dist/compat.d.ts +1 -1
  80. package/dist/compat.js +2 -2
  81. package/dist/components/agent-page.d.ts +384 -0
  82. package/dist/components/agent-page.d.ts.map +1 -0
  83. package/dist/components/agent-page.js +985 -0
  84. package/dist/components/agent-page.js.map +1 -0
  85. package/dist/components/agents.d.ts +102 -0
  86. package/dist/components/agents.d.ts.map +1 -0
  87. package/dist/components/agents.js +246 -0
  88. package/dist/components/agents.js.map +1 -0
  89. package/dist/components/calendar.d.ts +17 -17
  90. package/dist/components/calendar.d.ts.map +1 -1
  91. package/dist/components/calendar.js +7 -2
  92. package/dist/components/calendar.js.map +1 -1
  93. package/dist/components/charts.d.ts +157 -0
  94. package/dist/components/charts.d.ts.map +1 -0
  95. package/dist/components/charts.js +182 -0
  96. package/dist/components/charts.js.map +1 -0
  97. package/dist/components/comments.d.ts +2 -0
  98. package/dist/components/comments.d.ts.map +1 -1
  99. package/dist/components/comments.js +1 -1
  100. package/dist/components/comments.js.map +1 -1
  101. package/dist/components/connect.d.ts.map +1 -1
  102. package/dist/components/connect.js +7 -2
  103. package/dist/components/connect.js.map +1 -1
  104. package/dist/components/decision-form.d.ts +21 -0
  105. package/dist/components/decision-form.d.ts.map +1 -1
  106. package/dist/components/decision-form.js +20 -6
  107. package/dist/components/decision-form.js.map +1 -1
  108. package/dist/components/decision-list.d.ts +24 -0
  109. package/dist/components/decision-list.d.ts.map +1 -1
  110. package/dist/components/decision-list.js +54 -5
  111. package/dist/components/decision-list.js.map +1 -1
  112. package/dist/components/desk-records.d.ts +102 -0
  113. package/dist/components/desk-records.d.ts.map +1 -0
  114. package/dist/components/desk-records.js +221 -0
  115. package/dist/components/desk-records.js.map +1 -0
  116. package/dist/components/desk.d.ts +85 -0
  117. package/dist/components/desk.d.ts.map +1 -0
  118. package/dist/components/desk.js +135 -0
  119. package/dist/components/desk.js.map +1 -0
  120. package/dist/components/event-feed.d.ts.map +1 -1
  121. package/dist/components/event-feed.js +26 -1
  122. package/dist/components/event-feed.js.map +1 -1
  123. package/dist/components/home.d.ts +12 -1
  124. package/dist/components/home.d.ts.map +1 -1
  125. package/dist/components/home.js +175 -16
  126. package/dist/components/home.js.map +1 -1
  127. package/dist/components/my-decisions.d.ts +5 -0
  128. package/dist/components/my-decisions.d.ts.map +1 -1
  129. package/dist/components/my-decisions.js +3 -3
  130. package/dist/components/my-decisions.js.map +1 -1
  131. package/dist/components/people.d.ts +17 -0
  132. package/dist/components/people.d.ts.map +1 -1
  133. package/dist/components/people.js +55 -19
  134. package/dist/components/people.js.map +1 -1
  135. package/dist/components/picker.d.ts +2 -0
  136. package/dist/components/picker.d.ts.map +1 -1
  137. package/dist/components/picker.js +1 -1
  138. package/dist/components/picker.js.map +1 -1
  139. package/dist/components/pictures.d.ts +38 -10
  140. package/dist/components/pictures.d.ts.map +1 -1
  141. package/dist/components/pictures.js +195 -40
  142. package/dist/components/pictures.js.map +1 -1
  143. package/dist/components/plugin-events.d.ts +29 -0
  144. package/dist/components/plugin-events.d.ts.map +1 -0
  145. package/dist/components/plugin-events.js +139 -0
  146. package/dist/components/plugin-events.js.map +1 -0
  147. package/dist/components/plugin-frame.d.ts.map +1 -1
  148. package/dist/components/plugin-frame.js +14 -37
  149. package/dist/components/plugin-frame.js.map +1 -1
  150. package/dist/components/plugin-settings.d.ts.map +1 -1
  151. package/dist/components/plugin-settings.js +58 -7
  152. package/dist/components/plugin-settings.js.map +1 -1
  153. package/dist/components/projects.d.ts.map +1 -1
  154. package/dist/components/projects.js +30 -10
  155. package/dist/components/projects.js.map +1 -1
  156. package/dist/components/rules.d.ts +8 -10
  157. package/dist/components/rules.d.ts.map +1 -1
  158. package/dist/components/rules.js +36 -14
  159. package/dist/components/rules.js.map +1 -1
  160. package/dist/components/sessions.d.ts.map +1 -1
  161. package/dist/components/sessions.js +8 -4
  162. package/dist/components/sessions.js.map +1 -1
  163. package/dist/components/setup.d.ts +59 -0
  164. package/dist/components/setup.d.ts.map +1 -0
  165. package/dist/components/setup.js +93 -0
  166. package/dist/components/setup.js.map +1 -0
  167. package/dist/components/sign-in.js +1 -1
  168. package/dist/components/sign-in.js.map +1 -1
  169. package/dist/components/task-form.d.ts.map +1 -1
  170. package/dist/components/task-form.js +2 -2
  171. package/dist/components/task-form.js.map +1 -1
  172. package/dist/components/task-list.d.ts +7 -6
  173. package/dist/components/task-list.d.ts.map +1 -1
  174. package/dist/components/task-list.js.map +1 -1
  175. package/dist/components/task-view.d.ts +3 -0
  176. package/dist/components/task-view.d.ts.map +1 -1
  177. package/dist/components/task-view.js +1 -1
  178. package/dist/components/task-view.js.map +1 -1
  179. package/dist/components/ui.d.ts +78 -8
  180. package/dist/components/ui.d.ts.map +1 -1
  181. package/dist/components/ui.js +88 -9
  182. package/dist/components/ui.js.map +1 -1
  183. package/dist/components/work.d.ts +5 -5
  184. package/dist/components/work.d.ts.map +1 -1
  185. package/dist/components/work.js.map +1 -1
  186. package/dist/components/workspace.d.ts +17 -0
  187. package/dist/components/workspace.d.ts.map +1 -1
  188. package/dist/components/workspace.js +129 -2
  189. package/dist/components/workspace.js.map +1 -1
  190. package/dist/connect-page.d.ts.map +1 -1
  191. package/dist/connect-page.js +5 -2
  192. package/dist/connect-page.js.map +1 -1
  193. package/dist/console.css +7551 -4580
  194. package/dist/console.d.ts +20 -0
  195. package/dist/console.d.ts.map +1 -1
  196. package/dist/console.js +331 -57
  197. package/dist/console.js.map +1 -1
  198. package/dist/data.d.ts +22 -1
  199. package/dist/data.d.ts.map +1 -1
  200. package/dist/data.js +62 -34
  201. package/dist/data.js.map +1 -1
  202. package/dist/desk-page.d.ts +38 -0
  203. package/dist/desk-page.d.ts.map +1 -0
  204. package/dist/desk-page.js +184 -0
  205. package/dist/desk-page.js.map +1 -0
  206. package/dist/desk-records-page.d.ts +18 -0
  207. package/dist/desk-records-page.d.ts.map +1 -0
  208. package/dist/desk-records-page.js +130 -0
  209. package/dist/desk-records-page.js.map +1 -0
  210. package/dist/desk-records.d.ts +247 -0
  211. package/dist/desk-records.d.ts.map +1 -0
  212. package/dist/desk-records.js +543 -0
  213. package/dist/desk-records.js.map +1 -0
  214. package/dist/desk.d.ts +122 -0
  215. package/dist/desk.d.ts.map +1 -0
  216. package/dist/desk.js +211 -0
  217. package/dist/desk.js.map +1 -0
  218. package/dist/feed-stream.d.ts +39 -0
  219. package/dist/feed-stream.d.ts.map +1 -0
  220. package/dist/feed-stream.js +117 -0
  221. package/dist/feed-stream.js.map +1 -0
  222. package/dist/glances.d.ts +39 -0
  223. package/dist/glances.d.ts.map +1 -0
  224. package/dist/glances.js +94 -0
  225. package/dist/glances.js.map +1 -0
  226. package/dist/home-tiles.d.ts +69 -5
  227. package/dist/home-tiles.d.ts.map +1 -1
  228. package/dist/home-tiles.js +347 -9
  229. package/dist/home-tiles.js.map +1 -1
  230. package/dist/i18n/en.d.ts +773 -3
  231. package/dist/i18n/en.d.ts.map +1 -1
  232. package/dist/i18n/en.js +770 -9
  233. package/dist/i18n/en.js.map +1 -1
  234. package/dist/i18n/ko.d.ts.map +1 -1
  235. package/dist/i18n/ko.js +736 -9
  236. package/dist/i18n/ko.js.map +1 -1
  237. package/dist/index.d.ts +19 -7
  238. package/dist/index.d.ts.map +1 -1
  239. package/dist/index.js +17 -5
  240. package/dist/index.js.map +1 -1
  241. package/dist/limits.d.ts +67 -0
  242. package/dist/limits.d.ts.map +1 -1
  243. package/dist/limits.js +67 -0
  244. package/dist/limits.js.map +1 -1
  245. package/dist/onboarding.d.ts +21 -0
  246. package/dist/onboarding.d.ts.map +1 -0
  247. package/dist/onboarding.js +43 -0
  248. package/dist/onboarding.js.map +1 -0
  249. package/dist/persona.d.ts +34 -0
  250. package/dist/persona.d.ts.map +1 -0
  251. package/dist/persona.js +71 -0
  252. package/dist/persona.js.map +1 -0
  253. package/dist/plugin/context.d.ts +42 -11
  254. package/dist/plugin/context.d.ts.map +1 -1
  255. package/dist/plugin/limits.d.ts +2 -0
  256. package/dist/plugin/limits.d.ts.map +1 -1
  257. package/dist/plugin/limits.js +2 -0
  258. package/dist/plugin/limits.js.map +1 -1
  259. package/dist/plugin/manifest.d.ts +13 -0
  260. package/dist/plugin/manifest.d.ts.map +1 -1
  261. package/dist/plugin/manifest.js +34 -4
  262. package/dist/plugin/manifest.js.map +1 -1
  263. package/dist/plugin/rest-schemas.d.ts +56 -0
  264. package/dist/plugin/rest-schemas.d.ts.map +1 -1
  265. package/dist/plugin/rest-schemas.js +42 -0
  266. package/dist/plugin/rest-schemas.js.map +1 -1
  267. package/dist/plugin/sandbox.d.ts.map +1 -1
  268. package/dist/plugin/sandbox.js +4 -1
  269. package/dist/plugin/sandbox.js.map +1 -1
  270. package/dist/plugin/testing.d.ts +6 -2
  271. package/dist/plugin/testing.d.ts.map +1 -1
  272. package/dist/plugin/testing.js +52 -10
  273. package/dist/plugin/testing.js.map +1 -1
  274. package/dist/plugin.d.ts +1 -1
  275. package/dist/plugin.d.ts.map +1 -1
  276. package/dist/plugin.js +1 -1
  277. package/dist/plugin.js.map +1 -1
  278. package/dist/records.d.ts +283 -0
  279. package/dist/records.d.ts.map +1 -0
  280. package/dist/records.js +543 -0
  281. package/dist/records.js.map +1 -0
  282. package/dist/router.d.ts +50 -3
  283. package/dist/router.d.ts.map +1 -1
  284. package/dist/router.js +78 -7
  285. package/dist/router.js.map +1 -1
  286. package/dist/routes.d.ts +12 -2
  287. package/dist/routes.d.ts.map +1 -1
  288. package/dist/routes.js +14 -1
  289. package/dist/routes.js.map +1 -1
  290. package/dist/rules.d.ts +30 -11
  291. package/dist/rules.d.ts.map +1 -1
  292. package/dist/rules.js +99 -42
  293. package/dist/rules.js.map +1 -1
  294. package/dist/runner/acp.d.ts +20 -0
  295. package/dist/runner/acp.d.ts.map +1 -0
  296. package/dist/runner/acp.js +1132 -0
  297. package/dist/runner/acp.js.map +1 -0
  298. package/dist/runner/claude.d.ts +13 -0
  299. package/dist/runner/claude.d.ts.map +1 -0
  300. package/dist/runner/claude.js +615 -0
  301. package/dist/runner/claude.js.map +1 -0
  302. package/dist/runner/codex.d.ts +19 -0
  303. package/dist/runner/codex.d.ts.map +1 -0
  304. package/dist/runner/codex.js +597 -0
  305. package/dist/runner/codex.js.map +1 -0
  306. package/dist/runner/config.d.ts +35 -0
  307. package/dist/runner/config.d.ts.map +1 -0
  308. package/dist/runner/config.js +74 -0
  309. package/dist/runner/config.js.map +1 -0
  310. package/dist/runner/desk.d.ts +81 -0
  311. package/dist/runner/desk.d.ts.map +1 -0
  312. package/dist/runner/desk.js +303 -0
  313. package/dist/runner/desk.js.map +1 -0
  314. package/dist/runner/launchd.d.ts +7 -0
  315. package/dist/runner/launchd.d.ts.map +1 -0
  316. package/dist/runner/launchd.js +78 -0
  317. package/dist/runner/launchd.js.map +1 -0
  318. package/dist/runner/message.d.ts +66 -0
  319. package/dist/runner/message.d.ts.map +1 -0
  320. package/dist/runner/message.js +181 -0
  321. package/dist/runner/message.js.map +1 -0
  322. package/dist/runner/modules.d.ts +13 -0
  323. package/dist/runner/modules.d.ts.map +1 -0
  324. package/dist/runner/modules.js +30 -0
  325. package/dist/runner/modules.js.map +1 -0
  326. package/dist/runner/process.d.ts +7 -0
  327. package/dist/runner/process.d.ts.map +1 -0
  328. package/dist/runner/process.js +65 -0
  329. package/dist/runner/process.js.map +1 -0
  330. package/dist/runner/redact.d.ts +48 -0
  331. package/dist/runner/redact.d.ts.map +1 -0
  332. package/dist/runner/redact.js +214 -0
  333. package/dist/runner/redact.js.map +1 -0
  334. package/dist/runner/registry.d.ts +37 -0
  335. package/dist/runner/registry.d.ts.map +1 -0
  336. package/dist/runner/registry.js +26 -0
  337. package/dist/runner/registry.js.map +1 -0
  338. package/dist/runner/runner.d.ts +130 -0
  339. package/dist/runner/runner.d.ts.map +1 -0
  340. package/dist/runner/runner.js +1551 -0
  341. package/dist/runner/runner.js.map +1 -0
  342. package/dist/runner/slack.d.ts +16 -0
  343. package/dist/runner/slack.d.ts.map +1 -0
  344. package/dist/runner/slack.js +157 -0
  345. package/dist/runner/slack.js.map +1 -0
  346. package/dist/runner/systemd-user.d.ts +7 -0
  347. package/dist/runner/systemd-user.d.ts.map +1 -0
  348. package/dist/runner/systemd-user.js +93 -0
  349. package/dist/runner/systemd-user.js.map +1 -0
  350. package/dist/runner/task-scheduler.d.ts +38 -0
  351. package/dist/runner/task-scheduler.d.ts.map +1 -0
  352. package/dist/runner/task-scheduler.js +216 -0
  353. package/dist/runner/task-scheduler.js.map +1 -0
  354. package/dist/runner/types.d.ts +315 -0
  355. package/dist/runner/types.d.ts.map +1 -0
  356. package/dist/runner/types.js +24 -0
  357. package/dist/runner/types.js.map +1 -0
  358. package/dist/runner.d.ts +18 -0
  359. package/dist/runner.d.ts.map +1 -0
  360. package/dist/runner.js +20 -0
  361. package/dist/runner.js.map +1 -0
  362. package/dist/schemas.d.ts +6082 -1295
  363. package/dist/schemas.d.ts.map +1 -1
  364. package/dist/schemas.js +930 -31
  365. package/dist/schemas.js.map +1 -1
  366. package/dist/services.d.ts +110 -0
  367. package/dist/services.d.ts.map +1 -0
  368. package/dist/services.js +305 -0
  369. package/dist/services.js.map +1 -0
  370. package/dist/setup-guide.d.ts +64 -0
  371. package/dist/setup-guide.d.ts.map +1 -0
  372. package/dist/setup-guide.js +256 -0
  373. package/dist/setup-guide.js.map +1 -0
  374. package/dist/setup-page.d.ts +6 -0
  375. package/dist/setup-page.d.ts.map +1 -0
  376. package/dist/setup-page.js +29 -0
  377. package/dist/setup-page.js.map +1 -0
  378. package/dist/sse.d.ts +15 -0
  379. package/dist/sse.d.ts.map +1 -0
  380. package/dist/sse.js +73 -0
  381. package/dist/sse.js.map +1 -0
  382. package/dist/tab-title.d.ts +6 -0
  383. package/dist/tab-title.d.ts.map +1 -0
  384. package/dist/tab-title.js +22 -0
  385. package/dist/tab-title.js.map +1 -0
  386. package/dist/tokens.d.ts.map +1 -1
  387. package/dist/tokens.js +3 -0
  388. package/dist/tokens.js.map +1 -1
  389. package/dist/use-action.d.ts +5 -2
  390. package/dist/use-action.d.ts.map +1 -1
  391. package/dist/use-action.js +6 -1
  392. package/dist/use-action.js.map +1 -1
  393. package/dist/vocabulary.d.ts +84 -4
  394. package/dist/vocabulary.d.ts.map +1 -1
  395. package/dist/vocabulary.js +115 -3
  396. package/dist/vocabulary.js.map +1 -1
  397. package/docs/specs/cli.md +147 -41
  398. package/docs/specs/plugins.md +37 -27
  399. package/docs/specs/records.md +113 -0
  400. package/docs/specs/rest.md +155 -20
  401. package/docs/specs/runner.md +347 -0
  402. package/package.json +12 -3
  403. package/skills/building-a-console/SKILL.md +4 -4
  404. package/skills/building-a-console/references/configuring.md +1 -0
  405. package/skills/building-a-plugin/SKILL.md +7 -7
  406. package/skills/deploying-a-console/SKILL.md +4 -4
  407. package/skills/deploying-a-console/references/resources.md +48 -8
  408. package/skills/deploying-a-console/references/running-it-again.md +3 -2
  409. package/skills/keeping-a-desk/SKILL.md +133 -0
  410. package/skills/keeping-a-desk/collections.md +96 -0
  411. package/skills/planning-the-board/SKILL.md +14 -18
  412. package/skills/planning-the-board/references/a-task.md +2 -2
  413. package/skills/planning-the-board/references/project-rules.md +13 -14
  414. package/skills/planning-the-board/references/setting-up.md +22 -9
  415. package/skills/running-an-agent/SKILL.md +107 -0
  416. package/skills/running-an-agent/references/slack-app.md +61 -0
  417. package/skills/working-the-board/SKILL.md +66 -39
  418. package/skills/working-the-board/references/terms.md +9 -5
  419. package/skills/working-the-board/references/the-pack.md +14 -9
  420. package/skills/working-the-board/references/the-sentence.md +2 -2
  421. package/src/agent-page.tsx +1039 -0
  422. package/src/agent-stream.ts +199 -0
  423. package/src/api.ts +317 -2
  424. package/src/avatar.ts +1506 -0
  425. package/src/charts.ts +250 -0
  426. package/src/cli/cli.ts +3210 -503
  427. package/src/cli/command-words.ts +56 -0
  428. package/src/cli/credentials.ts +188 -16
  429. package/src/cli/directory.ts +28 -10
  430. package/src/cli/format.ts +470 -67
  431. package/src/cli/help.ts +233 -61
  432. package/src/cli/main.ts +89 -0
  433. package/src/cli/pack.ts +332 -263
  434. package/src/cli/plugin-check.ts +275 -34
  435. package/src/cli/plugin-cli.ts +28 -4
  436. package/src/cli/plugin-main.ts +1 -0
  437. package/src/cli/runner-host.ts +188 -0
  438. package/src/cli/serve.ts +320 -5
  439. package/src/cli/setup-machine.ts +153 -0
  440. package/src/client.ts +711 -126
  441. package/src/compat.ts +2 -2
  442. package/src/components/agent-page.tsx +1946 -0
  443. package/src/components/agents.tsx +638 -0
  444. package/src/components/calendar.tsx +74 -53
  445. package/src/components/charts.tsx +680 -0
  446. package/src/components/comments.tsx +3 -0
  447. package/src/components/connect.tsx +37 -2
  448. package/src/components/decision-form.tsx +89 -51
  449. package/src/components/decision-list.tsx +140 -4
  450. package/src/components/desk-records.tsx +724 -0
  451. package/src/components/desk.tsx +471 -0
  452. package/src/components/event-feed.tsx +30 -1
  453. package/src/components/home.tsx +353 -12
  454. package/src/components/my-decisions.tsx +8 -2
  455. package/src/components/people.tsx +300 -203
  456. package/src/components/picker.tsx +3 -1
  457. package/src/components/pictures.tsx +256 -44
  458. package/src/components/plugin-events.ts +159 -0
  459. package/src/components/plugin-frame.tsx +14 -38
  460. package/src/components/plugin-settings.tsx +178 -22
  461. package/src/components/projects.tsx +33 -15
  462. package/src/components/rules.tsx +96 -36
  463. package/src/components/sessions.tsx +7 -4
  464. package/src/components/setup.tsx +252 -0
  465. package/src/components/sign-in.tsx +1 -1
  466. package/src/components/task-form.tsx +11 -2
  467. package/src/components/task-list.tsx +7 -6
  468. package/src/components/task-view.tsx +4 -0
  469. package/src/components/ui.tsx +169 -25
  470. package/src/components/work.tsx +9 -9
  471. package/src/components/workspace.tsx +345 -4
  472. package/src/connect-page.tsx +15 -2
  473. package/src/console.tsx +657 -83
  474. package/src/data.ts +109 -43
  475. package/src/desk-page.tsx +332 -0
  476. package/src/desk-records-page.tsx +256 -0
  477. package/src/desk-records.ts +808 -0
  478. package/src/desk.ts +329 -0
  479. package/src/feed-stream.ts +144 -0
  480. package/src/glances.ts +132 -0
  481. package/src/home-tiles.ts +411 -9
  482. package/src/i18n/en.ts +828 -10
  483. package/src/i18n/ko.ts +792 -10
  484. package/src/index.ts +172 -3
  485. package/src/limits.ts +67 -0
  486. package/src/onboarding.ts +84 -0
  487. package/src/persona.ts +100 -0
  488. package/src/plugin/context.ts +55 -12
  489. package/src/plugin/limits.ts +2 -0
  490. package/src/plugin/manifest.ts +42 -3
  491. package/src/plugin/rest-schemas.ts +46 -0
  492. package/src/plugin/sandbox.ts +4 -1
  493. package/src/plugin/testing.ts +63 -12
  494. package/src/plugin.ts +2 -0
  495. package/src/records.ts +702 -0
  496. package/src/router.ts +120 -10
  497. package/src/routes.ts +17 -1
  498. package/src/rules.ts +109 -44
  499. package/src/runner/acp.ts +1267 -0
  500. package/src/runner/claude.ts +695 -0
  501. package/src/runner/codex.ts +691 -0
  502. package/src/runner/config.ts +97 -0
  503. package/src/runner/desk.ts +377 -0
  504. package/src/runner/launchd.ts +86 -0
  505. package/src/runner/message.ts +232 -0
  506. package/src/runner/modules.ts +30 -0
  507. package/src/runner/process.ts +72 -0
  508. package/src/runner/redact.ts +242 -0
  509. package/src/runner/registry.ts +67 -0
  510. package/src/runner/runner.ts +1879 -0
  511. package/src/runner/slack.ts +180 -0
  512. package/src/runner/systemd-user.ts +103 -0
  513. package/src/runner/task-scheduler.ts +236 -0
  514. package/src/runner/types.ts +334 -0
  515. package/src/runner.ts +110 -0
  516. package/src/schemas.ts +1183 -30
  517. package/src/services.ts +424 -0
  518. package/src/setup-guide.ts +336 -0
  519. package/src/setup-page.tsx +46 -0
  520. package/src/sse.ts +84 -0
  521. package/src/styles/README.md +111 -0
  522. package/src/styles/base.css +130 -0
  523. package/src/styles/console.css +85 -7095
  524. package/src/styles/drawn-by-pages.json +256 -0
  525. package/src/styles/pages/agents.css +1195 -0
  526. package/src/styles/pages/board.css +380 -0
  527. package/src/styles/pages/calendar.css +214 -0
  528. package/src/styles/pages/connect.css +182 -0
  529. package/src/styles/pages/decisions.css +370 -0
  530. package/src/styles/pages/desk.css +126 -0
  531. package/src/styles/pages/documents.css +273 -0
  532. package/src/styles/pages/feed.css +118 -0
  533. package/src/styles/pages/home.css +718 -0
  534. package/src/styles/pages/people.css +90 -0
  535. package/src/styles/pages/plugins.css +212 -0
  536. package/src/styles/pages/roadmap.css +377 -0
  537. package/src/styles/pages/settings.css +171 -0
  538. package/src/styles/pages/shell.css +208 -0
  539. package/src/styles/pages/sign-in.css +178 -0
  540. package/src/styles/pages/task.css +108 -0
  541. package/src/styles/pages/thread.css +331 -0
  542. package/src/styles/pages/work.css +68 -0
  543. package/src/styles/parts/avatar.css +82 -0
  544. package/src/styles/parts/badge.css +227 -0
  545. package/src/styles/parts/bars.css +80 -0
  546. package/src/styles/parts/button.css +99 -0
  547. package/src/styles/parts/calendar.css +547 -0
  548. package/src/styles/parts/callout.css +41 -0
  549. package/src/styles/parts/category.css +8 -0
  550. package/src/styles/parts/chart.css +173 -0
  551. package/src/styles/parts/chip.css +90 -0
  552. package/src/styles/parts/code.css +48 -0
  553. package/src/styles/parts/count.css +27 -0
  554. package/src/styles/parts/crumbs.css +61 -0
  555. package/src/styles/parts/detail.css +110 -0
  556. package/src/styles/parts/empty.css +21 -0
  557. package/src/styles/parts/eyebrow.css +9 -0
  558. package/src/styles/parts/facts.css +147 -0
  559. package/src/styles/parts/figures.css +65 -0
  560. package/src/styles/parts/files.css +38 -0
  561. package/src/styles/parts/filters.css +42 -0
  562. package/src/styles/parts/form.css +109 -0
  563. package/src/styles/parts/frame.css +45 -0
  564. package/src/styles/parts/input.css +243 -0
  565. package/src/styles/parts/legend.css +48 -0
  566. package/src/styles/parts/links.css +37 -0
  567. package/src/styles/parts/mark.css +79 -0
  568. package/src/styles/parts/menu.css +147 -0
  569. package/src/styles/parts/page.css +174 -0
  570. package/src/styles/parts/pager.css +19 -0
  571. package/src/styles/parts/panel.css +33 -0
  572. package/src/styles/parts/person.css +257 -0
  573. package/src/styles/parts/picker.css +185 -0
  574. package/src/styles/parts/progress.css +25 -0
  575. package/src/styles/parts/prose.css +128 -0
  576. package/src/styles/parts/rows.css +63 -0
  577. package/src/styles/parts/series.css +32 -0
  578. package/src/styles/parts/settings.css +101 -0
  579. package/src/styles/parts/share.css +25 -0
  580. package/src/styles/parts/spark.css +23 -0
  581. package/src/styles/parts/spinner.css +29 -0
  582. package/src/styles/parts/stat.css +69 -0
  583. package/src/styles/parts/steps.css +68 -0
  584. package/src/styles/parts/tabs.css +175 -0
  585. package/src/styles/parts/text.css +61 -0
  586. package/src/styles/parts/toggle.css +71 -0
  587. package/src/styles/parts/workers.css +37 -0
  588. package/src/styles/tokens.css +295 -0
  589. package/src/tab-title.ts +25 -0
  590. package/src/tokens.ts +3 -0
  591. package/src/use-action.ts +7 -2
  592. package/src/vocabulary.ts +151 -3
  593. package/template/desk-web/README.md +8 -0
  594. package/template/desk-web/index.html +13 -0
  595. package/template/desk-web/package.json +25 -0
  596. package/template/desk-web/src/main.tsx +24 -0
  597. package/template/desk-web/src/page.tsx +51 -0
  598. package/template/desk-web/tsconfig.json +16 -0
  599. package/template/desk-web/vite.config.ts +15 -0
package/dist/avatar.js ADDED
@@ -0,0 +1,1216 @@
1
+ // An agent account's avatar (ADR-0084, ADR-0097, ADR-0102): a small planet, flat and of two tones.
2
+ // A body, what lies on its surface, the ramp of colours both are drawn in, and one thing beside
3
+ // it or nothing, on a graphite ground with a few faint squares strewn over it. Its parts are
4
+ // a few numbers, each a place in a set, and this module draws the picture from them wherever it
5
+ // is shown and writes it out as a picture file where one is needed. Nothing drawn is kept: a
6
+ // person object carries the parts, some seventy bytes, and whoever shows the picture draws it.
7
+ //
8
+ // A set is data: outlines in a square of a hundred units a side, each filled in two tones, the
9
+ // lighter left of a line down it and the darker right. The module fills them itself, by how much
10
+ // of each pixel an outline covers, with no renderer of anyone else's, in the browser and in the
11
+ // command alike, and the same parts give the same pixels on every machine: nothing here is
12
+ // computed with a function a runtime may round its own way (no sine of the runtime's, no
13
+ // exponential), only with sums, products and square roots. The sine a curve is laid out with is
14
+ // a series written here.
15
+ //
16
+ // A released set never changes: a new look is a new version, and an avatar keeps the version it
17
+ // was made with. What is added to this file is a set, never a change to one.
18
+ /** The side of the square a set's outlines are written in. */
19
+ export const AVATAR_BOX = 100;
20
+ /** The largest picture file the module writes, in pixels a side (ADR-0084). */
21
+ export const MAX_AVATAR_PIXELS = 1024;
22
+ /**
23
+ * Under this many pixels a side a picture has no squares on its ground: they would be specks. A
24
+ * page draws a picture at about twice the size it shows it, so this is a picture shown under 48
25
+ * pixels.
26
+ */
27
+ export const AVATAR_PLAIN_UNDER = 96;
28
+ /**
29
+ * Under this many pixels a side, a picture shown in a line of text or among a task's workers,
30
+ * the planet is drawn closer: as large as what stands beside it leaves room for, up to
31
+ * `AVATAR_CLOSE_MOST` times what its set writes, or what the set's own `fill` says where that is
32
+ * more (ADR-0099).
33
+ */
34
+ export const AVATAR_CLOSE_UNDER = 64;
35
+ export const AVATAR_CLOSE_MOST = 1.1;
36
+ /** The most a set may ask its planet to be drawn larger by. */
37
+ export const AVATAR_FILL_MOST = 1.5;
38
+ // Numbers
39
+ const clamp = (value, low = 0, high = 1) => Math.min(Math.max(value, low), high);
40
+ const length = (x, y) => Math.sqrt(x * x + y * y);
41
+ /** A number that is one, or nothing a drawing can use. */
42
+ const finite = (value) => typeof value === "number" && Number.isFinite(value);
43
+ /**
44
+ * The sine of an angle in degrees, by its series: sums and products alone, so that every machine
45
+ * lays a curve out through the same points. Good to the last place a number keeps.
46
+ */
47
+ function sine(degrees) {
48
+ let turn = degrees % 360;
49
+ if (turn > 180) {
50
+ turn -= 360;
51
+ }
52
+ else if (turn < -180) {
53
+ turn += 360;
54
+ }
55
+ // The sine of what is left of a half turn is the same: the series is asked of a quarter turn at most.
56
+ if (turn > 90) {
57
+ turn = 180 - turn;
58
+ }
59
+ else if (turn < -90) {
60
+ turn = -180 - turn;
61
+ }
62
+ const x = (turn * Math.PI) / 180;
63
+ const s = x * x;
64
+ let sum = 1;
65
+ for (let term = 20; term >= 2; term -= 2) {
66
+ sum = 1 - (s / (term * (term + 1))) * sum;
67
+ }
68
+ return x * sum;
69
+ }
70
+ const cosine = (degrees) => sine(degrees + 90);
71
+ // Colours
72
+ const BLACK = [0, 0, 0];
73
+ /** A colour written `#rrggbb` as its three numbers; black where it is not written so. */
74
+ function colorOf(hex) {
75
+ if (typeof hex !== "string" || !/^#[0-9a-fA-F]{6}$/.test(hex)) {
76
+ return BLACK;
77
+ }
78
+ const read = (at) => Number.parseInt(hex.slice(at, at + 2), 16);
79
+ return [read(1), read(3), read(5)];
80
+ }
81
+ // Outlines: what the first set is written with. Every one runs the same way round, so that
82
+ // outlines laid over one another add up to one shape; `hole` turns one the other way.
83
+ /** How many sides a curve of this radius is drawn with: enough that the largest picture shows none. */
84
+ function sidesOf(radius) {
85
+ return 4 * Math.ceil(clamp(radius * 4, 48, 192) / 4);
86
+ }
87
+ /** An oval by its middle and its two radii. */
88
+ function oval(cx, cy, rx, ry) {
89
+ const sides = sidesOf(Math.max(rx, ry));
90
+ const points = [];
91
+ for (let side = 0; side < sides; side += 1) {
92
+ const at = (360 * side) / sides;
93
+ points.push([cx + rx * cosine(at), cy + ry * sine(at)]);
94
+ }
95
+ return points;
96
+ }
97
+ const disc = (cx, cy, radius) => oval(cx, cy, radius, radius);
98
+ /** A rectangle by its top left and its sides, its corners rounded by `radius`, which is half a side at most. */
99
+ function slab(x, y, w, h, radius) {
100
+ const r = Math.min(radius, w / 2, h / 2);
101
+ const steps = sidesOf(r) / 4;
102
+ const points = [];
103
+ const corner = (cx, cy, from) => {
104
+ for (let step = 0; step <= steps; step += 1) {
105
+ const at = from + (90 * step) / steps;
106
+ points.push([cx + r * cosine(at), cy + r * sine(at)]);
107
+ }
108
+ };
109
+ corner(x + w - r, y + r, -90);
110
+ corner(x + w - r, y + h - r, 0);
111
+ corner(x + r, y + h - r, 90);
112
+ corner(x + r, y + r, 180);
113
+ return points;
114
+ }
115
+ /** An outline run the other way round: a hole in the outline it lies in. */
116
+ const hole = (outline) => [...outline].reverse();
117
+ /** A place written with two digits after the point, as the set was drawn. */
118
+ const two = (value) => Math.round(value * 100) / 100;
119
+ /**
120
+ * A band across the whole picture, from `top` down to `bottom`, each edge straight, a wave or a
121
+ * zigzag `length` long from crest to crest. An edge is a line through points a step apart, two
122
+ * units for a wave and half its length for a zigzag, as the set was drawn.
123
+ */
124
+ function band(top, bottom, upper = {}, lower = {}, wave = {}) {
125
+ const long = wave.length ?? 26;
126
+ const zigzag = wave.zigzag === true;
127
+ const lift = (x, shift) => {
128
+ const t = (x + shift) / long;
129
+ return zigzag ? 2 * Math.abs(2 * (t - Math.floor(t + 0.5))) - 1 : sine(360 * t);
130
+ };
131
+ const step = zigzag ? long / 2 : 2;
132
+ const points = [];
133
+ for (let x = -4; x <= 104; x += step) {
134
+ points.push([two(x), two(top + (upper.height ?? 0) * lift(x, upper.shift ?? 0))]);
135
+ }
136
+ for (let x = 104; x >= -4; x -= step) {
137
+ points.push([two(x), two(bottom + (lower.height ?? 0) * lift(x, lower.shift ?? 0))]);
138
+ }
139
+ return points;
140
+ }
141
+ /** A band that runs from the upper right to the lower left, between two lines `from` and `to` along the edges. */
142
+ const slant = (from, to) => [
143
+ [from + 10, -10],
144
+ [to + 10, -10],
145
+ [-10, to + 10],
146
+ [-10, from + 10],
147
+ ];
148
+ /** A star of four points, its sides drawn in towards its middle. */
149
+ function sparkle(x, y, size) {
150
+ const pull = size * 0.16;
151
+ const tips = [
152
+ [x, y - size],
153
+ [x + size, y],
154
+ [x, y + size],
155
+ [x - size, y],
156
+ ];
157
+ const pulls = [
158
+ [x + pull, y - pull],
159
+ [x + pull, y + pull],
160
+ [x - pull, y + pull],
161
+ [x - pull, y - pull],
162
+ ];
163
+ const steps = 16;
164
+ const points = [];
165
+ for (let side = 0; side < 4; side += 1) {
166
+ const from = tips[side] ?? [x, y];
167
+ const by = pulls[side] ?? [x, y];
168
+ const to = tips[(side + 1) % 4] ?? [x, y];
169
+ for (let step = 0; step < steps; step += 1) {
170
+ const t = step / steps;
171
+ const a = (1 - t) * (1 - t);
172
+ const b = 2 * (1 - t) * t;
173
+ const c = t * t;
174
+ points.push([a * from[0] + b * by[0] + c * to[0], a * from[1] + b * by[1] + c * to[1]]);
175
+ }
176
+ }
177
+ return points;
178
+ }
179
+ // The first set
180
+ const ramp = (tones, partner) => ({ tones: tones.split(" "), partner });
181
+ const of = (outline, tone) => ({ outlines: [outline], tone });
182
+ /** The rim of the lumpy body: where each bump sits, in degrees round the middle, and its radius. */
183
+ const BUMPS = [
184
+ [-78, 5.2],
185
+ [-30, 4.4],
186
+ [12, 5],
187
+ [58, 4.2],
188
+ [104, 5.4],
189
+ [150, 4.6],
190
+ [196, 5],
191
+ [240, 4.2],
192
+ ];
193
+ /** A ring: an oval with an oval cut out of it. */
194
+ const RING = [oval(50, 50, 40, 11), hole(oval(50, 50, 32, 8))];
195
+ /** The line of an orbit: an oval with one a little smaller cut out of it. */
196
+ const ORBIT = [oval(50, 50, 42.4, 13.4), hole(oval(50, 50, 39.6, 10.9))];
197
+ /** The white of a polar cap, and its shade. */
198
+ const ICE = ["#ffffff", "#ebe4f1"];
199
+ /**
200
+ * The first set: four bodies, ten surfaces and eighteen ramps of five tones, each with the ramp
201
+ * that goes with it, on one ground, with one of five things beside the body or none.
202
+ */
203
+ export const AVATAR_SET_1 = {
204
+ version: 1,
205
+ // The set is drawn with air round its planet; on a page a tile reads better a little fuller.
206
+ fill: 1.05,
207
+ // A graphite ground, calm and of no hue, so that no ramp sinks into it as a blue would into a
208
+ // blue; and squares three fifths of the way from it to the bright colours they once were, seen
209
+ // as stars at the half they are laid at, and never louder than the planet (ADR-0102).
210
+ grounds: ["#51525c"],
211
+ confetti: ["#b9a14d", "#b98a56", "#6d86be", "#6366b0", "#9d9cae", "#adaab5"],
212
+ ramps: [
213
+ // Sunset, butter, gold, peach, terracotta, rose.
214
+ ramp("#ffd643 #ffb052 #ff8a5b #ff3d5a #d6264a", 7),
215
+ ramp("#fff4d6 #ffe08a #ffc25c #ff9f4a #f07a3a", 9),
216
+ ramp("#fff0b3 #ffd95a #f5b82e #d6911b #a86a10", 10),
217
+ ramp("#ffe3d3 #ffc4a8 #ff9f80 #f2735a #d9533f", 13),
218
+ ramp("#ffd2b8 #ffa77a #ff8a5b #e8613f #c24e33", 12),
219
+ ramp("#ffd6e4 #ffb3c7 #ff8fb3 #ff5c8a #d6336c", 11),
220
+ // Berry, violet, lavender, indigo, denim, ocean. Denim stands a step lighter than a navy
221
+ // would, so that it does not sink into the graphite ground (ADR-0102).
222
+ ramp("#ffd0f0 #f59ad8 #e05fbf #b83a9e #8c2479", 1),
223
+ ramp("#eadcff #cdb0ff #a77cf5 #8556de #6638bd", 1),
224
+ ramp("#fff3f2 #ebe4f1 #d0cde4 #a4a7cc #8a8db8", 0),
225
+ ramp("#9cb8ff #6f8cf5 #4f5fe0 #3a3fb8 #2a2f99", 1),
226
+ ramp("#d3dcf5 #a9b8e6 #8296d2 #6479bd #4c60a3", 2),
227
+ ramp("#c7e2ff #9cc4ff #7fa8ff #6f74e8 #5257c9", 0),
228
+ // Aqua, teal, mint, leaf, stone, graphite.
229
+ ramp("#d8fbff #a6f0ff #5fd0f0 #2aa7d6 #1b7bb3", 5),
230
+ ramp("#bff5ec #7fe3d3 #3fc4b3 #1f9a8d #127066", 3),
231
+ ramp("#5ef0b8 #22e3a5 #1cb2b2 #137f80 #0e5f60", 0),
232
+ ramp("#d9f7a0 #a8e070 #6cc46a #3f9e58 #2a7a45", 7),
233
+ ramp("#f6f1ea #e9e1d4 #d4c8b6 #b8a993 #998a74", 14),
234
+ ramp("#f2f3f5 #d9dce2 #b4b9c4 #8a909e #5f6573", 0),
235
+ ],
236
+ bodies: [
237
+ // A disc.
238
+ { outlines: [disc(50, 50, 27)] },
239
+ // A smaller disc.
240
+ { outlines: [disc(50, 50, 24)] },
241
+ // A lumpy one: a disc with small round bumps on its rim.
242
+ {
243
+ outlines: [
244
+ disc(50, 50, 24.5),
245
+ ...BUMPS.map(([at, radius]) => disc(50 + 23.5 * cosine(at), 50 + 23.5 * sine(at), radius)),
246
+ ],
247
+ },
248
+ // One with an atmosphere: a disc, and a faint larger one behind it.
249
+ {
250
+ outlines: [disc(50, 50, 24.5)],
251
+ behind: [{ outlines: [disc(50, 50, 29)], tone: 0, opacity: 0.2 }],
252
+ },
253
+ ],
254
+ surfaces: [
255
+ // Straight bands.
256
+ {
257
+ tone: 0,
258
+ shapes: [
259
+ of(band(-10, 30.7), 1),
260
+ of(band(38.4, 46.1), 1),
261
+ of(band(53.9, 61.6), 1),
262
+ of(band(69.3, 110), 1),
263
+ ],
264
+ },
265
+ // Wavy bands.
266
+ {
267
+ tone: 1,
268
+ shapes: [
269
+ of(band(-10, 31.5), 2),
270
+ of(band(40.5, 54, { height: 2.4, shift: 6 }), 0),
271
+ of(band(67, 110, { height: 2.4, shift: 19 }), 2),
272
+ ],
273
+ },
274
+ // Zigzag bands.
275
+ {
276
+ tone: 1,
277
+ shapes: [
278
+ of(band(-10, 33, {}, { height: 3 }, { length: 13, zigzag: true }), 2),
279
+ of(band(44, 56, { height: 3 }, { height: 3 }, { length: 13, zigzag: true }), 0),
280
+ of(band(67, 110, { height: 3 }, {}, { length: 13, zigzag: true }), 2),
281
+ ],
282
+ },
283
+ // Tilted bands.
284
+ { tone: 1, shapes: [of(slant(68, 80), 2), of(slant(92, 104), 0), of(slant(116, 128), 2)] },
285
+ // The eye of a storm.
286
+ {
287
+ tone: 0,
288
+ shapes: [
289
+ of(band(-10, 31), 1),
290
+ of(band(69, 110), 1),
291
+ of(band(46.5, 53.5), 1),
292
+ of(oval(50, 50, 15.5, 9.5), 1),
293
+ of(oval(50, 50, 8.5, 5), 0),
294
+ ],
295
+ },
296
+ // A great spot.
297
+ {
298
+ tone: 1,
299
+ shapes: [
300
+ of(band(-10, 34, {}, { height: 1.8, shift: 4 }), 2),
301
+ of(band(43, 49), 0),
302
+ of(band(64, 110, { height: 1.8, shift: 9 }), 2),
303
+ of(slab(53, 51.5, 14, 8, 4), 2),
304
+ ],
305
+ },
306
+ // Continents.
307
+ {
308
+ tone: 0,
309
+ shapes: [
310
+ of(slab(38, 31, 70, 12, 6), 1),
311
+ of(slab(-20, 47, 74, 11, 5.5), 1),
312
+ of(band(67, 110), 1),
313
+ ],
314
+ },
315
+ // Craters.
316
+ {
317
+ tone: 1,
318
+ shapes: [
319
+ of(disc(38, 40, 6.2), 2),
320
+ of(disc(38, 40, 3), 3),
321
+ of(disc(63, 45, 4.6), 2),
322
+ of(disc(42, 63, 5.2), 2),
323
+ of(slab(53, 31, 3.4, 3.4, 0.4), 2),
324
+ of(slab(30, 54, 3, 3, 0.4), 2),
325
+ of(slab(58, 57, 3, 3, 0.4), 2),
326
+ of(disc(50, 80, 7.5), 2),
327
+ ],
328
+ },
329
+ // Polar caps.
330
+ {
331
+ tone: 1,
332
+ shapes: [
333
+ { outlines: [band(-10, 32, {}, { height: 1.6, shift: 4 })], tone: 0, colors: ICE },
334
+ { outlines: [band(70, 110, { height: 1.6, shift: 12 })], tone: 0, colors: ICE },
335
+ of(disc(40, 52, 4.4), 2),
336
+ of(slab(54, 47, 16, 3.4, 1.7), 2),
337
+ ],
338
+ },
339
+ // Day and night.
340
+ { tone: 0, shapes: [of(disc(64, 40, 27), 1), of(disc(70, 34, 10), 2)] },
341
+ ],
342
+ accents: [
343
+ { behind: [], before: [] },
344
+ // A ring: all of it behind the body, and its lower half before it.
345
+ {
346
+ behind: [{ turn: -14, shapes: [{ outlines: RING, tone: 1 }] }],
347
+ before: [{ turn: -14, half: "lower", shapes: [{ outlines: RING, tone: 1 }] }],
348
+ },
349
+ // An orbit: a faint line round the body, and a small moon on it.
350
+ {
351
+ behind: [
352
+ {
353
+ turn: -18,
354
+ half: "upper",
355
+ shapes: [{ outlines: ORBIT, tone: 1, opacity: 0.55 }],
356
+ },
357
+ ],
358
+ before: [
359
+ {
360
+ turn: -18,
361
+ half: "lower",
362
+ shapes: [{ outlines: ORBIT, tone: 1, opacity: 0.55 }],
363
+ },
364
+ {
365
+ turn: -18,
366
+ shapes: [{ outlines: [disc(89.5, 54.4, 3.6)], tone: 1, split: 89.5, gap: 2 }],
367
+ },
368
+ ],
369
+ },
370
+ // A moon.
371
+ {
372
+ behind: [],
373
+ before: [{ shapes: [{ outlines: [disc(74.5, 27.5, 9.4)], tone: 1, split: 74.5, gap: 3 }] }],
374
+ },
375
+ // Two moons.
376
+ {
377
+ behind: [],
378
+ before: [
379
+ {
380
+ shapes: [
381
+ { outlines: [disc(75, 26, 7.6)], tone: 1, split: 75, gap: 2.8 },
382
+ { outlines: [disc(24, 75, 5.2)], tone: 0, split: 24, gap: 2.4 },
383
+ ],
384
+ },
385
+ ],
386
+ },
387
+ // A sparkle, and a smaller one.
388
+ {
389
+ behind: [],
390
+ before: [
391
+ {
392
+ shapes: [
393
+ { outlines: [sparkle(76, 23, 9)], tone: 0, split: 76, gap: 2.4 },
394
+ { outlines: [sparkle(85, 36, 4)], tone: 1, split: 85 },
395
+ ],
396
+ },
397
+ ],
398
+ },
399
+ ],
400
+ };
401
+ /** The sets the package ships, the oldest first; an avatar names the one it was made with. */
402
+ export const AVATAR_SETS = [AVATAR_SET_1];
403
+ /** The set an avatar was made with, among `sets`; the newest where they hold none of its version. */
404
+ export function avatarSetOf(parts, sets = AVATAR_SETS) {
405
+ const found = sets.find((set) => set.version === parts.set) ?? sets[sets.length - 1];
406
+ if (found === undefined) {
407
+ throw new Error("no set to draw an avatar from");
408
+ }
409
+ return found;
410
+ }
411
+ /** What a set holds where it should hold a list: the list, or nothing. */
412
+ const listOf = (value) => Array.isArray(value) ? value : [];
413
+ /** A thing of a set that is one, or nothing: a set of one's own may hold anything. */
414
+ const thing = (value) => typeof value === "object" && value !== null ? value : undefined;
415
+ /** The things of a list of a set; what in it is none is left out. */
416
+ const thingsOf = (value) => listOf(value).filter((one) => thing(one) !== undefined);
417
+ /**
418
+ * The choice an index names, counted round the end: an index a set does not have still draws,
419
+ * and what is no index at all names the first.
420
+ */
421
+ function choiceOf(choices, index) {
422
+ const list = listOf(choices);
423
+ return list.length === 0
424
+ ? undefined
425
+ : list[finite(index) ? Math.abs(Math.trunc(index)) % list.length : 0];
426
+ }
427
+ /** The most a place may be from the picture, in its own units: what is further is nobody's set, and is brought back. */
428
+ const FAR = 1e4;
429
+ /**
430
+ * The most corners one picture is drawn from, some ten times what the first set's fullest
431
+ * picture has: an outline that would take it past that is left out, so that a set of one's own
432
+ * with an outline of any length draws in a time that has a bound.
433
+ */
434
+ const MOST_CORNERS = 20_000;
435
+ /** An outline of a set as a path; what in it is no place of a picture is left out. */
436
+ function pathOf(outline) {
437
+ const path = [];
438
+ if (!Array.isArray(outline)) {
439
+ return path;
440
+ }
441
+ for (const point of outline) {
442
+ const x = Array.isArray(point) ? point[0] : undefined;
443
+ const y = Array.isArray(point) ? point[1] : undefined;
444
+ if (finite(x) && finite(y)) {
445
+ path.push(clamp(x, -FAR, FAR), clamp(y, -FAR, FAR));
446
+ }
447
+ }
448
+ return path;
449
+ }
450
+ /** What of a path lies where `a * x + b * y` is `c` at most: the path cut along a line. */
451
+ function cut(path, a, b, c) {
452
+ const out = [];
453
+ const corners = path.length / 2;
454
+ if (corners < 3) {
455
+ return out;
456
+ }
457
+ let px = path[path.length - 2] ?? 0;
458
+ let py = path[path.length - 1] ?? 0;
459
+ let pd = a * px + b * py - c;
460
+ for (let corner = 0; corner < corners; corner += 1) {
461
+ const x = path[corner * 2] ?? 0;
462
+ const y = path[corner * 2 + 1] ?? 0;
463
+ const d = a * x + b * y - c;
464
+ if (d <= 0 !== pd <= 0) {
465
+ const t = pd / (pd - d);
466
+ out.push(px + (x - px) * t, py + (y - py) * t);
467
+ }
468
+ if (d <= 0) {
469
+ out.push(x, y);
470
+ }
471
+ px = x;
472
+ py = y;
473
+ pd = d;
474
+ }
475
+ return out;
476
+ }
477
+ /** Twice the area a path goes round, its sign saying which way. */
478
+ function turnOf(path) {
479
+ let area = 0;
480
+ const corners = path.length / 2;
481
+ let px = path[path.length - 2] ?? 0;
482
+ let py = path[path.length - 1] ?? 0;
483
+ for (let corner = 0; corner < corners; corner += 1) {
484
+ const x = path[corner * 2] ?? 0;
485
+ const y = path[corner * 2 + 1] ?? 0;
486
+ area += px * y - x * py;
487
+ px = x;
488
+ py = y;
489
+ }
490
+ return area;
491
+ }
492
+ /** How long a join of two sides may reach past their corner, in line widths, before it is cut off flat. */
493
+ const JOIN_LIMIT = 4;
494
+ /**
495
+ * The line `width` wide along an outline, as paths that all run one way round: a piece for each
496
+ * side, and at each corner a piece that fills the outer side of the turn, pointed where the
497
+ * turn is gentle and cut off flat where it is sharp.
498
+ */
499
+ function lineAlong(path, width) {
500
+ const pieces = [];
501
+ const corners = path.length / 2;
502
+ const half = width / 2;
503
+ if (corners < 2 || !(half > 0)) {
504
+ return pieces;
505
+ }
506
+ const piece = (points) => {
507
+ const turn = turnOf(points);
508
+ if (turn === 0) {
509
+ return;
510
+ }
511
+ if (turn < 0) {
512
+ const back = [];
513
+ for (let at = points.length - 2; at >= 0; at -= 2) {
514
+ back.push(points[at] ?? 0, points[at + 1] ?? 0);
515
+ }
516
+ pieces.push(back);
517
+ }
518
+ else {
519
+ pieces.push(points);
520
+ }
521
+ };
522
+ /** The sides that have a length, each with the way it runs. */
523
+ const sides = [];
524
+ for (let corner = 0; corner < corners; corner += 1) {
525
+ const x = path[corner * 2] ?? 0;
526
+ const y = path[corner * 2 + 1] ?? 0;
527
+ const tx = path[((corner + 1) % corners) * 2] ?? 0;
528
+ const ty = path[((corner + 1) % corners) * 2 + 1] ?? 0;
529
+ const long = length(tx - x, ty - y);
530
+ if (long > 0) {
531
+ sides.push({ x, y, dx: (tx - x) / long, dy: (ty - y) / long, tx, ty });
532
+ }
533
+ }
534
+ for (const [at, side] of sides.entries()) {
535
+ // Across the side, to its left as it runs.
536
+ const nx = -side.dy * half;
537
+ const ny = side.dx * half;
538
+ piece([
539
+ side.x + nx,
540
+ side.y + ny,
541
+ side.tx + nx,
542
+ side.ty + ny,
543
+ side.tx - nx,
544
+ side.ty - ny,
545
+ side.x - nx,
546
+ side.y - ny,
547
+ ]);
548
+ const next = sides[(at + 1) % sides.length];
549
+ if (next === undefined || next === side) {
550
+ continue;
551
+ }
552
+ const cross = side.dx * next.dy - side.dy * next.dx;
553
+ if (cross === 0) {
554
+ continue;
555
+ }
556
+ // The outer side of the turn is the one away from where it turns to.
557
+ const out = cross > 0 ? -1 : 1;
558
+ const ax = side.tx + out * nx;
559
+ const ay = side.ty + out * ny;
560
+ const bx = side.tx + out * -next.dy * half;
561
+ const by = side.ty + out * next.dx * half;
562
+ const along = 1 + side.dx * next.dx + side.dy * next.dy;
563
+ if (along >= 2 / (JOIN_LIMIT * JOIN_LIMIT)) {
564
+ const reach = (out * half) / along;
565
+ piece([
566
+ side.tx,
567
+ side.ty,
568
+ ax,
569
+ ay,
570
+ side.tx + (-side.dy - next.dy) * reach,
571
+ side.ty + (side.dx + next.dx) * reach,
572
+ bx,
573
+ by,
574
+ ]);
575
+ }
576
+ else {
577
+ piece([side.tx, side.ty, ax, ay, bx, by]);
578
+ }
579
+ }
580
+ return pieces;
581
+ }
582
+ function placed(path, placing) {
583
+ const middle = AVATAR_BOX / 2;
584
+ const out = new Array(path.length);
585
+ for (let at = 0; at < path.length; at += 2) {
586
+ const x = (path[at] ?? 0) - middle;
587
+ const y = (path[at + 1] ?? 0) - middle;
588
+ out[at] = (middle + (x * placing.cos - y * placing.sin) * placing.zoom) * placing.scale;
589
+ out[at + 1] = (middle + (x * placing.sin + y * placing.cos) * placing.zoom) * placing.scale;
590
+ }
591
+ return out;
592
+ }
593
+ /**
594
+ * Adds a path to the sums its pixels are covered by: for each row a side crosses, how much of
595
+ * each pixel lies to the right of it, signed by the way the side runs. Summed along a row, they
596
+ * say how much of each pixel the path goes round, and how often.
597
+ */
598
+ function trace(sums, stride, path, frame, reach) {
599
+ let cutPath = cut(path, -1, 0, -frame.left);
600
+ cutPath = cut(cutPath, 1, 0, frame.right);
601
+ cutPath = cut(cutPath, 0, -1, -frame.top);
602
+ cutPath = cut(cutPath, 0, 1, frame.bottom);
603
+ const corners = cutPath.length / 2;
604
+ if (corners < 3) {
605
+ return;
606
+ }
607
+ let px = cutPath[cutPath.length - 2] ?? 0;
608
+ let py = cutPath[cutPath.length - 1] ?? 0;
609
+ for (let corner = 0; corner < corners; corner += 1) {
610
+ const cx = cutPath[corner * 2] ?? 0;
611
+ const cy = cutPath[corner * 2 + 1] ?? 0;
612
+ let x0 = px;
613
+ let y0 = py;
614
+ let x1 = cx;
615
+ let y1 = cy;
616
+ px = cx;
617
+ py = cy;
618
+ if (y0 === y1) {
619
+ continue;
620
+ }
621
+ let way = 1;
622
+ if (y0 > y1) {
623
+ way = -1;
624
+ [x0, y0, x1, y1] = [x1, y1, x0, y0];
625
+ }
626
+ const slope = (x1 - x0) / (y1 - y0);
627
+ let x = x0;
628
+ const first = Math.floor(y0);
629
+ const last = Math.ceil(y1);
630
+ reach.top = Math.min(reach.top, first);
631
+ reach.bottom = Math.max(reach.bottom, last);
632
+ for (let row = first; row < last; row += 1) {
633
+ const tall = Math.min(row + 1, y1) - Math.max(row, y0);
634
+ const after = x + slope * tall;
635
+ const share = tall * way;
636
+ const from = Math.min(x, after);
637
+ const to = Math.max(x, after);
638
+ const start = Math.floor(from);
639
+ const end = Math.ceil(to);
640
+ const base = row * stride;
641
+ reach.left = Math.min(reach.left, start);
642
+ reach.right = Math.max(reach.right, end + 1);
643
+ if (end <= start + 1) {
644
+ const across = 0.5 * (x + after) - start;
645
+ sums[base + start] = (sums[base + start] ?? 0) + share - share * across;
646
+ sums[base + start + 1] = (sums[base + start + 1] ?? 0) + share * across;
647
+ }
648
+ else {
649
+ const each = 1 / (to - from);
650
+ const inFirst = from - start;
651
+ const firstArea = 0.5 * each * (1 - inFirst) * (1 - inFirst);
652
+ const inLast = to - end + 1;
653
+ const lastArea = 0.5 * each * inLast * inLast;
654
+ sums[base + start] = (sums[base + start] ?? 0) + share * firstArea;
655
+ if (end === start + 2) {
656
+ sums[base + start + 1] =
657
+ (sums[base + start + 1] ?? 0) + share * (1 - firstArea - lastArea);
658
+ }
659
+ else {
660
+ const second = each * (1.5 - inFirst);
661
+ sums[base + start + 1] = (sums[base + start + 1] ?? 0) + share * (second - firstArea);
662
+ for (let column = start + 2; column < end - 1; column += 1) {
663
+ sums[base + column] = (sums[base + column] ?? 0) + share * each;
664
+ }
665
+ const before = second + (end - start - 3) * each;
666
+ sums[base + end - 1] = (sums[base + end - 1] ?? 0) + share * (1 - before - lastArea);
667
+ }
668
+ sums[base + end] = (sums[base + end] ?? 0) + share * lastArea;
669
+ }
670
+ x = after;
671
+ }
672
+ }
673
+ }
674
+ /**
675
+ * How much of a pixel is filled, from how much of it the outlines go round: once is all of it,
676
+ * more is no more, and what an outline goes round the other way is taken off.
677
+ */
678
+ const filled = (round) => Math.min(1, Math.abs(round));
679
+ function sheetOf(side) {
680
+ const stride = side + 2;
681
+ return {
682
+ side,
683
+ stride,
684
+ pixels: new Float32Array(side * side * 3),
685
+ whole: new Float32Array(stride * side),
686
+ left: new Float32Array(stride * side),
687
+ };
688
+ }
689
+ const emptyReach = () => ({
690
+ left: Infinity,
691
+ top: Infinity,
692
+ right: -Infinity,
693
+ bottom: -Infinity,
694
+ });
695
+ /**
696
+ * Fills paths on `target`, in one colour left of a line and another right of it: `leftPaths` is
697
+ * what of the shape lies left. Where `through` is given, only as much of each pixel is filled as
698
+ * it says. Every pixel is given its two colours at once, by how much of it each covers, so that
699
+ * no line of what is behind shows where they meet.
700
+ */
701
+ function fill(sheet, target, frame, paths, leftPaths, leftColor, rightColor, opacity, through) {
702
+ const { side, stride, whole, left } = sheet;
703
+ const reach = emptyReach();
704
+ for (const path of paths) {
705
+ trace(whole, stride, path, frame, reach);
706
+ }
707
+ if (leftPaths !== undefined) {
708
+ const unused = emptyReach();
709
+ for (const path of leftPaths) {
710
+ trace(left, stride, path, frame, unused);
711
+ }
712
+ }
713
+ if (reach.top >= reach.bottom) {
714
+ return;
715
+ }
716
+ const firstRow = Math.max(0, reach.top);
717
+ const lastRow = Math.min(side, reach.bottom);
718
+ const firstColumn = Math.max(0, reach.left);
719
+ const lastColumn = Math.min(side + 1, reach.right);
720
+ for (let row = firstRow; row < lastRow; row += 1) {
721
+ let round = 0;
722
+ let roundLeft = 0;
723
+ for (let column = firstColumn; column <= lastColumn; column += 1) {
724
+ const at = row * stride + column;
725
+ round += whole[at] ?? 0;
726
+ whole[at] = 0;
727
+ if (leftPaths !== undefined) {
728
+ roundLeft += left[at] ?? 0;
729
+ left[at] = 0;
730
+ }
731
+ if (column >= side) {
732
+ continue;
733
+ }
734
+ const all = filled(round);
735
+ if (all <= 0) {
736
+ continue;
737
+ }
738
+ const cell = row * side + column;
739
+ const share = opacity * (through === undefined ? 1 : (through[cell] ?? 0));
740
+ const onLeft = leftPaths === undefined ? 0 : Math.min(all, filled(roundLeft));
741
+ const a = onLeft * share;
742
+ const b = (all - onLeft) * share;
743
+ const pixel = cell * 3;
744
+ const keep = 1 - a - b;
745
+ target[pixel] = (target[pixel] ?? 0) * keep + leftColor[0] * a + rightColor[0] * b;
746
+ target[pixel + 1] = (target[pixel + 1] ?? 0) * keep + leftColor[1] * a + rightColor[1] * b;
747
+ target[pixel + 2] = (target[pixel + 2] ?? 0) * keep + leftColor[2] * a + rightColor[2] * b;
748
+ }
749
+ }
750
+ }
751
+ /** How much of each pixel paths cover, written into `mask`, and the pixels they reach. */
752
+ function cover(sheet, mask, paths) {
753
+ const { side, stride, whole } = sheet;
754
+ const reach = emptyReach();
755
+ const frame = { left: 0, top: 0, right: side, bottom: side };
756
+ for (const path of paths) {
757
+ trace(whole, stride, path, frame, reach);
758
+ }
759
+ if (reach.top >= reach.bottom) {
760
+ return reach;
761
+ }
762
+ const lastColumn = Math.min(side + 1, reach.right);
763
+ for (let row = Math.max(0, reach.top); row < Math.min(side, reach.bottom); row += 1) {
764
+ let round = 0;
765
+ for (let column = Math.max(0, reach.left); column <= lastColumn; column += 1) {
766
+ const at = row * stride + column;
767
+ round += whole[at] ?? 0;
768
+ whole[at] = 0;
769
+ if (column < side) {
770
+ mask[row * side + column] = filled(round);
771
+ }
772
+ }
773
+ }
774
+ return reach;
775
+ }
776
+ /** The ramp a shape is drawn in when the set has none: greys. */
777
+ const NO_RAMP = {
778
+ tones: ["#eeeeee", "#cccccc", "#aaaaaa", "#888888", "#666666"],
779
+ partner: 0,
780
+ };
781
+ const NO_GROUND = "#51525c";
782
+ /** The two colours of a shape: its own, or two tones of the ramp it is drawn in, the last tone twice where there is none after it. */
783
+ function tonesOf(shape, ramp) {
784
+ if (Array.isArray(shape.colors)) {
785
+ return [colorOf(shape.colors[0]), colorOf(shape.colors[1])];
786
+ }
787
+ const tones = Array.isArray(ramp.tones) ? ramp.tones : [];
788
+ const at = finite(shape.tone) ? clamp(Math.trunc(shape.tone), 0, tones.length - 1) : 0;
789
+ return [colorOf(tones[at]), colorOf(tones[Math.min(at + 1, tones.length - 1)])];
790
+ }
791
+ /** The numbers the squares on the ground are strewn by: the same seed, the same squares. */
792
+ function strewn(seed) {
793
+ let state = 0;
794
+ for (const letter of String(seed)) {
795
+ state = (state * 31 + letter.charCodeAt(0)) >>> 0;
796
+ }
797
+ state = state || 1;
798
+ return () => {
799
+ state = (Math.imul(state, 1664525) + 1013904223) >>> 0;
800
+ return state / 4294967296;
801
+ };
802
+ }
803
+ /**
804
+ * The side of a square on the ground, where its middle is taken to be from its corner, how far
805
+ * from the middle of the picture the squares keep, and how far from one another.
806
+ */
807
+ const SQUARE = 3.4;
808
+ const SQUARE_MIDDLE = 1.8;
809
+ const SQUARES_KEEP_OFF = 37;
810
+ const SQUARES_APART = 11;
811
+ /** The squares on the ground: six to eight, clear of the planet and of one another, each with its colour. */
812
+ function squaresOf(seed, colors) {
813
+ const next = strewn(seed);
814
+ const wanted = 6 + Math.floor(next() * 3);
815
+ const places = [];
816
+ const middle = AVATAR_BOX / 2;
817
+ for (let tries = 0; places.length < wanted && tries < 400; tries += 1) {
818
+ const x = 5 + next() * 87;
819
+ const y = 5 + next() * 87;
820
+ if (length(x + SQUARE_MIDDLE - middle, y + SQUARE_MIDDLE - middle) < SQUARES_KEEP_OFF) {
821
+ continue;
822
+ }
823
+ if (places.some(([px, py]) => length(px - x, py - y) < SQUARES_APART)) {
824
+ continue;
825
+ }
826
+ places.push([x, y]);
827
+ }
828
+ return places.map(([x, y]) => ({
829
+ x: two(x),
830
+ y: two(y),
831
+ color: colorOf(colors.length === 0 ? undefined : colors[Math.floor(next() * colors.length)]),
832
+ }));
833
+ }
834
+ /** How wide the line of the ground round a shape is: none where it names none, and no wider than the picture. */
835
+ const gapOf = (shape) => finite(shape.gap) ? clamp(shape.gap, 0, AVATAR_BOX) : 0;
836
+ /** How far a layer's shapes reach from the middle of the picture, across or down, once turned. */
837
+ function reachOf(shapes, turn) {
838
+ const middle = AVATAR_BOX / 2;
839
+ const cos = cosine(turn);
840
+ const sin = sine(turn);
841
+ let far = 0;
842
+ for (const shape of shapes) {
843
+ const margin = gapOf(shape) / 2;
844
+ for (const outline of listOf(shape.outlines)) {
845
+ const path = pathOf(outline);
846
+ for (let at = 0; at < path.length; at += 2) {
847
+ const x = (path[at] ?? 0) - middle;
848
+ const y = (path[at + 1] ?? 0) - middle;
849
+ far = Math.max(far, Math.abs(x * cos - y * sin) + margin, Math.abs(x * sin + y * cos) + margin);
850
+ }
851
+ }
852
+ }
853
+ return far;
854
+ }
855
+ /** How much of the picture's half a planet drawn larger may reach, with what stands beside it. */
856
+ const CLOSE_REACH = 0.94;
857
+ /** The picture an avatar's parts name, `side` pixels a side: red, green and blue of each pixel. */
858
+ function drawn(parts, side, sets) {
859
+ const set = avatarSetOf(parts, sets);
860
+ const own = thing(choiceOf(set.ramps, parts.palette)) ?? NO_RAMP;
861
+ const partner = thing(choiceOf(set.ramps, own.partner)) ?? own;
862
+ const body = thing(choiceOf(set.bodies, parts.form));
863
+ const surface = thing(choiceOf(set.surfaces, parts.material)) ?? { tone: 0, shapes: [] };
864
+ const accent = thing(choiceOf(set.accents, parts.accent)) ?? { behind: [], before: [] };
865
+ const ground = colorOf(choiceOf(set.grounds, parts.ground) ?? NO_GROUND);
866
+ const middle = AVATAR_BOX / 2;
867
+ const scale = side / AVATAR_BOX;
868
+ const sheet = sheetOf(side);
869
+ const { pixels } = sheet;
870
+ for (let at = 0; at < pixels.length; at += 3) {
871
+ pixels[at] = ground[0];
872
+ pixels[at + 1] = ground[1];
873
+ pixels[at + 2] = ground[2];
874
+ }
875
+ const all = { left: 0, top: 0, right: side, bottom: side };
876
+ let corners = MOST_CORNERS;
877
+ /** An outline as a path, while the picture has corners left for it. */
878
+ const pathIn = (outline) => {
879
+ const path = pathOf(outline);
880
+ if (path.length / 2 > corners) {
881
+ return [];
882
+ }
883
+ corners -= path.length / 2;
884
+ return path;
885
+ };
886
+ // The squares on the ground, faint, which a small picture has no room for.
887
+ if (side >= AVATAR_PLAIN_UNDER) {
888
+ const flat = { cos: 1, sin: 0, zoom: 1, scale };
889
+ for (const square of squaresOf(Math.abs(Math.trunc(finite(parts.vein) ? parts.vein : 0)), listOf(set.confetti))) {
890
+ const path = [
891
+ square.x,
892
+ square.y,
893
+ square.x + SQUARE,
894
+ square.y,
895
+ square.x + SQUARE,
896
+ square.y + SQUARE,
897
+ square.x,
898
+ square.y + SQUARE,
899
+ ];
900
+ fill(sheet, pixels, all, [placed(path, flat)], undefined, square.color, square.color, 0.5);
901
+ }
902
+ }
903
+ // The planet is drawn as much larger as its set asks, and that of a small picture closer
904
+ // still: never past what stands beside it leaves room for.
905
+ const fuller = finite(set.fill) ? clamp(set.fill, 1, AVATAR_FILL_MOST) : 1;
906
+ const most = side < AVATAR_CLOSE_UNDER ? Math.max(fuller, AVATAR_CLOSE_MOST) : fuller;
907
+ let zoom = 1;
908
+ if (most > 1) {
909
+ let far = reachOf([{ outlines: listOf(body?.outlines), tone: 0 }, ...thingsOf(body?.behind)], 0);
910
+ for (const layer of [...thingsOf(accent.behind), ...thingsOf(accent.before)]) {
911
+ far = Math.max(far, reachOf(thingsOf(layer.shapes), finite(layer.turn) ? layer.turn : 0));
912
+ }
913
+ zoom = far > 0 ? clamp((middle * CLOSE_REACH) / far, 1, most) : 1;
914
+ }
915
+ /** One shape, in its ramp, as its layer is turned and cut. */
916
+ const shapeOn = (target, frame, shape, inRamp, layer, through) => {
917
+ const turn = finite(layer.turn) ? layer.turn : 0;
918
+ const placing = { cos: cosine(turn), sin: sine(turn), zoom, scale };
919
+ const split = finite(shape.split) ? shape.split : middle;
920
+ const opacity = finite(shape.opacity) ? clamp(shape.opacity) : 1;
921
+ const outlines = listOf(shape.outlines).map(pathIn);
922
+ const gap = gapOf(shape);
923
+ if (gap > 0) {
924
+ const line = outlines.flatMap((path) => lineAlong(path, gap));
925
+ fill(sheet, target, frame, line.map((path) => placed(path, placing)), undefined, ground, ground, 1, through);
926
+ }
927
+ const kept = outlines.map((path) => layer.half === "upper"
928
+ ? cut(path, 0, 1, middle)
929
+ : layer.half === "lower"
930
+ ? cut(path, 0, -1, -middle)
931
+ : path);
932
+ const [lighter, darker] = tonesOf(shape, inRamp);
933
+ fill(sheet, target, frame, kept.map((path) => placed(path, placing)), kept.map((path) => placed(cut(path, 1, 0, split), placing)), lighter, darker, opacity, through);
934
+ };
935
+ for (const shape of thingsOf(body?.behind)) {
936
+ shapeOn(pixels, all, shape, own, {});
937
+ }
938
+ for (const layer of thingsOf(accent.behind)) {
939
+ for (const shape of thingsOf(layer.shapes)) {
940
+ shapeOn(pixels, all, shape, partner, layer);
941
+ }
942
+ }
943
+ // The body: its surface is drawn whole on a sheet of its own, and put on the picture through
944
+ // the body's outline, so that the body's edge is smoothed once.
945
+ if (body !== undefined) {
946
+ const still = { cos: 1, sin: 0, zoom, scale };
947
+ const mask = new Float32Array(side * side);
948
+ const reach = cover(sheet, mask, listOf(body.outlines).map((outline) => placed(pathIn(outline), still)));
949
+ if (reach.top < reach.bottom) {
950
+ const within = {
951
+ left: Math.max(0, reach.left - 1),
952
+ top: Math.max(0, reach.top - 1),
953
+ right: Math.min(side, reach.right + 1),
954
+ bottom: Math.min(side, reach.bottom + 1),
955
+ };
956
+ const skin = new Float32Array(side * side * 3);
957
+ const everywhere = [
958
+ [-AVATAR_BOX, -AVATAR_BOX],
959
+ [2 * AVATAR_BOX, -AVATAR_BOX],
960
+ [2 * AVATAR_BOX, 2 * AVATAR_BOX],
961
+ [-AVATAR_BOX, 2 * AVATAR_BOX],
962
+ ];
963
+ shapeOn(skin, within, { outlines: [everywhere], tone: finite(surface.tone) ? surface.tone : 0 }, own, {});
964
+ for (const shape of thingsOf(surface.shapes)) {
965
+ shapeOn(skin, within, shape, own, {});
966
+ }
967
+ for (let row = within.top; row < within.bottom; row += 1) {
968
+ for (let column = within.left; column < within.right; column += 1) {
969
+ const cell = row * side + column;
970
+ const share = mask[cell] ?? 0;
971
+ if (share <= 0) {
972
+ continue;
973
+ }
974
+ const pixel = cell * 3;
975
+ for (let color = 0; color < 3; color += 1) {
976
+ const under = pixels[pixel + color] ?? 0;
977
+ pixels[pixel + color] = under + ((skin[pixel + color] ?? 0) - under) * share;
978
+ }
979
+ }
980
+ }
981
+ }
982
+ }
983
+ for (const layer of thingsOf(accent.before)) {
984
+ for (const shape of thingsOf(layer.shapes)) {
985
+ shapeOn(pixels, all, shape, partner, layer);
986
+ }
987
+ }
988
+ return pixels;
989
+ }
990
+ /** The size a picture is drawn at: a whole number of pixels, from 16 to the most the module writes. */
991
+ function pixelsOf(size) {
992
+ const whole = Math.trunc(size);
993
+ if (!Number.isFinite(whole) || whole < 16 || whole > MAX_AVATAR_PIXELS) {
994
+ throw new RangeError(`an avatar is drawn from 16 to ${MAX_AVATAR_PIXELS} pixels a side`);
995
+ }
996
+ return whole;
997
+ }
998
+ /**
999
+ * The avatar as pixels, `size` a side: three bytes each, red, green and blue, row after row from
1000
+ * the top. The same parts give the same bytes wherever they are drawn.
1001
+ */
1002
+ export function avatarPixels(parts, size, sets = AVATAR_SETS) {
1003
+ const side = pixelsOf(size);
1004
+ const colors = drawn(parts, side, sets);
1005
+ const pixels = new Uint8Array(side * side * 3);
1006
+ for (let at = 0; at < pixels.length; at += 1) {
1007
+ // A typed array keeps a byte: what is above 255 or under 0 is brought back first.
1008
+ pixels[at] = Math.round(clamp(colors[at] ?? 0, 0, 255));
1009
+ }
1010
+ return pixels;
1011
+ }
1012
+ /**
1013
+ * The avatar as the rows a PNG file compresses: each row of pixels after the byte that says it
1014
+ * is filtered in no way. What comes back from a zlib deflate of these is `pngFile`'s to wrap.
1015
+ */
1016
+ export function avatarScanlines(parts, size, sets = AVATAR_SETS) {
1017
+ const side = pixelsOf(size);
1018
+ const pixels = avatarPixels(parts, side, sets);
1019
+ const row = side * 3;
1020
+ const lines = new Uint8Array(side * (row + 1));
1021
+ for (let y = 0; y < side; y += 1) {
1022
+ lines.set(pixels.subarray(y * row, (y + 1) * row), y * (row + 1) + 1);
1023
+ }
1024
+ return lines;
1025
+ }
1026
+ /** The checksum a PNG file keeps of each of its chunks. */
1027
+ const CRC_TABLE = Uint32Array.from({ length: 256 }, (_, index) => {
1028
+ let value = index;
1029
+ for (let bit = 0; bit < 8; bit += 1) {
1030
+ value = value & 1 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;
1031
+ }
1032
+ return value >>> 0;
1033
+ });
1034
+ function crc32(bytes) {
1035
+ let crc = 0xffffffff;
1036
+ for (const byte of bytes) {
1037
+ crc = (CRC_TABLE[(crc ^ byte) & 0xff] ?? 0) ^ (crc >>> 8);
1038
+ }
1039
+ return (crc ^ 0xffffffff) >>> 0;
1040
+ }
1041
+ /** One chunk of a PNG file: its length, its name, its bytes and their checksum. */
1042
+ function chunk(name, data) {
1043
+ const out = new Uint8Array(12 + data.length);
1044
+ const view = new DataView(out.buffer);
1045
+ view.setUint32(0, data.length);
1046
+ for (let i = 0; i < 4; i += 1) {
1047
+ out[4 + i] = name.charCodeAt(i);
1048
+ }
1049
+ out.set(data, 8);
1050
+ view.setUint32(8 + data.length, crc32(out.subarray(4, 8 + data.length)));
1051
+ return out;
1052
+ }
1053
+ /**
1054
+ * A PNG file of `size` pixels a side, of eight bits a colour and no transparency, from its rows
1055
+ * already compressed: `deflated` is the zlib stream of `avatarScanlines`, which the runtime
1056
+ * makes (`deflateSync` of `node:zlib`, a `CompressionStream("deflate")` in a browser).
1057
+ */
1058
+ export function pngFile(size, deflated) {
1059
+ const side = pixelsOf(size);
1060
+ const header = new Uint8Array(13);
1061
+ const view = new DataView(header.buffer);
1062
+ view.setUint32(0, side);
1063
+ view.setUint32(4, side);
1064
+ header[8] = 8; // bits a sample
1065
+ header[9] = 2; // red, green and blue
1066
+ const parts = [
1067
+ Uint8Array.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
1068
+ chunk("IHDR", header),
1069
+ chunk("IDAT", deflated),
1070
+ chunk("IEND", new Uint8Array(0)),
1071
+ ];
1072
+ const file = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
1073
+ let at = 0;
1074
+ for (const part of parts) {
1075
+ file.set(part, at);
1076
+ at += part.length;
1077
+ }
1078
+ return file;
1079
+ }
1080
+ /** The most bytes one block of a zlib stream holds unpacked. */
1081
+ const STORED_BLOCK = 65_535;
1082
+ /**
1083
+ * Bytes as a zlib stream that packs nothing: each block says its length and holds the bytes as
1084
+ * they are. Larger than a packed one, and written here, at once, with no help of a runtime: what
1085
+ * a picture shown on a page wants, where waiting for a compressor would leave a gap.
1086
+ */
1087
+ function stored(bytes) {
1088
+ const blocks = Math.max(1, Math.ceil(bytes.length / STORED_BLOCK));
1089
+ const out = new Uint8Array(2 + blocks * 5 + bytes.length + 4);
1090
+ out[0] = 0x78;
1091
+ out[1] = 0x01;
1092
+ let at = 2;
1093
+ for (let block = 0; block < blocks; block += 1) {
1094
+ const from = block * STORED_BLOCK;
1095
+ const held = Math.min(STORED_BLOCK, bytes.length - from);
1096
+ out[at] = block === blocks - 1 ? 1 : 0;
1097
+ out[at + 1] = held & 0xff;
1098
+ out[at + 2] = held >>> 8;
1099
+ out[at + 3] = ~held & 0xff;
1100
+ out[at + 4] = (~held >>> 8) & 0xff;
1101
+ out.set(bytes.subarray(from, from + held), at + 5);
1102
+ at += 5 + held;
1103
+ }
1104
+ // The checksum of a zlib stream, of what it holds unpacked.
1105
+ let low = 1;
1106
+ let high = 0;
1107
+ for (const byte of bytes) {
1108
+ low = (low + byte) % 65_521;
1109
+ high = (high + low) % 65_521;
1110
+ }
1111
+ out[at] = high >>> 8;
1112
+ out[at + 1] = high & 0xff;
1113
+ out[at + 2] = low >>> 8;
1114
+ out[at + 3] = low & 0xff;
1115
+ return out;
1116
+ }
1117
+ const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1118
+ /** Bytes in base64, as an address of a picture holds them. */
1119
+ function base64(bytes) {
1120
+ const out = [];
1121
+ let line = "";
1122
+ for (let at = 0; at < bytes.length; at += 3) {
1123
+ const a = bytes[at] ?? 0;
1124
+ const b = bytes[at + 1] ?? 0;
1125
+ const c = bytes[at + 2] ?? 0;
1126
+ line += BASE64.charAt(a >>> 2) + BASE64.charAt(((a & 3) << 4) | (b >>> 4));
1127
+ line += at + 1 < bytes.length ? BASE64.charAt(((b & 15) << 2) | (c >>> 6)) : "=";
1128
+ line += at + 2 < bytes.length ? BASE64.charAt(c & 63) : "=";
1129
+ if (line.length >= 8192) {
1130
+ out.push(line);
1131
+ line = "";
1132
+ }
1133
+ }
1134
+ out.push(line);
1135
+ return out.join("");
1136
+ }
1137
+ /** How many pictures are kept drawn for the pages, the ones asked for longest ago let go first. */
1138
+ const KEPT_PICTURES = 256;
1139
+ const kept = new WeakMap();
1140
+ /**
1141
+ * The avatar as the address of a picture, `data:image/png;base64,…`, `size` pixels a side: what a
1142
+ * page gives an `img`. Drawn at once and kept, so that a picture shown in many places, or shown
1143
+ * again, is drawn once. The file inside is a whole PNG, larger than a packed one.
1144
+ */
1145
+ export function avatarDataUrl(parts, size, sets = AVATAR_SETS) {
1146
+ const side = pixelsOf(size);
1147
+ let pictures = kept.get(sets);
1148
+ if (pictures === undefined) {
1149
+ pictures = new Map();
1150
+ kept.set(sets, pictures);
1151
+ }
1152
+ const key = [
1153
+ side,
1154
+ parts.set,
1155
+ parts.palette,
1156
+ parts.ground,
1157
+ parts.form,
1158
+ parts.material,
1159
+ parts.accent,
1160
+ parts.vein,
1161
+ ].join(".");
1162
+ const found = pictures.get(key);
1163
+ if (found !== undefined) {
1164
+ return found;
1165
+ }
1166
+ const address = `data:image/png;base64,${base64(pngFile(side, stored(avatarScanlines(parts, side, sets))))}`;
1167
+ if (pictures.size >= KEPT_PICTURES) {
1168
+ const oldest = pictures.keys().next();
1169
+ if (oldest.done !== true) {
1170
+ pictures.delete(oldest.value);
1171
+ }
1172
+ }
1173
+ pictures.set(key, address);
1174
+ return address;
1175
+ }
1176
+ /** Numbers from a seed: the same seed gives the same numbers, each from 0 up to but not 1. */
1177
+ export function seededNumbers(seed) {
1178
+ // A hash of the text for a start, then a generator of 32 bits; neither is for secrets.
1179
+ let start = 1779033703 ^ seed.length;
1180
+ for (let i = 0; i < seed.length; i += 1) {
1181
+ start = Math.imul(start ^ seed.charCodeAt(i), 3432918353);
1182
+ start = (start << 13) | (start >>> 19);
1183
+ }
1184
+ let state = start >>> 0;
1185
+ return () => {
1186
+ state = (state + 0x6d2b79f5) >>> 0;
1187
+ let next = state;
1188
+ next = Math.imul(next ^ (next >>> 15), next | 1);
1189
+ next ^= next + Math.imul(next ^ (next >>> 7), next | 61);
1190
+ return ((next ^ (next >>> 14)) >>> 0) / 4294967296;
1191
+ };
1192
+ }
1193
+ /** How many ways the squares on a ground may be strewn: the seed of one is a byte. */
1194
+ export const AVATAR_VEINS = 256;
1195
+ /**
1196
+ * The parts a seed gives, of the newest of `sets`: the same seed, the same avatar. A body, a
1197
+ * surface and a ramp are rolled alike; nothing stands beside the body a little less than half
1198
+ * the time, and the other accents share the rest.
1199
+ */
1200
+ export function rollAvatar(seed, sets = AVATAR_SETS) {
1201
+ const set = avatarSetOf({ set: Number.MAX_SAFE_INTEGER }, sets);
1202
+ const next = seededNumbers(`avatar:${seed}`);
1203
+ const pick = (choices) => (choices <= 0 ? 0 : Math.floor(next() * choices));
1204
+ /** One of the choices after the first, or the first, which is rolled `often` of the time. */
1205
+ const perhaps = (choices, often) => choices <= 1 || next() < often ? 0 : 1 + pick(choices - 1);
1206
+ return {
1207
+ set: set.version,
1208
+ palette: pick(listOf(set.ramps).length),
1209
+ ground: pick(listOf(set.grounds).length),
1210
+ form: pick(listOf(set.bodies).length),
1211
+ material: pick(listOf(set.surfaces).length),
1212
+ accent: perhaps(listOf(set.accents).length, 0.45),
1213
+ vein: pick(AVATAR_VEINS),
1214
+ };
1215
+ }
1216
+ //# sourceMappingURL=avatar.js.map