@holoscript/core 7.0.0 → 8.0.0

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 (345) hide show
  1. package/README.md +2 -2
  2. package/bin/holoscript.cjs +3 -0
  3. package/dist/GLTFPipeline-276GE64O.js +16 -0
  4. package/dist/GLTFPipeline-M7WSSJED.cjs +37 -0
  5. package/dist/HoloScriptPlusParser-7FBIFUFC.js +693 -0
  6. package/dist/HoloScriptPlusParser-A2W7OCN2.cjs +698 -0
  7. package/dist/HoloScriptPlusParser-F2Z56FJR.js +10 -0
  8. package/dist/HoloScriptPlusParser-WKHRIH6T.cjs +27 -0
  9. package/dist/HoloScriptRuntime-3URVTKPJ.js +10 -0
  10. package/dist/HoloScriptRuntime-SXEAEU2N.cjs +19 -0
  11. package/dist/USDZExporter-3FWJ25JI.cjs +1037 -0
  12. package/dist/USDZExporter-D2HQLQYK.js +1035 -0
  13. package/dist/agents/index.cjs +19 -0
  14. package/dist/agents/index.d.ts +100 -0
  15. package/dist/agents/index.js +17 -0
  16. package/dist/chunk-23J755AR.js +1046 -0
  17. package/dist/chunk-253GBQZY.cjs +627 -0
  18. package/dist/chunk-25IQCHTO.cjs +781 -0
  19. package/dist/chunk-2BSMSUCE.js +1941 -0
  20. package/dist/chunk-2M2DPHKB.js +762 -0
  21. package/dist/chunk-2YSNA2F2.cjs +1274 -0
  22. package/dist/chunk-3AO425MZ.cjs +886 -0
  23. package/dist/chunk-3FOKASKO.cjs +348 -0
  24. package/dist/chunk-3HYYMEXI.cjs +56578 -0
  25. package/dist/chunk-3NFFOWGG.js +4287 -0
  26. package/dist/chunk-3WZEJHUQ.cjs +116 -0
  27. package/dist/chunk-4C57PR42.js +468 -0
  28. package/dist/chunk-4N4SXXWF.js +769 -0
  29. package/dist/chunk-4PDEPEQW.cjs +41 -0
  30. package/dist/chunk-4R6SBXDB.js +45 -0
  31. package/dist/chunk-4V2E7U7Q.cjs +2015 -0
  32. package/dist/chunk-5FSKKMR7.cjs +2092 -0
  33. package/dist/chunk-5GLCTO44.js +161 -0
  34. package/dist/chunk-5JEU52DW.js +382 -0
  35. package/dist/chunk-5S7RKFGR.cjs +446 -0
  36. package/dist/chunk-5WUNN6ZN.cjs +428 -0
  37. package/dist/chunk-62FBK3B7.js +70 -0
  38. package/dist/chunk-6CTRH7HT.cjs +1985 -0
  39. package/dist/chunk-6DPSFNJB.cjs +847 -0
  40. package/dist/chunk-6EX3I5P4.cjs +130 -0
  41. package/dist/chunk-73FELZVJ.cjs +611 -0
  42. package/dist/chunk-7CUEMLDZ.cjs +6445 -0
  43. package/dist/chunk-7HIASF7S.cjs +814 -0
  44. package/dist/chunk-A6KINLZJ.js +236 -0
  45. package/dist/chunk-AIA52I7T.cjs +543 -0
  46. package/dist/chunk-ANXZFVY2.js +113 -0
  47. package/dist/chunk-AYBXB26F.js +2176 -0
  48. package/dist/chunk-B4TFTDG4.js +449 -0
  49. package/dist/chunk-BE4UJCQT.js +623 -0
  50. package/dist/chunk-BRQJKJGT.cjs +20 -0
  51. package/dist/chunk-C2A5DUMF.cjs +689 -0
  52. package/dist/chunk-C37BHB7N.cjs +636 -0
  53. package/dist/chunk-CBJY23VL.js +126 -0
  54. package/dist/chunk-CIWWXYHZ.cjs +50 -0
  55. package/dist/chunk-CXFDRBQU.cjs +672 -0
  56. package/dist/chunk-D54CNIAJ.cjs +413 -0
  57. package/dist/chunk-DAJXW4KX.js +725 -0
  58. package/dist/chunk-DTGBOSEM.cjs +319 -0
  59. package/dist/chunk-E7JP3BS3.cjs +61 -0
  60. package/dist/chunk-EKBKLK7P.js +1169 -0
  61. package/dist/chunk-EKYL4PE3.cjs +404 -0
  62. package/dist/chunk-EUDQTK7N.cjs +4310 -0
  63. package/dist/chunk-EXKSFGSX.cjs +274 -0
  64. package/dist/chunk-EXUP2BUM.cjs +1173 -0
  65. package/dist/chunk-F43YAA34.js +623 -0
  66. package/dist/chunk-FDSGHPAK.js +130 -0
  67. package/dist/chunk-FEWUHQNM.cjs +144 -0
  68. package/dist/chunk-FGGJQRLZ.js +270 -0
  69. package/dist/chunk-FHP6LXJS.js +415 -0
  70. package/dist/chunk-FJPADH77.cjs +666 -0
  71. package/dist/chunk-FYSPZT4V.cjs +169 -0
  72. package/dist/chunk-GIOYPNTH.js +5575 -0
  73. package/dist/chunk-GJNCFRJU.cjs +125 -0
  74. package/dist/chunk-GMP623FG.cjs +1508 -0
  75. package/dist/chunk-GQHQOPXZ.cjs +5580 -0
  76. package/dist/chunk-GQT4TYKY.cjs +4381 -0
  77. package/dist/chunk-GTU2Z2WW.cjs +262 -0
  78. package/dist/chunk-GYZE55MO.js +2007 -0
  79. package/dist/chunk-GZG4KA4E.js +529 -0
  80. package/dist/chunk-H652NHX5.js +600 -0
  81. package/dist/chunk-HCCQLAA4.cjs +74 -0
  82. package/dist/chunk-HINXWAOD.cjs +1049 -0
  83. package/dist/chunk-HYNTS5CP.js +422 -0
  84. package/dist/chunk-HZSPDCXV.cjs +457 -0
  85. package/dist/chunk-HZTDET3N.js +1399 -0
  86. package/dist/chunk-I6XZ5DZF.cjs +488 -0
  87. package/dist/chunk-ILRBGFVD.cjs +72 -0
  88. package/dist/chunk-IPWSXCCN.js +1183 -0
  89. package/dist/chunk-IUTY5WQ2.cjs +424 -0
  90. package/dist/chunk-IVSZDECV.js +882 -0
  91. package/dist/chunk-IVY74O6C.js +247 -0
  92. package/dist/chunk-IZM5VQZD.js +714 -0
  93. package/dist/chunk-J32ZJZJH.js +554 -0
  94. package/dist/chunk-J6M4FPK5.js +421 -0
  95. package/dist/chunk-JC5YBPSF.cjs +984 -0
  96. package/dist/chunk-JCLBKPMX.js +3813 -0
  97. package/dist/chunk-JD7CIZ33.js +1949 -0
  98. package/dist/chunk-JIYN45TV.cjs +2525 -0
  99. package/dist/chunk-JJBE3TIH.cjs +1189 -0
  100. package/dist/chunk-JX7YL6ZE.js +2252 -0
  101. package/dist/chunk-K4VVR7CN.cjs +2433 -0
  102. package/dist/chunk-KEFNV2WM.cjs +2257 -0
  103. package/dist/chunk-KH4CNH66.cjs +424 -0
  104. package/dist/chunk-KJLB4OPV.js +5731 -0
  105. package/dist/chunk-KKFZ3B6J.cjs +557 -0
  106. package/dist/chunk-KKP7JKN4.cjs +6002 -0
  107. package/dist/chunk-KPJL34Y7.cjs +186 -0
  108. package/dist/chunk-KQCN6AKJ.cjs +3042 -0
  109. package/dist/chunk-KVRSTFNH.cjs +72 -0
  110. package/dist/chunk-LICPB5HZ.cjs +1409 -0
  111. package/dist/chunk-LM2VU56C.cjs +37 -0
  112. package/dist/chunk-M56JSP4A.js +400 -0
  113. package/dist/chunk-MBOOR7X4.js +18 -0
  114. package/dist/chunk-MGE5Z4GS.js +608 -0
  115. package/dist/chunk-MXFUTKCO.js +56 -0
  116. package/dist/chunk-MYY4PMWX.cjs +264 -0
  117. package/dist/chunk-N75IH2HY.js +258 -0
  118. package/dist/chunk-NBMHU6SW.js +669 -0
  119. package/dist/chunk-NG77ATEW.cjs +778 -0
  120. package/dist/chunk-NGKREZ36.js +6384 -0
  121. package/dist/chunk-NHWSN2SD.cjs +718 -0
  122. package/dist/chunk-NV4VMVXU.js +421 -0
  123. package/dist/chunk-NW5G5FBQ.js +215 -0
  124. package/dist/chunk-NXZFOPVD.cjs +5737 -0
  125. package/dist/chunk-OBIYPYYS.cjs +1993 -0
  126. package/dist/chunk-OIQYIIO3.cjs +473 -0
  127. package/dist/chunk-OL46QLBJ.js +61 -0
  128. package/dist/chunk-OMXII44L.js +5386 -0
  129. package/dist/chunk-OR4Q2BGL.cjs +759 -0
  130. package/dist/chunk-OSYNRVOV.cjs +243 -0
  131. package/dist/chunk-PGANYCAG.cjs +220 -0
  132. package/dist/chunk-PHENW4MQ.js +65 -0
  133. package/dist/chunk-PHVRG4I2.js +844 -0
  134. package/dist/chunk-Q56TT7IL.js +483 -0
  135. package/dist/chunk-QPOQ7VPI.js +1491 -0
  136. package/dist/chunk-QPSKHBJP.js +5963 -0
  137. package/dist/chunk-QXH7QDSZ.js +1989 -0
  138. package/dist/chunk-R75BSDH7.cjs +50 -0
  139. package/dist/chunk-RARB3MBR.js +207 -0
  140. package/dist/chunk-RVBHAXFG.js +56160 -0
  141. package/dist/chunk-S3MDHNKB.cjs +490 -0
  142. package/dist/chunk-S4W6Z2MN.js +2426 -0
  143. package/dist/chunk-S6YWHCKV.cjs +410 -0
  144. package/dist/chunk-SIEXCILW.js +229 -0
  145. package/dist/chunk-SJBGLS25.cjs +2196 -0
  146. package/dist/chunk-SLU6UPJI.cjs +410 -0
  147. package/dist/chunk-SMIWS6DE.cjs +212 -0
  148. package/dist/chunk-T2QCTZMO.js +811 -0
  149. package/dist/chunk-T5J7ZKP3.cjs +4885 -0
  150. package/dist/chunk-TDCNJHWO.js +341 -0
  151. package/dist/chunk-TG7O4WBC.js +406 -0
  152. package/dist/chunk-THCK6ECW.js +2085 -0
  153. package/dist/chunk-TJHVSBP2.js +439 -0
  154. package/dist/chunk-TVHSPJ4N.cjs +606 -0
  155. package/dist/chunk-U44IKGG7.cjs +5390 -0
  156. package/dist/chunk-UJXISJBN.js +487 -0
  157. package/dist/chunk-UM6C3CGK.js +4375 -0
  158. package/dist/chunk-UMABK6SI.js +686 -0
  159. package/dist/chunk-UOIGFQXC.cjs +9750 -0
  160. package/dist/chunk-URG2SJLK.js +2521 -0
  161. package/dist/chunk-V6MKC2FZ.js +979 -0
  162. package/dist/chunk-VECQYRXL.js +474 -0
  163. package/dist/chunk-VJ3L7CHT.cjs +169 -0
  164. package/dist/chunk-VMLKSV26.js +1216 -0
  165. package/dist/chunk-VVKVQZI6.js +55 -0
  166. package/dist/chunk-W6RW64BB.cjs +1219 -0
  167. package/dist/chunk-W7VDOASB.cjs +639 -0
  168. package/dist/chunk-WDT3JTGM.cjs +483 -0
  169. package/dist/chunk-WJIHFLMJ.js +404 -0
  170. package/dist/chunk-WKX5AMOY.js +309 -0
  171. package/dist/chunk-WNNE3PO3.js +34 -0
  172. package/dist/chunk-WRKUDAZJ.js +3038 -0
  173. package/dist/chunk-WRLUBRKS.cjs +1943 -0
  174. package/dist/chunk-WRNEH5MO.js +3169 -0
  175. package/dist/chunk-WRWEX5ZF.js +658 -0
  176. package/dist/chunk-X3GJPRVK.cjs +3246 -0
  177. package/dist/chunk-XHIV6326.cjs +793 -0
  178. package/dist/chunk-XIVIE43A.cjs +729 -0
  179. package/dist/chunk-XJAN7CZG.cjs +432 -0
  180. package/dist/chunk-XKTPFXGA.js +164 -0
  181. package/dist/chunk-XL6INWKT.js +121 -0
  182. package/dist/chunk-XSFNHP2E.js +632 -0
  183. package/dist/chunk-XT6JY5W5.js +9684 -0
  184. package/dist/chunk-XUILI4KB.cjs +430 -0
  185. package/dist/chunk-XUUVDHIF.cjs +3962 -0
  186. package/dist/chunk-YF2I3MV3.js +46 -0
  187. package/dist/chunk-YIMN575O.js +4847 -0
  188. package/dist/chunk-YIVFJNYV.js +176 -0
  189. package/dist/chunk-YKGPCZEE.cjs +237 -0
  190. package/dist/chunk-YN6V7R3L.cjs +327 -0
  191. package/dist/chunk-YQELFNJV.js +39 -0
  192. package/dist/chunk-YYXH45E2.js +426 -0
  193. package/dist/chunk-ZBQXLH2L.js +756 -0
  194. package/dist/chunk-ZDSYWBIE.cjs +69 -0
  195. package/dist/chunk-ZU7NIRT6.js +325 -0
  196. package/dist/chunk-ZZ7RO2UQ.js +1243 -0
  197. package/dist/chunk-ZZEI7MV4.js +778 -0
  198. package/dist/cli/holoscript-runner.cjs +2255 -0
  199. package/dist/cli/holoscript-runner.js +2230 -0
  200. package/dist/codebase/index.cjs +336 -0
  201. package/dist/codebase/index.js +331 -0
  202. package/dist/compiler/agent-inference.cjs +31 -0
  203. package/dist/compiler/agent-inference.js +8 -0
  204. package/dist/compiler/android-xr.cjs +24 -0
  205. package/dist/compiler/android-xr.js +14 -0
  206. package/dist/compiler/android.cjs +24 -0
  207. package/dist/compiler/android.js +14 -0
  208. package/dist/compiler/ar.cjs +23 -0
  209. package/dist/compiler/ar.js +11 -0
  210. package/dist/compiler/babylon.cjs +21 -0
  211. package/dist/compiler/babylon.js +15 -0
  212. package/dist/compiler/business-quest.cjs +43 -0
  213. package/dist/compiler/business-quest.js +4 -0
  214. package/dist/compiler/coco.cjs +27 -0
  215. package/dist/compiler/coco.js +4 -0
  216. package/dist/compiler/context.cjs +25 -0
  217. package/dist/compiler/context.d.ts +28 -0
  218. package/dist/compiler/context.js +8 -0
  219. package/dist/compiler/domain-block-utils.cjs +605 -0
  220. package/dist/compiler/domain-block-utils.js +11 -0
  221. package/dist/compiler/dtdl.cjs +27 -0
  222. package/dist/compiler/dtdl.js +11 -0
  223. package/dist/compiler/gltf-pipeline.cjs +39 -0
  224. package/dist/compiler/gltf-pipeline.js +4 -0
  225. package/dist/compiler/godot.cjs +18 -0
  226. package/dist/compiler/godot.js +12 -0
  227. package/dist/compiler/incremental.cjs +34 -0
  228. package/dist/compiler/incremental.js +9 -0
  229. package/dist/compiler/index.cjs +5860 -0
  230. package/dist/compiler/index.d.ts +322 -21
  231. package/dist/compiler/index.js +5525 -0
  232. package/dist/compiler/ios.cjs +23 -0
  233. package/dist/compiler/ios.js +13 -0
  234. package/dist/compiler/llm-provider-capabilities.cjs +25 -0
  235. package/dist/compiler/llm-provider-capabilities.d.ts +43 -0
  236. package/dist/compiler/llm-provider-capabilities.js +8 -0
  237. package/dist/compiler/multi-layer.cjs +24 -0
  238. package/dist/compiler/multi-layer.js +15 -0
  239. package/dist/compiler/nodetoy.cjs +23 -0
  240. package/dist/compiler/nodetoy.js +4 -0
  241. package/dist/compiler/openxr.cjs +19 -0
  242. package/dist/compiler/openxr.js +13 -0
  243. package/dist/compiler/playcanvas.cjs +19 -0
  244. package/dist/compiler/playcanvas.js +13 -0
  245. package/dist/compiler/r3f.cjs +38 -0
  246. package/dist/compiler/r3f.d.ts +22 -0
  247. package/dist/compiler/r3f.js +16 -0
  248. package/dist/compiler/remotion.cjs +23 -0
  249. package/dist/compiler/remotion.js +4 -0
  250. package/dist/compiler/reproducibility.cjs +39 -0
  251. package/dist/compiler/reproducibility.js +4 -0
  252. package/dist/compiler/sdf.cjs +24 -0
  253. package/dist/compiler/sdf.js +12 -0
  254. package/dist/compiler/semantic-scene.cjs +31 -0
  255. package/dist/compiler/semantic-scene.js +4 -0
  256. package/dist/compiler/state.cjs +21 -0
  257. package/dist/compiler/state.js +11 -0
  258. package/dist/compiler/trait-composition.cjs +30 -0
  259. package/dist/compiler/trait-composition.js +9 -0
  260. package/dist/compiler/unity.cjs +19 -0
  261. package/dist/compiler/unity.js +13 -0
  262. package/dist/compiler/unreal.cjs +23 -0
  263. package/dist/compiler/unreal.js +13 -0
  264. package/dist/compiler/urdf.cjs +52 -0
  265. package/dist/compiler/urdf.js +12 -0
  266. package/dist/compiler/usd-physics.cjs +26 -0
  267. package/dist/compiler/usd-physics.js +9 -0
  268. package/dist/compiler/visionos.cjs +19 -0
  269. package/dist/compiler/visionos.js +13 -0
  270. package/dist/compiler/vrchat.cjs +22 -0
  271. package/dist/compiler/vrchat.js +12 -0
  272. package/dist/compiler/vrr.cjs +24 -0
  273. package/dist/compiler/vrr.js +12 -0
  274. package/dist/compiler/wasm.cjs +36 -0
  275. package/dist/compiler/wasm.js +12 -0
  276. package/dist/compiler/webgpu.cjs +18 -0
  277. package/dist/compiler/webgpu.js +12 -0
  278. package/dist/coordinators/index.cjs +1266 -0
  279. package/dist/coordinators/index.d.ts +72 -1
  280. package/dist/coordinators/index.js +1259 -0
  281. package/dist/debugger.cjs +24 -0
  282. package/dist/debugger.js +11 -0
  283. package/dist/entries/interop.cjs +64 -0
  284. package/dist/entries/interop.js +7 -0
  285. package/dist/entries/scripting.cjs +55 -0
  286. package/dist/entries/scripting.js +10 -0
  287. package/dist/hololand/index.cjs +146 -0
  288. package/dist/hololand/index.d.ts +70 -0
  289. package/dist/hololand/index.js +5 -0
  290. package/dist/index.cjs +43233 -0
  291. package/dist/index.d.ts +976 -21
  292. package/dist/index.js +39995 -0
  293. package/dist/math/tropical-spmv.cjs +45 -0
  294. package/dist/math/tropical-spmv.js +4 -0
  295. package/dist/math/vec3.cjs +57 -0
  296. package/dist/math/vec3.js +4 -0
  297. package/dist/ml-dsa-FSKBTE3W.cjs +1265 -0
  298. package/dist/ml-dsa-Z7JDKW4L.js +1265 -0
  299. package/dist/paper-0c-spike/index.cjs +150 -0
  300. package/dist/paper-0c-spike/index.js +141 -0
  301. package/dist/parser.cjs +61 -0
  302. package/dist/parser.d.ts +11 -0
  303. package/dist/parser.js +12 -0
  304. package/dist/playwright-3AT3AKTV.cjs +98673 -0
  305. package/dist/playwright-VZPDVUEQ.js +98660 -0
  306. package/dist/reconstruction/index.cjs +153 -0
  307. package/dist/reconstruction/index.d.ts +29 -2
  308. package/dist/reconstruction/index.js +8 -0
  309. package/dist/runtime.cjs +316 -0
  310. package/dist/runtime.d.ts +61 -0
  311. package/dist/runtime.js +31 -0
  312. package/dist/self-improvement/index.cjs +563 -0
  313. package/dist/self-improvement/index.js +545 -0
  314. package/dist/storage/index.cjs +38 -0
  315. package/dist/storage/index.js +5 -0
  316. package/dist/testing.cjs +25 -0
  317. package/dist/testing.d.ts +70 -0
  318. package/dist/testing.js +4 -0
  319. package/dist/traitDocs/traitDocs.cjs +33 -0
  320. package/dist/traitDocs/traitDocs.js +7 -0
  321. package/dist/traits/botanical-lotus.cjs +41 -0
  322. package/dist/traits/botanical-lotus.d.ts +172 -0
  323. package/dist/traits/botanical-lotus.js +4 -0
  324. package/dist/traits/engines/index.cjs +520 -0
  325. package/dist/traits/engines/index.js +380 -0
  326. package/dist/traits/index.cjs +24409 -0
  327. package/dist/traits/index.d.ts +171 -35
  328. package/dist/traits/index.js +21634 -0
  329. package/dist/traits/simulation-solver-factory.cjs +13 -0
  330. package/dist/traits/simulation-solver-factory.d.ts +23 -0
  331. package/dist/traits/simulation-solver-factory.js +4 -0
  332. package/dist/traits/webcam-gaze.cjs +35 -0
  333. package/dist/traits/webcam-gaze.d.ts +17 -0
  334. package/dist/traits/webcam-gaze.js +4 -0
  335. package/dist/type-checker.cjs +19 -0
  336. package/dist/type-checker.js +6 -0
  337. package/dist/world/index.cjs +947 -0
  338. package/dist/world/index.d.ts +147 -0
  339. package/dist/world/index.js +939 -0
  340. package/dist/world-model/index.cjs +1446 -0
  341. package/dist/world-model/index.d.ts +119 -0
  342. package/dist/world-model/index.js +1414 -0
  343. package/dist/wot/index.cjs +29 -0
  344. package/dist/wot/index.js +4 -0
  345. package/package.json +93 -49
