@masterbble/dsh-coo-pet 0.0.0-stage → 0.6.29

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 (507) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +112 -2
  3. package/assets/desk-main.cjs +623 -0
  4. package/assets/desk-preload.cjs +116 -0
  5. package/assets/desk-probe.ps1 +213 -0
  6. package/assets/icon-snapshot.json +1 -0
  7. package/assets/pet/desk.html +2734 -0
  8. package/assets/pet/kit/body.js +1053 -0
  9. package/assets/pet/kit/rig.js +242 -0
  10. package/assets/pet/speech/zh.json +1 -0
  11. package/assets/pet/speech/zh.ogg +0 -0
  12. package/assets/pet/whale/feat/dizzy_eyeL.png +0 -0
  13. package/assets/pet/whale/feat/dizzy_eyeR.png +0 -0
  14. package/assets/pet/whale/feat/dizzy_mouth.png +0 -0
  15. package/assets/pet/whale/feat/drag_eyeL.png +0 -0
  16. package/assets/pet/whale/feat/drag_eyeR.png +0 -0
  17. package/assets/pet/whale/feat/drag_mouth.png +0 -0
  18. package/assets/pet/whale/feat/eyeL_ball.png +0 -0
  19. package/assets/pet/whale/feat/eyeL_hl.png +0 -0
  20. package/assets/pet/whale/feat/eyeL_iris.png +0 -0
  21. package/assets/pet/whale/feat/eyeL_lash.png +0 -0
  22. package/assets/pet/whale/feat/eyeR_ball.png +0 -0
  23. package/assets/pet/whale/feat/eyeR_hl.png +0 -0
  24. package/assets/pet/whale/feat/eyeR_iris.png +0 -0
  25. package/assets/pet/whale/feat/eyeR_lash.png +0 -0
  26. package/assets/pet/whale/feat/happy_eyeL.png +0 -0
  27. package/assets/pet/whale/feat/happy_eyeR.png +0 -0
  28. package/assets/pet/whale/feat/happy_mouth.png +0 -0
  29. package/assets/pet/whale/feat/love_eyeL.png +0 -0
  30. package/assets/pet/whale/feat/love_eyeR.png +0 -0
  31. package/assets/pet/whale/feat/love_mouth.png +0 -0
  32. package/assets/pet/whale/feat/neutral_mouth.png +0 -0
  33. package/assets/pet/whale/feat/sleep_eyeL.png +0 -0
  34. package/assets/pet/whale/feat/sleep_eyeR.png +0 -0
  35. package/assets/pet/whale/feat/sleep_mouth.png +0 -0
  36. package/assets/pet/whale/feat/surprised_eyeL.png +0 -0
  37. package/assets/pet/whale/feat/surprised_eyeR.png +0 -0
  38. package/assets/pet/whale/feat/surprised_mouth.png +0 -0
  39. package/assets/pet/whale/figure.js +948 -0
  40. package/assets/pet/whale/figure.json +997 -0
  41. package/assets/pet/whale/model.json +1710 -0
  42. package/assets/pet/whale/outfits/cape/arm_far.png +0 -0
  43. package/assets/pet/whale/outfits/cape/arm_far_end_front.png +0 -0
  44. package/assets/pet/whale/outfits/cape/arm_near.png +0 -0
  45. package/assets/pet/whale/outfits/cape/cloak.png +0 -0
  46. package/assets/pet/whale/outfits/cape/cloak_shoulder_cover.png +0 -0
  47. package/assets/pet/whale/outfits/cape/hood_back.png +0 -0
  48. package/assets/pet/whale/outfits/cape/hood_fin_far.png +0 -0
  49. package/assets/pet/whale/outfits/cape/hood_fin_near.png +0 -0
  50. package/assets/pet/whale/outfits/cape/hood_front.png +0 -0
  51. package/assets/pet/whale/outfits/cape/hood_lining.png +0 -0
  52. package/assets/pet/whale/outfits/cape/hood_tie_far.png +0 -0
  53. package/assets/pet/whale/outfits/cape/hood_tie_near.png +0 -0
  54. package/assets/pet/whale/outfits/cape/leg_back.png +0 -0
  55. package/assets/pet/whale/outfits/cape/leg_front.png +0 -0
  56. package/assets/pet/whale/outfits/cape/scarf_neck.png +0 -0
  57. package/assets/pet/whale/outfits/cape/scarf_tail_back.png +0 -0
  58. package/assets/pet/whale/outfits/cape/scarf_tail_front.png +0 -0
  59. package/assets/pet/whale/outfits/cape/skirt.png +0 -0
  60. package/assets/pet/whale/outfits/cape/skirt_sit.png +0 -0
  61. package/assets/pet/whale/outfits/cape/spout.png +0 -0
  62. package/assets/pet/whale/outfits/crew/arm_far.png +0 -0
  63. package/assets/pet/whale/outfits/crew/arm_near.png +0 -0
  64. package/assets/pet/whale/outfits/crew/bow_near.png +0 -0
  65. package/assets/pet/whale/outfits/crew/headset.png +0 -0
  66. package/assets/pet/whale/outfits/crew/leg_back.png +0 -0
  67. package/assets/pet/whale/outfits/crew/leg_front.png +0 -0
  68. package/assets/pet/whale/outfits/crew/pony_bow.png +0 -0
  69. package/assets/pet/whale/outfits/crew/skirt_shadow.png +0 -0
  70. package/assets/pet/whale/outfits/crew/torso_up.png +0 -0
  71. package/assets/pet/whale/outfits/crew/visor.png +0 -0
  72. package/assets/pet/whale/schemes/chatgpt/feat/dizzy_eyeL.png +0 -0
  73. package/assets/pet/whale/schemes/chatgpt/feat/dizzy_eyeR.png +0 -0
  74. package/assets/pet/whale/schemes/chatgpt/feat/dizzy_mouth.png +0 -0
  75. package/assets/pet/whale/schemes/chatgpt/feat/drag_eyeL.png +0 -0
  76. package/assets/pet/whale/schemes/chatgpt/feat/drag_eyeR.png +0 -0
  77. package/assets/pet/whale/schemes/chatgpt/feat/drag_mouth.png +0 -0
  78. package/assets/pet/whale/schemes/chatgpt/feat/eyeL_ball.png +0 -0
  79. package/assets/pet/whale/schemes/chatgpt/feat/eyeL_iris.png +0 -0
  80. package/assets/pet/whale/schemes/chatgpt/feat/eyeL_lash.png +0 -0
  81. package/assets/pet/whale/schemes/chatgpt/feat/eyeR_ball.png +0 -0
  82. package/assets/pet/whale/schemes/chatgpt/feat/eyeR_iris.png +0 -0
  83. package/assets/pet/whale/schemes/chatgpt/feat/eyeR_lash.png +0 -0
  84. package/assets/pet/whale/schemes/chatgpt/feat/happy_eyeL.png +0 -0
  85. package/assets/pet/whale/schemes/chatgpt/feat/happy_eyeR.png +0 -0
  86. package/assets/pet/whale/schemes/chatgpt/feat/happy_mouth.png +0 -0
  87. package/assets/pet/whale/schemes/chatgpt/feat/love_eyeL.png +0 -0
  88. package/assets/pet/whale/schemes/chatgpt/feat/love_eyeR.png +0 -0
  89. package/assets/pet/whale/schemes/chatgpt/feat/love_mouth.png +0 -0
  90. package/assets/pet/whale/schemes/chatgpt/feat/neutral_mouth.png +0 -0
  91. package/assets/pet/whale/schemes/chatgpt/feat/sleep_eyeL.png +0 -0
  92. package/assets/pet/whale/schemes/chatgpt/feat/sleep_eyeR.png +0 -0
  93. package/assets/pet/whale/schemes/chatgpt/feat/sleep_mouth.png +0 -0
  94. package/assets/pet/whale/schemes/chatgpt/feat/surprised_eyeL.png +0 -0
  95. package/assets/pet/whale/schemes/chatgpt/feat/surprised_eyeR.png +0 -0
  96. package/assets/pet/whale/schemes/chatgpt/feat/surprised_mouth.png +0 -0
  97. package/assets/pet/whale/schemes/chatgpt/tex/ahoge.png +0 -0
  98. package/assets/pet/whale/schemes/chatgpt/tex/arm_far.png +0 -0
  99. package/assets/pet/whale/schemes/chatgpt/tex/arm_far_end_front.png +0 -0
  100. package/assets/pet/whale/schemes/chatgpt/tex/arm_near.png +0 -0
  101. package/assets/pet/whale/schemes/chatgpt/tex/bangs.png +0 -0
  102. package/assets/pet/whale/schemes/chatgpt/tex/bow.png +0 -0
  103. package/assets/pet/whale/schemes/chatgpt/tex/brows.png +0 -0
  104. package/assets/pet/whale/schemes/chatgpt/tex/crew_hair_back.png +0 -0
  105. package/assets/pet/whale/schemes/chatgpt/tex/crew_ponytail.png +0 -0
  106. package/assets/pet/whale/schemes/chatgpt/tex/crew_sidelocks.png +0 -0
  107. package/assets/pet/whale/schemes/chatgpt/tex/crew_skirt.png +0 -0
  108. package/assets/pet/whale/schemes/chatgpt/tex/crew_skirt_sit.png +0 -0
  109. package/assets/pet/whale/schemes/chatgpt/tex/eye_creases.png +0 -0
  110. package/assets/pet/whale/schemes/chatgpt/tex/face.png +0 -0
  111. package/assets/pet/whale/schemes/chatgpt/tex/fin_far.png +0 -0
  112. package/assets/pet/whale/schemes/chatgpt/tex/fin_near.png +0 -0
  113. package/assets/pet/whale/schemes/chatgpt/tex/hair_back.png +0 -0
  114. package/assets/pet/whale/schemes/chatgpt/tex/hair_back_curl.png +0 -0
  115. package/assets/pet/whale/schemes/chatgpt/tex/hair_front_left.png +0 -0
  116. package/assets/pet/whale/schemes/chatgpt/tex/hair_front_right.png +0 -0
  117. package/assets/pet/whale/schemes/chatgpt/tex/headdress.png +0 -0
  118. package/assets/pet/whale/schemes/chatgpt/tex/leg_back.png +0 -0
  119. package/assets/pet/whale/schemes/chatgpt/tex/leg_front.png +0 -0
  120. package/assets/pet/whale/schemes/chatgpt/tex/sidelocks.png +0 -0
  121. package/assets/pet/whale/schemes/chatgpt/tex/skirt.png +0 -0
  122. package/assets/pet/whale/schemes/chatgpt/tex/skirt_sit.png +0 -0
  123. package/assets/pet/whale/schemes/chatgpt/tex/tail.png +0 -0
  124. package/assets/pet/whale/schemes/chatgpt/tex/torso_up.png +0 -0
  125. package/assets/pet/whale/schemes/chatgpt/tex/waist_bow_front.png +0 -0
  126. package/assets/pet/whale/schemes/chatgpt/tex/waist_bow_sit_front.png +0 -0
  127. package/assets/pet/whale/schemes/claude/feat/dizzy_eyeL.png +0 -0
  128. package/assets/pet/whale/schemes/claude/feat/dizzy_eyeR.png +0 -0
  129. package/assets/pet/whale/schemes/claude/feat/dizzy_mouth.png +0 -0
  130. package/assets/pet/whale/schemes/claude/feat/drag_eyeL.png +0 -0
  131. package/assets/pet/whale/schemes/claude/feat/drag_eyeR.png +0 -0
  132. package/assets/pet/whale/schemes/claude/feat/drag_mouth.png +0 -0
  133. package/assets/pet/whale/schemes/claude/feat/eyeL_ball.png +0 -0
  134. package/assets/pet/whale/schemes/claude/feat/eyeL_iris.png +0 -0
  135. package/assets/pet/whale/schemes/claude/feat/eyeL_lash.png +0 -0
  136. package/assets/pet/whale/schemes/claude/feat/eyeR_ball.png +0 -0
  137. package/assets/pet/whale/schemes/claude/feat/eyeR_iris.png +0 -0
  138. package/assets/pet/whale/schemes/claude/feat/eyeR_lash.png +0 -0
  139. package/assets/pet/whale/schemes/claude/feat/happy_eyeL.png +0 -0
  140. package/assets/pet/whale/schemes/claude/feat/happy_eyeR.png +0 -0
  141. package/assets/pet/whale/schemes/claude/feat/happy_mouth.png +0 -0
  142. package/assets/pet/whale/schemes/claude/feat/love_eyeL.png +0 -0
  143. package/assets/pet/whale/schemes/claude/feat/love_eyeR.png +0 -0
  144. package/assets/pet/whale/schemes/claude/feat/love_mouth.png +0 -0
  145. package/assets/pet/whale/schemes/claude/feat/neutral_mouth.png +0 -0
  146. package/assets/pet/whale/schemes/claude/feat/sleep_eyeL.png +0 -0
  147. package/assets/pet/whale/schemes/claude/feat/sleep_eyeR.png +0 -0
  148. package/assets/pet/whale/schemes/claude/feat/sleep_mouth.png +0 -0
  149. package/assets/pet/whale/schemes/claude/feat/surprised_eyeL.png +0 -0
  150. package/assets/pet/whale/schemes/claude/feat/surprised_eyeR.png +0 -0
  151. package/assets/pet/whale/schemes/claude/feat/surprised_mouth.png +0 -0
  152. package/assets/pet/whale/schemes/claude/tex/ahoge.png +0 -0
  153. package/assets/pet/whale/schemes/claude/tex/arm_far.png +0 -0
  154. package/assets/pet/whale/schemes/claude/tex/arm_far_end_front.png +0 -0
  155. package/assets/pet/whale/schemes/claude/tex/arm_near.png +0 -0
  156. package/assets/pet/whale/schemes/claude/tex/bangs.png +0 -0
  157. package/assets/pet/whale/schemes/claude/tex/bow.png +0 -0
  158. package/assets/pet/whale/schemes/claude/tex/brows.png +0 -0
  159. package/assets/pet/whale/schemes/claude/tex/crew_hair_back.png +0 -0
  160. package/assets/pet/whale/schemes/claude/tex/crew_ponytail.png +0 -0
  161. package/assets/pet/whale/schemes/claude/tex/crew_sidelocks.png +0 -0
  162. package/assets/pet/whale/schemes/claude/tex/crew_skirt.png +0 -0
  163. package/assets/pet/whale/schemes/claude/tex/crew_skirt_sit.png +0 -0
  164. package/assets/pet/whale/schemes/claude/tex/eye_creases.png +0 -0
  165. package/assets/pet/whale/schemes/claude/tex/face.png +0 -0
  166. package/assets/pet/whale/schemes/claude/tex/fin_far.png +0 -0
  167. package/assets/pet/whale/schemes/claude/tex/fin_near.png +0 -0
  168. package/assets/pet/whale/schemes/claude/tex/hair_back.png +0 -0
  169. package/assets/pet/whale/schemes/claude/tex/hair_back_curl.png +0 -0
  170. package/assets/pet/whale/schemes/claude/tex/hair_front_left.png +0 -0
  171. package/assets/pet/whale/schemes/claude/tex/hair_front_right.png +0 -0
  172. package/assets/pet/whale/schemes/claude/tex/headdress.png +0 -0
  173. package/assets/pet/whale/schemes/claude/tex/leg_back.png +0 -0
  174. package/assets/pet/whale/schemes/claude/tex/leg_front.png +0 -0
  175. package/assets/pet/whale/schemes/claude/tex/sidelocks.png +0 -0
  176. package/assets/pet/whale/schemes/claude/tex/skirt.png +0 -0
  177. package/assets/pet/whale/schemes/claude/tex/skirt_sit.png +0 -0
  178. package/assets/pet/whale/schemes/claude/tex/tail.png +0 -0
  179. package/assets/pet/whale/schemes/claude/tex/torso_up.png +0 -0
  180. package/assets/pet/whale/schemes/claude/tex/waist_bow_front.png +0 -0
  181. package/assets/pet/whale/schemes/claude/tex/waist_bow_sit_front.png +0 -0
  182. package/assets/pet/whale/schemes/gemini/feat/dizzy_eyeL.png +0 -0
  183. package/assets/pet/whale/schemes/gemini/feat/dizzy_eyeR.png +0 -0
  184. package/assets/pet/whale/schemes/gemini/feat/dizzy_mouth.png +0 -0
  185. package/assets/pet/whale/schemes/gemini/feat/drag_eyeL.png +0 -0
  186. package/assets/pet/whale/schemes/gemini/feat/drag_eyeR.png +0 -0
  187. package/assets/pet/whale/schemes/gemini/feat/drag_mouth.png +0 -0
  188. package/assets/pet/whale/schemes/gemini/feat/eyeL_ball.png +0 -0
  189. package/assets/pet/whale/schemes/gemini/feat/eyeL_iris.png +0 -0
  190. package/assets/pet/whale/schemes/gemini/feat/eyeL_lash.png +0 -0
  191. package/assets/pet/whale/schemes/gemini/feat/eyeR_ball.png +0 -0
  192. package/assets/pet/whale/schemes/gemini/feat/eyeR_iris.png +0 -0
  193. package/assets/pet/whale/schemes/gemini/feat/eyeR_lash.png +0 -0
  194. package/assets/pet/whale/schemes/gemini/feat/happy_eyeL.png +0 -0
  195. package/assets/pet/whale/schemes/gemini/feat/happy_eyeR.png +0 -0
  196. package/assets/pet/whale/schemes/gemini/feat/happy_mouth.png +0 -0
  197. package/assets/pet/whale/schemes/gemini/feat/love_eyeL.png +0 -0
  198. package/assets/pet/whale/schemes/gemini/feat/love_eyeR.png +0 -0
  199. package/assets/pet/whale/schemes/gemini/feat/love_mouth.png +0 -0
  200. package/assets/pet/whale/schemes/gemini/feat/neutral_mouth.png +0 -0
  201. package/assets/pet/whale/schemes/gemini/feat/sleep_eyeL.png +0 -0
  202. package/assets/pet/whale/schemes/gemini/feat/sleep_eyeR.png +0 -0
  203. package/assets/pet/whale/schemes/gemini/feat/sleep_mouth.png +0 -0
  204. package/assets/pet/whale/schemes/gemini/feat/surprised_eyeL.png +0 -0
  205. package/assets/pet/whale/schemes/gemini/feat/surprised_eyeR.png +0 -0
  206. package/assets/pet/whale/schemes/gemini/feat/surprised_mouth.png +0 -0
  207. package/assets/pet/whale/schemes/gemini/tex/ahoge.png +0 -0
  208. package/assets/pet/whale/schemes/gemini/tex/arm_far.png +0 -0
  209. package/assets/pet/whale/schemes/gemini/tex/arm_far_end_front.png +0 -0
  210. package/assets/pet/whale/schemes/gemini/tex/arm_near.png +0 -0
  211. package/assets/pet/whale/schemes/gemini/tex/bangs.png +0 -0
  212. package/assets/pet/whale/schemes/gemini/tex/bow.png +0 -0
  213. package/assets/pet/whale/schemes/gemini/tex/brows.png +0 -0
  214. package/assets/pet/whale/schemes/gemini/tex/crew_hair_back.png +0 -0
  215. package/assets/pet/whale/schemes/gemini/tex/crew_ponytail.png +0 -0
  216. package/assets/pet/whale/schemes/gemini/tex/crew_sidelocks.png +0 -0
  217. package/assets/pet/whale/schemes/gemini/tex/crew_skirt.png +0 -0
  218. package/assets/pet/whale/schemes/gemini/tex/crew_skirt_sit.png +0 -0
  219. package/assets/pet/whale/schemes/gemini/tex/eye_creases.png +0 -0
  220. package/assets/pet/whale/schemes/gemini/tex/face.png +0 -0
  221. package/assets/pet/whale/schemes/gemini/tex/fin_far.png +0 -0
  222. package/assets/pet/whale/schemes/gemini/tex/fin_near.png +0 -0
  223. package/assets/pet/whale/schemes/gemini/tex/hair_back.png +0 -0
  224. package/assets/pet/whale/schemes/gemini/tex/hair_back_curl.png +0 -0
  225. package/assets/pet/whale/schemes/gemini/tex/hair_front_left.png +0 -0
  226. package/assets/pet/whale/schemes/gemini/tex/hair_front_right.png +0 -0
  227. package/assets/pet/whale/schemes/gemini/tex/headdress.png +0 -0
  228. package/assets/pet/whale/schemes/gemini/tex/leg_back.png +0 -0
  229. package/assets/pet/whale/schemes/gemini/tex/leg_front.png +0 -0
  230. package/assets/pet/whale/schemes/gemini/tex/sidelocks.png +0 -0
  231. package/assets/pet/whale/schemes/gemini/tex/skirt.png +0 -0
  232. package/assets/pet/whale/schemes/gemini/tex/skirt_sit.png +0 -0
  233. package/assets/pet/whale/schemes/gemini/tex/tail.png +0 -0
  234. package/assets/pet/whale/schemes/gemini/tex/torso_up.png +0 -0
  235. package/assets/pet/whale/schemes/gemini/tex/waist_bow_front.png +0 -0
  236. package/assets/pet/whale/schemes/gemini/tex/waist_bow_sit_front.png +0 -0
  237. package/assets/pet/whale/schemes/harness/feat/dizzy_eyeL.png +0 -0
  238. package/assets/pet/whale/schemes/harness/feat/dizzy_eyeR.png +0 -0
  239. package/assets/pet/whale/schemes/harness/feat/dizzy_mouth.png +0 -0
  240. package/assets/pet/whale/schemes/harness/feat/drag_eyeL.png +0 -0
  241. package/assets/pet/whale/schemes/harness/feat/drag_eyeR.png +0 -0
  242. package/assets/pet/whale/schemes/harness/feat/drag_mouth.png +0 -0
  243. package/assets/pet/whale/schemes/harness/feat/eyeL_ball.png +0 -0
  244. package/assets/pet/whale/schemes/harness/feat/eyeL_iris.png +0 -0
  245. package/assets/pet/whale/schemes/harness/feat/eyeL_lash.png +0 -0
  246. package/assets/pet/whale/schemes/harness/feat/eyeR_ball.png +0 -0
  247. package/assets/pet/whale/schemes/harness/feat/eyeR_iris.png +0 -0
  248. package/assets/pet/whale/schemes/harness/feat/eyeR_lash.png +0 -0
  249. package/assets/pet/whale/schemes/harness/feat/happy_eyeL.png +0 -0
  250. package/assets/pet/whale/schemes/harness/feat/happy_eyeR.png +0 -0
  251. package/assets/pet/whale/schemes/harness/feat/happy_mouth.png +0 -0
  252. package/assets/pet/whale/schemes/harness/feat/love_eyeL.png +0 -0
  253. package/assets/pet/whale/schemes/harness/feat/love_eyeR.png +0 -0
  254. package/assets/pet/whale/schemes/harness/feat/love_mouth.png +0 -0
  255. package/assets/pet/whale/schemes/harness/feat/neutral_mouth.png +0 -0
  256. package/assets/pet/whale/schemes/harness/feat/sleep_eyeL.png +0 -0
  257. package/assets/pet/whale/schemes/harness/feat/sleep_eyeR.png +0 -0
  258. package/assets/pet/whale/schemes/harness/feat/sleep_mouth.png +0 -0
  259. package/assets/pet/whale/schemes/harness/feat/surprised_eyeL.png +0 -0
  260. package/assets/pet/whale/schemes/harness/feat/surprised_eyeR.png +0 -0
  261. package/assets/pet/whale/schemes/harness/feat/surprised_mouth.png +0 -0
  262. package/assets/pet/whale/schemes/harness/tex/ahoge.png +0 -0
  263. package/assets/pet/whale/schemes/harness/tex/arm_far.png +0 -0
  264. package/assets/pet/whale/schemes/harness/tex/arm_far_end_front.png +0 -0
  265. package/assets/pet/whale/schemes/harness/tex/arm_near.png +0 -0
  266. package/assets/pet/whale/schemes/harness/tex/bangs.png +0 -0
  267. package/assets/pet/whale/schemes/harness/tex/bow.png +0 -0
  268. package/assets/pet/whale/schemes/harness/tex/brows.png +0 -0
  269. package/assets/pet/whale/schemes/harness/tex/crew_hair_back.png +0 -0
  270. package/assets/pet/whale/schemes/harness/tex/crew_ponytail.png +0 -0
  271. package/assets/pet/whale/schemes/harness/tex/crew_sidelocks.png +0 -0
  272. package/assets/pet/whale/schemes/harness/tex/crew_skirt.png +0 -0
  273. package/assets/pet/whale/schemes/harness/tex/crew_skirt_sit.png +0 -0
  274. package/assets/pet/whale/schemes/harness/tex/eye_creases.png +0 -0
  275. package/assets/pet/whale/schemes/harness/tex/face.png +0 -0
  276. package/assets/pet/whale/schemes/harness/tex/fin_far.png +0 -0
  277. package/assets/pet/whale/schemes/harness/tex/fin_near.png +0 -0
  278. package/assets/pet/whale/schemes/harness/tex/hair_back.png +0 -0
  279. package/assets/pet/whale/schemes/harness/tex/hair_back_curl.png +0 -0
  280. package/assets/pet/whale/schemes/harness/tex/hair_front_left.png +0 -0
  281. package/assets/pet/whale/schemes/harness/tex/hair_front_right.png +0 -0
  282. package/assets/pet/whale/schemes/harness/tex/headdress.png +0 -0
  283. package/assets/pet/whale/schemes/harness/tex/leg_back.png +0 -0
  284. package/assets/pet/whale/schemes/harness/tex/leg_front.png +0 -0
  285. package/assets/pet/whale/schemes/harness/tex/sidelocks.png +0 -0
  286. package/assets/pet/whale/schemes/harness/tex/skirt.png +0 -0
  287. package/assets/pet/whale/schemes/harness/tex/skirt_sit.png +0 -0
  288. package/assets/pet/whale/schemes/harness/tex/tail.png +0 -0
  289. package/assets/pet/whale/schemes/harness/tex/torso_up.png +0 -0
  290. package/assets/pet/whale/schemes/harness/tex/waist_bow_front.png +0 -0
  291. package/assets/pet/whale/schemes/harness/tex/waist_bow_sit_front.png +0 -0
  292. package/assets/pet/whale/schemes/kimi/feat/dizzy_eyeL.png +0 -0
  293. package/assets/pet/whale/schemes/kimi/feat/dizzy_eyeR.png +0 -0
  294. package/assets/pet/whale/schemes/kimi/feat/dizzy_mouth.png +0 -0
  295. package/assets/pet/whale/schemes/kimi/feat/drag_eyeL.png +0 -0
  296. package/assets/pet/whale/schemes/kimi/feat/drag_eyeR.png +0 -0
  297. package/assets/pet/whale/schemes/kimi/feat/drag_mouth.png +0 -0
  298. package/assets/pet/whale/schemes/kimi/feat/eyeL_ball.png +0 -0
  299. package/assets/pet/whale/schemes/kimi/feat/eyeL_iris.png +0 -0
  300. package/assets/pet/whale/schemes/kimi/feat/eyeL_lash.png +0 -0
  301. package/assets/pet/whale/schemes/kimi/feat/eyeR_ball.png +0 -0
  302. package/assets/pet/whale/schemes/kimi/feat/eyeR_iris.png +0 -0
  303. package/assets/pet/whale/schemes/kimi/feat/eyeR_lash.png +0 -0
  304. package/assets/pet/whale/schemes/kimi/feat/happy_eyeL.png +0 -0
  305. package/assets/pet/whale/schemes/kimi/feat/happy_eyeR.png +0 -0
  306. package/assets/pet/whale/schemes/kimi/feat/happy_mouth.png +0 -0
  307. package/assets/pet/whale/schemes/kimi/feat/love_eyeL.png +0 -0
  308. package/assets/pet/whale/schemes/kimi/feat/love_eyeR.png +0 -0
  309. package/assets/pet/whale/schemes/kimi/feat/love_mouth.png +0 -0
  310. package/assets/pet/whale/schemes/kimi/feat/neutral_mouth.png +0 -0
  311. package/assets/pet/whale/schemes/kimi/feat/sleep_eyeL.png +0 -0
  312. package/assets/pet/whale/schemes/kimi/feat/sleep_eyeR.png +0 -0
  313. package/assets/pet/whale/schemes/kimi/feat/sleep_mouth.png +0 -0
  314. package/assets/pet/whale/schemes/kimi/feat/surprised_eyeL.png +0 -0
  315. package/assets/pet/whale/schemes/kimi/feat/surprised_eyeR.png +0 -0
  316. package/assets/pet/whale/schemes/kimi/feat/surprised_mouth.png +0 -0
  317. package/assets/pet/whale/schemes/kimi/tex/ahoge.png +0 -0
  318. package/assets/pet/whale/schemes/kimi/tex/arm_far.png +0 -0
  319. package/assets/pet/whale/schemes/kimi/tex/arm_far_end_front.png +0 -0
  320. package/assets/pet/whale/schemes/kimi/tex/arm_near.png +0 -0
  321. package/assets/pet/whale/schemes/kimi/tex/bangs.png +0 -0
  322. package/assets/pet/whale/schemes/kimi/tex/bow.png +0 -0
  323. package/assets/pet/whale/schemes/kimi/tex/brows.png +0 -0
  324. package/assets/pet/whale/schemes/kimi/tex/crew_hair_back.png +0 -0
  325. package/assets/pet/whale/schemes/kimi/tex/crew_ponytail.png +0 -0
  326. package/assets/pet/whale/schemes/kimi/tex/crew_sidelocks.png +0 -0
  327. package/assets/pet/whale/schemes/kimi/tex/crew_skirt.png +0 -0
  328. package/assets/pet/whale/schemes/kimi/tex/crew_skirt_sit.png +0 -0
  329. package/assets/pet/whale/schemes/kimi/tex/eye_creases.png +0 -0
  330. package/assets/pet/whale/schemes/kimi/tex/face.png +0 -0
  331. package/assets/pet/whale/schemes/kimi/tex/fin_far.png +0 -0
  332. package/assets/pet/whale/schemes/kimi/tex/fin_near.png +0 -0
  333. package/assets/pet/whale/schemes/kimi/tex/hair_back.png +0 -0
  334. package/assets/pet/whale/schemes/kimi/tex/hair_back_curl.png +0 -0
  335. package/assets/pet/whale/schemes/kimi/tex/hair_front_left.png +0 -0
  336. package/assets/pet/whale/schemes/kimi/tex/hair_front_right.png +0 -0
  337. package/assets/pet/whale/schemes/kimi/tex/headdress.png +0 -0
  338. package/assets/pet/whale/schemes/kimi/tex/leg_back.png +0 -0
  339. package/assets/pet/whale/schemes/kimi/tex/leg_front.png +0 -0
  340. package/assets/pet/whale/schemes/kimi/tex/sidelocks.png +0 -0
  341. package/assets/pet/whale/schemes/kimi/tex/skirt.png +0 -0
  342. package/assets/pet/whale/schemes/kimi/tex/skirt_sit.png +0 -0
  343. package/assets/pet/whale/schemes/kimi/tex/tail.png +0 -0
  344. package/assets/pet/whale/schemes/kimi/tex/torso_up.png +0 -0
  345. package/assets/pet/whale/schemes/kimi/tex/waist_bow_front.png +0 -0
  346. package/assets/pet/whale/schemes/kimi/tex/waist_bow_sit_front.png +0 -0
  347. package/assets/pet/whale/schemes/minimax/feat/dizzy_eyeL.png +0 -0
  348. package/assets/pet/whale/schemes/minimax/feat/dizzy_eyeR.png +0 -0
  349. package/assets/pet/whale/schemes/minimax/feat/dizzy_mouth.png +0 -0
  350. package/assets/pet/whale/schemes/minimax/feat/drag_eyeL.png +0 -0
  351. package/assets/pet/whale/schemes/minimax/feat/drag_eyeR.png +0 -0
  352. package/assets/pet/whale/schemes/minimax/feat/drag_mouth.png +0 -0
  353. package/assets/pet/whale/schemes/minimax/feat/eyeL_ball.png +0 -0
  354. package/assets/pet/whale/schemes/minimax/feat/eyeL_iris.png +0 -0
  355. package/assets/pet/whale/schemes/minimax/feat/eyeL_lash.png +0 -0
  356. package/assets/pet/whale/schemes/minimax/feat/eyeR_ball.png +0 -0
  357. package/assets/pet/whale/schemes/minimax/feat/eyeR_iris.png +0 -0
  358. package/assets/pet/whale/schemes/minimax/feat/eyeR_lash.png +0 -0
  359. package/assets/pet/whale/schemes/minimax/feat/happy_eyeL.png +0 -0
  360. package/assets/pet/whale/schemes/minimax/feat/happy_eyeR.png +0 -0
  361. package/assets/pet/whale/schemes/minimax/feat/happy_mouth.png +0 -0
  362. package/assets/pet/whale/schemes/minimax/feat/love_eyeL.png +0 -0
  363. package/assets/pet/whale/schemes/minimax/feat/love_eyeR.png +0 -0
  364. package/assets/pet/whale/schemes/minimax/feat/love_mouth.png +0 -0
  365. package/assets/pet/whale/schemes/minimax/feat/neutral_mouth.png +0 -0
  366. package/assets/pet/whale/schemes/minimax/feat/sleep_eyeL.png +0 -0
  367. package/assets/pet/whale/schemes/minimax/feat/sleep_eyeR.png +0 -0
  368. package/assets/pet/whale/schemes/minimax/feat/sleep_mouth.png +0 -0
  369. package/assets/pet/whale/schemes/minimax/feat/surprised_eyeL.png +0 -0
  370. package/assets/pet/whale/schemes/minimax/feat/surprised_eyeR.png +0 -0
  371. package/assets/pet/whale/schemes/minimax/feat/surprised_mouth.png +0 -0
  372. package/assets/pet/whale/schemes/minimax/tex/ahoge.png +0 -0
  373. package/assets/pet/whale/schemes/minimax/tex/arm_far.png +0 -0
  374. package/assets/pet/whale/schemes/minimax/tex/arm_far_end_front.png +0 -0
  375. package/assets/pet/whale/schemes/minimax/tex/arm_near.png +0 -0
  376. package/assets/pet/whale/schemes/minimax/tex/bangs.png +0 -0
  377. package/assets/pet/whale/schemes/minimax/tex/bow.png +0 -0
  378. package/assets/pet/whale/schemes/minimax/tex/brows.png +0 -0
  379. package/assets/pet/whale/schemes/minimax/tex/crew_hair_back.png +0 -0
  380. package/assets/pet/whale/schemes/minimax/tex/crew_ponytail.png +0 -0
  381. package/assets/pet/whale/schemes/minimax/tex/crew_sidelocks.png +0 -0
  382. package/assets/pet/whale/schemes/minimax/tex/crew_skirt.png +0 -0
  383. package/assets/pet/whale/schemes/minimax/tex/crew_skirt_sit.png +0 -0
  384. package/assets/pet/whale/schemes/minimax/tex/eye_creases.png +0 -0
  385. package/assets/pet/whale/schemes/minimax/tex/face.png +0 -0
  386. package/assets/pet/whale/schemes/minimax/tex/fin_far.png +0 -0
  387. package/assets/pet/whale/schemes/minimax/tex/fin_near.png +0 -0
  388. package/assets/pet/whale/schemes/minimax/tex/hair_back.png +0 -0
  389. package/assets/pet/whale/schemes/minimax/tex/hair_back_curl.png +0 -0
  390. package/assets/pet/whale/schemes/minimax/tex/hair_front_left.png +0 -0
  391. package/assets/pet/whale/schemes/minimax/tex/hair_front_right.png +0 -0
  392. package/assets/pet/whale/schemes/minimax/tex/headdress.png +0 -0
  393. package/assets/pet/whale/schemes/minimax/tex/leg_back.png +0 -0
  394. package/assets/pet/whale/schemes/minimax/tex/leg_front.png +0 -0
  395. package/assets/pet/whale/schemes/minimax/tex/sidelocks.png +0 -0
  396. package/assets/pet/whale/schemes/minimax/tex/skirt.png +0 -0
  397. package/assets/pet/whale/schemes/minimax/tex/skirt_sit.png +0 -0
  398. package/assets/pet/whale/schemes/minimax/tex/tail.png +0 -0
  399. package/assets/pet/whale/schemes/minimax/tex/torso_up.png +0 -0
  400. package/assets/pet/whale/schemes/minimax/tex/waist_bow_front.png +0 -0
  401. package/assets/pet/whale/schemes/minimax/tex/waist_bow_sit_front.png +0 -0
  402. package/assets/pet/whale/schemes/qwen/feat/dizzy_eyeL.png +0 -0
  403. package/assets/pet/whale/schemes/qwen/feat/dizzy_eyeR.png +0 -0
  404. package/assets/pet/whale/schemes/qwen/feat/dizzy_mouth.png +0 -0
  405. package/assets/pet/whale/schemes/qwen/feat/drag_eyeL.png +0 -0
  406. package/assets/pet/whale/schemes/qwen/feat/drag_eyeR.png +0 -0
  407. package/assets/pet/whale/schemes/qwen/feat/drag_mouth.png +0 -0
  408. package/assets/pet/whale/schemes/qwen/feat/eyeL_ball.png +0 -0
  409. package/assets/pet/whale/schemes/qwen/feat/eyeL_iris.png +0 -0
  410. package/assets/pet/whale/schemes/qwen/feat/eyeL_lash.png +0 -0
  411. package/assets/pet/whale/schemes/qwen/feat/eyeR_ball.png +0 -0
  412. package/assets/pet/whale/schemes/qwen/feat/eyeR_iris.png +0 -0
  413. package/assets/pet/whale/schemes/qwen/feat/eyeR_lash.png +0 -0
  414. package/assets/pet/whale/schemes/qwen/feat/happy_eyeL.png +0 -0
  415. package/assets/pet/whale/schemes/qwen/feat/happy_eyeR.png +0 -0
  416. package/assets/pet/whale/schemes/qwen/feat/happy_mouth.png +0 -0
  417. package/assets/pet/whale/schemes/qwen/feat/love_eyeL.png +0 -0
  418. package/assets/pet/whale/schemes/qwen/feat/love_eyeR.png +0 -0
  419. package/assets/pet/whale/schemes/qwen/feat/love_mouth.png +0 -0
  420. package/assets/pet/whale/schemes/qwen/feat/neutral_mouth.png +0 -0
  421. package/assets/pet/whale/schemes/qwen/feat/sleep_eyeL.png +0 -0
  422. package/assets/pet/whale/schemes/qwen/feat/sleep_eyeR.png +0 -0
  423. package/assets/pet/whale/schemes/qwen/feat/sleep_mouth.png +0 -0
  424. package/assets/pet/whale/schemes/qwen/feat/surprised_eyeL.png +0 -0
  425. package/assets/pet/whale/schemes/qwen/feat/surprised_eyeR.png +0 -0
  426. package/assets/pet/whale/schemes/qwen/feat/surprised_mouth.png +0 -0
  427. package/assets/pet/whale/schemes/qwen/tex/ahoge.png +0 -0
  428. package/assets/pet/whale/schemes/qwen/tex/arm_far.png +0 -0
  429. package/assets/pet/whale/schemes/qwen/tex/arm_far_end_front.png +0 -0
  430. package/assets/pet/whale/schemes/qwen/tex/arm_near.png +0 -0
  431. package/assets/pet/whale/schemes/qwen/tex/bangs.png +0 -0
  432. package/assets/pet/whale/schemes/qwen/tex/bow.png +0 -0
  433. package/assets/pet/whale/schemes/qwen/tex/brows.png +0 -0
  434. package/assets/pet/whale/schemes/qwen/tex/crew_hair_back.png +0 -0
  435. package/assets/pet/whale/schemes/qwen/tex/crew_ponytail.png +0 -0
  436. package/assets/pet/whale/schemes/qwen/tex/crew_sidelocks.png +0 -0
  437. package/assets/pet/whale/schemes/qwen/tex/crew_skirt.png +0 -0
  438. package/assets/pet/whale/schemes/qwen/tex/crew_skirt_sit.png +0 -0
  439. package/assets/pet/whale/schemes/qwen/tex/eye_creases.png +0 -0
  440. package/assets/pet/whale/schemes/qwen/tex/face.png +0 -0
  441. package/assets/pet/whale/schemes/qwen/tex/fin_far.png +0 -0
  442. package/assets/pet/whale/schemes/qwen/tex/fin_near.png +0 -0
  443. package/assets/pet/whale/schemes/qwen/tex/hair_back.png +0 -0
  444. package/assets/pet/whale/schemes/qwen/tex/hair_back_curl.png +0 -0
  445. package/assets/pet/whale/schemes/qwen/tex/hair_front_left.png +0 -0
  446. package/assets/pet/whale/schemes/qwen/tex/hair_front_right.png +0 -0
  447. package/assets/pet/whale/schemes/qwen/tex/headdress.png +0 -0
  448. package/assets/pet/whale/schemes/qwen/tex/leg_back.png +0 -0
  449. package/assets/pet/whale/schemes/qwen/tex/leg_front.png +0 -0
  450. package/assets/pet/whale/schemes/qwen/tex/sidelocks.png +0 -0
  451. package/assets/pet/whale/schemes/qwen/tex/skirt.png +0 -0
  452. package/assets/pet/whale/schemes/qwen/tex/skirt_sit.png +0 -0
  453. package/assets/pet/whale/schemes/qwen/tex/tail.png +0 -0
  454. package/assets/pet/whale/schemes/qwen/tex/torso_up.png +0 -0
  455. package/assets/pet/whale/schemes/qwen/tex/waist_bow_front.png +0 -0
  456. package/assets/pet/whale/schemes/qwen/tex/waist_bow_sit_front.png +0 -0
  457. package/assets/pet/whale/tex/ahoge.png +0 -0
  458. package/assets/pet/whale/tex/arm_far.png +0 -0
  459. package/assets/pet/whale/tex/arm_far_end_front.png +0 -0
  460. package/assets/pet/whale/tex/arm_near.png +0 -0
  461. package/assets/pet/whale/tex/bangs.png +0 -0
  462. package/assets/pet/whale/tex/bow.png +0 -0
  463. package/assets/pet/whale/tex/brows.png +0 -0
  464. package/assets/pet/whale/tex/crew_hair_back.png +0 -0
  465. package/assets/pet/whale/tex/crew_ponytail.png +0 -0
  466. package/assets/pet/whale/tex/crew_sidelocks.png +0 -0
  467. package/assets/pet/whale/tex/crew_skirt.png +0 -0
  468. package/assets/pet/whale/tex/crew_skirt_sit.png +0 -0
  469. package/assets/pet/whale/tex/eye_creases.png +0 -0
  470. package/assets/pet/whale/tex/face.png +0 -0
  471. package/assets/pet/whale/tex/fin_far.png +0 -0
  472. package/assets/pet/whale/tex/fin_near.png +0 -0
  473. package/assets/pet/whale/tex/hair_back.png +0 -0
  474. package/assets/pet/whale/tex/hair_back_curl.png +0 -0
  475. package/assets/pet/whale/tex/hair_front_left.png +0 -0
  476. package/assets/pet/whale/tex/hair_front_right.png +0 -0
  477. package/assets/pet/whale/tex/headdress.png +0 -0
  478. package/assets/pet/whale/tex/leg_back.png +0 -0
  479. package/assets/pet/whale/tex/leg_front.png +0 -0
  480. package/assets/pet/whale/tex/sidelocks.png +0 -0
  481. package/assets/pet/whale/tex/skirt.png +0 -0
  482. package/assets/pet/whale/tex/skirt_shadow.png +0 -0
  483. package/assets/pet/whale/tex/skirt_sit.png +0 -0
  484. package/assets/pet/whale/tex/tail.png +0 -0
  485. package/assets/pet/whale/tex/torso_up.png +0 -0
  486. package/assets/pet/whale/tex/waist_bow_front.png +0 -0
  487. package/assets/pet/whale/tex/waist_bow_sit_front.png +0 -0
  488. package/assets/pet/whale/thumbs/cape.png +0 -0
  489. package/assets/pet/whale/thumbs/chatgpt.png +0 -0
  490. package/assets/pet/whale/thumbs/claude.png +0 -0
  491. package/assets/pet/whale/thumbs/crew.png +0 -0
  492. package/assets/pet/whale/thumbs/deepseek.png +0 -0
  493. package/assets/pet/whale/thumbs/gemini.png +0 -0
  494. package/assets/pet/whale/thumbs/harness.png +0 -0
  495. package/assets/pet/whale/thumbs/kimi.png +0 -0
  496. package/assets/pet/whale/thumbs/maid.png +0 -0
  497. package/assets/pet/whale/thumbs/minimax.png +0 -0
  498. package/assets/pet/whale/thumbs/qwen.png +0 -0
  499. package/assets/restart-dsh.cmd +16 -0
  500. package/assets/restart-dsh.log +195 -0
  501. package/client.js +1169 -0
  502. package/cordis.patch.yml +3 -0
  503. package/icon.svg +8 -0
  504. package/index.js +1273 -0
  505. package/locale/en.json +6 -0
  506. package/locale/zh.json +6 -0
  507. package/package.json +50 -4
