@typeonce/ritmo-browser 0.10.0 → 0.12.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 (63) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +6 -1
  3. package/dist/Controls.d.ts +496 -0
  4. package/dist/Controls.d.ts.map +1 -0
  5. package/dist/Controls.js +343 -0
  6. package/dist/Controls.js.map +1 -0
  7. package/dist/Gamepad.d.ts +376 -0
  8. package/dist/Gamepad.d.ts.map +1 -0
  9. package/dist/Gamepad.js +459 -0
  10. package/dist/Gamepad.js.map +1 -0
  11. package/dist/InputCapture.d.ts +46 -16
  12. package/dist/InputCapture.d.ts.map +1 -1
  13. package/dist/InputCapture.js +1 -1
  14. package/dist/InputCapture.js.map +1 -1
  15. package/dist/Keyboard.d.ts +177 -25
  16. package/dist/Keyboard.d.ts.map +1 -1
  17. package/dist/Keyboard.js +257 -91
  18. package/dist/Keyboard.js.map +1 -1
  19. package/dist/Pointer.d.ts +233 -64
  20. package/dist/Pointer.d.ts.map +1 -1
  21. package/dist/Pointer.js +205 -145
  22. package/dist/Pointer.js.map +1 -1
  23. package/dist/Touch.d.ts +75 -33
  24. package/dist/Touch.d.ts.map +1 -1
  25. package/dist/Touch.js +25 -30
  26. package/dist/Touch.js.map +1 -1
  27. package/dist/index.d.ts +10 -1
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +10 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/internal/buttons.d.ts +52 -0
  32. package/dist/internal/buttons.d.ts.map +1 -0
  33. package/dist/internal/buttons.js +211 -0
  34. package/dist/internal/buttons.js.map +1 -0
  35. package/dist/internal/introspect.d.ts +14 -0
  36. package/dist/internal/introspect.d.ts.map +1 -0
  37. package/dist/internal/introspect.js +19 -0
  38. package/dist/internal/introspect.js.map +1 -0
  39. package/dist/internal/state.d.ts +13 -0
  40. package/dist/internal/state.d.ts.map +1 -0
  41. package/dist/internal/state.js +2 -0
  42. package/dist/internal/state.js.map +1 -0
  43. package/dist/internal/used.d.ts +8 -0
  44. package/dist/internal/used.d.ts.map +1 -0
  45. package/dist/internal/used.js +14 -0
  46. package/dist/internal/used.js.map +1 -0
  47. package/dist/internal/vectors.d.ts +29 -0
  48. package/dist/internal/vectors.d.ts.map +1 -0
  49. package/dist/internal/vectors.js +22 -0
  50. package/dist/internal/vectors.js.map +1 -0
  51. package/package.json +4 -3
  52. package/src/Controls.ts +800 -0
  53. package/src/Gamepad.ts +752 -0
  54. package/src/InputCapture.ts +43 -24
  55. package/src/Keyboard.ts +387 -72
  56. package/src/Pointer.ts +392 -166
  57. package/src/Touch.ts +113 -61
  58. package/src/index.ts +10 -1
  59. package/src/internal/buttons.ts +222 -0
  60. package/src/internal/introspect.ts +23 -0
  61. package/src/internal/state.ts +12 -0
  62. package/src/internal/used.ts +14 -0
  63. package/src/internal/vectors.ts +41 -0
@@ -0,0 +1,41 @@
1
+ /**
2
+ * A direction and strength, length at most 1, `y` growing down as on
3
+ * screen, the same on every device and in `Controls`: a vector action, a
4
+ * stick's tilt (dead zone removed, zero at rest, 1 at full tilt), or a
5
+ * touch stick, swipe or aim.
6
+ */
7
+ export interface Vector {
8
+ readonly x: number
9
+ readonly y: number
10
+ }
11
+
12
+ /** The four directions a digital vector binding names. */
13
+ export const directions = ["up", "down", "left", "right"] as const
14
+
15
+ /** One direction of a vector action; a keyboard timeline names it as `"move.right"`. */
16
+ export type Direction = (typeof directions)[number]
17
+
18
+ export const zero: Vector = { x: 0, y: 0 }
19
+
20
+ /** The internal action name of one direction of a vector, for timelines and the button trackers. */
21
+ export const directionName = (vector: string, direction: Direction): string => `${vector}.${direction}`
22
+
23
+ /**
24
+ * The vector four held directions give: opposite directions cancel and a
25
+ * diagonal has length 1, so it is not faster than a straight line.
26
+ */
27
+ export const digital = (up: boolean, down: boolean, left: boolean, right: boolean): Vector => {
28
+ const x = (right ? 1 : 0) - (left ? 1 : 0)
29
+ const y = (down ? 1 : 0) - (up ? 1 : 0)
30
+ if (x === 0 && y === 0) return zero
31
+ return x !== 0 && y !== 0 ? { x: x * Math.SQRT1_2, y: y * Math.SQRT1_2 } : { x, y }
32
+ }
33
+
34
+ const lengthSquared = (vector: Vector): number => vector.x * vector.x + vector.y * vector.y
35
+
36
+ /** The longer of two vectors, the first on a tie: how vectors from several sources combine. */
37
+ export const longer = (a: Vector, b: Vector): Vector => lengthSquared(b) > lengthSquared(a) ? b : a
38
+
39
+ /** Whether a binding entry is a vector binding (`Keyboard.vector`, `Gamepad.vector`). */
40
+ export const isVectorBinding = (entry: unknown): entry is { readonly _tag: "Vector" } =>
41
+ typeof entry === "object" && entry !== null && !Array.isArray(entry) && (entry as { readonly _tag?: unknown })._tag === "Vector"