@benev/tact 0.3.0-5 → 0.4.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 (504) hide show
  1. package/README.md +72 -53
  2. package/package.json +18 -20
  3. package/s/_archive/deck/deck.ts +76 -53
  4. package/s/_archive/demo/demo-app/element.ts +17 -0
  5. package/s/_archive/{deck/views/bindings → demo/demo-app}/style.css.ts +4 -0
  6. package/s/_archive/demo/main.bundle.ts +67 -6
  7. package/s/_archive/demo/main.css +6 -8
  8. package/s/_archive/lib/bindings/resolver.ts +61 -0
  9. package/s/_archive/lib/bindings/types.ts +67 -0
  10. package/s/_archive/lib/bindings/utils/action-resolver.ts +51 -0
  11. package/s/_archive/lib/bindings/utils/evaluator.ts +162 -0
  12. package/s/_archive/lib/bindings/utils/hash-bindings.ts +22 -0
  13. package/s/_archive/lib/bindings/utils/intent-coding.ts +50 -0
  14. package/s/_archive/lib/bindings/utils/intent-resolver.ts +52 -0
  15. package/s/_archive/lib/bindings/utils/investigate.ts +47 -0
  16. package/s/_archive/lib/bindings/utils/is-expression.ts +11 -0
  17. package/s/_archive/lib/index.ts +12 -0
  18. package/s/_archive/lib/sampling/sources/example.ts +7 -0
  19. package/s/_archive/lib/sampling/sources/gamepad.ts +63 -0
  20. package/s/_archive/lib/sampling/sources/keyboard.ts +52 -0
  21. package/s/_archive/lib/sampling/sources/pointer.ts +56 -0
  22. package/s/_archive/lib/sampling/sources/sources.ts +13 -0
  23. package/s/_archive/lib/sampling/sources/stick.ts +27 -0
  24. package/s/_archive/lib/sampling/types.ts +11 -0
  25. package/s/_archive/lib/sampling/utils/add-sample.ts +12 -0
  26. package/s/_archive/lib/test.ts +57 -0
  27. package/s/_archive/lib/utils/backwards.ts +6 -0
  28. package/s/_archive/lib/utils/mouse-button.ts +10 -0
  29. package/s/_archive/lib/utils/pad/on-pad.ts +50 -0
  30. package/s/_archive/lib/utils/pad/pad.ts +10 -0
  31. package/s/_archive/lib2/core/decoder/decoder.ts +34 -0
  32. package/s/_archive/lib2/core/decoder/utils/update-input.ts +21 -0
  33. package/s/_archive/lib2/core/encoder/encoder.ts +60 -0
  34. package/s/_archive/lib2/core/encoder/evaluate/context.ts +22 -0
  35. package/s/_archive/lib2/core/encoder/evaluate/evaluate.ts +144 -0
  36. package/s/_archive/lib2/core/encoder/parts/expression-index.ts +27 -0
  37. package/s/_archive/lib2/core/encoder/parts/hash-bindings.ts +22 -0
  38. package/s/_archive/lib2/core/encoder/parts/investigate.ts +50 -0
  39. package/s/_archive/lib2/core/encoder/parts/sampler.ts +22 -0
  40. package/s/_archive/lib2/core/sources/example.ts +9 -0
  41. package/s/_archive/lib2/core/sources/sources.ts +16 -0
  42. package/s/_archive/lib2/core/types.ts +78 -0
  43. package/s/_archive/lib2/core/utils/data.ts +50 -0
  44. package/s/_archive/lib2/core/utils/is-down.ts +5 -0
  45. package/s/_archive/lib2/core/utils/is-expression.ts +11 -0
  46. package/s/_archive/lib3/input/data/decode.ts +25 -0
  47. package/s/_archive/lib3/input/data/encode.ts +24 -0
  48. package/s/_archive/lib3/input/data/params.ts +7 -0
  49. package/s/_archive/lib3/input/decoder.ts +56 -0
  50. package/s/_archive/lib3/input/encoder.ts +99 -0
  51. package/s/_archive/lib3/input/evaluate/context.ts +15 -0
  52. package/s/_archive/lib3/input/evaluate/evaluate.ts +142 -0
  53. package/s/_archive/lib3/input/evaluate/utils/clock.ts +14 -0
  54. package/s/_archive/lib3/input/investigate/hash-bindings.ts +22 -0
  55. package/s/_archive/lib3/input/investigate/investigate.ts +42 -0
  56. package/s/_archive/lib3/input/investigate/is-expression.ts +11 -0
  57. package/s/_archive/lib3/input/investigate/make-input.ts +18 -0
  58. package/s/_archive/lib3/input/investigate/root-index.ts +26 -0
  59. package/s/_archive/lib3/input/mixer.ts +20 -0
  60. package/s/_archive/lib3/input/sources/gamepad.ts +58 -0
  61. package/s/_archive/lib3/input/sources/keyboard.ts +49 -0
  62. package/s/_archive/lib3/input/sources/plain.ts +9 -0
  63. package/s/_archive/lib3/input/sources/pointer.ts +58 -0
  64. package/s/_archive/lib3/input/sources/sources.ts +24 -0
  65. package/s/_archive/lib3/input/sources/stick.ts +29 -0
  66. package/s/_archive/lib3/input/testing/quickbind.ts +20 -0
  67. package/s/_archive/lib3/input/types.ts +96 -0
  68. package/s/_archive/lib3/input/utils/evergreen.ts +10 -0
  69. package/s/_archive/lib3/input/utils/is-down.ts +5 -0
  70. package/s/_archive/lib3/input/utils/mouse-button.ts +10 -0
  71. package/s/_archive/lib3/input/utils/pad/on-pad.ts +50 -0
  72. package/s/_archive/lib3/input/utils/pad/pad.ts +10 -0
  73. package/s/_archive/lib3/input/utils/sampler.ts +28 -0
  74. package/s/_archive/lib3/input/utils/split-axis.ts +15 -0
  75. package/s/_archive/lib3/test.ts +100 -0
  76. package/s/_archive/lib4/input/data/decode.ts +25 -0
  77. package/s/_archive/lib4/input/data/encode.ts +24 -0
  78. package/s/_archive/lib4/input/data/params.ts +7 -0
  79. package/s/_archive/lib4/input/encoder.ts +100 -0
  80. package/s/_archive/lib4/input/evaluate/context.ts +16 -0
  81. package/s/_archive/lib4/input/evaluate/evaluate.ts +157 -0
  82. package/s/_archive/lib4/input/evaluate/utils/clock.ts +14 -0
  83. package/s/_archive/lib4/input/investigate/hash-bindings.ts +22 -0
  84. package/s/_archive/lib4/input/investigate/investigate.ts +37 -0
  85. package/s/_archive/lib4/input/investigate/is.ts +19 -0
  86. package/s/_archive/lib4/input/investigate/make-input.ts +18 -0
  87. package/s/_archive/lib4/input/investigate/root-index.ts +26 -0
  88. package/s/_archive/lib4/input/sources/gamepad.ts +58 -0
  89. package/s/_archive/lib4/input/sources/keyboard.ts +46 -0
  90. package/s/_archive/lib4/input/sources/plain.ts +9 -0
  91. package/s/_archive/lib4/input/sources/pointer.ts +50 -0
  92. package/s/_archive/lib4/input/sources/sources.ts +24 -0
  93. package/s/_archive/lib4/input/sources/stick.ts +25 -0
  94. package/s/_archive/lib4/input/types.ts +102 -0
  95. package/s/_archive/lib4/input/utils/evergreen.ts +10 -0
  96. package/s/_archive/lib4/input/utils/is-down.ts +5 -0
  97. package/s/_archive/lib4/input/utils/mouse-button.ts +10 -0
  98. package/s/_archive/lib4/input/utils/pad/on-pad.ts +50 -0
  99. package/s/_archive/lib4/input/utils/pad/pad.ts +10 -0
  100. package/s/_archive/lib4/input/utils/sampler.ts +28 -0
  101. package/s/_archive/lib4/input/utils/split-axis.ts +15 -0
  102. package/s/_archive/lib4/test.ts +12 -0
  103. package/s/_archive/utils/circular-clamp.ts +2 -2
  104. package/s/_archive/utils/is-down.ts +5 -0
  105. package/s/demo/demo-app/element.ts +2 -4
  106. package/s/demo/main.bundle.ts +2 -65
  107. package/s/gamepad/gamepad-app/element.ts +14 -11
  108. package/s/lib/index.ts +18 -0
  109. package/s/lib/input/data/decode.ts +25 -0
  110. package/s/lib/input/data/encode.ts +24 -0
  111. package/s/lib/input/data/params.ts +7 -0
  112. package/s/lib/input/decoder.ts +40 -0
  113. package/s/lib/input/encoder.ts +64 -0
  114. package/s/lib/input/evaluate/context.ts +17 -0
  115. package/s/lib/input/evaluate/evaluate.ts +199 -0
  116. package/s/lib/input/expression.ts +44 -0
  117. package/s/lib/input/investigate/hash-bindings.ts +22 -0
  118. package/s/lib/input/investigate/investigate.ts +35 -0
  119. package/s/lib/input/investigate/is-compatible.ts +8 -0
  120. package/s/lib/input/investigate/is-expression.ts +12 -0
  121. package/s/lib/input/investigate/make-input.ts +11 -0
  122. package/s/lib/input/sources/gamepad.ts +55 -0
  123. package/s/lib/input/sources/keyboard.ts +46 -0
  124. package/s/lib/input/sources/plain.ts +9 -0
  125. package/s/lib/input/sources/pointer.ts +56 -0
  126. package/s/lib/input/sources/sources.ts +24 -0
  127. package/s/lib/input/sources/stick.ts +32 -0
  128. package/s/lib/input/testing/quickbind.ts +20 -0
  129. package/s/lib/input/types.ts +52 -0
  130. package/s/lib/input/utils/clock.ts +14 -0
  131. package/s/lib/input/utils/evergreen.ts +10 -0
  132. package/s/lib/input/utils/is-down.ts +5 -0
  133. package/s/lib/input/utils/mouse-button.ts +10 -0
  134. package/s/lib/input/utils/pad/on-pad.ts +50 -0
  135. package/s/lib/input/utils/pad/pad.ts +10 -0
  136. package/s/lib/input/utils/sampler.ts +28 -0
  137. package/s/lib/input/utils/split-axis.ts +15 -0
  138. package/s/lib/test.ts +180 -0
  139. package/x/_archive/demo/main.css +6 -8
  140. package/x/demo/demo-app/element.d.ts +1 -3
  141. package/x/demo/demo-app/element.js +2 -3
  142. package/x/demo/demo-app/element.js.map +1 -1
  143. package/x/demo/main.bundle.js +1 -50
  144. package/x/demo/main.bundle.js.map +1 -1
  145. package/x/demo/main.bundle.min.js +9 -134
  146. package/x/demo/main.bundle.min.js.map +4 -4
  147. package/x/gamepad/gamepad-app/element.js +12 -10
  148. package/x/gamepad/gamepad-app/element.js.map +1 -1
  149. package/x/gamepad/index.html +2 -2
  150. package/x/gamepad/main.bundle.min.js +9 -9
  151. package/x/gamepad/main.bundle.min.js.map +4 -4
  152. package/x/index.html +2 -2
  153. package/x/lib/index.d.ts +13 -0
  154. package/x/lib/index.js +14 -0
  155. package/x/lib/index.js.map +1 -0
  156. package/x/lib/input/data/decode.d.ts +5 -0
  157. package/x/lib/input/data/decode.js +17 -0
  158. package/x/lib/input/data/decode.js.map +1 -0
  159. package/x/lib/input/data/encode.d.ts +2 -0
  160. package/x/lib/input/data/encode.js +17 -0
  161. package/x/lib/input/data/encode.js.map +1 -0
  162. package/x/lib/input/data/params.d.ts +5 -0
  163. package/x/lib/input/data/params.js +6 -0
  164. package/x/lib/input/data/params.js.map +1 -0
  165. package/x/lib/input/decoder.d.ts +7 -0
  166. package/x/lib/input/decoder.js +31 -0
  167. package/x/lib/input/decoder.js.map +1 -0
  168. package/x/lib/input/encoder.d.ts +10 -0
  169. package/x/lib/input/encoder.js +49 -0
  170. package/x/lib/input/encoder.js.map +1 -0
  171. package/x/lib/input/evaluate/context.d.ts +16 -0
  172. package/x/lib/input/evaluate/context.js +12 -0
  173. package/x/lib/input/evaluate/context.js.map +1 -0
  174. package/x/lib/input/evaluate/evaluate.d.ts +3 -0
  175. package/x/lib/input/evaluate/evaluate.js +147 -0
  176. package/x/lib/input/evaluate/evaluate.js.map +1 -0
  177. package/x/lib/input/expression.d.ts +1 -0
  178. package/x/lib/input/expression.js +2 -0
  179. package/x/lib/input/expression.js.map +1 -0
  180. package/x/lib/input/investigate/hash-bindings.d.ts +2 -0
  181. package/x/lib/input/investigate/hash-bindings.js +17 -0
  182. package/x/lib/input/investigate/hash-bindings.js.map +1 -0
  183. package/x/lib/input/investigate/investigate.d.ts +8 -0
  184. package/x/lib/input/investigate/investigate.js +28 -0
  185. package/x/lib/input/investigate/investigate.js.map +1 -0
  186. package/x/lib/input/investigate/is-compatible.d.ts +2 -0
  187. package/x/lib/input/investigate/is-compatible.js +5 -0
  188. package/x/lib/input/investigate/is-compatible.js.map +1 -0
  189. package/x/lib/input/investigate/is-expression.d.ts +3 -0
  190. package/x/lib/input/investigate/is-expression.js +11 -0
  191. package/x/lib/input/investigate/is-expression.js.map +1 -0
  192. package/x/lib/input/investigate/make-input.d.ts +2 -0
  193. package/x/lib/input/investigate/make-input.js +8 -0
  194. package/x/lib/input/investigate/make-input.js.map +1 -0
  195. package/x/lib/input/sources/gamepad.d.ts +9 -0
  196. package/x/lib/input/sources/gamepad.js +45 -0
  197. package/x/lib/input/sources/gamepad.js.map +1 -0
  198. package/x/lib/input/sources/keyboard.d.ts +5 -0
  199. package/x/lib/input/sources/keyboard.js +36 -0
  200. package/x/lib/input/sources/keyboard.js.map +1 -0
  201. package/x/lib/input/sources/plain.d.ts +5 -0
  202. package/x/lib/input/sources/plain.js +6 -0
  203. package/x/lib/input/sources/plain.js.map +1 -0
  204. package/x/lib/input/sources/pointer.d.ts +7 -0
  205. package/x/lib/input/sources/pointer.js +54 -0
  206. package/x/lib/input/sources/pointer.js.map +1 -0
  207. package/x/lib/input/sources/sources.d.ts +7 -0
  208. package/x/lib/input/sources/sources.js +15 -0
  209. package/x/lib/input/sources/sources.js.map +1 -0
  210. package/x/lib/input/sources/stick.d.ts +10 -0
  211. package/x/lib/input/sources/stick.js +25 -0
  212. package/x/lib/input/sources/stick.js.map +1 -0
  213. package/x/lib/input/testing/quickbind.d.ts +11 -0
  214. package/x/lib/input/testing/quickbind.js +12 -0
  215. package/x/lib/input/testing/quickbind.js.map +1 -0
  216. package/x/lib/input/types.d.ts +37 -0
  217. package/x/lib/input/types.js +2 -0
  218. package/x/lib/input/types.js.map +1 -0
  219. package/x/lib/input/utils/clock.d.ts +7 -0
  220. package/x/lib/input/utils/clock.js +14 -0
  221. package/x/lib/input/utils/clock.js.map +1 -0
  222. package/x/lib/input/utils/evergreen.js.map +1 -0
  223. package/x/lib/input/utils/is-down.js.map +1 -0
  224. package/x/lib/input/utils/mouse-button.d.ts +1 -0
  225. package/x/lib/input/utils/mouse-button.js +9 -0
  226. package/x/lib/input/utils/mouse-button.js.map +1 -0
  227. package/x/lib/input/utils/pad/on-pad.js.map +1 -0
  228. package/x/lib/input/utils/pad/pad.js.map +1 -0
  229. package/x/lib/input/utils/sampler.d.ts +7 -0
  230. package/x/lib/input/utils/sampler.js +23 -0
  231. package/x/lib/input/utils/sampler.js.map +1 -0
  232. package/x/lib/input/utils/split-axis.js.map +1 -0
  233. package/x/lib/test.d.ts +1 -0
  234. package/x/lib/test.js +134 -0
  235. package/x/lib/test.js.map +1 -0
  236. package/s/_archive/README.md +0 -435
  237. package/s/_archive/core/bindings/action.ts +0 -30
  238. package/s/_archive/core/bindings/parts/defaults.ts +0 -32
  239. package/s/_archive/core/bindings/parts/is-pressed.ts +0 -5
  240. package/s/_archive/core/bindings/parts/lens-algo.ts +0 -84
  241. package/s/_archive/core/bindings/parts/lookup-proxies.ts +0 -17
  242. package/s/_archive/core/bindings/resolver.ts +0 -103
  243. package/s/_archive/core/bindings/sample-map.ts +0 -25
  244. package/s/_archive/core/bindings/types.ts +0 -60
  245. package/s/_archive/core/core.test.ts +0 -155
  246. package/s/_archive/core/devices/auto-gamepads.ts +0 -8
  247. package/s/_archive/core/devices/device.ts +0 -12
  248. package/s/_archive/core/devices/infra/group.ts +0 -24
  249. package/s/_archive/core/devices/infra/sampler.ts +0 -22
  250. package/s/_archive/core/devices/standard/gamepad.ts +0 -83
  251. package/s/_archive/core/devices/standard/index.ts +0 -8
  252. package/s/_archive/core/devices/standard/keyboard.ts +0 -31
  253. package/s/_archive/core/devices/standard/pointer.ts +0 -97
  254. package/s/_archive/core/devices/standard/primary.ts +0 -20
  255. package/s/_archive/core/devices/standard/stick.ts +0 -27
  256. package/s/_archive/core/devices/standard/vpad.ts +0 -25
  257. package/s/_archive/core/devices/types.ts +0 -3
  258. package/s/_archive/core/hub/hub.ts +0 -118
  259. package/s/_archive/core/hub/meta-bindings.ts +0 -23
  260. package/s/_archive/core/hub/parts/connected.ts +0 -15
  261. package/s/_archive/core/hub/port.ts +0 -26
  262. package/s/_archive/core/hub/types.ts +0 -13
  263. package/s/_archive/core/index.ts +0 -19
  264. package/s/_archive/core/testing/testing.ts +0 -57
  265. package/s/_archive/deck/index.ts +0 -13
  266. package/s/_archive/deck/parts/catalog.ts +0 -58
  267. package/s/_archive/deck/parts/db.ts +0 -65
  268. package/s/_archive/deck/parts/device-skins/device-icons.ts +0 -38
  269. package/s/_archive/deck/parts/device-skins/device-skin.ts +0 -29
  270. package/s/_archive/deck/parts/local-storage-kv.ts +0 -8
  271. package/s/_archive/deck/parts/merge-bindings.ts +0 -21
  272. package/s/_archive/deck/parts/overlay-visibility.ts +0 -49
  273. package/s/_archive/deck/views/bindings/view.ts +0 -95
  274. package/s/_archive/deck/views/overlay/style.css.ts +0 -110
  275. package/s/_archive/deck/views/overlay/view.ts +0 -46
  276. package/s/_archive/demo/game/game.ts +0 -85
  277. package/s/_archive/demo/game/parts/agent.ts +0 -10
  278. package/s/_archive/demo/game/parts/game-bindings.ts +0 -20
  279. package/s/_archive/demo/game/parts/logic.ts +0 -24
  280. package/s/_archive/demo/game/parts/player.ts +0 -32
  281. package/s/_archive/demo/game/parts/renderer.ts +0 -112
  282. package/s/_archive/demo/game/parts/state.ts +0 -23
  283. package/s/_archive/demo/game/parts/virtual-device.ts +0 -13
  284. package/s/_archive/demo/ui/theater/styles.css.ts +0 -57
  285. package/s/_archive/demo/ui/theater/view.ts +0 -55
  286. package/s/_archive/demo/ui/theater/virtual/style.css.ts +0 -43
  287. package/s/_archive/demo/ui/theater/virtual/view.ts +0 -29
  288. package/s/_archive/demo/ui/utils/loader.ts +0 -5
  289. package/s/_archive/index.html.ts +0 -61
  290. package/s/_archive/index.ts +0 -8
  291. package/s/_archive/nubs/index.ts +0 -5
  292. package/s/_archive/nubs/lookpad/styles.ts +0 -21
  293. package/s/_archive/nubs/lookpad/view.ts +0 -39
  294. package/s/_archive/nubs/stick/style.css.ts +0 -70
  295. package/s/_archive/nubs/stick/view.ts +0 -108
  296. package/s/_archive/nubs/vpad/styles.css.ts +0 -134
  297. package/s/_archive/nubs/vpad/utils/gamepad-inputs.ts +0 -42
  298. package/s/_archive/nubs/vpad/utils/prevent-default-touch-shenanigans.ts +0 -12
  299. package/s/_archive/nubs/vpad/utils/touch-tracking.ts +0 -75
  300. package/s/_archive/nubs/vpad/view.ts +0 -141
  301. package/s/_archive/tests.test.ts +0 -6
  302. package/s/_archive/utils/dispensers.ts +0 -20
  303. package/s/_archive/utils/gamepads.ts +0 -41
  304. package/s/_archive/utils/quick-math.ts +0 -13
  305. package/s/deck/deck.ts +0 -92
  306. package/s/index.ts +0 -31
  307. package/s/utils/circular-clamp.ts +0 -14
  308. package/x/core/atom/defaults.d.ts +0 -3
  309. package/x/core/atom/defaults.js +0 -26
  310. package/x/core/atom/defaults.js.map +0 -1
  311. package/x/core/atom/lens-algo.d.ts +0 -2
  312. package/x/core/atom/lens-algo.js +0 -54
  313. package/x/core/atom/lens-algo.js.map +0 -1
  314. package/x/core/atom/types.d.ts +0 -27
  315. package/x/core/atom/types.js +0 -2
  316. package/x/core/atom/types.js.map +0 -1
  317. package/x/core/bindings/normalize.d.ts +0 -2
  318. package/x/core/bindings/normalize.js +0 -17
  319. package/x/core/bindings/normalize.js.map +0 -1
  320. package/x/core/bindings/shape.d.ts +0 -2
  321. package/x/core/bindings/shape.js +0 -10
  322. package/x/core/bindings/shape.js.map +0 -1
  323. package/x/core/bindings/table.d.ts +0 -2
  324. package/x/core/bindings/table.js +0 -15
  325. package/x/core/bindings/table.js.map +0 -1
  326. package/x/core/intent/bucket.d.ts +0 -7
  327. package/x/core/intent/bucket.js +0 -21
  328. package/x/core/intent/bucket.js.map +0 -1
  329. package/x/core/intent/consts.d.ts +0 -2
  330. package/x/core/intent/consts.js +0 -3
  331. package/x/core/intent/consts.js.map +0 -1
  332. package/x/core/intent/decode.d.ts +0 -3
  333. package/x/core/intent/decode.js +0 -18
  334. package/x/core/intent/decode.js.map +0 -1
  335. package/x/core/intent/encode.d.ts +0 -3
  336. package/x/core/intent/encode.js +0 -15
  337. package/x/core/intent/encode.js.map +0 -1
  338. package/x/core/intent/merge.d.ts +0 -3
  339. package/x/core/intent/merge.js +0 -10
  340. package/x/core/intent/merge.js.map +0 -1
  341. package/x/core/parts/action.d.ts +0 -14
  342. package/x/core/parts/action.js +0 -30
  343. package/x/core/parts/action.js.map +0 -1
  344. package/x/core/parts/sample-map.d.ts +0 -6
  345. package/x/core/parts/sample-map.js +0 -21
  346. package/x/core/parts/sample-map.js.map +0 -1
  347. package/x/core/resolvers/actions.d.ts +0 -2
  348. package/x/core/resolvers/actions.js +0 -23
  349. package/x/core/resolvers/actions.js.map +0 -1
  350. package/x/core/resolvers/intents.d.ts +0 -2
  351. package/x/core/resolvers/intents.js +0 -89
  352. package/x/core/resolvers/intents.js.map +0 -1
  353. package/x/core/types.d.ts +0 -43
  354. package/x/core/types.js +0 -2
  355. package/x/core/types.js.map +0 -1
  356. package/x/deck/controller.d.ts +0 -11
  357. package/x/deck/controller.js +0 -28
  358. package/x/deck/controller.js.map +0 -1
  359. package/x/deck/deck.d.ts +0 -31
  360. package/x/deck/deck.js +0 -68
  361. package/x/deck/deck.js.map +0 -1
  362. package/x/deck/parts/profiles.d.ts +0 -12
  363. package/x/deck/parts/profiles.js +0 -31
  364. package/x/deck/parts/profiles.js.map +0 -1
  365. package/x/deck/parts/runtime.d.ts +0 -8
  366. package/x/deck/parts/runtime.js +0 -7
  367. package/x/deck/parts/runtime.js.map +0 -1
  368. package/x/deck/parts/settings.d.ts +0 -11
  369. package/x/deck/parts/settings.js +0 -26
  370. package/x/deck/parts/settings.js.map +0 -1
  371. package/x/deck/port.d.ts +0 -10
  372. package/x/deck/port.js +0 -24
  373. package/x/deck/port.js.map +0 -1
  374. package/x/deck/types.d.ts +0 -11
  375. package/x/deck/types.js +0 -2
  376. package/x/deck/types.js.map +0 -1
  377. package/x/device/devices.d.ts +0 -7
  378. package/x/device/devices.js +0 -17
  379. package/x/device/devices.js.map +0 -1
  380. package/x/device/gamepad.d.ts +0 -9
  381. package/x/device/gamepad.js +0 -37
  382. package/x/device/gamepad.js.map +0 -1
  383. package/x/device/keyboard.d.ts +0 -6
  384. package/x/device/keyboard.js +0 -30
  385. package/x/device/keyboard.js.map +0 -1
  386. package/x/device/pad/on-pad.js.map +0 -1
  387. package/x/device/pad/pad.js.map +0 -1
  388. package/x/device/pointer.d.ts +0 -12
  389. package/x/device/pointer.js +0 -73
  390. package/x/device/pointer.js.map +0 -1
  391. package/x/device/sampler.d.ts +0 -9
  392. package/x/device/sampler.js +0 -19
  393. package/x/device/sampler.js.map +0 -1
  394. package/x/device/stick.d.ts +0 -14
  395. package/x/device/stick.js +0 -22
  396. package/x/device/stick.js.map +0 -1
  397. package/x/index-ui.d.ts +0 -1
  398. package/x/index-ui.js +0 -2
  399. package/x/index-ui.js.map +0 -1
  400. package/x/index.d.ts +0 -27
  401. package/x/index.js +0 -28
  402. package/x/index.js.map +0 -1
  403. package/x/test.d.ts +0 -9
  404. package/x/test.js +0 -307
  405. package/x/test.js.map +0 -1
  406. package/x/ui/views/desk/style.css.d.ts +0 -2
  407. package/x/ui/views/desk/style.css.js +0 -69
  408. package/x/ui/views/desk/style.css.js.map +0 -1
  409. package/x/ui/views/desk/view.d.ts +0 -7
  410. package/x/ui/views/desk/view.js +0 -102
  411. package/x/ui/views/desk/view.js.map +0 -1
  412. package/x/utils/circular-clamp.d.ts +0 -2
  413. package/x/utils/circular-clamp.js +0 -8
  414. package/x/utils/circular-clamp.js.map +0 -1
  415. package/x/utils/do-async.d.ts +0 -1
  416. package/x/utils/do-async.js +0 -4
  417. package/x/utils/do-async.js.map +0 -1
  418. package/x/utils/evergreen.js.map +0 -1
  419. package/x/utils/freeze-clone.d.ts +0 -1
  420. package/x/utils/freeze-clone.js +0 -5
  421. package/x/utils/freeze-clone.js.map +0 -1
  422. package/x/utils/identifier.d.ts +0 -6
  423. package/x/utils/identifier.js +0 -25
  424. package/x/utils/identifier.js.map +0 -1
  425. package/x/utils/insert.d.ts +0 -1
  426. package/x/utils/insert.js +0 -5
  427. package/x/utils/insert.js.map +0 -1
  428. package/x/utils/is-down.js.map +0 -1
  429. package/x/utils/make-id.d.ts +0 -1
  430. package/x/utils/make-id.js +0 -5
  431. package/x/utils/make-id.js.map +0 -1
  432. package/x/utils/remap.d.ts +0 -1
  433. package/x/utils/remap.js +0 -6
  434. package/x/utils/remap.js.map +0 -1
  435. package/x/utils/shift-limit.d.ts +0 -2
  436. package/x/utils/shift-limit.js +0 -7
  437. package/x/utils/shift-limit.js.map +0 -1
  438. package/x/utils/sort-by-key.d.ts +0 -1
  439. package/x/utils/sort-by-key.js +0 -6
  440. package/x/utils/sort-by-key.js.map +0 -1
  441. package/x/utils/split-axis.js.map +0 -1
  442. package/x/utils/tmax.d.ts +0 -1
  443. package/x/utils/tmax.js +0 -6
  444. package/x/utils/tmax.js.map +0 -1
  445. package/x/utils/tmin.d.ts +0 -1
  446. package/x/utils/tmin.js +0 -6
  447. package/x/utils/tmin.js.map +0 -1
  448. /package/s/{core → _archive/core}/atom/defaults.ts +0 -0
  449. /package/s/{core → _archive/core}/atom/lens-algo.ts +0 -0
  450. /package/s/{core → _archive/core}/atom/types.ts +0 -0
  451. /package/s/{core → _archive/core}/bindings/normalize.ts +0 -0
  452. /package/s/{core → _archive/core}/bindings/shape.ts +0 -0
  453. /package/s/{core → _archive/core}/bindings/table.ts +0 -0
  454. /package/s/{core → _archive/core}/intent/bucket.ts +0 -0
  455. /package/s/{core → _archive/core}/intent/consts.ts +0 -0
  456. /package/s/{core → _archive/core}/intent/decode.ts +0 -0
  457. /package/s/{core → _archive/core}/intent/encode.ts +0 -0
  458. /package/s/{core → _archive/core}/intent/merge.ts +0 -0
  459. /package/s/{core → _archive/core}/parts/action.ts +0 -0
  460. /package/s/{core → _archive/core}/parts/sample-map.ts +0 -0
  461. /package/s/{core → _archive/core}/resolvers/actions.ts +0 -0
  462. /package/s/{core → _archive/core}/resolvers/intents.ts +0 -0
  463. /package/s/{core → _archive/core}/types.ts +0 -0
  464. /package/s/{deck → _archive/deck}/controller.ts +0 -0
  465. /package/s/{deck → _archive/deck}/parts/profiles.ts +0 -0
  466. /package/s/{deck → _archive/deck}/parts/runtime.ts +0 -0
  467. /package/s/{deck → _archive/deck}/parts/settings.ts +0 -0
  468. /package/s/{deck → _archive/deck}/port.ts +0 -0
  469. /package/s/{deck → _archive/deck}/types.ts +0 -0
  470. /package/s/{device → _archive/device}/devices.ts +0 -0
  471. /package/s/{device → _archive/device}/gamepad.ts +0 -0
  472. /package/s/{device → _archive/device}/keyboard.ts +0 -0
  473. /package/s/{device → _archive/device}/pad/on-pad.ts +0 -0
  474. /package/s/{device → _archive/device}/pad/pad.ts +0 -0
  475. /package/s/{device → _archive/device}/pointer.ts +0 -0
  476. /package/s/{device → _archive/device}/sampler.ts +0 -0
  477. /package/s/{device → _archive/device}/stick.ts +0 -0
  478. /package/s/{index-ui.ts → _archive/index-ui.ts} +0 -0
  479. /package/s/{utils → _archive/lib/bindings/utils}/is-down.ts +0 -0
  480. /package/s/{utils → _archive/lib/utils}/evergreen.ts +0 -0
  481. /package/s/{utils → _archive/lib/utils}/split-axis.ts +0 -0
  482. /package/s/{test.ts → _archive/test.ts} +0 -0
  483. /package/s/{ui → _archive/ui}/views/desk/style.css.ts +0 -0
  484. /package/s/{ui → _archive/ui}/views/desk/view.ts +0 -0
  485. /package/s/{utils → _archive/utils}/do-async.ts +0 -0
  486. /package/s/{utils → _archive/utils}/freeze-clone.ts +0 -0
  487. /package/s/{utils → _archive/utils}/identifier.ts +0 -0
  488. /package/s/{utils → _archive/utils}/insert.ts +0 -0
  489. /package/s/{utils → _archive/utils}/make-id.ts +0 -0
  490. /package/s/{utils → _archive/utils}/remap.ts +0 -0
  491. /package/s/{utils → _archive/utils}/shift-limit.ts +0 -0
  492. /package/s/{utils → _archive/utils}/sort-by-key.ts +0 -0
  493. /package/s/{utils → _archive/utils}/tmax.ts +0 -0
  494. /package/s/{utils → _archive/utils}/tmin.ts +0 -0
  495. /package/x/{utils → lib/input/utils}/evergreen.d.ts +0 -0
  496. /package/x/{utils → lib/input/utils}/evergreen.js +0 -0
  497. /package/x/{utils → lib/input/utils}/is-down.d.ts +0 -0
  498. /package/x/{utils → lib/input/utils}/is-down.js +0 -0
  499. /package/x/{device → lib/input/utils}/pad/on-pad.d.ts +0 -0
  500. /package/x/{device → lib/input/utils}/pad/on-pad.js +0 -0
  501. /package/x/{device → lib/input/utils}/pad/pad.d.ts +0 -0
  502. /package/x/{device → lib/input/utils}/pad/pad.js +0 -0
  503. /package/x/{utils → lib/input/utils}/split-axis.d.ts +0 -0
  504. /package/x/{utils → lib/input/utils}/split-axis.js +0 -0
