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,705 @@
1
+ // Copyright 2026 The cuju Authors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // The languages of the page. Every text the page shows is a message of a language file, one JSON
5
+ // object per language keyed by message id, which web/languages/ ships and the folder languages of
6
+ // the renderer's home adds to. A message is a text with placeholders in braces, such as
7
+ // `{count} recordings`, or an object of plural forms keyed by the categories of
8
+ // Intl.PluralRules, `one`, `few`, `many`, `other` and the rest, and by exact counts such as `=0`.
9
+ // The key `@language` holds the code, the name, the locale of numbers and dates, the direction of
10
+ // the text and the plural categories of the language.
11
+ //
12
+ // A message may mark its words in two ways. Two asterisks on each side, **so**, give strong
13
+ // emphasis, and backticks, `so`, mark code such as a command, a program or a variable, or a
14
+ // shortcut, a chord of key names such as `Ctrl K`, which keys.js draws as keycaps. The marks are
15
+ // read from the message before its values fill it, so a value never adds one. t() gives the text
16
+ // without the marks, for attributes, titles, notifications and canvases, and tn() and tm() give
17
+ // strong, code and kbd elements, built as nodes with text, never as markup.
18
+ //
19
+ // The module loads English and the chosen language before any module that imports it runs, so
20
+ // t() answers at once everywhere, also in the tables that modules build as they load. The server
21
+ // puts the shipped files into the page itself, so they need no request of their own. A message
22
+ // that the chosen language lacks comes from English, and an id that English lacks shows as the
23
+ // id itself and is noted once on the console. The choice is the stored one, else the address
24
+ // parameter `lang`, else the first language of the browser that a file exists for, else English.
25
+ // Changing it stores the choice and tells the listeners, and the page then reloads at the same
26
+ // address, so every module renders again in the new language.
27
+
28
+ const STORE_KEY = 'cuju.language';
29
+ // How long a language file may take to arrive, in milliseconds.
30
+ const FETCH_MS = 10000;
31
+ const ID = /^[A-Za-z0-9_.-]+$/;
32
+ const CODE = /^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$/;
33
+ const PLACEHOLDER = /\{([A-Za-z0-9_]+)\}/g;
34
+ const BASE = new URL('../../languages/', import.meta.url);
35
+ const IN_BROWSER = typeof window !== 'undefined' && typeof document !== 'undefined';
36
+ // Node reads the files from the disk, while a page and a worker of the page fetch them.
37
+ const IN_NODE = !IN_BROWSER && typeof process !== 'undefined' && Boolean(process.versions && process.versions.node);
38
+
39
+ let english = {};
40
+ let table = {};
41
+ let info = { code: 'en', name: 'English', locale: 'en-US', dir: 'ltr', plurals: ['one', 'other'] };
42
+ let englishInfo = info;
43
+ const rules = new Map();
44
+ const missingIds = new Set();
45
+ const listeners = new Set();
46
+
47
+ // The plural rules of a locale for numbers shown with so many decimals, made once.
48
+ function pluralRules(locale, digits = 0) {
49
+ const key = `${locale} ${digits}`;
50
+ let r = rules.get(key);
51
+ if (!r) {
52
+ const options = digits ? { minimumFractionDigits: digits } : {};
53
+ try {
54
+ r = new Intl.PluralRules(locale, options);
55
+ } catch {
56
+ r = new Intl.PluralRules('en-US', options);
57
+ }
58
+ rules.set(key, r);
59
+ }
60
+ return r;
61
+ }
62
+
63
+ // A count given as text with decimals, such as 1.0 or 1,5, as a number and its decimals, since
64
+ // English reads 1 minute but 1.0 minutes. Any other value is a number without decimals.
65
+ const DECIMAL_COUNT = /^\s*(-?\d+)[.,](\d+)\s*$/;
66
+ function countOf(value) {
67
+ const match = typeof value === 'string' ? DECIMAL_COUNT.exec(value) : null;
68
+ if (match) {
69
+ return { count: Number(`${match[1]}.${match[2]}`), digits: match[2].length };
70
+ }
71
+ return { count: Number(value), digits: 0 };
72
+ }
73
+
74
+ // Whether a code names a language file safely, a language tag of BCP 47 such as pt or pt-BR, of
75
+ // letters and digits in parts. Two codes that differ in case alone name the same language.
76
+ export function validCode(code) {
77
+ return typeof code === 'string' && CODE.test(code);
78
+ }
79
+
80
+ // The shipped languages that the server put into the page, by code, read once, or null on a page
81
+ // served without them.
82
+ let inlined;
83
+ function inlinedFiles() {
84
+ if (inlined === undefined) {
85
+ inlined = null;
86
+ try {
87
+ const block = IN_BROWSER ? document.getElementById('cuju-languages') : null;
88
+ const text = block ? block.textContent.trim() : '';
89
+ inlined = text ? JSON.parse(text) : null;
90
+ } catch {
91
+ inlined = null;
92
+ }
93
+ }
94
+ return inlined;
95
+ }
96
+
97
+ // The shipped file of a code that the server put into the page, whatever the case of the code, or
98
+ // null.
99
+ function inlinedLanguage(code) {
100
+ const shipped = inlinedFiles();
101
+ const lower = String(code).toLowerCase();
102
+ const key = shipped ? Object.keys(shipped).find((name) => name.toLowerCase() === lower) : undefined;
103
+ return key !== undefined && shipped[key] && typeof shipped[key] === 'object' ? shipped[key] : null;
104
+ }
105
+
106
+ // Reads a shipped file from the page itself or from beside this module, or a language of the home
107
+ // folder from the server.
108
+ async function readFile(code) {
109
+ if (!validCode(code)) {
110
+ throw new Error(tOr('language.error.none', `there is no language ${code}`, { code }));
111
+ }
112
+ if (IN_NODE) {
113
+ // Under Node a test may load a copy of the modules alone, so the files of the repository
114
+ // root, the working folder of the tests, stand behind those beside the module.
115
+ const { readFile: read } = await import('node:fs/promises');
116
+ const { pathToFileURL } = await import('node:url');
117
+ const places = [new URL(`${code}.json`, BASE)];
118
+ if (typeof process !== 'undefined') {
119
+ places.push(pathToFileURL(`${process.cwd()}/src/cuju/render/web/languages/${code}.json`));
120
+ // The drafts of other languages, which a page imports, wait in translations/, each in
121
+ // a folder named after its code.
122
+ places.push(pathToFileURL(`${process.cwd()}/translations/${code}/${code}.json`));
123
+ }
124
+ let failure;
125
+ for (const place of places) {
126
+ try {
127
+ return JSON.parse(await read(place, 'utf8'));
128
+ } catch (err) {
129
+ failure = err;
130
+ }
131
+ }
132
+ throw failure;
133
+ }
134
+ const inlinedFile = inlinedLanguage(code);
135
+ if (inlinedFile) {
136
+ return inlinedFile;
137
+ }
138
+ // Every module of the page waits on this load, so a request that never answers gives up after
139
+ // a while and the page starts in English.
140
+ const get = (url) => fetch(url, typeof AbortSignal.timeout === 'function' ? { signal: AbortSignal.timeout(FETCH_MS) } : {})
141
+ .catch(() => null);
142
+ let res = await get(new URL(`${code}.json`, BASE));
143
+ if (!res || !res.ok) {
144
+ res = await get(`/api/languages/${encodeURIComponent(code)}`);
145
+ }
146
+ if (!res || !res.ok) {
147
+ throw new Error(tOr('language.error.none', `there is no language ${code}`, { code }));
148
+ }
149
+ return res.json();
150
+ }
151
+
152
+ // Splits a file into its header and its messages, keeping well formed messages alone.
153
+ function parse(data, code) {
154
+ if (!data || typeof data !== 'object' || Array.isArray(data)) {
155
+ throw new Error(tOr('language.error.notObject', `the language ${code} is not a JSON object`, { code }));
156
+ }
157
+ const head = data['@language'] && typeof data['@language'] === 'object' ? data['@language'] : {};
158
+ const messages = {};
159
+ for (const [id, value] of Object.entries(data)) {
160
+ if (id.startsWith('@') || !ID.test(id)) {
161
+ continue;
162
+ }
163
+ if (typeof value === 'string' || (value && typeof value === 'object' && typeof value.other === 'string')) {
164
+ messages[id] = value;
165
+ }
166
+ }
167
+ const locale = typeof head.locale === 'string' && head.locale ? head.locale : (head.code || code);
168
+ // The file spells its code as the list of languages does, such as pt-BR for pt-br.
169
+ const spelled = typeof head.code === 'string' && head.code.toLowerCase() === String(code).toLowerCase() ? head.code : code;
170
+ return {
171
+ info: {
172
+ code: spelled,
173
+ name: typeof head.name === 'string' && head.name ? head.name : code,
174
+ english: typeof head.english === 'string' ? head.english : '',
175
+ locale,
176
+ dir: head.dir === 'rtl' ? 'rtl' : 'ltr',
177
+ plurals: Array.isArray(head.plurals) ? head.plurals : ['other'],
178
+ },
179
+ messages,
180
+ };
181
+ }
182
+
183
+ // The language codes to try, in order, each marked chosen when the stored choice or the address
184
+ // names it. English ends the list, since it is always there.
185
+ function wanted() {
186
+ const out = [];
187
+ let done = false;
188
+ const add = (code, chosen) => {
189
+ const c = String(code || '');
190
+ const lower = c.toLowerCase();
191
+ if (done || !validCode(c)) {
192
+ return;
193
+ }
194
+ // English ends the list, and so does a variant of English the browser prefers, which the
195
+ // page shows as English. A chosen variant, such as en-x-mine of the home folder, loads.
196
+ if (lower === 'en' || (!chosen && lower.startsWith('en-'))) {
197
+ done = true;
198
+ } else if (!out.some((item) => item.code.toLowerCase() === lower)) {
199
+ out.push({ code: c, chosen });
200
+ }
201
+ };
202
+ if (IN_BROWSER) {
203
+ try {
204
+ const stored = localStorage.getItem(STORE_KEY);
205
+ if (stored) {
206
+ add(JSON.parse(stored), true);
207
+ }
208
+ } catch {
209
+ // Storage can be unavailable, the browser's language then decides.
210
+ }
211
+ try {
212
+ add(new URLSearchParams(location.search).get('lang'), true);
213
+ } catch {
214
+ // An address without parameters leaves the choice to the browser.
215
+ }
216
+ // The first languages of the browser, each also by its base language, up to English.
217
+ for (const tag of (navigator.languages && navigator.languages.length ? navigator.languages : [navigator.language]).slice(0, 3)) {
218
+ const whole = String(tag || '');
219
+ add(whole, false);
220
+ add(whole.split('-')[0], false);
221
+ }
222
+ }
223
+ return out;
224
+ }
225
+
226
+ // Loads English and the language to show. A language that fails to load leaves English.
227
+ async function start() {
228
+ try {
229
+ const parsed = parse(await readFile('en'), 'en');
230
+ english = parsed.messages;
231
+ englishInfo = parsed.info;
232
+ info = englishInfo;
233
+ table = english;
234
+ } catch (err) {
235
+ // Without the English file every message shows its id, which the console notes.
236
+ console.warn(`i18n: the English messages failed to load, ${err.message}`);
237
+ }
238
+ const list = wanted();
239
+ const shipped = inlinedFiles();
240
+ for (const [i, { code, chosen }] of list.entries()) {
241
+ // A language the browser prefers that the page does not hold gives way to a later one it
242
+ // holds, such as pt for pt-BR, so the start asks the server for nothing it may not have.
243
+ if (!chosen && shipped && !inlinedLanguage(code) && list.slice(i + 1).some((item) => inlinedLanguage(item.code))) {
244
+ continue;
245
+ }
246
+ try {
247
+ const parsed = parse(await readFile(code), code);
248
+ table = parsed.messages;
249
+ info = parsed.info;
250
+ break;
251
+ } catch {
252
+ // The next language of the list is tried.
253
+ }
254
+ }
255
+ applyDocument();
256
+ }
257
+
258
+ // The language and direction of the document, and its static texts.
259
+ function applyDocument() {
260
+ if (!IN_BROWSER) {
261
+ return;
262
+ }
263
+ document.documentElement.lang = info.locale;
264
+ document.documentElement.dir = info.dir;
265
+ // An install of the page names its description and shortcuts in the page's language.
266
+ const manifest = typeof document.querySelector === 'function' ? document.querySelector('link[rel="manifest"]') : null;
267
+ if (manifest) {
268
+ manifest.setAttribute('href', info.code === 'en' ? 'manifest.webmanifest' : `manifest.webmanifest?lang=${encodeURIComponent(info.code)}`);
269
+ }
270
+ translateDom(document);
271
+ }
272
+
273
+ // Notes an id that no language holds, once.
274
+ function noteMissing(id) {
275
+ if (!missingIds.has(id)) {
276
+ missingIds.add(id);
277
+ console.warn(`i18n: missing message ${id}`);
278
+ }
279
+ }
280
+
281
+ // The message of an id in the shown language, else in English, else undefined.
282
+ function lookup(id) {
283
+ if (Object.prototype.hasOwnProperty.call(table, id)) {
284
+ return { message: table[id], locale: info.locale };
285
+ }
286
+ if (Object.prototype.hasOwnProperty.call(english, id)) {
287
+ return { message: english[id], locale: englishInfo.locale };
288
+ }
289
+ return null;
290
+ }
291
+
292
+ // The form of a plural message for the count of the values.
293
+ function pick(message, values, locale) {
294
+ if (typeof message === 'string') {
295
+ return message;
296
+ }
297
+ const { count, digits } = countOf(values ? values.count : undefined);
298
+ if (Number.isFinite(count) && !digits && typeof message[`=${count}`] === 'string') {
299
+ return message[`=${count}`];
300
+ }
301
+ const category = Number.isFinite(count) ? pluralRules(locale, digits).select(count) : 'other';
302
+ return typeof message[category] === 'string' ? message[category] : message.other;
303
+ }
304
+
305
+ // The marks of a message, strong emphasis in double asterisks and code in backticks. A mark
306
+ // that does not close is text, as the two asterisks of 2**64 are.
307
+ const MARK = /\*\*(.+?)\*\*|`([^`]+)`/g;
308
+
309
+ // A text as its parts, each with its kind, text, strong or code, in order.
310
+ export function markParts(text) {
311
+ const parts = [];
312
+ let last = 0;
313
+ for (const match of String(text).matchAll(MARK)) {
314
+ if (match.index > last) {
315
+ parts.push({ kind: 'text', text: text.slice(last, match.index) });
316
+ }
317
+ parts.push(match[1] !== undefined ? { kind: 'strong', text: match[1] } : { kind: 'code', text: match[2] });
318
+ last = match.index + match[0].length;
319
+ }
320
+ if (last < text.length) {
321
+ parts.push({ kind: 'text', text: text.slice(last) });
322
+ }
323
+ return parts;
324
+ }
325
+
326
+ // How the page shows code, as text and as a node, which keys.js sets so that a shortcut shows
327
+ // as keycaps. Without it, code shows as it is written, inside a code element.
328
+ let codeKind = {
329
+ text: (code) => code,
330
+ node: (code) => {
331
+ const node = document.createElement('code');
332
+ node.textContent = code;
333
+ return node;
334
+ },
335
+ };
336
+ export function setCodeKind(kind) {
337
+ codeKind = { ...codeKind, ...kind };
338
+ }
339
+
340
+ // A text without its marks, the code as codeKind writes it, such as a shortcut in its legends.
341
+ export function plainMarks(text) {
342
+ return markParts(text).map((part) => (part.kind === 'code' ? codeKind.text(part.text) : part.text)).join('');
343
+ }
344
+
345
+ function fill(text, values) {
346
+ if (!values) {
347
+ return text;
348
+ }
349
+ return text.replace(PLACEHOLDER, (whole, name) => (values[name] === undefined || values[name] === null ? whole : String(values[name])));
350
+ }
351
+
352
+ // The text of a message, with its placeholders filled from values. A count in the values picks
353
+ // the plural form.
354
+ export function t(id, values) {
355
+ const found = lookup(id);
356
+ if (!found) {
357
+ noteMissing(id);
358
+ return id;
359
+ }
360
+ return markParts(pick(found.message, values, found.locale))
361
+ .map((part) => (part.kind === 'code' ? codeKind.text(fill(part.text, values)) : fill(part.text, values)))
362
+ .join('');
363
+ }
364
+
365
+ // The text of a message whose id the server or a table may lack, such as the title of a
366
+ // challenge, else the given fallback, which is the server's own English text.
367
+ export function tOr(id, fallback, values) {
368
+ if (typeof id !== 'string' || !id || !lookup(id)) {
369
+ return fill(plainText(fallback), values);
370
+ }
371
+ return t(id, values);
372
+ }
373
+
374
+ // A value as text, a text as it is and a number or a truth value in digits or words. Anything
375
+ // else, such as an object of a malformed file, is the empty text, since some objects throw when
376
+ // made text.
377
+ export function plainText(value) {
378
+ const kind = typeof value;
379
+ if (kind === 'string') {
380
+ return value;
381
+ }
382
+ return kind === 'number' || kind === 'boolean' || kind === 'bigint' ? String(value) : '';
383
+ }
384
+
385
+ // Whether a language holds the id.
386
+ export function has(id) {
387
+ return lookup(id) !== null;
388
+ }
389
+
390
+ // The text of a message from the server, an object with the English text in `field` and, when
391
+ // the server gives them, its id in `field_id` and its values in `field_values`. A name that the
392
+ // server makes, such as that of the built-in AI or of a round, comes the same way, while a name
393
+ // that a person gave comes as text alone and shows as given. `allow`, when given, says which
394
+ // message ids may show, in the object and in the labels of its values, and a label of any other
395
+ // id shows its English text.
396
+ export function serverText(object, field = 'error', allow = null) {
397
+ if (!object || typeof object !== 'object') {
398
+ return plainText(object);
399
+ }
400
+ return labelText({ id: object[`${field}_id`], text: object[field], values: object[`${field}_values`] }, allow);
401
+ }
402
+
403
+ // Labels nest this deep at most, as an entrant inside a match inside the title of a tournament
404
+ // recording does, and a deeper label shows its English text.
405
+ const LABEL_DEPTH = 16;
406
+
407
+ // The text of a label of the server, an object with its English `text`, its message `id` and
408
+ // its `values`, as a value of another message holds one, or a plain text. A label with a `kind`
409
+ // names a thing that a module of the page shows, such as a scenario by its `name`. `allow` reads
410
+ // as in serverText.
411
+ export function labelText(label, allow = null, depth = 0) {
412
+ if (!label || typeof label !== 'object') {
413
+ return plainText(label);
414
+ }
415
+ if (typeof label.kind === 'string') {
416
+ const show = valueKinds.get(label.kind);
417
+ return show ? show(plainText(label.name), label) : plainText(label.text ?? label.name);
418
+ }
419
+ const id = typeof label.id === 'string' && (!allow || allow(label.id)) ? label.id : null;
420
+ if (!id || depth >= LABEL_DEPTH) {
421
+ return plainText(label.text);
422
+ }
423
+ const values = label.values && typeof label.values === 'object' ? serverValues(label.values, allow, depth + 1) : undefined;
424
+ return tOr(id, label.text, values);
425
+ }
426
+
427
+ // How the page shows each kind of label, such as `scenario`, which scenarios.js gives, so this
428
+ // module imports none of them.
429
+ const valueKinds = new Map();
430
+ export function setValueKind(kind, show) {
431
+ valueKinds.set(kind, show);
432
+ }
433
+
434
+ // A decimal number among the values, such as the ability 0.50 of a name, which shows with the
435
+ // decimal sign of the language and as many digits.
436
+ const DECIMAL = /^-?\d+\.\d+$/;
437
+
438
+ // The values of a server message for the page's language. A value is text, or a label of its
439
+ // own, such as the name of an entrant inside the title of a recording.
440
+ function serverValues(values, allow, depth) {
441
+ const out = {};
442
+ for (const [key, value] of Object.entries(values)) {
443
+ if (value && typeof value === 'object') {
444
+ out[key] = labelText(value, allow, depth);
445
+ } else if (typeof value === 'string' && DECIMAL.test(value)) {
446
+ const digits = value.length - value.indexOf('.') - 1;
447
+ out[key] = formatNumber(Number(value), { minimumFractionDigits: digits, maximumFractionDigits: digits });
448
+ } else {
449
+ out[key] = value;
450
+ }
451
+ }
452
+ return out;
453
+ }
454
+
455
+ // A message as a list of texts and nodes, where a placeholder whose value is a node, or a number
456
+ // in braces that indexes the nodes given, takes the node itself. Text stays text, so a message
457
+ // never carries markup.
458
+ export function tn(id, values = {}) {
459
+ const found = lookup(id);
460
+ if (!found) {
461
+ noteMissing(id);
462
+ return [id];
463
+ }
464
+ return markNodes(pick(found.message, values, found.locale), values);
465
+ }
466
+
467
+ // A message as a fragment of nodes, its marks as strong, code and kbd elements, for a place that
468
+ // takes one node, such as the text of a paragraph.
469
+ export function tm(id, values = {}) {
470
+ const fragment = document.createDocumentFragment();
471
+ fragment.append(...tn(id, values).map((part) => (typeof part === 'string' ? document.createTextNode(part) : part)));
472
+ return fragment;
473
+ }
474
+
475
+ // The nodes of a text with marks, each mark an element whose text the values fill, and each
476
+ // placeholder whose value is a node the node itself.
477
+ function markNodes(text, values) {
478
+ const out = [];
479
+ for (const part of markParts(text)) {
480
+ if (part.kind === 'text') {
481
+ out.push(...splitNodes(part.text, values));
482
+ } else if (part.kind === 'code') {
483
+ out.push(codeKind.node(fill(part.text, plainValues(values))));
484
+ } else {
485
+ const node = document.createElement('strong');
486
+ node.append(...splitNodes(part.text, values));
487
+ out.push(node);
488
+ }
489
+ }
490
+ return out;
491
+ }
492
+
493
+ // The values as text, a node as its text content, for the inside of code.
494
+ function plainValues(values) {
495
+ const out = {};
496
+ for (const [key, value] of Object.entries(values || {})) {
497
+ out[key] = value && typeof value === 'object' && 'textContent' in value ? value.textContent : value;
498
+ }
499
+ return out;
500
+ }
501
+
502
+ // The nodes of a message of the server, with its marks, as serverText reads it in text.
503
+ export function serverNodes(object, field = 'error', allow = null) {
504
+ if (!object || typeof object !== 'object') {
505
+ return [plainText(object)];
506
+ }
507
+ return labelNodes({ id: object[`${field}_id`], text: object[field], values: object[`${field}_values`] }, allow);
508
+ }
509
+
510
+ // The nodes of a label of the server, as labelText reads it in text. Its values show as text.
511
+ export function labelNodes(label, allow = null) {
512
+ const id = label && typeof label === 'object' && typeof label.id === 'string' && !label.kind && (!allow || allow(label.id)) ? label.id : null;
513
+ if (!id || !lookup(id)) {
514
+ return [labelText(label, allow)];
515
+ }
516
+ const values = label.values && typeof label.values === 'object' ? serverValues(label.values, allow, 1) : undefined;
517
+ return tn(id, values);
518
+ }
519
+
520
+ function splitNodes(text, values) {
521
+ const out = [];
522
+ let last = 0;
523
+ for (const match of text.matchAll(PLACEHOLDER)) {
524
+ const value = values[match[1]];
525
+ if (value === undefined || value === null) {
526
+ continue;
527
+ }
528
+ if (match.index > last) {
529
+ out.push(text.slice(last, match.index));
530
+ }
531
+ out.push(typeof value === 'object' ? value : String(value));
532
+ last = match.index + match[0].length;
533
+ }
534
+ if (last < text.length) {
535
+ out.push(text.slice(last));
536
+ }
537
+ return out;
538
+ }
539
+
540
+ // The attributes that static markup translates, each read from data-i18n-<attribute>.
541
+ const ATTRIBUTES = ['title', 'aria-label', 'placeholder', 'alt', 'aria-description', 'aria-roledescription', 'label'];
542
+
543
+ // A symbol of the sprite, an svg of the class icon, which a message of static markup leaves alone.
544
+ const isSymbol = (node) => node.localName === 'svg' && /(^|\s)icon(\s|$)/.test(node.getAttribute('class') || '');
545
+
546
+ // Translates the static texts under root. An element with data-i18n takes the message as its
547
+ // text, and when it holds elements, they fill the placeholders {0}, {1} and on in their order. A
548
+ // symbol among them fills no placeholder and stays in front of the message. Each
549
+ // data-i18n-<attribute> sets that attribute.
550
+ export function translateDom(root = document) {
551
+ if (!root || !root.querySelectorAll) {
552
+ return;
553
+ }
554
+ const nodes = [];
555
+ if (root.nodeType === 1) {
556
+ nodes.push(root);
557
+ }
558
+ nodes.push(...root.querySelectorAll('[data-i18n], [data-i18n-title], [data-i18n-aria-label], [data-i18n-placeholder], [data-i18n-alt], [data-i18n-aria-description], [data-i18n-aria-roledescription], [data-i18n-label]'));
559
+ for (const node of nodes) {
560
+ const id = node.dataset.i18n;
561
+ if (id) {
562
+ const symbols = [...node.children].filter(isSymbol);
563
+ const children = [...node.children].filter((child) => !isSymbol(child));
564
+ const found = lookup(id);
565
+ const marked = found && markParts(pick(found.message, {}, found.locale)).some((part) => part.kind !== 'text');
566
+ if (children.length || symbols.length) {
567
+ const values = {};
568
+ children.forEach((child, i) => { values[i] = child; });
569
+ node.replaceChildren(...symbols, ...tn(id, values));
570
+ } else if (marked) {
571
+ node.replaceChildren(...tn(id));
572
+ } else {
573
+ node.textContent = t(id);
574
+ }
575
+ }
576
+ for (const name of ATTRIBUTES) {
577
+ const key = node.getAttribute(`data-i18n-${name}`);
578
+ if (key) {
579
+ node.setAttribute(name, t(key));
580
+ }
581
+ }
582
+ }
583
+ }
584
+
585
+ // A number in the locale of the language.
586
+ export function formatNumber(value, options) {
587
+ try {
588
+ return new Intl.NumberFormat(info.locale, options).format(value);
589
+ } catch {
590
+ return String(value);
591
+ }
592
+ }
593
+
594
+ // A date in the locale of the language, from a Date, an ISO text or milliseconds.
595
+ export function formatDateTime(value, options = { dateStyle: 'medium', timeStyle: 'short' }) {
596
+ const date = value instanceof Date ? value : new Date(value);
597
+ if (Number.isNaN(date.getTime())) {
598
+ return '';
599
+ }
600
+ try {
601
+ return new Intl.DateTimeFormat(info.locale, options).format(date);
602
+ } catch {
603
+ return date.toISOString();
604
+ }
605
+ }
606
+
607
+ // Items joined as a list in the language, such as `a, b and c`.
608
+ export function formatList(items, type = 'conjunction') {
609
+ const list = [...items].map(String);
610
+ try {
611
+ return new Intl.ListFormat(info.locale, { style: 'long', type }).format(list);
612
+ } catch {
613
+ return list.join(', ');
614
+ }
615
+ }
616
+
617
+ // The language shown, its code, name, locale, direction and plural categories.
618
+ export function language() {
619
+ return { ...info };
620
+ }
621
+
622
+ // The locale of numbers and dates.
623
+ export function locale() {
624
+ return info.locale;
625
+ }
626
+
627
+ // The stored choice, or null while the page follows the browser.
628
+ export function storedLanguage() {
629
+ try {
630
+ const v = localStorage.getItem(STORE_KEY);
631
+ return v ? JSON.parse(v) : null;
632
+ } catch {
633
+ return null;
634
+ }
635
+ }
636
+
637
+ // The ids that no language held since the page loaded, for checks.
638
+ export function missing() {
639
+ return [...missingIds];
640
+ }
641
+
642
+ // The raw messages whose ids start with prefix, in the shown language with English beneath, for
643
+ // a module with its own formatter such as the captions.
644
+ export function messages(prefix = '') {
645
+ const out = {};
646
+ for (const source of [english, table]) {
647
+ for (const [id, value] of Object.entries(source)) {
648
+ if (id.startsWith(prefix)) {
649
+ out[id] = value;
650
+ }
651
+ }
652
+ }
653
+ return out;
654
+ }
655
+
656
+ // The languages to choose from, shipped first, from the server, else the shipped pair.
657
+ export async function listLanguages() {
658
+ try {
659
+ const res = await fetch('/api/languages');
660
+ if (res.ok) {
661
+ const body = await res.json();
662
+ if (Array.isArray(body.languages)) {
663
+ return body.languages;
664
+ }
665
+ }
666
+ } catch {
667
+ // Without the server the shipped languages remain.
668
+ }
669
+ return [
670
+ { code: 'en', name: 'English', source: 'shipped', usable: true },
671
+ ];
672
+ }
673
+
674
+ // Calls fn with the new language after each change.
675
+ export function onLanguageChange(fn) {
676
+ listeners.add(fn);
677
+ return () => listeners.delete(fn);
678
+ }
679
+
680
+ // Chooses a language, or null to follow the browser. The language loads first, so a file that
681
+ // fails leaves the page as it is and the promise rejects. Listeners then hear of the change.
682
+ export async function setLanguage(code) {
683
+ if (code === null) {
684
+ try {
685
+ localStorage.removeItem(STORE_KEY);
686
+ } catch {
687
+ // Storage can be unavailable.
688
+ }
689
+ } else {
690
+ const parsed = code === 'en' ? { messages: english, info: englishInfo } : parse(await readFile(code), code);
691
+ table = parsed.messages;
692
+ info = parsed.info;
693
+ try {
694
+ localStorage.setItem(STORE_KEY, JSON.stringify(code));
695
+ } catch {
696
+ // Storage can be unavailable, the choice then lasts for this visit only.
697
+ }
698
+ applyDocument();
699
+ }
700
+ for (const fn of listeners) {
701
+ fn(language());
702
+ }
703
+ }
704
+
705
+ await start();