@tamagui/react-native-use-responder-events 1.13.2 → 1.13.4
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.
- package/dist/cjs/ResponderSystem.js +1 -388
- package/dist/cjs/ResponderSystem.js.map +2 -2
- package/dist/cjs/ResponderTouchHistoryStore.js +5 -193
- package/dist/cjs/ResponderTouchHistoryStore.js.map +2 -2
- package/dist/cjs/createResponderEvent.js +1 -150
- package/dist/cjs/createResponderEvent.js.map +2 -2
- package/dist/cjs/index.js +1 -18
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js +1 -97
- package/dist/cjs/types.js.map +2 -2
- package/dist/cjs/useResponderEvents.js +1 -79
- package/dist/cjs/useResponderEvents.js.map +2 -2
- package/dist/cjs/utils.js +2 -173
- package/dist/cjs/utils.js.map +2 -2
- package/dist/esm/ResponderSystem.js +1 -364
- package/dist/esm/ResponderSystem.js.map +2 -2
- package/dist/esm/ResponderSystem.mjs +1 -364
- package/dist/esm/ResponderSystem.mjs.map +2 -2
- package/dist/esm/ResponderTouchHistoryStore.js +5 -169
- package/dist/esm/ResponderTouchHistoryStore.js.map +2 -2
- package/dist/esm/ResponderTouchHistoryStore.mjs +5 -169
- package/dist/esm/ResponderTouchHistoryStore.mjs.map +2 -2
- package/dist/esm/createResponderEvent.js +1 -128
- package/dist/esm/createResponderEvent.js.map +2 -2
- package/dist/esm/createResponderEvent.mjs +1 -128
- package/dist/esm/createResponderEvent.mjs.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/types.js +1 -54
- package/dist/esm/types.js.map +2 -2
- package/dist/esm/types.mjs +1 -54
- package/dist/esm/types.mjs.map +2 -2
- package/dist/esm/useResponderEvents.js +1 -44
- package/dist/esm/useResponderEvents.js.map +2 -2
- package/dist/esm/useResponderEvents.mjs +1 -44
- package/dist/esm/useResponderEvents.mjs.map +2 -2
- package/dist/esm/utils.js +2 -141
- package/dist/esm/utils.js.map +2 -2
- package/dist/esm/utils.mjs +2 -141
- package/dist/esm/utils.mjs.map +2 -2
- package/package.json +2 -2
|
@@ -1,170 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
function createTouchRecord(touch) {
|
|
7
|
-
return {
|
|
8
|
-
touchActive: true,
|
|
9
|
-
startPageX: touch.pageX,
|
|
10
|
-
startPageY: touch.pageY,
|
|
11
|
-
startTimeStamp: timestampForTouch(touch),
|
|
12
|
-
currentPageX: touch.pageX,
|
|
13
|
-
currentPageY: touch.pageY,
|
|
14
|
-
currentTimeStamp: timestampForTouch(touch),
|
|
15
|
-
previousPageX: touch.pageX,
|
|
16
|
-
previousPageY: touch.pageY,
|
|
17
|
-
previousTimeStamp: timestampForTouch(touch)
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function resetTouchRecord(touchRecord, touch) {
|
|
21
|
-
touchRecord.touchActive = true;
|
|
22
|
-
touchRecord.startPageX = touch.pageX;
|
|
23
|
-
touchRecord.startPageY = touch.pageY;
|
|
24
|
-
touchRecord.startTimeStamp = timestampForTouch(touch);
|
|
25
|
-
touchRecord.currentPageX = touch.pageX;
|
|
26
|
-
touchRecord.currentPageY = touch.pageY;
|
|
27
|
-
touchRecord.currentTimeStamp = timestampForTouch(touch);
|
|
28
|
-
touchRecord.previousPageX = touch.pageX;
|
|
29
|
-
touchRecord.previousPageY = touch.pageY;
|
|
30
|
-
touchRecord.previousTimeStamp = timestampForTouch(touch);
|
|
31
|
-
}
|
|
32
|
-
function getTouchIdentifier({ identifier }) {
|
|
33
|
-
if (identifier == null) {
|
|
34
|
-
console.error("Touch object is missing identifier.");
|
|
35
|
-
}
|
|
36
|
-
if (process.env.NODE_ENV === "development") {
|
|
37
|
-
if (identifier > MAX_TOUCH_BANK) {
|
|
38
|
-
console.error(
|
|
39
|
-
"Touch identifier %s is greater than maximum supported %s which causes performance issues backfilling array locations for all of the indices.",
|
|
40
|
-
identifier,
|
|
41
|
-
MAX_TOUCH_BANK
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return identifier;
|
|
46
|
-
}
|
|
47
|
-
function recordTouchStart(touch, touchHistory) {
|
|
48
|
-
const identifier = getTouchIdentifier(touch);
|
|
49
|
-
const touchRecord = touchHistory.touchBank[identifier];
|
|
50
|
-
if (touchRecord) {
|
|
51
|
-
resetTouchRecord(touchRecord, touch);
|
|
52
|
-
} else {
|
|
53
|
-
touchHistory.touchBank[identifier] = createTouchRecord(touch);
|
|
54
|
-
}
|
|
55
|
-
touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
|
|
56
|
-
}
|
|
57
|
-
function recordTouchMove(touch, touchHistory) {
|
|
58
|
-
const touchRecord = touchHistory.touchBank[getTouchIdentifier(touch)];
|
|
59
|
-
if (touchRecord) {
|
|
60
|
-
touchRecord.touchActive = true;
|
|
61
|
-
touchRecord.previousPageX = touchRecord.currentPageX;
|
|
62
|
-
touchRecord.previousPageY = touchRecord.currentPageY;
|
|
63
|
-
touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
|
|
64
|
-
touchRecord.currentPageX = touch.pageX;
|
|
65
|
-
touchRecord.currentPageY = touch.pageY;
|
|
66
|
-
touchRecord.currentTimeStamp = timestampForTouch(touch);
|
|
67
|
-
touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
|
|
68
|
-
} else {
|
|
69
|
-
console.warn(
|
|
70
|
-
"Cannot record touch move without a touch start.\n",
|
|
71
|
-
`Touch Move: ${printTouch(touch)}
|
|
72
|
-
`,
|
|
73
|
-
`Touch Bank: ${printTouchBank(touchHistory)}`
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function recordTouchEnd(touch, touchHistory) {
|
|
78
|
-
const touchRecord = touchHistory.touchBank[getTouchIdentifier(touch)];
|
|
79
|
-
if (touchRecord) {
|
|
80
|
-
touchRecord.touchActive = false;
|
|
81
|
-
touchRecord.previousPageX = touchRecord.currentPageX;
|
|
82
|
-
touchRecord.previousPageY = touchRecord.currentPageY;
|
|
83
|
-
touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
|
|
84
|
-
touchRecord.currentPageX = touch.pageX;
|
|
85
|
-
touchRecord.currentPageY = touch.pageY;
|
|
86
|
-
touchRecord.currentTimeStamp = timestampForTouch(touch);
|
|
87
|
-
touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
|
|
88
|
-
} else {
|
|
89
|
-
console.warn(
|
|
90
|
-
"Cannot record touch end without a touch start.\n",
|
|
91
|
-
`Touch End: ${printTouch(touch)}
|
|
92
|
-
`,
|
|
93
|
-
`Touch Bank: ${printTouchBank(touchHistory)}`
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function printTouch(touch) {
|
|
98
|
-
return JSON.stringify({
|
|
99
|
-
identifier: touch.identifier,
|
|
100
|
-
pageX: touch.pageX,
|
|
101
|
-
pageY: touch.pageY,
|
|
102
|
-
timestamp: timestampForTouch(touch)
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
function printTouchBank(touchHistory) {
|
|
106
|
-
const { touchBank } = touchHistory;
|
|
107
|
-
let printed = JSON.stringify(touchBank.slice(0, MAX_TOUCH_BANK));
|
|
108
|
-
if (touchBank.length > MAX_TOUCH_BANK) {
|
|
109
|
-
printed += ` (original size: ${touchBank.length})`;
|
|
110
|
-
}
|
|
111
|
-
return printed;
|
|
112
|
-
}
|
|
113
|
-
class ResponderTouchHistoryStore {
|
|
114
|
-
constructor() {
|
|
115
|
-
this._touchHistory = {
|
|
116
|
-
touchBank: [],
|
|
117
|
-
//Array<TouchRecord>
|
|
118
|
-
numberActiveTouches: 0,
|
|
119
|
-
// If there is only one active touch, we remember its location. This prevents
|
|
120
|
-
// us having to loop through all of the touches all the time in the most
|
|
121
|
-
// common case.
|
|
122
|
-
indexOfSingleActiveTouch: -1,
|
|
123
|
-
mostRecentTimeStamp: 0
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
recordTouchTrack(topLevelType, nativeEvent) {
|
|
127
|
-
const touchHistory = this._touchHistory;
|
|
128
|
-
if (isMoveish(topLevelType)) {
|
|
129
|
-
nativeEvent.changedTouches.forEach(
|
|
130
|
-
(touch) => recordTouchMove(touch, touchHistory)
|
|
131
|
-
);
|
|
132
|
-
} else if (isStartish(topLevelType)) {
|
|
133
|
-
nativeEvent.changedTouches.forEach(
|
|
134
|
-
(touch) => recordTouchStart(touch, touchHistory)
|
|
135
|
-
);
|
|
136
|
-
touchHistory.numberActiveTouches = nativeEvent.touches.length;
|
|
137
|
-
if (touchHistory.numberActiveTouches === 1) {
|
|
138
|
-
touchHistory.indexOfSingleActiveTouch = nativeEvent.touches[0].identifier;
|
|
139
|
-
}
|
|
140
|
-
} else if (isEndish(topLevelType)) {
|
|
141
|
-
nativeEvent.changedTouches.forEach(
|
|
142
|
-
(touch) => recordTouchEnd(touch, touchHistory)
|
|
143
|
-
);
|
|
144
|
-
touchHistory.numberActiveTouches = nativeEvent.touches.length;
|
|
145
|
-
if (touchHistory.numberActiveTouches === 1) {
|
|
146
|
-
const { touchBank } = touchHistory;
|
|
147
|
-
for (let i = 0; i < touchBank.length; i++) {
|
|
148
|
-
const touchTrackToCheck = touchBank[i];
|
|
149
|
-
if (touchTrackToCheck == null ? void 0 : touchTrackToCheck.touchActive) {
|
|
150
|
-
touchHistory.indexOfSingleActiveTouch = i;
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (process.env.NODE_ENV === "development") {
|
|
155
|
-
const activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch];
|
|
156
|
-
if (!(activeRecord == null ? void 0 : activeRecord.touchActive)) {
|
|
157
|
-
console.error("Cannot find single active touch.");
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
get touchHistory() {
|
|
164
|
-
return this._touchHistory;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
export {
|
|
168
|
-
ResponderTouchHistoryStore
|
|
169
|
-
};
|
|
1
|
+
import{isEndish as p,isMoveish as T,isStartish as h}from"./types";const c=20;function i(e){return e.timeStamp||e.timestamp}function f(e){return{touchActive:!0,startPageX:e.pageX,startPageY:e.pageY,startTimeStamp:i(e),currentPageX:e.pageX,currentPageY:e.pageY,currentTimeStamp:i(e),previousPageX:e.pageX,previousPageY:e.pageY,previousTimeStamp:i(e)}}function v(e,t){e.touchActive=!0,e.startPageX=t.pageX,e.startPageY=t.pageY,e.startTimeStamp=i(t),e.currentPageX=t.pageX,e.currentPageY=t.pageY,e.currentTimeStamp=i(t),e.previousPageX=t.pageX,e.previousPageY=t.pageY,e.previousTimeStamp=i(t)}function s({identifier:e}){return e==null&&console.error("Touch object is missing identifier."),process.env.NODE_ENV==="development"&&e>c&&console.error("Touch identifier %s is greater than maximum supported %s which causes performance issues backfilling array locations for all of the indices.",e,c),e}function l(e,t){const r=s(e),n=t.touchBank[r];n?v(n,e):t.touchBank[r]=f(e),t.mostRecentTimeStamp=i(e)}function d(e,t){const r=t.touchBank[s(e)];r?(r.touchActive=!0,r.previousPageX=r.currentPageX,r.previousPageY=r.currentPageY,r.previousTimeStamp=r.currentTimeStamp,r.currentPageX=e.pageX,r.currentPageY=e.pageY,r.currentTimeStamp=i(e),t.mostRecentTimeStamp=i(e)):console.warn(`Cannot record touch move without a touch start.
|
|
2
|
+
`,`Touch Move: ${m(e)}
|
|
3
|
+
`,`Touch Bank: ${g(t)}`)}function S(e,t){const r=t.touchBank[s(e)];r?(r.touchActive=!1,r.previousPageX=r.currentPageX,r.previousPageY=r.currentPageY,r.previousTimeStamp=r.currentTimeStamp,r.currentPageX=e.pageX,r.currentPageY=e.pageY,r.currentTimeStamp=i(e),t.mostRecentTimeStamp=i(e)):console.warn(`Cannot record touch end without a touch start.
|
|
4
|
+
`,`Touch End: ${m(e)}
|
|
5
|
+
`,`Touch Bank: ${g(t)}`)}function m(e){return JSON.stringify({identifier:e.identifier,pageX:e.pageX,pageY:e.pageY,timestamp:i(e)})}function g(e){const{touchBank:t}=e;let r=JSON.stringify(t.slice(0,c));return t.length>c&&(r+=` (original size: ${t.length})`),r}class X{constructor(){this._touchHistory={touchBank:[],numberActiveTouches:0,indexOfSingleActiveTouch:-1,mostRecentTimeStamp:0}}recordTouchTrack(t,r){const n=this._touchHistory;if(T(t))r.changedTouches.forEach(o=>d(o,n));else if(h(t))r.changedTouches.forEach(o=>l(o,n)),n.numberActiveTouches=r.touches.length,n.numberActiveTouches===1&&(n.indexOfSingleActiveTouch=r.touches[0].identifier);else if(p(t)&&(r.changedTouches.forEach(o=>S(o,n)),n.numberActiveTouches=r.touches.length,n.numberActiveTouches===1)){const{touchBank:o}=n;for(let a=0;a<o.length;a++){const u=o[a];if(u!=null&&u.touchActive){n.indexOfSingleActiveTouch=a;break}}if(process.env.NODE_ENV==="development"){const a=o[n.indexOfSingleActiveTouch];a!=null&&a.touchActive||console.error("Cannot find single active touch.")}}}get touchHistory(){return this._touchHistory}}export{X as ResponderTouchHistoryStore};
|
|
170
6
|
//# sourceMappingURL=ResponderTouchHistoryStore.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/ResponderTouchHistoryStore.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport type { Touch, TouchEvent } from './types'\nimport { isEndish, isMoveish, isStartish } from './types'\n\ntype TouchRecord = {\n currentPageX: number\n currentPageY: number\n currentTimeStamp: number\n previousPageX: number\n previousPageY: number\n previousTimeStamp: number\n startPageX: number\n startPageY: number\n startTimeStamp: number\n touchActive: boolean\n}\n\nexport type TouchHistory = {\n indexOfSingleActiveTouch: number\n mostRecentTimeStamp: number\n numberActiveTouches: number\n touchBank: Array<TouchRecord>\n}\n\n/**\n * Tracks the position and time of each active touch by `touch.identifier`. We\n * should typically only see IDs in the range of 1-20 because IDs get recycled\n * when touches end and start again.\n */\n\nconst MAX_TOUCH_BANK = 20\n\nfunction timestampForTouch(touch: Touch): number {\n // The legacy internal implementation provides \"timeStamp\", which has been\n // renamed to \"timestamp\".\n return touch['timeStamp'] || touch.timestamp\n}\n\n/**\n * TODO: Instead of making gestures recompute filtered velocity, we could\n * include a built in velocity computation that can be reused globally.\n */\nfunction createTouchRecord(touch: Touch): TouchRecord {\n return {\n touchActive: true,\n startPageX: touch.pageX,\n startPageY: touch.pageY,\n startTimeStamp: timestampForTouch(touch),\n currentPageX: touch.pageX,\n currentPageY: touch.pageY,\n currentTimeStamp: timestampForTouch(touch),\n previousPageX: touch.pageX,\n previousPageY: touch.pageY,\n previousTimeStamp: timestampForTouch(touch),\n }\n}\n\nfunction resetTouchRecord(touchRecord: TouchRecord, touch: Touch): void {\n touchRecord.touchActive = true\n touchRecord.startPageX = touch.pageX\n touchRecord.startPageY = touch.pageY\n touchRecord.startTimeStamp = timestampForTouch(touch)\n touchRecord.currentPageX = touch.pageX\n touchRecord.currentPageY = touch.pageY\n touchRecord.currentTimeStamp = timestampForTouch(touch)\n touchRecord.previousPageX = touch.pageX\n touchRecord.previousPageY = touch.pageY\n touchRecord.previousTimeStamp = timestampForTouch(touch)\n}\n\nfunction getTouchIdentifier({ identifier }: Touch): number {\n if (identifier == null) {\n // eslint-disable-next-line no-console\n console.error('Touch object is missing identifier.')\n }\n if (process.env.NODE_ENV === 'development') {\n if (identifier > MAX_TOUCH_BANK) {\n // eslint-disable-next-line no-console\n console.error(\n 'Touch identifier %s is greater than maximum supported %s which causes ' +\n 'performance issues backfilling array locations for all of the indices.',\n identifier,\n MAX_TOUCH_BANK,\n )\n }\n }\n return identifier\n}\n\nfunction recordTouchStart(touch: Touch, touchHistory): void {\n const identifier = getTouchIdentifier(touch)\n const touchRecord = touchHistory.touchBank[identifier]\n if (touchRecord) {\n resetTouchRecord(touchRecord, touch)\n } else {\n touchHistory.touchBank[identifier] = createTouchRecord(touch)\n }\n touchHistory.mostRecentTimeStamp = timestampForTouch(touch)\n}\n\nfunction recordTouchMove(touch: Touch, touchHistory): void {\n const touchRecord = touchHistory.touchBank[getTouchIdentifier(touch)]\n if (touchRecord) {\n touchRecord.touchActive = true\n touchRecord.previousPageX = touchRecord.currentPageX\n touchRecord.previousPageY = touchRecord.currentPageY\n touchRecord.previousTimeStamp = touchRecord.currentTimeStamp\n touchRecord.currentPageX = touch.pageX\n touchRecord.currentPageY = touch.pageY\n touchRecord.currentTimeStamp = timestampForTouch(touch)\n touchHistory.mostRecentTimeStamp = timestampForTouch(touch)\n } else {\n // eslint-disable-next-line no-console\n console.warn(\n 'Cannot record touch move without a touch start.\\n',\n `Touch Move: ${printTouch(touch)}\\n`,\n `Touch Bank: ${printTouchBank(touchHistory)}`,\n )\n }\n}\n\nfunction recordTouchEnd(touch: Touch, touchHistory): void {\n const touchRecord = touchHistory.touchBank[getTouchIdentifier(touch)]\n if (touchRecord) {\n touchRecord.touchActive = false\n touchRecord.previousPageX = touchRecord.currentPageX\n touchRecord.previousPageY = touchRecord.currentPageY\n touchRecord.previousTimeStamp = touchRecord.currentTimeStamp\n touchRecord.currentPageX = touch.pageX\n touchRecord.currentPageY = touch.pageY\n touchRecord.currentTimeStamp = timestampForTouch(touch)\n touchHistory.mostRecentTimeStamp = timestampForTouch(touch)\n } else {\n // eslint-disable-next-line no-console\n console.warn(\n 'Cannot record touch end without a touch start.\\n',\n `Touch End: ${printTouch(touch)}\\n`,\n `Touch Bank: ${printTouchBank(touchHistory)}`,\n )\n }\n}\n\nfunction printTouch(touch: Touch): string {\n return JSON.stringify({\n identifier: touch.identifier,\n pageX: touch.pageX,\n pageY: touch.pageY,\n timestamp: timestampForTouch(touch),\n })\n}\n\nfunction printTouchBank(touchHistory): string {\n const { touchBank } = touchHistory\n let printed = JSON.stringify(touchBank.slice(0, MAX_TOUCH_BANK))\n if (touchBank.length > MAX_TOUCH_BANK) {\n printed += ` (original size: ${touchBank.length})`\n }\n return printed\n}\n\nexport class ResponderTouchHistoryStore {\n _touchHistory = {\n touchBank: [], //Array<TouchRecord>\n numberActiveTouches: 0,\n // If there is only one active touch, we remember its location. This prevents\n // us having to loop through all of the touches all the time in the most\n // common case.\n indexOfSingleActiveTouch: -1,\n mostRecentTimeStamp: 0,\n }\n\n recordTouchTrack(topLevelType: string, nativeEvent: TouchEvent): void {\n const touchHistory = this._touchHistory\n if (isMoveish(topLevelType)) {\n nativeEvent.changedTouches.forEach((touch) =>\n recordTouchMove(touch, touchHistory),\n )\n } else if (isStartish(topLevelType)) {\n nativeEvent.changedTouches.forEach((touch) =>\n recordTouchStart(touch, touchHistory),\n )\n touchHistory.numberActiveTouches = nativeEvent.touches.length\n if (touchHistory.numberActiveTouches === 1) {\n touchHistory.indexOfSingleActiveTouch = nativeEvent.touches[0].identifier\n }\n } else if (isEndish(topLevelType)) {\n nativeEvent.changedTouches.forEach((touch) =>\n recordTouchEnd(touch, touchHistory),\n )\n touchHistory.numberActiveTouches = nativeEvent.touches.length\n if (touchHistory.numberActiveTouches === 1) {\n const { touchBank } = touchHistory\n for (let i = 0; i < touchBank.length; i++) {\n const touchTrackToCheck = touchBank[i]\n // @ts-ignore\n if (touchTrackToCheck?.touchActive) {\n touchHistory.indexOfSingleActiveTouch = i\n break\n }\n }\n if (process.env.NODE_ENV === 'development') {\n const activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch]\n // @ts-ignore\n if (!activeRecord?.touchActive) {\n // eslint-disable-next-line no-console\n console.error('Cannot find single active touch.')\n }\n }\n }\n }\n }\n\n get touchHistory(): TouchHistory {\n return this._touchHistory\n }\n}\n"],
|
|
5
|
-
"mappings": "AAQA,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AAQA,OAAS,YAAAA,EAAU,aA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vB,EAEA,iBAAiBC,EAAsBC,EAA+B,CACpE,MAAMT,EAAe,KAAK,cAC1B,GAAIX,EAAUmB,CAAY,EACxBC,EAAY,eAAe,QAAShB,GAClCQ,EAAgBR,EAAOO,CAAY,CACrC,UACSV,EAAWkB,CAAY,EAChCC,EAAY,eAAe,QAAShB,GAClCM,EAAiBN,EAAOO,CAAY,CACtC,EACAA,EAAa,oBAAsBS,EAAY,QAAQ,OACnDT,EAAa,sBAAwB,IACvCA,EAAa,yBAA2BS,EAAY,QAAQ,CAAC,EAAE,oBAExDrB,EAASoB,CAAY,IAC9BC,EAAY,eAAe,QAAShB,GAClCW,EAAeX,EAAOO,CAAY,CACpC,EACAA,EAAa,oBAAsBS,EAAY,QAAQ,OACnDT,EAAa,sBAAwB,GAAG,CAC1C,KAAM,CAAE,UAAAK,CAAU,EAAIL,EACtB,QAASU,EAAI,EAAGA,EAAIL,EAAU,OAAQK,IAAK,CACzC,MAAMC,EAAoBN,EAAUK,CAAC,EAErC,GAAIC,GAAA,MAAAA,EAAmB,YAAa,CAClCX,EAAa,yBAA2BU,EACxC,KACF,CACF,CACA,GAAI,QAAQ,IAAI,WAAa,cAAe,CAC1C,MAAME,EAAeP,EAAUL,EAAa,wBAAwB,EAE/DY,GAAA,MAAAA,EAAc,aAEjB,QAAQ,MAAM,kCAAkC,CAEpD,CACF,CAEJ,CAEA,IAAI,cAA6B,CAC/B,OAAO,KAAK,aACd,CACF",
|
|
6
|
+
"names": ["isEndish", "isMoveish", "isStartish", "MAX_TOUCH_BANK", "timestampForTouch", "touch", "createTouchRecord", "resetTouchRecord", "touchRecord", "getTouchIdentifier", "identifier", "recordTouchStart", "touchHistory", "recordTouchMove", "printTouch", "printTouchBank", "recordTouchEnd", "touchBank", "printed", "ResponderTouchHistoryStore", "topLevelType", "nativeEvent", "i", "touchTrackToCheck", "activeRecord"]
|
|
7
7
|
}
|
|
@@ -1,170 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
function createTouchRecord(touch) {
|
|
7
|
-
return {
|
|
8
|
-
touchActive: true,
|
|
9
|
-
startPageX: touch.pageX,
|
|
10
|
-
startPageY: touch.pageY,
|
|
11
|
-
startTimeStamp: timestampForTouch(touch),
|
|
12
|
-
currentPageX: touch.pageX,
|
|
13
|
-
currentPageY: touch.pageY,
|
|
14
|
-
currentTimeStamp: timestampForTouch(touch),
|
|
15
|
-
previousPageX: touch.pageX,
|
|
16
|
-
previousPageY: touch.pageY,
|
|
17
|
-
previousTimeStamp: timestampForTouch(touch)
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function resetTouchRecord(touchRecord, touch) {
|
|
21
|
-
touchRecord.touchActive = true;
|
|
22
|
-
touchRecord.startPageX = touch.pageX;
|
|
23
|
-
touchRecord.startPageY = touch.pageY;
|
|
24
|
-
touchRecord.startTimeStamp = timestampForTouch(touch);
|
|
25
|
-
touchRecord.currentPageX = touch.pageX;
|
|
26
|
-
touchRecord.currentPageY = touch.pageY;
|
|
27
|
-
touchRecord.currentTimeStamp = timestampForTouch(touch);
|
|
28
|
-
touchRecord.previousPageX = touch.pageX;
|
|
29
|
-
touchRecord.previousPageY = touch.pageY;
|
|
30
|
-
touchRecord.previousTimeStamp = timestampForTouch(touch);
|
|
31
|
-
}
|
|
32
|
-
function getTouchIdentifier({ identifier }) {
|
|
33
|
-
if (identifier == null) {
|
|
34
|
-
console.error("Touch object is missing identifier.");
|
|
35
|
-
}
|
|
36
|
-
if (process.env.NODE_ENV === "development") {
|
|
37
|
-
if (identifier > MAX_TOUCH_BANK) {
|
|
38
|
-
console.error(
|
|
39
|
-
"Touch identifier %s is greater than maximum supported %s which causes performance issues backfilling array locations for all of the indices.",
|
|
40
|
-
identifier,
|
|
41
|
-
MAX_TOUCH_BANK
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return identifier;
|
|
46
|
-
}
|
|
47
|
-
function recordTouchStart(touch, touchHistory) {
|
|
48
|
-
const identifier = getTouchIdentifier(touch);
|
|
49
|
-
const touchRecord = touchHistory.touchBank[identifier];
|
|
50
|
-
if (touchRecord) {
|
|
51
|
-
resetTouchRecord(touchRecord, touch);
|
|
52
|
-
} else {
|
|
53
|
-
touchHistory.touchBank[identifier] = createTouchRecord(touch);
|
|
54
|
-
}
|
|
55
|
-
touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
|
|
56
|
-
}
|
|
57
|
-
function recordTouchMove(touch, touchHistory) {
|
|
58
|
-
const touchRecord = touchHistory.touchBank[getTouchIdentifier(touch)];
|
|
59
|
-
if (touchRecord) {
|
|
60
|
-
touchRecord.touchActive = true;
|
|
61
|
-
touchRecord.previousPageX = touchRecord.currentPageX;
|
|
62
|
-
touchRecord.previousPageY = touchRecord.currentPageY;
|
|
63
|
-
touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
|
|
64
|
-
touchRecord.currentPageX = touch.pageX;
|
|
65
|
-
touchRecord.currentPageY = touch.pageY;
|
|
66
|
-
touchRecord.currentTimeStamp = timestampForTouch(touch);
|
|
67
|
-
touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
|
|
68
|
-
} else {
|
|
69
|
-
console.warn(
|
|
70
|
-
"Cannot record touch move without a touch start.\n",
|
|
71
|
-
`Touch Move: ${printTouch(touch)}
|
|
72
|
-
`,
|
|
73
|
-
`Touch Bank: ${printTouchBank(touchHistory)}`
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function recordTouchEnd(touch, touchHistory) {
|
|
78
|
-
const touchRecord = touchHistory.touchBank[getTouchIdentifier(touch)];
|
|
79
|
-
if (touchRecord) {
|
|
80
|
-
touchRecord.touchActive = false;
|
|
81
|
-
touchRecord.previousPageX = touchRecord.currentPageX;
|
|
82
|
-
touchRecord.previousPageY = touchRecord.currentPageY;
|
|
83
|
-
touchRecord.previousTimeStamp = touchRecord.currentTimeStamp;
|
|
84
|
-
touchRecord.currentPageX = touch.pageX;
|
|
85
|
-
touchRecord.currentPageY = touch.pageY;
|
|
86
|
-
touchRecord.currentTimeStamp = timestampForTouch(touch);
|
|
87
|
-
touchHistory.mostRecentTimeStamp = timestampForTouch(touch);
|
|
88
|
-
} else {
|
|
89
|
-
console.warn(
|
|
90
|
-
"Cannot record touch end without a touch start.\n",
|
|
91
|
-
`Touch End: ${printTouch(touch)}
|
|
92
|
-
`,
|
|
93
|
-
`Touch Bank: ${printTouchBank(touchHistory)}`
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function printTouch(touch) {
|
|
98
|
-
return JSON.stringify({
|
|
99
|
-
identifier: touch.identifier,
|
|
100
|
-
pageX: touch.pageX,
|
|
101
|
-
pageY: touch.pageY,
|
|
102
|
-
timestamp: timestampForTouch(touch)
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
function printTouchBank(touchHistory) {
|
|
106
|
-
const { touchBank } = touchHistory;
|
|
107
|
-
let printed = JSON.stringify(touchBank.slice(0, MAX_TOUCH_BANK));
|
|
108
|
-
if (touchBank.length > MAX_TOUCH_BANK) {
|
|
109
|
-
printed += ` (original size: ${touchBank.length})`;
|
|
110
|
-
}
|
|
111
|
-
return printed;
|
|
112
|
-
}
|
|
113
|
-
class ResponderTouchHistoryStore {
|
|
114
|
-
constructor() {
|
|
115
|
-
this._touchHistory = {
|
|
116
|
-
touchBank: [],
|
|
117
|
-
//Array<TouchRecord>
|
|
118
|
-
numberActiveTouches: 0,
|
|
119
|
-
// If there is only one active touch, we remember its location. This prevents
|
|
120
|
-
// us having to loop through all of the touches all the time in the most
|
|
121
|
-
// common case.
|
|
122
|
-
indexOfSingleActiveTouch: -1,
|
|
123
|
-
mostRecentTimeStamp: 0
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
recordTouchTrack(topLevelType, nativeEvent) {
|
|
127
|
-
const touchHistory = this._touchHistory;
|
|
128
|
-
if (isMoveish(topLevelType)) {
|
|
129
|
-
nativeEvent.changedTouches.forEach(
|
|
130
|
-
(touch) => recordTouchMove(touch, touchHistory)
|
|
131
|
-
);
|
|
132
|
-
} else if (isStartish(topLevelType)) {
|
|
133
|
-
nativeEvent.changedTouches.forEach(
|
|
134
|
-
(touch) => recordTouchStart(touch, touchHistory)
|
|
135
|
-
);
|
|
136
|
-
touchHistory.numberActiveTouches = nativeEvent.touches.length;
|
|
137
|
-
if (touchHistory.numberActiveTouches === 1) {
|
|
138
|
-
touchHistory.indexOfSingleActiveTouch = nativeEvent.touches[0].identifier;
|
|
139
|
-
}
|
|
140
|
-
} else if (isEndish(topLevelType)) {
|
|
141
|
-
nativeEvent.changedTouches.forEach(
|
|
142
|
-
(touch) => recordTouchEnd(touch, touchHistory)
|
|
143
|
-
);
|
|
144
|
-
touchHistory.numberActiveTouches = nativeEvent.touches.length;
|
|
145
|
-
if (touchHistory.numberActiveTouches === 1) {
|
|
146
|
-
const { touchBank } = touchHistory;
|
|
147
|
-
for (let i = 0; i < touchBank.length; i++) {
|
|
148
|
-
const touchTrackToCheck = touchBank[i];
|
|
149
|
-
if (touchTrackToCheck == null ? void 0 : touchTrackToCheck.touchActive) {
|
|
150
|
-
touchHistory.indexOfSingleActiveTouch = i;
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (process.env.NODE_ENV === "development") {
|
|
155
|
-
const activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch];
|
|
156
|
-
if (!(activeRecord == null ? void 0 : activeRecord.touchActive)) {
|
|
157
|
-
console.error("Cannot find single active touch.");
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
get touchHistory() {
|
|
164
|
-
return this._touchHistory;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
export {
|
|
168
|
-
ResponderTouchHistoryStore
|
|
169
|
-
};
|
|
1
|
+
import{isEndish as p,isMoveish as T,isStartish as h}from"./types";const c=20;function i(e){return e.timeStamp||e.timestamp}function f(e){return{touchActive:!0,startPageX:e.pageX,startPageY:e.pageY,startTimeStamp:i(e),currentPageX:e.pageX,currentPageY:e.pageY,currentTimeStamp:i(e),previousPageX:e.pageX,previousPageY:e.pageY,previousTimeStamp:i(e)}}function v(e,t){e.touchActive=!0,e.startPageX=t.pageX,e.startPageY=t.pageY,e.startTimeStamp=i(t),e.currentPageX=t.pageX,e.currentPageY=t.pageY,e.currentTimeStamp=i(t),e.previousPageX=t.pageX,e.previousPageY=t.pageY,e.previousTimeStamp=i(t)}function s({identifier:e}){return e==null&&console.error("Touch object is missing identifier."),process.env.NODE_ENV==="development"&&e>c&&console.error("Touch identifier %s is greater than maximum supported %s which causes performance issues backfilling array locations for all of the indices.",e,c),e}function l(e,t){const r=s(e),n=t.touchBank[r];n?v(n,e):t.touchBank[r]=f(e),t.mostRecentTimeStamp=i(e)}function d(e,t){const r=t.touchBank[s(e)];r?(r.touchActive=!0,r.previousPageX=r.currentPageX,r.previousPageY=r.currentPageY,r.previousTimeStamp=r.currentTimeStamp,r.currentPageX=e.pageX,r.currentPageY=e.pageY,r.currentTimeStamp=i(e),t.mostRecentTimeStamp=i(e)):console.warn(`Cannot record touch move without a touch start.
|
|
2
|
+
`,`Touch Move: ${m(e)}
|
|
3
|
+
`,`Touch Bank: ${g(t)}`)}function S(e,t){const r=t.touchBank[s(e)];r?(r.touchActive=!1,r.previousPageX=r.currentPageX,r.previousPageY=r.currentPageY,r.previousTimeStamp=r.currentTimeStamp,r.currentPageX=e.pageX,r.currentPageY=e.pageY,r.currentTimeStamp=i(e),t.mostRecentTimeStamp=i(e)):console.warn(`Cannot record touch end without a touch start.
|
|
4
|
+
`,`Touch End: ${m(e)}
|
|
5
|
+
`,`Touch Bank: ${g(t)}`)}function m(e){return JSON.stringify({identifier:e.identifier,pageX:e.pageX,pageY:e.pageY,timestamp:i(e)})}function g(e){const{touchBank:t}=e;let r=JSON.stringify(t.slice(0,c));return t.length>c&&(r+=` (original size: ${t.length})`),r}class X{constructor(){this._touchHistory={touchBank:[],numberActiveTouches:0,indexOfSingleActiveTouch:-1,mostRecentTimeStamp:0}}recordTouchTrack(t,r){const n=this._touchHistory;if(T(t))r.changedTouches.forEach(o=>d(o,n));else if(h(t))r.changedTouches.forEach(o=>l(o,n)),n.numberActiveTouches=r.touches.length,n.numberActiveTouches===1&&(n.indexOfSingleActiveTouch=r.touches[0].identifier);else if(p(t)&&(r.changedTouches.forEach(o=>S(o,n)),n.numberActiveTouches=r.touches.length,n.numberActiveTouches===1)){const{touchBank:o}=n;for(let a=0;a<o.length;a++){const u=o[a];if(u!=null&&u.touchActive){n.indexOfSingleActiveTouch=a;break}}if(process.env.NODE_ENV==="development"){const a=o[n.indexOfSingleActiveTouch];a!=null&&a.touchActive||console.error("Cannot find single active touch.")}}}get touchHistory(){return this._touchHistory}}export{X as ResponderTouchHistoryStore};
|
|
170
6
|
//# sourceMappingURL=ResponderTouchHistoryStore.mjs.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/ResponderTouchHistoryStore.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport type { Touch, TouchEvent } from './types'\nimport { isEndish, isMoveish, isStartish } from './types'\n\ntype TouchRecord = {\n currentPageX: number\n currentPageY: number\n currentTimeStamp: number\n previousPageX: number\n previousPageY: number\n previousTimeStamp: number\n startPageX: number\n startPageY: number\n startTimeStamp: number\n touchActive: boolean\n}\n\nexport type TouchHistory = {\n indexOfSingleActiveTouch: number\n mostRecentTimeStamp: number\n numberActiveTouches: number\n touchBank: Array<TouchRecord>\n}\n\n/**\n * Tracks the position and time of each active touch by `touch.identifier`. We\n * should typically only see IDs in the range of 1-20 because IDs get recycled\n * when touches end and start again.\n */\n\nconst MAX_TOUCH_BANK = 20\n\nfunction timestampForTouch(touch: Touch): number {\n // The legacy internal implementation provides \"timeStamp\", which has been\n // renamed to \"timestamp\".\n return touch['timeStamp'] || touch.timestamp\n}\n\n/**\n * TODO: Instead of making gestures recompute filtered velocity, we could\n * include a built in velocity computation that can be reused globally.\n */\nfunction createTouchRecord(touch: Touch): TouchRecord {\n return {\n touchActive: true,\n startPageX: touch.pageX,\n startPageY: touch.pageY,\n startTimeStamp: timestampForTouch(touch),\n currentPageX: touch.pageX,\n currentPageY: touch.pageY,\n currentTimeStamp: timestampForTouch(touch),\n previousPageX: touch.pageX,\n previousPageY: touch.pageY,\n previousTimeStamp: timestampForTouch(touch),\n }\n}\n\nfunction resetTouchRecord(touchRecord: TouchRecord, touch: Touch): void {\n touchRecord.touchActive = true\n touchRecord.startPageX = touch.pageX\n touchRecord.startPageY = touch.pageY\n touchRecord.startTimeStamp = timestampForTouch(touch)\n touchRecord.currentPageX = touch.pageX\n touchRecord.currentPageY = touch.pageY\n touchRecord.currentTimeStamp = timestampForTouch(touch)\n touchRecord.previousPageX = touch.pageX\n touchRecord.previousPageY = touch.pageY\n touchRecord.previousTimeStamp = timestampForTouch(touch)\n}\n\nfunction getTouchIdentifier({ identifier }: Touch): number {\n if (identifier == null) {\n // eslint-disable-next-line no-console\n console.error('Touch object is missing identifier.')\n }\n if (process.env.NODE_ENV === 'development') {\n if (identifier > MAX_TOUCH_BANK) {\n // eslint-disable-next-line no-console\n console.error(\n 'Touch identifier %s is greater than maximum supported %s which causes ' +\n 'performance issues backfilling array locations for all of the indices.',\n identifier,\n MAX_TOUCH_BANK,\n )\n }\n }\n return identifier\n}\n\nfunction recordTouchStart(touch: Touch, touchHistory): void {\n const identifier = getTouchIdentifier(touch)\n const touchRecord = touchHistory.touchBank[identifier]\n if (touchRecord) {\n resetTouchRecord(touchRecord, touch)\n } else {\n touchHistory.touchBank[identifier] = createTouchRecord(touch)\n }\n touchHistory.mostRecentTimeStamp = timestampForTouch(touch)\n}\n\nfunction recordTouchMove(touch: Touch, touchHistory): void {\n const touchRecord = touchHistory.touchBank[getTouchIdentifier(touch)]\n if (touchRecord) {\n touchRecord.touchActive = true\n touchRecord.previousPageX = touchRecord.currentPageX\n touchRecord.previousPageY = touchRecord.currentPageY\n touchRecord.previousTimeStamp = touchRecord.currentTimeStamp\n touchRecord.currentPageX = touch.pageX\n touchRecord.currentPageY = touch.pageY\n touchRecord.currentTimeStamp = timestampForTouch(touch)\n touchHistory.mostRecentTimeStamp = timestampForTouch(touch)\n } else {\n // eslint-disable-next-line no-console\n console.warn(\n 'Cannot record touch move without a touch start.\\n',\n `Touch Move: ${printTouch(touch)}\\n`,\n `Touch Bank: ${printTouchBank(touchHistory)}`,\n )\n }\n}\n\nfunction recordTouchEnd(touch: Touch, touchHistory): void {\n const touchRecord = touchHistory.touchBank[getTouchIdentifier(touch)]\n if (touchRecord) {\n touchRecord.touchActive = false\n touchRecord.previousPageX = touchRecord.currentPageX\n touchRecord.previousPageY = touchRecord.currentPageY\n touchRecord.previousTimeStamp = touchRecord.currentTimeStamp\n touchRecord.currentPageX = touch.pageX\n touchRecord.currentPageY = touch.pageY\n touchRecord.currentTimeStamp = timestampForTouch(touch)\n touchHistory.mostRecentTimeStamp = timestampForTouch(touch)\n } else {\n // eslint-disable-next-line no-console\n console.warn(\n 'Cannot record touch end without a touch start.\\n',\n `Touch End: ${printTouch(touch)}\\n`,\n `Touch Bank: ${printTouchBank(touchHistory)}`,\n )\n }\n}\n\nfunction printTouch(touch: Touch): string {\n return JSON.stringify({\n identifier: touch.identifier,\n pageX: touch.pageX,\n pageY: touch.pageY,\n timestamp: timestampForTouch(touch),\n })\n}\n\nfunction printTouchBank(touchHistory): string {\n const { touchBank } = touchHistory\n let printed = JSON.stringify(touchBank.slice(0, MAX_TOUCH_BANK))\n if (touchBank.length > MAX_TOUCH_BANK) {\n printed += ` (original size: ${touchBank.length})`\n }\n return printed\n}\n\nexport class ResponderTouchHistoryStore {\n _touchHistory = {\n touchBank: [], //Array<TouchRecord>\n numberActiveTouches: 0,\n // If there is only one active touch, we remember its location. This prevents\n // us having to loop through all of the touches all the time in the most\n // common case.\n indexOfSingleActiveTouch: -1,\n mostRecentTimeStamp: 0,\n }\n\n recordTouchTrack(topLevelType: string, nativeEvent: TouchEvent): void {\n const touchHistory = this._touchHistory\n if (isMoveish(topLevelType)) {\n nativeEvent.changedTouches.forEach((touch) =>\n recordTouchMove(touch, touchHistory),\n )\n } else if (isStartish(topLevelType)) {\n nativeEvent.changedTouches.forEach((touch) =>\n recordTouchStart(touch, touchHistory),\n )\n touchHistory.numberActiveTouches = nativeEvent.touches.length\n if (touchHistory.numberActiveTouches === 1) {\n touchHistory.indexOfSingleActiveTouch = nativeEvent.touches[0].identifier\n }\n } else if (isEndish(topLevelType)) {\n nativeEvent.changedTouches.forEach((touch) =>\n recordTouchEnd(touch, touchHistory),\n )\n touchHistory.numberActiveTouches = nativeEvent.touches.length\n if (touchHistory.numberActiveTouches === 1) {\n const { touchBank } = touchHistory\n for (let i = 0; i < touchBank.length; i++) {\n const touchTrackToCheck = touchBank[i]\n // @ts-ignore\n if (touchTrackToCheck?.touchActive) {\n touchHistory.indexOfSingleActiveTouch = i\n break\n }\n }\n if (process.env.NODE_ENV === 'development') {\n const activeRecord = touchBank[touchHistory.indexOfSingleActiveTouch]\n // @ts-ignore\n if (!activeRecord?.touchActive) {\n // eslint-disable-next-line no-console\n console.error('Cannot find single active touch.')\n }\n }\n }\n }\n }\n\n get touchHistory(): TouchHistory {\n return this._touchHistory\n }\n}\n"],
|
|
5
|
-
"mappings": "AAQA,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AAQA,OAAS,YAAAA,EAAU,aAAAC,EAAW,cAAAC,MAAkB,UA4BhD,MAAMC,EAAiB,GAEvB,SAASC,EAAkBC,EAAsB,CAG/C,OAAOA,EAAM,WAAgBA,EAAM,SACrC,CAMA,SAASC,EAAkBD,EAA2B,CACpD,MAAO,CACL,YAAa,GACb,WAAYA,EAAM,MAClB,WAAYA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GAClCM,EAAiBN,EAAOO,CAAY,CACtC,EACAA,EAAa,oBAAsBS,EAAY,QAAQ,OACnDT,EAAa,sBAAwB,IACvCA,EAAa,yBAA2BS,EAAY,QAAQ,CAAC,EAAE,oBAExDrB,EAASoB,CAAY,IAC9BC,EAAY,eAAe,QAAShB,GAClCW,EAAeX,EAAOO,CAAY,CACpC,EACAA,EAAa,oBAAsBS,EAAY,QAAQ,OACnDT,EAAa,sBAAwB,GAAG,CAC1C,KAAM,CAAE,UAAAK,CAAU,EAAIL,EACtB,QAASU,EAAI,EAAGA,EAAIL,EAAU,OAAQK,IAAK,CACzC,MAAMC,EAAoBN,EAAUK,CAAC,EAErC,GAAIC,GAAA,MAAAA,EAAmB,YAAa,CAClCX,EAAa,yBAA2BU,EACxC,KACF,CACF,CACA,GAAI,QAAQ,IAAI,WAAa,cAAe,CAC1C,MAAME,EAAeP,EAAUL,EAAa,wBAAwB,EAE/DY,GAAA,MAAAA,EAAc,aAEjB,QAAQ,MAAM,kCAAkC,CAEpD,CACF,CAEJ,CAEA,IAAI,cAA6B,CAC/B,OAAO,KAAK,aACd,CACF",
|
|
6
|
+
"names": ["isEndish", "isMoveish", "isStartish", "MAX_TOUCH_BANK", "timestampForTouch", "touch", "createTouchRecord", "resetTouchRecord", "touchRecord", "getTouchIdentifier", "identifier", "recordTouchStart", "touchHistory", "recordTouchMove", "printTouch", "printTouchBank", "recordTouchEnd", "touchBank", "printed", "ResponderTouchHistoryStore", "topLevelType", "nativeEvent", "i", "touchTrackToCheck", "activeRecord"]
|
|
7
7
|
}
|
|
@@ -1,129 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
const emptyFunction = () => {
|
|
3
|
-
};
|
|
4
|
-
const emptyObject = {};
|
|
5
|
-
const emptyArray = [];
|
|
6
|
-
function normalizeIdentifier(identifier) {
|
|
7
|
-
return identifier > 20 ? identifier % 20 : identifier;
|
|
8
|
-
}
|
|
9
|
-
function createResponderEvent(domEvent, responderTouchHistoryStore) {
|
|
10
|
-
let rect;
|
|
11
|
-
let propagationWasStopped = false;
|
|
12
|
-
let changedTouches;
|
|
13
|
-
let touches;
|
|
14
|
-
const domEventChangedTouches = domEvent.changedTouches;
|
|
15
|
-
const domEventType = domEvent.type;
|
|
16
|
-
const metaKey = domEvent.metaKey === true;
|
|
17
|
-
const shiftKey = domEvent.shiftKey === true;
|
|
18
|
-
const force = (domEventChangedTouches == null ? void 0 : domEventChangedTouches[0].force) || 0;
|
|
19
|
-
const identifier = normalizeIdentifier((domEventChangedTouches == null ? void 0 : domEventChangedTouches[0].identifier) || 0);
|
|
20
|
-
const clientX = (domEventChangedTouches == null ? void 0 : domEventChangedTouches[0].clientX) || domEvent.clientX;
|
|
21
|
-
const clientY = (domEventChangedTouches == null ? void 0 : domEventChangedTouches[0].clientY) || domEvent.clientY;
|
|
22
|
-
const pageX = (domEventChangedTouches == null ? void 0 : domEventChangedTouches[0].pageX) || domEvent.pageX;
|
|
23
|
-
const pageY = (domEventChangedTouches == null ? void 0 : domEventChangedTouches[0].pageY) || domEvent.pageY;
|
|
24
|
-
const preventDefault = typeof domEvent.preventDefault === "function" ? domEvent.preventDefault.bind(domEvent) : emptyFunction;
|
|
25
|
-
const timestamp = domEvent.timeStamp;
|
|
26
|
-
function normalizeTouches(touches2) {
|
|
27
|
-
return Array.prototype.slice.call(touches2).map((touch) => {
|
|
28
|
-
return {
|
|
29
|
-
force: touch.force,
|
|
30
|
-
identifier: normalizeIdentifier(touch.identifier),
|
|
31
|
-
get locationX() {
|
|
32
|
-
return locationX(touch.clientX);
|
|
33
|
-
},
|
|
34
|
-
get locationY() {
|
|
35
|
-
return locationY(touch.clientY);
|
|
36
|
-
},
|
|
37
|
-
pageX: touch.pageX,
|
|
38
|
-
pageY: touch.pageY,
|
|
39
|
-
target: touch.target,
|
|
40
|
-
timestamp
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
if (domEventChangedTouches != null) {
|
|
45
|
-
changedTouches = normalizeTouches(domEventChangedTouches);
|
|
46
|
-
touches = normalizeTouches(domEvent.touches);
|
|
47
|
-
} else {
|
|
48
|
-
const emulatedTouches = [
|
|
49
|
-
{
|
|
50
|
-
force,
|
|
51
|
-
identifier,
|
|
52
|
-
get locationX() {
|
|
53
|
-
return locationX(clientX);
|
|
54
|
-
},
|
|
55
|
-
get locationY() {
|
|
56
|
-
return locationY(clientY);
|
|
57
|
-
},
|
|
58
|
-
pageX,
|
|
59
|
-
pageY,
|
|
60
|
-
target: domEvent.target,
|
|
61
|
-
timestamp
|
|
62
|
-
}
|
|
63
|
-
];
|
|
64
|
-
changedTouches = emulatedTouches;
|
|
65
|
-
touches = domEventType === "mouseup" || domEventType === "dragstart" ? emptyArray : emulatedTouches;
|
|
66
|
-
}
|
|
67
|
-
const responderEvent = {
|
|
68
|
-
bubbles: true,
|
|
69
|
-
cancelable: true,
|
|
70
|
-
// `currentTarget` is set before dispatch
|
|
71
|
-
currentTarget: null,
|
|
72
|
-
defaultPrevented: domEvent.defaultPrevented,
|
|
73
|
-
dispatchConfig: emptyObject,
|
|
74
|
-
eventPhase: domEvent.eventPhase,
|
|
75
|
-
isDefaultPrevented() {
|
|
76
|
-
return domEvent.defaultPrevented;
|
|
77
|
-
},
|
|
78
|
-
isPropagationStopped() {
|
|
79
|
-
return propagationWasStopped;
|
|
80
|
-
},
|
|
81
|
-
isTrusted: domEvent.isTrusted,
|
|
82
|
-
nativeEvent: {
|
|
83
|
-
altKey: false,
|
|
84
|
-
ctrlKey: false,
|
|
85
|
-
metaKey,
|
|
86
|
-
shiftKey,
|
|
87
|
-
changedTouches,
|
|
88
|
-
force,
|
|
89
|
-
identifier,
|
|
90
|
-
get locationX() {
|
|
91
|
-
return locationX(clientX);
|
|
92
|
-
},
|
|
93
|
-
get locationY() {
|
|
94
|
-
return locationY(clientY);
|
|
95
|
-
},
|
|
96
|
-
pageX,
|
|
97
|
-
pageY,
|
|
98
|
-
target: domEvent.target,
|
|
99
|
-
timestamp,
|
|
100
|
-
touches,
|
|
101
|
-
type: domEventType
|
|
102
|
-
},
|
|
103
|
-
persist: emptyFunction,
|
|
104
|
-
preventDefault,
|
|
105
|
-
stopPropagation() {
|
|
106
|
-
propagationWasStopped = true;
|
|
107
|
-
},
|
|
108
|
-
target: domEvent.target,
|
|
109
|
-
timeStamp: timestamp,
|
|
110
|
-
touchHistory: responderTouchHistoryStore.touchHistory
|
|
111
|
-
};
|
|
112
|
-
function locationX(x) {
|
|
113
|
-
rect = rect || getBoundingClientRect(responderEvent.currentTarget);
|
|
114
|
-
if (rect) {
|
|
115
|
-
return x - rect.left;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function locationY(y) {
|
|
119
|
-
rect = rect || getBoundingClientRect(responderEvent.currentTarget);
|
|
120
|
-
if (rect) {
|
|
121
|
-
return y - rect.top;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return responderEvent;
|
|
125
|
-
}
|
|
126
|
-
export {
|
|
127
|
-
createResponderEvent as default
|
|
128
|
-
};
|
|
1
|
+
import{getBoundingClientRect as H}from"./utils";const R=()=>{},A={},N=[];function D(t){return t>20?t%20:t}function j(t,K){let r,f=!1,o,l;const e=t.changedTouches,s=t.type,T=t.metaKey===!0,x=t.shiftKey===!0,g=(e==null?void 0:e[0].force)||0,y=D((e==null?void 0:e[0].identifier)||0),b=(e==null?void 0:e[0].clientX)||t.clientX,P=(e==null?void 0:e[0].clientY)||t.clientY,X=(e==null?void 0:e[0].pageX)||t.pageX,Y=(e==null?void 0:e[0].pageY)||t.pageY,z=typeof t.preventDefault=="function"?t.preventDefault.bind(t):R,i=t.timeStamp;function S(n){return Array.prototype.slice.call(n).map(a=>({force:a.force,identifier:D(a.identifier),get locationX(){return p(a.clientX)},get locationY(){return u(a.clientY)},pageX:a.pageX,pageY:a.pageY,target:a.target,timestamp:i}))}if(e!=null)o=S(e),l=S(t.touches);else{const n=[{force:g,identifier:y,get locationX(){return p(b)},get locationY(){return u(P)},pageX:X,pageY:Y,target:t.target,timestamp:i}];o=n,l=s==="mouseup"||s==="dragstart"?N:n}const c={bubbles:!0,cancelable:!0,currentTarget:null,defaultPrevented:t.defaultPrevented,dispatchConfig:A,eventPhase:t.eventPhase,isDefaultPrevented(){return t.defaultPrevented},isPropagationStopped(){return f},isTrusted:t.isTrusted,nativeEvent:{altKey:!1,ctrlKey:!1,metaKey:T,shiftKey:x,changedTouches:o,force:g,identifier:y,get locationX(){return p(b)},get locationY(){return u(P)},pageX:X,pageY:Y,target:t.target,timestamp:i,touches:l,type:s},persist:R,preventDefault:z,stopPropagation(){f=!0},target:t.target,timeStamp:i,touchHistory:K.touchHistory};function p(n){if(r=r||H(c.currentTarget),r)return n-r.left}function u(n){if(r=r||H(c.currentTarget),r)return n-r.top}return c}export{j as default};
|
|
129
2
|
//# sourceMappingURL=createResponderEvent.js.map
|