@@ -0,0 +1,348 @@
1
+ 'use strict';
2
+
3
+ // src/traits/WebcamGazeTrait.ts
4
+ var LEFT_EYE_CORNERS = [33, 133];
5
+ var RIGHT_EYE_CORNERS = [362, 263];
6
+ var LEFT_IRIS = [468, 469, 470, 471, 472];
7
+ var RIGHT_IRIS = [473, 474, 475, 476, 477];
8
+ var DEFAULT_WEBCAM_GAZE_CONFIG = {
9
+ auto_start: false,
10
+ video_width: 640,
11
+ video_height: 480,
12
+ sample_rate_hz: 30,
13
+ confidence_threshold: 0.35,
14
+ wasm_base_path: "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision/wasm",
15
+ model_asset_path: "https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task",
16
+ gaze_gain_x: 1.35,
17
+ gaze_gain_y: 1.8,
18
+ max_ray_angle_degrees: 10
19
+ };
20
+ function clamp01(value) {
21
+ if (!Number.isFinite(value)) return 0.5;
22
+ return Math.min(1, Math.max(0, value));
23
+ }
24
+ function clamp(value, min, max) {
25
+ if (!Number.isFinite(value)) return min;
26
+ return Math.min(max, Math.max(min, value));
27
+ }
28
+ function meanLandmark(landmarks, indices) {
29
+ let x = 0;
30
+ let y = 0;
31
+ let z = 0;
32
+ let count = 0;
33
+ for (const index of indices) {
34
+ const point = landmarks[index];
35
+ if (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y)) continue;
36
+ x += point.x;
37
+ y += point.y;
38
+ z += point.z ?? 0;
39
+ count += 1;
40
+ }
41
+ if (count === 0) return null;
42
+ return { x: x / count, y: y / count, z: z / count };
43
+ }
44
+ function distance2D(a, b) {
45
+ const dx = a.x - b.x;
46
+ const dy = a.y - b.y;
47
+ return Math.sqrt(dx * dx + dy * dy);
48
+ }
49
+ function estimateEyeOffset(landmarks, cornerIndices, irisIndices) {
50
+ const a = landmarks[cornerIndices[0]];
51
+ const b = landmarks[cornerIndices[1]];
52
+ const iris = meanLandmark(landmarks, irisIndices);
53
+ if (!a || !b || !iris) return null;
54
+ const span = Math.max(distance2D(a, b), 1e-4);
55
+ const midX = (a.x + b.x) * 0.5;
56
+ const midY = (a.y + b.y) * 0.5;
57
+ const verticalSpan = Math.max(span * 0.45, 1e-4);
58
+ return {
59
+ x: (iris.x - midX) / span,
60
+ y: (iris.y - midY) / verticalSpan,
61
+ span
62
+ };
63
+ }
64
+ function estimateWebcamGazeFromLandmarks(landmarks, config = {}) {
65
+ const resolved = { ...DEFAULT_WEBCAM_GAZE_CONFIG, ...config };
66
+ const left = estimateEyeOffset(landmarks, LEFT_EYE_CORNERS, LEFT_IRIS);
67
+ const right = estimateEyeOffset(landmarks, RIGHT_EYE_CORNERS, RIGHT_IRIS);
68
+ const eyes = [left, right].filter((eye) => Boolean(eye));
69
+ if (eyes.length === 0) return null;
70
+ const avgX = eyes.reduce((sum, eye) => sum + eye.x, 0) / eyes.length;
71
+ const avgY = eyes.reduce((sum, eye) => sum + eye.y, 0) / eyes.length;
72
+ const avgSpan = eyes.reduce((sum, eye) => sum + eye.span, 0) / eyes.length;
73
+ const gazeX = clamp01(0.5 + avgX * resolved.gaze_gain_x);
74
+ const gazeY = clamp01(0.5 + avgY * resolved.gaze_gain_y);
75
+ const confidence = clamp(avgSpan / 0.08, 0, 1);
76
+ return {
77
+ gaze_x: gazeX,
78
+ gaze_y: gazeY,
79
+ foveal_center: [gazeX * 2 - 1, 1 - gazeY * 2],
80
+ confidence,
81
+ timestamp: Date.now(),
82
+ source: "webcam"
83
+ };
84
+ }
85
+ function webcamGazeToRay(sample, maxAngleDegrees = DEFAULT_WEBCAM_GAZE_CONFIG.max_ray_angle_degrees) {
86
+ const angle = maxAngleDegrees * Math.PI / 180;
87
+ const yaw = sample.foveal_center[0] * angle;
88
+ const pitch = sample.foveal_center[1] * angle;
89
+ const x = Math.tan(yaw);
90
+ const y = Math.tan(pitch);
91
+ const z = -1;
92
+ const len = Math.sqrt(x * x + y * y + z * z) || 1;
93
+ return [x / len, y / len, z / len];
94
+ }
95
+ function firstFaceSample(result, config) {
96
+ const face = result.faceLandmarks[0];
97
+ if (!face) return null;
98
+ return estimateWebcamGazeFromLandmarks(face, config);
99
+ }
100
+ function parseLandmarks(value) {
101
+ if (!Array.isArray(value)) return null;
102
+ const out = [];
103
+ for (const item of value) {
104
+ if (!item || typeof item !== "object") return null;
105
+ const record = item;
106
+ if (typeof record.x !== "number" || typeof record.y !== "number") return null;
107
+ out.push({
108
+ x: record.x,
109
+ y: record.y,
110
+ z: typeof record.z === "number" ? record.z : void 0
111
+ });
112
+ }
113
+ return out;
114
+ }
115
+ function errorFromUnknown(error) {
116
+ return error instanceof Error ? error : new Error(String(error));
117
+ }
118
+ function mediaPipeNow() {
119
+ if (typeof performance !== "undefined" && typeof performance.now === "function") {
120
+ return performance.now();
121
+ }
122
+ return Date.now();
123
+ }
124
+ var WebcamGazeTracker = class {
125
+ constructor(options) {
126
+ this.ownsVideoElement = false;
127
+ this.stream = null;
128
+ this.landmarker = null;
129
+ this.frameHandle = null;
130
+ this.lastRunAt = 0;
131
+ this.running = false;
132
+ this.config = options.config;
133
+ this.onSample = options.onSample;
134
+ this.onError = options.onError;
135
+ this.videoElement = options.videoElement ?? null;
136
+ }
137
+ getStream() {
138
+ return this.stream;
139
+ }
140
+ getVideoElement() {
141
+ return this.videoElement;
142
+ }
143
+ async start() {
144
+ if (this.running) return;
145
+ if (typeof navigator === "undefined" || !navigator.mediaDevices?.getUserMedia) {
146
+ throw new Error("WebcamGaze: navigator.mediaDevices.getUserMedia is unavailable.");
147
+ }
148
+ if (typeof document === "undefined" && !this.videoElement) {
149
+ throw new Error("WebcamGaze: a video element is required outside the browser DOM.");
150
+ }
151
+ const vision = await import('@mediapipe/tasks-vision');
152
+ const wasmFileset = await vision.FilesetResolver.forVisionTasks(this.config.wasm_base_path);
153
+ this.landmarker = await vision.FaceLandmarker.createFromOptions(wasmFileset, {
154
+ baseOptions: { modelAssetPath: this.config.model_asset_path },
155
+ runningMode: "VIDEO",
156
+ numFaces: 1,
157
+ outputFaceBlendshapes: false,
158
+ outputFacialTransformationMatrixes: false
159
+ });
160
+ this.stream = await navigator.mediaDevices.getUserMedia({
161
+ video: {
162
+ width: { ideal: this.config.video_width },
163
+ height: { ideal: this.config.video_height },
164
+ facingMode: "user"
165
+ },
166
+ audio: false
167
+ });
168
+ if (!this.videoElement) {
169
+ this.videoElement = document.createElement("video");
170
+ this.ownsVideoElement = true;
171
+ }
172
+ this.videoElement.srcObject = this.stream;
173
+ this.videoElement.muted = true;
174
+ this.videoElement.playsInline = true;
175
+ await this.videoElement.play();
176
+ this.running = true;
177
+ this.scheduleFrame();
178
+ }
179
+ stop() {
180
+ this.running = false;
181
+ if (this.frameHandle !== null && typeof window !== "undefined") {
182
+ window.cancelAnimationFrame(this.frameHandle);
183
+ this.frameHandle = null;
184
+ }
185
+ this.stream?.getTracks().forEach((track) => track.stop());
186
+ this.stream = null;
187
+ this.landmarker?.close?.();
188
+ this.landmarker = null;
189
+ if (this.videoElement) {
190
+ this.videoElement.pause();
191
+ this.videoElement.srcObject = null;
192
+ if (this.ownsVideoElement) this.videoElement.remove();
193
+ }
194
+ this.videoElement = null;
195
+ this.ownsVideoElement = false;
196
+ }
197
+ scheduleFrame() {
198
+ if (!this.running || typeof window === "undefined") return;
199
+ this.frameHandle = window.requestAnimationFrame(() => this.tick());
200
+ }
201
+ tick() {
202
+ if (!this.running || !this.landmarker || !this.videoElement) return;
203
+ const now = mediaPipeNow();
204
+ const minIntervalMs = 1e3 / Math.max(1, this.config.sample_rate_hz);
205
+ if (now - this.lastRunAt >= minIntervalMs && this.videoElement.readyState >= 2) {
206
+ try {
207
+ const result = this.landmarker.detectForVideo(this.videoElement, now);
208
+ const sample = firstFaceSample(result, this.config);
209
+ if (sample && sample.confidence >= this.config.confidence_threshold) {
210
+ this.onSample(sample);
211
+ }
212
+ this.lastRunAt = now;
213
+ } catch (error) {
214
+ this.onError?.(errorFromUnknown(error));
215
+ }
216
+ }
217
+ this.scheduleFrame();
218
+ }
219
+ };
220
+ function emitWebcamGazeSample(node, config, context, sample) {
221
+ const direction = webcamGazeToRay(sample, config.max_ray_angle_degrees);
222
+ context.emit?.("webcam_gaze_update", { node, ...sample });
223
+ context.emit?.("foveal_center_update", {
224
+ node,
225
+ foveal_center: sample.foveal_center,
226
+ confidence: sample.confidence,
227
+ source: sample.source
228
+ });
229
+ context.emit?.("avatar_input_sample", {
230
+ type: "avatar_input_sample",
231
+ node,
232
+ device: "eye_tracking",
233
+ axes: {
234
+ gaze_x: sample.gaze_x,
235
+ gaze_y: sample.gaze_y,
236
+ foveal_x: sample.foveal_center[0],
237
+ foveal_y: sample.foveal_center[1],
238
+ confidence: sample.confidence
239
+ },
240
+ buttons: {}
241
+ });
242
+ context.emit?.("eye_gaze_update", {
243
+ type: "eye_gaze_update",
244
+ node,
245
+ origin: [0, 0, 0],
246
+ direction,
247
+ confidence: sample.confidence,
248
+ source: sample.source
249
+ });
250
+ }
251
+ async function startWebcamGaze(node, config, context) {
252
+ const state = node.__webcamGazeState;
253
+ if (!state || state.tracker) return;
254
+ const tracker = new WebcamGazeTracker({
255
+ config,
256
+ onSample(sample) {
257
+ state.lastSample = sample;
258
+ state.isTracking = true;
259
+ state.error = null;
260
+ emitWebcamGazeSample(node, config, context, sample);
261
+ },
262
+ onError(error) {
263
+ state.error = error.message;
264
+ context.emit?.("webcam_gaze_error", { node, error: error.message });
265
+ }
266
+ });
267
+ state.tracker = tracker;
268
+ try {
269
+ await tracker.start();
270
+ state.isTracking = true;
271
+ context.emit?.("webcam_gaze_started", { node });
272
+ } catch (error) {
273
+ state.tracker = null;
274
+ state.isTracking = false;
275
+ state.error = errorFromUnknown(error).message;
276
+ context.emit?.("webcam_gaze_error", { node, error: state.error });
277
+ }
278
+ }
279
+ var webcamGazeHandler = {
280
+ name: "webcam_gaze",
281
+ defaultConfig: DEFAULT_WEBCAM_GAZE_CONFIG,
282
+ onAttach(node, config, context) {
283
+ const state = {
284
+ tracker: null,
285
+ isTracking: false,
286
+ lastSample: null,
287
+ error: null
288
+ };
289
+ node.__webcamGazeState = state;
290
+ context.emit?.("webcam_gaze_ready", { node, autoStart: config.auto_start });
291
+ if (config.auto_start) {
292
+ void startWebcamGaze(node, config, context);
293
+ }
294
+ },
295
+ onDetach(node, _config, context) {
296
+ const state = node.__webcamGazeState;
297
+ state?.tracker?.stop();
298
+ delete node.__webcamGazeState;
299
+ context.emit?.("webcam_gaze_stopped", { node });
300
+ },
301
+ onEvent(node, config, context, event) {
302
+ const state = node.__webcamGazeState;
303
+ if (!state) return;
304
+ if (event.type === "webcam_gaze_start") {
305
+ void startWebcamGaze(node, config, context);
306
+ return;
307
+ }
308
+ if (event.type === "webcam_gaze_stop") {
309
+ state.tracker?.stop();
310
+ state.tracker = null;
311
+ state.isTracking = false;
312
+ context.emit?.("webcam_gaze_stopped", { node });
313
+ return;
314
+ }
315
+ if (event.type === "webcam_gaze_landmarks") {
316
+ const record = event;
317
+ const landmarks = parseLandmarks(record.landmarks);
318
+ if (!landmarks) {
319
+ context.emit?.("webcam_gaze_error", { node, error: "Invalid landmark payload." });
320
+ return;
321
+ }
322
+ const sample = estimateWebcamGazeFromLandmarks(landmarks, config);
323
+ if (!sample || sample.confidence < config.confidence_threshold) return;
324
+ state.lastSample = sample;
325
+ state.isTracking = true;
326
+ emitWebcamGazeSample(node, config, context, sample);
327
+ return;
328
+ }
329
+ if (event.type === "webcam_gaze_query") {
330
+ context.emit?.("webcam_gaze_state", {
331
+ node,
332
+ isTracking: state.isTracking,
333
+ lastSample: state.lastSample,
334
+ error: state.error
335
+ });
336
+ }
337
+ }
338
+ };
339
+ var WebcamGazeTrait_default = webcamGazeHandler;
340
+
341
+ exports.DEFAULT_WEBCAM_GAZE_CONFIG = DEFAULT_WEBCAM_GAZE_CONFIG;
342
+ exports.WebcamGazeTracker = WebcamGazeTracker;
343
+ exports.WebcamGazeTrait_default = WebcamGazeTrait_default;
344
+ exports.estimateWebcamGazeFromLandmarks = estimateWebcamGazeFromLandmarks;
345
+ exports.webcamGazeHandler = webcamGazeHandler;
346
+ exports.webcamGazeToRay = webcamGazeToRay;
347
+ //# sourceMappingURL=chunk-3FOKASKO.cjs.map
348
+ //# sourceMappingURL=chunk-3FOKASKO.cjs.map