@@ -0,0 +1,948 @@
1
+ /**
2
+ * The DeepSeek whale maid as a figure for the kit (web/kit/body.js): a sprite rig drawn with the kit's createRig (kit/rig.js).
3
+ *
4
+ * She stands the way Coo does, three-quarters on and facing right; the kit mirrors the whole
5
+ * group when she turns. The kit runs the body (walking, jumping, dragging, faces); this file turns
6
+ * each frame it hands over into rig parameters, runs springs for hair, skirt, tail, fins and ahoge,
7
+ * paints the face (eyes, mouth, blush) into a live texture, and draws the rig into a canvas that
8
+ * lives in the pet's own SVG group, so the stage's transform (position, squash, tilt, facing) applies.
9
+ *
10
+ * Every layer was cut from one master drawing, so at rest the parts line up pixel for pixel;
11
+ * what each part hides (the dress under the arm, the hair behind the face, the legs under the
12
+ * skirt) was painted in by edits of that same drawing.
13
+ *
14
+ * Rig space = the kit's logo space: x=128 under the body, soles at y=256.
15
+ * model.json keeps the master drawing's pixel frame for the face sprites; U/V convert.
16
+ */
17
+ const f1 = n => Math.round(n * 100) / 100;
18
+ const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
19
+ const lerp = (a, b, k) => a + (b - a) * k;
20
+ const ease = (rate, dt) => 1 - Math.exp(-rate * dt);
21
+ const bump = u => Math.sin(Math.PI * clamp(u, 0, 1));
22
+ const smooth = (a, b, x) => { const k = clamp((x - a) / (b - a), 0, 1); return k * k * (3 - 2 * k); };
23
+ const SVGNS = 'http://www.w3.org/2000/svg';
24
+
25
+ // the face texture covers this rect of the master drawing, one texel per master pixel
26
+ const FACE = { x: 520, y: 578, w: 390, h: 252 };
27
+ // the head's parallax warps act over this rect (rig units); the long hair below it stays put
28
+ const HEAD = [30, 12, 215, 168];
29
+
30
+ /**
31
+ * A leg's warp: from 14 units below the hip pivot down it turns about the pivot by `a` degrees as a rigid
32
+ * rotation would; above that the turn fades out over 20 units, so the top of the bloomer, which a rotation
33
+ * would swing out past the narrow top of the skirt at the waist, stays where it was drawn. `ty` lifts the leg
34
+ * the same way: all of it below the hinge, none of the bloomer's top, which would rise above the skirt.
35
+ */
36
+ function hinge([px, py], a, ty) {
37
+ const c = Math.cos(a * Math.PI / 180), s = Math.sin(a * Math.PI / 180);
38
+ return (u, v, x, y) => {
39
+ const w = smooth(py - 6, py + 14, y), lx = x - px, ly = y - py;
40
+ return [(lx * c - ly * s - lx) * w, ((lx * s + ly * c - ly) + ty) * w];
41
+ };
42
+ }
43
+
44
+ /* ---------- springs ---------- */
45
+ // `lim` bounds the output: a hard throw may overshoot, the hair must not fold over itself
46
+ /** Whether a spring was handed a target that is not a finite number yet: logged the first time only. */
47
+ let badTargetLogged = false;
48
+ function spring(k, c, lim = Infinity) {
49
+ return {
50
+ x: 0, v: 0,
51
+ step(target, dt) {
52
+ // a NaN target would stay in x for good, and the warps that read it (hair, tail, skirt) draw nothing
53
+ if (!Number.isFinite(target) || !Number.isFinite(dt)) {
54
+ if (!badTargetLogged) { badTargetLogged = true; console.warn(`[大肥鱼] 弹簧收到的目标不是有限数,这一帧不动:target=${target} dt=${dt}`); }
55
+ return this.x;
56
+ }
57
+ this.v += ((target - this.x) * k - this.v * c) * dt;
58
+ this.x += this.v * dt;
59
+ if (Math.abs(this.x) > lim) { this.x = Math.sign(this.x) * lim; this.v = 0; }
60
+ return this.x;
61
+ },
62
+ };
63
+ }
64
+
65
+ function loadImage(url) {
66
+ return new Promise((ok, bad) => { const im = new Image(); im.onload = () => ok(im); im.onerror = bad; im.src = url; });
67
+ }
68
+
69
+ /**
70
+ * Loads the model and textures; resolves to a figure object for the kit's `opts.figure` (createPet, createBody).
71
+ * `opts.raster` shows each frame as an SVG <image> copied from the canvas instead of the canvas itself (slower;
72
+ * for pages that are screen-recorded, where a WebGL canvas inside SVG is not always in the capture).
73
+ * `opts.scheme` picks a colour scheme (model.schemes) and an outfit (model.outfits) as `<scheme>-<outfit>`, the
74
+ * pack's two axes; a bare `<scheme>` is the first outfit, the maid dress. `opts.model` (model.json
75
+ * already parsed) and `opts.asset(path)` (a texture's URL) are for pages that bundle the files;
76
+ * `opts.loadImage` is the figure frame's (figure-frame.js), which loads images WebGL may read there.
77
+ * `opts.kit` is the frame's kit, whose `createRig` draws her; without it (a page that imports this file
78
+ * from the package) the package's own kit/rig.js does. A pack installed elsewhere has no ../kit/.
79
+ */
80
+ export async function createWhaleFigure(base = new URL('./', import.meta.url), opts = {}) {
81
+ const createRig = opts.kit?.createRig ?? (await import('../kit/rig.js')).createRig;
82
+ const model = opts.model || await (await fetch(new URL('model.json', base))).json();
83
+ const asset = opts.asset || (p => new URL(p, base));
84
+ const load = opts.loadImage || loadImage;
85
+ const { S, X0, FEET } = model.units;
86
+ const U = x => 128 + (x - X0) * S, V = y => 256 - (FEET - y) * S;
87
+ const feat = model.feat;
88
+ const EYES = ['eyeL', 'eyeR']; // near (left) eye, far (right) eye
89
+ const featNames = [...Object.keys(feat.sprites), ...EYES.flatMap(k => ['lash', 'ball', 'iris', ...(feat.eyes[k].rim ? ['rim'] : [])].map(n => `${k}_${n}`))];
90
+ // a scheme is a set of textures over the same geometry; the original's are at tex/ and feat/
91
+ const SCHEMES = (model.schemes || [{ id: 'deepseek' }]).filter(sc => sc.ready !== false);
92
+ const schemeInfo = id => SCHEMES.find(sc => sc.id === id) || SCHEMES[0];
93
+ // an outfit is its own part list: the maid dress is model.parts; another lists the parts it keeps from it and
94
+ // its own, whose `src` is the texture file (drawn in the outfit's colours, which no scheme changes); an own part
95
+ // without `src` has a texture in every scheme, beside the maid dress's
96
+ const OUTFITS = model.outfits || [{ id: 'maid' }];
97
+ const outfitInfo = id => OUTFITS.find(o => o.id === id) || OUTFITS[0];
98
+ const pickOf = id => { const [c, o] = String(id ?? '').split('-'); return { scheme: schemeInfo(c).id, outfit: outfitInfo(o).id }; };
99
+ const partsOf = id => outfitInfo(id).parts || model.parts;
100
+ // the scheme's accent colours the listening arcs, thought bubbles and sleep z's
101
+ const accent = () => schemeInfo(scheme).accent || '#4d6bfe';
102
+ const loaded = {}, ready = {};
103
+ function loadScheme(sc, of) {
104
+ const key = `${sc}-${of}`;
105
+ if (loaded[key]) return loaded[key];
106
+ const dir = sc === SCHEMES[0].id ? '' : `schemes/${sc}/`;
107
+ const set = { tex: {}, img: {} };
108
+ loaded[key] = Promise.all([
109
+ // an outfit's own part with a `src` is drawn in the outfit's colours
110
+ ...partsOf(of).map(async p => { set.tex[p.tex] = await load(asset(p.src || `${dir}tex/${p.tex}.png`)); }),
111
+ ...featNames.map(async n => { set.img[n] = await load(asset(`${dir}feat/${n}.png`)); }),
112
+ // a scheme with `eyeHighlights` has each eye's highlights as their own sprite and an iris without them
113
+ ...(schemeInfo(sc).eyeHighlights ? EYES.map(async k => { set.img[`${k}_hl`] = await load(asset(`${dir}feat/${k}_hl.png`)); }) : []),
114
+ ]).then(() => (ready[key] = set));
115
+ return loaded[key];
116
+ }
117
+ let { scheme, outfit } = pickOf(opts.scheme);
118
+ let { tex, img } = await loadScheme(scheme, outfit);
119
+
120
+ // each brow on the master: where its stroke ends, and the stretch of the brows texture it owns (x)
121
+ const BROWS = [
122
+ { outer: [610, 559.5], inner: [703, 548.7], x0: 596, x1: 765 }, // near
123
+ { outer: [890, 560.8], inner: [837, 555.6], x0: 765, x1: 904 }, // far
124
+ ];
125
+
126
+ /** The rig's deformers and parts for an outfit; its pivots and boxes override the maid dress's. */
127
+ function layoutOf(of) {
128
+ const list = partsOf(of);
129
+ const PV = { ...model.pivots, ...outfitInfo(of).pivots };
130
+ const box = Object.fromEntries([...model.parts, ...list].map(p => [p.id, p.box]));
131
+ const rectOf = id => { const [x, y, w, h] = box[id]; return [x, y, x + w, y + h]; };
132
+
133
+ /* deformers: each acts in rest space; parents act after children */
134
+ const deformers = {
135
+ body: { kind: 'rot', pivot: PV.body },
136
+ skirt: { kind: 'warp', parent: 'body', rect: rectOf('skirt') },
137
+ skirtSit: { kind: 'warp', parent: 'body', rect: rectOf('skirt_sit') },
138
+ // the upper body (bodice, arms, head) turns about the waist for a bow; the skirt and legs stay put
139
+ waist: { kind: 'rot', parent: 'body', pivot: PV.waist },
140
+ armNear: { kind: 'rot', parent: 'waist', pivot: PV.armNear },
141
+ armFar: { kind: 'rot', parent: 'waist', pivot: PV.armFar },
142
+ // the legs swing about the hip (see `hinge`), as warps so the bloomer above it stays under the skirt
143
+ legBack: { kind: 'warp', parent: 'body', rect: rectOf('leg_back') },
144
+ legFront: { kind: 'warp', parent: 'body', rect: rectOf('leg_front') },
145
+ tail: { kind: 'rot', parent: 'body', pivot: PV.tail },
146
+ tailBend: { kind: 'warp', parent: 'tail', rect: rectOf('tail') },
147
+ neck: { kind: 'rot', parent: 'waist', pivot: PV.neck },
148
+ headBack: { kind: 'warp', parent: 'neck', rect: HEAD },
149
+ headMid: { kind: 'warp', parent: 'neck', rect: HEAD },
150
+ headFeat: { kind: 'warp', parent: 'neck', rect: HEAD },
151
+ headFront: { kind: 'warp', parent: 'neck', rect: HEAD },
152
+ hairSway: { kind: 'warp', parent: 'headBack', rect: rectOf('hair_back') },
153
+ bangsSway: { kind: 'warp', parent: 'headFront', rect: rectOf('bangs') },
154
+ finNear: { kind: 'rot', parent: 'headMid', pivot: PV.finNear },
155
+ finFar: { kind: 'rot', parent: 'headBack', pivot: PV.finFar },
156
+ ahoge: { kind: 'rot', parent: 'headFront', pivot: PV.ahoge },
157
+ };
158
+ // an outfit's own pieces that hang and swing about a root (pompoms on the hood ties, scarf ends)
159
+ const swings = outfitInfo(of).deformers || {};
160
+ for (const [k, d] of Object.entries(swings)) deformers[k] = { kind: 'rot', parent: d.parent, pivot: d.pivot };
161
+ const parts = list.map(p => ({ ...p, parent: p.id === 'torso_up' ? 'waist' : p.parent }));
162
+ // the face features ride a little ahead of the face for the turn
163
+ parts.push({ id: 'faceFx', tex: 'faceFx', box: [U(FACE.x), V(FACE.y), FACE.w * S, FACE.h * S], z: 9, parent: 'headFeat', grid: [4, 4] });
164
+ // the brows lie on the skin under the fringe, and show through the hair: each is drawn again over the
165
+ // fringe, faint. As in a Live2D model each brow moves and turns as a whole about the middle of the line
166
+ // between its ends, and bends a little; the sorry faces swap in the same drawing turned over that line,
167
+ // so the arch becomes a dip with the stroke as drawn, crossfading.
168
+ const brows = parts.find(p => p.id === 'brows');
169
+ if (brows) {
170
+ parts.splice(parts.indexOf(brows), 1);
171
+ const [bx, by, bw, bh] = brows.box;
172
+ BROWS.forEach((b, i) => {
173
+ const x0 = Math.max(bx, U(b.x0)), x1 = Math.min(bx + bw, U(b.x1)), u0 = (x0 - bx) / bw, u1 = (x1 - bx) / bw;
174
+ const mid = [U((b.outer[0] + b.inner[0]) / 2), V((b.outer[1] + b.inner[1]) / 2)];
175
+ deformers[`brow${i}`] = { kind: 'rot', parent: 'headFeat', pivot: mid };
176
+ deformers[`browBend${i}`] = { kind: 'warp', parent: `brow${i}`, rect: [x0, by, x1, by + bh] };
177
+ deformers[`browOver${i}`] = { kind: 'rot', parent: `browBend${i}`, pivot: mid };
178
+ for (const [layer, z, alpha] of [['', brows.z, 1], ['_through', 13.2, .55]]) {
179
+ parts.push({ ...brows, id: `brow${i}${layer}`, box: [x0, by, x1 - x0, bh], uvBox: [u0, 0, u1, 1], parent: `browBend${i}`, z, alpha, grid: [12, 2] });
180
+ // mirrored about the middle's height (the texture upside down in the mirrored box); `browOver` turns it back onto the line
181
+ parts.push({ ...brows, id: `browOver${i}${layer}`, box: [x0, 2 * mid[1] - by - bh, x1 - x0, bh], uvBox: [u0, 1, u1, 0], parent: `browOver${i}`, z, alpha, grid: [12, 2] });
182
+ }
183
+ });
184
+ }
185
+ // the lid creases follow each eye's upper lid down when the eye narrows, and go when it closes
186
+ const creases = parts.find(p => p.id === 'eye_creases');
187
+ if (creases) {
188
+ deformers.creases = { kind: 'warp', parent: 'headFeat', rect: rectOf('eye_creases') };
189
+ creases.parent = 'creases';
190
+ }
191
+ // how far the arms fly out while she is held, as a share of the maid dress's (short sleeves look wrong flung wide)
192
+ const heldArms = outfitInfo(of).heldArms ?? 1;
193
+ // an outfit whose tail turns about its root inside the body (`tailRoot`) bends it from there to the tip (see `tailBend`)
194
+ const tailRoot = outfitInfo(of).tailRoot ? { x: PV.tail[0], tip: rectOf('tail')[0] } : null;
195
+ return { PV, deformers, parts, brows, creases, swings, heldArms, tailRoot };
196
+ }
197
+ let L = layoutOf(outfit);
198
+
199
+ /* ---------- face painting (master pixels) ---------- */
200
+ const faceCv = document.createElement('canvas');
201
+ faceCv.width = FACE.w; faceCv.height = FACE.h;
202
+ // while a scheme fades in, the face is painted a second time with the incoming scheme's sprites
203
+ const faceCv2 = document.createElement('canvas');
204
+ faceCv2.width = FACE.w; faceCv2.height = FACE.h;
205
+ const fg1 = faceCv.getContext('2d'), fg2 = faceCv2.getContext('2d');
206
+ let fg = fg1;
207
+ const eyeCv = document.createElement('canvas');
208
+ const INK = '#5a2330';
209
+ const poly2 = (c, x) => c[0] * x * x + c[1] * x + c[2];
210
+
211
+ // how far the lid travels to close: from the lid line down past the lower rim
212
+ const EYE = Object.fromEntries(EYES.map(k => {
213
+ const e = feat.eyes[k], [x0, , x1] = e.ball;
214
+ let h = 0;
215
+ for (let x = x0 + 4; x < x1 - 4; x += 2) h = Math.max(h, poly2(e.rimFit, x) - poly2(e.lidFit, x));
216
+ const cx = (e.iris[0] + e.iris[2]) / 2;
217
+ return [k, { ...e, travel: h + 2, cx, cy: poly2(e.lidFit, cx) }];
218
+ }));
219
+
220
+ // the eye highlights' state this frame (master pixels), stepped once per frame in draw()
221
+ const hl = { dx: 0, dy: 0, scale: 1, quiver: 0, alpha: 1 };
222
+ // how each face changes the highlights: welling eyes quiver and shine bigger, a glare narrows them, drowsy eyes dull
223
+ const HL_MOOD = {
224
+ sad: { scale: 1.12, quiver: 1 }, worried: { scale: 1.1, quiver: .8 }, shy: { scale: 1.1, quiver: .6 }, pout: { scale: 1.06, quiver: .4 },
225
+ excited: { scale: 1.18 }, listening: { scale: 1.06 }, angry: { scale: .78 }, determined: { scale: .86 },
226
+ sleepy: { scale: .92, alpha: .7 }, content: { alpha: .8 }, waking: { alpha: .75 },
227
+ };
228
+
229
+ /**
230
+ * The neutral eye with its lid at `open` (0 shut, 1 rest), iris moved by ix/iy, lid tilted by tilt (rad), its
231
+ * highlights as `hl` (the state above) has them; `glint` (0..1) adds star highlights on the iris, which twinkle
232
+ * with `t`, as the highlights quiver with it.
233
+ */
234
+ function paintOpenEye(k, open, ix, iy, tilt, glint, hl, t) {
235
+ const e = EYE[k], [bx0, by0, bx1, by1] = e.ball, w = bx1 - bx0, h = by1 - by0;
236
+ if (eyeCv.width !== w + 40 || eyeCv.height !== h + 40) { eyeCv.width = w + 40; eyeCv.height = h + 40; }
237
+ const g = eyeCv.getContext('2d');
238
+ g.setTransform(1, 0, 0, 1, 20 - bx0, 20 - by0);
239
+ g.clearRect(bx0 - 20, by0 - 20, w + 40, h + 40);
240
+ g.globalCompositeOperation = 'source-over';
241
+ g.drawImage(img[`${k}_ball`], bx0, by0);
242
+ g.globalCompositeOperation = 'source-atop';
243
+ g.drawImage(img[`${k}_iris`], e.iris[0] + ix, e.iris[1] + iy);
244
+ const d = (1 - clamp(open, 0, 1)) * e.travel, tn = Math.tan(tilt);
245
+ const hlImg = img[`${k}_hl`];
246
+ if (hlImg && e.hl) {
247
+ // the highlights ride on the iris, trail it on their spring, are pushed down by a closing lid as far as the
248
+ // iris's middle (so a half-shut eye still shines) and take the face's size, quiver and strength; the far
249
+ // eye's x is foreshortened
250
+ const gx = k === 'eyeL' ? 1 : .35, ph = k === 'eyeL' ? 0 : 1.7, q = hl.quiver;
251
+ const w = hlImg.width * hl.scale, h = hlImg.height * hl.scale;
252
+ const cx = (e.hl[0] + e.hl[2]) / 2 + ix + (hl.dx + q * .8 * Math.sin(t * 29 + ph)) * gx;
253
+ let cy = (e.hl[1] + e.hl[3]) / 2 + iy + hl.dy + q * .6 * Math.sin(t * 37 + ph);
254
+ const lid = poly2(e.lidFit, clamp(cx, bx0, bx1)) + d + tn * (cx - e.cx) + 2;
255
+ if (cy - h / 2 < lid) cy = Math.max(cy, Math.min(lid + h / 2, (e.iris[1] + e.iris[3]) / 2 + iy));
256
+ g.globalAlpha = hl.alpha;
257
+ g.drawImage(hlImg, cx - w / 2, cy - h / 2, w, h);
258
+ g.globalAlpha = 1;
259
+ }
260
+ // the eye's outline over the iris, so a shifted iris tucks under it
261
+ if (e.rim) { g.globalCompositeOperation = 'source-over'; g.drawImage(img[`${k}_rim`], e.rim[0], e.rim[1]); }
262
+ if (glint > 0) {
263
+ // white four-point stars on the iris, the far eye's foreshortened; painted inside the eye, so the lid and lashes cover them
264
+ g.globalCompositeOperation = 'source-atop';
265
+ const sc = k === 'eyeL' ? 1 : .6, ic = [(e.iris[0] + e.iris[2]) / 2 + ix, (e.iris[1] + e.iris[3]) / 2 + iy];
266
+ [[-.16, -.2, 24], [.2, .2, 13]].forEach(([fx, fy, r], j) => {
267
+ const R = r * glint * (.8 + .3 * Math.sin(t * 7 + j * 2 + (k === 'eyeL' ? 0 : 1))), w = R * .28;
268
+ const cx = ic[0] + fx * (e.iris[2] - e.iris[0]), cy = ic[1] + fy * (e.iris[3] - e.iris[1]);
269
+ g.save(); g.translate(cx, cy); g.scale(sc, 1);
270
+ g.fillStyle = 'rgba(255,255,255,.95)';
271
+ g.beginPath(); g.moveTo(0, -R); g.quadraticCurveTo(w, -w, R, 0); g.quadraticCurveTo(w, w, 0, R); g.quadraticCurveTo(-w, w, -R, 0); g.quadraticCurveTo(-w, -w, 0, -R); g.fill();
272
+ g.restore();
273
+ });
274
+ }
275
+ // the lid hides everything above it
276
+ g.globalCompositeOperation = 'destination-out';
277
+ g.beginPath();
278
+ g.moveTo(bx0 - 20, by0 - 20);
279
+ for (let x = bx0 - 20; x <= bx1 + 20; x += 3) g.lineTo(x, poly2(e.lidFit, clamp(x, bx0, bx1)) + d + tn * (x - e.cx) - 1);
280
+ g.lineTo(bx1 + 20, by0 - 20);
281
+ g.closePath(); g.fill();
282
+ g.globalCompositeOperation = 'source-over';
283
+ fg.drawImage(eyeCv, bx0 - 20 - FACE.x, by0 - 20 - FACE.y);
284
+ // the lashes ride down with the lid and flatten as they close
285
+ const L = e.lash, sy = .55 + .45 * clamp(open, 0, 1);
286
+ fg.save();
287
+ fg.translate(e.cx - FACE.x, e.cy + d - FACE.y);
288
+ fg.rotate(tilt);
289
+ fg.scale(1, sy);
290
+ fg.drawImage(img[`${k}_lash`], L[0] - e.cx, L[1] - e.cy);
291
+ fg.restore();
292
+ }
293
+
294
+ // Each mouth sprite sits where its expression edit drew it, and three of those edits drew the mouth
295
+ // higher than the master's: these move them down (master pixels) so the middle of each visible mouth
296
+ // is on the master's mouth line, y 769, as the neutral, love, dizzy and surprised mouths already are.
297
+ const MOUTH_DY = { happy_mouth: 9, drag_mouth: 16, sleep_mouth: 4 };
298
+
299
+ /** A whole drawn sprite (an expression's eye or mouth) at its place, optionally scaled/rotated about its centre. */
300
+ function sprite(name, o = {}) {
301
+ const b = feat.sprites[name];
302
+ if (!b) return;
303
+ const cx = (b[0] + b[2]) / 2, cy = (b[1] + b[3]) / 2;
304
+ fg.save();
305
+ fg.globalAlpha = o.alpha ?? 1;
306
+ fg.translate(cx - FACE.x, cy + (MOUTH_DY[name] || 0) - FACE.y);
307
+ if (o.rot) fg.rotate(o.rot);
308
+ fg.scale(o.sx ?? o.s ?? 1, o.sy ?? o.s ?? 1);
309
+ fg.drawImage(img[name], b[0] - cx, b[1] - cy);
310
+ fg.restore();
311
+ }
312
+
313
+ const CHEEKS = [[618, 770, 40, 20], [852, 762, 22, 15]];
314
+ function paintBlush(a) {
315
+ for (const [x, y, rx, ry] of CHEEKS) {
316
+ fg.save();
317
+ fg.translate(x - FACE.x, y - FACE.y); fg.scale(1, ry / rx);
318
+ const gr = fg.createRadialGradient(0, 0, 0, 0, 0, rx);
319
+ gr.addColorStop(0, `rgba(255,120,140,${f1(.55 * a)})`); gr.addColorStop(1, 'rgba(255,120,140,0)');
320
+ fg.fillStyle = gr; fg.beginPath(); fg.arc(0, 0, rx, 0, Math.PI * 2); fg.fill();
321
+ fg.restore();
322
+ }
323
+ }
324
+
325
+ /** Small drawn mouths for the moods the sprites don't cover (form < 0 frowns). */
326
+ function lineMouth(form, w = 1) {
327
+ const cx = 766 - FACE.x, cy = 772 - FACE.y;
328
+ fg.save(); fg.strokeStyle = INK; fg.lineWidth = 3; fg.lineCap = 'round';
329
+ fg.beginPath(); fg.moveTo(cx - 9 * w, cy - form * 3); fg.quadraticCurveTo(cx, cy + form * 5, cx + 9 * w, cy - form * 3); fg.stroke();
330
+ fg.restore();
331
+ }
332
+
333
+ const MOUTH = {
334
+ neutral: 'neutral_mouth', happy: 'happy_mouth', wink: ['happy_mouth', .8], love: 'love_mouth', shy: ['drag_mouth', .7],
335
+ surprised: 'surprised_mouth', sleepy: 'sleep_mouth', sleep: 'sleep_mouth', dizzy: 'dizzy_mouth', dragged: 'drag_mouth',
336
+ content: 'neutral_mouth', waking: ['surprised_mouth', .6], squeeze: 'sleep_mouth', listening: 'neutral_mouth',
337
+ thinking: 'sleep_mouth', run: ['happy_mouth', .7], angry: -1, sad: -1.2,
338
+ smug: .7, pout: ['surprised_mouth', .45], worried: ['drag_mouth', .6], determined: .15, flustered: ['drag_mouth', .8],
339
+ scared: ['drag_mouth', .8], excited: 'happy_mouth', cry: ['surprised_mouth', .8], confused: -.35,
340
+ };
341
+
342
+ // where the face's outline is under each eye's tear (master y), with room for the stream's rounded end
343
+ const TEAR_END = { eyeL: 816, eyeR: 786 };
344
+ /** Tears running from each eye's lower lid down the cheek (master pixels), wavering with `t`. */
345
+ function paintStreams(t) {
346
+ fg.save();
347
+ EYES.forEach((k, i) => {
348
+ const e = EYE[k], [bx0, , bx1, by1] = e.ball, w = (bx1 - bx0) * (k === 'eyeL' ? .22 : .2);
349
+ // from just under the shut lid, narrow where it wells up and widening as it runs down
350
+ // (painted before the eyes, so the shut lid's lashes lie over its top; it stops above the jaw under each eye)
351
+ const x = bx0 + (bx1 - bx0) * (k === 'eyeL' ? .55 : .5) - FACE.x, y0 = by1 - 6 - FACE.y;
352
+ const y1 = Math.min(FACE.h - 4, TEAR_END[k] - FACE.y, y0 + 110), wob = 4 * Math.sin(t * 6 + i);
353
+ const gr = fg.createLinearGradient(0, y0, 0, y1);
354
+ gr.addColorStop(0, 'rgba(120,195,255,.95)'); gr.addColorStop(1, 'rgba(120,195,255,.3)');
355
+ fg.fillStyle = gr;
356
+ fg.beginPath();
357
+ fg.moveTo(x - w * .15, y0);
358
+ fg.bezierCurveTo(x - w * .5 + wob, y0 + 25, x - w * .55 + wob, y1 - 20, x - w * .4, y1);
359
+ fg.quadraticCurveTo(x, y1 + 6, x + w * .4, y1);
360
+ fg.bezierCurveTo(x + w * .55 + wob, y1 - 20, x + w * .5 + wob, y0 + 25, x + w * .15, y0);
361
+ fg.closePath(); fg.fill();
362
+ });
363
+ fg.restore();
364
+ }
365
+
366
+ /**
367
+ * The face for this frame as a list of paint calls, `[what, ...arguments]` (PAINT): the same list paints the same
368
+ * face, so the texture is painted and uploaded again only when the list changes. Everything the face shows is in
369
+ * the arguments, the clock only where it moves something.
370
+ */
371
+ function faceOps(fc, face, o, t) {
372
+ const ops = [];
373
+ if ((fc.blush || 0) >= .02) ops.push(['blush', fc.blush]);
374
+ if (fc.streams) ops.push(['streams', t]);
375
+ const shut = Math.max(o.blink || 0, o.eyeClose || 0);
376
+ const lx = clamp(o.look[0], -6, 6), ly = clamp(o.look[1], -5, 5);
377
+ const tilt = fc.brows === 'angry' ? .2 : fc.brows === 'sad' ? -.16 : 0;
378
+ // a quiver that has died down to under a hundredth of a pixel is still
379
+ const h = { ...hl, quiver: hl.quiver < .01 ? 0 : hl.quiver };
380
+ fc.eyes.forEach((e, i) => {
381
+ const k = EYES[i], side = k === 'eyeL' ? 1 : -1; // the near eye's inner corner is to its right
382
+ const squash = { sy: 1 - .85 * (o.eyeClose || 0) };
383
+ if ((face === 'surprised' || fc.wide) && e.shape === 'ring') { ops.push(['sprite', `surprised_${k}`, squash]); return; }
384
+ switch (e.shape) {
385
+ case 'ring': case 'lid': {
386
+ const open = (e.shape === 'ring' ? clamp(e.ry / e.rx, 0, 1) * (tilt ? .8 : 1) : clamp(e.ry / 16, 0, 1)) * (1 - shut);
387
+ // the iris fills most of the eye: it only shifts a little, less in the foreshortened far eye,
388
+ // so the white never shows past the eye's outline
389
+ const gx = k === 'eyeL' ? 1 : .35;
390
+ const ix = clamp((lx + (e.dx || 0)) * gx, -6 * gx, 6 * gx), iy = clamp(ly * .7 + (e.dy || 0) * .7, -3.5, 3.5);
391
+ const glint = fc.sparkle ? 1 : 0;
392
+ ops.push(['eye', k, open, ix, iy + (e.shape === 'lid' ? 3 : 0), tilt * side, glint, h, glint || h.quiver ? t : 0]);
393
+ break;
394
+ }
395
+ case 'up': ops.push(['sprite', `happy_${k}`, squash]); break;
396
+ case 'down': ops.push(['sprite', `sleep_${k}`, squash]); break;
397
+ case 'gt': case 'lt': ops.push(['sprite', `drag_${k}`, { s: 1 + .03 * Math.sin(t * 22 + i) }]); break;
398
+ case 'heart': ops.push(['sprite', `love_${k}`, { s: .94 + .06 * (e.s ?? 1) / .8 }]); break;
399
+ case 'spiral': ops.push(['sprite', `dizzy_${k}`, { rot: (e.rot || 0) * .6 }]); break;
400
+ }
401
+ });
402
+ // mouth: talking opens the happy mouth about its middle, which stays on the mouth line; otherwise the face's own
403
+ const talk = o.talk || 0;
404
+ const gapOpen = clamp((Math.max(fc.gap[0], fc.gap[1]) - 50) / 14, 0, 1);
405
+ const m = MOUTH[face] ?? 'neutral_mouth';
406
+ const open = Math.max(talk * (.45 + .45 * Math.abs(Math.sin(t * 17))), face === 'sleepy' || face === 'waking' ? gapOpen : 0);
407
+ if (open > .12) ops.push(['sprite', face === 'surprised' ? 'surprised_mouth' : 'happy_mouth', { sy: .35 + .65 * open, sx: .85 + .15 * open }]);
408
+ else if (typeof m === 'number') ops.push(['line', m]);
409
+ else if (Array.isArray(m)) ops.push(['sprite', m[0], { s: m[1] }]);
410
+ else ops.push(['sprite', m]);
411
+ return ops;
412
+ }
413
+ const PAINT = { blush: paintBlush, streams: paintStreams, eye: paintOpenEye, sprite, line: lineMouth };
414
+ /** A paint list as text, its numbers to the hundredth: lists that paint the same face read the same. */
415
+ const opsKey = (ops) => JSON.stringify(ops, (k, v) => (typeof v === 'number' ? f1(v) : v));
416
+ function paintFace(ops) {
417
+ fg.setTransform(1, 0, 0, 1, 0, 0);
418
+ fg.clearRect(0, 0, FACE.w, FACE.h);
419
+ for (const [what, ...args] of ops) PAINT[what](...args);
420
+ }
421
+
422
+ /* ---------- mounting inside the pet's SVG group ---------- */
423
+ const VIEW = model.view;
424
+ let fo = null, canvas = null, fxG = null, rig = null, mountedIn = null, pxScale = 0, frameN = 0;
425
+ function mount(petG) {
426
+ petG.textContent = '';
427
+ // the previous rig's GL context outlives its canvas until GC: release it or repeated
428
+ // figure switches pile up live contexts (Chromium caps them per page)
429
+ rig?.dispose();
430
+ rig = null;
431
+ const box = (el) => { el.setAttribute('x', VIEW[0]); el.setAttribute('y', VIEW[1]); el.setAttribute('width', VIEW[2] - VIEW[0]); el.setAttribute('height', VIEW[3] - VIEW[1]); return el; };
432
+ canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
433
+ if (opts.raster) {
434
+ // each frame is copied into a plain SVG image: screenshots and recordings then always see it
435
+ fo = box(document.createElementNS(SVGNS, 'image'));
436
+ // raster conversion (canvas.toDataURL) costs real CPU every frame; callers that only need it
437
+ // for cloning can switch it off while no clones exist (`rasterLive = false`)
438
+ rasterLive = true;
439
+ } else {
440
+ fo = box(document.createElementNS(SVGNS, 'foreignObject'));
441
+ canvas.style.cssText = 'width:100%;height:100%;display:block';
442
+ fo.appendChild(canvas);
443
+ }
444
+ fxG = document.createElementNS(SVGNS, 'g');
445
+ petG.append(fo, fxG);
446
+ rig = createRig(canvas, { deformers: L.deformers, parts: L.parts, view: VIEW });
447
+ for (const n in tex) rig.upload(n, tex[n]);
448
+ if (fade) for (const n in fade.set.tex) rig.upload(n + '@mix', fade.set.tex[n]);
449
+ mountedIn = petG; pxScale = 0;
450
+ }
451
+ // a fade in progress: the rig crossfades every part from `tex` to fade.set's textures over fade.dur seconds
452
+ let fade = null;
453
+ function endFade() {
454
+ if (!fade) return;
455
+ tex = fade.set.tex; img = fade.set.img; fade = null;
456
+ if (rig) for (const n in tex) rig.upload(n, tex[n]);
457
+ }
458
+ /**
459
+ * Switches the colour scheme and outfit (`<scheme>-<outfit>`, as opts.scheme): at once if their textures are
460
+ * loaded (see preload), else once they are. Within one outfit `o.fade` (seconds) crossfades instead of cutting
461
+ * over, the clock being the frames' `t` from `o.at` (the pet's time now) or else from the next frame drawn;
462
+ * another outfit is another set of parts, so the rig is built again and the change is a cut.
463
+ */
464
+ function setScheme(id, o = {}) {
465
+ const next = pickOf(id), key = `${next.scheme}-${next.outfit}`;
466
+ const apply = set => {
467
+ endFade();
468
+ if (scheme === next.scheme && outfit === next.outfit && tex === set.tex) return;
469
+ scheme = next.scheme;
470
+ if (outfit !== next.outfit) {
471
+ outfit = next.outfit; L = layoutOf(outfit);
472
+ tex = set.tex; img = set.img;
473
+ rig?.dispose(); rig = null; mountedIn = null;
474
+ return;
475
+ }
476
+ if (o.fade > 0 && rig) {
477
+ fade = { set, dur: o.fade, t0: o.at ?? null };
478
+ for (const n in set.tex) rig.upload(n + '@mix', set.tex[n]);
479
+ return;
480
+ }
481
+ tex = set.tex; img = set.img;
482
+ if (rig) for (const n in tex) rig.upload(n, tex[n]);
483
+ };
484
+ if (ready[key]) { apply(ready[key]); return Promise.resolve(); }
485
+ return loadScheme(next.scheme, next.outfit).then(apply);
486
+ }
487
+ let decoded = null; // raster mode: settles once the last frame's image is decoded
488
+ let rasterLive = !!opts.raster; // raster conversion actually runs (callers may pause it to save CPU)
489
+ let rasterMinGap = opts.rasterFps ? 1 / Math.max(1, opts.rasterFps) : 0; // seconds between raster conversions; 0 = every drawn frame
490
+ let rasterAt = -Infinity; // clock time of the last conversion
491
+ let fixedRes = 0; // canvas pixels per rig unit for a snapshot; 0 = follow the screen
492
+ function fitCanvas() {
493
+ const m = fixedRes ? null : mountedIn.getScreenCTM();
494
+ if (!m && !fixedRes) return;
495
+ // the vertical axis: turning round squeezes the horizontal one through zero, which would shrink the canvas to a few texels
496
+ const k = fixedRes || Math.hypot(m.c, m.d) * (window.devicePixelRatio || 1) * 1.25;
497
+ if (Math.abs(k - pxScale) / (pxScale || 1) < .08) return;
498
+ pxScale = k;
499
+ canvas.width = Math.max(16, Math.round((VIEW[2] - VIEW[0]) * Math.min(k, 6)));
500
+ canvas.height = Math.max(16, Math.round((VIEW[3] - VIEW[1]) * Math.min(k, 6)));
501
+ }
502
+
503
+ /* ---------- per-frame state ---------- */
504
+ const sp = {
505
+ hair: spring(55, 7, 1.8), hairY: spring(50, 8, 1.2), bangs: spring(110, 10, 1.6),
506
+ skirt: spring(100, 9, 1.6), skirtY: spring(90, 10, 1.1), tail: spring(40, 5, 32), fins: spring(90, 9, 30),
507
+ ahoge: spring(140, 6, 38), head: spring(70, 10, 16), armN: spring(60, 9, 125), armF: spring(60, 9, 95),
508
+ hlX: spring(160, 9, 3), hlY: spring(160, 9, 3),
509
+ };
510
+ let lastT = null, prevTilt = 0, prevYaw = 0, prevLow = 0, headTilt = 0, fx = '';
511
+ let prevLook = null, prevShut = 0;
512
+ /** The face texture as last painted: its paint list (opsKey), from which sprites (`img`), into which rig. */
513
+ let painted = { key: '', img: null, rig: null };
514
+ // the angle each hanging piece's root was last turned to (see the pendulums)
515
+ let rootWas = {};
516
+ // the kit tips Coo's whole round body to listen, nod, doze or wobble; she keeps her feet on the floor and
517
+ // moves her head instead. Only flight, dragging and the jump's crouch and landing tip the whole group,
518
+ // running keeps half its lean. The shares ease between modes so the group never snaps.
519
+ // dancing sways her mostly as a whole, the rest of the sway goes to the neck
520
+ const GROUP = { air: [1, 1], drag: [1, 1], crouch: [1, 1], land: [1, 1], walk: [1, .5], run: [1, .5], dance: [.6, 0] };
521
+ // the ninja run leans her whole body forward from the soles, in a straight line: bent at the waist instead,
522
+ // the bodice comes away from the skirt and its bow and the tops of the legs show at the waist
523
+ let wTilt = 0, wLean = 0, facing = 1;
524
+ let finMood = 0, tailMood = 0, wagAmp = 0, sitK = 0, walkK = 0, runK = 0, swingK = 0;
525
+ const groupTilt = (mode, tilt, lean) => tilt * wTilt + lean * wLean + runK * 14 * facing;
526
+ const st = { z: {}, alpha: {} };
527
+
528
+ // fins and tail by face: fins up (+) or drooping (-), tail wag size
529
+ const MOOD = {
530
+ happy: [.8, 1], love: [.9, 1], wink: [.5, .7], surprised: [1, .2], angry: [.9, .15], sad: [-1, 0], shy: [-.5, .3],
531
+ sleepy: [-.7, 0], sleep: [-.9, 0], dizzy: [-.3, 0], dragged: [.6, .6], content: [-.2, .25], listening: [.6, .2],
532
+ thinking: [.1, .15], run: [.2, .4], waking: [-.4, 0], squeeze: [-.3, 0], neutral: [0, .25],
533
+ smug: [.5, .6], pout: [.3, 0], worried: [-.3, .1], determined: [.9, .3], flustered: [.4, .8], scared: [-1, 0],
534
+ excited: [1, 1], cry: [-1, 0], confused: [.2, .1], bowing: [-.2, .2],
535
+ };
536
+ // brows by face, per brow [near, far], in master pixels: [Y lift of the whole brow, A how much higher its
537
+ // inner end (by the nose) sits than its outer end (a negative A is the frown), F how much more its middle
538
+ // arches over its ends, X its shift toward the nose]. Sized from the master redrawn with each expression;
539
+ // the far brow is shorter, and `both` gives it the same angle and curve.
540
+ const both = (y, a = 0, f = 0, x = 0) => [[y, a, f, x], [y, a * .6, f * .6, x * .6]];
541
+ const BROW = {
542
+ surprised: both(32, 4, 12), excited: both(20, 2, 9),
543
+ happy: both(9, 0, 6), love: both(9, 4, 6), listening: both(9, 0, 4), waking: both(6, 6),
544
+ wink: [[9, 0, 6, 0], [-5, 0, 3, 0]],
545
+ angry: both(-14, -44, -6, 8), determined: both(-6, -28, -3, 5), pout: both(-6, -22, -6, 5), run: both(2, -12, -3),
546
+ squeeze: both(-12, -14, -8, 6), shy: both(0, 16, -4, 4),
547
+ sad: both(-10, 30, -2, 6), cry: both(-10, 38, -4, 8), worried: both(-6, 24, 0, 5), scared: both(6, 26, 0, 5),
548
+ flustered: both(2, 22, 0, 4), dragged: both(-4, 24, 0, 6),
549
+ sleepy: both(-10, 2, -4), sleep: both(-10, 4, -2), content: both(-3, 0, 3), bowing: both(-3, 3),
550
+ dizzy: [[12, 14, 0, 0], [-6, -10, 0, 0]],
551
+ thinking: [[-6, -14, -4, 4], [14, 4, 6, 0]],
552
+ smug: [[-8, -18, 0, 0], [14, -6, 4, 0]],
553
+ confused: [[-10, -12, -4, 3], [22, 6, 8, 0]],
554
+ };
555
+ // faces whose brows are turned over, the arch a dip: the inner ends hook up out of it, pulled in
556
+ const BROW_OVER = new Set(['sad', 'cry', 'worried', 'scared', 'flustered', 'dragged']);
557
+ // how fast each face's brows get there (per second): a startle snaps them, sorrow sinks them slowly
558
+ const BROW_RATE = { surprised: 18, scared: 18, excited: 14, angry: 16, dragged: 16, squeeze: 16, sad: 4, cry: 4, worried: 6, sleepy: 3, sleep: 3, content: 4 };
559
+ // faces whose brows hold still during talk
560
+ const BROW_STILL = new Set(['angry', 'sad', 'cry', 'sleepy', 'sleep', 'squeeze', 'dizzy']);
561
+ // the head by face: tilt (degrees, forward +) and pitch (angleY, down +)
562
+ const HEAD_TILT = { shy: 7, thinking: -8, smug: -6, pout: -4, confused: -7, worried: 3, cry: 4 };
563
+ const HEAD_PITCH = { sad: .35, cry: .45, worried: .15 };
564
+ const BROW_SPLIT = U(765); // the near brow is left of this, the far brow right of it
565
+ const browNow = [[0, 0, 0, 0], [0, 0, 0, 0]];
566
+ let browOver = 0; // 0 the brows as drawn, 1 turned over
567
+ // a quick raise of both brows now and then during talk: when the last one started, and when talk was last seen
568
+ let browFlashAt = -Infinity, talkedAt = -Infinity;
569
+ // how far an eye's upper lid sits below its rest line (master pixels), and whether it is an open eye at all
570
+ // (the same openness paintFace gives the eye, over the lid's full travel; the crease keeps a little above the lid)
571
+ const lidDrop = (e, k, tilt) => {
572
+ const open = e.shape === 'ring' ? clamp((e.ry ?? 16) / (e.rx ?? 16), 0, 1) * (tilt ? .8 : 1) : e.shape === 'lid' ? clamp(e.ry / 16, 0, 1) : 1;
573
+ return EYE[k].travel * (1 - open) * .75;
574
+ };
575
+ const lidOpen = e => e.shape === 'ring' || e.shape === 'lid' ? 1 : 0;
576
+ const creaseDrop = [0, 0];
577
+ let creaseA = 1;
578
+
579
+ function draw(petG, fc, o) {
580
+ if (mountedIn !== petG || !petG.contains(fo)) mount(petG);
581
+ if (frameN++ % 20 === 0) fitCanvas();
582
+ const t = o.t, dt = lastT == null ? 1 / 60 : clamp(t - lastT, 0, .05);
583
+ lastT = t;
584
+ const mode = o.mode || 'idle', face = o.face || 'neutral';
585
+ facing = Math.sign(o.facing || 1);
586
+ const walking = mode === 'walk' || mode === 'run', held = mode === 'drag', airborne = mode === 'air';
587
+
588
+ /* body: the kit's `low` is how far the hips sink (sitting, the walk's bob), in these units */
589
+ sitK = lerp(sitK, clamp(o.sit ?? 0, 0, 1), ease(12, dt));
590
+ const low = o.low || 0;
591
+ const lowV = (low - prevLow) / Math.max(dt, 1e-3); prevLow = low;
592
+ const breath = Math.sin(t * (mode === 'sleep' ? 1.7 : 2.4));
593
+
594
+ /* head: tilt toward what it looks at, nod with sleep, wobble with dizzy */
595
+ let tiltT = o.look[0] * .7 + Math.sin(t * .9) * 1.2 + o.look[1] * .4;
596
+ if (mode === 'sleep') tiltT += 6;
597
+ tiltT += HEAD_TILT[face] || 0;
598
+ if (face === 'dizzy') tiltT += 3 * Math.sin(t * 4.5);
599
+ if (held) tiltT += o.swing * .25;
600
+ headTilt = sp.head.step(tiltT, dt);
601
+ // what the kit meant for the whole body and the group did not take goes to the neck (forward +)
602
+ const [gT, gL] = GROUP[mode] || [0, 0];
603
+ const bend = (o.tilt ?? 0) * (1 - wTilt) + (o.lean ?? 0) * Math.sign(o.facing || 1) * (1 - wLean);
604
+ wTilt = lerp(wTilt, gT, ease(10, dt)); wLean = lerp(wLean, gL, ease(10, dt));
605
+ // the kit's short gestures, as she does them. Nod, shake, wave and bow are hers alone (see `gestures`):
606
+ // a nod pitches the face down twice (angleY +) and dips the head forward, a shake turns the face from side
607
+ // to side (angleX) under a slight roll; both die away by the end. The rest add to what the kit does.
608
+ const g = o.gesture, gk = g ? g.k : 0;
609
+ const env = (a, b) => smooth(0, a, gk) * (1 - smooth(b, 1, gk));
610
+ const nod = g?.kind === 'nod' ? Math.sin(gk * Math.PI * 2) ** 2 * (1 - .3 * gk) : 0;
611
+ const shake = g?.kind === 'shake' ? Math.sin(gk * Math.PI * 6) * smooth(0, .12, gk) * (1 - gk) : 0;
612
+ const wave = g?.kind === 'wave' ? env(.15, .8) : 0; // the near arm up beside her head, waving
613
+ const bow = g?.kind === 'bow' ? env(.25, .7) : 0; // the upper body tips forward about the waist
614
+ const shiver = g?.kind === 'shiver' ? env(.08, .85) : 0; // arms hugged in, trembling, fins down
615
+ const flap = g?.kind === 'flap' ? env(.05, .75) : 0; // fins, tail, ahoge and arms all flutter
616
+ const gNeck = nod * 7 + shake * 2.5 + bow * 10 + wave * 4, gYaw = shake * 1.1;
617
+ const headA = headTilt + gNeck;
618
+ const tiltVel = (headA - prevTilt) / Math.max(dt, 1e-3); prevTilt = headA;
619
+ const yawVel = (gYaw - prevYaw) / Math.max(dt, 1e-3); prevYaw = gYaw;
620
+ const angleX = clamp(clamp(o.look[0] / 5, -1, 1) * .9 + gYaw, -1.4, 1.4);
621
+ // angleY + pitches the face down (the features slide down, more crown shows), as a gaze down (look[1] +) does
622
+ const angleY = clamp(clamp(o.look[1] / 4, -1, 1) * .7 + (mode === 'sleep' ? .8 : 0) + (HEAD_PITCH[face] || 0) + nod * .9 + bow * .5, -1.4, 1.4);
623
+
624
+ /* springs */
625
+ const sway = clamp(o.swing / 26, -1.6, 1.6);
626
+ const up = airborne || held ? 1 : 0;
627
+ const hair = sp.hair.step(sway * 1.1 - tiltVel * .004 - yawVel * .02 + (walking ? -.25 : 0) - runK * .5, dt);
628
+ const hairY = sp.hairY.step(up * -1 + lowV * .006, dt);
629
+ const bangs = sp.bangs.step(sway * .7 - tiltVel * .004 - yawVel * .03, dt);
630
+ const skirt = sp.skirt.step(sway * .8 + (walking ? -.2 : 0), dt);
631
+ const flare = sp.skirtY.step(up * .8 + sitK * .6 + clamp(-lowV * .01, -.3, .6), dt);
632
+ const [fm, wg] = MOOD[face] || MOOD.neutral;
633
+ finMood = lerp(finMood, lerp(fm, -.6, shiver), ease(6, dt));
634
+ wagAmp = lerp(wagAmp, wg, ease(3, dt));
635
+ tailMood = lerp(tailMood, mode === 'sleep' || face === 'sad' || face === 'cry' || face === 'scared' ? -1 : 0, ease(3, dt));
636
+ // fast flutters go on after the springs, which would smooth them away
637
+ const fins = sp.fins.step(finMood * 14 + sway * 10, dt) + (face === 'angry' ? 2.5 * Math.sin(t * 40) : 0) + flap * 13 * Math.sin(t * 26);
638
+ const ahoge = sp.ahoge.step(-tiltVel * .12 - yawVel * .5 + sway * 18 + (face === 'surprised' ? -16 : 0) + (face === 'confused' ? 20 : 0) + (mode === 'sleep' ? 22 : 0) - hairY * 12, dt)
639
+ + flap * 12 * Math.sin(t * 19);
640
+ const tail = sp.tail.step(sway * 14 + tailMood * 12, dt) + wagAmp * 13 * Math.sin(t * (4 + 5 * wagAmp)) + Math.sin(t * 1.3) * 3
641
+ + flap * 14 * Math.sin(t * 17);
642
+
643
+ /* legs: the kit hands hip→foot segments sized for Coo; keep their angle (forward = foot to the right) */
644
+ const legA = o.legs.map(l => -Math.atan2(l[2] - l[0], Math.max(4, l[3] - l[1])) * 180 / Math.PI);
645
+ const lift = o.legs.map(l => clamp(29 - Math.hypot(l[2] - l[0], l[3] - l[1]), -8, 20));
646
+ // sitting swaps the lower body for its own drawing (skirt spread on the floor, legs forward) in a
647
+ // couple of frames halfway down, under a little squash; a long crossfade would show both skirts at once
648
+ const sitIn = smooth(.44, .54, sitK), plop = Math.sin(Math.PI * smooth(.3, .8, sitK));
649
+
650
+ /* arms: swing against the legs when walking, out in the air, flailing when held */
651
+ // running is a ninja run: both arms swept straight back, the whole body leaning forward (groupTilt)
652
+ walkK = lerp(walkK, walking ? 1 : 0, ease(8, dt));
653
+ runK = lerp(runK, mode === 'run' ? 1 : 0, ease(7, dt));
654
+ // `swing` is whether the walk swings the arms: a pose that sets both arms holds them still
655
+ let aN = 4, aF = -2, swing = walking ? 1 : 0;
656
+ if (airborne) { aN = 40; aF = -30; }
657
+ if (held) { aN = (70 + 16 * Math.sin(t * 13)) * L.heldArms; aF = (-45 - 12 * Math.sin(t * 13 + 1.3)) * L.heldArms; }
658
+ if (sitK > .5 && !walking) { aN = lerp(aN, -4, sitK); aF = lerp(aF, -6, sitK); }
659
+ if (face === 'happy' || face === 'love') { aN += 12 + 5 * Math.sin(t * 8); aF -= 8 + 4 * Math.sin(t * 8); }
660
+ if (face === 'angry') { aN = 20 + 3 * Math.sin(t * 30); aF = -18 - 3 * Math.sin(t * 30); swing = 0; }
661
+ if (face === 'determined') { aN = 14; aF = -10; swing = 0; }
662
+ if (face === 'excited') { aN += 18; aF -= 12; }
663
+ if (mode === 'dance') { const b = Math.sin((o.modeT || 0) * Math.PI * 2 * 1.1); aN = 16 + 24 * Math.max(0, b); aF = -8 - 22 * Math.max(0, -b); }
664
+ if (runK > .001) { aN = lerp(aN, 38, runK); aF = lerp(aF, 32, runK); }
665
+ if (wave) aN = lerp(aN, 108, wave);
666
+ if (shiver) { aN = lerp(aN, -10, shiver); aF = lerp(aF, 8, shiver); }
667
+ // each arm swings against the leg on its side. The swing goes on after the arm springs, which settle at about
668
+ // 1.2 Hz: the walk's 2.1 Hz stride would come out of them about 120° late, each arm moving with its own leg.
669
+ swingK = lerp(swingK, swing, ease(8, dt));
670
+ const gait = swingK * (1 - runK) * (1 - wave) * (1 - shiver) * .5;
671
+ const armN = sp.armN.step(aN, dt) - legA[0] * gait + wave * 13 * Math.sin(t * 15) + shiver * 1.4 * Math.sin(t * 47) + flap * 9 * Math.sin(t * 24);
672
+ const armF = sp.armF.step(aF, dt) - legA[1] * gait - shiver * 1.2 * Math.sin(t * 43 + 1) - flap * 9 * Math.sin(t * 24 + 1);
673
+
674
+ /* deformer states */
675
+ // the kit sinks the hips 29 when seated; the sitting drawing's lowest point is 19.4 above the soles
676
+ st.body = { a: -sway * 1.2 + (held ? o.swing * .15 : 0), ty: low - 9.6 * sitK, sx: (1 + .006 * breath + .04 * plop) * (1 - .03 * shiver), sy: 1 - .012 * breath - .06 * plop };
677
+ st.waist = { a: bow * 20 };
678
+ st.skirt = {
679
+ fn: (u, v) => {
680
+ const k = v * v;
681
+ // on the way down the hem spreads a little before the sitting skirt takes over
682
+ return [skirt * 4 * k + flare * (u - .45) * 9 * v + sitK * (u - .45) * 10 * v, -flare * k * 3 - sitK * k * 8];
683
+ },
684
+ };
685
+ // the sitting skirt breathes a little at its hem, and its front edge swings with the body
686
+ st.skirtSit = { fn: (u, v) => [skirt * 1.5 * v * v, -Math.max(0, breath) * .4 * v] };
687
+ st.alpha.skirt = st.alpha.waist_bow_front = st.alpha.skirt_shadow = 1 - sitIn;
688
+ st.alpha.leg_back = st.alpha.leg_front = 1 - smooth(.42, .52, sitK);
689
+ st.alpha.skirt_sit = st.alpha.waist_bow_sit_front = sitIn;
690
+ st.armNear = { a: armN };
691
+ st.armFar = { a: armF };
692
+ // the far arm's cuff layer sits over the bodice; swept back, the arm is behind her and so is the cuff
693
+ st.alpha.arm_far_end_front = 1 - smooth(12, 30, armF);
694
+ // she is turned toward us, so a foot behind its hip is also farther away: it rides a little higher,
695
+ // which reads as the heel coming up at the push-off
696
+ const behind = o.legs.map(l => Math.max(0, l[0] - l[2]) * .3 * walkK);
697
+ st.legBack = { fn: hinge(L.PV.legBack, lerp(legA[0], -55, sitK), (-lift[0] * .9 - behind[0]) * (1 - sitK)) };
698
+ st.legFront = { fn: hinge(L.PV.legFront, lerp(legA[1], -60, sitK), (-lift[1] * .9 - behind[1]) * (1 - sitK)) };
699
+ st.tail = { a: tail - 10 * sitK };
700
+ // the maid dress's tail turns about the edge of the skirt and bends most at its root end, out of sight under the
701
+ // skirt; one that turns about its root inside the body stays put there and its tip trails the turn
702
+ const tr = L.tailRoot;
703
+ st.tailBend = tr
704
+ ? { fn: (u, v, x) => { const k = clamp((tr.x - x) / (tr.x - tr.tip), 0, 1); return [0, tail * .3 * k * k]; } }
705
+ : { fn: u => [0, -tail * .5 * u * u] };
706
+ // the head stays up while she leans forward for the ninja run
707
+ st.neck = { a: headA + clamp(bend * .8, -10, 12) - runK * 12, ty: (mode === 'sleep' ? 2.5 : 0) + breath * .35 };
708
+ const parallax = (k, ky) => (u, v) => [angleX * k * bump(u) * (.4 + .6 * bump(v)), angleY * ky * bump(v) * (.4 + .6 * bump(u))];
709
+ st.headFront = { fn: parallax(4.2, 2.8) };
710
+ // the eyes and mouth move with the face: the eyes' outline is shared between the two layers
711
+ st.headFeat = { fn: parallax(2, 1.4) };
712
+ if (L.brows) {
713
+ // the start of a line raises them once, and now and then a while into it
714
+ if ((o.talk || 0) > .2) {
715
+ if (t - talkedAt > .8 || (t - browFlashAt > 2.5 && Math.random() < dt * .4)) browFlashAt = t;
716
+ talkedAt = t;
717
+ }
718
+ const ft = (t - browFlashAt) / .5, flash = ft >= 0 && ft < 1 && !BROW_STILL.has(face) ? 7 * Math.sin(Math.PI * ft) ** 2 : 0;
719
+ const pose = BROW[face] || both(0), rate = BROW_RATE[face] || 9;
720
+ browNow.forEach((b, i) => {
721
+ // the whole brow leads and its tilt and curve follow, so the ends travel on a slight arc
722
+ b[0] = lerp(b[0], pose[i][0] + flash - 2 * (o.blink || 0), ease(rate, dt));
723
+ for (let j = 1; j < 4; j++) b[j] = lerp(b[j], pose[i][j], ease(rate * .75, dt));
724
+ });
725
+ browOver = lerp(browOver, BROW_OVER.has(face) ? 1 : 0, ease(14, dt));
726
+ BROWS.forEach((b, i) => {
727
+ const [Y, A, F, X] = browNow[i], outer = U(b.outer[0]), inner = U(b.inner[0]), toNose = Math.sign(inner - outer);
728
+ // raising the inner end turns the brow toward its outer side
729
+ st[`brow${i}`] = { a: -toNose * Math.atan2(A, Math.abs(b.inner[0] - b.outer[0])) * 180 / Math.PI, tx: X * toNose * S, ty: -Y * S };
730
+ // a bend along the line between the ends: 0 at either end, F at the middle
731
+ st[`browBend${i}`] = { fn: (u, v, x) => { const k = clamp((2 * x - outer - inner) / (inner - outer), -1, 1); return [0, -F * (1 - k * k) * S]; } };
732
+ // the mirrored copy turned back so its ends sit where the drawing's do (a reflection over that line)
733
+ st[`browOver${i}`] = { a: 2 * Math.atan((b.outer[1] - b.inner[1]) / (b.outer[0] - b.inner[0])) * 180 / Math.PI };
734
+ st.alpha[`brow${i}`] = 1 - browOver; st.alpha[`browOver${i}`] = browOver;
735
+ st.alpha[`brow${i}_through`] = .55 * (1 - browOver); st.alpha[`browOver${i}_through`] = .55 * browOver;
736
+ });
737
+ }
738
+ if (L.creases) {
739
+ // an eye drawn with the wide (surprised) sprite has no lowered lid, whatever the brows do
740
+ fc.eyes.forEach((e, i) => { creaseDrop[i] = lerp(creaseDrop[i], lidDrop(e, EYES[i], fc.wide && e.shape === 'ring' ? 0 : fc.brows), ease(12, dt)); });
741
+ creaseA = lerp(creaseA, (lidOpen(fc.eyes[0]) + lidOpen(fc.eyes[1])) / 2, ease(12, dt));
742
+ st.alpha.eye_creases = creaseA;
743
+ st.creases = { fn: (u, v, x) => [0, (x < BROW_SPLIT ? creaseDrop[0] : creaseDrop[1]) * S] };
744
+ }
745
+ st.headMid = { fn: parallax(2, 1.4) };
746
+ st.headBack = { fn: parallax(-1.4, -1) };
747
+ // the long hair hangs from the head but its lower half keeps to the body when the head tilts
748
+ const nk = L.PV.neck, na = headA * Math.PI / 180;
749
+ st.hairSway = {
750
+ fn: (u, v, x, y) => {
751
+ const w = smooth(.3, .8, v), a = -na * w, c = Math.cos(a), s = Math.sin(a);
752
+ const dx = x - nk[0], dy = y - nk[1];
753
+ const wv = Math.pow(v, 1.6);
754
+ return [nk[0] + dx * c - dy * s - x + hair * 8 * wv + Math.sin(t * 1.6 + v * 3) * wv,
755
+ nk[1] + dx * s + dy * c - y + hairY * 12 * wv * wv - Math.abs(hair) * 1.5 * wv];
756
+ },
757
+ };
758
+ st.bangsSway = { fn: (u, v) => [bangs * 3.2 * v * v + Math.sin(t * 1.9 + u * 2) * .5 * v * v, hairY * 3 * v * v] };
759
+ st.ahoge = { a: ahoge * .5 + Math.sin(t * 2.1) * 2 };
760
+ st.finNear = { a: fins + Math.sin(t * 1.4) * 1.5 };
761
+ st.finFar = { a: -fins * .8 - Math.sin(t * 1.4) * 1.2 };
762
+ // what hangs off her (the pompoms on the hood ties, the scarf ends) is a pendulum: it hangs down whichever way
763
+ // its root and the whole of her are turned, and the motion that flings her hair flings it, so it trails, swings
764
+ // back and settles over a few swings. A quick turn of its root (a nod, a landing) kicks it, and so does each
765
+ // step; one hung from the head also swings as the face turns (a shake, a look round), and idly sways a little.
766
+ // `gain` is how freely it swings: 1 for a pompom on a string, less for cloth, which hangs only partly
767
+ const faceTurn = (angleX - (rootWas.face ?? angleX)) / Math.max(dt, 1e-3); rootWas.face = angleX;
768
+ for (const [k, d] of Object.entries(L.swings)) {
769
+ let root = (o.groupRot || 0) * facing, onHead = false;
770
+ for (let p = d.parent; p; p = L.deformers[p].parent) {
771
+ if (L.deformers[p].kind === 'rot') root += st[p]?.a || 0;
772
+ if (p === 'neck') onHead = true;
773
+ }
774
+ const kick = (root - (rootWas[k] ?? root)) / Math.max(dt, 1e-3); rootWas[k] = root;
775
+ // a short string: it takes a good many degrees before the swing shows
776
+ const pend = sp[`pend_${k}`] ||= spring(28, 1.8, 55), ph = d.pivot[0] * .05;
777
+ const a = pend.step((-sway * 34 - kick * .15 + (onHead ? faceTurn * 8 : 0) + walkK * (legA[0] - legA[1]) * .3) * d.gain, dt);
778
+ const idle = onHead ? Math.sin(t * 1.7 + ph) * 6 + Math.sin(t * 2.9 + ph * 1.3) * 2.5 : Math.sin(t * 1.7 + ph) * 2;
779
+ st[k] = { a: a + idle * d.gain - root * Math.min(1, d.gain) };
780
+ }
781
+
782
+ // the highlights lag a gaze shift or a turn of the face and spring back; an opening lid flicks them up
783
+ const look = [clamp(o.look[0], -6, 6), clamp(o.look[1], -5, 5)], was = prevLook || look; prevLook = look;
784
+ const shut = Math.max(o.blink || 0, o.eyeClose || 0), shutV = (shut - prevShut) / Math.max(dt, 1e-3); prevShut = shut;
785
+ hl.dx = sp.hlX.step(-(look[0] - was[0]) / Math.max(dt, 1e-3) * .03 - yawVel * .8, dt);
786
+ hl.dy = sp.hlY.step(-(look[1] - was[1]) / Math.max(dt, 1e-3) * .03 + shutV * .12, dt);
787
+ const mood = HL_MOOD[face] || {};
788
+ hl.scale = lerp(hl.scale, mood.scale ?? 1, ease(6, dt));
789
+ hl.quiver = lerp(hl.quiver, mood.quiver ?? 0, ease(4, dt));
790
+ hl.alpha = lerp(hl.alpha, mood.alpha ?? 1, ease(4, dt));
791
+
792
+ const ops = faceOps(fc, face, o, t), key = opsKey(ops);
793
+ if (key !== painted.key || img !== painted.img || rig !== painted.rig) {
794
+ paintFace(ops);
795
+ rig.upload('faceFx', faceCv);
796
+ painted = { key, img, rig };
797
+ }
798
+ st.mix = 0;
799
+ if (fade) {
800
+ if (fade.t0 == null) fade.t0 = t;
801
+ st.mix = smooth(0, 1, (t - fade.t0) / fade.dur);
802
+ const own = img;
803
+ img = fade.set.img; fg = fg2;
804
+ paintFace(ops);
805
+ img = own; fg = fg1;
806
+ rig.upload('faceFx@mix', faceCv2);
807
+ }
808
+ rig.render(st);
809
+ // raster conversion is the one costly step (GPU readback + PNG encode) and this environment only
810
+ // accepts the picture as an SVG image: cap it at rasterFps conversions a second — skipped frames
811
+ // just keep showing the previous one, which at pet frame rates reads as no change at all
812
+ if (opts.raster && rasterLive && t - rasterAt >= rasterMinGap) {
813
+ rasterAt = t;
814
+ fo.setAttribute('href', canvas.toDataURL('image/png')); decoded = fo.decode ? fo.decode().catch(() => {}) : null;
815
+ }
816
+ if (fade && st.mix >= 1) endFade();
817
+ drawFx(fc, t);
818
+ }
819
+
820
+ /* ---------- effects over the figure (SVG, like the built-in figure's) ---------- */
821
+ const at = (x, y) => rig.point('neck', st, x, y);
822
+ function drawFx(fc, t) {
823
+ let s = '';
824
+ const ac = accent();
825
+ const top = at(124, 34), side = at(204, 52);
826
+ if (fc.orbit) {
827
+ for (let i = 0; i < 3; i++) {
828
+ const a = t * 3.2 + i * 2.094, sn = Math.sin(a);
829
+ s += `<path fill="#ffd23f" stroke="#3a2f7a" stroke-width="1.6" stroke-linejoin="round" opacity="${sn < 0 ? .55 : 1}" transform="translate(${f1(top[0] + 56 * Math.cos(a))} ${f1(top[1] - 4 + 10 * sn)}) scale(${sn < 0 ? .7 : 1})" d="M0 -7L2 -2L7 -2L3 1L4.5 6.5L0 3.3L-4.5 6.5L-3 1L-7 -2L-2 -2Z"/>`;
830
+ }
831
+ }
832
+ if (fc.listen) {
833
+ for (let i = 0; i < 3; i++) {
834
+ const p = (t * .9 + i / 3) % 1, r = 36 - 24 * p, c = at(214, 116);
835
+ s += `<path fill="none" stroke="${ac}" stroke-width="5" stroke-linecap="round" opacity="${f1(Math.sin(Math.PI * p))}" d="M${f1(c[0] + r * Math.cos(-.55))} ${f1(c[1] + r * Math.sin(-.55))}A${f1(r)} ${f1(r)} 0 0 1 ${f1(c[0] + r * Math.cos(.55))} ${f1(c[1] + r * Math.sin(.55))}"/>`;
836
+ }
837
+ }
838
+ if (fc.think) {
839
+ for (let i = 0; i < 3; i++) {
840
+ const k = (t * .8 + i / 3) % 1;
841
+ s += `<circle fill="#e8f0ff" stroke="${ac}" stroke-width="3" cx="${f1(side[0] + 10 * i)}" cy="${f1(side[1] - 20 * i - 6 * k)}" r="${4 + 3 * i}" opacity="${f1(.4 + .6 * Math.sin(Math.PI * k))}"/>`;
842
+ }
843
+ }
844
+ if (fc.sweat) {
845
+ const c = at(196, 88 + 3 * Math.sin(t * 7));
846
+ s += `<path fill="#8fd0ff" stroke="#2f5fae" stroke-width="1.4" transform="translate(${f1(c[0])} ${f1(c[1])}) scale(1.4)" d="M0 -9C4 -3 6 0 6 3.5A6 6 0 0 1 -6 3.5C-6 0 -4 -3 0 -9Z"/>`;
847
+ }
848
+ if (fc.anger) {
849
+ const c = at(190, 62), k = 1 + .12 * Math.sin(t * 10);
850
+ s += `<g transform="translate(${f1(c[0])} ${f1(c[1])}) scale(${f1(k)})" fill="none" stroke="#e5484d" stroke-width="5" stroke-linecap="round"><path d="M-11 -3Q-3 -3 -3 -11M3 -11Q3 -3 11 -3M11 3Q3 3 3 11M-3 11Q-3 3 -11 3"/></g>`;
851
+ }
852
+ if (fc.bang) {
853
+ const c = at(206, 36);
854
+ s += `<g transform="translate(${f1(c[0])} ${f1(c[1])})"><path fill="none" stroke="#252049" stroke-width="8" stroke-linecap="round" d="M0 -16V3"/><circle fill="#252049" cx="0" cy="14" r="4.5"/></g>`;
855
+ }
856
+ if (fc.question) {
857
+ const c = at(206, 36), k = 1 + .06 * Math.sin(t * 3);
858
+ s += `<g transform="translate(${f1(c[0])} ${f1(c[1])}) scale(${f1(k)})"><path fill="none" stroke="#252049" stroke-width="7" stroke-linecap="round" stroke-linejoin="round" d="M-8 -9Q-8 -19 0 -19Q9 -19 9 -11Q9 -4 0 -1V4"/><circle fill="#252049" cx="0" cy="14" r="4.5"/></g>`;
859
+ }
860
+ if (fx !== s) { fxG.innerHTML = s; fx = s; }
861
+ }
862
+
863
+ return {
864
+ draw,
865
+ groupTilt,
866
+ /** The gestures she draws herself, from the frame's `gesture` (the kit leaves them off the body). */
867
+ gestures: ['nod', 'shake', 'wave', 'bow'],
868
+ setScheme,
869
+ /** Forgets the motion state (springs, clocks), for callers that replay a timeline from its start. */
870
+ /**
871
+ * Renders `frames` frames of one pose (face `fc`, frame fields `o`, its clock starting at o.t) at `res` canvas
872
+ * pixels per rig unit, then gives up the WebGL context; returns an SVG <image> for the result in rig space.
873
+ * For pages showing many still figures, which would otherwise hold a GPU context each.
874
+ */
875
+ snapshot(fc, o, res = 3, frames = 60) {
876
+ fixedRes = res;
877
+ const g = document.createElementNS(SVGNS, 'g');
878
+ for (let i = 0; i < frames; i++) draw(g, fc, { ...o, t: (o.t || 0) + i / 60 });
879
+ const href = canvas.toDataURL('image/png');
880
+ rig.dispose();
881
+ rig = null; mountedIn = null; fixedRes = 0;
882
+ return `<image href="${href}" x="${VIEW[0]}" y="${VIEW[1]}" width="${VIEW[2] - VIEW[0]}" height="${VIEW[3] - VIEW[1]}"/>`;
883
+ },
884
+ /**
885
+ * Renders `count` frames of a short animation clip with ONE WebGL context: `frame(i)` returns
886
+ * { fc, o } for frame i (its `t` is overwritten — an 8s lead-in lets the springs settle before
887
+ * frame 0), each frame is read back as a dataURL at `res` canvas pixels per rig unit, and the
888
+ * context is given up at the end. For pages that need a looping sprite per clone/prop without
889
+ * holding a GPU context for each (desk clones play these frames back at their own pace).
890
+ */
891
+ clipFrames(frame, res = 2, count = 8) {
892
+ // a fresh figure's springs/clocks already start at their rest state, so no reset is needed
893
+ fixedRes = res;
894
+ const g = document.createElementNS(SVGNS, 'g');
895
+ const frames = [];
896
+ for (let i = 0; i < count; i++) frames.push(frame(i));
897
+ // warm-up: one pass of the whole loop before capturing, so the springs reach their
898
+ // cycle's steady state and no starting transient is baked into frame 0
899
+ for (let i = 0; i < count; i++) draw(g, frames[i].fc, { ...frames[i].o, t: 8 + (frames[i].o.t || 0) });
900
+ const out = [];
901
+ const t0 = 8 + Math.max(...frames.map(f => f.o.t || 0)) + 1 / 60;
902
+ for (let i = 0; i < count; i++) {
903
+ const { fc, o } = frames[i];
904
+ draw(g, fc, { ...o, t: t0 + (o.t || 0) });
905
+ out.push(canvas.toDataURL('image/png'));
906
+ }
907
+ rig.dispose();
908
+ rig = null; mountedIn = null; fixedRes = 0;
909
+ return out;
910
+ },
911
+ /**
912
+ * Releases the WebGL context and drops the mounted DOM (what `setFigure` switching away from
913
+ * this figure calls). The figure object stays usable: the next `draw` re-mounts from scratch.
914
+ */
915
+ dispose() {
916
+ rig?.dispose();
917
+ rig = null; canvas = null; fo = null; fxG = null; mountedIn = null;
918
+ },
919
+ reset() {
920
+ endFade();
921
+ for (const k in sp) { sp[k].x = 0; sp[k].v = 0; }
922
+ lastT = null; rootWas = {}; prevTilt = 0; prevYaw = 0; prevLow = 0; headTilt = 0; wTilt = 0; wLean = 0; finMood = 0; tailMood = 0; wagAmp = 0; sitK = 0; walkK = 0; runK = 0; swingK = 0;
923
+ prevLook = null; prevShut = 0; Object.assign(hl, { dx: 0, dy: 0, scale: 1, quiver: 0, alpha: 1 });
924
+ },
925
+ /** Loads every scheme's and outfit's textures, so later switches are immediate. */
926
+ preload: () => Promise.all(SCHEMES.flatMap(sc => OUTFITS.map(of => loadScheme(sc.id, of.id)))),
927
+ get scheme() { return `${scheme}-${outfit}`; },
928
+ /** Raster mode: a promise that settles once the last drawn frame is ready to be painted. */
929
+ get painted() { return decoded || Promise.resolve(); },
930
+ /** Raster conversion switch: while false the per-frame toDataURL copy is skipped (saves CPU
931
+ * when nothing needs the raster image, e.g. no clones on the desk). */
932
+ set rasterLive(on) { rasterLive = !!on; },
933
+ get rasterLive() { return rasterLive; },
934
+ get colors() { return { z: accent() }; },
935
+ schemes: SCHEMES,
936
+ // points the kit uses: eye tracking, a tear and one under each eye (where the streams run), sleep z's, hearts [x from, x to, y], bubble
937
+ anchors: {
938
+ gaze: [U(745), V(690)], tear: [U(640), V(752)], tears: [[U(654), V(752)], [U(852), V(750)]], z: [196, 44],
939
+ hearts: [96, 176, 62], bubble: [128, 18],
940
+ },
941
+ model,
942
+ };
943
+ }
944
+
945
+ /** The whale pack's entry (figure.json): her body for the figure frame, the kit's body drawn by her figure. */
946
+ export async function createWhaleBody(base, opts) {
947
+ return opts.kit.createBody(opts.host, { figure: await createWhaleFigure(base, opts), ground: opts.ground });
948
+ }