cuju-render 0.1.0__py3-none-any.whl

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 (382) hide show
  1. cuju/render/__init__.py +759 -0
  2. cuju/render/__main__.py +1065 -0
  3. cuju/render/_export/__init__.py +3 -0
  4. cuju/render/_export/feed.py +542 -0
  5. cuju/render/_export/sizes.py +157 -0
  6. cuju/render/_export/video.py +1618 -0
  7. cuju/render/_export/video_jobs.py +408 -0
  8. cuju/render/_format/__init__.py +3 -0
  9. cuju/render/_format/annotations.py +235 -0
  10. cuju/render/_format/codec.py +307 -0
  11. cuju/render/_format/keep.py +121 -0
  12. cuju/render/_format/recording.py +860 -0
  13. cuju/render/_format/writer.py +54 -0
  14. cuju/render/_guide/__init__.py +3 -0
  15. cuju/render/_guide/doctor.py +523 -0
  16. cuju/render/_guide/help.py +62 -0
  17. cuju/render/_guide/tutorial.py +254 -0
  18. cuju/render/_http/__init__.py +3 -0
  19. cuju/render/_http/commands.py +57 -0
  20. cuju/render/_http/headers.py +103 -0
  21. cuju/render/_http/launch.py +500 -0
  22. cuju/render/_http/launchers.py +408 -0
  23. cuju/render/_http/pwa.py +128 -0
  24. cuju/render/_http/server.py +2105 -0
  25. cuju/render/_http/window.py +360 -0
  26. cuju/render/_moments/__init__.py +3 -0
  27. cuju/render/_moments/captions.py +284 -0
  28. cuju/render/_moments/events.py +1123 -0
  29. cuju/render/_moments/search.py +694 -0
  30. cuju/render/_packages/__init__.py +3 -0
  31. cuju/render/_packages/glsl.py +746 -0
  32. cuju/render/_packages/loudness.py +334 -0
  33. cuju/render/_packages/pack.py +1959 -0
  34. cuju/render/_packages/presentation.py +1376 -0
  35. cuju/render/_packages/vocabulary.py +609 -0
  36. cuju/render/_playing/__init__.py +3 -0
  37. cuju/render/_playing/achievements.py +463 -0
  38. cuju/render/_playing/bench.py +609 -0
  39. cuju/render/_playing/challenges.py +1813 -0
  40. cuju/render/_playing/demo.py +323 -0
  41. cuju/render/_playing/draw.py +211 -0
  42. cuju/render/_playing/errors.py +20 -0
  43. cuju/render/_playing/game.py +645 -0
  44. cuju/render/_playing/limits.py +339 -0
  45. cuju/render/_playing/play.py +926 -0
  46. cuju/render/_playing/policy_worker.py +250 -0
  47. cuju/render/_playing/strict.py +810 -0
  48. cuju/render/_registry/__init__.py +3 -0
  49. cuju/render/_registry/clips.py +394 -0
  50. cuju/render/_registry/joints.py +108 -0
  51. cuju/render/_registry/teams.py +2058 -0
  52. cuju/render/_store/__init__.py +3 -0
  53. cuju/render/_store/home.py +70 -0
  54. cuju/render/_store/library.py +604 -0
  55. cuju/render/_store/samples.py +163 -0
  56. cuju/render/_text/__init__.py +3 -0
  57. cuju/render/_text/languages.py +637 -0
  58. cuju/render/_text/messages.py +1396 -0
  59. cuju/render/_tournaments/__init__.py +3 -0
  60. cuju/render/_tournaments/results.py +547 -0
  61. cuju/render/_tournaments/tournament.py +2742 -0
  62. cuju/render/_tournaments/tournament_cli.py +587 -0
  63. cuju/render/_tournaments/tournament_runner.py +1975 -0
  64. cuju/render/_version.py +6 -0
  65. cuju/render/_watch/__init__.py +3 -0
  66. cuju/render/_watch/grid.py +265 -0
  67. cuju/render/_watch/live.py +664 -0
  68. cuju/render/_watch/notebook.py +79 -0
  69. cuju/render/_watch/show.py +171 -0
  70. cuju/render/samples/sample-11v11.cjr +0 -0
  71. cuju/render/samples/sample-5v5.cjr +0 -0
  72. cuju/render/samples/teams/starter/main.py +33 -0
  73. cuju/render/scenarios/benchmark_full_game_11_vs_11_easy.py +46 -0
  74. cuju/render/scenarios/benchmark_full_game_11_vs_11_hard.py +46 -0
  75. cuju/render/scenarios/benchmark_full_game_11_vs_11_medium.py +46 -0
  76. cuju/render/scenarios/benchmark_full_game_5_vs_5_easy.py +34 -0
  77. cuju/render/scenarios/benchmark_full_game_5_vs_5_hard.py +34 -0
  78. cuju/render/scenarios/benchmark_full_game_5_vs_5_medium.py +34 -0
  79. cuju/render/web/assets/adboard_polygon.webp +0 -0
  80. cuju/render/web/assets/adboard_your_ad_here.webp +0 -0
  81. cuju/render/web/assets/animations/kaykit-rig-medium-combatmelee.glb +0 -0
  82. cuju/render/web/assets/animations/kaykit-rig-medium-general.glb +0 -0
  83. cuju/render/web/assets/animations/kaykit-rig-medium-movementadvanced.glb +0 -0
  84. cuju/render/web/assets/animations/kaykit-rig-medium-movementbasic.glb +0 -0
  85. cuju/render/web/assets/animations/kaykit-rig-medium-simulation.glb +0 -0
  86. cuju/render/web/assets/animations/kaykit-rig-medium-special.glb +0 -0
  87. cuju/render/web/assets/ball.glb +0 -0
  88. cuju/render/web/assets/challenges/3_vs_1_with_keeper.mp4 +0 -0
  89. cuju/render/web/assets/challenges/3_vs_1_with_keeper.webp +0 -0
  90. cuju/render/web/assets/challenges/corner.mp4 +0 -0
  91. cuju/render/web/assets/challenges/corner.webp +0 -0
  92. cuju/render/web/assets/challenges/counterattack_easy.mp4 +0 -0
  93. cuju/render/web/assets/challenges/counterattack_easy.webp +0 -0
  94. cuju/render/web/assets/challenges/counterattack_hard.mp4 +0 -0
  95. cuju/render/web/assets/challenges/counterattack_hard.webp +0 -0
  96. cuju/render/web/assets/challenges/empty_goal.mp4 +0 -0
  97. cuju/render/web/assets/challenges/empty_goal.webp +0 -0
  98. cuju/render/web/assets/challenges/empty_goal_close.mp4 +0 -0
  99. cuju/render/web/assets/challenges/empty_goal_close.webp +0 -0
  100. cuju/render/web/assets/challenges/manifest.json +375 -0
  101. cuju/render/web/assets/challenges/one_on_one.mp4 +0 -0
  102. cuju/render/web/assets/challenges/one_on_one.webp +0 -0
  103. cuju/render/web/assets/challenges/one_on_one_hard.mp4 +0 -0
  104. cuju/render/web/assets/challenges/one_on_one_hard.webp +0 -0
  105. cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.mp4 +0 -0
  106. cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.webp +0 -0
  107. cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.mp4 +0 -0
  108. cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.webp +0 -0
  109. cuju/render/web/assets/challenges/run_to_score.mp4 +0 -0
  110. cuju/render/web/assets/challenges/run_to_score.webp +0 -0
  111. cuju/render/web/assets/challenges/run_to_score_with_keeper.mp4 +0 -0
  112. cuju/render/web/assets/challenges/run_to_score_with_keeper.webp +0 -0
  113. cuju/render/web/assets/challenges/single_goal_versus_lazy.mp4 +0 -0
  114. cuju/render/web/assets/challenges/single_goal_versus_lazy.webp +0 -0
  115. cuju/render/web/assets/crowd.webp +0 -0
  116. cuju/render/web/assets/crowd_normal.webp +0 -0
  117. cuju/render/web/assets/cuju-logo-384.png +0 -0
  118. cuju/render/web/assets/cuju-logo.png +0 -0
  119. cuju/render/web/assets/cuju-logo.svg +46 -0
  120. cuju/render/web/assets/cuju-mark-light.svg +33 -0
  121. cuju/render/web/assets/cuju-mark.svg +33 -0
  122. cuju/render/web/assets/goal.glb +0 -0
  123. cuju/render/web/assets/grass.webp +0 -0
  124. cuju/render/web/assets/hair_black.png +0 -0
  125. cuju/render/web/assets/hair_blonde.png +0 -0
  126. cuju/render/web/assets/hair_brown.png +0 -0
  127. cuju/render/web/assets/hair_darkblonde.png +0 -0
  128. cuju/render/web/assets/hair_long01.glb +0 -0
  129. cuju/render/web/assets/hair_long02.glb +0 -0
  130. cuju/render/web/assets/hair_medium01.glb +0 -0
  131. cuju/render/web/assets/hair_red.png +0 -0
  132. cuju/render/web/assets/hair_short01.glb +0 -0
  133. cuju/render/web/assets/hair_short02.glb +0 -0
  134. cuju/render/web/assets/icons/cuju-192.png +0 -0
  135. cuju/render/web/assets/icons/cuju-512.png +0 -0
  136. cuju/render/web/assets/icons/cuju-maskable-512.png +0 -0
  137. cuju/render/web/assets/kit_goalkeeper.webp +0 -0
  138. cuju/render/web/assets/kit_mask.png +0 -0
  139. cuju/render/web/assets/kit_normal.webp +0 -0
  140. cuju/render/web/assets/manifest.json +601 -0
  141. cuju/render/web/assets/models/kaykit-barbarian.glb +0 -0
  142. cuju/render/web/assets/models/kaykit-barbarian.json +23 -0
  143. cuju/render/web/assets/models/kaykit-knight.glb +0 -0
  144. cuju/render/web/assets/models/kaykit-knight.json +23 -0
  145. cuju/render/web/assets/models/kaykit-mage.glb +0 -0
  146. cuju/render/web/assets/models/kaykit-mage.json +23 -0
  147. cuju/render/web/assets/models/kaykit-mannequin-medium.glb +0 -0
  148. cuju/render/web/assets/models/kaykit-mannequin-medium.json +23 -0
  149. cuju/render/web/assets/models/kaykit-ranger.glb +0 -0
  150. cuju/render/web/assets/models/kaykit-ranger.json +23 -0
  151. cuju/render/web/assets/models/kaykit-rogue-hooded.glb +0 -0
  152. cuju/render/web/assets/models/kaykit-rogue-hooded.json +23 -0
  153. cuju/render/web/assets/models/kaykit-rogue.glb +0 -0
  154. cuju/render/web/assets/models/kaykit-rogue.json +23 -0
  155. cuju/render/web/assets/models/kaykit-skeleton-mage.glb +0 -0
  156. cuju/render/web/assets/models/kaykit-skeleton-mage.json +23 -0
  157. cuju/render/web/assets/models/kaykit-skeleton-minion.glb +0 -0
  158. cuju/render/web/assets/models/kaykit-skeleton-minion.json +23 -0
  159. cuju/render/web/assets/models/kaykit-skeleton-rogue.glb +0 -0
  160. cuju/render/web/assets/models/kaykit-skeleton-rogue.json +23 -0
  161. cuju/render/web/assets/models/kaykit-skeleton-warrior.glb +0 -0
  162. cuju/render/web/assets/models/kaykit-skeleton-warrior.json +23 -0
  163. cuju/render/web/assets/pitch.webp +0 -0
  164. cuju/render/web/assets/pitch_normal.webp +0 -0
  165. cuju/render/web/assets/player.glb +0 -0
  166. cuju/render/web/assets/shoe.webp +0 -0
  167. cuju/render/web/assets/shoe_sole.png +0 -0
  168. cuju/render/web/assets/skin_01.png +0 -0
  169. cuju/render/web/assets/skin_02.png +0 -0
  170. cuju/render/web/assets/skin_03.png +0 -0
  171. cuju/render/web/assets/skin_04.png +0 -0
  172. cuju/render/web/assets/sounds/applause.ogg +0 -0
  173. cuju/render/web/assets/sounds/beach-wave-1.ogg +0 -0
  174. cuju/render/web/assets/sounds/beach-wave-2.ogg +0 -0
  175. cuju/render/web/assets/sounds/beach-wave-3.ogg +0 -0
  176. cuju/render/web/assets/sounds/beach-wave-4.ogg +0 -0
  177. cuju/render/web/assets/sounds/city-horn.ogg +0 -0
  178. cuju/render/web/assets/sounds/city-loop.ogg +0 -0
  179. cuju/render/web/assets/sounds/city-siren.ogg +0 -0
  180. cuju/render/web/assets/sounds/crowd-cheer.ogg +0 -0
  181. cuju/render/web/assets/sounds/crowd-loop.ogg +0 -0
  182. cuju/render/web/assets/sounds/crowd-ooh.ogg +0 -0
  183. cuju/render/web/assets/sounds/gulls.ogg +0 -0
  184. cuju/render/web/assets/sounds/neon-sting.ogg +0 -0
  185. cuju/render/web/assets/sounds/rain-loop.ogg +0 -0
  186. cuju/render/web/assets/sounds/sounds.json +46 -0
  187. cuju/render/web/assets/sounds/space-beep.ogg +0 -0
  188. cuju/render/web/assets/sounds/space-hum.ogg +0 -0
  189. cuju/render/web/assets/sounds/space-radio.ogg +0 -0
  190. cuju/render/web/assets/sounds/whistle-long.ogg +0 -0
  191. cuju/render/web/assets/sounds/whistle-short.ogg +0 -0
  192. cuju/render/web/assets/sounds/wind-loop.ogg +0 -0
  193. cuju/render/web/easy.css +357 -0
  194. cuju/render/web/export.html +23 -0
  195. cuju/render/web/feed.css +262 -0
  196. cuju/render/web/feed.html +28 -0
  197. cuju/render/web/flat.css +120 -0
  198. cuju/render/web/home.css +837 -0
  199. cuju/render/web/index.html +373 -0
  200. cuju/render/web/js/boot.js +50 -0
  201. cuju/render/web/js/broadcast/audio.js +2141 -0
  202. cuju/render/web/js/broadcast/celebrate.js +1238 -0
  203. cuju/render/web/js/broadcast/decisions.js +609 -0
  204. cuju/render/web/js/broadcast/hud.js +352 -0
  205. cuju/render/web/js/broadcast/show.js +3614 -0
  206. cuju/render/web/js/broadcast/transition.js +2231 -0
  207. cuju/render/web/js/broadcast/voices.js +153 -0
  208. cuju/render/web/js/capture.js +101 -0
  209. cuju/render/web/js/core/accessibility.js +90 -0
  210. cuju/render/web/js/core/api.js +429 -0
  211. cuju/render/web/js/core/comfort.js +135 -0
  212. cuju/render/web/js/core/i18n.js +705 -0
  213. cuju/render/web/js/core/icons.js +167 -0
  214. cuju/render/web/js/core/input-settings.js +156 -0
  215. cuju/render/web/js/core/keys.js +277 -0
  216. cuju/render/web/js/core/language-ui.js +125 -0
  217. cuju/render/web/js/core/menu.js +853 -0
  218. cuju/render/web/js/core/names.js +113 -0
  219. cuju/render/web/js/core/page-structure.js +110 -0
  220. cuju/render/web/js/core/scenarios.js +109 -0
  221. cuju/render/web/js/core/spoilers.js +236 -0
  222. cuju/render/web/js/core/typeahead.js +38 -0
  223. cuju/render/web/js/export/dom-picture.js +330 -0
  224. cuju/render/web/js/export/export-host.js +97 -0
  225. cuju/render/web/js/export/feed-dialog.js +191 -0
  226. cuju/render/web/js/export/feed-params.js +266 -0
  227. cuju/render/web/js/export/feed.js +363 -0
  228. cuju/render/web/js/export/mp4-mux.js +295 -0
  229. cuju/render/web/js/export/photo-core.js +313 -0
  230. cuju/render/web/js/export/photo.js +1314 -0
  231. cuju/render/web/js/export/safe-frame.js +59 -0
  232. cuju/render/web/js/export/size-fields.js +103 -0
  233. cuju/render/web/js/export/sizes.js +178 -0
  234. cuju/render/web/js/export/video-boot.js +55 -0
  235. cuju/render/web/js/export/video-browser.js +325 -0
  236. cuju/render/web/js/export/video-export.js +417 -0
  237. cuju/render/web/js/export/video-plan.js +207 -0
  238. cuju/render/web/js/export/video-range.js +185 -0
  239. cuju/render/web/js/export/webm-mux.js +198 -0
  240. cuju/render/web/js/feed-boot.js +151 -0
  241. cuju/render/web/js/feed-frame.js +101 -0
  242. cuju/render/web/js/help/doctor.js +488 -0
  243. cuju/render/web/js/help/firstrun.js +379 -0
  244. cuju/render/web/js/help/help-center.js +438 -0
  245. cuju/render/web/js/help/install-offer.js +164 -0
  246. cuju/render/web/js/help/install-state.js +104 -0
  247. cuju/render/web/js/help/lessons-core.js +207 -0
  248. cuju/render/web/js/help/lessons.js +463 -0
  249. cuju/render/web/js/help/palette.js +584 -0
  250. cuju/render/web/js/help/pwa.js +257 -0
  251. cuju/render/web/js/help/tour-core.js +241 -0
  252. cuju/render/web/js/help/tour.js +461 -0
  253. cuju/render/web/js/main.js +2513 -0
  254. cuju/render/web/js/pages/draw.js +188 -0
  255. cuju/render/web/js/pages/fieldpage.js +530 -0
  256. cuju/render/web/js/pages/home.js +521 -0
  257. cuju/render/web/js/pages/matches.js +779 -0
  258. cuju/render/web/js/pages/moments-ui.js +359 -0
  259. cuju/render/web/js/pages/queue-filters.js +63 -0
  260. cuju/render/web/js/pages/recording-groups.js +80 -0
  261. cuju/render/web/js/pages/recordings.js +1069 -0
  262. cuju/render/web/js/play/bench.js +347 -0
  263. cuju/render/web/js/play/challenges.js +1302 -0
  264. cuju/render/web/js/play/medals.js +127 -0
  265. cuju/render/web/js/play/play.js +1953 -0
  266. cuju/render/web/js/play/teasers.js +196 -0
  267. cuju/render/web/js/play/touch.js +350 -0
  268. cuju/render/web/js/play/tournament-layout.js +487 -0
  269. cuju/render/web/js/play/tournament-results.js +441 -0
  270. cuju/render/web/js/play/tournament-strict.js +560 -0
  271. cuju/render/web/js/play/tournament.js +2585 -0
  272. cuju/render/web/js/players/animate.js +972 -0
  273. cuju/render/web/js/players/clips.js +224 -0
  274. cuju/render/web/js/players/kaykit.js +162 -0
  275. cuju/render/web/js/players/kits.js +676 -0
  276. cuju/render/web/js/players/number-patch.js +82 -0
  277. cuju/render/web/js/players/players.js +2694 -0
  278. cuju/render/web/js/players/recolor.js +893 -0
  279. cuju/render/web/js/players/retarget.js +325 -0
  280. cuju/render/web/js/players/rig-numbers.js +174 -0
  281. cuju/render/web/js/presentation/animator.js +231 -0
  282. cuju/render/web/js/presentation/assign.js +85 -0
  283. cuju/render/web/js/presentation/behaviors.js +440 -0
  284. cuju/render/web/js/presentation/budget.js +209 -0
  285. cuju/render/web/js/presentation/catalog.js +1674 -0
  286. cuju/render/web/js/presentation/clocks.js +72 -0
  287. cuju/render/web/js/presentation/commands.js +301 -0
  288. cuju/render/web/js/presentation/contract.js +240 -0
  289. cuju/render/web/js/presentation/effects.js +904 -0
  290. cuju/render/web/js/presentation/flash.js +605 -0
  291. cuju/render/web/js/presentation/freeze-worklet.js +22 -0
  292. cuju/render/web/js/presentation/glsl.js +464 -0
  293. cuju/render/web/js/presentation/host.js +323 -0
  294. cuju/render/web/js/presentation/index.js +2066 -0
  295. cuju/render/web/js/presentation/loudness-worklet.js +235 -0
  296. cuju/render/web/js/presentation/loudness.js +740 -0
  297. cuju/render/web/js/presentation/moments.js +536 -0
  298. cuju/render/web/js/presentation/post.js +327 -0
  299. cuju/render/web/js/presentation/preview.js +180 -0
  300. cuju/render/web/js/presentation/protocol.js +174 -0
  301. cuju/render/web/js/presentation/reach.js +158 -0
  302. cuju/render/web/js/presentation/rigging.js +130 -0
  303. cuju/render/web/js/presentation/sandbox.js +157 -0
  304. cuju/render/web/js/presentation/shaders.js +235 -0
  305. cuju/render/web/js/presentation/stage.js +402 -0
  306. cuju/render/web/js/presentation/teamaudio.js +722 -0
  307. cuju/render/web/js/presentation/tracks.js +197 -0
  308. cuju/render/web/js/presentation/values.js +81 -0
  309. cuju/render/web/js/recording/annotation-data.js +203 -0
  310. cuju/render/web/js/recording/captions.js +491 -0
  311. cuju/render/web/js/recording/codec.js +185 -0
  312. cuju/render/web/js/recording/decode-worker.js +70 -0
  313. cuju/render/web/js/recording/decode.js +94 -0
  314. cuju/render/web/js/recording/episodes.js +46 -0
  315. cuju/render/web/js/recording/format.js +461 -0
  316. cuju/render/web/js/recording/live.js +348 -0
  317. cuju/render/web/js/recording/moments-query.js +59 -0
  318. cuju/render/web/js/recording/moments.js +149 -0
  319. cuju/render/web/js/recording/pose.js +86 -0
  320. cuju/render/web/js/recording/timeline.js +275 -0
  321. cuju/render/web/js/teams/art.js +50 -0
  322. cuju/render/web/js/teams/clip-editor.js +293 -0
  323. cuju/render/web/js/teams/editor.js +1979 -0
  324. cuju/render/web/js/teams/library.js +344 -0
  325. cuju/render/web/js/teams/painter.js +633 -0
  326. cuju/render/web/js/teams/surprise-ui.js +195 -0
  327. cuju/render/web/js/teams/surprise.js +497 -0
  328. cuju/render/web/js/teams/team-check.js +127 -0
  329. cuju/render/web/js/watch/annotations.js +270 -0
  330. cuju/render/web/js/watch/flat.js +366 -0
  331. cuju/render/web/js/watch/grid.js +436 -0
  332. cuju/render/web/js/watch/pitch2d.js +289 -0
  333. cuju/render/web/js/watch/player-tools.js +192 -0
  334. cuju/render/web/js/watch/presets.js +201 -0
  335. cuju/render/web/js/world/arenas.js +997 -0
  336. cuju/render/web/js/world/ball.js +204 -0
  337. cuju/render/web/js/world/cameras.js +982 -0
  338. cuju/render/web/js/world/crowd.js +376 -0
  339. cuju/render/web/js/world/field.js +227 -0
  340. cuju/render/web/js/world/framing.js +145 -0
  341. cuju/render/web/js/world/occlusion.js +48 -0
  342. cuju/render/web/js/world/pitch.js +703 -0
  343. cuju/render/web/js/world/scene.js +395 -0
  344. cuju/render/web/js/world/sky.js +325 -0
  345. cuju/render/web/js/world/stadium.js +1262 -0
  346. cuju/render/web/js/world/vendor-sky.js +367 -0
  347. cuju/render/web/js/world/weather.js +264 -0
  348. cuju/render/web/languages/en.json +4750 -0
  349. cuju/render/web/lessons.json +137 -0
  350. cuju/render/web/manifest.webmanifest +23 -0
  351. cuju/render/web/style.css +8399 -0
  352. cuju/render/web/sw.js +235 -0
  353. cuju/render/web/vendor/fabric/LICENSE +16 -0
  354. cuju/render/web/vendor/fabric/fabric.min.mjs +1 -0
  355. cuju/render/web/vendor/lucide/LICENSE +43 -0
  356. cuju/render/web/vendor/lucide/icons.js +141 -0
  357. cuju/render/web/vendor/three/LICENSE +21 -0
  358. cuju/render/web/vendor/three/build/three.core.js +60586 -0
  359. cuju/render/web/vendor/three/build/three.module.js +19719 -0
  360. cuju/render/web/vendor/three/examples/jsm/loaders/GLTFLoader.js +4925 -0
  361. cuju/render/web/vendor/three/examples/jsm/postprocessing/EffectComposer.js +365 -0
  362. cuju/render/web/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  363. cuju/render/web/vendor/three/examples/jsm/postprocessing/OutputPass.js +148 -0
  364. cuju/render/web/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  365. cuju/render/web/vendor/three/examples/jsm/postprocessing/RenderPass.js +193 -0
  366. cuju/render/web/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  367. cuju/render/web/vendor/three/examples/jsm/postprocessing/UnrealBloomPass.js +541 -0
  368. cuju/render/web/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  369. cuju/render/web/vendor/three/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
  370. cuju/render/web/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  371. cuju/render/web/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1501 -0
  372. cuju/render/web/vendor/three/examples/jsm/utils/SkeletonUtils.js +496 -0
  373. cuju_render-0.1.0.dist-info/METADATA +116 -0
  374. cuju_render-0.1.0.dist-info/RECORD +382 -0
  375. cuju_render-0.1.0.dist-info/WHEEL +4 -0
  376. cuju_render-0.1.0.dist-info/licenses/LICENSE +202 -0
  377. cuju_render-0.1.0.dist-info/licenses/LICENSES/CC-BY-4.0.txt +396 -0
  378. cuju_render-0.1.0.dist-info/licenses/LICENSES/CC0-1.0.txt +127 -0
  379. cuju_render-0.1.0.dist-info/licenses/LICENSES/ISC.txt +16 -0
  380. cuju_render-0.1.0.dist-info/licenses/LICENSES/MIT.txt +24 -0
  381. cuju_render-0.1.0.dist-info/licenses/LICENSES/Unlicense.txt +13 -0
  382. cuju_render-0.1.0.dist-info/licenses/NOTICE +35 -0
