@yusho/server 0.0.0-stage → 0.1.17

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 (115) hide show
  1. package/README.md +135 -2
  2. package/app/appguide.mjs +33 -0
  3. package/app/asr.mjs +82 -0
  4. package/app/assets/agents/claude-192.webp +0 -0
  5. package/app/assets/agents/claude-96.webp +0 -0
  6. package/app/assets/agents/codex-192.webp +0 -0
  7. package/app/assets/agents/codex-96.webp +0 -0
  8. package/app/assets/agents/default-192.webp +0 -0
  9. package/app/assets/agents/default-96.webp +0 -0
  10. package/app/assets/agents/dsh-192.webp +0 -0
  11. package/app/assets/agents/dsh-96.webp +0 -0
  12. package/app/assets/brand/logo.webp +0 -0
  13. package/app/assets/lib/THIRD-PARTY.txt +1 -0
  14. package/app/assets/lib/jsqr.js +10102 -0
  15. package/app/assets/linux/alpine-arm64.tar.gz +0 -0
  16. package/app/assets/linux/alpine-x64.tar.gz +0 -0
  17. package/app/assets/live/claude.livliv +0 -0
  18. package/app/assets/live/dafeiyu.livliv +0 -0
  19. package/app/assets/live/gpt.livliv +0 -0
  20. package/app/assets/live/sho.livliv +0 -0
  21. package/app/assets/live//345/275/242/350/261/241/346/235/245/346/272/220.md +5 -0
  22. package/app/assets/livliv/LICENSE +202 -0
  23. package/app/assets/livliv/NOTICE +7 -0
  24. package/app/assets/livliv/player.mjs +15 -0
  25. package/app/assets/looks/claude.webp +0 -0
  26. package/app/assets/looks/dafeiyu.webp +0 -0
  27. package/app/assets/looks/gpt.webp +0 -0
  28. package/app/assets/looks//345/275/242/350/261/241/346/235/245/346/272/220.md +5 -0
  29. package/app/assets/sho/avatar.webp +0 -0
  30. package/app/assets/sho/done.webp +0 -0
  31. package/app/assets/sho/eat.webp +0 -0
  32. package/app/assets/sho/idle-blink.webp +0 -0
  33. package/app/assets/sho/idle.webp +0 -0
  34. package/app/assets/sho/listen.webp +0 -0
  35. package/app/assets/sho/need.webp +0 -0
  36. package/app/assets/sho/work.webp +0 -0
  37. package/app/companion.mjs +519 -0
  38. package/app/diag.mjs +51 -0
  39. package/app/index.html +497 -0
  40. package/app/judge.mjs +103 -0
  41. package/app/lanxfer.mjs +157 -0
  42. package/app/launcher.mjs +2715 -0
  43. package/app/linux.mjs +97 -0
  44. package/app/livliv-pack.mjs +12 -0
  45. package/app/memory.mjs +53 -0
  46. package/app/net.mjs +717 -0
  47. package/app/office.mjs +172 -0
  48. package/app/p2plink.mjs +134 -0
  49. package/app/pcupdate.mjs +55 -0
  50. package/app/plans.mjs +126 -0
  51. package/app/plugins.mjs +79 -0
  52. package/app/realtime.mjs +67 -0
  53. package/app/skills/app-icon/SKILL.md +31 -0
  54. package/app/skills/daily-brief/SKILL.md +29 -0
  55. package/app/skills/expense-review/SKILL.md +28 -0
  56. package/app/skills/make-app/SKILL.md +92 -0
  57. package/app/skills/make-skin/SKILL.md +51 -0
  58. package/app/skills/meeting-notes/SKILL.md +23 -0
  59. package/app/skills/reading-notes/SKILL.md +25 -0
  60. package/app/skills/sho-stickers/SKILL.md +34 -0
  61. package/app/skills/sho-stickers/stickers/eat.webp +0 -0
  62. package/app/skills/sho-stickers/stickers/got-it.webp +0 -0
  63. package/app/skills/sho-stickers/stickers/hi.webp +0 -0
  64. package/app/skills/sho-stickers/stickers/huh.webp +0 -0
  65. package/app/skills/sho-stickers/stickers/on-it.webp +0 -0
  66. package/app/skills/sho-stickers/stickers/yay.webp +0 -0
  67. package/app/skills/sho-stickers/stickers.json +12 -0
  68. package/app/skills/study-plan/SKILL.md +30 -0
  69. package/app/skills/trip-planner/SKILL.md +29 -0
  70. package/app/skills/weekly-report/SKILL.md +30 -0
  71. package/app/skills/workout-plan/SKILL.md +30 -0
  72. package/app/skills/writing-polish/SKILL.md +33 -0
  73. package/app/skills.mjs +173 -0
  74. package/app/skins.mjs +40 -0
  75. package/app/social.mjs +1067 -0
  76. package/app/storage.mjs +143 -0
  77. package/app/tts.mjs +68 -0
  78. package/app/ttslocal.mjs +77 -0
  79. package/app/voices.mjs +102 -0
  80. package/backup.mjs +109 -0
  81. package/bin/yusho.mjs +141 -0
  82. package/connector/lib/api.mjs +14 -0
  83. package/connector/lib/autostart.mjs +40 -0
  84. package/connector/lib/client.js +165 -0
  85. package/connector/lib/connector.mjs +468 -0
  86. package/connector/lib/dsh-acp.mjs +129 -0
  87. package/connector/lib/dsh-headless.patch.yml +4 -0
  88. package/connector/lib/dsh-plugin.mjs +80 -0
  89. package/connector/lib/lanfile.mjs +151 -0
  90. package/connector/lib/nostr.mjs +53 -0
  91. package/connector/lib/page.html +121 -0
  92. package/connector/lib/qr.mjs +4 -0
  93. package/connector/lib/service.mjs +54 -0
  94. package/node_modules/@local/shoal-mobile/lib/index.js +485 -0
  95. package/node_modules/@local/shoal-mobile/lib/polyfill.js +82 -0
  96. package/node_modules/@local/shoal-mobile/lib/session-context.js +34 -0
  97. package/node_modules/@local/shoal-mobile/lib/shell.js +60 -0
  98. package/node_modules/@local/shoal-mobile/lib/web-startup.js +33 -0
  99. package/node_modules/@local/shoal-mobile/package.json +24 -0
  100. package/node_modules/@local/yusho-pc/lib/client.js +9100 -0
  101. package/node_modules/@local/yusho-pc/lib/index.js +3 -0
  102. package/node_modules/@local/yusho-pc/package.json +28 -0
  103. package/node_modules/@local/yusho-web-login/brand/icon-192.webp +0 -0
  104. package/node_modules/@local/yusho-web-login/brand/logo-dark.svg +25 -0
  105. package/node_modules/@local/yusho-web-login/brand.mjs +8 -0
  106. package/node_modules/@local/yusho-web-login/dsh-web-login.mjs +974 -0
  107. package/node_modules/@local/yusho-web-login/lib/client.js +607 -0
  108. package/node_modules/@local/yusho-web-login/login-page.mjs +609 -0
  109. package/node_modules/@local/yusho-web-login/login-store.mjs +708 -0
  110. package/node_modules/@local/yusho-web-login/package.json +25 -0
  111. package/node_modules/@local/yusho-web-login/whale-scene.mjs +509 -0
  112. package/node_modules/@local/yusho-web-login/yusho-scene.mjs +227 -0
  113. package/package.json +38 -4
  114. package/pc.patch.yml +83 -0
  115. package/run.mjs +138 -0
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ # 形象来源
2
+
3
+ 大肥鱼、Claude 大小姐、GPT 龙娘的形象参考了社区二创:鲸鱼娘源于 B 站 UP 主「上善无形」的原创角色「溟月」,Claude 娘、GPT 娘等 AI 娘形象最早见于画师 ZipZipPipe(胖次狐)。我们用网络上流传的图片垫图,经 AI 重新生成为现在的 Q 版形象。如果你是权利人并有异议,请联系我们,我们会及时修改或删除。Sho 酱为鱼Sho 原创形象。
4
+
5
+ 本文件夹里 `live/dafeiyu.livliv`、`live/claude.livliv`、`live/gpt.livliv` 和 `looks/dafeiyu.webp`、`looks/claude.webp`、`looks/gpt.webp` 这几个形象文件不属于本项目代码的开源许可,单独说明如上。
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,7 @@
1
+ LivLiv Player
2
+ Copyright 2026 LivLiv
3
+
4
+ This product includes software developed by LivLiv (https://livliv.ai).
5
+
6
+ The featured characters in characters/ are not licensed under the Apache License 2.0. Their own terms are in
7
+ characters/LICENSE.md and characters/CREDITS.md. Three of them (Kujira, Kujira Q, Pen) come from other people's work.
@@ -0,0 +1,15 @@
1
+ var kt=()=>({angleX:0,angleY:0,angleZ:0,eyeLOpen:1,eyeROpen:1,eyeBallX:0,eyeBallY:0,browLY:0,browRY:0,mouthOpen:0,smile:0,vowel:0,bodyX:0,bodyZ:0,breath:0}),ft={angleX:[-30,30],angleY:[-30,30],angleZ:[-30,30],eyeLOpen:[0,1],eyeROpen:[0,1],eyeBallX:[-1,1],eyeBallY:[-1,1],browLY:[-1,1],browRY:[-1,1],mouthOpen:[0,1],smile:[0,1],vowel:[-1,1],bodyX:[-10,10],bodyZ:[-10,10],breath:[0,1]},U=(t,e,a)=>{let i=Math.min(1,Math.max(0,(a-t)/(e-t)));return i*i*(3-2*i)};var V=class extends Error{code;status;constructor(t,e,a={}){super(e,a.cause===void 0?void 0:{cause:a.cause}),this.name="LivLivError",this.code=t,a.status!==void 0&&(this.status=a.status)}};var Fe="livliv-model",$e=4,fe="livemaker-puppet",Ue=[],N={canvas:8192,layers:512,images:2048,expressions:256,eyes:16,chains:64,points:256,texture:8192,texels:64*2**20,modelJson:4*2**20,keyforms:32*2**20,vertices:2**21,skinned:2**20},tt=(t,e)=>Object.assign(Error(e),{code:t}),Xe=1e6,Ie=["head","body","hair_back","hair_side","hair_front","hair_inner"],Vt=(t,e)=>Math.max(6,Math.round(Math.max(t,e)/128)),Ne=/^textures\/[A-Za-z0-9_][A-Za-z0-9_.-]*\.(?:webp|png)$/,Yt=/^(?!.*(?:^|\/)\.\.(?:\/|$))[A-Za-z0-9_][A-Za-z0-9_.-]*(?:\/[A-Za-z0-9_][A-Za-z0-9_.-]*)*$/,Wt=new WeakSet;function It(t,e=ce()){if(!t||typeof t!="object"||Array.isArray(t))throw tt("not-a-model","not a LivLiv model (model.json is not an object)");if(Wt.has(t))return t;let a=t;if(a.format===void 0||a.format==="livemaker-puppet"){let s=a.version??3;if(s>3)throw tt("not-a-model",`this model says format "${fe}" version ${s}, which never existed`);return ne(a),Wt.add(a),a}if(a.format!=="livliv-model")throw tt("not-a-model",`not a LivLiv model (format "${String(a.format)}")`);let i=a.version;if(typeof i!="number"||i>4)throw tt("newer-format",`this model is format version ${i}; this player reads up to 4: update the player`);let o=(a.requires||[]).filter(s=>!Ue.includes(s));if(o.length)throw tt("missing-feature",`this model needs ${o.join(", ")}, which this player does not have: update the player`);let n=je(a,e);return ne(n),Wt.add(n),n}function ne(t){var _;let e=(l,u="invalid")=>{throw tt(u,`this model is not valid: ${l}`)},a=l=>typeof l=="number"&&Number.isFinite(l),i=(l,u,A)=>l===void 0?[]:((!Array.isArray(l)||l.length>u)&&e(`${A} is not a list of at most ${u}`),l),[o=NaN,n=NaN]=Array.isArray(t.canvas)?t.canvas:[];a(o)&&a(n)&&o>0&&n>0&&o<=N.canvas&&n<=N.canvas||e(`its canvas ${o} x ${n} is out of range`,o>N.canvas||n>N.canvas?"too-large":"invalid"),Array.isArray(t.layers)&&t.layers.length||e("it has no layers"),t.layers.length>N.layers&&e(`it has ${t.layers.length} layers, more than ${N.layers}`,"too-large");let s=t.anchors,r=s==null?void 0:s.head,h=l=>a(l)&&Math.abs(l)<=Xe;r&&[r.cx,r.cy,r.rx,r.ry,s.neck_y,s.top_y,s.bottom_y,s.hair_root_y].every(h)&&r.rx>.001&&r.ry>.001&&Array.isArray(s.face)&&s.face.length===4&&s.face.every(h)||e("its anchors are missing or not numbers");let c=(l,u)=>{l!=null&&!h(l)&&e(`${u} is not a number in range`)},y=(l,u,A,v)=>{l!=null&&(!Array.isArray(l)||l.length<u||l.length>A||!l.every(h))&&e(`${v} is not a list of ${u} to ${A} numbers`)},m=(l,u,A)=>{if(l!=null){typeof l!="object"&&e(`${A} is not an object`);for(let v of u.split(" "))c(l[v],`${A}.${v}`)}},d=(l,u)=>{if(l!=null){(typeof l!="object"||Array.isArray(l))&&e(`${u} is not an object`);for(let[A,v]of Object.entries(l))c(v,`${u}.${A.slice(0,60)}`)}};c(s.collar_y,"anchors.collar_y"),m(s.jaw,"top chin half open round wide","anchors.jaw"),m(s.chest,"cx cy rx ry","anchors.chest");for(let l of i(s.eyes,N.eyes,"anchors.eyes"))l??e("anchors.eyes has an empty entry"),y(l,4,4,"anchors.eyes");for(let l of i(s.brows,N.eyes,"anchors.brows"))y(l,4,4,"anchors.brows");for(let l of i(s.brow_lines,N.eyes,"anchors.brow_lines")){if(l==null)continue;let u=i(l.x,N.points,"a brow line").length;u||e("a brow line has no points"),y(l.x,u,u,"a brow line"),y(l.bottom??[],u,u,"a brow line"),y(l.lid??[],u,u,"a brow line"),l.cap!=null&&y(l.cap,u,u,"a brow line")}m(t.tuning,"turn nod hair blink expr mouth breath hairFront hairBack","tuning");let f=t.rig;if(m(f,"yaw pitch roll bulge bulge_shape hair_limit wind breath sway brow pitch_ease jaw","rig"),y(f==null?void 0:f.bulge_extent,3,5,"rig.bulge_extent"),y(f==null?void 0:f.drift,2,2,"rig.drift"),y(f==null?void 0:f.hair_drive,3,3,"rig.hair_drive"),m(f==null?void 0:f.body,"yaw roll breath bust","rig.body"),m(f==null?void 0:f.neck,"twist reach","rig.neck"),(f==null?void 0:f.hair)!=null)for(let l of["front","back","side"])y(f.hair[l],5,5,`rig.hair.${l}`);for(let l of i(f==null?void 0:f.chains,N.chains,"rig.chains")){l&&typeof l.id=="string"||e("a chain has no id");let u=`chain ${l.id.slice(0,60)}`,A=i(l.points,N.points,`${u}'s points`);A.length<2&&e(`${u} has fewer than two points`);for(let v of A)v??e(`${u} has an empty point`),y(v,2,2,`${u}'s points`);l.k||e(`${u} has no k`),y(l.k,2,2,`${u}'s k`);for(let v of["damp","drive","hang","wind"])a(l[v])||e(`${u} has no ${v}`);m(l,"depth damp drive hang wind freq limit sigma reach",u),d(l.bias,`${u}'s bias`)}let p=Vt(o,n),g=(_=t.layers.find(l=>(l==null?void 0:l.group)==="hair_front"))==null?void 0:_.bones,x=0,b=0,k=0,w=0;for(let l of t.layers){l&&typeof l=="object"&&typeof l.id=="string"||e("a layer has no id"),(![l.x,l.y,l.w,l.h].every(a)||!(l.w>0&&l.h>0)||l.x<-o||l.y<-n||l.x+l.w>2*o||l.y+l.h>2*n)&&e(`layer ${l.id.slice(0,60)}'s box is out of range`),typeof l.texture!="string"&&e(`layer ${l.id.slice(0,60)} has no texture`);for(let R of[l.texture,...i(l.frames,N.images,`layer ${l.id.slice(0,60)}'s frames`),l.mask,l.talk,l.brow_tex])R!==void 0&&(typeof R=="string"&&Yt.test(R)||e(`layer ${l.id.slice(0,60)}: "${String(R).slice(0,80)}" is not a path inside the package`),++x>N.images&&e(`it names more than ${N.images} images`));let u=`layer ${l.id.slice(0,60)}`;Ie.includes(l.group)||e(`${u}'s group is not one a player knows`);for(let R of["role","clip","param"])l[R]!=null&&typeof l[R]!="string"&&e(`${u}'s ${R} is not text`);l.visemes!=null&&!(Array.isArray(l.visemes)&&l.visemes.every(R=>typeof R=="string"))&&e(`${u}'s visemes are not text`),c(l.depth,`${u}'s depth`),c(l.fall,`${u}'s fall`),c(l.fall_end,`${u}'s fall_end`),y(l.pivot,2,2,`${u}'s pivot`),y(l.range,2,2,`${u}'s range`),y(l.rigid,2,2,`${u}'s rigid`),d(l.blush,`${u}'s blush`),d(l.show,`${u}'s show`),d(l.hide,`${u}'s hide`);let A=i(l.bones,N.chains,`${u}'s bones`);new Set(A).size!==A.length&&e(`${u} names a chain twice`),A.every(R=>typeof R=="string")||e(`${u}'s bones are not chain ids`);let v=(Math.ceil((l.x+l.w)/p)-Math.floor(l.x/p)+1)*(Math.ceil((l.y+l.h)/p)-Math.floor(l.y/p)+1),T=l.id==="brows"||l.role==="expr_brows"||!!l.brow_tex;b+=v,k+=v*(A.length+(T&&Array.isArray(g)?g.length:0)),T&&(w+=l.w*l.h)}b>N.vertices&&e(`its layers' meshes would have ${b} vertices, more than ${N.vertices}`,"too-large"),k>N.skinned&&e(`its chains would bend ${k} vertices, more than ${N.skinned}`,"too-large"),w>N.texels&&e(`its brows layers cover ${w} pixels, more than ${N.texels}`,"too-large");for(let l of i(t.expressions,N.expressions,"expressions"))l&&typeof l.id=="string"||e("an expression has no id");t.keyforms===void 0||typeof t.keyforms=="string"&&Yt.test(t.keyforms)||e("keyforms is not a path inside the package"),t.watermark!=null&&typeof t.watermark!="string"&&e("its watermark is not text")}function je(t,e){var h,c;if(!Array.isArray(t.layers)||!t.layers.length)throw tt("invalid","this model has no layers");if(t.layers.length>N.layers)throw tt("too-large",`this model has ${t.layers.length} layers, more than ${N.layers}`);let[a,i]=t.canvas||[];if(!(a>0&&i>0&&a<=N.canvas&&i<=N.canvas))throw tt(a>N.canvas||i>N.canvas?"too-large":"invalid",`this model's canvas ${a} x ${i} is out of range`);for(let y of t.layers)for(let m of[y.texture,...y.frames||[],y.mask,y.talk,y.brow_tex])if(m!==void 0&&!Ne.test(m))throw tt("invalid",`layer ${y.id}: "${m}" is not an image path of the package`);for(let[y,m]of Object.entries(t.files||{}))if(!y.startsWith("x-")&&(typeof m!="string"||!Yt.test(m)))throw tt("invalid",`files.${y}: "${m}" is not a path in the package`);let o=t.layers.map(({label:y,expression:m,...d})=>({...d,depth:d.depth??0,name:y?Ut(y,"en",d.id):d.id,...m?{param:m}:{}})),n;if(t.tuning){let{hair_front:y,hair_back:m,...d}=t.tuning;n={...d,...y===void 0?{}:{hairFront:y},...m===void 0?{}:{hairBack:m}}}let s=t.profile,r=(h=t.meta)==null?void 0:h.watermark;return{format:t.format,version:t.version,name:t.name,canvas:t.canvas,anchors:t.anchors,layers:o,rig:t.rig,tuning:n,profile:s&&{id:s.id,label:"",class:{input:{facing:s.facing,glasses:s.glasses}}},expressions:(t.expressions||[]).map(y=>({id:y.id,label:Ut(y.label,e,y.id),labels:y.label,...y.hotkey?{key:y.hotkey}:{}})),keyforms:(c=t.files)==null?void 0:c.keyforms,watermark:(r==null?void 0:r.kind)==="livliv"?"LivLiv":(r==null?void 0:r.kind)==="text"?r.text??null:null,meta:t.meta,files:t.files}}function ce(){return typeof navigator<"u"&&navigator.language||"en"}function Ut(t,e,a){if(!t)return a;let i=Object.keys(t),o=h=>i.find(c=>c.toLowerCase()===h.toLowerCase()),n=e||"en",s=n.split("-")[0].toLowerCase(),r=s==="zh"&&/-(hant|tw|hk|mo)\b/i.test(n);for(let h of[n,...s==="zh"?[r?"zh-Hant":"zh-Hans"]:[],s,...r?["zh"]:[],"en","zh"]){let c=o(h);if(c&&t[c])return t[c]}return i.length?t[i[0]]:a}function ue(t){return/[぀-ヿ]/.test(t)?"ja":/[가-힯]/.test(t)?"ko":/[一-鿿]/.test(t)?"zh":"en"}var zt={nod:.95,shake:1.05,tilt:1.8,hop:.65,shy:2.4},Ce=(t,e)=>U(0,.18,t)*(1-U(e-.22,e,t));function We(t,e){let a=zt[t],i=Ce(e,a),o={},n=0;return t==="nod"&&(o.angleY=-(e<.45?11*Math.sin(Math.PI*e/.45):6*Math.sin(Math.PI*Math.min(e-.45,.45)/.45))*i),t==="shake"&&(o.angleX=13*Math.sin(2*Math.PI*e/.5)*i,o.bodyX=o.angleX*.15),t==="tilt"&&(o.angleZ=11*i,o.angleX=3*i,o.angleY=2*i),t==="hop"&&(n=e<.2?-.025*Math.sin(Math.PI*e/.2):e<.6?.04*Math.sin(Math.PI*(e-.2)/.4):0,o.angleY=e>.2&&e<.6?5*Math.sin(Math.PI*(e-.2)/.4)*i:0),t==="shy"&&(o.angleY=-12*i,o.angleX=9*i,o.angleZ=-4*i,o.eyeBallX=.7*i,o.eyeBallY=-.5*i),{offsets:o,x:0,y:n}}var De={eyeLOpen:0,eyeROpen:0,angleY:-11,angleZ:5,angleX:0,mouthOpen:0,smile:0,eyeBallX:0,eyeBallY:0},Ye=class{playing=[];away=!1;auto=!1;awayW=0;off={};y=0;play(t){if(t==="away")this.setAway(!this.away);else{for(let e of this.playing)e.id===t&&e.out<0&&(e.out=0);this.playing.push({id:t,t:0,out:-1})}}setAway(t,e=!1){this.away=t,this.auto=t&&e}get busy(){return this.playing.length>0||this.awayW>0}update(t){let e=this.off;for(let a of Object.keys(e))delete e[a];this.y=0;for(let a of this.playing){a.t+=t,a.out>=0&&(a.out+=t);let i=We(a.id,Math.min(a.t,zt[a.id])),o=a.out<0?1:1-U(0,.15,a.out);for(let[n,s]of Object.entries(i.offsets))e[n]=(e[n]??0)+s*o;this.y+=i.y*o}return this.playing=this.playing.filter(a=>a.t<zt[a.id]&&a.out<.15),this.awayW+=(+!!this.away-this.awayW)*Math.min(1,t*(this.away?2.2:4)),this.awayW<.002&&!this.away&&(this.awayW=0),e}awayPose(t){return{...De,breath:.5+.5*Math.sin(t*1.15)}}},ct=(t,e,a)=>{let i=Math.min(1,Math.max(0,(a-t)/(e-t)));return i*i*(3-2*i)},ut=(t,e,a)=>Math.max(e,Math.min(a,t)),Ft=(t,e,a)=>{let i=Math.abs(t);return i<=e?t:Math.sign(t)*(e+(a-e)*Math.tanh((i-e)/(a-e)))},Lt=(t,e,a,i)=>t<0||t>e+a+i?0:t<e?ct(0,e,t):1-ct(e+a,e+a+i,t);function le(t,e){let a=s=>{let r=Math.sin(s*127.1+e*311.7)*43758.5453;return r-Math.floor(r)},i=Math.floor(t),o=t-i,n=o*o*(3-2*o);return(a(i)*(1-n)+a(i+1)*n)*2-1}var lt=(t,e)=>le(t,e)*.7+le(t*2.3,e+17)*.3;function ze(t,e){if(e<=t[0][0])return t[0][1];let a=t.length-1;if(e>=t[a][0])return t[a][1];let i=0;for(;e>t[i+1][0];)i++;let o=c=>c<=0||c>=a?0:(t[c+1][1]-t[c-1][1])/(t[c+1][0]-t[c-1][0]),n=t[i+1][0]-t[i][0],s=(e-t[i][0])/n,r=s*s,h=r*s;return(2*h-3*r+1)*t[i][1]+(h-2*r+s)*o(i)*n+(-2*h+3*r)*t[i+1][1]+(h-r)*o(i+1)*n}var $t={glance:{dur:4,tracks:{eyeBallX:[[0,0],[.15,.8],[2.5,.75],[2.8,0]],eyeBallY:[[0,0],[.15,.25],[2.5,.2],[2.8,0]],angleX:[[0,0],[.6,11],[2.5,10],[3.4,0]],angleY:[[0,0],[.6,4],[2.5,3],[3.4,0]],angleZ:[[0,0],[.7,-4],[2.5,-3],[3.4,0]],bodyX:[[0,0],[1,2],[2.6,1.5],[3.8,0]],brow:[[0,0],[.4,.25],[2.5,.2],[3.2,0]],breath:[[0,.1],[.6,.7],[2.6,.6],[3.6,0],[4,.15]]}},lookAround:{dur:5,tracks:{eyeBallX:[[0,0],[.2,-.8],[1.4,-.75],[1.7,.1],[2,.8],[3.2,.75],[3.5,0]],angleX:[[0,0],[.7,-15],[1.5,-14],[2.4,15],[3.3,14],[4.2,0]],angleY:[[0,0],[.8,3],[2.4,3],[4.2,0]],angleZ:[[0,0],[.8,3],[1.7,0],[2.5,-3],[4.2,0]],bodyX:[[0,0],[1,-3],[2.7,3],[4.4,0]],brow:[[0,0],[.5,.3],[3.4,.25],[4.2,0]],breath:[[0,.2],[.6,.8],[3.4,.7],[4.4,0],[5,.1]]}},sway:{dur:6,tracks:{bodyZ:[[0,0],[1.5,3.5],[3,-3.5],[4.5,3],[6,0]],bodyX:[[0,0],[1.5,2],[3,-2],[4.5,1.5],[6,0]],angleZ:[[0,0],[1.6,-7],[3.1,7],[4.6,-6],[6,0]],angleX:[[0,0],[1.6,4],[3.1,-4],[4.6,3],[6,0]],eyeBallX:[[0,0],[1.6,-.25],[3.1,.25],[4.6,-.2],[6,0]],eye:[[0,1],[.8,.88],[5.2,.88],[6,1]],breath:[[0,0],[.75,1],[1.5,0],[2.25,1],[3,0],[3.75,1],[4.5,0],[5.25,.8],[6,0]]}},think:{dur:4.4,tracks:{eyeBallX:[[0,0],[.3,-.6],[3.4,-.55],[3.8,0]],eyeBallY:[[0,0],[.3,.6],[3.4,.55],[3.8,0]],angleX:[[0,0],[.8,-9],[3.4,-8],[4.2,0]],angleY:[[0,0],[.8,6],[3.4,5],[4.2,0]],angleZ:[[0,0],[.9,6],[3.4,5],[4.2,0]],brow:[[0,0],[.6,.35],[3.4,.3],[4.2,0]],eye:[[0,1],[.6,.92],[3.4,.92],[4,1]]}},lookDown:{dur:2.4,tracks:{eyeBallY:[[0,0],[.2,-.85],[1.4,-.8],[1.65,0]],eyeBallX:[[0,0],[.2,-.1],[1.4,-.1],[1.65,0]],angleY:[[0,0],[.45,-8],[1.4,-7],[1.9,1],[2.4,0]],angleZ:[[0,0],[.5,2],[1.5,2],[2.4,0]],eye:[[0,1],[.3,.8],[1.4,.8],[1.65,1]]}}},Dt={angleX:[55,.72],angleY:[55,.72],angleZ:[45,.75],bodyX:[14,.9],bodyZ:[12,.9]},Ze={wander:1,look:1,moves:1,bodyTurn:0,bodyTilt:0,pointer:"attend",smile:.4},he={yaw:9,yawKnee:10,yawCap:13,pitch:5,pitchKnee:6,pitchCap:10,roll:2,rollKnee:8,rollCap:12,lean:0,bodyTurn:1.5,eyeX:1,eyeY:.8,eyeXCap:.78,eyeYCap:.55,eyeKnee:.7,hold:2.2};function Ve(t,e,a,i,o,n,s){var _;let r=(_=e.model)==null?void 0:_.anchors.head,[h,c,y,m,d]=e.lastView,f=!!r&&d>1,p=f?(r.cx*h+y+1)/2:.5,g=f?(r.cy*c+m+1)/2:.3,x=f?Math.abs(r.rx*h)/2:.12,b=f?Math.abs(r.ry*c)/2:.1,k=a/Math.max(1,o),w=i/Math.max(1,n);t.pointer={x:ut((k-p)*2,-1,1),y:ut(-(w-g)*1.6,-1,1),d:Math.hypot((k-p)/x,(w-g)/b),on:s}}var He=class{nextBlink=2;blinkT=-1;blinkAt=-99;look={x:0,y:0};blinkRate=1;nextSaccade=1;gaze={x:0,y:0};busy=!1;moves=1;style={...Ze};shown={x:0,z:0};pointer={x:0,y:0,d:99,on:!1};tracked=!1;faceFree=!0;smiling=!1;att={px:0,py:0,on:!1,moved:-99,speed:0,engaged:!1,since:0,x:0,y:0,slow:{x:0,y:0},soft:0,side:1,notice:-99,back:-99,smile:-99,smiled:-99,jitter:{x:0,y:0}};fol={x:0,z:0,x2:0,z2:0};move=null;nextMove=6;last="";s=Object.fromEntries(Object.keys(Dt).map(t=>[t,{x:0,v:0}]));aim=null;breathPhase=0;breathPeriod=3.8;double=!1;seed=Math.random()*100;breath(t){this.breathPhase+=t/this.breathPeriod,this.breathPhase>=1&&(--this.breathPhase,this.breathPeriod=3.2+Math.random()*1.4);let e=this.breathPhase;return e<.4?ct(0,.4,e):e<.88?1-ct(.4,.88,e):0}apply(t,e,a){a=a>0?Math.min(a,.1):0;let i=this.style,o=i.pointer==="attend"&&!this.tracked;o&&this.attend(e,a);let n=this.busy||o&&this.att.engaged;if(this.move)this.move.t+=a,n&&(this.move.fade=Math.max(0,this.move.fade-a/.4)),(this.move.t>=$t[this.move.id].dur||this.move.fade<=0)&&(this.move=null);else if(n)this.nextMove=Math.max(this.nextMove,e+3);else if(this.moves>0&&e>this.nextMove){let v=Object.keys($t).filter(R=>R!==this.last),T=v[Math.floor(Math.random()*v.length)];this.move={id:T,t:0,side:Math.random()<.5?-1:1,fade:1},this.last=T,this.nextMove=e+$t[T].dur+10+Math.random()*10}let s=this.move,r=s?$t[s.id]:null,h=s?s.fade*ct(0,.15,s.t)*(1-ct(r.dur-.25,r.dur,s.t)):0,c=(v,T=0)=>{let R=r==null?void 0:r.tracks[v];return R?T+(ze(R,s.t)*(v==="angleX"||v==="angleZ"||v==="bodyX"||v==="bodyZ"||v==="eyeBallX"?s.side:1)-T)*h*this.moves*(v.startsWith("angle")||v.startsWith("body")?i.moves:1):T},y=1;if(this.blinkT<0&&e>this.nextBlink&&(this.blinkT=0,this.blinkAt=e),this.blinkT>=0){this.blinkT+=a;let v=this.blinkT/.075;y=ut(v<1?1-v:v<2.6?(v-1)/1.6:1,0,1),v>=2.6&&(this.blinkT=-1,!this.double&&Math.random()<.18?(this.double=!0,this.nextBlink=e+.08):(this.double=!1,this.nextBlink=e+(1.8+Math.random()*3.8)/Math.max(.2,this.blinkRate)))}let m=ut(c("eye",1),0,1)*y;t.eyeLOpen=t.eyeROpen=o?m*(1-.16*this.att.soft):m;let d=this.seed,f=this.look,p=i.look,g=i.wander,x,b,k;if(o){let v=this.att,T=he;e>this.nextSaccade&&(v.jitter={x:(Math.random()-.5)*.2,y:(Math.random()-.5)*.16},this.nextSaccade=e+.6+Math.random()*1.6),this.gaze={x:T.eyeX*v.x+v.jitter.x,y:T.eyeY*v.y+v.jitter.y};let R=this.gaze.x+c("eyeBallX"),P=this.gaze.y+c("eyeBallY"),E=Math.hypot(R/T.eyeXCap,P/T.eyeYCap),L=E>T.eyeKnee?Ft(E,T.eyeKnee,1)/E:1;x=R*L,b=P*L;let O=v.slow;Math.hypot(x-O.x,b-O.y)>.5&&(this.blinkT<0&&e-this.blinkAt>1.2&&(this.nextBlink=Math.min(this.nextBlink,e)),O.x=x,O.y=b),O.x+=(x-O.x)*Math.min(1,a/.35),O.y+=(b-O.y)*Math.min(1,a/.35);let S=this.moves>0?3*Lt(e-v.notice,.12,.15,.5)-2.5*Lt(e-v.back,.15,.1,.45):0;k={angleX:Ft(v.x*T.yaw*p+lt(e*.17,d)*4*g+this.gaze.x*2+c("angleX"),T.yawKnee,T.yawCap),angleY:Ft(v.y*T.pitch*p+lt(e*.13,d+1)*3*g+this.gaze.y*2+S+c("angleY"),T.pitchKnee,T.pitchCap),angleZ:Ft(v.x*T.roll*p+v.side*3*v.soft+lt(e*.11,d+2)*5*g+c("angleZ"),T.rollKnee,T.rollCap),bodyX:v.x*T.bodyTurn*p+lt(e*.09,d+3)*3*g+c("bodyX"),bodyZ:v.x*T.lean*p+lt(e*.08,d+4)*2.5*g+c("bodyZ")}}else e>this.nextSaccade&&(this.gaze={x:this.look.x+(Math.random()-.5)*.25,y:this.look.y*.8+(Math.random()-.5)*.2},this.nextSaccade=e+.6+Math.random()*1.6),x=ut(this.gaze.x*1.2+c("eyeBallX"),-1,1),b=ut(this.gaze.y+c("eyeBallY"),-1,1),k={angleX:f.x*20*p+lt(e*.17,d)*7*g+this.gaze.x*5+c("angleX"),angleY:f.y*13*p+lt(e*.13,d+1)*4*g+this.gaze.y*3+c("angleY"),angleZ:-f.x*4*p+lt(e*.11,d+2)*6*g+c("angleZ"),bodyX:f.x*4*p+lt(e*.09,d+3)*3*g+c("bodyX"),bodyZ:lt(e*.08,d+4)*2.5*g+c("bodyZ")};t.eyeBallX+=(x-t.eyeBallX)*Math.min(1,a*18),t.eyeBallY+=(b-t.eyeBallY)*Math.min(1,a*18);let w=Math.max(1,Math.ceil(a/(1/120))),_=this.aim??={...k};for(let v of Object.keys(Dt)){let[T,R]=Dt[v],P=2*Math.sqrt(T)*R,E=this.s[v];for(let L=0;L<w;L++)_[v]+=(k[v]-_[v])*Math.min(1,a/w/.12),E.v+=(T*(_[v]-E.x)-P*E.v)*(a/w),E.x+=E.v*(a/w);t[v]=E.x}let l=this.fol,u=Math.min(1,a/.12);l.x+=(i.bodyTurn*this.shown.x-l.x)*u,l.x2+=(l.x-l.x2)*u,l.z+=(i.bodyTilt*this.shown.z-l.z)*u,l.z2+=(l.z-l.z2)*u,(i.bodyTurn||i.bodyTilt)&&(t.bodyX=ut(t.bodyX+l.x2,-10,10),t.bodyZ=ut(t.bodyZ+l.z2,-10,10)),t.breath=ut(c("breath",this.breath(a)),0,1);let A=(o?this.attendBrow(e):f.y>.4?.5:0)-(1-y)*.15+c("brow");t.browLY+=(A-t.browLY)*Math.min(1,a*10),t.browRY=t.browLY,o?(t.smile=+(e>=this.att.smile&&e<this.att.smile+1.6),this.smiling=t.smile>0):this.smiling&&=(t.smile=0,!1)}attend(t,e){let a=this.att,i=this.pointer;if(i.on&&!a.on&&(a.notice=t,a.moved=t,a.px=i.x,a.py=i.y,a.side=Math.random()<.5?-1:1),i.on){let h=Math.hypot(i.x-a.px,i.y-a.py);a.speed+=(h/Math.max(e,.001)-a.speed)*Math.min(1,e/.15),h>.003&&(a.moved=t),a.px=i.x,a.py=i.y}else a.speed*=Math.max(0,1-e/.15);a.on=i.on;let o=i.on&&i.d<1,n=i.on&&(o||!!i.keep||t-a.moved<he.hold);n!==a.engaged&&(!n&&t-a.since>.8&&(a.back=t,this.nextMove=Math.max(this.nextMove,t+6)),a.since=t,a.engaged=n);let s=this.style.smile??0;o&&t-a.moved>1.2&&s>0&&this.faceFree&&!this.busy&&t-a.smiled>25&&t>a.smile+1.6&&((a.smiled<0||Math.random()<s)&&(a.smile=t),a.smiled=t);let r=t>=a.smile&&t<a.smile+1.6?0:Math.max(o&&t-a.moved>.5?1:0,Lt(t-a.back,.2,.6,.6));a.soft+=(r-a.soft)*Math.min(1,e/.25),a.x=n?i.x:0,a.y=n?i.y:0}attendBrow(t){let e=this.att,a=this.pointer,i=a.on&&t-e.moved<.3?1-ct(1,2.2,a.d):0;return Math.min(.7,.4*ct(.35,.9,e.y)+.3*ct(1.5,5,e.speed)+.15*i+.45*Lt(t-e.notice,.08,.25,.35)+.2*Lt(t-e.back,.15,.3,.5)+.12*e.soft)}},Ge=["angleX","angleY","angleZ","eyeLOpen","eyeROpen","eyeBallX","eyeBallY","browLY","browRY","bodyX","bodyZ","breath"],de=(t,e,a)=>Math.min(a,Math.max(e,t)),Je=class{lv=new He;P=kt();turn={x:0,y:0};held=!1;constructor(){typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches&&(this.lv.moves=0)}apply(t,e,a,i){let o=this.lv;o.busy=i.busy,o.tracked=i.tracked,o.faceFree=i.faceFree,o.look=this.turn,o.apply(this.P,e,a);for(let n of Ge)t[n]=this.P[n];t.smile=Math.max(t.smile,this.P.smile)}shown(t){this.lv.shown.x=t.angleX,this.lv.shown.z=t.angleZ}pointer(t,e,a,i,o,n){this.held||(Ve(this.lv,t,e,a,i,o,n),n&&(this.turn={x:de((e/Math.max(1,i)-.5)*2,-1,1),y:de(-(a/Math.max(1,o)-.3)*1.6,-1,1)}))}leave(){this.held||(this.lv.pointer.on=!1),this.turn={x:0,y:0}}lookAt(t,e,a,i,o){this.held=!1,e===null?(this.lv.pointer={...this.lv.pointer,on:!1,keep:!1},this.turn={x:0,y:0}):(this.pointer(t,(e+1)/2*i,(1-a)/2*o,i,o,!0),this.lv.pointer.keep=!0,this.held=!0,this.turn={x:e,y:a})}blink(t){this.lv.nextBlink=Math.min(this.lv.nextBlink,t)}},Zt=new WeakSet,Rt=new WeakMap;function qe(t,e){if(!e||Zt.has(t)||Rt.has(t))return;let a=setTimeout(()=>{var i;Rt.delete(t),Zt.add(t),(i=e.getExtension("WEBGL_lose_context"))==null||i.loseContext()});Rt.set(t,()=>clearTimeout(a))}function me(t){var e;if((e=Rt.get(t))==null||e(),Rt.delete(t),Zt.has(t))throw new V("released","LivLiv: this canvas gave up its WebGL context with dispose({ release: true }): use a new canvas")}var Tt=(t,e,a)=>Math.min(a,Math.max(e,t)),Ot=t=>new DOMException(`LivLiv: ${t}`,"AbortError"),Xt=()=>new V("context-lost","LivLiv: this canvas has lost its WebGL context: use a new canvas and a new player");async function ye(t,e,a=i=>i){let i=t.headers.get("content-encoding")?0:Number(t.headers.get("content-length"))||0;if(!t.body)return t.blob();let o=t.body.getReader(),n=[],s=0;for(;;){let{done:r,value:h}=await o.read();if(r)break;n.push(h),s+=h.byteLength,i&&e.progress(a(Math.min(1,s/i)))}return new Blob(n)}var Ke=kt(),Qe=Object.keys(ft),pe=class{canvas;params=kt();idle;followPointer;view={x:0,y:0,zoom:1,head:!1};lang;onContextLost;info=null;disposed=!1;idler=new Je;was={tracked:!1,mouth:0};actions=new Ye;drivers=[];expr={};smile=0;raf=0;last=0;visible=!0;io;queue=Promise.resolve();lost=!1;running=null;posterOver=null;frame;constructor(t,e,a){this.canvas=t,this.idle=a.idle??!0,this.followPointer=a.followPointer??"page",this.lang=a.lang||ce(),this.frame={params:e,dt:0,time:0,tracked:!1,move:{x:0,y:0,s:1},add(i){for(let[o,n]of Object.entries(i))n&&(e[o]=Tt(e[o]+n,ft[o][0],ft[o][1]))}},addEventListener("pointermove",this.onMove),document.addEventListener("pointerleave",this.onLeave),t.addEventListener("webglcontextlost",this.onLost),typeof IntersectionObserver<"u"&&(this.io=new IntersectionObserver(i=>{this.visible=i[i.length-1].isIntersecting}),this.io.observe(t)),(a.autoplay??!0)&&this.play()}get contextLost(){var t;return this.lost||!!((t=this.gl)!=null&&t.isContextLost())}get model(){return this.info}get expressions(){var t;return((t=this.info)==null?void 0:t.expressions)??[]}get playing(){return this.raf!==0}start({signal:t,onProgress:e,poster:a},i){var g;let o,n,s=new Promise((x,b)=>{o=x,n=b}),r=x=>{(x==null?void 0:x.name)==="AbortError"&&s.catch(()=>{}),n(x)};if(t!=null&&t.aborted)return r(t.reason),s;if(this.disposed)return r(Ot("the player was disposed")),s;if(this.contextLost)return r(Xt()),s;(g=this.running)==null||g.abort(Ot("a newer load took its place"));let h=this.running=new AbortController,c=()=>h.abort(t.reason);t==null||t.addEventListener("abort",c,{once:!0}),this.setPoster(a);let y=x=>{try{e==null||e(x)}catch(b){console.error(b)}},m=-1,d=!1,f={signal:h.signal,progress(x){x>m&&!d&&(m=x,y({step:"download",progress:x}))},build(){d||(m>=0&&m<1&&y({step:"download",progress:1}),d=!0,y({step:"build"}))}},p=()=>{t==null||t.removeEventListener("abort",c),this.running===h&&(this.running=null)};return i(f).then(x=>{p(),o(x)},x=>{let b=this.running===h;p(),b&&this.setPoster(),r(h.signal.aborted?h.signal.reason:x)}),s}setPoster(t){let e=this.canvas.style;if(this.posterOver){for(let[i,o]of Object.entries(this.posterOver))e.setProperty(i,o);this.posterOver=null}if(!t||this.info)return;let a={"background-image":`url(${JSON.stringify(String(t))})`,"background-position":"center","background-size":"contain","background-repeat":"no-repeat"};this.posterOver=Object.fromEntries(Object.keys(a).map(i=>[i,e.getPropertyValue(i)]));for(let[i,o]of Object.entries(a))e.setProperty(i,o)}inTurn(t){let e=this.queue.then(t);return this.queue=e.catch(()=>{}),e}neutral(){this.expr={},this.smile=0}setExpression(t,e=1){if(t!==null&&!this.expressions.some(i=>i.id===t))return!1;let a=Tt(e,0,1);return this.smile=t==="smile"?a:0,this.expr=t===null||t==="smile"?{}:{[t]:a},!0}act(t){if(t==="away")throw TypeError("LivLiv: act('away') is setAway(true) now");this.actions.play(t)}setAway(t){this.actions.setAway(t)}lookAt(t,e=0){this.idler.lookAt(this.seen(),t===null?null:Tt(t,-1,1),Tt(e,-1,1),this.canvas.clientWidth,this.canvas.clientHeight)}blink(){this.idler.blink(this.clock)}use(t){var e;return this.disposed?((e=t.dispose)==null||e.call(t),()=>{}):(this.drivers.push(t),this.drivers.sort((a,i)=>(a.order??0)-(i.order??0)),()=>{var i;let a=this.drivers.indexOf(t);a>=0&&(this.drivers.splice(a,1),(i=t.dispose)==null||i.call(t))})}play(){if(this.raf||this.disposed)return;this.last=performance.now();let t=e=>{this.raf=requestAnimationFrame(t);let a=Math.min(.05,(e-this.last)/1e3);this.last=e,this.visible&&this.draw(a)};this.raf=requestAnimationFrame(t)}pause(){cancelAnimationFrame(this.raf),this.raf=0}resize(){this.draw(0)}snapshot(){return this.draw(0),this.canvas.toDataURL("image/png")}dispose({release:t=!1}={}){let e=this.gl;this.stop(),t&&qe(this.canvas,e)}stop(){var t,e,a;if(!this.disposed){this.pause(),this.disposed=!0,(t=this.running)==null||t.abort(Ot("the player was disposed")),this.setPoster(),removeEventListener("pointermove",this.onMove),document.removeEventListener("pointerleave",this.onLeave),this.canvas.removeEventListener("webglcontextlost",this.onLost),(e=this.io)==null||e.disconnect();for(let i of this.drivers.splice(0))(a=i.dispose)==null||a.call(i);this.free(),this.info=null}}draw(t){if(!this.drawable||this.disposed||this.contextLost)return;let e=this.frame,a=e.params,i=this.clock,o=this.shownExpr,n=this.actions;this.idler.shown(a),Object.assign(a,this.params),this.idle&&this.idler.apply(a,i,t,{busy:n.busy||this.was.mouth>.05,tracked:this.was.tracked,faceFree:!this.smile&&!Object.values(o).some(s=>s>.02)}),Object.assign(e,{dt:t,time:i,tracked:!1}),Object.assign(e.move,{x:0,y:0,s:1});for(let s of this.drivers)s.update(e,this);if(this.was={tracked:e.tracked,mouth:a.mouthOpen},e.add(n.update(t)),this.smile&&(a.smile=Math.max(a.smile,this.smile)),n.awayW)for(let[s,r]of Object.entries(n.awayPose(i)))a[s]+=(r-a[s])*n.awayW;for(let s of Qe){let r=+a[s];a[s]=r===r?Tt(r,ft[s][0],ft[s][1]):Ke[s]}for(let s of Object.keys(this.expr))s in o||(o[s]=0);for(let s of Object.keys(o))o[s]+=((this.expr[s]??0)*(1-n.awayW)-o[s])*Math.min(1,t*8);this.show(t),this.posterOver&&this.setPoster()}onMove=t=>{if(!this.followPointer)return;let e=this.canvas.getBoundingClientRect(),a=!(t.clientX<e.left||t.clientX>e.right||t.clientY<e.top||t.clientY>e.bottom);this.idler.pointer(this.seen(),t.clientX-e.left,t.clientY-e.top,e.width,e.height,this.followPointer==="page"||a)};onLeave=()=>this.idler.leave();onLost=()=>{var t,e;this.lost=!0,(t=this.running)==null||t.abort(Xt()),(e=this.onContextLost)==null||e.call(this)}};var Nt=()=>({yaw:.27,pitch:.22,roll:.5,bulge:.6,hair:{front:[140,11,.022,70,7],back:[48,5.5,.06,24,3.5]},hair_limit:.25,wind:1,breath:1,sway:1,brow:.06,body:{yaw:.35,roll:.3,breath:1,bust:0}}),ge=()=>({turn:1,nod:1,hair:1,blink:1,expr:1,mouth:1,breath:1,gaze:1}),ta=`#version 300 es
2
+ in vec2 aPos; in vec2 aUv; uniform vec4 uView; out vec2 vUv;
3
+ void main(){ vUv=aUv; vec2 p=aPos*uView.xy+uView.zw; gl_Position=vec4(p.x,-p.y,0.,1.); }`,ea=`#version 300 es
4
+ precision mediump float; in vec2 vUv; uniform sampler2D uTex; uniform float uAlpha; uniform float uCut; out vec4 o;
5
+ uniform int uMode; uniform sampler2D uMask; uniform highp ivec2 uMaskOff; uniform vec4 uMaskSel; uniform float uSoft;
6
+ void main(){ vec4 c=texture(uTex,vUv); if(c.a<uCut) discard;
7
+ if(uMode==1){ o=vec4(c.a); return; }
8
+ if(uMode==2){ highp ivec2 q=ivec2(gl_FragCoord.xy)-uMaskOff, n=textureSize(uMask,0);
9
+ float m=all(greaterThanEqual(q,ivec2(0)))&&all(lessThan(q,n))?dot(texelFetch(uMask,q,0),uMaskSel):0.;
10
+ c*=mix(step(.5,m),m,uSoft); }
11
+ o=c*uAlpha; }`,we=[.12,.5],aa=.04,ia=.055,sa=.3,ra=.65,oa=.35,na=.4,Ht=(t,e,a)=>{if(a<=t[0])return e[0];for(let i=1;i<t.length;i++)if(a<=t[i])return e[i-1]+(e[i]-e[i-1])*(a-t[i-1])/(t[i]-t[i-1]);return e[e.length-1]},Ct=(t,e)=>1-U(0,(t[2]-t[0])*.45,Math.max(t[0]-e,e-t[2],0)),Ae=t=>(t[3]-t[1])*1.6+6;function la(t,e,a,i){if(i<t[1])return Ct(t,a)*(1-U(0,Ae(t),t[1]-i));let o=Ht(e.x,e.bottom,a);return i<=o?Ct(t,a):Ct(t,a)*(1-U(o,Ht(e.x,e.lid,a),i))}function ha(t,e){var n;let a=e,i=e,o=!1;return(n=t.brows)==null||n.forEach((s,r)=>{var c;let h=(c=t.brow_lines)==null?void 0:c[r];s&&h&&(o=!0,a=Math.min(a,.6*Ae(s)),h.x.forEach((y,m)=>{i=Math.min(i,.6*(h.lid[m]-h.bottom[m])/Math.max(.001,Ct(s,y)))}))}),o?[a,i]:[0,0]}var bt=()=>({x:0,y:0,vx:0,vy:0}),be=[.5,.85],da=class{gl;canvas;model;layers=[];byId=new Map;params=kt();prog;uView;uAlpha;uTex;uCut;uMode;uMaskOff;uMaskSel;uSoft;maskFb=null;maskTex=null;maskSize=[0,0];chains={front:[bt(),bt()],back:[bt(),bt()],side:[bt(),bt()]};lastHead={x:0,y:0,roll:0};drive={x:0,y:0,vx:0,vy:0,ax:0,ay:0,started:!1};body={yaw:0,roll:0};bust={x:0,y:0,vx:0,vy:0,px:0,py:0};time=0;background=[0,0,0,0];zoom=1;panY=0;view={x:0,y:0,s:1};move={x:0,y:0,s:1};cutBottom=!1;maxDpr=2;size=null;physicsScale=1;hidden=new Set;tuning=ge();rig=Nt();expr={};smileShown=0;mouthFrame=0;mouthW=[1,0,0];mouthHeld=1;mouthAmp=0;mouthShape="";vis={};frameKind=["closed","half","open"];frameJaw=[0,0,0];procJaw=.015;chinFollow=!0;chinNeck=.08;chinNeckX=[.2,.34];neckFollow=.2;neckFollowY=.6;neckFollowX=[.6,1.3];talkLeft=0;focusHead=!1;keys=[];kfPair=null;kfOff=!1;keyWeights=null;only=null;masks=!1;lidCurve=!0;irisLid=!0;irisDrop=.3;softIris=!0;irisNasal=!0;irisNasalNarrow=.7;nasal={};chainRuns=[];get chained(){return this.chainRuns.length>0}bodyHidden=!1;headHidden=!1;lastView=[1,1,0,0,1,1];constructor(t){this.canvas=t;let e=t.getContext("webgl2",{premultipliedAlpha:!0,alpha:!0,antialias:!0,preserveDrawingBuffer:!0,stencil:!0});if(!e)throw Error("this browser has no WebGL2");this.gl=e;let a=(o,n)=>{let s=e.createShader(o);if(e.shaderSource(s,n),e.compileShader(s),!e.getShaderParameter(s,e.COMPILE_STATUS))throw Error(e.getShaderInfoLog(s)||"shader");return s},i=e.createProgram();e.attachShader(i,a(e.VERTEX_SHADER,ta)),e.attachShader(i,a(e.FRAGMENT_SHADER,ea)),e.bindAttribLocation(i,0,"aPos"),e.bindAttribLocation(i,1,"aUv"),e.linkProgram(i),this.prog=i,this.uView=e.getUniformLocation(i,"uView"),this.uAlpha=e.getUniformLocation(i,"uAlpha"),this.uTex=e.getUniformLocation(i,"uTex"),this.uCut=e.getUniformLocation(i,"uCut"),this.uMode=e.getUniformLocation(i,"uMode"),this.uMaskOff=e.getUniformLocation(i,"uMaskOff"),this.uMaskSel=e.getUniformLocation(i,"uMaskSel"),this.uSoft=e.getUniformLocation(i,"uSoft"),e.useProgram(i),e.uniform1i(e.getUniformLocation(i,"uMask"),1)}async load(t,{png:e=!1,pack:a=!0,signal:i,onImage:o}={}){let{file:n,base:s,query:r}=Le(t),h=await fetch(n+(r?`?${r}`:""),{cache:"no-store",signal:i});if(!h.ok)throw Object.assign(Error(h.status===404?"model not found":`model.json ${h.status}`),{status:h.status});let c=await h.text();if(c.length>N.modelJson)throw tt("too-large",`model.json is larger than ${N.modelJson} bytes`);let y=It(JSON.parse(c)),m=y.tex;if(!m){let x=JSON.stringify(y.layers)+(h.headers.get("last-modified")||""),b=0;for(let k=0;k<x.length;k++)b=b*31+x.charCodeAt(k)|0;m=(b>>>0).toString(36)}let d=`?v=${m}${r?`&${r}`:""}`,f=y.keyforms?fetch(s+y.keyforms+d,{signal:i}).then(async x=>{let b=x.ok?await x.text():"";return b&&b.length<=N.keyforms?JSON.parse(b):void 0}).catch(()=>{}):void 0,p=e||!a?null:await ya(ma(t,m),i),g=x=>i?pa(s+x+d,i):Te(s+x+d);await this.loadModel(y,x=>{let b=p==null?void 0:p.get(x);return b?qt(b):g(x)},{png:e,keyforms:f,signal:i,onImage:o})}async loadModel(t,e,{png:a=!1,keyforms:i,signal:o,onImage:n}={}){var p;let s=It(t),r=0,h=0,c=g=>(n==null||n(++h,r),g),[y,m]=await Promise.all([Promise.all(s.layers.map(async g=>{let x=u=>(r++,e(g.webp&&!a?u.replace(/\.png$/,".webp"):u).then(c)),[b,k,w,_,l]=await Promise.all([x(g.texture),Promise.all((g.frames||[]).map(x)),g.mask?x(g.mask):void 0,g.talk?x(g.talk):void 0,g.brow_tex?x(g.brow_tex):void 0]);return{main:b,frames:k,mask:w,talk:_,brows:l}})),i]);if(o!=null&&o.aborted)throw o.reason;let d=Math.min(N.texture,((p=this.gl)==null?void 0:p.getParameter(this.gl.MAX_TEXTURE_SIZE))||N.texture),f=0;for(let g of y)for(let x of[g.main,...g.frames,g.mask,g.talk,g.brows]){if(!x)continue;let b=x.naturalWidth||x.width,k=x.naturalHeight||x.height;if(b>d||k>d||(f+=b*k)>N.texels)throw tt("too-large",`this model's images are too large (${b} x ${k}: ${d} px a side and ${N.texels} pixels in all at most)`)}this.install(s,y,m)}install(t,e,a){let i=this.gl,o={...this,drive:{...this.drive},chains:Object.fromEntries(Object.entries(this.chains).map(([s,r])=>[s,r.map(h=>({...h}))]))},n=[];for(let s=0;s<8&&i.getError();s++);try{this.build(t,e,a,n);for(let s=0,r;s<8&&(r=i.getError());s++)if(r===i.OUT_OF_MEMORY)throw tt("too-large","the GPU ran out of memory for this model")}catch(s){throw this.freeLayers(n),Object.assign(this,o),s}this.freeLayers(o.layers),this.freeMask()}build(t,e,a,i){var y,m,d,f;this.model=t,this.chainRuns=(((y=t.rig)==null?void 0:y.chains)||[]).map(ca);let o=t.layers.find(p=>p.role==="mouth");this.frameKind=((o==null?void 0:o.frames)||["","",""]).map((p,g)=>{var x;return((x=o==null?void 0:o.visemes)==null?void 0:x[g])||["closed","half","open"][g]||""});let n=t.anchors.jaw;this.frameJaw=this.frameKind.map(p=>n&&p!=="closed"&&(p!=="half"||n.open>0)&&n[p]||0);let s=this.procJaw>0?((m=t.rig)==null?void 0:m.jaw)??this.procJaw:0;if(n&&s>0&&!this.frameJaw.some(p=>p>0)){let p=t.anchors.face[3]-t.anchors.face[1],g={half:.45,open:1,round:.7,wide:.35};this.frameJaw=this.frameKind.map(x=>s*p*(g[x]??0))}this.vis={},this.frameKind.forEach((p,g)=>{(p==="round"||p==="wide"||p==="shut")&&(this.vis[p]=g)});let r=t.layers.findIndex(p=>p.group==="hair_front"),h=r>=0?{img:e[r].main,def:t.layers[r]}:void 0;t.layers.forEach((p,g)=>i.push(this.buildLayer(p,e[g].main,e[g].frames,e[g].mask,e[g].talk,e[g].brows,p.id==="brows"||p.role==="expr_brows"||p.brow_tex?h:void 0))),this.layers=i,this.byId=new Map(this.layers.map(p=>[p.def.id,p])),this.nasal={};let c=t.anchors.eyes;if(c&&c.length>=2){let p=c.reduce((g,x)=>g+(x[0]+x[2])/2,0)/c.length;t.layers.forEach((g,x)=>{var l;let b=(l=g.role)!=null&&l.startsWith("iris_")?g.role.slice(5):"",k=g.clip?t.layers.findIndex(u=>u.id===g.clip):-1,w=k>=0?e[k].mask:void 0;if(!b||!g.range||!w||this.nasal[b])return;let _=xa(e[x].main,g,w,t.layers[k],p>g.x+g.w/2?1:-1);_&&(this.nasal[b]=_)})}if(this.lidCurve&&ba(t))for(let p of["L","R"]){let g=t.layers.findIndex(b=>b.role===`lid_${p}`),x=g>=0?va(e[g].main,t.layers[g]):null;if(x){for(let b of this.layers)if(b.def.role===`eye_${p}`||b.def.role===`iris_${p}`||b.def.role===`shine_${p}`){b.pivY=new Float32Array(b.rest.length/2);for(let k=0;k<b.pivY.length;k++)b.pivY[k]=x(b.rest[2*k]);b.pivC=x(b.def.x+b.def.w/2)}}}this.tuning={...ge(),...t.tuning||{}},this.rig={...Nt(),...t.rig||{},hair:{...Nt().hair,...((d=t.rig)==null?void 0:d.hair)||{}},body:{...Nt().body,...((f=t.rig)==null?void 0:f.body)||{}}},this.expr={},this.resetMouth(),this.talkLeft=0,this.cutBottom=t.anchors.bottom_y>=t.canvas[1]-4,this.resetPhysics(),this.keys=[],this.kfPair=null,a&&fa(a)?this.prepareKeyforms(a):a&&console.warn("LivLiv: keyforms.json is not one this player reads; the character plays on the rig alone")}prepareKeyforms(t){let e=new Map,a=s=>{let r=e.get(s);if(!r){let h=atob(s);r=new Uint8Array(h.length);for(let c=0;c<h.length;c++)r[c]=h.charCodeAt(c);e.set(s,r)}return r},i={params:this.params,body:{...this.body},bust:{...this.bust},mouthW:this.mouthW,smile:this.smileShown,chains:Object.values(this.chains).map(s=>s.map(r=>({...r})))},o=this.rig.body,n=this.tuning.turn;t.keys.forEach((s,r)=>{var y,m;let h={...kt(),[s.param]:s.value};this.params=h,this.body={yaw:h.bodyX+h.angleX*o.yaw*n,roll:h.bodyZ+h.angleZ*this.rig.body.roll*n};for(let d of Object.values(this.chains))for(let f of d)Object.assign(f,bt());Object.assign(this.bust,{x:0,y:0,vx:0,vy:0}),this.mouthW=[1,0,0],this.smileShown=0,this.kfOff=!0,this.deform(),this.kfOff=!1;for(let d of this.layers){let f=Object.hasOwn(s.fields,d.def.id)?d.def.id:d.def.group==="head"?"head":d.def.group.startsWith("hair")?"hair":d.def.group==="body"&&(w=>{var _;return!!s.fields[w]||!!((_=s.same)!=null&&_.includes(w))})("torso")?"torso":d.def.id,p=s.fields[f]??((y=s.same)!=null&&y.includes(f)?s.fields.head:void 0);if(d.kf||=[],!p){d.kf[r]=null;continue}let g=a(p),x=new Int16Array(g.buffer,g.byteOffset,g.byteLength>>1),b=(m=t.mask)!=null&&m[f]?a(t.mask[f]):void 0,k=new Float32Array(d.rest.length);for(let w=0;w<k.length;w+=2){let[_,l]=ga(x,t,d.rest[w],d.rest[w+1]),u=b?wa(b,t,d.rest[w],d.rest[w+1]):1;k[w]=(d.rest[w]+_-d.out[w])*u,k[w+1]=(d.rest[w+1]+l-d.out[w+1])*u}d.kf[r]=k}let c=s.param==="angleY";this.keys.push({param:s.param,value:s.value,scale:n*(c?this.tuning.nod:1)/(t.turn*(c?t.nod:1))})}),this.params=i.params,this.body=i.body,Object.assign(this.bust,i.bust),this.mouthW=i.mouthW,this.smileShown=i.smile,Object.values(this.chains).forEach((s,r)=>s.forEach((h,c)=>Object.assign(h,i.chains[r][c]))),this.kfPair=t.interp==="hermite"?this.keys.map(s=>this.keys.findIndex(r=>r.param===s.param&&s.param!=="diag"&&r.value===-s.value)):null}dispose(){this.freeLayers(this.layers),this.freeMask(),this.layers=[]}freeLayers(t){let e=this.gl;for(let a of t)e.deleteTexture(a.tex),a.frames.forEach(i=>e.deleteTexture(i)),a.mask&&e.deleteTexture(a.mask),a.talk&&e.deleteTexture(a.talk),a.browTex&&e.deleteTexture(a.browTex),e.deleteVertexArray(a.vao),e.deleteBuffer(a.pos),e.deleteBuffer(a.uvs),e.deleteBuffer(a.tris)}freeMask(){let t=this.gl;this.maskFb&&(t.deleteFramebuffer(this.maskFb),t.deleteTexture(this.maskTex),this.maskFb=this.maskTex=null,this.maskSize=[0,0])}texture(t){let e=this.gl,a=e.createTexture();e.bindTexture(e.TEXTURE_2D,a),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);try{e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t)}catch(i){throw e.deleteTexture(a),i}return e.generateMipmap(e.TEXTURE_2D),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),a}buildLayer(t,e,a,i,o,n,s){var Kt,Qt,te,ee;let r=this.gl,h=this.model.anchors,c=this.model.layers.some(F=>F.id==="brows"),[y,m]=this.model.canvas,d=Vt(y,m),f=Math.floor(t.x/d),p=Math.floor(t.y/d),g=Math.ceil((t.x+t.w)/d)-f,x=Math.ceil((t.y+t.h)/d)-p,b=Ma([e,...a],g,x,(t.x-f*d)/d,(t.y-p*d)/d,t.w/d,t.h/d),k=new Int32Array((g+1)*(x+1)).fill(-1),w=[],_=[],l=[],u=(F,j)=>{let Y=j*(g+1)+F;if(k[Y]<0){k[Y]=w.length/2;let nt=(f+F)*d,wt=(p+j)*d;w.push(nt,wt),_.push((nt-t.x)/t.w,(wt-t.y)/t.h)}return k[Y]};for(let F=0;F<x;F++)for(let j=0;j<g;j++){if(!b[F*g+j])continue;let Y=u(j,F),nt=u(j+1,F),wt=u(j,F+1),Bt=u(j+1,F+1);l.push(Y,nt,wt,nt,Bt,wt)}let A=w.length/2,v=new Float32Array(w),T=new Float32Array(A),R=new Float32Array(A),P=new Float32Array(A),E=new Float32Array(A),L=new Float32Array(A),O=new Int8Array(A).fill(-1),S=new Float32Array(A),M=new Float32Array(A).fill(1/0),B=new Float32Array(A),X=this.neckFollow>0&&t.group==="body"?new Float32Array(A):void 0,$=(Kt=this.model.rig)==null?void 0:Kt.neck,H=$&&$.twist>0&&t.group==="body"?new Float32Array(A):void 0,it=s&&(t.id==="brows"||t.role==="expr_brows")?xe(e,t,s.img,s.def,v,d):void 0,et=s&&n?xe(n,t,s.img,s.def,v,d):void 0,G=it||et?new Float32Array(5*A):void 0,K=h.face[2]-h.face[0],W=h.head,vt=h.neck_y-.1*W.ry,St=Math.max(1,h.bottom_y-vt);for(let F=0;F<A;F++){let j=v[2*F],Y=v[2*F+1],nt=Math.hypot((j-W.cx)/W.rx,(Y-W.cy)/W.ry);E[F]=t.group==="head"?t.depth:t.group==="hair_front"?t.depth*U(t.fall_end??1,t.fall??.55,nt):t.depth*U(t.fall_end??1,t.fall_end===void 0?.7:t.fall??.7,nt);let wt=1-U(h.neck_y+.05*W.ry,h.neck_y+1.1*W.ry,Y),Bt=Math.min(1,Math.max(0,(Y-vt)/St)),ae=U(0,.55,Bt),ie=U(.25,1,Bt)**1.3,at=U(.95,.7,nt)*(1-U(h.neck_y-.2*W.ry,h.neck_y+.3*W.ry,Y)),_t=U(h.hair_root_y+.25*W.ry,W.cy+.7*W.ry,Y);if(t.group==="head"?T[F]=1:t.group==="body"?T[F]=0:(T[F]=at+(1-at)*wt,R[F]=at*_t+(1-at)*ae,P[F]=at*_t*_t+(1-at)*ie,S[F]=at,t.group==="hair_inner"&&(T[F]*=.5,R[F]*=.35,P[F]*=.35)),G&&s){let z=5*F;G[z]=s.def.depth*U(1,s.def.fall??.55,nt),G[z+1]=at+(1-at)*wt,G[z+2]=at*_t+(1-at)*ae,G[z+3]=at*_t*_t+(1-at)*ie,G[z+4]=at}let se=t.group==="hair_side"||t.group==="hair_front",Be=this.chinFollow&&t.role==="mouth";if((t.id==="face"||t.role==="expr"||se||Be||t.role==="neck_shadow")&&h.jaw&&this.frameJaw.some(z=>z>0)){let z=U(h.jaw.top-.02*W.ry,h.jaw.chin,Y)*(se?1-U(h.jaw.chin,h.jaw.chin+.15*W.ry,Y):1),ot=1-U(.22*K,.5*K,Math.abs(j-W.cx));B[F]=z*ot}if(t.role==="neck_shadow"&&h.jaw){let z=1-U(h.jaw.chin,h.jaw.chin+sa*(h.face[3]-h.face[1]),Y);T[F]=z,B[F]*=z}if(this.chinFollow&&t.group==="body"&&h.jaw){let z=h.face[3]-h.face[1],ot=(1-U(h.jaw.chin,h.jaw.chin+this.chinNeck*z,Y))*(1-U(this.chinNeckX[0]*K,this.chinNeckX[1]*K,Math.abs(j-W.cx)));if(ot>0&&(T[F]=ot,this.frameJaw.some(dt=>dt>0))){let dt=U(h.jaw.top-.02*W.ry,h.jaw.chin,Y);B[F]=dt*(1-U(.22*K,.5*K,Math.abs(j-W.cx)))*ot}}if(X){let z=h.face[3]-h.face[1];X[F]=Math.max(0,this.neckFollow*(1-U(h.neck_y,h.neck_y+this.neckFollowY*z,Y))*(1-U(this.neckFollowX[0]*K,this.neckFollowX[1]*K,Math.abs(j-W.cx)))-T[F])}if(H&&$){let z=h.face[3]-h.face[1],ot=((Qt=h.jaw)==null?void 0:Qt.chin)??h.neck_y;H[F]=Math.max(0,$.twist*(1-U(ot,ot+($.reach??.45)*z,Y))*(1-U(this.chinNeckX[0]*K,this.chinNeckX[1]*K,Math.abs(j-W.cx)))-T[F])}!h.brows||t.group!=="head"||(t.role||"").startsWith("iris_")||c&&t.id!=="brows"||h.brows.forEach((z,ot)=>{var oe;let dt=(oe=h.brow_lines)==null?void 0:oe[ot];if(!z||!dt)return;let re=la(z,dt,j,Y);re>L[F]&&(L[F]=re,O[F]=ot,M[F]=dt.cap?Ht(dt.x,dt.cap,j):1/0)})}let I=(te=t.bones)!=null&&te.length?this.skinOf(t.bones,v):void 0;I&&!t.bones.every(F=>{var j;return((j=this.chainRuns.find(Y=>Y.def.id===F))==null?void 0:j.def.reach)!==void 0})&&(R.fill(0),P.fill(0)),t.rigid&&(R.fill(0),P.fill(0));let ht=G&&((ee=s==null?void 0:s.def.bones)!=null&&ee.length)?this.skinOf(s.def.bones,v):void 0;if(G&&ht)for(let F=0;F<A;F++)G[5*F+2]=0,G[5*F+3]=0;let Q=r.createVertexArray();r.bindVertexArray(Q);let st=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,st),r.bufferData(r.ARRAY_BUFFER,v,r.DYNAMIC_DRAW),r.enableVertexAttribArray(0),r.vertexAttribPointer(0,2,r.FLOAT,!1,0,0);let rt=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,rt),r.bufferData(r.ARRAY_BUFFER,new Float32Array(_),r.STATIC_DRAW),r.enableVertexAttribArray(1),r.vertexAttribPointer(1,2,r.FLOAT,!1,0,0);let Mt=r.createBuffer();r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,Mt);let Et=new Uint32Array(l);r.bufferData(r.ELEMENT_ARRAY_BUFFER,Et,r.STATIC_DRAW),r.bindVertexArray(null);let C=[],D=F=>{let j=this.texture(F);return C.push(j),j},Z,J,yt,pt,gt;try{Z=D(e),J=a.map(D),yt=i&&D(i),pt=o&&D(o),gt=n&&D(n)}catch(F){throw C.forEach(j=>r.deleteTexture(j)),r.deleteVertexArray(Q),r.deleteBuffer(st),r.deleteBuffer(rt),r.deleteBuffer(Mt),F}return{def:t,tex:Z,frames:J,mask:yt,talk:pt,browTex:gt,vao:Q,pos:st,uvs:rt,tris:Mt,count:l.length,rest:v,out:new Float32Array(v.length),tri:Et,tw:e.naturalWidth||e.width,th:e.naturalHeight||e.height,wHead:T,wPhys1:R,wPhys2:P,dep:E,wBrow:L,browSide:O,browCap:M,wFront:S,wJaw:B,wNeck:X,wTwist:H,fol:it,folB:et,alt:G,outB:et?new Float32Array(v.length):void 0,stencilRef:0,soft:0,maskCh:-1,skin:I,altSkin:ht}}skinOf(t,e){let a=t.map(s=>this.chainRuns.findIndex(r=>r.def.id===s)).filter(s=>s>=0);if(!a.length)return;let i=e.length/2,o=a.length,n={B:o,c:new Int16Array(i*o),seg:new Int16Array(i*o),t:new Float32Array(i*o),ux:new Float32Array(i*o),uy:new Float32Array(i*o),w:new Float32Array(i*o),sum:new Float32Array(i)};for(let s=0;s<i;s++){let r=e[2*s],h=e[2*s+1],c=0;a.forEach((d,f)=>{let p=this.chainRuns[d],g=p.R,x=g.length/2,b=1/0,k=0,w=0;for(let R=0;R<x-1;R++){let P=g[2*R],E=g[2*R+1],L=g[2*R+2]-P,O=g[2*R+3]-E,S=L*L+O*O||1,M=((r-P)*L+(h-E)*O)/S;R>0&&(M=Math.max(0,M)),R<x-2&&(M=Math.min(1,M));let B=P+L*M,X=E+O*M,$=Math.hypot(r-B,h-X);$<b&&(b=$,k=R,w=M)}let _=s*o+f,l=k,u=Math.min(1,w),A=g[2*l]+(g[2*l+2]-g[2*l])*u,v=g[2*l+1]+(g[2*l+3]-g[2*l+1])*u,T=p.def.sigma??40;n.c[_]=d,n.seg[_]=l,n.t[_]=w,n.ux[_]=r-A,n.uy[_]=h-v,n.w[_]=Math.exp(-((b/T)**2))+1e-6,c+=n.w[_]});let y=1/0,m=1/0;for(let d=0;d<o;d++){let f=this.chainRuns[n.c[s*o+d]];n.w[s*o+d]/=c,f.def.reach!==void 0&&(m=Math.min(m,f.def.reach)),y=Math.min(y,Math.hypot(n.ux[s*o+d],n.uy[s*o+d]))}if(m<1/0){let d=1-U(m,1.6*m,y);for(let f=0;f<o;f++)n.w[s*o+f]*=d}for(let d=0;d<o;d++)n.sum[s]+=n.w[s*o+d]}return n}skinOffset(t,e,a){let i=0,o=0;if(t.sum[e]<1e-4)a[0]=0,a[1]=0;else{for(let n=0;n<t.B;n++){let s=e*t.B+n,r=this.chainRuns[t.c[s]],h=t.seg[s];if(!r.moving)continue;let c=Math.min(1,Math.max(0,t.t[s])),y=t.t[s]<0?0:1,m=(r.disp[2*h]+(r.disp[2*h+2]-r.disp[2*h])*c)*y,d=(r.disp[2*h+1]+(r.disp[2*h+3]-r.disp[2*h+1])*c)*y,f=(r.beta[h]+(r.beta[h+1]-r.beta[h])*c)*y,p=Math.cos(f),g=Math.sin(f),x=t.ux[s],b=t.uy[s],k=m+x*p-b*g-x,w=d+x*g+b*p-b,_=Math.cos(r.rho),l=Math.sin(r.rho);i+=t.w[s]*(k*_-w*l),o+=t.w[s]*(k*l+w*_)}a[0]=i,a[1]=o}}chainRoot(t,e,a,i){let[o,n]=t.points[0],s=this.model.anchors;if(t.attach==="body"){let r=[0,0];this.bodyOffset(o,n,e,r),i[0]=o+r[0],i[1]=n+r[1],i[2]=this.body.roll*Math.PI/180*U(s.bottom_y,s.neck_y,n)}else{let r=[0,0];this.headXform(o,n,t.depth??0,e,r),i[0]=r[0]+a[0],i[1]=r[1]+a[1],i[2]=e.angleZ*Math.PI/180*this.rig.roll*this.tuning.turn}}exprAlpha(t){return U(.3,.7,t.param==="smile"||!t.param?this.smileShown:this.expr[t.param]??0)}moodAlpha(t){let e=a=>{let i=0;for(let[o,n]of Object.entries(a||{}))i+=n*this.exprValue(o);return Math.min(1,i)};return(t.show?e(t.show):1)*(t.hide?1-e(t.hide):1)}shown(t){let e=t.def,a=e.role||"";if(this.hidden.has(e.id)||(e.group==="body"?this.bodyHidden:this.headHidden)||(e.show||e.hide)&&this.moodAlpha(e)<=.01)return!1;if(a==="expr"||a==="expr_brows")return this.exprAlpha(e)>.01;if(a.startsWith("lid_"))return 1-U(.05,.35,a==="lid_L"?this.params.eyeLOpen:this.params.eyeROpen)>.01;if(a==="blush"){let i=0;for(let[o,n]of Object.entries(e.blush||{}))i+=n*this.exprValue(o);return i>.01}return!0}exprValue(t){return t==="smile"?this.smileShown:this.expr[t]??0}stepChains(t){if(!this.chainRuns.length||t<=0)return;let e=this.params,a=this.model.anchors,i=[0,0];this.bodyOffset(a.head.cx,a.neck_y,e,i);let o=this.physicsScale*(this.tuning.hairBack??this.tuning.hair),n=[0,0,0];for(let s of this.chainRuns){let r=s.def,h=s.R,c=s.p,y=s.q,m=h.length/2;this.chainRoot(r,e,i,n),s.started||=(s.W=[n[0],n[1]],s.V=[0,0],s.acc=[0,0],!0);let d=(n[0]-s.W[0])/t,f=(n[1]-s.W[1])/t,p=(d-s.V[0])/t,g=(f-s.V[1])/t;s.W=[n[0],n[1]],s.V=[d,f],s.rho=n[2];let x=Math.min(1,t*30);s.acc[0]+=(p-s.acc[0])*x,s.acc[1]+=(g-s.acc[1])*x;let b=Math.cos(-s.rho),k=Math.sin(-s.rho),w=s.acc[0]*b-s.acc[1]*k,_=s.acc[0]*k+s.acc[1]*b,l=0;for(let[M,B]of Object.entries(r.bias||{}))l+=B*this.exprValue(M);let u=-s.rho*r.hang+l*Math.PI/180,A=Math.cos(u),v=Math.sin(u),T=r.freq??.5,R=2*Math.PI*T*this.time+s.phase,P=r.wind*o*this.rig.wind*(Math.sin(R)+.4*Math.sin(1.7*R+2*s.phase)),E=Math.max(0,1-r.damp*t);for(let M=1;M<m;M++){let B=s.s[M],X=r.k[0]+(r.k[1]-r.k[0])*B,$=h[2*M]-h[0],H=h[2*M+1]-h[1],it=h[0]+$*A-H*v+P*B,et=h[1]+$*v+H*A,G=X*(it-c[2*M])-r.drive*o*w,K=X*(et-c[2*M+1])-r.drive*o*_,W=c[2*M]+(c[2*M]-y[2*M])*E+G*t*t,vt=c[2*M+1]+(c[2*M+1]-y[2*M+1])*E+K*t*t;y[2*M]=c[2*M],y[2*M+1]=c[2*M+1],c[2*M]=W,c[2*M+1]=vt}let L=r.limit??1/0;for(let M=1;M<m;M++){let B=c[2*M]-c[2*M-2],X=c[2*M+1]-c[2*M-1],$=Math.hypot(B,X)||1;c[2*M]=c[2*M-2]+B/$*s.len[M],c[2*M+1]=c[2*M-1]+X/$*s.len[M];let H=c[2*M]-h[2*M],it=c[2*M+1]-h[2*M+1],et=Math.hypot(H,it);et>L&&(c[2*M]=h[2*M]+H*L/et,c[2*M+1]=h[2*M+1]+it*L/et)}let O=0;for(let M=0;M<m;M++)s.disp[2*M]=c[2*M]-h[2*M],s.disp[2*M+1]=c[2*M+1]-h[2*M+1],O=Math.max(O,Math.abs(s.disp[2*M]),Math.abs(s.disp[2*M+1]));s.moving=O>.001;let S=[];for(let M=0;M<m-1;M++){let B=h[2*M+2]-h[2*M],X=h[2*M+3]-h[2*M+1],$=c[2*M+2]-c[2*M],H=c[2*M+3]-c[2*M+1];S.push(Math.atan2(B*H-X*$,B*$+X*H))}s.beta[0]=0;for(let M=1;M<m-1;M++)s.beta[M]=.5*(S[M-1]+S[M]);s.beta[m-1]=S[m-2]}}hxC={ax:NaN,ay:NaN,az:NaN,t:NaN,n:NaN,ry:NaN,rp:NaN,rr:NaN,pe:NaN,cy:1,sy:0,cp:1,sp:0,cr:1,sr:0};headTrig(t){let e=this.hxC,a=this.rig,i=this.tuning.turn,o=this.tuning.nod??1,n=a.pitch_ease??.25;if(e.ax!==t.angleX||e.ay!==t.angleY||e.az!==t.angleZ||e.t!==i||e.n!==o||e.ry!==a.yaw||e.rp!==a.pitch||e.rr!==a.roll||e.pe!==n){let s=t.angleY/30,r=t.angleX/30*a.yaw*i,h=s*(1-n*s*s)*a.pitch*i*o,c=t.angleZ*Math.PI/180*a.roll*i;Object.assign(e,{ax:t.angleX,ay:t.angleY,az:t.angleZ,t:i,n:o,ry:a.yaw,rp:a.pitch,rr:a.roll,pe:n,cy:Math.cos(r),sy:Math.sin(r),cp:Math.cos(h),sp:Math.sin(h),cr:Math.cos(c),sr:Math.sin(c)})}return e}headXform(t,e,a,i,o){let n=this.model.anchors.head,s=(t-n.cx)/n.rx,r=(e-n.cy)/n.ry,h=this.rig,c=h.bulge_shape??1,y=h.bulge_extent,m=y?y[0]:1;if(y&&y.length>3&&r>0){let S=Math.min(1,r/(y[2]*(y[4]??1)));m+=(y[3]-y[0])*S*S*(3-2*S)}let d=y?s/m:s,f=y?r/(r<0?y[1]:y[2]):r,p=h.bulge*Math.max(0,c===1?1-d*d-f*f:1-(d*d+f*f)**+c)+a,{cy:g,sy:x,cp:b,sp:k,cr:w,sr:_}=this.headTrig(i),l=s*g+p*x,u=-s*x+p*g,A=r*b-u*k,v=h.drift;l+=(v?v[0]:.12)*x,A-=(v?v[1]:.08)*k;let T=n.cx+l*n.rx,R=n.cy+A*n.ry,P=n.cx,E=this.model.anchors.neck_y,L=T-P,O=R-E;T=P+L*w-O*_,R=E+L*_+O*w,o[0]=T,o[1]=R}bodyOffset(t,e,a,i,o=!0){let n=this.model.anchors,s=n.head,r=this.rig.body,h=U(n.bottom_y,n.neck_y,e),c=n.face[2]-n.face[0],y=a.breath*this.tuning.breath*this.rig.breath*r.breath,m=(t-s.cx)*.01*y*h,d=-y*.024*s.ry*h**1.3,f=this.body.yaw/30,p=1.4*c,g=Math.max(-1.6,Math.min(1.6,(t-s.cx)/p));m+=f*p*.16*h**1.2*(1-.18*g*g)+f*(t-s.cx)*-.04*Math.sign(g)*h;let x=this.body.roll*Math.PI/180*h;if(x!==0){let k=s.cx,w=n.bottom_y+.4*(n.bottom_y-n.neck_y),_=t-k,l=e-w,u=Math.cos(x),A=Math.sin(x);m+=_*(u-1)-l*A,d+=_*A+l*(u-1)}let b=n.chest;if(b&&o){let k=(t-b.cx)/b.rx,w=(e-b.cy)/b.ry,_=Math.sqrt(k*k+w*w),l=1-U(.2,1.15,_);l>0&&(d-=y*.012*s.ry*l*(.4+r.bust),m+=this.bust.x*l,d+=this.bust.y*l)}i[0]=m,i[1]=d}stepBody(t){let e=this.params,a=this.rig.body,i=this.tuning.turn,o=e.bodyX+e.angleX*a.yaw*i,n=e.bodyZ+e.angleZ*a.roll*i,s=Math.min(1,t*5);this.body.yaw+=(o-this.body.yaw)*s,this.body.roll+=(n-this.body.roll)*s;let r=this.model.anchors.chest;if(!r||a.bust<=0){this.bust.x=this.bust.y=0;return}let h=[0,0];this.bodyOffset(r.cx,r.cy,e,h,!1);let c=1/Math.max(t,1e-4),y=(h[0]-this.bust.px)*c,m=(h[1]-this.bust.py)*c;this.bust.px=h[0],this.bust.py=h[1];let d=a.bust*this.physicsScale;this.bust.vx+=(-70*this.bust.x-7*this.bust.vx-y*3.2*d)*t,this.bust.vy+=(-70*this.bust.y-7*this.bust.vy-m*4.2*d)*t,this.bust.x+=this.bust.vx*t,this.bust.y+=this.bust.vy*t;let f=.035*this.model.anchors.head.ry*(.5+d);this.bust.x=Math.max(-f,Math.min(f,this.bust.x)),this.bust.y=Math.max(-f,Math.min(f,this.bust.y))}resetMouth(){this.mouthFrame=0,this.mouthAmp=0,this.mouthShape="",this.mouthHeld=1,this.mouthW=this.frameKind.map((t,e)=>+(e===0))}stepMouth(t){let e=Math.min(1,Math.max(0,this.params.mouthOpen)),a=Math.min(1,Math.max(-1,this.params.vowel||0)),[i,o]=we,n=aa;this.mouthHeld+=t;let s=this.mouthAmp;s===0&&e>i+n?s=e>o+n?2:1:s===1&&(e<i-n||e>o+n)?s=e<i-n?0:2:s===2&&e<o-n&&(s=e<i-n?0:1);let r=this.mouthShape;(!r||(r==="round"?a>-.35:a<oa))&&(r=a<-.65?"round":a>ra?"wide":"");let h=s>0&&r&&this.vis[r]!==void 0?this.vis[r]:s;h===0&&this.talkLeft>0&&this.vis.shut!==void 0&&(h=this.vis.shut),h===this.mouthFrame?(this.mouthAmp=s,this.mouthShape=r):this.mouthHeld>=ia&&(this.mouthFrame=h,this.mouthAmp=s,this.mouthShape=r,this.mouthHeld=0);let c=this.mouthFrame;this.talkLeft=c>0&&c!==this.vis.shut?na:Math.max(0,this.talkLeft-t);let y=Math.min(1,t*28);for(let m=0;m<this.mouthW.length;m++)this.mouthW[m]+=(+(m===c)-this.mouthW[m])*y}frameEase(t,e){let[a,i]=we,o=this.frameKind[t];return o==="half"?U(a,i,e):U(o==="open"?i:a,1,e)}stepPhysics(t){let e=this.params,a=this.model.anchors,i=[0,0];this.headXform(a.head.cx,a.hair_root_y,0,e,i);let o=1/Math.max(t,1e-4),n=(i[0]-this.lastHead.x)*o,s=(i[1]-this.lastHead.y)*o;this.lastHead={x:i[0],y:i[1],roll:e.angleZ};let r=this.rig.hair_drive,h=this.drive;if(r){let d=[0,0];this.headXform(a.head.cx,a.head.cy,0,e,d),h.started||Object.assign(h,{x:d[0],y:d[1],vx:0,vy:0,ax:0,ay:0,started:!0});let f=Math.min(1,t*25),p=h.vx+((d[0]-h.x)*o-h.vx)*f,g=h.vy+((d[1]-h.y)*o-h.vy)*f;h.ax+=((p-h.vx)*o-h.ax)*f,h.ay+=((g-h.vy)*o-h.ay)*f,Object.assign(h,{x:d[0],y:d[1],vx:p,vy:g})}let c=this.rig,y={front:c.hair.front,back:c.hair.back,side:c.hair.side},m=a.head.ry*c.hair_limit;for(let d of c.hair.side?["front","back","side"]:["front","back"]){let[f,p,g,x,b]=y[d],[k,w]=this.chains[d],_=this.physicsScale*((d==="back"?this.tuning.hairBack:this.tuning.hairFront)??this.tuning.hair),l=d==="side"?Math.sin(this.time*1.5+.7)*1.2*_*c.wind:Math.sin(this.time*(d==="front"?1.9:1.15))*(d==="front"?.6:1.8)*_*c.wind,u=-e.angleZ*.2*_,A=-f*(k.x-l-u)-p*k.vx-n*g*f*.06*_,v=-f*k.y-p*k.vy-s*g*f*.04*_;if(r){let P=(d==="front"?r[0]:d==="back"?r[1]:r[2]??r[0])*_;A-=h.ax*P,v-=h.ay*P}k.vx+=A*t,k.vy+=v*t,k.x+=k.vx*t,k.y+=k.vy*t;let T=-x*(w.x-k.x*1.6)-b*w.vx,R=-x*(w.y-k.y*1.4)-b*w.vy;w.vx+=T*t,w.vy+=R*t,w.x+=w.vx*t,w.y+=w.vy*t;for(let P of[k,w])P.x=Math.max(-m,Math.min(m,P.x)),P.y=Math.max(-m*.6,Math.min(m*.6,P.y))}}update(t,e=!0){if(!this.model)return;this.time+=t;let a=this.params;this.smileShown+=(a.smile-this.smileShown)*Math.min(1,t*7),this.stepMouth(t);for(let o of["angleX","angleY","angleZ"])a[o]=Math.max(ft[o][0],Math.min(ft[o][1],a[o]));let i=Math.max(1,Math.ceil(t/(1/120)));for(let o=0;o<i;o++)this.stepBody(t/i),this.stepPhysics(t/i),this.stepChains(t/i);e&&this.deform()}deform(){var _;let t=this.params,e=this.model.anchors,a=[0,0];this.bodyOffset(e.head.cx,e.neck_y,t,a);let i=[0,0],o=[0,0],[n,s]=ha(e,e.head.ry*this.rig.brow),r=l=>l>0?Math.min(1,l)*n:Math.max(-1,l)*s,h=[r(t.browLY),r(t.browRY)],c=Math.min(1,Math.max(0,t.mouthOpen)),y=0;this.mouthW.forEach((l,u)=>{l>0&&this.frameJaw[u]>0&&(y+=l*this.frameJaw[u]*(this.frameKind[u]==="half"?.6+.4*this.frameEase(u,c):.75+.25*this.frameEase(u,c)))});let m=[0,0],d=!!this.rig.hair.side,f=(l,u,A,v,T,R,P)=>{A<1?this.bodyOffset(l,u,t,o):(o[0]=0,o[1]=0);let E=l+o[0],L=u+o[1];if(A>0&&(this.headXform(l,u,v,t,i),E=E*(1-A)+(i[0]+a[0])*A,L=L*(1-A)+(i[1]+a[1])*A),(T>0||R>0)&&d){let O=this.chains.back,S=this.chains.front,M=this.chains.side,B=U(be[0],be[1],Math.abs(l-e.head.cx)/e.head.rx),X=P*(1-B),$=P*B,H=S[0].x*X+M[0].x*$+O[0].x*(1-P),it=S[0].y*X+M[0].y*$+O[0].y*(1-P),et=S[1].x*X+M[1].x*$+O[1].x*(1-P),G=S[1].y*X+M[1].y*$+O[1].y*(1-P);E+=H*T+et*R,L+=it*T+G*R}else if(T>0||R>0){let O=this.chains.back,S=this.chains.front,M=S[0].x*P+O[0].x*(1-P),B=S[0].y*P+O[0].y*(1-P),X=S[1].x*P+O[1].x*(1-P),$=S[1].y*P+O[1].y*(1-P);E+=M*T+X*R,L+=B*T+$*R}m[0]=E,m[1]=L},p=[0,0],g=this.kfOff?[]:this.keyWeights??this.keys.map(l=>l.param==="diag"?0:Math.min(2,Math.max(0,t[l.param]*l.scale/l.value)));if(this.kfPair&&!this.kfOff&&!this.keyWeights){let l=g.slice();for(let u=0;u<l.length;u++){let A=this.kfPair[u];if(A<0||l[u]<=0||l[u]>=1)continue;let v=l[u],T=v*v*v-2*v*v+v;g[u]=3*v*v-2*v*v*v+.5*T+v*v*v-v*v,g[A]-=.5*T}}let x=t.angleZ*Math.PI/180*this.rig.roll*this.tuning.turn,b=this.tuning.gaze,k=typeof b=="number"&&b>=0&&b<1?b:1,w=0;if(this.rig.neck){let l=((_=e.jaw)==null?void 0:_.chin)??e.neck_y;this.headXform(e.head.cx,l,0,t,i),this.bodyOffset(e.head.cx,l,t,o),w=i[0]+a[0]-(e.head.cx+o[0])}for(let l of this.layers){if(!this.kfOff&&!this.shown(l))continue;let u=l.def,A=l.rest,v=l.out;l.uploaded=!1;let T=A.length/2,R=u.role||"",P=R.endsWith("_L")?"L":R.endsWith("_R")?"R":"",E=R.startsWith("eye_")||R.startsWith("iris_")||R.startsWith("shine_"),L=.12+.88*(P==="L"?t.eyeLOpen:P==="R"?t.eyeROpen:1),O=R.startsWith("iris_"),S=0,M=0;O&&u.range&&(S=t.eyeBallX*u.range[0]*k,M=-t.eyeBallY*u.range[1]*k),this.chained&&R.startsWith("shine_")&&u.range&&(S=t.eyeBallX*u.range[0]*k,M=-t.eyeBallY*u.range[1]*k);let B=S,X=0,$=this.irisNasal&&S!==0?this.nasal[P]:void 0;$&&S*$.sign>$.room&&(X=-(Math.min(S*$.sign,$.room+(1-this.irisNasalNarrow)*$.w)-$.room)/$.w,B=$.sign*$.room-X*$.inner);let H=O&&this.irisLid&&!!u.pivot&&!!u.range&&(u.range[0]>0||u.range[1]>0);H&&(M+=this.irisDrop*(1-L)*((l.pivC??u.pivot[1])-(u.y+u.h/2))),O&&(l.soft=Math.min(1,Math.hypot(S,M)+(H?(1-L)*u.h/2:0)));let it=this.chained&&R.startsWith("shine_")?ua(this.time+(P==="R"?1.3:0)):1,et=u.x+u.w/2,G=u.y+u.h/2,K=0,W=0;u.rigid&&(this.headXform(u.rigid[0],u.rigid[1],u.depth,t,i),K=i[0]+a[0],W=i[1]+a[1]);let vt=Math.cos(x),St=Math.sin(x);for(let I=0;I<T;I++){let ht=A[2*I],Q=A[2*I+1];if(it!==1&&(ht=et+(ht-et)*it,Q=G+(Q-G)*it),E&&u.pivot){let C=l.pivY?l.pivY[I]:u.pivot[1];ht+=B+X*A[2*I],Q+=M,(!H||Q>C)&&(Q=C+(Q-C)*L)}if(l.browSide[I]>=0){let C=h[l.browSide[I]];Q-=Math.sign(C)*Math.min(Math.abs(C),l.browCap[I])*l.wBrow[I]}if(y>0&&l.wJaw[I]>0&&(Q+=y*l.wJaw[I]),u.rigid){let C=ht-u.rigid[0],D=Q-u.rigid[1];m[0]=K+C*vt-D*St,m[1]=W+C*St+D*vt}else f(ht,Q,l.wHead[I],l.dep[I],l.wPhys1[I],l.wPhys2[I],l.wFront[I]);l.skin&&(this.skinOffset(l.skin,I,p),m[0]+=p[0],m[1]+=p[1]);let st=m[0],rt=m[1];if(l.wTwist&&l.wTwist[I]>0&&(st+=w*l.wTwist[I]),l.wNeck&&l.wNeck[I]>0){let C=x*l.wNeck[I],D=Math.cos(C),Z=Math.sin(C),J=e.head.cx+a[0],yt=e.neck_y+a[1],pt=st-J,gt=rt-yt;st=J+pt*D-gt*Z,rt=yt+pt*Z+gt*D}let Mt=l.fol?l.fol[I]:0,Et=l.folB?l.folB[I]:0;if(Mt>0||Et>0){let C=5*I,D=l.alt,Z=st,J=rt;f(ht,Q,D[C+1],D[C],D[C+2],D[C+3],D[C+4]),l.altSkin&&(this.skinOffset(l.altSkin,I,p),m[0]+=p[0],m[1]+=p[1]),st+=(m[0]-Z)*Mt,rt+=(m[1]-J)*Mt,l.outB&&(l.outB[2*I]=Z+(m[0]-Z)*Et,l.outB[2*I+1]=J+(m[1]-J)*Et)}else l.outB&&(l.outB[2*I]=st,l.outB[2*I+1]=rt);if(l.kf){let C=0,D=0;for(let Z=0;Z<g.length;Z++){let J=l.kf[Z];J&&g[Z]!==0&&(C+=g[Z]*J[2*I],D+=g[Z]*J[2*I+1])}if(C!==0||D!==0){let Z=x*l.wHead[I],J=Math.cos(Z),yt=Math.sin(Z),pt=C*J-D*yt,gt=C*yt+D*J;st+=pt,rt+=gt,l.outB&&(l.outB[2*I]+=pt,l.outB[2*I+1]+=gt)}}v[2*I]=st,v[2*I+1]=rt}}}drawLayer(t,e,a,i,o=0){let n=this.gl;n.bindBuffer(n.ARRAY_BUFFER,t.pos),i?(n.bufferSubData(n.ARRAY_BUFFER,0,i),t.uploaded=!1):t.uploaded||=(n.bufferSubData(n.ARRAY_BUFFER,0,t.out),!0),n.bindTexture(n.TEXTURE_2D,e),n.uniform1f(this.uAlpha,a),n.uniform1f(this.uCut,o),n.bindVertexArray(t.vao),n.drawElements(n.TRIANGLES,t.count,n.UNSIGNED_INT,0)}drawMasks(t,e,a,i,o,n){let s=this.gl,r=[];for(let d of this.layers)d.maskCh=-1;for(let d of this.softIris?this.layers:[]){let f=d.def.clip?this.byId.get(d.def.clip):void 0;!(d.def.role||"").startsWith("iris_")||!(f!=null&&f.mask)||!(d.soft>0)||f.maskCh>=0||r.length>=4||this.hidden.has(d.def.id)||this.hidden.has(f.def.id)||(f.maskCh=r.length,r.push(f))}if(!r.length)return;let h=1/0,c=1/0,y=-1/0,m=-1/0;for(let d of r)for(let f=0;f<d.out.length;f+=2){let p=(d.out[f]*a+o+1)*t/2,g=(1-(d.out[f+1]*i+n))*e/2;h=Math.min(h,p),y=Math.max(y,p),c=Math.min(c,g),m=Math.max(m,g)}if(h=Math.max(0,Math.floor(h)-2),c=Math.max(0,Math.floor(c)-2),y=Math.min(t,Math.ceil(y)+2),m=Math.min(e,Math.ceil(m)+2),y<=h||m<=c)for(let d of r)d.maskCh=-1;else{if(s.activeTexture(s.TEXTURE1),s.bindTexture(s.TEXTURE_2D,null),s.activeTexture(s.TEXTURE0),!this.maskFb||y-h>this.maskSize[0]||m-c>this.maskSize[1]){let d=Math.max(this.maskSize[0],Math.ceil((y-h)/64)*64),f=Math.max(this.maskSize[1],Math.ceil((m-c)/64)*64);this.maskTex||=s.createTexture(),s.bindTexture(s.TEXTURE_2D,this.maskTex),s.texImage2D(s.TEXTURE_2D,0,s.RGBA8,d,f,0,s.RGBA,s.UNSIGNED_BYTE,null),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.NEAREST),this.maskFb||=s.createFramebuffer(),s.bindFramebuffer(s.FRAMEBUFFER,this.maskFb),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,this.maskTex,0),this.maskSize=[d,f]}s.bindFramebuffer(s.FRAMEBUFFER,this.maskFb),s.viewport(-h,-c,t,e),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT),s.disable(s.BLEND),s.uniform1i(this.uMode,1),r.forEach((d,f)=>{s.colorMask(f===0,f===1,f===2,f===3),this.drawLayer(d,d.mask,1)}),s.colorMask(!0,!0,!0,!0),s.uniform1i(this.uMode,0),s.enable(s.BLEND),s.bindFramebuffer(s.FRAMEBUFFER,null),s.viewport(0,0,t,e),s.activeTexture(s.TEXTURE1),s.bindTexture(s.TEXTURE_2D,this.maskTex),s.activeTexture(s.TEXTURE0),s.uniform2i(this.uMaskOff,h,c)}}render(){let t=this.gl,e=this.canvas,a=Math.min(this.maxDpr,window.devicePixelRatio||1),[i,o]=this.size??[Math.round(e.clientWidth*a),Math.round(e.clientHeight*a)];(e.width!==i||e.height!==o)&&(e.width=i,e.height=o),t.viewport(0,0,i,o);let n=()=>{t.clearColor(...this.background),t.clearStencil(0),t.clear(t.COLOR_BUFFER_BIT|t.STENCIL_BUFFER_BIT)};if(!this.model){n();return}t.useProgram(this.prog),t.enable(t.BLEND),t.blendFunc(t.ONE,t.ONE_MINUS_SRC_ALPHA),t.activeTexture(t.TEXTURE0),t.uniform1i(this.uTex,0),t.uniform1i(this.uMode,0);let[s,r]=this.model.canvas,h=this.view,c=this.move,y=this.model.anchors.head,m=(E,L)=>(this.focusHead?-(y.cy+y.ry*.15)*(2*E)/o:-r*E/o)+this.panY-2*L,d=(E,L)=>-(2*E*r/o+L),f=Math.min(i/s,o/r)*this.zoom,p=f*h.s*c.s,g=2*p/i,x=2*p/o,b=m(p,h.y+c.y);if(this.cutBottom){let E=Math.max(d(f*h.s,m(f*h.s,h.y)),-1);b+=Math.max(0,d(p,b)-E)}let k=(this.focusHead?-y.cx*g:-s*p/i)+2*(h.x+c.x);t.uniform4f(this.uView,g,x,k,b),this.drawMasks(i,o,g,x,k,b),n(),this.lastView=[g,x,k,b,i,o];let w=this.params,_=E=>{let L=Math.min(1,Math.max(0,w.mouthOpen)),O=this.mouthFrame,S=E.def.pivot?E.def.pivot[1]:E.def.y,M=this.frameKind[O]==="half"?.88+.12*this.frameEase(O,L):.9+.1*this.frameEase(O,L),B;if(O>0&&O!==this.vis.shut){B=E.out.slice();let X=this.chinFollow?E.wJaw:void 0;for(let $=1;$<B.length;$+=2)B[$]+=(E.rest[$]-S)*(M-1)*(X?1-X[$>>1]:1)}this.drawLayer(E,E.frames[O],1,B)},l=this.talkLeft>0?this.layers.findLastIndex(E=>E.def.role==="expr"):-1,u=E=>this.exprAlpha(E),A=null,v=this.layers.findLastIndex(E=>E.def.id==="brows"||E.def.role==="expr_brows"),T=v<0,R=()=>{if(T=!0,!this.headHidden){for(let E of this.layers)if(E.browTex&&E.def.role==="expr"&&!this.hidden.has(E.def.id)&&(!this.only||this.only(E.def))){let L=u(E.def);L>.01&&this.drawLayer(E,E.browTex,L,E.outB)}}},P=0;for(let E=0;E<this.layers.length;E++){let L=this.layers[E],O=L.def,S=O.role||"";if(A&&E>l&&(_(A),A=null),!T&&E>v&&R(),this.hidden.has(O.id)||(O.group==="body"?this.bodyHidden:this.headHidden)||this.only&&!this.only(O)||(S==="hole"||S==="edge"||S==="edge_wide")&&!this.masks)continue;if(S==="mouth"&&L.frames.length>=3){E<l?A=L:_(L);continue}if(S==="expr"){let B=u(O);B>.01&&this.drawLayer(L,this.talkLeft>0&&L.talk?L.talk:L.tex,B);continue}if(S==="expr_brows"){let B=u(O);B>.01&&this.drawLayer(L,L.tex,B);continue}if(O.id==="brows"){let B=0;for(let X of this.layers)X.def.role==="expr"&&X.def.brows==="redrawn"&&!this.hidden.has(X.def.id)&&(B=Math.max(B,u(X.def)));B<.99&&this.drawLayer(L,L.tex,1-B);continue}if(S.startsWith("lid_")){let B=S==="lid_L"?w.eyeLOpen:w.eyeROpen,X=1-U(.05,.35,B);X>.01&&this.drawLayer(L,L.tex,X);continue}if(S.startsWith("eye_")){let B=S==="eye_L"?w.eyeLOpen:w.eyeROpen;this.drawLayer(L,L.tex,U(.02,.2,B)),L.stencilRef=0,L.mask&&L.maskCh<0&&(P=P%250+1,L.stencilRef=P,t.enable(t.STENCIL_TEST),t.stencilFunc(t.ALWAYS,P,255),t.stencilOp(t.KEEP,t.KEEP,t.REPLACE),t.colorMask(!1,!1,!1,!1),this.drawLayer(L,L.mask,1,void 0,.5),t.colorMask(!0,!0,!0,!0),t.disable(t.STENCIL_TEST));continue}if(S==="blush"){let B=0;for(let[X,$]of Object.entries(O.blush||{}))B+=$*this.exprValue(X);B>.01&&this.drawLayer(L,L.tex,Math.min(1,B));continue}if(S.startsWith("iris_")||S.startsWith("shine_")){let B=O.clip?this.byId.get(O.clip):void 0,X=S.endsWith("_L")?w.eyeLOpen:w.eyeROpen;if(B&&B.maskCh>=0){let $=B.maskCh;t.uniform1i(this.uMode,2),t.uniform4f(this.uMaskSel,+($===0),+($===1),+($===2),+($===3)),t.uniform1f(this.uSoft,L.soft),this.drawLayer(L,L.tex,U(.02,.2,X)),t.uniform1i(this.uMode,0)}else B&&B.stencilRef&&(t.enable(t.STENCIL_TEST),t.stencilFunc(t.EQUAL,B.stencilRef,255),t.stencilOp(t.KEEP,t.KEEP,t.KEEP),this.drawLayer(L,L.tex,U(.02,.2,X)),t.disable(t.STENCIL_TEST));continue}let M=O.show||O.hide?this.moodAlpha(O):1;M>.01&&this.drawLayer(L,L.tex,M)}A&&_(A),T||R(),t.bindVertexArray(null)}canvasToModel(t,e){let[a,i,o,n,s,r]=this.lastView,h=this.canvas,c=2*t*(s/Math.max(1,h.clientWidth))/s-1,y=2*e*(r/Math.max(1,h.clientHeight))/r-1;return[(c-o)/a,(y-n)/i]}poke(t,e,a=1){let i=0;for(let o of this.chainRuns){let n=o.R,s=n.length/2,r=1.5*(o.def.sigma??40)+20,h=1/0;for(let y=0;y<s;y++)h=Math.min(h,Math.hypot(n[2*y]-t,n[2*y+1]-e));if(h>r)continue;i++;let c=t<n[0]?1:-1;for(let y=1;y<s;y++){let m=(1-h/r)*o.s[y]*9*a;o.q[2*y]-=c*m,o.q[2*y+1]+=m*.3}}return i}resetPhysics(){for(let t of this.chainRuns)t.p.set(t.R),t.q.set(t.R),t.disp.fill(0),t.beta.fill(0),t.started=!1,t.moving=!1;for(let t of Object.values(this.chains))for(let e of t)Object.assign(e,bt());this.lastHead={x:0,y:0,roll:0},this.drive.started=!1,this.body={yaw:0,roll:0},this.bust={x:0,y:0,vx:0,vy:0,px:0,py:0}}snapshot(){return this.canvas.toDataURL("image/png")}};function fa(t){let e=(n,s,r)=>Number.isInteger(n)&&n>=s&&n<=r;if((t==null?void 0:t.version)!==1||!e(t.cols,2,4096)||!e(t.rows,2,4096)||t.cols*t.rows>2**22||![t.cell,t.units,t.turn,t.nod].every(n=>typeof n=="number"&&Number.isFinite(n)&&n>0)||!Array.isArray(t.keys)||t.keys.length>32)return!1;let a=n=>Math.ceil(n/3)*4,i=a(t.cols*t.rows*4),o=a(t.cols*t.rows);for(let n of t.keys)if(!n||!["angleX","angleY","diag"].includes(n.param)||!Number.isFinite(n.value)||n.param!=="diag"&&!n.value||!n.fields||typeof n.fields!="object"||Object.values(n.fields).some(s=>typeof s!="string"||s.length!==i)||n.same!==void 0&&!(Array.isArray(n.same)&&n.same.every(s=>typeof s=="string")))return!1;return Object.values(t.mask||{}).every(n=>typeof n=="string"&&n.length===o)}function ca(t){let e=t.points.length,a=new Float32Array(t.points.flat()),i=new Float32Array(e),o=new Float32Array(e);for(let r=1;r<e;r++)i[r]=Math.hypot(a[2*r]-a[2*r-2],a[2*r+1]-a[2*r-1]),o[r]=o[r-1]+i[r];let n=o[e-1]||1;for(let r=1;r<e;r++)o[r]/=n;let s=0;for(let r of t.id)s=(s*31+r.charCodeAt(0))%997;return{def:t,R:a,p:a.slice(),q:a.slice(),len:i,s:o,disp:new Float32Array(2*e),beta:new Float32Array(e),W:[0,0],V:[0,0],acc:[0,0],rho:0,started:!1,phase:s/997*2*Math.PI,moving:!1}}function ua(t){let e=Math.floor(t/5.3),a=t-e*5.3-e*7919%13/13*3.5,i=a>0&&a<.35?Math.sin(a/.35*Math.PI):0;return 1+.03*Math.sin(t*2.1)+.12*i}function Le(t){let[e,a=""]=t.split("?"),i=e.endsWith(".json")?e:(e.endsWith("/")?e:e+"/")+"model.json";return{file:i,base:i.slice(0,i.lastIndexOf("/")+1),query:a}}function ma(t,e){let{base:a,query:i}=Le(t);return a+`textures.bin?v=${e}${i?`&${i}`:""}`}async function ya(t,e){try{let a=await fetch(t,{signal:e});if(!a.ok)return null;let i=await a.arrayBuffer(),o=new DataView(i).getUint32(0,!0),n=JSON.parse(new TextDecoder().decode(new Uint8Array(i,4,o)));return new Map(Object.entries(n).filter(s=>Array.isArray(s[1])).map(([s,[r,h]])=>[s,new Blob([new Uint8Array(i,4+o+r,h)],{type:s.endsWith(".png")?"image/png":"image/webp"})]))}catch(a){if(e!=null&&e.aborted)throw a;return null}}function qt(t){let e=URL.createObjectURL(t);return Te(e).finally(()=>URL.revokeObjectURL(e))}async function pa(t,e){let a;try{let i=await fetch(t,{signal:e});if(!i.ok)throw Error();a=await i.blob()}catch(i){throw e.aborted?i:Error("image "+t)}return qt(a)}function Te(t){return new Promise((e,a)=>{let i=new Image;i.crossOrigin="anonymous",i.onload=()=>e(i),i.onerror=()=>a(Error("image "+t)),i.src=t})}function ga(t,e,a,i){let o=Math.min(e.cols-1.001,Math.max(0,a/e.cell)),n=Math.min(e.rows-1.001,Math.max(0,i/e.cell)),s=Math.floor(o),r=Math.floor(n),h=o-s,c=n-r,y=(d,f,p)=>t[2*(f*e.cols+d)+p],m=d=>(y(s,r,d)*(1-h)+y(s+1,r,d)*h)*(1-c)+(y(s,r+1,d)*(1-h)+y(s+1,r+1,d)*h)*c;return[m(0)*e.units,m(1)*e.units]}function wa(t,e,a,i){let o=Math.min(e.cols-1.001,Math.max(0,a/e.cell)),n=Math.min(e.rows-1.001,Math.max(0,i/e.cell)),s=Math.floor(o),r=Math.floor(n),h=o-s,c=n-r,y=(m,d)=>t[d*e.cols+m];return((y(s,r)*(1-h)+y(s+1,r)*h)*(1-c)+(y(s,r+1)*(1-h)+y(s+1,r+1)*h)*c)/255}function xe(t,e,a,i,o,n){let s=document.createElement("canvas");s.width=e.w,s.height=e.h;let r=s.getContext("2d",{willReadFrequently:!0});r.drawImage(t,0,0,e.w,e.h);let h=r.getImageData(0,0,e.w,e.h).data;r.clearRect(0,0,e.w,e.h),r.drawImage(a,i.x-e.x,i.y-e.y,i.w,i.h);let c=r.getImageData(0,0,e.w,e.h).data,y=new Float32Array(o.length/2);for(let m=0;m<y.length;m++){let d=o[2*m]-e.x,f=o[2*m+1]-e.y,p=0,g=0,x=0,b=0;for(let k=Math.max(0,Math.round(f-n));k<Math.min(e.h,Math.round(f+n));k++)for(let w=Math.max(0,Math.round(d-n));w<Math.min(e.w,Math.round(d+n));w++){let _=4*(k*e.w+w)+3,l=h[_]/255,u=c[_]/255;p+=l,g+=l*u,x+=u,b++}y[m]=p>1?g/p:b?x/b:0}return y}function ba(t){var i;let e=t.profile,a=(i=e==null?void 0:e.class)==null?void 0:i.input;return!!e&&(e.id==="anime_half"||e.id==="painterly")&&(a==null?void 0:a.facing)==="front"&&a.glasses!==!0&&!t.layers.some(o=>o.id==="glasses")}function xa(t,e,a,i,o){let n=b=>{let k=b.naturalWidth||b.width,w=b.naturalHeight||b.height,_=document.createElement("canvas");_.width=k,_.height=w;let l=_.getContext("2d",{willReadFrequently:!0});return l.drawImage(b,0,0),{w:k,h:w,d:l.getImageData(0,0,k,w).data}},s=n(t),r=n(a),h=e.w/s.w,c=e.h/s.h,y=(b,k)=>{let w=Math.floor((b-i.x)/i.w*r.w),_=Math.floor((k-i.y)/i.h*r.h);return w>=0&&_>=0&&w<r.w&&_<r.h&&r.d[4*(_*r.w+w)+3]>=128},m=[];for(let b=0;b<s.h;b++){let k=e.y+(b+.5)*c,w=0,_=1/0,l=-1/0;for(let u=0;u<s.w;u++){let A=e.x+(u+.5)*h;s.d[4*(b*s.w+u)+3]<200||!y(A,k)||(w++,_=Math.min(_,A),l=Math.max(l,A))}w&&m.push([k,w,o>0?l:_,o>0?_:l])}if(!m.length)return null;let d=Math.max(...m.map(b=>b[1])),f=[],p=[],g=[];for(let[b,k,w,_]of m){if(k<.9*d)continue;let l=0;for(;y(w+o*(l+1)*h,b);)l++;f.push(l*h),p.push(w+o*h/2),g.push(Math.abs(w-_)+h)}let x=b=>b.sort((k,w)=>k-w)[b.length>>1];return{room:x(f),sign:o,inner:x(p),w:x(g)}}function va(t,e){let a=t.naturalWidth||t.width,i=t.naturalHeight||t.height,o=document.createElement("canvas");o.width=a,o.height=i;let n=o.getContext("2d",{willReadFrequently:!0});n.drawImage(t,0,0);let s=n.getImageData(0,0,a,i).data,r=Array(a).fill(NaN);for(let w=0;w<a;w++){let _=255,l=-1;for(let u=0;u<i;u++){let A=4*(u*a+w);if(s[A+3]<200)continue;let v=.3*s[A]+.59*s[A+1]+.11*s[A+2];v<_&&(_=v,l=u)}l>=0&&_<110&&(r[w]=l)}if(r.filter(w=>!Number.isNaN(w)).length<.2*a)return null;let h=[];r.forEach((w,_)=>{Number.isNaN(w)||h.push([e.x+(_+.5)*(e.w/a),e.y+(w+.5)*(e.h/i)])});let c=w=>{let _=w.reduce((E,L)=>E+L[0],0)/w.length,l=Math.max(1,(w[w.length-1][0]-w[0][0])/2),u=[,,,,,].fill(0),A=[0,0,0];for(let[E,L]of w){let O=(E-_)/l,S=1;for(let M=0;M<5;M++)u[M]+=S,M<3&&(A[M]+=S*L),S*=O}let v=[[u[0],u[1],u[2]],[u[1],u[2],u[3]],[u[2],u[3],u[4]]],T=E=>E[0][0]*(E[1][1]*E[2][2]-E[1][2]*E[2][1])-E[0][1]*(E[1][0]*E[2][2]-E[1][2]*E[2][0])+E[0][2]*(E[1][0]*E[2][1]-E[1][1]*E[2][0]),R=T(v);if(!(Math.abs(R)>1e-9))return null;let P=[0,1,2].map(E=>T(v.map((L,O)=>L.map((S,M)=>M===E?A[O]:S)))/R);return P.every(Number.isFinite)?E=>{let L=(E-_)/l;return P[0]+P[1]*L+P[2]*L*L}:null},y=c(h);if(!y)return null;let m=h.map(([w,_])=>Math.abs(_-y(w))).sort((w,_)=>w-_),d=Math.max(1.5,2.5*m[m.length>>1]),f=h,p=h.filter(([w,_])=>Math.abs(_-y(w))<=d),g=p.length>=.6*h.length?c(p):null;g&&(y=g,f=p);let x=f[0][0],b=f[f.length-1][0],k=y;return w=>k(Math.min(b,Math.max(x,w)))}function Ma(t,e,a,i=0,o=0,n=e,s=a){let r=document.createElement("canvas");r.width=e,r.height=a;let h=r.getContext("2d",{willReadFrequently:!0});h.imageSmoothingEnabled=!0;for(let d of t)h.drawImage(d,i,o,n,s);let c=h.getImageData(0,0,e,a).data,y=new Uint8Array(e*a);for(let d=0;d<e*a;d++)y[d]=+(c[4*d+3]>0);let m=y.slice();for(let d=0;d<a;d++)for(let f=0;f<e;f++)if(!y[d*e+f])for(let p=-1;p<=1;p++)for(let g=-1;g<=1;g++){let x=d+p,b=f+g;x>=0&&x<a&&b>=0&&b<e&&y[x*e+b]&&(m[d*e+f]=1)}return m}var ka="LivLiv",Re="#ff4d5e",Pt=[27,44,430,133],ve="M101.5 62.5V141.5Q101.5 158.5 115.5 158.5M145 107.5V158.5M176.3 107.5L200.5 158.5L224.7 107.5M257.5 62.5V141.5Q257.5 158.5 271.5 158.5M303 107.5V158.5M335.3 107.5L359.5 158.5L383.7 107.5",Me="M40.5 122L49.5 142.1M60.5 122L69.5 142.1M421.5 122L412.5 142.1M441.5 122L432.5 142.1",xt={cx:145,cy:67,r:13.5},ke="M293.5 69H312.5A8 8 0 0 1 312.5 85H293.5A8 8 0 0 1 293.5 69Z",Gt={center:.38,centerY:.62,centerAlpha:.18,centerShadow:"rgba(0,0,0,.25)",centerBlur:.06,corner:.13,cornerMin:64,margin:.035,text:.026,top:.12};function Jt(t){let e=t%5500/5500;return e<.93?1:e<.955?1-(e-.93)/.025*.88:.12+(e-.955)/.045*.88}function Oe(t,e,a,i,o,n=0,s=Re,r=0,h="#222"){let[c,y,m,d]=Pt,f=i/d;t.save(),t.translate(e-m*f,a-i),t.scale(f,f),t.translate(-c,-y),t.lineCap="round",t.lineJoin="round",r&&(t.strokeStyle=h,t.lineWidth=25+r*2,t.stroke(new Path2D(ve)),t.lineWidth=12.5+r*2,t.stroke(new Path2D(Me)),t.lineWidth=r*2,t.beginPath(),t.ellipse(xt.cx,xt.cy,xt.r,xt.r*Jt(n),0,0,Math.PI*2),t.stroke(),t.stroke(new Path2D(ke))),t.strokeStyle=o,t.lineWidth=25,t.stroke(new Path2D(ve)),t.strokeStyle=s,t.lineWidth=12.5,t.stroke(new Path2D(Me)),t.fillStyle=s,t.beginPath(),t.ellipse(xt.cx,xt.cy,xt.r,xt.r*Jt(n),0,0,Math.PI*2),t.fill(),t.fill(new Path2D(ke)),t.restore()}function Pe(t,e,a=!1,i=1){let{corner:o,cornerMin:n,margin:s,text:r}=Gt,h=Math.min(t,e),c=Math.max(12*i,h*s);return{right:t-c,y:a?e>t?e*Gt.top:c:e-c,top:a,logo:Math.max(n*i,h*o)*Pt[3]/Pt[2],text:Math.max(12*i,h*r)}}function Se(t,e,a,i=0,o=1,n=!1,s=!1){let r=Pe(e,a,n,o);t.save(),s||(t.shadowColor="rgba(0,0,0,.55)",t.shadowBlur=r.logo*.12),Oe(t,r.right,r.top?r.y+r.logo:r.y,r.logo,s?"#fff":"rgba(255,255,255,.95)",i,Re,s?9:0),t.restore()}function Ea(t,e,a,i,o=1,n=!1){let s=Pe(e,a,n,o);t.save(),t.shadowColor="rgba(0,0,0,.6)",t.shadowBlur=s.text*.25,t.font=`600 ${s.text}px system-ui, sans-serif`,t.textAlign="right",t.textBaseline=s.top?"top":"bottom",t.fillStyle="rgba(255,255,255,.85)",t.fillText(i,s.right,s.y),t.restore()}function _a(t,e,a,i=0,o=1,n=!1){let{center:s,centerY:r,centerAlpha:h,centerShadow:c,centerBlur:y}=Gt,m=Math.min(e,a)*s,d=m*Pt[3]/Pt[2];t.save(),t.globalAlpha=h,t.shadowColor=c,t.shadowBlur=d*y,Oe(t,(e+m)/2,a*r+d/2,d,"#fff",i,"#fff"),t.restore(),Se(t,e,a,i,o,n)}var Aa=`#version 300 es
12
+ in vec2 aPos; out vec2 vUv;
13
+ void main(){ vUv=vec2(aPos.x*.5+.5,.5-aPos.y*.5); gl_Position=vec4(aPos,0.,1.); }`,La=`#version 300 es
14
+ precision mediump float; in vec2 vUv; uniform sampler2D uTex; out vec4 o;
15
+ void main(){ o=texture(uTex,vUv); }`,Ta=class{logo=!1;text=null;gl;prog;vao;buf;tex;c=document.createElement("canvas");drawn="";constructor(t){this.gl=t;let e=(i,o)=>{let n=t.createShader(i);return t.shaderSource(n,o),t.compileShader(n),n},a=this.prog=t.createProgram();t.attachShader(a,e(t.VERTEX_SHADER,Aa)),t.attachShader(a,e(t.FRAGMENT_SHADER,La)),t.bindAttribLocation(a,0,"aPos"),t.linkProgram(a),this.vao=t.createVertexArray(),t.bindVertexArray(this.vao),this.buf=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this.buf),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(0),t.vertexAttribPointer(0,2,t.FLOAT,!1,0,0),t.bindVertexArray(null),this.tex=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.tex),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)}set(t,e,a=!0){this.logo=t==="livliv",this.text=t==="text"?e:null,this.center=a}center=!0;draw(t,e){let a=this.logo?ka:this.text,i=this.gl;if(!a)return;let o=i.drawingBufferWidth,n=i.drawingBufferHeight,s=`${o}x${n}:${e}:${this.logo?Math.round(Jt(t)*10):""}:${this.logo}:${this.center}:${a}`;if(i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this.tex),s!==this.drawn){this.drawn=s;let r=this.c;(r.width!==o||r.height!==n)&&(r.width=o,r.height=n);let h=r.getContext("2d");h.clearRect(0,0,o,n),h.save(),this.logo&&this.center?_a(h,o,n,t,e):this.logo?Se(h,o,n,t,e):Ea(h,o,n,a,e),h.restore(),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,r)}i.viewport(0,0,o,n),i.useProgram(this.prog),i.disable(i.STENCIL_TEST),i.enable(i.BLEND),i.blendFunc(i.ONE,i.ONE_MINUS_SRC_ALPHA),i.bindVertexArray(this.vao),i.drawArrays(i.TRIANGLE_STRIP,0,4),i.bindVertexArray(null)}dispose(){let t=this.gl;t.deleteTexture(this.tex),t.deleteBuffer(this.buf),t.deleteVertexArray(this.vao),t.deleteProgram(this.prog)}},mt={entries:2048,bytes:256*2**20,modelJson:N.modelJson,keyforms:N.keyforms},q=(t,e="invalid")=>new V(e,`LivLiv: ${t}`),Ra={webp:"image/webp",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",json:"application/json"};async function Ee(t){let e=new Uint8Array(await t.slice(0,4).arrayBuffer());return e.length===4&&e[0]===80&&e[1]===75&&(e[2]===3&&e[3]===4||e[2]===5&&e[3]===6)}async function Oa(t){let e=Math.min(t.size,65557),a=new DataView(await t.slice(t.size-e).arrayBuffer()),i=-1;for(let m=a.byteLength-22;m>=0;m--)if(a.getUint32(m,!0)===101010256){i=m;break}if(i<0)throw q("this is not a ZIP (no end record)","not-a-model");let o=a.getUint16(i+10,!0),n=a.getUint32(i+12,!0),s=a.getUint32(i+16,!0);if(o===65535||n===4294967295||s===4294967295)throw q("ZIP64 packages are not supported","too-large");if(o>mt.entries)throw q(`the package has ${o} entries, more than ${mt.entries}`,"too-large");let r=new DataView(await t.slice(s,s+n).arrayBuffer()),h=new TextDecoder,c=new Map,y=0;for(let m=0,d=0;d<o;d++){if(m+46>r.byteLength||r.getUint32(m,!0)!==33639248)throw q("the package is damaged (central directory)");let f=r.getUint16(m+8,!0),p=r.getUint16(m+10,!0),g=r.getUint32(m+20,!0),x=r.getUint32(m+24,!0),b=r.getUint16(m+28,!0),k=r.getUint16(m+30,!0),w=r.getUint16(m+32,!0),_=r.getUint32(m+42,!0),l=h.decode(new Uint8Array(r.buffer,r.byteOffset+m+46,b));m+=46+b+k+w;let u=l.replace(/\\/g,"/"),A=u.slice(u.lastIndexOf("/")+1);if(u.endsWith("/")||u.startsWith("__MACOSX/")||A.startsWith("._")||A===".DS_Store"||A==="Thumbs.db")continue;if(u.startsWith("/")||/^[A-Za-z]:/.test(u)||u.split("/").some(L=>L===".."||L==="."))throw q(`the package holds a path outside itself: ${l}`);if(f&1)throw q(`${u} is encrypted`);if(c.has(u))throw q(`${u} is in the package twice`);let v=A==="keyforms.json";if(x>(A==="model.json"?mt.modelJson:v?mt.keyforms:mt.bytes)||(y+=x)>mt.bytes)throw q(`${u} is too large (${x} bytes)`,"too-large");let T=new DataView(await t.slice(_,_+30).arrayBuffer());if(T.byteLength<30||T.getUint32(0,!0)!==67324752)throw q(`the package is damaged (${u})`);let R=_+30+T.getUint16(26,!0)+T.getUint16(28,!0),P=t.slice(R,R+g),E=Ra[A.slice(A.lastIndexOf(".")+1).toLowerCase()]||"";if(R+g>t.size)throw q(`the package is damaged (${u} runs past its end)`);if(p===0){if(g!==x)throw q(`the package is damaged (${u})`);c.set(u,P.slice(0,g,E))}else if(p===8){if(!Pa()){if(v){console.warn(`LivLiv: this browser cannot inflate ${u}; the character plays without it`);continue}throw q(`this browser cannot open the compressed ${u} (no DecompressionStream): store it uncompressed`,"missing-feature")}c.set(u,await Sa(P,x,u,E))}else throw q(`${u} uses ZIP method ${p}; a package stores its files or deflates them`)}return c}var jt;function Pa(){if(jt===void 0)try{jt=typeof DecompressionStream<"u"&&!!new DecompressionStream("deflate-raw")}catch{jt=!1}return jt}async function Sa(t,e,a,i){var r;let o=t.stream().pipeThrough(new DecompressionStream("deflate-raw")).getReader(),n=[],s=0;try{for(;;){let{done:h,value:c}=await o.read();if(h)break;if(s+=c.length,s>e)throw o.cancel(),q(`${a} inflates past its ${e} bytes`);n.push(c)}}catch(h){throw(r=h.message)!=null&&r.startsWith(a)?h:q(`the package is damaged (${a}: ${h.message})`)}if(s!==e)throw q(`the package is damaged (${a}: ${s} bytes, ${e} expected)`);return new Blob(n,{type:i})}var qa="0.3.0",Ba={zh:"\u7B11","zh-Hant":"\u7B11",en:"Smile",ja:"\u7B11\u9854"},Fa="this browser has no WebGL2",Ka=class extends pe{puppet;mark;static isSupported(){var e;let t=document.createElement("canvas").getContext("webgl2");return(e=t==null?void 0:t.getExtension("WEBGL_lose_context"))==null||e.loseContext(),!!t}constructor(t,e={}){var i;me(t);let a;try{a=new da(t)}catch(o){throw(i=t.getContext("webgl2"))!=null&&i.isContextLost()?new V("context-lost","LivLiv: this canvas has lost its WebGL context: use a new canvas",{cause:o}):new V("no-webgl",typeof WebGL2RenderingContext>"u"?"LivLiv: this browser has no WebGL2":o.message===Fa?"LivLiv: could not start WebGL2 on this canvas: it is turned off in this browser, or the canvas already draws in 2D":`LivLiv: could not start WebGL2 on this canvas (${o.message})`,{cause:o})}super(t,a.params,e),this.puppet=a,this.puppet.maxDpr=e.maxPixelRatio??2,this.mark=new Ta(this.puppet.gl)}get maxPixelRatio(){return this.puppet.maxDpr}set maxPixelRatio(t){this.puppet.maxDpr=t}get gl(){return this.puppet.gl}get drawable(){return!!this.puppet.model}get clock(){return this.puppet.time}get shownExpr(){return this.puppet.expr}seen(){return this.puppet}canvasToModel(t,e){return this.puppet.canvasToModel(t,e)}poke(t,e,a=1){return this.puppet.poke(t,e,a)}load(t,e={}){return this.start(e,a=>this.loadNow(t,a))}async loadNow(t,e){var h,c,y;let a=this.puppet,{signal:i}=e,o=null;if(typeof t=="string"||t instanceof URL){let m=new URL(String(t),document.baseURI);if(/\.(livliv|zip)$/i.test(m.pathname)){if(e.progress(0),o=await Ua(m.href,e),i.aborted)throw i.reason}else e.progress(0),await a.load(m.href,{pack:!1,signal:i,onImage:(d,f)=>{e.progress(d/f),d===f&&e.build()}}).catch(d=>{throw At(d,m.href)})}else o=t;if(o){e.build();let{model:m,image:d,keyforms:f}=await Xa(o);if(i.aborted)throw i.reason;await a.loadModel(m,d,{keyforms:f,signal:i}).catch(p=>{throw At(p,"model.json")})}if(this.disposed)throw a.dispose(),Ot("the player was disposed");if(a.gl.isContextLost())throw Xt();let n=a.model,s=n.expressions||(n.layers.some(m=>m.id==="expr_smile")?[{id:"smile",label:"",labels:Ba}]:[]);this.info={name:n.name,format:n.format||"livemaker-puppet",version:n.version??3,size:n.canvas,expressions:s.map(({id:m,label:d,labels:f})=>{let p=f||{[ue(d)]:d};return{id:m,label:Ut(p,this.lang,m),labels:p}}),watermark:n.watermark??null,meta:n.meta??null};let r=n.meta?((h=n.meta.watermark)==null?void 0:h.kind)??"none":n.watermark==="LivLiv"?"livliv":n.watermark?"text":"none";return this.mark.set(r,n.watermark??null,((y=(c=n.meta)==null?void 0:c.watermark)==null?void 0:y.center)!==!1),this.neutral(),this.playing||this.resize(),this.info}show(t){let e=this.puppet,a=this.frame,i=this.view;e.view={x:i.x,y:i.y,s:i.zoom},e.focusHead=i.head,e.move={x:a.move.x,y:a.move.y+this.actions.y,s:a.move.s},e.update(t),e.render(),this.mark.draw(performance.now(),e.gl.drawingBufferWidth/Math.max(1,this.canvas.clientWidth))}free(){let t=this.puppet.gl;this.puppet.dispose(),this.mark.dispose(),t.deleteProgram(this.puppet.prog),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT)}};function At(t,e){let a=t;if(a instanceof V||(a==null?void 0:a.name)==="AbortError")return t;let i=String((a==null?void 0:a.message)||t),o=t;return a!=null&&a.status?new V("http",`LivLiv: could not load ${e} (HTTP ${a.status})`,{status:a.status,cause:o}):i.startsWith("image ")?new V("missing-file",`LivLiv: could not load the image ${i.slice(6)}: it is missing, or on another origin that sends no CORS header`,{cause:o}):a instanceof SyntaxError?new V("not-a-model",`LivLiv: ${e} is not a model.json (${i})`,{cause:o}):a instanceof TypeError&&/fetch|load failed|network/i.test(i)?new V("unreachable",`LivLiv: could not load ${e}: unreachable, or on another origin that sends no CORS header`,{cause:o}):new V((a==null?void 0:a.code)??"invalid",i.startsWith("LivLiv")?i:`LivLiv: ${i}`,{cause:o})}var _e=()=>new V("not-a-model","LivLiv: this is a VRM or glTF file, and a Player plays LivLiv models: use a BodyPlayer with VrmBody (@livliv-dev/player/vrm)"),$a=async t=>{let e=new DataView(await t.slice(0,4).arrayBuffer());return e.byteLength===4&&e.getUint32(0,!0)===1179937895};async function Ua(t,e){for(let a=!0;;a=!1)try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw Object.assign(Error(`HTTP ${i.status}`),{status:i.status});return await ye(i,e)}catch(i){if(e.signal.aborted)throw i;let o=i.status;if(o&&o<500)throw At(i,t);if(!a)throw o?At(i,t):new V("unreachable",`LivLiv: could not load ${t}: unreachable or the connection dropped, or on another origin that sends no CORS header`,{cause:i})}}async function Xa(t){let e=new Map,a=f=>f.replace(/\\/g,"/").replace(/^(\.\/|\/)+/,""),i=async f=>{if(await $a(f))throw _e();if(!await Ee(f))throw new V("not-a-model","LivLiv: this file is not a .livliv package (not a ZIP)");return Oa(f).catch(p=>{throw At(p,"the package")})};if(t instanceof Blob)(await i(t)).forEach((f,p)=>e.set(p,f));else if(t instanceof Map)t.forEach((f,p)=>e.set(a(p),f));else if(Symbol.iterator in t)for(let f of t)e.set(a(f.webkitRelativePath||f.name),f);else for(let[f,p]of Object.entries(t))e.set(a(f),p);let o=f=>f==="model.json"||f.endsWith("/model.json");if(!(t instanceof Blob)&&![...e.keys()].some(o)){for(let f of e.values())if(await Ee(f)){let p=await i(f);e.clear(),p.forEach((g,x)=>e.set(x,g));break}}let n=[...e.keys()].filter(o).sort((f,p)=>f.length-p.length)[0];if(!n&&[...e.keys()].some(f=>/\.(vrm|glb)$/i.test(f)))throw _e();if(!n)throw new V("missing-file","LivLiv: no model.json among the files");let s=n.slice(0,n.length-10);if(e.get(n).size>mt.modelJson)throw new V("too-large",`LivLiv: ${n} is larger than ${mt.modelJson} bytes`);let r;try{r=It(JSON.parse(await e.get(n).text()))}catch(f){throw At(f,n)}let h=new Map;e.forEach((f,p)=>h.set(p.slice(p.lastIndexOf("/")+1),f));let c=f=>e.get(s+a(f))??h.get(f.slice(f.lastIndexOf("/")+1)),y=f=>{let p=c(f);return p?qt(p):Promise.reject(new V("missing-file",`LivLiv: ${f} is not among the files`))},m,d=r.keyforms?c(r.keyforms):void 0;return d&&d.size<=mt.keyforms&&(m=await d.text().then(f=>JSON.parse(f)).catch(()=>{})),r.keyforms&&!m&&console.warn(`LivLiv: ${r.keyforms} is missing or unreadable; the character plays on the rig alone`),{model:r,image:y,keyforms:m}}export{Fe as FORMAT,$e as FORMAT_VERSION,fe as LEGACY_FORMAT,V as LivLivError,ft as PARAM_RANGES,Ka as Player,qa as VERSION,kt as defaultParams};
Binary file
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ # 形象来源
2
+
3
+ 大肥鱼、Claude 大小姐、GPT 龙娘的形象参考了社区二创:鲸鱼娘源于 B 站 UP 主「上善无形」的原创角色「溟月」,Claude 娘、GPT 娘等 AI 娘形象最早见于画师 ZipZipPipe(胖次狐)。我们用网络上流传的图片垫图,经 AI 重新生成为现在的 Q 版形象。如果你是权利人并有异议,请联系我们,我们会及时修改或删除。Sho 酱为鱼Sho 原创形象。
4
+
5
+ 本文件夹里 `live/dafeiyu.livliv`、`live/claude.livliv`、`live/gpt.livliv` 和 `looks/dafeiyu.webp`、`looks/claude.webp`、`looks/gpt.webp` 这几个形象文件不属于本项目代码的开源许可,单独说明如上。
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file