rn-gamekit 0.1.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 (231) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE +21 -0
  3. package/README.md +131 -0
  4. package/lib/module/assets/defineAssets.js +48 -0
  5. package/lib/module/assets/defineAssets.js.map +1 -0
  6. package/lib/module/assets/errors.js +38 -0
  7. package/lib/module/assets/errors.js.map +1 -0
  8. package/lib/module/assets/types.js +2 -0
  9. package/lib/module/assets/types.js.map +1 -0
  10. package/lib/module/assets/validation.js +99 -0
  11. package/lib/module/assets/validation.js.map +1 -0
  12. package/lib/module/core/frameDriver.js +20 -0
  13. package/lib/module/core/frameDriver.js.map +1 -0
  14. package/lib/module/core/input/createInputBuffer.js +296 -0
  15. package/lib/module/core/input/createInputBuffer.js.map +1 -0
  16. package/lib/module/core/input/types.js +4 -0
  17. package/lib/module/core/input/types.js.map +1 -0
  18. package/lib/module/core/session/createGameSession.js +554 -0
  19. package/lib/module/core/session/createGameSession.js.map +1 -0
  20. package/lib/module/core/session/deepFreeze.js +155 -0
  21. package/lib/module/core/session/deepFreeze.js.map +1 -0
  22. package/lib/module/core/session/diagnostics.js +2 -0
  23. package/lib/module/core/session/diagnostics.js.map +1 -0
  24. package/lib/module/core/session/types.js +43 -0
  25. package/lib/module/core/session/types.js.map +1 -0
  26. package/lib/module/definition/defineGame.js +57 -0
  27. package/lib/module/definition/defineGame.js.map +1 -0
  28. package/lib/module/definition/types.js +4 -0
  29. package/lib/module/definition/types.js.map +1 -0
  30. package/lib/module/geometry/types.js +2 -0
  31. package/lib/module/geometry/types.js.map +1 -0
  32. package/lib/module/index.js +12 -0
  33. package/lib/module/index.js.map +1 -0
  34. package/lib/module/package.json +1 -0
  35. package/lib/module/react/GamePointerInput.js +385 -0
  36. package/lib/module/react/GamePointerInput.js.map +1 -0
  37. package/lib/module/react/GameView.js +223 -0
  38. package/lib/module/react/GameView.js.map +1 -0
  39. package/lib/module/react/alphaClock.js +42 -0
  40. package/lib/module/react/alphaClock.js.map +1 -0
  41. package/lib/module/react/assets/createGameAssetStore.js +358 -0
  42. package/lib/module/react/assets/createGameAssetStore.js.map +1 -0
  43. package/lib/module/react/assets/decodeSkiaImage.js +54 -0
  44. package/lib/module/react/assets/decodeSkiaImage.js.map +1 -0
  45. package/lib/module/react/assets/errors.js +10 -0
  46. package/lib/module/react/assets/errors.js.map +1 -0
  47. package/lib/module/react/assets/useGameAssets.js +160 -0
  48. package/lib/module/react/assets/useGameAssets.js.map +1 -0
  49. package/lib/module/react/bindAppLifecycle.js +58 -0
  50. package/lib/module/react/bindAppLifecycle.js.map +1 -0
  51. package/lib/module/react/bindGameSession.js +37 -0
  52. package/lib/module/react/bindGameSession.js.map +1 -0
  53. package/lib/module/react/gestureLifecycle.js +68 -0
  54. package/lib/module/react/gestureLifecycle.js.map +1 -0
  55. package/lib/module/react/instrumentation.js +4 -0
  56. package/lib/module/react/instrumentation.js.map +1 -0
  57. package/lib/module/react/pointerBinding.js +196 -0
  58. package/lib/module/react/pointerBinding.js.map +1 -0
  59. package/lib/module/react/pointerCoalescer.js +224 -0
  60. package/lib/module/react/pointerCoalescer.js.map +1 -0
  61. package/lib/module/react/pointerContainment.js +27 -0
  62. package/lib/module/react/pointerContainment.js.map +1 -0
  63. package/lib/module/react/sprites/GameSprite.js +116 -0
  64. package/lib/module/react/sprites/GameSprite.js.map +1 -0
  65. package/lib/module/react/sprites/GameWorld2D.js +44 -0
  66. package/lib/module/react/sprites/GameWorld2D.js.map +1 -0
  67. package/lib/module/react/sprites/Sprite.js +147 -0
  68. package/lib/module/react/sprites/Sprite.js.map +1 -0
  69. package/lib/module/react/sprites/SpriteBatch.js +173 -0
  70. package/lib/module/react/sprites/SpriteBatch.js.map +1 -0
  71. package/lib/module/react/sprites/spriteBatchPolicy.js +25 -0
  72. package/lib/module/react/sprites/spriteBatchPolicy.js.map +1 -0
  73. package/lib/module/react/sprites/spriteTransform.js +135 -0
  74. package/lib/module/react/sprites/spriteTransform.js.map +1 -0
  75. package/lib/module/react/viewportBinding.js +101 -0
  76. package/lib/module/react/viewportBinding.js.map +1 -0
  77. package/lib/module/react.js +13 -0
  78. package/lib/module/react.js.map +1 -0
  79. package/lib/module/scene/defineScene.js +29 -0
  80. package/lib/module/scene/defineScene.js.map +1 -0
  81. package/lib/module/scene/types.js +4 -0
  82. package/lib/module/scene/types.js.map +1 -0
  83. package/lib/module/sprites/sampleSpriteClip.js +50 -0
  84. package/lib/module/sprites/sampleSpriteClip.js.map +1 -0
  85. package/lib/module/sprites/spriteAnimationState.js +165 -0
  86. package/lib/module/sprites/spriteAnimationState.js.map +1 -0
  87. package/lib/module/testing.js +57 -0
  88. package/lib/module/testing.js.map +1 -0
  89. package/lib/module/viewport2d/index.js +4 -0
  90. package/lib/module/viewport2d/index.js.map +1 -0
  91. package/lib/module/viewport2d/math.js +129 -0
  92. package/lib/module/viewport2d/math.js.map +1 -0
  93. package/lib/module/viewport2d/types.js +2 -0
  94. package/lib/module/viewport2d/types.js.map +1 -0
  95. package/lib/typescript/package.json +1 -0
  96. package/lib/typescript/src/assets/defineAssets.d.ts +20 -0
  97. package/lib/typescript/src/assets/defineAssets.d.ts.map +1 -0
  98. package/lib/typescript/src/assets/errors.d.ts +20 -0
  99. package/lib/typescript/src/assets/errors.d.ts.map +1 -0
  100. package/lib/typescript/src/assets/types.d.ts +138 -0
  101. package/lib/typescript/src/assets/types.d.ts.map +1 -0
  102. package/lib/typescript/src/assets/validation.d.ts +15 -0
  103. package/lib/typescript/src/assets/validation.d.ts.map +1 -0
  104. package/lib/typescript/src/core/frameDriver.d.ts +12 -0
  105. package/lib/typescript/src/core/frameDriver.d.ts.map +1 -0
  106. package/lib/typescript/src/core/input/createInputBuffer.d.ts +12 -0
  107. package/lib/typescript/src/core/input/createInputBuffer.d.ts.map +1 -0
  108. package/lib/typescript/src/core/input/types.d.ts +64 -0
  109. package/lib/typescript/src/core/input/types.d.ts.map +1 -0
  110. package/lib/typescript/src/core/session/createGameSession.d.ts +18 -0
  111. package/lib/typescript/src/core/session/createGameSession.d.ts.map +1 -0
  112. package/lib/typescript/src/core/session/deepFreeze.d.ts +27 -0
  113. package/lib/typescript/src/core/session/deepFreeze.d.ts.map +1 -0
  114. package/lib/typescript/src/core/session/diagnostics.d.ts +36 -0
  115. package/lib/typescript/src/core/session/diagnostics.d.ts.map +1 -0
  116. package/lib/typescript/src/core/session/types.d.ts +104 -0
  117. package/lib/typescript/src/core/session/types.d.ts.map +1 -0
  118. package/lib/typescript/src/definition/defineGame.d.ts +66 -0
  119. package/lib/typescript/src/definition/defineGame.d.ts.map +1 -0
  120. package/lib/typescript/src/definition/types.d.ts +56 -0
  121. package/lib/typescript/src/definition/types.d.ts.map +1 -0
  122. package/lib/typescript/src/geometry/types.d.ts +8 -0
  123. package/lib/typescript/src/geometry/types.d.ts.map +1 -0
  124. package/lib/typescript/src/index.d.ts +18 -0
  125. package/lib/typescript/src/index.d.ts.map +1 -0
  126. package/lib/typescript/src/react/GamePointerInput.d.ts +37 -0
  127. package/lib/typescript/src/react/GamePointerInput.d.ts.map +1 -0
  128. package/lib/typescript/src/react/GameView.d.ts +61 -0
  129. package/lib/typescript/src/react/GameView.d.ts.map +1 -0
  130. package/lib/typescript/src/react/alphaClock.d.ts +29 -0
  131. package/lib/typescript/src/react/alphaClock.d.ts.map +1 -0
  132. package/lib/typescript/src/react/assets/createGameAssetStore.d.ts +33 -0
  133. package/lib/typescript/src/react/assets/createGameAssetStore.d.ts.map +1 -0
  134. package/lib/typescript/src/react/assets/decodeSkiaImage.d.ts +12 -0
  135. package/lib/typescript/src/react/assets/decodeSkiaImage.d.ts.map +1 -0
  136. package/lib/typescript/src/react/assets/errors.d.ts +8 -0
  137. package/lib/typescript/src/react/assets/errors.d.ts.map +1 -0
  138. package/lib/typescript/src/react/assets/useGameAssets.d.ts +35 -0
  139. package/lib/typescript/src/react/assets/useGameAssets.d.ts.map +1 -0
  140. package/lib/typescript/src/react/bindAppLifecycle.d.ts +32 -0
  141. package/lib/typescript/src/react/bindAppLifecycle.d.ts.map +1 -0
  142. package/lib/typescript/src/react/bindGameSession.d.ts +14 -0
  143. package/lib/typescript/src/react/bindGameSession.d.ts.map +1 -0
  144. package/lib/typescript/src/react/gestureLifecycle.d.ts +37 -0
  145. package/lib/typescript/src/react/gestureLifecycle.d.ts.map +1 -0
  146. package/lib/typescript/src/react/instrumentation.d.ts +47 -0
  147. package/lib/typescript/src/react/instrumentation.d.ts.map +1 -0
  148. package/lib/typescript/src/react/pointerBinding.d.ts +104 -0
  149. package/lib/typescript/src/react/pointerBinding.d.ts.map +1 -0
  150. package/lib/typescript/src/react/pointerCoalescer.d.ts +106 -0
  151. package/lib/typescript/src/react/pointerCoalescer.d.ts.map +1 -0
  152. package/lib/typescript/src/react/pointerContainment.d.ts +12 -0
  153. package/lib/typescript/src/react/pointerContainment.d.ts.map +1 -0
  154. package/lib/typescript/src/react/sprites/GameSprite.d.ts +75 -0
  155. package/lib/typescript/src/react/sprites/GameSprite.d.ts.map +1 -0
  156. package/lib/typescript/src/react/sprites/GameWorld2D.d.ts +29 -0
  157. package/lib/typescript/src/react/sprites/GameWorld2D.d.ts.map +1 -0
  158. package/lib/typescript/src/react/sprites/Sprite.d.ts +43 -0
  159. package/lib/typescript/src/react/sprites/Sprite.d.ts.map +1 -0
  160. package/lib/typescript/src/react/sprites/SpriteBatch.d.ts +41 -0
  161. package/lib/typescript/src/react/sprites/SpriteBatch.d.ts.map +1 -0
  162. package/lib/typescript/src/react/sprites/spriteBatchPolicy.d.ts +10 -0
  163. package/lib/typescript/src/react/sprites/spriteBatchPolicy.d.ts.map +1 -0
  164. package/lib/typescript/src/react/sprites/spriteTransform.d.ts +86 -0
  165. package/lib/typescript/src/react/sprites/spriteTransform.d.ts.map +1 -0
  166. package/lib/typescript/src/react/viewportBinding.d.ts +42 -0
  167. package/lib/typescript/src/react/viewportBinding.d.ts.map +1 -0
  168. package/lib/typescript/src/react.d.ts +20 -0
  169. package/lib/typescript/src/react.d.ts.map +1 -0
  170. package/lib/typescript/src/scene/defineScene.d.ts +26 -0
  171. package/lib/typescript/src/scene/defineScene.d.ts.map +1 -0
  172. package/lib/typescript/src/scene/types.d.ts +71 -0
  173. package/lib/typescript/src/scene/types.d.ts.map +1 -0
  174. package/lib/typescript/src/sprites/sampleSpriteClip.d.ts +24 -0
  175. package/lib/typescript/src/sprites/sampleSpriteClip.d.ts.map +1 -0
  176. package/lib/typescript/src/sprites/spriteAnimationState.d.ts +45 -0
  177. package/lib/typescript/src/sprites/spriteAnimationState.d.ts.map +1 -0
  178. package/lib/typescript/src/testing.d.ts +28 -0
  179. package/lib/typescript/src/testing.d.ts.map +1 -0
  180. package/lib/typescript/src/viewport2d/index.d.ts +3 -0
  181. package/lib/typescript/src/viewport2d/index.d.ts.map +1 -0
  182. package/lib/typescript/src/viewport2d/math.d.ts +25 -0
  183. package/lib/typescript/src/viewport2d/math.d.ts.map +1 -0
  184. package/lib/typescript/src/viewport2d/types.d.ts +59 -0
  185. package/lib/typescript/src/viewport2d/types.d.ts.map +1 -0
  186. package/package.json +120 -0
  187. package/src/assets/defineAssets.ts +62 -0
  188. package/src/assets/errors.ts +64 -0
  189. package/src/assets/types.ts +164 -0
  190. package/src/assets/validation.ts +158 -0
  191. package/src/core/frameDriver.ts +31 -0
  192. package/src/core/input/createInputBuffer.ts +337 -0
  193. package/src/core/input/types.ts +67 -0
  194. package/src/core/session/createGameSession.ts +652 -0
  195. package/src/core/session/deepFreeze.ts +158 -0
  196. package/src/core/session/diagnostics.ts +35 -0
  197. package/src/core/session/types.ts +122 -0
  198. package/src/definition/defineGame.ts +94 -0
  199. package/src/definition/types.ts +67 -0
  200. package/src/geometry/types.ts +7 -0
  201. package/src/index.ts +84 -0
  202. package/src/react/GamePointerInput.tsx +478 -0
  203. package/src/react/GameView.tsx +317 -0
  204. package/src/react/alphaClock.ts +59 -0
  205. package/src/react/assets/createGameAssetStore.ts +459 -0
  206. package/src/react/assets/decodeSkiaImage.ts +64 -0
  207. package/src/react/assets/errors.ts +7 -0
  208. package/src/react/assets/useGameAssets.ts +171 -0
  209. package/src/react/bindAppLifecycle.ts +79 -0
  210. package/src/react/bindGameSession.ts +41 -0
  211. package/src/react/gestureLifecycle.ts +73 -0
  212. package/src/react/instrumentation.ts +54 -0
  213. package/src/react/pointerBinding.ts +226 -0
  214. package/src/react/pointerCoalescer.ts +234 -0
  215. package/src/react/pointerContainment.ts +23 -0
  216. package/src/react/sprites/GameSprite.tsx +192 -0
  217. package/src/react/sprites/GameWorld2D.tsx +46 -0
  218. package/src/react/sprites/Sprite.tsx +194 -0
  219. package/src/react/sprites/SpriteBatch.tsx +219 -0
  220. package/src/react/sprites/spriteBatchPolicy.ts +21 -0
  221. package/src/react/sprites/spriteTransform.ts +163 -0
  222. package/src/react/viewportBinding.ts +104 -0
  223. package/src/react.ts +37 -0
  224. package/src/scene/defineScene.ts +38 -0
  225. package/src/scene/types.ts +79 -0
  226. package/src/sprites/sampleSpriteClip.ts +51 -0
  227. package/src/sprites/spriteAnimationState.ts +176 -0
  228. package/src/testing.ts +61 -0
  229. package/src/viewport2d/index.ts +7 -0
  230. package/src/viewport2d/math.ts +134 -0
  231. package/src/viewport2d/types.ts +63 -0