@@ -0,0 +1,1069 @@
1
+ // Copyright 2026 The cuju Authors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // The Recordings page, a file explorer with a folder tree, a sortable table with search, filters
5
+ // and a selection of many rows, rename, move, details, and dragging recordings onto folders. A
6
+ // deleted recording goes to the Trash, which restores it or deletes it for good. The recordings of
7
+ // one run of a challenge show as one group row, which opens to the rows of its attempts.
8
+
9
+ import { api, formatBytes, formatDate } from '../core/api.js';
10
+ import { plainText, serverText, t, tn } from '../core/i18n.js';
11
+ import { h, listKeys } from '../teams/library.js';
12
+ import { Dropdown, enhanceSelect, menuHeading, menuItem } from '../core/menu.js';
13
+ import { icon, labelText, relabel, symbolOnly } from '../core/icons.js';
14
+ import { recordingTitle, summaryTeams } from '../core/names.js';
15
+ import { groupRows, groupTotals, navigationRows } from './recording-groups.js';
16
+ import { scenarioName } from '../core/scenarios.js';
17
+ import { fold } from '../core/typeahead.js';
18
+
19
+ const FOLDERS_KEY = 'cuju.folders';
20
+ const COLUMNS = [
21
+ { key: 'title' },
22
+ { key: 'teams' },
23
+ { key: 'score', numeric: true },
24
+ { key: 'scenario' },
25
+ { key: 'steps', numeric: true },
26
+ { key: 'created' },
27
+ { key: 'bytes', numeric: true },
28
+ ].map((column) => ({ ...column, label: t(`recordings.column.${column.key}`) }));
29
+ // The choices of a select, each value with the message of its label, whose id is the prefix and
30
+ // the value with its colons as dots.
31
+ const choices = (prefix, values) => values.map((v) => [v, t(`${prefix}.${v.replace(/:/g, '.')}`)]);
32
+ const SORTS = choices('recordings.sort', ['created:-1', 'created:1', 'title:1', 'score:-1', 'teams:1', 'steps:-1', 'bytes:-1']);
33
+ const RANGES = choices('recordings.range', ['any', 'today', 'week', 'month', 'year']);
34
+ const SOURCES = Object.fromEntries(['requested_match', 'human_game', 'challenge', 'recorder', 'live', 'unknown']
35
+ .map((key) => [key, t(`recordings.source.${key}`)]));
36
+ const RESULTS = choices('recordings.result', ['all', 'left', 'right', 'draw', 'unknown']);
37
+ const DEFAULT_FILTERS = { scenario: 'all', team: 'all', range: 'any', favorite: 'all', source: 'all', result: 'all' };
38
+ // The provenance fields in the order and with the names the details panel shows.
39
+ const PROVENANCE = ['source', 'cuju_version', 'seed', 'scenario', 'teams', 'humans', 'controls', 'agent_counts',
40
+ 'action_set', 'ability', 'late_steps', 'environment'].map((key) => [key, t(`recordings.provenance.${key}`)]);
41
+
42
+ // The teams of a recording joined, such as Greens against Blues.
43
+ function joinTeams(teams) {
44
+ return teams.length ? teams.map((v) => (v == null ? '' : String(v))).reduce((left, right) => t('recordings.teams', { left, right })) : '';
45
+ }
46
+
47
+ // The values of the left and right side joined, such as person and built-in AI, and more in turn.
48
+ function joinSides(values) {
49
+ return values.length ? values.reduce((left, right) => t('recordings.provenance.sides', { left, right })) : '';
50
+ }
51
+
52
+ function sourceOf(m) {
53
+ const source = m.provenance && m.provenance.source;
54
+ return typeof source === 'string' && source ? source : 'unknown';
55
+ }
56
+
57
+ // The result of a recording from its final score, unknown for a recording without one.
58
+ function resultOf(m) {
59
+ if (!Array.isArray(m.score) || m.score.length !== 2) {
60
+ return 'unknown';
61
+ }
62
+ const [a, b] = m.score;
63
+ return a === b ? 'draw' : a > b ? 'left' : 'right';
64
+ }
65
+
66
+ function provenanceValue(key, value, provenance = {}) {
67
+ if (key === 'source') {
68
+ return SOURCES[value] || String(value);
69
+ }
70
+ if (key === 'scenario') {
71
+ return scenarioName(value);
72
+ }
73
+ if (key === 'humans' && Array.isArray(value)) {
74
+ // A side without a person is the built-in AI unless a registered team played it.
75
+ const teams = Array.isArray(provenance.teams) ? provenance.teams : [];
76
+ return joinSides(value.map((v, side) => t(v ? 'recordings.provenance.person'
77
+ : teams[side] && teams[side] !== 'builtin' ? 'recordings.provenance.registered' : 'recordings.provenance.builtin')));
78
+ }
79
+ if (Array.isArray(value) && value.every((v) => v === null || typeof v !== 'object')) {
80
+ return joinSides(value.map((v) => (v === null ? t('recordings.provenance.scenarioValue') : String(v))));
81
+ }
82
+ return typeof value === 'object' && value !== null ? JSON.stringify(value) : String(value);
83
+ }
84
+
85
+ // The routes of the groups of recordings, which move or restore a whole run at once.
86
+ async function groupCall(method, path) {
87
+ let res;
88
+ try {
89
+ res = await fetch(path, { method, cache: 'no-store' });
90
+ } catch {
91
+ throw new Error(t('api.unreachable', { origin: location.origin }));
92
+ }
93
+ const data = await res.json().catch(() => null);
94
+ if (!res.ok) {
95
+ throw new Error((data && data.error && serverText(data, 'error')) || t('api.status', { status: res.status, text: res.statusText }));
96
+ }
97
+ return data;
98
+ }
99
+
100
+ export const groupApi = {
101
+ list: (id, trash = false) => groupCall('GET', `/api/${trash ? 'trash' : 'matches'}?group=${encodeURIComponent(id)}`),
102
+ trash: (id) => groupCall('DELETE', `/api/groups/${encodeURIComponent(id)}`),
103
+ restore: (id) => groupCall('POST', `/api/groups/${encodeURIComponent(id)}/restore`),
104
+ };
105
+
106
+ function loadFolders() {
107
+ try {
108
+ const v = JSON.parse(localStorage.getItem(FOLDERS_KEY) || '[]');
109
+ return Array.isArray(v) ? v.filter((f) => typeof f === 'string') : [];
110
+ } catch {
111
+ return [];
112
+ }
113
+ }
114
+
115
+ function saveFolders(list) {
116
+ try {
117
+ localStorage.setItem(FOLDERS_KEY, JSON.stringify(list));
118
+ } catch {
119
+ // Empty folders then last for this visit only.
120
+ }
121
+ }
122
+
123
+ function cleanPath(path) {
124
+ return path.split('/').map((p) => p.trim()).filter(Boolean).join('/');
125
+ }
126
+
127
+ function createdMs(m) {
128
+ return typeof m.created === 'number' ? (m.created < 1e12 ? m.created * 1000 : m.created) : Date.parse(m.created) || 0;
129
+ }
130
+
131
+ // Sort keys, a score by its total of goals and then by its margin.
132
+ function sortValue(m, key) {
133
+ switch (key) {
134
+ case 'teams':
135
+ return summaryTeams(m).join(' ').toLowerCase();
136
+ case 'title':
137
+ return (recordingTitle(m) || m.id || '').toLowerCase();
138
+ case 'score': {
139
+ const [a, b] = m.score || [0, 0];
140
+ return (a + b) * 1000 + Math.abs(a - b);
141
+ }
142
+ case 'created':
143
+ return createdMs(m);
144
+ case 'steps':
145
+ case 'bytes':
146
+ return Number(m[key]) || 0;
147
+ default:
148
+ return String(m[key] || '').toLowerCase();
149
+ }
150
+ }
151
+
152
+ function inRange(m, range) {
153
+ if (range === 'any') {
154
+ return true;
155
+ }
156
+ const t = createdMs(m);
157
+ const now = new Date();
158
+ if (range === 'today') {
159
+ return t >= new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
160
+ }
161
+ if (range === 'week') {
162
+ return t >= now.getTime() - 7 * 864e5;
163
+ }
164
+ if (range === 'month') {
165
+ return t >= now.getTime() - 30 * 864e5;
166
+ }
167
+ return t >= new Date(now.getFullYear(), 0, 1).getTime();
168
+ }
169
+
170
+ export class RecordingsPage {
171
+ constructor(app) {
172
+ this.app = app;
173
+ this.root = document.getElementById('page-recordings');
174
+ this.list = [];
175
+ // The folder shown, empty for every recording.
176
+ this.folder = '';
177
+ this.selected = new Set();
178
+ this.anchor = null;
179
+ this.sortKey = 'created';
180
+ this.sortDir = -1;
181
+ this.query = '';
182
+ this.filters = { ...DEFAULT_FILTERS };
183
+ this.extraFolders = loadFolders();
184
+ this.error = null;
185
+ // Whether the page shows the Trash instead of the library.
186
+ this.trash = false;
187
+ // The recording whose details are open, or null.
188
+ this.editing = null;
189
+ // The groups shown open, by identifier.
190
+ this.open = new Set();
191
+ // The rows that the keyboard walks, groups and recordings in the order of the table.
192
+ this.nav = [];
193
+ }
194
+
195
+ async refresh() {
196
+ try {
197
+ this.list = await (this.trash ? api.trash() : api.matches());
198
+ this.error = null;
199
+ } catch (err) {
200
+ this.error = err;
201
+ }
202
+ const ids = new Set(this.list.map((m) => m.id));
203
+ if (this.editing && !ids.has(this.editing)) {
204
+ this.editing = null;
205
+ }
206
+ this.selected = new Set([...this.selected].filter((id) => ids.has(id)));
207
+ if (this.folder && !this.folders().includes(this.folder)) {
208
+ this.folder = '';
209
+ }
210
+ this.render();
211
+ }
212
+
213
+ folders() {
214
+ const all = new Set(['']);
215
+ const add = (path) => {
216
+ const parts = cleanPath(path || '').split('/').filter(Boolean);
217
+ for (let i = 1; i <= parts.length; i++) {
218
+ all.add(parts.slice(0, i).join('/'));
219
+ }
220
+ };
221
+ for (const m of this.list) {
222
+ add(m.folder);
223
+ }
224
+ for (const f of this.extraFolders) {
225
+ add(f);
226
+ }
227
+ return [...all].sort((a, b) => a.localeCompare(b));
228
+ }
229
+
230
+ inFolder(m, path) {
231
+ const f = cleanPath(m.folder || '');
232
+ return !path || f === path || f.startsWith(`${path}/`);
233
+ }
234
+
235
+ visible() {
236
+ // Case and accents never matter, as in the menus and the search of moments.
237
+ const q = fold(this.query.trim());
238
+ const f = this.filters;
239
+ let rows = this.list.filter((m) => {
240
+ if (q) {
241
+ const group = m.group ? [m.group.title, serverText(m.group, 'title')] : [];
242
+ const text = fold([m.title, recordingTitle(m), ...(m.teams || []), ...summaryTeams(m), ...(m.tags || []), m.notes, m.scenario, scenarioName(m.scenario), m.folder, ...group].map(plainText).join(' '));
243
+ if (!text.includes(q)) {
244
+ return false;
245
+ }
246
+ } else if (!this.inFolder(m, this.folder)) {
247
+ return false;
248
+ }
249
+ if (f.scenario !== 'all' && m.scenario !== f.scenario) {
250
+ return false;
251
+ }
252
+ if (f.team !== 'all' && !(m.teams || []).includes(f.team)) {
253
+ return false;
254
+ }
255
+ if (f.favorite === 'yes' && !m.favorite) {
256
+ return false;
257
+ }
258
+ if (f.source !== 'all' && sourceOf(m) !== f.source) {
259
+ return false;
260
+ }
261
+ if (f.result !== 'all' && resultOf(m) !== f.result) {
262
+ return false;
263
+ }
264
+ return inRange(m, f.range);
265
+ });
266
+ rows = rows.slice().sort((a, b) => {
267
+ const x = sortValue(a, this.sortKey);
268
+ const y = sortValue(b, this.sortKey);
269
+ return (x < y ? -1 : x > y ? 1 : 0) * this.sortDir;
270
+ });
271
+ return rows;
272
+ }
273
+
274
+ // A select of the toolbar, made a dropdown, whose change runs pick. Its look is the words of
275
+ // a prefix, or a symbol given as { icon }, which then stands in front of the value.
276
+ filterSelect(label, look, entries, value, pick, align = 'left') {
277
+ const el = h('select', { 'aria-label': label }, entries.map(([v, t]) => h('option', { value: v }, t)));
278
+ el.value = entries.some(([v]) => v === value) ? value : entries[0][0];
279
+ el.addEventListener('change', () => pick(el.value));
280
+ queueMicrotask(() => enhanceSelect(el, { label, ...(typeof look === 'string' ? { prefix: look } : look), align }));
281
+ return el;
282
+ }
283
+
284
+ render() {
285
+ const tree = this.renderTree();
286
+ const search = h('input', { type: 'search', placeholder: t('recordings.search.placeholder'), value: this.query, class: 'search', 'aria-label': t('recordings.search.label') });
287
+ search.addEventListener('input', () => {
288
+ this.query = search.value;
289
+ this.renderTree(true);
290
+ this.renderTable();
291
+ });
292
+ const scenarios = [...new Set(this.list.map((m) => m.scenario).filter(Boolean))].sort();
293
+ // The filter keeps the English name of a team, which the summaries hold, and shows it in the
294
+ // page's language.
295
+ const shownTeams = new Map(this.list.flatMap((m) => (m.teams || []).map((name, i) => [name, summaryTeams(m)[i]])));
296
+ const teams = [...shownTeams.keys()].sort((a, b) => shownTeams.get(a).localeCompare(shownTeams.get(b)));
297
+ const folderNames = this.folders();
298
+ const sources = [...new Set(this.list.map(sourceOf))].sort();
299
+ if (!sources.includes(this.filters.source)) {
300
+ this.filters.source = 'all';
301
+ }
302
+ const filters = h('div', { class: 'filter-bar' },
303
+ this.filterSelect(t('recordings.filter.view'), { icon: (v) => (v === 'trash' ? 'trash' : 'archive') }, [['library', t('recordings.view.library')], ['trash', t('recordings.view.trash')]], this.trash ? 'trash' : 'library', (v) => {
304
+ this.trash = v === 'trash';
305
+ this.selected.clear();
306
+ this.editing = null;
307
+ this.refresh();
308
+ }),
309
+ this.filterSelect(t('recordings.filter.folder'), { icon: 'folder' }, folderNames.map((p) => [p, p || t('recordings.folder.any')]), this.folder, (v) => {
310
+ this.folder = v;
311
+ this.query = '';
312
+ this.selected.clear();
313
+ this.render();
314
+ }),
315
+ this.filterSelect(t('recordings.filter.scenario'), { icon: 'field' }, [['all', t('recordings.scenario.any')], ...scenarios.map((s) => [s, scenarioName(s)])], this.filters.scenario, (v) => {
316
+ this.filters.scenario = v;
317
+ this.renderTable();
318
+ }),
319
+ this.filterSelect(t('recordings.filter.team'), { icon: 'shirt' }, [['all', t('recordings.team.any')], ...teams.map((name) => [name, shownTeams.get(name)])], this.filters.team, (v) => {
320
+ this.filters.team = v;
321
+ this.renderTable();
322
+ }),
323
+ this.filterSelect(t('recordings.filter.date'), { icon: 'calendar' }, RANGES, this.filters.range, (v) => {
324
+ this.filters.range = v;
325
+ this.renderTable();
326
+ }),
327
+ this.filterSelect(t('recordings.filter.favorites'), { icon: 'star' }, [['all', t('recordings.favorite.all')], ['yes', t('recordings.favorite.yes')]], this.filters.favorite, (v) => {
328
+ this.filters.favorite = v;
329
+ this.renderTable();
330
+ }),
331
+ this.filterSelect(t('recordings.filter.source'), t('recordings.filter.source'), [['all', t('recordings.source.any')], ...sources.map((v) => [v, SOURCES[v] || v])], this.filters.source, (v) => {
332
+ this.filters.source = v;
333
+ this.renderTable();
334
+ }),
335
+ this.filterSelect(t('recordings.filter.result'), t('recordings.filter.result'), RESULTS, this.filters.result, (v) => {
336
+ this.filters.result = v;
337
+ this.renderTable();
338
+ }),
339
+ this.sortSelectEl = this.filterSelect(t('recordings.filter.sort'), { icon: 'sort' }, SORTS, `${this.sortKey}:${this.sortDir}`, (v) => {
340
+ const [key, dir] = v.split(':');
341
+ this.sortKey = key;
342
+ this.sortDir = Number(dir);
343
+ this.renderTable();
344
+ }, 'right'));
345
+ this.moveBtn = h('button', { type: 'button', class: 'btn', disabled: true, ...symbolOnly(t('recordings.action.move')) }, icon('folder-move'), h('span', { class: 'dd-caret', 'aria-hidden': 'true' }));
346
+ const movePanel = h('div', { role: 'menu', class: 'move-menu', 'aria-label': t('recordings.move.menu') });
347
+ this.moveDropdown = new Dropdown(this.moveBtn, movePanel, { onOpen: () => this.fillMove(movePanel) });
348
+ const actions = h('div', { class: 'toolbar actions' },
349
+ this.countLabel = h('span', { class: 'muted small selection-count' }),
350
+ h('span', { class: 'spacer' }),
351
+ h('button', { class: 'btn', type: 'button', disabled: true, 'data-act': 'open', ...symbolOnly(t('recordings.action.open')), onclick: () => this.openSelected() }, icon('play')),
352
+ h('button', { class: 'btn', type: 'button', disabled: true, 'data-act': 'rename', ...symbolOnly(t('recordings.action.rename')), onclick: () => this.renameSelected() }, icon('edit')),
353
+ h('button', { class: 'btn', type: 'button', disabled: true, 'data-act': 'details', 'aria-expanded': 'false', ...symbolOnly(t('recordings.action.details')), onclick: () => this.toggleDetails() }, icon('info')),
354
+ h('span', { class: 'dd-wrap' }, this.moveBtn, movePanel),
355
+ h('button', { class: 'btn', type: 'button', disabled: true, hidden: !this.trash, 'data-act': 'restore', ...symbolOnly(t('recordings.action.restore')), onclick: () => this.restoreSelected() }, icon('reset')),
356
+ // Moving to the Trash shows its symbol alone, deleting for good keeps its words beside it.
357
+ this.trash
358
+ ? h('button', { class: 'btn danger', type: 'button', disabled: true, 'data-act': 'delete', onclick: () => this.deleteSelected() }, icon('trash'), labelText(t('recordings.action.purge')))
359
+ : h('button', { class: 'btn danger', type: 'button', disabled: true, 'data-act': 'delete', ...symbolOnly(t('recordings.action.trash')), onclick: () => this.deleteSelected() }, icon('trash')),
360
+ h('button', { class: 'btn ghost', type: 'button', ...symbolOnly(t('recordings.action.refresh'), t(this.trash ? 'recordings.action.refresh.trash' : 'recordings.action.refresh.library')), onclick: () => this.refresh() }, icon('refresh')));
361
+ this.detailsHost = h('div', { class: 'details-host' });
362
+ // The search of moments across every recording, a panel above the table.
363
+ this.momentsHost = h('div', { class: 'moments-host' });
364
+ const momentsToggle = this.app.moments && !this.trash
365
+ ? this.app.moments.mount(this.momentsHost, scenarios.map((s) => [s, scenarioName(s)]), teams) : null;
366
+ this.tableHost = h('div', { class: 'table-host' });
367
+ this.treeHost = h('div', { class: 'tree-host' }, tree);
368
+ this.root.replaceChildren(h('div', { class: 'explorer' },
369
+ h('aside', { class: 'folders', 'aria-label': t('recordings.folders') },
370
+ h('div', { class: 'pane-head' }, h('span', { class: 'label' }, t('recordings.folders')),
371
+ h('button', { class: 'btn small', type: 'button', ...symbolOnly(t('recordings.folder.new')), onclick: () => this.newFolder() }, icon('folder-plus'))),
372
+ this.treeHost),
373
+ h('div', { class: 'files' }, h('div', { class: 'toolbar' }, search, filters, momentsToggle), this.momentsHost, actions, this.detailsHost, this.tableHost)));
374
+ this.renderTable();
375
+ this.renderDetails();
376
+ }
377
+
378
+ // The details of the recording being edited, its favorite mark, tags, notes and provenance.
379
+ renderDetails(focus = false) {
380
+ if (!this.detailsHost) {
381
+ return;
382
+ }
383
+ const m = this.editing && this.list.find((x) => x.id === this.editing);
384
+ const button = this.root.querySelector('.actions [data-act="details"]');
385
+ if (button) {
386
+ button.setAttribute('aria-expanded', m ? 'true' : 'false');
387
+ }
388
+ if (!m || this.trash) {
389
+ this.detailsHost.replaceChildren();
390
+ return;
391
+ }
392
+ const favorite = h('input', { type: 'checkbox', checked: !!m.favorite });
393
+ const tags = h('input', { type: 'text', value: (m.tags || []).join(', '), maxlength: 1000 });
394
+ const notes = h('textarea', { rows: 4, maxlength: 10000 });
395
+ notes.value = m.notes || '';
396
+ const provenance = m.provenance || {};
397
+ const known = PROVENANCE.filter(([key]) => provenance[key] !== undefined && provenance[key] !== null);
398
+ const extra = Object.keys(provenance).filter((key) => !PROVENANCE.some(([k]) => k === key));
399
+ const rows = [...known, ...extra.map((key) => [key, key.replaceAll('_', ' ')])].flatMap(([key, label]) => [
400
+ h('dt', {}, label), h('dd', {}, provenanceValue(key, provenance[key], provenance))]);
401
+ const save = h('button', { class: 'btn primary', type: 'submit', ...symbolOnly(t('recordings.details.save')) }, icon('save'));
402
+ const close = () => {
403
+ this.editing = null;
404
+ this.renderDetails();
405
+ const again = this.root.querySelector('.actions [data-act="details"]');
406
+ if (again && !again.disabled) {
407
+ again.focus();
408
+ }
409
+ };
410
+ const form = h('form', { class: 'recording-details', 'aria-label': t('recordings.details.label', { title: recordingTitle(m) || m.id }) },
411
+ h('h3', {}, recordingTitle(m) || m.id),
412
+ h('label', { class: 'check' }, favorite, t('recordings.details.favorite')),
413
+ h('label', { class: 'field' }, t('recordings.details.tags'), tags),
414
+ h('label', { class: 'field' }, t('recordings.details.notes'), notes),
415
+ h('div', { class: 'provenance' },
416
+ h('h4', {}, t('recordings.details.provenance')),
417
+ rows.length ? h('dl', {}, rows) : h('p', { class: 'muted small' }, t('recordings.details.noProvenance')),
418
+ h('p', { class: 'muted small' }, tn('recordings.details.provenanceNote'))),
419
+ h('div', { class: 'toolbar' }, save,
420
+ h('button', { class: 'btn', type: 'button', ...symbolOnly(t('recordings.details.close')), onclick: close }, icon('close'))));
421
+ form.addEventListener('keydown', (e) => {
422
+ if (e.key === 'Escape') {
423
+ e.preventDefault();
424
+ e.stopPropagation();
425
+ close();
426
+ }
427
+ });
428
+ form.addEventListener('submit', async (e) => {
429
+ e.preventDefault();
430
+ save.disabled = true;
431
+ try {
432
+ await api.patchMatch(m.id, {
433
+ favorite: favorite.checked,
434
+ tags: [...new Set(tags.value.split(',').map((t) => t.trim()).filter(Boolean))],
435
+ notes: notes.value,
436
+ });
437
+ this.app.hud.toast(t('recordings.details.saved'));
438
+ await this.refresh();
439
+ const again = this.detailsHost.querySelector('input[type="checkbox"]');
440
+ if (again) {
441
+ again.focus();
442
+ }
443
+ } catch (err) {
444
+ this.app.hud.toast(err.message, 'error', 7000);
445
+ save.disabled = false;
446
+ }
447
+ });
448
+ this.detailsHost.replaceChildren(form);
449
+ if (focus) {
450
+ favorite.focus();
451
+ }
452
+ }
453
+
454
+ toggleDetails() {
455
+ const [id] = this.selected;
456
+ if (this.trash || this.selected.size !== 1 || !id) {
457
+ return;
458
+ }
459
+ this.editing = this.editing === id ? null : id;
460
+ this.renderDetails(true);
461
+ }
462
+
463
+ fillMove(panel) {
464
+ const ids = [...this.selected];
465
+ const current = new Set(ids.map((id) => cleanPath((this.list.find((m) => m.id === id) || {}).folder || '')));
466
+ panel.replaceChildren(menuHeading(t('recordings.move.heading', { count: ids.length })),
467
+ ...this.folders().map((path) => menuItem(path ? path.split('/').pop() : t('recordings.move.top'), {
468
+ hint: path.includes('/') ? path : null,
469
+ className: `depth-${Math.min(4, path ? path.split('/').length - 1 : 0)}`,
470
+ checked: current.size === 1 && current.has(path),
471
+ onSelect: () => this.move(ids, path),
472
+ })),
473
+ menuItem(t('recordings.folder.new'), { hint: t('recordings.move.newHint'), onSelect: () => {
474
+ const path = this.askFolder();
475
+ if (path) {
476
+ this.move(ids, path);
477
+ }
478
+ } }));
479
+ }
480
+
481
+ renderTree(only = false) {
482
+ const folders = this.folders();
483
+ const items = folders.map((path) => {
484
+ const depth = path ? path.split('/').length : 0;
485
+ const name = path ? path.split('/').pop() : t('recordings.folder.all');
486
+ const count = path ? this.list.filter((m) => this.inFolder(m, path)).length : this.list.length;
487
+ const active = path === this.folder && !this.query;
488
+ const open = () => {
489
+ this.folder = path;
490
+ this.query = '';
491
+ this.selected.clear();
492
+ this.render();
493
+ const again = this.root.querySelector(`.folder[data-path="${CSS.escape(path)}"]`);
494
+ if (again) {
495
+ again.focus();
496
+ }
497
+ };
498
+ const row = h('li', {
499
+ class: `folder${active ? ' active' : ''}`,
500
+ style: `padding-left:${8 + depth * 14}px`,
501
+ tabindex: '0',
502
+ role: 'treeitem',
503
+ 'aria-selected': active ? 'true' : 'false',
504
+ 'data-path': path,
505
+ onclick: open,
506
+ onkeydown: (e) => {
507
+ if ((e.key === 'Enter' || e.key === ' ') && e.target === row) {
508
+ e.preventDefault();
509
+ open();
510
+ } else if (e.key === 'F2' && path) {
511
+ e.preventDefault();
512
+ this.renameFolder(path);
513
+ }
514
+ },
515
+ }, h('span', { class: 'folder-icon', 'aria-hidden': 'true' }), h('span', { class: 'folder-name' }, name), h('span', { class: 'count' }, String(count)),
516
+ path ? h('span', { class: 'folder-actions' },
517
+ h('button', { type: 'button', class: 'link', ...symbolOnly(t('recordings.folder.rename.title')), onclick: (e) => { e.stopPropagation(); this.renameFolder(path); } }, icon('edit')),
518
+ h('button', { type: 'button', class: 'link danger', ...symbolOnly(t('recordings.folder.delete.title')), onclick: (e) => { e.stopPropagation(); this.deleteFolder(path); } }, icon('trash'))) : null);
519
+ row.addEventListener('dragover', (e) => {
520
+ if (e.dataTransfer.types.includes('application/x-cuju-matches')) {
521
+ e.preventDefault();
522
+ row.classList.add('drop');
523
+ }
524
+ });
525
+ row.addEventListener('dragleave', () => row.classList.remove('drop'));
526
+ row.addEventListener('drop', (e) => {
527
+ e.preventDefault();
528
+ row.classList.remove('drop');
529
+ let ids;
530
+ try {
531
+ ids = JSON.parse(e.dataTransfer.getData('application/x-cuju-matches') || '[]');
532
+ } catch {
533
+ return;
534
+ }
535
+ if (Array.isArray(ids) && ids.length) {
536
+ this.move(ids.filter((id) => typeof id === 'string'), path);
537
+ }
538
+ });
539
+ return row;
540
+ });
541
+ const tree = h('ul', { class: 'tree', role: 'tree', 'aria-label': t('recordings.folders') }, items);
542
+ listKeys(tree, '.folder');
543
+ if (only && this.treeHost) {
544
+ this.treeHost.replaceChildren(tree);
545
+ }
546
+ return tree;
547
+ }
548
+
549
+ renderTable() {
550
+ if (!this.tableHost) {
551
+ return;
552
+ }
553
+ if (this.error) {
554
+ this.tableHost.replaceChildren(h('div', { class: 'notice error' }, h('p', {}, this.error.message),
555
+ h('p', { class: 'muted' }, tn('recordings.error.hint')),
556
+ h('button', { class: 'btn', type: 'button', ...symbolOnly(t('recordings.error.retry')), onclick: () => this.refresh() }, icon('refresh'))));
557
+ this.updateActions();
558
+ return;
559
+ }
560
+ const active = document.activeElement;
561
+ const focusedKey = active && active.closest && active.closest('tr[data-key]') ? active.closest('tr[data-key]').dataset.key : null;
562
+ const onToggle = !!(active && active.classList && active.classList.contains('group-toggle'));
563
+ const rows = this.visible();
564
+ this.rows = rows;
565
+ const head = h('tr', {}, COLUMNS.map((c) => {
566
+ const sorted = this.sortKey === c.key;
567
+ const sortBy = () => {
568
+ if (sorted) {
569
+ this.sortDir = -this.sortDir;
570
+ } else {
571
+ this.sortKey = c.key;
572
+ this.sortDir = c.numeric || c.key === 'created' ? -1 : 1;
573
+ }
574
+ if (this.sortSelectEl && SORTS.some(([v]) => v === `${this.sortKey}:${this.sortDir}`)) {
575
+ this.sortSelectEl.value = `${this.sortKey}:${this.sortDir}`;
576
+ }
577
+ this.renderTable();
578
+ };
579
+ return h('th', {
580
+ class: `${c.numeric ? 'num' : ''}${sorted ? ' sorted' : ''}`,
581
+ 'aria-sort': sorted ? (this.sortDir > 0 ? 'ascending' : 'descending') : 'none',
582
+ tabindex: '0',
583
+ onclick: sortBy,
584
+ onkeydown: (e) => {
585
+ if (e.key === 'Enter' || e.key === ' ') {
586
+ e.preventDefault();
587
+ sortBy();
588
+ }
589
+ },
590
+ title: t(`recordings.column.${c.key}.sort`),
591
+ }, c.label, sorted ? (this.sortDir > 0 ? ' ▲' : ' ▼') : '');
592
+ }));
593
+ const showFolder = !!this.query || !this.folder || rows.some((m) => cleanPath(m.folder || '') !== this.folder);
594
+ const items = groupRows(rows);
595
+ this.nav = navigationRows(items, this.open);
596
+ const body = [];
597
+ for (const item of items) {
598
+ if (item.kind === 'recording') {
599
+ body.push(this.recordingRow(item.recording, showFolder));
600
+ continue;
601
+ }
602
+ body.push(this.groupRow(item));
603
+ for (const member of item.members) {
604
+ body.push(this.recordingRow(member, showFolder, item.id));
605
+ }
606
+ }
607
+ const table = h('table', { class: 'grid', 'aria-label': t(this.trash ? 'recordings.table.trash' : 'recordings.table.library'), 'aria-multiselectable': 'true' }, h('thead', {}, head), h('tbody', {}, body));
608
+ const filtered = Object.entries(DEFAULT_FILTERS).some(([key, value]) => this.filters[key] !== value);
609
+ const empty = rows.length ? null : this.trash && !this.list.length ? h('div', { class: 'empty-state' },
610
+ h('p', { class: 'empty-title' }, t('recordings.empty.trash.title')),
611
+ h('p', { class: 'muted' }, tn('recordings.empty.trash.text')))
612
+ : h('div', { class: 'empty-state' },
613
+ h('p', { class: 'empty-title' }, t(this.query || filtered ? 'recordings.empty.filtered.title' : this.list.length ? 'recordings.empty.folder.title' : 'recordings.empty.none.title')),
614
+ h('p', { class: 'muted' }, this.query || filtered ? tn('recordings.empty.filtered.text')
615
+ : this.list.length ? tn('recordings.empty.folder.text')
616
+ : tn('recordings.empty.none.text', { sample: h('code', {}, 'cuju render sample'), recorder: h('code', {}, 'cuju.render.Recorder') })),
617
+ !this.list.length ? h('div', { class: 'empty-actions' },
618
+ h('button', { type: 'button', class: 'btn primary', onclick: () => this.app.showPage('matches') }, icon('matches'), t('recordings.empty.none.match')),
619
+ h('button', { type: 'button', class: 'btn', onclick: () => this.app.palette?.helpTopic('help-start') }, icon('help'), t('recordings.empty.none.help'))) : null);
620
+ this.tableHost.replaceChildren(table, ...(empty ? [empty] : []));
621
+ if (focusedKey) {
622
+ const again = this.tableHost.querySelector(`tr[data-key="${CSS.escape(focusedKey)}"]`);
623
+ const target = again && onToggle ? again.querySelector('.group-toggle') : again;
624
+ if (target && !again.hidden) {
625
+ target.focus({ preventScroll: true });
626
+ }
627
+ }
628
+ this.updateActions();
629
+ }
630
+
631
+ // The row of one recording, inside a group when `parent` names it, hidden while it is closed.
632
+ recordingRow(m, showFolder, parent = null) {
633
+ const tr = h('tr', {
634
+ id: `recording-row-${m.id}`,
635
+ class: `${this.selected.has(m.id) ? 'selected' : ''}${parent ? ' group-member' : ''}`,
636
+ hidden: !!parent && !this.open.has(parent),
637
+ draggable: this.trash ? 'false' : 'true',
638
+ tabindex: '0',
639
+ 'aria-selected': this.selected.has(m.id) ? 'true' : 'false',
640
+ 'data-id': m.id,
641
+ 'data-key': m.id,
642
+ 'data-group': parent,
643
+ },
644
+ h('td', { class: 'title-cell' },
645
+ m.favorite ? h('span', { class: 'favorite-mark', role: 'img', 'aria-label': t('recordings.favorite'), title: t('recordings.favorite') }, '★') : null,
646
+ h('span', { class: 'ellipsis' }, recordingTitle(m) || m.id),
647
+ showFolder && m.folder ? h('span', { class: 'folder-tag' }, m.folder) : null,
648
+ ...(m.tags || []).slice(0, 3).map((tag) => h('span', { class: 'folder-tag tag' }, tag))),
649
+ h('td', { class: 'wrap' }, joinTeams(summaryTeams(m))),
650
+ h('td', { class: 'num' }, m.score ? t('recordings.score', { left: m.score[0], right: m.score[1] }) : ''),
651
+ h('td', { class: 'wrap' }, scenarioName(m.scenario)),
652
+ h('td', { class: 'num' }, m.steps != null ? String(m.steps) : ''),
653
+ h('td', {}, formatDate(m.created)),
654
+ h('td', { class: 'num' }, formatBytes(m.bytes)));
655
+ tr.addEventListener('click', (e) => this.select(this.nav.findIndex((r) => r.key === m.id), e));
656
+ tr.addEventListener('dblclick', () => this.openSelected(m.id));
657
+ tr.addEventListener('keydown', (e) => this.rowKey(e, this.nav.findIndex((r) => r.key === m.id)));
658
+ this.dragRows(tr, [m.id]);
659
+ return tr;
660
+ }
661
+
662
+ // The row of a group, a disclosure button that names the challenge and the competitor, the
663
+ // run's result and the count of its recordings, with the totals of its members.
664
+ groupRow(item) {
665
+ const ids = item.members.map((m) => m.id);
666
+ const key = `group:${item.id}`;
667
+ const open = this.open.has(item.id);
668
+ const selected = ids.every((id) => this.selected.has(id));
669
+ const totals = groupTotals(item.members);
670
+ const title = serverText(item.group, 'title') || item.id;
671
+ const result = serverText(item.group, 'result');
672
+ const count = ids.length;
673
+ const toggle = h('button', {
674
+ type: 'button',
675
+ class: 'group-toggle',
676
+ 'aria-expanded': open ? 'true' : 'false',
677
+ 'aria-controls': ids.map((id) => `recording-row-${id}`).join(' '),
678
+ 'aria-label': t('recordings.group.label', { title, result, count }),
679
+ onclick: (e) => {
680
+ e.stopPropagation();
681
+ this.toggleGroup(item.id);
682
+ },
683
+ }, h('span', { class: 'group-caret', 'aria-hidden': 'true' }), h('span', { class: 'ellipsis' }, title));
684
+ const first = item.members[0];
685
+ const tr = h('tr', {
686
+ class: `group-row${selected ? ' selected' : ''}`,
687
+ draggable: this.trash ? 'false' : 'true',
688
+ tabindex: '0',
689
+ 'aria-selected': selected ? 'true' : 'false',
690
+ 'data-key': key,
691
+ 'data-group': item.id,
692
+ },
693
+ h('td', { class: 'title-cell' }, toggle,
694
+ result ? h('span', { class: 'group-result muted small' }, result) : null,
695
+ h('span', { class: 'folder-tag' }, t('recordings.group.count', { count }))),
696
+ h('td', { class: 'wrap' }, joinTeams(summaryTeams(first))),
697
+ h('td', { class: 'num' }, ''),
698
+ h('td', { class: 'wrap' }, scenarioName(first.scenario)),
699
+ h('td', { class: 'num' }, String(totals.steps)),
700
+ h('td', {}, totals.created ? formatDate(totals.created) : ''),
701
+ h('td', { class: 'num' }, formatBytes(totals.bytes)));
702
+ tr.addEventListener('click', (e) => this.select(this.nav.findIndex((r) => r.key === key), e));
703
+ tr.addEventListener('dblclick', () => this.toggleGroup(item.id));
704
+ tr.addEventListener('keydown', (e) => this.rowKey(e, this.nav.findIndex((r) => r.key === key)));
705
+ this.dragRows(tr, ids);
706
+ return tr;
707
+ }
708
+
709
+ // Dragging a row drags the selection, or the row's recordings when it is not selected.
710
+ dragRows(tr, ids) {
711
+ tr.addEventListener('dragstart', (e) => {
712
+ if (this.trash) {
713
+ e.preventDefault();
714
+ return;
715
+ }
716
+ if (!ids.every((id) => this.selected.has(id))) {
717
+ this.selected = new Set(ids);
718
+ this.renderTable();
719
+ }
720
+ e.dataTransfer.setData('application/x-cuju-matches', JSON.stringify([...this.selected]));
721
+ e.dataTransfer.effectAllowed = 'move';
722
+ });
723
+ }
724
+
725
+ // Opens or closes a group, and keeps the focus where it was.
726
+ toggleGroup(id, open = !this.open.has(id)) {
727
+ if (open) {
728
+ this.open.add(id);
729
+ } else {
730
+ this.open.delete(id);
731
+ }
732
+ this.renderTable();
733
+ }
734
+
735
+ // The groups whose recordings of the view are all among `ids`, each with those recordings.
736
+ wholeGroups(ids) {
737
+ const chosen = new Set(ids);
738
+ return groupRows(this.list)
739
+ .filter((item) => item.kind === 'group' && item.members.every((m) => chosen.has(m.id)))
740
+ .map((item) => ({ id: item.id, ids: item.members.map((m) => m.id) }));
741
+ }
742
+
743
+ updateActions() {
744
+ const count = this.selected.size;
745
+ const q = (act) => this.root.querySelector(`.actions [data-act="${act}"]`);
746
+ if (!q('open')) {
747
+ return;
748
+ }
749
+ q('open').disabled = count !== 1 || this.trash;
750
+ q('rename').disabled = count !== 1 || this.trash;
751
+ q('details').disabled = count !== 1 || this.trash;
752
+ q('restore').disabled = count === 0 || !this.trash;
753
+ q('delete').disabled = count === 0;
754
+ const verb = this.trash ? 'recordings.action.purge' : 'recordings.action.trash';
755
+ relabel(q('delete'), count > 1 ? t(`${verb}.count`, { count }) : t(verb));
756
+ this.moveBtn.disabled = count === 0 || this.trash;
757
+ const shown = this.rows ? this.rows.length : 0;
758
+ // The total counts every recording of the view, the library or the Trash, on disk.
759
+ const total = this.list.reduce((sum, m) => sum + (Number(m.bytes) || 0), 0);
760
+ const where = this.trash ? 'trash' : 'library';
761
+ this.countLabel.textContent = count ? t(`recordings.count.selected.${where}`, { count, shown, size: formatBytes(total) })
762
+ : t(`recordings.count.${where}`, { count: shown, size: formatBytes(total) });
763
+ }
764
+
765
+ // Arrows move through the rows and select, with Shift they extend, Enter opens, Delete deletes
766
+ // and F2 renames. On a group, Enter and the right and left arrows open and close it, and the
767
+ // left arrow on a row of a group goes back to the group.
768
+ rowKey(e, i) {
769
+ if (e.target !== e.currentTarget) {
770
+ return;
771
+ }
772
+ const entry = this.nav[i];
773
+ if (!entry) {
774
+ return;
775
+ }
776
+ const go = (j) => {
777
+ j = Math.max(0, Math.min(this.nav.length - 1, j));
778
+ const key = this.nav[j].key;
779
+ this.select(j, { shiftKey: e.shiftKey, ctrlKey: false, metaKey: false });
780
+ const tr = this.tableHost.querySelector(`tr[data-key="${CSS.escape(key)}"]`);
781
+ if (tr) {
782
+ tr.focus();
783
+ }
784
+ };
785
+ if (e.key === 'ArrowDown') {
786
+ go(i + 1);
787
+ } else if (e.key === 'ArrowUp') {
788
+ go(i - 1);
789
+ } else if (e.key === 'Home') {
790
+ go(0);
791
+ } else if (e.key === 'End') {
792
+ go(this.nav.length - 1);
793
+ } else if ((e.key === 'ArrowRight' || e.key === 'ArrowLeft') && entry.group) {
794
+ this.toggleGroup(entry.group.id, e.key === 'ArrowRight');
795
+ } else if (e.key === 'ArrowLeft' && entry.parent) {
796
+ go(this.nav.findIndex((r) => r.key === `group:${entry.parent}`));
797
+ } else if (e.key === 'Enter') {
798
+ if (entry.group) {
799
+ this.toggleGroup(entry.group.id);
800
+ } else {
801
+ this.openSelected(entry.recording.id);
802
+ }
803
+ } else if (e.key === ' ') {
804
+ this.select(i, { shiftKey: false, ctrlKey: true, metaKey: false });
805
+ } else if (e.key === 'Delete') {
806
+ if (!entry.ids.every((id) => this.selected.has(id))) {
807
+ this.selected = new Set(entry.ids);
808
+ }
809
+ this.deleteSelected();
810
+ } else if (e.key === 'F2') {
811
+ if (this.trash || !entry.recording) {
812
+ return;
813
+ }
814
+ this.selected = new Set([entry.recording.id]);
815
+ this.renameSelected();
816
+ } else {
817
+ return;
818
+ }
819
+ e.preventDefault();
820
+ }
821
+
822
+ // Click selects one row, Ctrl or Cmd toggles, Shift selects the range from the last click. A
823
+ // group's row selects every recording of the group.
824
+ select(index, e) {
825
+ const entry = this.nav[index];
826
+ if (!entry) {
827
+ return;
828
+ }
829
+ if (e.shiftKey && this.anchor != null) {
830
+ const a = Math.min(this.anchor, index);
831
+ const b = Math.max(this.anchor, index);
832
+ if (!(e.ctrlKey || e.metaKey)) {
833
+ this.selected.clear();
834
+ }
835
+ for (let i = a; i <= b && i < this.nav.length; i++) {
836
+ for (const id of this.nav[i].ids) {
837
+ this.selected.add(id);
838
+ }
839
+ }
840
+ } else if (e.ctrlKey || e.metaKey) {
841
+ const all = entry.ids.every((id) => this.selected.has(id));
842
+ for (const id of entry.ids) {
843
+ if (all) {
844
+ this.selected.delete(id);
845
+ } else {
846
+ this.selected.add(id);
847
+ }
848
+ }
849
+ this.anchor = index;
850
+ } else {
851
+ this.selected = new Set(entry.ids);
852
+ this.anchor = index;
853
+ }
854
+ this.renderTable();
855
+ }
856
+
857
+ // A recording of the Trash opens only after Restore.
858
+ openSelected(id = [...this.selected][0]) {
859
+ if (id && !this.trash) {
860
+ this.app.openMatchInWatch(id);
861
+ }
862
+ }
863
+
864
+ async renameSelected() {
865
+ if (this.trash) {
866
+ return;
867
+ }
868
+ const [id] = this.selected;
869
+ const m = this.list.find((x) => x.id === id);
870
+ if (!m) {
871
+ return;
872
+ }
873
+ const shown = recordingTitle(m) || m.title || '';
874
+ const title = prompt(t('recordings.rename.prompt'), shown);
875
+ if (title == null || !title.trim() || title.trim() === shown || title.trim() === m.title) {
876
+ return;
877
+ }
878
+ try {
879
+ await api.patchMatch(id, { title: title.trim() });
880
+ } catch (err) {
881
+ this.app.hud.toast(err.message, 'error');
882
+ }
883
+ this.refresh();
884
+ }
885
+
886
+ async deleteSelected() {
887
+ const ids = [...this.selected];
888
+ if (!ids.length) {
889
+ return;
890
+ }
891
+ const question = ids.length === 1
892
+ ? t('recordings.purge.confirmOne', { title: recordingTitle(this.list.find((m) => m.id === ids[0])) || ids[0] })
893
+ : t('recordings.purge.confirm', { count: ids.length });
894
+ // Moving to the Trash can be undone, so only a permanent deletion asks first.
895
+ if (this.trash && !confirm(question)) {
896
+ return;
897
+ }
898
+ const failed = [];
899
+ // A whole group moves to the Trash in one step.
900
+ const groups = this.trash ? [] : this.wholeGroups(ids);
901
+ const grouped = new Set(groups.flatMap((group) => group.ids));
902
+ for (const group of groups) {
903
+ try {
904
+ await groupApi.trash(group.id);
905
+ } catch (err) {
906
+ failed.push(...group.ids.map(() => err.message));
907
+ }
908
+ }
909
+ for (const id of ids.filter((x) => !grouped.has(x))) {
910
+ try {
911
+ await (this.trash ? api.purgeMatch(id) : api.deleteMatch(id));
912
+ } catch (err) {
913
+ failed.push(err.message);
914
+ }
915
+ }
916
+ const done = ids.length - failed.length;
917
+ if (failed.length) {
918
+ this.app.hud.toast(t(this.trash ? 'recordings.purge.failed' : 'recordings.trash.failed', { count: failed.length, reason: failed[0] }), 'error', 7000);
919
+ } else if (this.trash) {
920
+ this.app.hud.toast(t('recordings.purge.done', { count: done }));
921
+ } else {
922
+ this.app.hud.toast(t('recordings.trash.done', { count: done }));
923
+ }
924
+ this.selected.clear();
925
+ this.refresh();
926
+ }
927
+
928
+ async restoreSelected() {
929
+ const ids = [...this.selected];
930
+ if (!this.trash || !ids.length) {
931
+ return;
932
+ }
933
+ const failed = [];
934
+ // A whole group of the Trash comes back in one step, and any recording on its own.
935
+ const groups = this.wholeGroups(ids);
936
+ const grouped = new Set(groups.flatMap((group) => group.ids));
937
+ for (const group of groups) {
938
+ try {
939
+ await groupApi.restore(group.id);
940
+ } catch (err) {
941
+ failed.push(...group.ids.map(() => err.message));
942
+ }
943
+ }
944
+ for (const id of ids.filter((x) => !grouped.has(x))) {
945
+ try {
946
+ await api.restoreMatch(id);
947
+ } catch (err) {
948
+ failed.push(err.message);
949
+ }
950
+ }
951
+ const done = ids.length - failed.length;
952
+ if (failed.length) {
953
+ this.app.hud.toast(t('recordings.restore.failed', { count: failed.length, reason: failed[0] }), 'error', 7000);
954
+ } else {
955
+ this.app.hud.toast(t('recordings.restore.done', { count: done }));
956
+ }
957
+ this.selected.clear();
958
+ this.refresh();
959
+ }
960
+
961
+ async move(ids, folder) {
962
+ if (this.trash) {
963
+ return;
964
+ }
965
+ let failed = 0;
966
+ for (const id of ids) {
967
+ try {
968
+ await api.patchMatch(id, { folder });
969
+ } catch {
970
+ failed++;
971
+ }
972
+ }
973
+ if (failed < ids.length) {
974
+ this.extraFolders = this.extraFolders.filter((f) => !(folder === f || folder.startsWith(`${f}/`)));
975
+ saveFolders(this.extraFolders);
976
+ }
977
+ if (failed) {
978
+ this.app.hud.toast(t('recordings.move.failed', { count: failed, total: ids.length }), 'error');
979
+ } else {
980
+ this.app.hud.toast(folder ? t('recordings.move.done', { count: ids.length, folder }) : t('recordings.move.doneTop', { count: ids.length }));
981
+ }
982
+ this.selected.clear();
983
+ this.refresh();
984
+ }
985
+
986
+ // Asks for a new folder's name and keeps it, returning its path or null.
987
+ askFolder() {
988
+ const name = prompt(t('recordings.folder.new.prompt'), '');
989
+ const clean = cleanPath(name || '').replace(/\//g, ' ');
990
+ if (!clean) {
991
+ return null;
992
+ }
993
+ const path = this.folder ? `${this.folder}/${clean}` : clean;
994
+ if (!this.extraFolders.includes(path)) {
995
+ this.extraFolders.push(path);
996
+ saveFolders(this.extraFolders);
997
+ }
998
+ return path;
999
+ }
1000
+
1001
+ newFolder() {
1002
+ if (this.askFolder()) {
1003
+ this.render();
1004
+ }
1005
+ }
1006
+
1007
+ // Renames a folder on the server first, and changes the view only for what the server took.
1008
+ async renameFolder(path) {
1009
+ const name = prompt(t('recordings.folder.rename.prompt'), path.split('/').pop());
1010
+ const clean = cleanPath(name || '').replace(/\//g, ' ');
1011
+ if (!clean || clean === path.split('/').pop()) {
1012
+ return;
1013
+ }
1014
+ const target = [...path.split('/').slice(0, -1), clean].join('/');
1015
+ const inside = this.list.filter((m) => this.inFolder(m, path) && cleanPath(m.folder || ''));
1016
+ let failed = 0;
1017
+ let error = '';
1018
+ for (const m of inside) {
1019
+ const f = cleanPath(m.folder || '');
1020
+ try {
1021
+ await api.patchMatch(m.id, { folder: target + f.slice(path.length) });
1022
+ } catch (err) {
1023
+ failed++;
1024
+ error = err.message;
1025
+ }
1026
+ }
1027
+ if (failed) {
1028
+ this.app.hud.toast(t('recordings.folder.rename.failed', { count: failed, total: inside.length, reason: error }), 'error', 7000);
1029
+ await this.refresh();
1030
+ return;
1031
+ }
1032
+ this.extraFolders = this.extraFolders.map((f) => (f === path || f.startsWith(`${path}/`) ? target + f.slice(path.length) : f));
1033
+ saveFolders(this.extraFolders);
1034
+ if (this.folder === path || this.folder.startsWith(`${path}/`)) {
1035
+ this.folder = target + this.folder.slice(path.length);
1036
+ }
1037
+ this.app.hud.toast(t('recordings.folder.rename.done', { name: clean }));
1038
+ this.refresh();
1039
+ }
1040
+
1041
+ async deleteFolder(path) {
1042
+ const inside = this.list.filter((m) => cleanPath(m.folder || '') && this.inFolder(m, path));
1043
+ const parent = path.split('/').slice(0, -1).join('/');
1044
+ const question = parent ? t('recordings.folder.delete.confirm', { path, count: inside.length, parent })
1045
+ : t('recordings.folder.delete.confirmTop', { path, count: inside.length });
1046
+ if (inside.length && !confirm(question)) {
1047
+ return;
1048
+ }
1049
+ let failed = 0;
1050
+ for (const m of inside) {
1051
+ try {
1052
+ await api.patchMatch(m.id, { folder: parent });
1053
+ } catch (err) {
1054
+ failed++;
1055
+ this.app.hud.toast(err.message, 'error');
1056
+ }
1057
+ }
1058
+ if (failed) {
1059
+ this.refresh();
1060
+ return;
1061
+ }
1062
+ this.extraFolders = this.extraFolders.filter((f) => !(f === path || f.startsWith(`${path}/`)));
1063
+ saveFolders(this.extraFolders);
1064
+ if (this.folder === path || this.folder.startsWith(`${path}/`)) {
1065
+ this.folder = parent;
1066
+ }
1067
+ this.refresh();
1068
+ }
1069
+ }