@@ -0,0 +1,50 @@
1
+
2
+ import {ev} from "@e280/stz"
3
+ import {Pad} from "./pad.js"
4
+ import {evergreen} from "../../utils/evergreen.js"
5
+
6
+ /** listen for gamepads coming and going */
7
+ export function onPad(fn: (pad: Pad) => () => void) {
8
+ const known = new Map<number, {pad: Pad, dispose: () => void}>()
9
+
10
+ function refresh() {
11
+ addNew()
12
+ deleteOld()
13
+ }
14
+
15
+ function addNew() {
16
+ for (const gamepad of navigator.getGamepads()) {
17
+ if (gamepad?.connected && !known.has(gamepad.index)) {
18
+ const get = () => navigator.getGamepads()[gamepad.index]
19
+ const pad = new Pad(evergreen(gamepad, get))
20
+ const dispose = fn(pad)
21
+ known.set(gamepad.index, {pad, dispose})
22
+ }
23
+ }
24
+ }
25
+
26
+ function deleteOld() {
27
+ for (const [index, {pad, dispose}] of known) {
28
+ const gamepad = navigator.getGamepads()[pad.gamepad.index]
29
+ if (!gamepad?.connected) {
30
+ dispose()
31
+ known.delete(index)
32
+ }
33
+ }
34
+ }
35
+
36
+ refresh()
37
+
38
+ const unlisten = ev(window, {
39
+ gamepadconnected: refresh,
40
+ gamepaddisconnected: refresh,
41
+ })
42
+
43
+ return () => {
44
+ unlisten()
45
+ for (const {dispose} of known.values())
46
+ dispose()
47
+ known.clear()
48
+ }
49
+ }
50
+
@@ -0,0 +1,10 @@
1
+
2
+ /** stable reference to a gamepad, has a getter to get the latest gamepad snapshot */
3
+ export class Pad {
4
+ constructor(private get: () => Gamepad) {}
5
+
6
+ get gamepad() {
7
+ return this.get()
8
+ }
9
+ }
10
+
@@ -0,0 +1,28 @@
1
+
2
+ import {arraylimit} from "@e280/stz"
3
+ import {Sample, Source} from "../types.js"
4
+
5
+ const limit = 1024
6
+
7
+ export class Sampler {
8
+ readonly dispose
9
+ #source
10
+ #samples: Sample[] = []
11
+
12
+ constructor(source: Source) {
13
+ this.#source = source
14
+ this.dispose = source.onSample(sample => {
15
+ this.#samples.push(sample)
16
+ if (this.#samples.length > limit) console.warn(`tact sampler exceeded limit ${limit}`)
17
+ this.#samples = arraylimit(this.#samples, limit)
18
+ })
19
+ }
20
+
21
+ take() {
22
+ this.#source.poll?.()
23
+ const samples = this.#samples
24
+ this.#samples = []
25
+ return samples
26
+ }
27
+ }
28
+
@@ -0,0 +1,15 @@
1
+
2
+ import {Xy} from "@benev/math"
3
+
4
+ export function splitAxis(n: number) {
5
+ return (n >= 0)
6
+ ? [n, 0]
7
+ : [0, Math.abs(n)]
8
+ }
9
+
10
+ export function splitVector(vector: Xy) {
11
+ const [right, left] = splitAxis(vector.x)
12
+ const [down, up] = splitAxis(vector.y)
13
+ return {up, down, left, right}
14
+ }
15
+
@@ -0,0 +1,12 @@
1
+
2
+ import {expect, run, suite, test} from "@e280/science"
3
+
4
+ await run({
5
+ input: suite({
6
+ "roundtrip": test(async() => {
7
+ //...
8
+ expect(true).ok()
9
+ }),
10
+ }),
11
+ })
12
+
@@ -1,10 +1,10 @@
1
1
 
2
- import {Scalar, Vec2, Xy} from "@benev/math"
2
+ import {remap, Vec2, Xy} from "@benev/math"
3
3
 
4
4
  export function circularClamp(vector: Xy, range: Vec2) {
5
5
  const v = Vec2.from(vector)
6
6
  const distance = v.distance_(0, 0)
7
- const modifiedDistance = Scalar.remap(
7
+ const modifiedDistance = remap(
8
8
  distance,
9
9
  range.x, range.y,
10
10
  0, 1,
@@ -0,0 +1,5 @@
1
+
2
+ export function isDown(value: number) {
3
+ return value !== 0
4
+ }
5
+
@@ -2,15 +2,13 @@
2
2
  import {html} from "lit"
3
3
  import {shadowElement, useCss} from "@e280/sly"
4
4
  import styleCss from "./style.css.js"
5
- import {Deck} from "../../deck/deck.js"
6
- import {DeskOptions, DeskView} from "../../ui/views/desk/view.js"
7
5
 
8
- export const setupDemoApp = (deck: Deck, options: DeskOptions = {}) => shadowElement(() => {
6
+ export const setupDemoApp = () => shadowElement(() => {
9
7
  useCss(styleCss)
10
8
 
11
9
  return html`
12
10
  <div class=plate>
13
- ${DeskView(deck, options)}
11
+ coming soon, lol
14
12
  </div>
15
13
  `
16
14
  })
@@ -1,71 +1,8 @@
1
1
 
2
- import {Content, dom} from "@e280/sly"
3
- import {LocalStore} from "@e280/strata"
4
-
5
- import {Deck} from "../deck/deck.js"
6
- import {DeckState} from "../deck/types.js"
7
- import {asBindings} from "../core/types.js"
8
- import {Devices} from "../device/devices.js"
9
- import {onPad} from "../device/pad/on-pad.js"
10
- import {Controller} from "../deck/controller.js"
11
- import {PointerDevice} from "../device/pointer.js"
12
- import {GamepadDevice} from "../device/gamepad.js"
2
+ import {dom} from "@e280/sly"
13
3
  import {setupDemoApp} from "./demo-app/element.js"
14
- import {KeyboardDevice} from "../device/keyboard.js"
15
-
16
- const bindings = asBindings({
17
- play: {
18
- action: ["or", "Space", "pointer.button.left", "gamepad.button.1"],
19
- up: ["or", "KeyW", "gamepad.axis.2.pos"],
20
- down: ["or", "KeyS", "gamepad.axis.2.neg"],
21
- left: ["or", "KeyA", "gamepad.axis.1.pos"],
22
- right: ["or", "KeyD", "gamepad.axis.1.neg"],
23
- },
24
- })
25
-
26
- const store = new LocalStore<DeckState>("tactDeck")
27
-
28
- const deck = new Deck({
29
- store,
30
- stockProfiles: {
31
- standard: {label: "📜standard", bindings},
32
- micro: {label: "🦠micro", bindings: asBindings<typeof bindings>({
33
- play: {
34
- action: ["or", "Space", "pointer.button.left", "gamepad.button.1"],
35
- up: ["or", "KeyW", "gamepad.axis.2.pos"],
36
- down: ["or", "KeyS", "gamepad.axis.2.neg"],
37
- left: ["or", "KeyA", "gamepad.axis.1.pos"],
38
- right: ["or", "KeyD", "gamepad.axis.1.neg"],
39
- },
40
- })},
41
- },
42
- })
43
-
44
- await deck.load()
45
- store.onStorageEvent(() => deck.load())
46
-
47
- const port = deck.createPort()
48
- const controller = deck.createController("primary", "standard", new Devices(
49
- new KeyboardDevice(),
50
- new PointerDevice(),
51
- ))
52
-
53
- port.plug(controller)
54
-
55
- const labels = new Map<Controller, Content>()
56
- .set(controller, "⌨️🖱keyboard+mouse")
57
-
58
- onPad(pad => {
59
- const handle = `(${pad.gamepad.index + 1}) ${pad.gamepad.id}`
60
- const controller = deck.createController(handle, "standard", new GamepadDevice(pad))
61
- labels.set(controller, `🎮${handle}`)
62
- port.plug(controller)
63
- return () => deck.deleteController(controller)
64
- })
65
4
 
66
5
  dom.register({
67
- DemoApp: setupDemoApp(deck, {
68
- getControllerLabel: labels.get.bind(labels),
69
- }),
6
+ DemoApp: setupDemoApp(),
70
7
  })
71
8
 
@@ -5,29 +5,32 @@ import {RMap, RSet} from "@e280/strata"
5
5
  import {shadowElement, useCss, useMount, useOnce} from "@e280/sly"
6
6
 
7
7
  import styleCss from "./style.css.js"
8
- import {onPad} from "../../device/pad/on-pad.js"
9
- import {GamepadDevice} from "../../device/gamepad.js"
8
+
9
+ import {onPad} from "../../lib/input/utils/pad/on-pad.js"
10
+ import {GamepadSource} from "../../lib/input/sources/gamepad.js"
10
11
 
11
12
  export const GamepadApp = shadowElement(() => {
12
13
  useCss(styleCss)
13
14
 
14
15
  const connected = useOnce(() => new RSet<{
15
- device: GamepadDevice
16
+ source: GamepadSource
16
17
  samples: RMap<string, number>
17
18
  }>())
18
19
 
19
20
  useMount(() => onPad(pad => {
20
- const device = new GamepadDevice(pad)
21
- const connectee = {device, samples: new RMap<string, number>()}
21
+ const source = new GamepadSource(pad)
22
+ const connectee = {source, samples: new RMap<string, number>()}
23
+ const stop = source.onSample(sample => connectee.samples.set(sample.code, sample.value))
22
24
  connected.add(connectee)
23
- return () => connected.delete(connectee)
25
+ return () => {
26
+ stop()
27
+ connected.delete(connectee)
28
+ }
24
29
  }))
25
30
 
26
31
  useMount(() => cycle(async() => {
27
- for (const conn of connected) {
28
- for (const [code, value] of conn.device.samples())
29
- conn.samples.set(code, value)
30
- }
32
+ for (const conn of connected)
33
+ conn.source.poll()
31
34
  await nap(1000 / 60)
32
35
  }))
33
36
 
@@ -40,7 +43,7 @@ export const GamepadApp = shadowElement(() => {
40
43
 
41
44
  return html`
42
45
  <div class=plate>
43
- ${connected.size > 0 ? [...connected].map(({samples, device: {gamepad}}) => html`
46
+ ${connected.size > 0 ? [...connected].map(({samples, source: {gamepad}}) => html`
44
47
  <div class=device>
45
48
  <h2>🎮 ${gamepad.id}</h2>
46
49
  <div class=stats>
package/s/lib/index.ts ADDED
@@ -0,0 +1,18 @@
1
+
2
+ export * from "./input/investigate/is-compatible.js"
3
+
4
+ export * from "./input/sources/gamepad.js"
5
+ export * from "./input/sources/keyboard.js"
6
+ export * from "./input/sources/plain.js"
7
+ export * from "./input/sources/pointer.js"
8
+ export * from "./input/sources/sources.js"
9
+ export * from "./input/sources/stick.js"
10
+
11
+ export * from "./input/utils/pad/on-pad.js"
12
+ export * from "./input/utils/pad/pad.js"
13
+ export * from "./input/utils/is-down.js"
14
+
15
+ export * from "./input/encoder.js"
16
+ export * from "./input/decoder.js"
17
+ export * from "./input/types.js"
18
+
@@ -0,0 +1,25 @@
1
+
2
+ import {Intent} from "../types.js"
3
+ import {endian, sizeHash, sizeId, sizeValue} from "./params.js"
4
+
5
+ export function decodeData(buffer: ArrayBuffer) {
6
+ const intents: Intent[] = []
7
+ const dv = new DataView(buffer)
8
+ let cursor = 0
9
+
10
+ const hash = dv.getUint32(cursor, endian)
11
+ cursor += sizeHash
12
+
13
+ while (cursor < buffer.byteLength) {
14
+ const id = dv.getUint16(cursor, endian)
15
+ cursor += sizeId
16
+
17
+ const value = dv.getFloat32(cursor, endian)
18
+ cursor += sizeValue
19
+
20
+ intents.push({id, value})
21
+ }
22
+
23
+ return {hash, intents}
24
+ }
25
+
@@ -0,0 +1,24 @@
1
+
2
+ import {Intent} from "../types.js"
3
+ import {endian, sizeHash, sizeId, sizeIntention, sizeValue} from "./params.js"
4
+
5
+ export function encodeData(hash: number, intents: Intent[]) {
6
+ const byteCount = sizeHash + (intents.length * sizeIntention)
7
+ const buffer = new ArrayBuffer(byteCount)
8
+ const dv = new DataView(buffer)
9
+ let cursor = 0
10
+
11
+ dv.setUint32(cursor, hash, endian)
12
+ cursor += sizeHash
13
+
14
+ for (const intention of intents) {
15
+ dv.setUint16(cursor, intention.id, endian)
16
+ cursor += sizeId
17
+
18
+ dv.setFloat32(cursor, intention.value, endian)
19
+ cursor += sizeValue
20
+ }
21
+
22
+ return buffer
23
+ }
24
+
@@ -0,0 +1,7 @@
1
+
2
+ export const endian = false
3
+ export const sizeHash = 4
4
+ export const sizeId = 2
5
+ export const sizeValue = 4
6
+ export const sizeIntention = sizeId + sizeValue
7
+
@@ -0,0 +1,40 @@
1
+
2
+ import {decodeData} from "./data/decode.js"
3
+ import {Inputs, Bindings, InputData} from "./types.js"
4
+ import {investigate} from "./investigate/investigate.js"
5
+
6
+ export class InputDecoder<B extends Bindings> {
7
+ #investigation
8
+
9
+ constructor(bindings: B) {
10
+ this.#investigation = investigate(bindings)
11
+ }
12
+
13
+ get inputs() {
14
+ return this.#investigation.inputs
15
+ }
16
+
17
+ decode(...datas: InputData[]): Inputs<B> {
18
+ for (const input of this.#investigation.inputList) {
19
+ input.was = input.value
20
+ input.delta = 0
21
+ }
22
+
23
+ for (const data of datas) {
24
+ const decoded = decodeData(data)
25
+
26
+ if (decoded.hash !== this.#investigation.hash)
27
+ throw new Error("intent bindings hash mismatch")
28
+
29
+ for (const {id, value} of decoded.intents) {
30
+ const input = this.#investigation.inputList[id]
31
+ if (!input) throw new Error(`unknown input id ${id}`)
32
+ input.value = value
33
+ input.delta = input.value - input.was
34
+ }
35
+ }
36
+
37
+ return this.inputs
38
+ }
39
+ }
40
+
@@ -0,0 +1,64 @@
1
+
2
+ import {deepFreeze} from "@e280/stz"
3
+ import {Sampler} from "./utils/sampler.js"
4
+ import {encodeData} from "./data/encode.js"
5
+ import {evaluate} from "./evaluate/evaluate.js"
6
+ import {EvaluationContext} from "./evaluate/context.js"
7
+ import {investigate} from "./investigate/investigate.js"
8
+ import {Bindings, InputData, Intent, Rebindings, Source} from "./types.js"
9
+
10
+ export class InputEncoder<B extends Bindings = any> {
11
+ #sampler
12
+ #bindings
13
+ #investigation
14
+ #context
15
+
16
+ constructor(source: Source, bindings: B) {
17
+ this.#bindings = deepFreeze(structuredClone(bindings)) as any as Rebindings<B>
18
+ this.#investigation = investigate(this.#bindings)
19
+ this.#sampler = new Sampler(source)
20
+ this.#context = new EvaluationContext()
21
+ }
22
+
23
+ get bindings() {
24
+ return this.#bindings
25
+ }
26
+
27
+ set bindings(b: Rebindings<B>) {
28
+ const bindings = deepFreeze(structuredClone(b)) as Rebindings<B>
29
+ const fresh = investigate(bindings)
30
+
31
+ if (fresh.hash !== this.#investigation.hash)
32
+ throw new Error("incompatible bindings")
33
+
34
+ this.#bindings = bindings
35
+ this.#investigation.rootList = fresh.rootList
36
+ this.#context = new EvaluationContext()
37
+ }
38
+
39
+ encode(time = performance.now()): InputData {
40
+ return encodeData(this.#investigation.hash, [...this.evaluate(time)])
41
+ }
42
+
43
+ *evaluate(time = performance.now()) {
44
+ const samples = this.#sampler.take()
45
+
46
+ this.#context.clock.update(time)
47
+ this.#context.recentSamples = samples
48
+ this.#context.dt = this.#context.clock.since / 1000
49
+
50
+ for (const {code, value} of samples)
51
+ this.#context.latestValues.set(code, value)
52
+
53
+ for (const [id, expression] of this.#investigation.rootList.entries())
54
+ yield {id, value: evaluate(this.#context, id, expression)} as Intent
55
+
56
+ for (const {code, value} of samples)
57
+ this.#context.previousValues.set(code, value)
58
+ }
59
+
60
+ dispose() {
61
+ return this.#sampler.dispose()
62
+ }
63
+ }
64
+
@@ -0,0 +1,17 @@
1
+
2
+ import {Sample} from "../types.js"
3
+ import {Clock} from "../utils/clock.js"
4
+
5
+ export class EvaluationContext {
6
+ dt = 0
7
+ clock = new Clock()
8
+
9
+ recentSamples: Sample[] = []
10
+ latestValues = new Map<string, number>()
11
+ previousValues = new Map<string, number>()
12
+
13
+ accumulated = new Map<object, number>()
14
+ holding = new WeakMap<object, {start: number}>()
15
+ tapping = new WeakMap<object, {events: number[]}>()
16
+ }
17
+
@@ -0,0 +1,199 @@
1
+
2
+ import {remap} from "@benev/math"
3
+ import {arraylimit, guarantee, isNumber, isString} from "@e280/stz"
4
+
5
+ import {isDown} from "../utils/is-down.js"
6
+ import {EvaluationContext} from "./context.js"
7
+ import type {Expression} from "../expression.js"
8
+
9
+ export function evaluate(
10
+ context: EvaluationContext,
11
+ id: number,
12
+ expression: Expression,
13
+ ): number {
14
+
15
+ const e = (expression: Expression) => evaluate(context, id, expression)
16
+
17
+ if (isNumber(expression))
18
+ return expression
19
+
20
+ else if (isString(expression))
21
+ return context.latestValues.get(expression) ?? 0
22
+
23
+ else switch (expression[0]) {
24
+ case "accumulate": {
25
+ const subexpression = expression[1]
26
+ const total = (context.accumulated.get(expression) ?? 0) + e(subexpression)
27
+ context.accumulated.set(expression, total)
28
+ return total
29
+ }
30
+
31
+ case "sum": {
32
+ const code = expression[1]
33
+ let x = 0
34
+ for (const sample of context.recentSamples) {
35
+ if (sample.code === code)
36
+ x += sample.value
37
+ }
38
+ return x
39
+ }
40
+
41
+ case "up": {
42
+ const code = expression[1]
43
+ let ups = 0
44
+ let was = context.previousValues.get(code) ?? 0
45
+ for (const sample of context.recentSamples) {
46
+ if (sample.code !== code) continue
47
+ if (isDown(was) && !isDown(sample.value))
48
+ ups++
49
+ was = sample.value
50
+ }
51
+ return ups
52
+ }
53
+
54
+ case "down": {
55
+ const code = expression[1]
56
+ let downs = 0
57
+ let was = context.previousValues.get(code) ?? 0
58
+ for (const sample of context.recentSamples) {
59
+ if (sample.code !== code) continue
60
+ if (!isDown(was) && isDown(sample.value))
61
+ downs++
62
+ was = sample.value
63
+ }
64
+ return downs
65
+ }
66
+
67
+ case "was": {
68
+ const code = expression[1]
69
+ return context.previousValues.get(code) ?? 0
70
+ }
71
+
72
+ case "since": {
73
+ const code = expression[1]
74
+ const was = context.previousValues.get(code) ?? 0
75
+ const latest = context.latestValues.get(code) ?? 0
76
+ return latest - was
77
+ }
78
+
79
+ case "if": {
80
+ const [, condition, yes, no] = expression
81
+ return e(condition)
82
+ ? e(yes)
83
+ : (no ? e(no) : 0)
84
+ }
85
+
86
+ case "min":
87
+ return Math.min(...expression.slice(1).map(e))
88
+
89
+ case "max":
90
+ return Math.max(...expression.slice(1).map(e))
91
+
92
+ case "+":
93
+ return expression.slice(1)
94
+ .map(e)
95
+ .reduce((p, c) => p + c, 0)
96
+
97
+ case "*":
98
+ return expression.slice(1)
99
+ .map(e)
100
+ .reduce((p, c) => p * c, 1)
101
+
102
+ case "==":
103
+ return +(e(expression[1]) === e(expression[2]))
104
+
105
+ case "!=":
106
+ return +(e(expression[1]) !== e(expression[2]))
107
+
108
+ case ">":
109
+ return +(e(expression[1]) > e(expression[2]))
110
+
111
+ case "<":
112
+ return +(e(expression[1]) < e(expression[2]))
113
+
114
+ case ">=":
115
+ return +(e(expression[1]) >= e(expression[2]))
116
+
117
+ case "<=":
118
+ return +(e(expression[1]) <= e(expression[2]))
119
+
120
+ case "!":
121
+ return +(e(expression[1]) === 0)
122
+
123
+ case "!!":
124
+ return +(e(expression[1]) !== 0)
125
+
126
+ case "clamp": {
127
+ const [, min, max, expr] = expression
128
+ const value = e(expr)
129
+ return Math.min(
130
+ max === null ? Infinity : e(max),
131
+ Math.max(
132
+ min === null ? -Infinity : e(min),
133
+ value,
134
+ ),
135
+ )
136
+ }
137
+
138
+ case "remap": {
139
+ const [, a, b, c, d, expr] = expression
140
+ return remap(e(expr), e(a), e(b), e(c), e(d))
141
+ }
142
+
143
+ case "dt":
144
+ return context.dt
145
+
146
+ case "held": {
147
+ const [, ms, subexpression] = expression
148
+ const down = isDown(e(subexpression))
149
+ let held = context.holding.get(expression)
150
+
151
+ if (down && !held) {
152
+ held = {start: context.clock.time}
153
+ context.holding.set(expression, held)
154
+ }
155
+
156
+ if (!down && held) {
157
+ held = undefined
158
+ context.holding.delete(expression)
159
+ }
160
+
161
+ if (held) {
162
+ const timeHeld = context.clock.time - held.start
163
+ if (timeHeld >= ms)
164
+ return 1
165
+ }
166
+
167
+ return 0
168
+ }
169
+
170
+ case "taps": {
171
+ const [, taps, ms, subexpression] = expression
172
+ const presses = e(subexpression)
173
+ const now = context.clock.time
174
+
175
+ const tapped = guarantee(context.tapping, expression, () => ({
176
+ events: [] as number[],
177
+ }))
178
+
179
+ for (let i = 0; i < presses; i++)
180
+ tapped.events.push(now)
181
+
182
+ tapped.events = arraylimit(
183
+ tapped.events.filter(time => time >= now - ms),
184
+ 128,
185
+ )
186
+
187
+ if (tapped.events.length >= taps) {
188
+ tapped.events = []
189
+ return 1
190
+ }
191
+
192
+ return 0
193
+ }
194
+
195
+ default:
196
+ throw new Error("unknown expression")
197
+ }
198
+ }
199
+