@@ -0,0 +1,385 @@
1
+ "use strict";
2
+
3
+ import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
4
+ import { StyleSheet, View } from 'react-native';
5
+ import { GestureDetector, GestureStateManager, useManualGesture } from 'react-native-gesture-handler';
6
+ import { useFrameCallback, useSharedValue } from 'react-native-reanimated';
7
+ import { scheduleOnRN } from 'react-native-worklets';
8
+ import { GameViewportContext } from "./GameView.js";
9
+ import { canBeginPrimaryPointer, cancelOnActiveFinalize, deactivateAfterUp, reduceSamplerMirrorState, samplerMirrorFromBatch } from "./gestureLifecycle.js";
10
+ import { isBeginAllowed } from "./pointerContainment.js";
11
+ import { createPointerCoalescerState, reducePointerCoalescer } from "./pointerCoalescer.js";
12
+ import { PointerBinding } from "./pointerBinding.js";
13
+
14
+ /** Declared pointer action names of an input map. */
15
+ import { jsx as _jsx } from "react/jsx-runtime";
16
+ /** Monotonic adapter-owned binding generation; never resets to zero (F3). */
17
+ let nextBindingGeneration = 1;
18
+
19
+ /** Props for the pointer input adapter that covers the game surface. */
20
+
21
+ function advanceSharedCoalescer(sharedState, input) {
22
+ 'worklet';
23
+
24
+ const transition = reducePointerCoalescer(sharedState.value, input);
25
+ sharedState.value = transition.state;
26
+ return transition.events;
27
+ }
28
+
29
+ /**
30
+ * F2 trailing-flush sampler (review fix).
31
+ *
32
+ * Mounted only while the coalescer owns a pointer: the frame callback starts
33
+ * active at creation (autostart), forwards a deferred trailing move whenever
34
+ * the flush interval elapses, and the component unmounts — unregistering the
35
+ * callback — when the final pointer exits. No permanent frame callback and
36
+ * no runtime activation calls.
37
+ */
38
+ function TrailingFlushSampler({
39
+ coalescerState,
40
+ forwardEventOnJS,
41
+ instrumentation,
42
+ layoutEpoch,
43
+ forwardSeq,
44
+ generation
45
+ }) {
46
+ // F2 acceptance: report the sampler's mounted lifecycle so the lab can
47
+ // prove no idle frame callback survives pointer exit, replacement, or
48
+ // screen close/reopen.
49
+ const instrumentationRef = useRef(instrumentation);
50
+ useEffect(() => {
51
+ instrumentationRef.current?.onSamplerChanged?.(true);
52
+ return () => {
53
+ instrumentationRef.current?.onSamplerChanged?.(false);
54
+ };
55
+ }, []);
56
+ useFrameCallback(() => {
57
+ 'worklet';
58
+
59
+ const batch = advanceSharedCoalescer(coalescerState, {
60
+ kind: 'flush',
61
+ nowMs: Date.now()
62
+ });
63
+ for (const forwarded of batch) {
64
+ instrumentation?.onForwarded?.(forwarded.kind, 'pointerId' in forwarded ? forwarded.pointerId : -1, Date.now());
65
+ forwardSeq.value += 1;
66
+ scheduleOnRN(forwardEventOnJS, {
67
+ ...forwarded,
68
+ generation,
69
+ layoutEpoch: layoutEpoch.value,
70
+ seq: forwardSeq.value,
71
+ atMs: Date.now()
72
+ });
73
+ }
74
+ });
75
+ return null;
76
+ }
77
+
78
+ /**
79
+ * Bind one primary pointer to a declared pointer action.
80
+ *
81
+ * Gesture Handler is an implementation detail: the manual gesture activates
82
+ * explicitly on touch down, mirrors the letterbox containment check on the UI
83
+ * runtime (failing the gesture before activation), forwards plain touch data
84
+ * through a coalescer that crosses runtimes at most once per fixed step
85
+ * (latest dirty position only; edges never throttled or dropped), and ends
86
+ * explicitly when the last touch lifts. Ownership and edge sampling stay
87
+ * authoritative in the session input buffer, which re-validates every
88
+ * forwarded event on the JS side.
89
+ *
90
+ * All separately registered touch-handler worklets share one explicit
91
+ * coalescer SharedValue; closure-local mutation is not used because each
92
+ * handler can receive its own serialized closure copy. The binding is stable
93
+ * across ordinary React renders and is recreated only when its semantic
94
+ * session, action, or viewport owner changes.
95
+ */
96
+ export function GamePointerInput({
97
+ game,
98
+ action,
99
+ instrumentation
100
+ }) {
101
+ const viewportContext = useContext(GameViewportContext);
102
+ if (viewportContext === null) {
103
+ throw new Error('GamePointerInput must be rendered inside a GameView');
104
+ }
105
+ const viewportShared = viewportContext.viewport;
106
+ const maxMoveIntervalMs = game.getRenderFrame().stepMs;
107
+ const coalescerState = useSharedValue(() => createPointerCoalescerState(maxMoveIntervalMs));
108
+ const viewportBinding = viewportContext.binding;
109
+ // F3 follow-up: the binding identity includes the declared action, the
110
+ // session input controller, and the viewport owner; changing any of them
111
+ // creates a fresh binding stamped with a NEW monotonic generation that
112
+ // never resets to zero. The worklet closures created in the same render
113
+ // stamp packets with that same generation, so the packet producer and
114
+ // consumer agree by construction — no post-commit synchronization.
115
+ const binding = useMemo(() => new PointerBinding(action, game.input, () => viewportBinding.resolved, nextBindingGeneration++), [action, game, viewportBinding]);
116
+ const generation = binding.generation;
117
+ // F6/F3: the layout epoch is adapter-owned (ref + UI mirror), bumped only
118
+ // on layout revisions and unmount; it never resets, so replacement cannot
119
+ // desynchronize it. The RN-side dispatch check rejects old-layout packets.
120
+ const layoutEpochRef = useRef(0);
121
+ const layoutEpoch = useSharedValue(0);
122
+ const bumpLayoutEpoch = useCallback(() => {
123
+ layoutEpochRef.current += 1;
124
+ layoutEpoch.value = layoutEpochRef.current;
125
+ }, [layoutEpoch]);
126
+ // F1: monotonic forward sequence carried with every packet so the RN side
127
+ // can attribute latency causally (never by reading a separate "latest").
128
+ const forwardSeq = useSharedValue(0);
129
+
130
+ // F2 follow-up: the sampler mirror is keyed by binding generation, so a
131
+ // replacement binding is inactive by construction and a stale terminal
132
+ // edge from an older generation can never alter the current generation's
133
+ // sampler state.
134
+ const [samplerState, setSamplerState] = useState({
135
+ generation: -1,
136
+ active: false
137
+ });
138
+ const reportSamplerState = useCallback(next => {
139
+ setSamplerState(previous => reduceSamplerMirrorState(generation, previous, next));
140
+ }, [generation]);
141
+
142
+ // F2 review: `autostart` is only consulted at creation (changing it later
143
+ // re-registers but never activates) and `setActive` from an effect proved
144
+ // unreliable in this stack, so the sampler is a conditionally mounted
145
+ // component (see TrailingFlushSampler): it mounts with autostart active
146
+ // exactly while this mirror is true and unmounts when the pointer exits.
147
+
148
+ // JS-thread handler (never captured by gesture worklets): the binding
149
+ // rejects packets stamped with a stale epoch (layout revision, binding
150
+ // replacement, unmount) and re-validates the viewport before forwarding
151
+ // into the session input buffer.
152
+ const forwardEventOnJS = useCallback(packet => {
153
+ // F6/F3: adapter-owned layout epoch — packets scheduled under an older
154
+ // layout die here, before the binding sees them.
155
+ if (packet.layoutEpoch !== layoutEpochRef.current) {
156
+ instrumentation?.onDispatchResult?.(packet.seq, packet.atMs, false);
157
+ return;
158
+ }
159
+ const accepted = binding.dispatch(packet);
160
+ instrumentation?.onDispatchResult?.(packet.seq, packet.atMs, accepted);
161
+ }, [binding, instrumentation]);
162
+ const handleTouchesDown = useCallback(event => {
163
+ 'worklet';
164
+
165
+ const touch = event.changedTouches[0];
166
+ if (touch === undefined) {
167
+ return;
168
+ }
169
+ instrumentation?.onRawTouch?.('down', touch.id, Date.now());
170
+ // This adapter owns one primary pointer for the whole native gesture.
171
+ // If another touch is already present, it cannot replace a pointer that
172
+ // ended earlier while the manual recognizer is still active.
173
+ if (!canBeginPrimaryPointer(event.numberOfTouches)) {
174
+ return;
175
+ }
176
+ // UI-side containment mirror: an invalid layout or `fit` letterbox
177
+ // begin fails the gesture before it activates. JS re-validates.
178
+ if (!isBeginAllowed(viewportShared.value, touch.x, touch.y)) {
179
+ GestureStateManager.fail(event.handlerTag);
180
+ return;
181
+ }
182
+ const batch = advanceSharedCoalescer(coalescerState, {
183
+ kind: 'down',
184
+ pointerId: touch.id,
185
+ x: touch.x,
186
+ y: touch.y,
187
+ nowMs: Date.now()
188
+ });
189
+ for (const forwarded of batch) {
190
+ instrumentation?.onForwarded?.(forwarded.kind, 'pointerId' in forwarded ? forwarded.pointerId : -1, Date.now());
191
+ forwardSeq.value += 1;
192
+ scheduleOnRN(forwardEventOnJS, {
193
+ ...forwarded,
194
+ generation,
195
+ layoutEpoch: layoutEpoch.value,
196
+ seq: forwardSeq.value,
197
+ atMs: Date.now()
198
+ });
199
+ }
200
+ const nextActive = samplerMirrorFromBatch(batch);
201
+ if (nextActive !== undefined) {
202
+ scheduleOnRN(reportSamplerState, {
203
+ generation,
204
+ active: nextActive
205
+ });
206
+ }
207
+ GestureStateManager.activate(event.handlerTag);
208
+ }, [coalescerState, forwardEventOnJS, generation, instrumentation, layoutEpoch, reportSamplerState, viewportShared]);
209
+ const handleTouchesMove = useCallback(event => {
210
+ 'worklet';
211
+
212
+ for (const touch of event.changedTouches) {
213
+ instrumentation?.onRawTouch?.('move', touch.id, Date.now());
214
+ const batch = advanceSharedCoalescer(coalescerState, {
215
+ kind: 'move',
216
+ pointerId: touch.id,
217
+ x: touch.x,
218
+ y: touch.y,
219
+ nowMs: Date.now()
220
+ });
221
+ for (const forwarded of batch) {
222
+ instrumentation?.onForwarded?.(forwarded.kind, 'pointerId' in forwarded ? forwarded.pointerId : -1, Date.now());
223
+ forwardSeq.value += 1;
224
+ scheduleOnRN(forwardEventOnJS, {
225
+ ...forwarded,
226
+ generation,
227
+ layoutEpoch: layoutEpoch.value,
228
+ seq: forwardSeq.value,
229
+ atMs: Date.now()
230
+ });
231
+ }
232
+ }
233
+ }, [coalescerState, forwardEventOnJS, generation, instrumentation, layoutEpoch]);
234
+ const handleTouchesUp = useCallback(event => {
235
+ 'worklet';
236
+
237
+ let nextActive;
238
+ for (const touch of event.changedTouches) {
239
+ instrumentation?.onRawTouch?.('up', touch.id, Date.now());
240
+ const batch = advanceSharedCoalescer(coalescerState, {
241
+ kind: 'up',
242
+ pointerId: touch.id,
243
+ x: touch.x,
244
+ y: touch.y,
245
+ nowMs: Date.now()
246
+ });
247
+ for (const forwarded of batch) {
248
+ instrumentation?.onForwarded?.(forwarded.kind, 'pointerId' in forwarded ? forwarded.pointerId : -1, Date.now());
249
+ forwardSeq.value += 1;
250
+ scheduleOnRN(forwardEventOnJS, {
251
+ ...forwarded,
252
+ generation,
253
+ layoutEpoch: layoutEpoch.value,
254
+ seq: forwardSeq.value,
255
+ atMs: Date.now()
256
+ });
257
+ }
258
+ const mirror = samplerMirrorFromBatch(batch);
259
+ if (mirror !== undefined) {
260
+ nextActive = mirror;
261
+ }
262
+ }
263
+ if (nextActive !== undefined) {
264
+ scheduleOnRN(reportSamplerState, {
265
+ generation,
266
+ active: nextActive
267
+ });
268
+ }
269
+ if (deactivateAfterUp(event.numberOfTouches)) {
270
+ GestureStateManager.deactivate(event.handlerTag);
271
+ }
272
+ }, [coalescerState, forwardEventOnJS, generation, instrumentation, layoutEpoch, reportSamplerState]);
273
+ const handleTouchesCancel = useCallback(() => {
274
+ 'worklet';
275
+
276
+ instrumentation?.onRawTouch?.('cancel', -1, Date.now());
277
+ const batch = advanceSharedCoalescer(coalescerState, {
278
+ kind: 'cancel',
279
+ nowMs: Date.now()
280
+ });
281
+ for (const forwarded of batch) {
282
+ instrumentation?.onForwarded?.(forwarded.kind, -1, Date.now());
283
+ forwardSeq.value += 1;
284
+ scheduleOnRN(forwardEventOnJS, {
285
+ ...forwarded,
286
+ generation,
287
+ layoutEpoch: layoutEpoch.value,
288
+ seq: forwardSeq.value,
289
+ atMs: Date.now()
290
+ });
291
+ }
292
+ const nextActive = samplerMirrorFromBatch(batch);
293
+ if (nextActive !== undefined) {
294
+ scheduleOnRN(reportSamplerState, {
295
+ generation,
296
+ active: nextActive
297
+ });
298
+ }
299
+ }, [coalescerState, forwardEventOnJS, generation, instrumentation, layoutEpoch, reportSamplerState]);
300
+ const handleFinalize = useCallback(() => {
301
+ 'worklet';
302
+
303
+ if (!cancelOnActiveFinalize(coalescerState.value.active?.pointerId)) {
304
+ return;
305
+ }
306
+ instrumentation?.onRawTouch?.('cancel', -1, Date.now());
307
+ const batch = advanceSharedCoalescer(coalescerState, {
308
+ kind: 'cancel',
309
+ nowMs: Date.now()
310
+ });
311
+ for (const forwarded of batch) {
312
+ instrumentation?.onForwarded?.(forwarded.kind, -1, Date.now());
313
+ forwardSeq.value += 1;
314
+ scheduleOnRN(forwardEventOnJS, {
315
+ ...forwarded,
316
+ generation,
317
+ layoutEpoch: layoutEpoch.value,
318
+ seq: forwardSeq.value,
319
+ atMs: Date.now()
320
+ });
321
+ }
322
+ const nextActive = samplerMirrorFromBatch(batch);
323
+ if (nextActive !== undefined) {
324
+ scheduleOnRN(reportSamplerState, {
325
+ generation,
326
+ active: nextActive
327
+ });
328
+ }
329
+ }, [coalescerState, forwardEventOnJS, generation, instrumentation, layoutEpoch, reportSamplerState]);
330
+
331
+ // RNGH 3 re-registers its gesture callbacks whenever this config identity
332
+ // changes. Keep both the config and its worklets stable across unrelated
333
+ // React renders (for example, a score HUD update during a live drag).
334
+ const gestureConfig = useMemo(() => ({
335
+ shouldCancelWhenOutside: false,
336
+ onTouchesDown: handleTouchesDown,
337
+ onTouchesMove: handleTouchesMove,
338
+ onTouchesUp: handleTouchesUp,
339
+ onTouchesCancel: handleTouchesCancel,
340
+ onFinalize: handleFinalize
341
+ }), [handleFinalize, handleTouchesCancel, handleTouchesDown, handleTouchesMove, handleTouchesUp]);
342
+ const gesture = useManualGesture(gestureConfig);
343
+ useEffect(() => {
344
+ // F6/F3: a layout revision advances the adapter-owned layout epoch so
345
+ // queued old-layout packets die on arrival, while the active gesture
346
+ // keeps flowing (the binding reads the viewport lazily and the
347
+ // coalescer state is preserved). Binding replacement needs no epoch
348
+ // synchronization: the generation agreement is by construction.
349
+ const unsubscribeLayout = viewportBinding.subscribe(() => {
350
+ bumpLayoutEpoch();
351
+ });
352
+ return () => {
353
+ unsubscribeLayout();
354
+ // Unmount or replacement: bump the layout epoch so packets already in
355
+ // flight become harmless no-ops, neutralize old input ownership exactly
356
+ // once, reset the coalescer, remove the old sampler (generation
357
+ // mismatch makes it inactive by construction), and dispose the binding.
358
+ bumpLayoutEpoch();
359
+ setSamplerState({
360
+ generation: -1,
361
+ active: false
362
+ });
363
+ if (game.status !== 'disposed') {
364
+ binding.cancel();
365
+ }
366
+ coalescerState.value = createPointerCoalescerState(maxMoveIntervalMs);
367
+ binding.dispose();
368
+ };
369
+ }, [binding, bumpLayoutEpoch, coalescerState, game, layoutEpoch, maxMoveIntervalMs, viewportBinding]);
370
+ return /*#__PURE__*/_jsx(GestureDetector, {
371
+ gesture: gesture,
372
+ children: /*#__PURE__*/_jsx(View, {
373
+ style: StyleSheet.absoluteFill,
374
+ children: samplerState.active && samplerState.generation === generation ? /*#__PURE__*/_jsx(TrailingFlushSampler, {
375
+ coalescerState: coalescerState,
376
+ forwardEventOnJS: forwardEventOnJS,
377
+ instrumentation: instrumentation,
378
+ layoutEpoch: layoutEpoch,
379
+ forwardSeq: forwardSeq,
380
+ generation: generation
381
+ }) : null
382
+ })
383
+ });
384
+ }
385
+ //# sourceMappingURL=GamePointerInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useContext","useEffect","useMemo","useRef","useState","StyleSheet","View","GestureDetector","GestureStateManager","useManualGesture","useFrameCallback","useSharedValue","scheduleOnRN","GameViewportContext","canBeginPrimaryPointer","cancelOnActiveFinalize","deactivateAfterUp","reduceSamplerMirrorState","samplerMirrorFromBatch","isBeginAllowed","createPointerCoalescerState","reducePointerCoalescer","PointerBinding","jsx","_jsx","nextBindingGeneration","advanceSharedCoalescer","sharedState","input","transition","value","state","events","TrailingFlushSampler","coalescerState","forwardEventOnJS","instrumentation","layoutEpoch","forwardSeq","generation","instrumentationRef","current","onSamplerChanged","batch","kind","nowMs","Date","now","forwarded","onForwarded","pointerId","seq","atMs","GamePointerInput","game","action","viewportContext","Error","viewportShared","viewport","maxMoveIntervalMs","getRenderFrame","stepMs","viewportBinding","binding","resolved","layoutEpochRef","bumpLayoutEpoch","samplerState","setSamplerState","active","reportSamplerState","next","previous","packet","onDispatchResult","accepted","dispatch","handleTouchesDown","event","touch","changedTouches","undefined","onRawTouch","id","numberOfTouches","x","y","fail","handlerTag","nextActive","activate","handleTouchesMove","handleTouchesUp","mirror","deactivate","handleTouchesCancel","handleFinalize","gestureConfig","shouldCancelWhenOutside","onTouchesDown","onTouchesMove","onTouchesUp","onTouchesCancel","onFinalize","gesture","unsubscribeLayout","subscribe","status","cancel","dispose","children","style","absoluteFill"],"sourceRoot":"../../../src","sources":["react/GamePointerInput.tsx"],"mappings":";;AAAA,SAASA,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACrF,SAASC,UAAU,EAAEC,IAAI,QAAQ,cAAc;AAC/C,SACEC,eAAe,EACfC,mBAAmB,EACnBC,gBAAgB,QAEX,8BAA8B;AACrC,SAASC,gBAAgB,EAAEC,cAAc,QAA0B,yBAAyB;AAC5F,SAASC,YAAY,QAAQ,uBAAuB;AAIpD,SAASC,mBAAmB,QAAQ,eAAY;AAChD,SACEC,sBAAsB,EACtBC,sBAAsB,EACtBC,iBAAiB,EACjBC,wBAAwB,EACxBC,sBAAsB,QAEjB,uBAAoB;AAE3B,SAASC,cAAc,QAAQ,yBAAsB;AACrD,SACEC,2BAA2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AACjB,eAAe;IAACkG,OAAO,EAAEA,OAAQ;IAAAM,QAAA,eAChCvF,IAAA,CAAClB,IAAI;MAAC0G,KAAK,EAAE3G,UAAU,CAAC4G,YAAa;MAAAF,QAAA,EAClC3C,YAAY,CAACE,MAAM,IAAIF,YAAY,CAAC7B,UAAU,KAAKA,UAAU,gBAC5Df,IAAA,CAACS,oBAAoB;QACnBC,cAAc,EAAEA,cAAe;QAC/BC,gBAAgB,EAAEA,gBAAiB;QACnCC,eAAe,EAAEA,eAAgB;QACjCC,WAAW,EAAEA,WAAY;QACzBC,UAAU,EAAEA,UAAW;QACvBC,UAAU,EAAEA;MAAW,CACxB,CAAC,GACA;IAAI,CACJ;EAAC,CACQ,CAAC;AAEtB","ignoreList":[]}
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+
3
+ import { Canvas } from '@shopify/react-native-skia';
4
+ import { createContext, useCallback, useEffect, useMemo, useRef } from 'react';
5
+ import { AppState, StyleSheet, View } from 'react-native';
6
+ import { useFrameCallback, useSharedValue } from 'react-native-reanimated';
7
+ import { scheduleOnRN } from 'react-native-worklets';
8
+ import { advanceAlpha } from "./alphaClock.js";
9
+ import { bindAppLifecycle } from "./bindAppLifecycle.js";
10
+ import { bindGameSession } from "./bindGameSession.js";
11
+ import { bindingForViewport } from "./viewportBinding.js";
12
+
13
+ /** Stable imperative values supplied to a Skia renderer component. */
14
+
15
+ /** Props for the Skia-backed GameKit view. */
16
+
17
+ /**
18
+ * Context supplying the resolved viewport to pointer input children.
19
+ *
20
+ * `GamePointerInput` consumes the binding for JS-side conversion and the
21
+ * shared value for the UI-side containment mirror, so drawing and hit
22
+ * testing always use the same resolved viewport instance for a layout
23
+ * revision.
24
+ */
25
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
26
+ export const GameViewportContext = /*#__PURE__*/createContext(null);
27
+
28
+ /**
29
+ * Mount a headless GameSession into a Skia canvas.
30
+ *
31
+ * Simulation commits update the frame shared value at commit frequency (one
32
+ * per fixed step, never per display frame); the presentation fraction lives
33
+ * on the UI runtime and is advanced by a frame callback that resets on every
34
+ * new commit, clamps at 1, and never extrapolates. The clock is gated by a
35
+ * `running` shared value so pause, background, unmount, and dispose hold the
36
+ * presentation. React owns the surface and static overlay tree; it is never
37
+ * the frame store. The session is started while mounted, paused on cleanup
38
+ * and app backgrounding, and is never disposed by this component — the
39
+ * creator owns disposal.
40
+ */
41
+ /**
42
+ * Per-session presentation binding (RF6).
43
+ *
44
+ * Keyed by the session so the frame, alpha, epoch, and clock initialize from
45
+ * the new session BEFORE its renderer can execute — a replacement renderer
46
+ * never observes the previous session's frame, even when both scenes are
47
+ * named the same.
48
+ */
49
+ function GamePresentation({
50
+ game,
51
+ assets,
52
+ renderer,
53
+ viewportValue,
54
+ instrumentationRef
55
+ }) {
56
+ const Renderer = renderer;
57
+ const frame = useSharedValue(() => game.getRenderFrame());
58
+ const alpha = useSharedValue(0);
59
+ const running = useSharedValue(true);
60
+ // Binding epoch: bumped per (re)subscription so a replacement session whose
61
+ // revision restarts at zero is still accepted by the UI clock.
62
+ const epoch = useSharedValue(0);
63
+ const clockEpoch = useSharedValue(0);
64
+ const clockRevision = useSharedValue(-1);
65
+ // F1: last revision/epoch the UI clock observed, so the instrumentation can
66
+ // report the FIRST UI frame that saw a new commit.
67
+ const observedRevision = useSharedValue(-1);
68
+ const observedEpoch = useSharedValue(-1);
69
+ useEffect(() => {
70
+ epoch.value += 1;
71
+ // RF6: the frame is seeded at mount from this session; the keyed remount
72
+ // guarantees the renderer below never reads the previous session's frame.
73
+ frame.value = game.getRenderFrame();
74
+ const cleanupBinding = bindGameSession(game, nextFrame => {
75
+ frame.value = nextFrame;
76
+ instrumentationRef.current?.onPresentCommit?.(nextFrame.revision, Date.now());
77
+ });
78
+ const cleanupLifecycle = bindAppLifecycle(AppState, {
79
+ getStatus: () => game.status,
80
+ pause: () => {
81
+ running.value = false;
82
+ if (game.status !== 'disposed') {
83
+ game.pause();
84
+ }
85
+ },
86
+ resume: () => {
87
+ if (game.status !== 'disposed') {
88
+ game.start();
89
+ running.value = true;
90
+ }
91
+ }
92
+ });
93
+ return () => {
94
+ cleanupLifecycle();
95
+ cleanupBinding();
96
+ };
97
+ }, [epoch, frame, game, running]);
98
+
99
+ // F1: the first UI frame that sees a new commit revision is reported back
100
+ // to the RN runtime through scheduleOnRN — never by calling the JS hook
101
+ // directly from the UI worklet (cross-runtime calls crash the app).
102
+ const reportUiObserved = useCallback((revision, atMs) => {
103
+ instrumentationRef.current?.onUiRevisionObserved?.(revision, atMs);
104
+ }, []);
105
+
106
+ // UI-owned alpha clock: advances only while the session is running,
107
+ // resets on every new commit, clamps at 1 and holds (no extrapolation).
108
+ useFrameCallback(frameInfo => {
109
+ 'worklet';
110
+
111
+ if (!running.value) {
112
+ return;
113
+ }
114
+ const envelope = frame.value;
115
+ if (observedEpoch.value !== epoch.value || observedRevision.value !== envelope.revision) {
116
+ observedEpoch.value = epoch.value;
117
+ observedRevision.value = envelope.revision;
118
+ scheduleOnRN(reportUiObserved, envelope.revision, Date.now());
119
+ }
120
+ const previousState = {
121
+ epoch: clockEpoch.value,
122
+ revision: clockRevision.value,
123
+ alpha: alpha.value
124
+ };
125
+ const nextState = advanceAlpha(previousState, {
126
+ epoch: epoch.value,
127
+ revision: envelope.revision,
128
+ stepMs: envelope.stepMs
129
+ }, frameInfo.timeSincePreviousFrame ?? 1000 / 60);
130
+ clockEpoch.value = nextState.epoch;
131
+ clockRevision.value = nextState.revision;
132
+ alpha.value = nextState.alpha;
133
+ });
134
+ return /*#__PURE__*/_jsx(Renderer, {
135
+ frame: frame,
136
+ alpha: alpha,
137
+ viewport: viewportValue,
138
+ ...(assets === undefined ? {} : {
139
+ assets
140
+ })
141
+ });
142
+ }
143
+
144
+ // Stable per-session fallback identity (T8.6): one incrementing id per
145
+ // session object for the life of the module. A replaced session is a new
146
+ // object and therefore a new id; the same session keeps its id across
147
+ // renders so the presentation never remounts spuriously.
148
+ const sessionPresentationIds = new WeakMap();
149
+ let nextSessionPresentationId = 1;
150
+ function sessionPresentationId(game) {
151
+ let id = sessionPresentationIds.get(game);
152
+ if (id === undefined) {
153
+ id = nextSessionPresentationId;
154
+ nextSessionPresentationId += 1;
155
+ sessionPresentationIds.set(game, id);
156
+ }
157
+ return id;
158
+ }
159
+ export function GameView({
160
+ game,
161
+ presentationKey,
162
+ assets,
163
+ renderer: Renderer,
164
+ children,
165
+ style,
166
+ instrumentation
167
+ }) {
168
+ const instrumentationRef = useRef(instrumentation);
169
+ const bindingRef = useRef(null);
170
+ bindingRef.current = bindingForViewport(game.viewport, bindingRef.current);
171
+ const binding = bindingRef.current;
172
+ const viewportValue = useSharedValue(undefined);
173
+ const viewportContext = useMemo(() => ({
174
+ binding,
175
+ viewport: viewportValue
176
+ }), [binding, viewportValue]);
177
+ useEffect(() => {
178
+ instrumentationRef.current = instrumentation;
179
+ }, [instrumentation]);
180
+ useEffect(() => {
181
+ viewportValue.value = binding.resolved;
182
+ }, [binding, viewportValue]);
183
+ useEffect(() => () => {
184
+ binding.dispose();
185
+ }, [binding]);
186
+ return /*#__PURE__*/_jsx(GameViewportContext.Provider, {
187
+ value: viewportContext,
188
+ children: /*#__PURE__*/_jsxs(View, {
189
+ style: [styles.surface, style],
190
+ onLayout: event => {
191
+ const {
192
+ width,
193
+ height
194
+ } = event.nativeEvent.layout;
195
+ binding.setSurfaceSize({
196
+ width,
197
+ height
198
+ });
199
+ viewportValue.value = binding.resolved;
200
+ },
201
+ children: [/*#__PURE__*/_jsx(Canvas, {
202
+ style: StyleSheet.absoluteFill,
203
+ children: /*#__PURE__*/_jsx(GamePresentation, {
204
+ game: game,
205
+ assets: assets,
206
+ renderer: Renderer,
207
+ viewportValue: viewportValue,
208
+ instrumentationRef: instrumentationRef
209
+ }, presentationKey ?? sessionPresentationId(game))
210
+ }), children === undefined ? null : /*#__PURE__*/_jsx(View, {
211
+ pointerEvents: "box-none",
212
+ style: StyleSheet.absoluteFill,
213
+ children: children
214
+ })]
215
+ })
216
+ });
217
+ }
218
+ const styles = StyleSheet.create({
219
+ surface: {
220
+ overflow: 'hidden'
221
+ }
222
+ });
223
+ //# sourceMappingURL=GameView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Canvas","createContext","useCallback","useEffect","useMemo","useRef","AppState","StyleSheet","View","useFrameCallback","useSharedValue","scheduleOnRN","advanceAlpha","bindAppLifecycle","bindGameSession","bindingForViewport","jsx","_jsx","jsxs","_jsxs","GameViewportContext","GamePresentation","game","assets","renderer","viewportValue","instrumentationRef","Renderer","frame","getRenderFrame","alpha","running","epoch","clockEpoch","clockRevision","observedRevision","observedEpoch","value","cleanupBinding","nextFrame","current","onPresentCommit","revision","Date","now","cleanupLifecycle","getStatus","status","pause","resume","start","reportUiObserved","atMs","onUiRevisionObserved","frameInfo","envelope","previousState","nextState","stepMs","timeSincePreviousFrame","viewport","undefined","sessionPresentationIds","WeakMap","nextSessionPresentationId","sessionPresentationId","id","get","set","GameView","presentationKey","children","style","instrumentation","bindingRef","binding","viewportContext","resolved","dispose","Provider","styles","surface","onLayout","event","width","height","nativeEvent","layout","setSurfaceSize","absoluteFill","pointerEvents","create","overflow"],"sourceRoot":"../../../src","sources":["react/GameView.tsx"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,4BAA4B;AACnD,SACEC,aAAa,EACbC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,MAAM,QAGD,OAAO;AACd,SACEC,QAAQ,EACRC,UAAU,EACVC,IAAI,QAGC,cAAc;AACrB,SAASC,gBAAgB,EAAEC,cAAc,QAA0B,yBAAyB;AAC5F,SAASC,YAAY,QAAQ,uBAAuB;AAMpD,SAASC,YAAY,QAAQ,iBAAc;AAC3C,SAASC,gBAAgB,QAAQ,uBAAoB;AACrD,SAASC,eAAe,QAAQ,sBAAmB;AAEnD,SAASC,kBAAkB,QAA8B,sBAAmB;;AAE5E;;AAkBA;;AA2BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPA,SAAAC,GAAA,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