forgebook 0.1.4 → 0.1.6

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 (184) hide show
  1. package/README.md +32 -1
  2. package/dist/bin/forgebook/agentClient.d.ts.map +1 -1
  3. package/dist/bin/forgebook/agentClient.js +2 -2
  4. package/dist/bin/forgebook/agentClient.js.map +1 -1
  5. package/dist/bin/forgebook/agentLoopCommands.d.mts.map +1 -1
  6. package/dist/bin/forgebook/agentLoopCommands.mjs +24 -3
  7. package/dist/bin/forgebook/agentLoopCommands.mjs.map +1 -1
  8. package/dist/bin/forgebook/agents.md +7 -1
  9. package/dist/bin/forgebook/errorsRun.d.ts.map +1 -1
  10. package/dist/bin/forgebook/errorsRun.js +14 -1
  11. package/dist/bin/forgebook/errorsRun.js.map +1 -1
  12. package/dist/bin/forgebook/forgebook.mjs +12 -2
  13. package/dist/bin/forgebook/forgebook.mjs.map +1 -1
  14. package/dist/bin/forgebook/importers/storybook.d.ts.map +1 -1
  15. package/dist/bin/forgebook/importers/storybook.js +41 -7
  16. package/dist/bin/forgebook/importers/storybook.js.map +1 -1
  17. package/dist/bin/forgebook/initCommands.d.mts.map +1 -1
  18. package/dist/bin/forgebook/initCommands.mjs +5 -2
  19. package/dist/bin/forgebook/initCommands.mjs.map +1 -1
  20. package/dist/bin/forgebook/mcpTools.d.ts.map +1 -1
  21. package/dist/bin/forgebook/mcpTools.js +14 -2
  22. package/dist/bin/forgebook/mcpTools.js.map +1 -1
  23. package/dist/bin/forgebook/storyCheckRun.d.ts +10 -0
  24. package/dist/bin/forgebook/storyCheckRun.d.ts.map +1 -1
  25. package/dist/bin/forgebook/storyCheckRun.js +4 -3
  26. package/dist/bin/forgebook/storyCheckRun.js.map +1 -1
  27. package/dist/bin/forgebook/touchWindowRun.d.ts +17 -0
  28. package/dist/bin/forgebook/touchWindowRun.d.ts.map +1 -0
  29. package/dist/bin/forgebook/touchWindowRun.js +22 -0
  30. package/dist/bin/forgebook/touchWindowRun.js.map +1 -0
  31. package/dist/src/catalogue.d.ts +6 -4
  32. package/dist/src/catalogue.d.ts.map +1 -1
  33. package/dist/src/catalogue.js +2 -1
  34. package/dist/src/catalogue.js.map +1 -1
  35. package/dist/src/controlKeys.d.ts +4 -4
  36. package/dist/src/controlKeys.d.ts.map +1 -1
  37. package/dist/src/controlKeys.js +12 -8
  38. package/dist/src/controlKeys.js.map +1 -1
  39. package/dist/src/frame/frameView.d.ts.map +1 -1
  40. package/dist/src/frame/frameView.js +7 -2
  41. package/dist/src/frame/frameView.js.map +1 -1
  42. package/dist/src/frame/mountFrame.d.ts.map +1 -1
  43. package/dist/src/frame/mountFrame.js +5 -1
  44. package/dist/src/frame/mountFrame.js.map +1 -1
  45. package/dist/src/frame/spillOutline.d.ts.map +1 -1
  46. package/dist/src/frame/spillOutline.js +2 -0
  47. package/dist/src/frame/spillOutline.js.map +1 -1
  48. package/dist/src/frame/touchDots.d.ts +32 -0
  49. package/dist/src/frame/touchDots.d.ts.map +1 -0
  50. package/dist/src/frame/touchDots.js +52 -0
  51. package/dist/src/frame/touchDots.js.map +1 -0
  52. package/dist/src/frame/touchEvents.d.ts +66 -0
  53. package/dist/src/frame/touchEvents.d.ts.map +1 -0
  54. package/dist/src/frame/touchEvents.js +152 -0
  55. package/dist/src/frame/touchEvents.js.map +1 -0
  56. package/dist/src/frame/touchGesture.d.ts +80 -0
  57. package/dist/src/frame/touchGesture.d.ts.map +1 -0
  58. package/dist/src/frame/touchGesture.js +87 -0
  59. package/dist/src/frame/touchGesture.js.map +1 -0
  60. package/dist/src/frame/touchLayer.d.ts +7 -0
  61. package/dist/src/frame/touchLayer.d.ts.map +1 -0
  62. package/dist/src/frame/touchLayer.js +449 -0
  63. package/dist/src/frame/touchLayer.js.map +1 -0
  64. package/dist/src/frame/touchScroll.d.ts +51 -0
  65. package/dist/src/frame/touchScroll.d.ts.map +1 -0
  66. package/dist/src/frame/touchScroll.js +154 -0
  67. package/dist/src/frame/touchScroll.js.map +1 -0
  68. package/dist/src/namedViews.d.ts +10 -1
  69. package/dist/src/namedViews.d.ts.map +1 -1
  70. package/dist/src/namedViews.js +24 -0
  71. package/dist/src/namedViews.js.map +1 -1
  72. package/dist/src/realTouch.d.ts +21 -0
  73. package/dist/src/realTouch.d.ts.map +1 -0
  74. package/dist/src/realTouch.js +16 -0
  75. package/dist/src/realTouch.js.map +1 -0
  76. package/dist/src/shell/ComponentPage.d.ts +6 -1
  77. package/dist/src/shell/ComponentPage.d.ts.map +1 -1
  78. package/dist/src/shell/ComponentPage.js +11 -3
  79. package/dist/src/shell/ComponentPage.js.map +1 -1
  80. package/dist/src/shell/ControlRow.d.ts.map +1 -1
  81. package/dist/src/shell/ControlRow.js +4 -1
  82. package/dist/src/shell/ControlRow.js.map +1 -1
  83. package/dist/src/shell/Example.d.ts +5 -0
  84. package/dist/src/shell/Example.d.ts.map +1 -1
  85. package/dist/src/shell/Example.js +18 -2
  86. package/dist/src/shell/Example.js.map +1 -1
  87. package/dist/src/shell/FrameView.d.ts +7 -0
  88. package/dist/src/shell/FrameView.d.ts.map +1 -1
  89. package/dist/src/shell/FrameView.js +12 -0
  90. package/dist/src/shell/FrameView.js.map +1 -1
  91. package/dist/src/shell/InfoTip.d.ts +23 -0
  92. package/dist/src/shell/InfoTip.d.ts.map +1 -0
  93. package/dist/src/shell/InfoTip.js +53 -0
  94. package/dist/src/shell/InfoTip.js.map +1 -0
  95. package/dist/src/shell/NamedViews.d.ts.map +1 -1
  96. package/dist/src/shell/NamedViews.js +2 -2
  97. package/dist/src/shell/NamedViews.js.map +1 -1
  98. package/dist/src/shell/PinnedControl.d.ts.map +1 -1
  99. package/dist/src/shell/PinnedControl.js +14 -2
  100. package/dist/src/shell/PinnedControl.js.map +1 -1
  101. package/dist/src/shell/Shell.d.ts.map +1 -1
  102. package/dist/src/shell/Shell.js +21 -3
  103. package/dist/src/shell/Shell.js.map +1 -1
  104. package/dist/src/shell/UsedIn.d.ts +4 -3
  105. package/dist/src/shell/UsedIn.d.ts.map +1 -1
  106. package/dist/src/shell/UsedIn.js +11 -7
  107. package/dist/src/shell/UsedIn.js.map +1 -1
  108. package/dist/src/shell/ViewMenu.d.ts +4 -2
  109. package/dist/src/shell/ViewMenu.d.ts.map +1 -1
  110. package/dist/src/shell/ViewMenu.js +14 -7
  111. package/dist/src/shell/ViewMenu.js.map +1 -1
  112. package/dist/src/shell/controlCycle.d.ts.map +1 -1
  113. package/dist/src/shell/controlCycle.js +3 -2
  114. package/dist/src/shell/controlCycle.js.map +1 -1
  115. package/dist/src/shell/icons.d.ts +1 -0
  116. package/dist/src/shell/icons.d.ts.map +1 -1
  117. package/dist/src/shell/icons.js +1 -0
  118. package/dist/src/shell/icons.js.map +1 -1
  119. package/dist/src/shell/shell.css +58 -1
  120. package/dist/src/shell/storyTouch.d.ts +52 -0
  121. package/dist/src/shell/storyTouch.d.ts.map +1 -0
  122. package/dist/src/shell/storyTouch.js +33 -0
  123. package/dist/src/shell/storyTouch.js.map +1 -0
  124. package/dist/src/shell/strings.d.ts +4 -3
  125. package/dist/src/shell/strings.d.ts.map +1 -1
  126. package/dist/src/shell/strings.js +4 -3
  127. package/dist/src/shell/strings.js.map +1 -1
  128. package/dist/src/shell/useFold.d.ts.map +1 -1
  129. package/dist/src/shell/useFold.js +2 -0
  130. package/dist/src/shell/useFold.js.map +1 -1
  131. package/dist/src/shell/useFrameMessages.d.ts +5 -2
  132. package/dist/src/shell/useFrameMessages.d.ts.map +1 -1
  133. package/dist/src/shell/useFrameMessages.js +1 -1
  134. package/dist/src/shell/useFrameMessages.js.map +1 -1
  135. package/dist/src/shell/useLiveView.d.ts +8 -1
  136. package/dist/src/shell/useLiveView.d.ts.map +1 -1
  137. package/dist/src/shell/useLiveView.js +14 -4
  138. package/dist/src/shell/useLiveView.js.map +1 -1
  139. package/dist/src/shell/useWorstCase.d.ts +2 -2
  140. package/dist/src/shell/useWorstCase.d.ts.map +1 -1
  141. package/dist/src/shell/useWorstCase.js +10 -3
  142. package/dist/src/shell/useWorstCase.js.map +1 -1
  143. package/dist/src/storyTree.d.ts +2 -0
  144. package/dist/src/storyTree.d.ts.map +1 -1
  145. package/dist/src/storyTree.js +1 -0
  146. package/dist/src/storyTree.js.map +1 -1
  147. package/dist/src/switches.d.ts +32 -6
  148. package/dist/src/switches.d.ts.map +1 -1
  149. package/dist/src/switches.js +45 -7
  150. package/dist/src/switches.js.map +1 -1
  151. package/dist/src/viewState.d.ts +27 -2
  152. package/dist/src/viewState.d.ts.map +1 -1
  153. package/dist/src/viewState.js +35 -2
  154. package/dist/src/viewState.js.map +1 -1
  155. package/dist/src/vite/agentRoutes.d.ts +7 -0
  156. package/dist/src/vite/agentRoutes.d.ts.map +1 -1
  157. package/dist/src/vite/agentRoutes.js +15 -2
  158. package/dist/src/vite/agentRoutes.js.map +1 -1
  159. package/dist/src/vite/forcedStates.d.ts +6 -2
  160. package/dist/src/vite/forcedStates.d.ts.map +1 -1
  161. package/dist/src/vite/forcedStates.js +20 -4
  162. package/dist/src/vite/forcedStates.js.map +1 -1
  163. package/dist/src/vite/forgebookPlugin.d.ts.map +1 -1
  164. package/dist/src/vite/forgebookPlugin.js +11 -21
  165. package/dist/src/vite/forgebookPlugin.js.map +1 -1
  166. package/dist/src/vite/indexStoryFile.d.ts +1 -1
  167. package/dist/src/vite/indexStoryFile.d.ts.map +1 -1
  168. package/dist/src/vite/indexStoryFile.js +14 -1
  169. package/dist/src/vite/indexStoryFile.js.map +1 -1
  170. package/dist/src/vite/mcpProtocol.d.ts.map +1 -1
  171. package/dist/src/vite/mcpProtocol.js +9 -1
  172. package/dist/src/vite/mcpProtocol.js.map +1 -1
  173. package/dist/src/vite/storyFilesModule.d.ts +25 -3
  174. package/dist/src/vite/storyFilesModule.d.ts.map +1 -1
  175. package/dist/src/vite/storyFilesModule.js +31 -4
  176. package/dist/src/vite/storyFilesModule.js.map +1 -1
  177. package/dist/src/vite/touchMedia.d.ts +35 -0
  178. package/dist/src/vite/touchMedia.d.ts.map +1 -0
  179. package/dist/src/vite/touchMedia.js +282 -0
  180. package/dist/src/vite/touchMedia.js.map +1 -0
  181. package/dist/src/vite/usageGraph.d.ts.map +1 -1
  182. package/dist/src/vite/usageGraph.js +25 -1
  183. package/dist/src/vite/usageGraph.js.map +1 -1
  184. package/package.json +8 -4
@@ -0,0 +1,449 @@
1
+ /**
2
+ * The frame's simulated touch, on while the root has `data-forgebook-touch` (the Touch switch): the real mouse's
3
+ * events are caught before the story and sent again as a finger, or as two with Shift held.
4
+ *
5
+ * @remarks
6
+ * A press sends `pointerdown` (touch) and `touchstart`; a move sends `touchmove`, and `pointermove` until a drag
7
+ * starts scrolling, when the pointer is cancelled as the browser cancels it (`touchScroll.ts`); a lift sends
8
+ * `pointerup` and `touchend`. A tap then sends the mouse's compatibility events and its own click of the `touch` type
9
+ * in place of the real one, so a button, a link or a checkbox reacts as it would; a press held half a second sends `contextmenu`. A moving mouse with
10
+ * no button down sends nothing: a finger does not hover. Shift fixes a centre beside the mouse (the second finger shows 80 px to its left); a press then puts a
11
+ * second finger mirrored around it, so dragging pinches and rotates. The real cursor is hidden and the fingers are
12
+ * dots (`touchDots.ts`). While it is on, `navigator.maxTouchPoints` and `ontouchstart` say touch, and capturing a
13
+ * simulated pointer works. A simulation: the events are not trusted, so the browser's own scrolling, focus from a
14
+ * touch, a virtual keyboard and real Safari stay a device's (or `forgebook dev --touch`'s).
15
+ *
16
+ * @module
17
+ */
18
+ import { isRealTouchWindow } from "../realTouch.js";
19
+ import { touchDots } from "./touchDots.js";
20
+ import { sendClick, sendMouse, sendPointer, sendTouch } from "./touchEvents.js";
21
+ import { dragAxis, isDragging, LONG_PRESS_MS, mirroredFinger } from "./touchGesture.js";
22
+ import { endPan, panBy, panOf } from "./touchScroll.js";
23
+ /** The root's attribute that turns the simulation on. */
24
+ const TOUCH_ATTRIBUTE = "data-forgebook-touch";
25
+ /** The simulated pointers' ids: apart from the real mouse's, so the browser never confuses them. */
26
+ const FINGER_IDS = [100, 101];
27
+ /** How far apart two fingers start, in CSS px: Shift fixes the centre half of it to the left of the mouse. */
28
+ const START_SPREAD_PX = 80;
29
+ /** A finger held still longer than this before it lifts, in ms, lifts without a fling. */
30
+ const STILL_MS = 80;
31
+ /** The real events that never reach the story while touch is simulated (the hover a finger does not have). */
32
+ const SWALLOWED = ["mousedown", "mouseup", "mousemove", "mouseover", "mouseout", "mouseenter", "mouseleave"];
33
+ /** The real pointer events that never reach the story: the fingers send their own. */
34
+ const SWALLOWED_POINTER = ["pointerover", "pointerout", "pointerenter", "pointerleave"];
35
+ /**
36
+ * The two-finger centre Shift fixes when it goes down with the mouse at a point: half the fingers' spread to its left,
37
+ * so the second finger shows at once beside the first, and moves mirrored from then on.
38
+ *
39
+ * @param point - where the mouse is.
40
+ */
41
+ const shiftCenter = (point) => ({ x: point.x - START_SPREAD_PX / 2, y: point.y });
42
+ /**
43
+ * The fingers' dots: the fingers of a press, or the mouse (and the second finger to come, with Shift) between presses.
44
+ *
45
+ * @param state - the simulation's state.
46
+ */
47
+ const drawDots = (state) => {
48
+ const { press, mouse, center } = state;
49
+ if (press !== undefined) {
50
+ state.dots.draw(press.fingers.map((finger) => ({ point: finger.point, isPressed: true })));
51
+ return;
52
+ }
53
+ if (mouse === undefined) {
54
+ state.dots.draw([]);
55
+ return;
56
+ }
57
+ // the second finger where a press will put it: mirrored around Shift's centre
58
+ const second = center === undefined ? [] : [{ point: mirroredFinger(center, mouse), isPressed: false }];
59
+ state.dots.draw([{ point: mouse, isPressed: false }, ...second]);
60
+ };
61
+ /**
62
+ * The second finger going down at a point.
63
+ *
64
+ * @param document - the frame's document.
65
+ * @param id - its id.
66
+ * @param point - where.
67
+ * @param fallback - the element when none is under the point.
68
+ */
69
+ const fingerAt = (document, id, point, fallback) => {
70
+ const target = document.elementFromPoint(point.x, point.y) ?? fallback;
71
+ return { id, isPrimary: false, point, startTarget: target, captureTarget: target };
72
+ };
73
+ /**
74
+ * A press begins: its fingers go down, each sending its pointer and touch events.
75
+ *
76
+ * @param state - the simulation's state.
77
+ * @param event - the real pointer's press.
78
+ */
79
+ const pressDown = (state, event) => {
80
+ state.stopFling();
81
+ const point = { x: event.clientX, y: event.clientY };
82
+ const target = event.target instanceof Element ? event.target : state.document.documentElement;
83
+ const center = event.shiftKey ? (state.center ?? shiftCenter(point)) : undefined;
84
+ // the first finger goes down where the real press did, on the element the browser found under it
85
+ const fingers = [
86
+ { id: FINGER_IDS[0], isPrimary: true, point, startTarget: target, captureTarget: target }
87
+ ];
88
+ if (center !== undefined)
89
+ fingers.push(fingerAt(state.document, FINGER_IDS[1], mirroredFinger(center, point), target));
90
+ // the press is the layer's before its first event: a story that captures the pointer in its pointerdown finds it
91
+ const press = {
92
+ fingers,
93
+ start: point,
94
+ center,
95
+ isDrag: false,
96
+ isLongPress: false,
97
+ isDownCancelled: false,
98
+ isTouchCancelled: false,
99
+ pan: undefined,
100
+ last: { point, time: event.timeStamp },
101
+ speed: { x: 0, y: 0 },
102
+ timer: undefined
103
+ };
104
+ state.press = press;
105
+ for (const finger of fingers) {
106
+ sendPointer("pointerover", finger, true);
107
+ sendPointer("pointerenter", finger, true);
108
+ if (!sendPointer("pointerdown", finger, true))
109
+ press.isDownCancelled = true;
110
+ }
111
+ press.isTouchCancelled = !sendTouch("touchstart", fingers, fingers, true);
112
+ // a long press opens the story's menu, as on a phone
113
+ press.timer = window.setTimeout(() => {
114
+ if (press.isDrag || press.fingers.length > 1 || state.press !== press)
115
+ return;
116
+ press.isLongPress = true;
117
+ const [first] = press.fingers;
118
+ if (first !== undefined)
119
+ sendMouse("contextmenu", first);
120
+ }, LONG_PRESS_MS);
121
+ drawDots(state);
122
+ };
123
+ /**
124
+ * Starts the drag of a press, the first time its finger passes a tap's reach: a single finger whose move no handler
125
+ * cancelled scrolls what it can (the pointer is then cancelled, as the browser cancels it).
126
+ *
127
+ * @param press - the press.
128
+ * @param isMoveCancelled - whether a handler cancelled this `touchmove`.
129
+ */
130
+ const startDrag = (press, isMoveCancelled) => {
131
+ press.isDrag = true;
132
+ window.clearTimeout(press.timer);
133
+ const [first] = press.fingers;
134
+ if (isMoveCancelled || press.isTouchCancelled || press.fingers.length > 1 || first === undefined)
135
+ return;
136
+ press.pan = panOf(first.startTarget, dragAxis(press.start, first.point));
137
+ if (press.pan !== undefined)
138
+ sendPointer("pointercancel", first, false);
139
+ };
140
+ /**
141
+ * The fingers follow the mouse: touch events always, pointer events until the drag scrolls, the scroll otherwise.
142
+ *
143
+ * @param state - the simulation's state.
144
+ * @param press - the press.
145
+ * @param event - the real pointer's move.
146
+ */
147
+ const pressMove = (state, press, event) => {
148
+ const point = { x: event.clientX, y: event.clientY };
149
+ // the mouse goes with the finger: after the lift, its dot stays where the finger left the screen
150
+ state.mouse = point;
151
+ const [first, second] = press.fingers;
152
+ if (first === undefined)
153
+ return;
154
+ const from = first.point;
155
+ first.point = point;
156
+ if (second !== undefined && press.center !== undefined)
157
+ second.point = mirroredFinger(press.center, point);
158
+ const isMoveCancelled = !sendTouch("touchmove", press.fingers, press.fingers, press.pan === undefined);
159
+ if (!press.isDrag && isDragging(press.start, point))
160
+ startDrag(press, isMoveCancelled);
161
+ const ms = Math.max(1, event.timeStamp - press.last.time);
162
+ press.speed = { x: (point.x - press.last.point.x) / ms, y: (point.y - press.last.point.y) / ms };
163
+ press.last = { point, time: event.timeStamp };
164
+ if (press.pan !== undefined)
165
+ panBy(press.pan, from, point);
166
+ else
167
+ for (const finger of press.fingers)
168
+ sendPointer("pointermove", finger, true);
169
+ drawDots(state);
170
+ };
171
+ /**
172
+ * A press ends: the fingers lift, a scroll flings on, a tap sends the mouse's compatibility events and readies its
173
+ * click.
174
+ *
175
+ * @param state - the simulation's state.
176
+ * @param press - the press.
177
+ * @param isCancel - whether the browser cancelled the real pointer, or the layer stops mid-press.
178
+ * @param time - when, as the events' `timeStamp`.
179
+ */
180
+ const pressUp = (state, press, isCancel, time) => {
181
+ window.clearTimeout(press.timer);
182
+ // a finger that stopped before it lifted throws nothing
183
+ if (time - press.last.time > STILL_MS)
184
+ press.speed = { x: 0, y: 0 };
185
+ if (press.pan === undefined) {
186
+ // the press is still the layer's while its pointer ends: a story's pointerup may release its capture
187
+ for (const finger of press.fingers) {
188
+ sendPointer(isCancel ? "pointercancel" : "pointerup", finger, false);
189
+ // a touch pointer is captured from its press on (by its target, or where the story moved it), and lost here
190
+ sendPointer("lostpointercapture", finger, false);
191
+ sendPointer("pointerout", finger, false);
192
+ sendPointer("pointerleave", finger, false);
193
+ }
194
+ }
195
+ state.press = undefined;
196
+ const isEndCancelled = !sendTouch(isCancel ? "touchcancel" : "touchend", [], press.fingers, press.pan === undefined);
197
+ if (press.pan !== undefined)
198
+ state.stopFling = endPan(press.pan, press.speed);
199
+ const [first] = press.fingers;
200
+ const isTap = !isCancel && !press.isDrag && !press.isLongPress && press.fingers.length === 1;
201
+ const isClicking = isTap && !press.isTouchCancelled && !isEndCancelled;
202
+ state.tapper = isClicking ? first : undefined;
203
+ if (isClicking && !press.isDownCancelled && first !== undefined) {
204
+ sendMouse("mousedown", first);
205
+ sendMouse("mouseup", first);
206
+ }
207
+ drawDots(state);
208
+ };
209
+ /**
210
+ * A real event the layer handles apart from the pointer's, before the story: the mouse's click (a tap's is sent again as
211
+ * a finger's, a drag's or a long press's is none), a text selection or an image dragged by the finger, the right
212
+ * button's menu. A click from the keyboard (Enter or Space on a button, Enter in a form) and the keyboard's menu key
213
+ * reach the story as they are: a finger changes nothing of the keyboard.
214
+ *
215
+ * @param state - the simulation's state.
216
+ * @param event - the real event.
217
+ * @returns whether the event was one of them, handled here.
218
+ */
219
+ const handledApart = (state, event) => {
220
+ const isMouseEvent = event instanceof MouseEvent;
221
+ if (event.type === "click") {
222
+ // a click the keyboard made has no press behind it (`detail` 0) and no tap waiting for it
223
+ if (state.tapper === undefined && isMouseEvent && event.detail === 0)
224
+ return true;
225
+ event.preventDefault();
226
+ event.stopImmediatePropagation();
227
+ const finger = state.tapper;
228
+ state.tapper = undefined;
229
+ // after the real click's dispatch: cancelling it undoes a checkbox's toggle at its end, a click sent inside it too
230
+ const { target } = event;
231
+ if (finger !== undefined && target !== null)
232
+ state.clickTimer = window.setTimeout(() => {
233
+ state.clickTimer = undefined;
234
+ sendClick(target, finger);
235
+ }, 0);
236
+ return true;
237
+ }
238
+ if (event.type === "contextmenu" && !(isMouseEvent && event.button === 2))
239
+ return true;
240
+ if (event.type !== "selectstart" && event.type !== "dragstart" && event.type !== "contextmenu")
241
+ return false;
242
+ event.preventDefault();
243
+ event.stopImmediatePropagation();
244
+ return true;
245
+ };
246
+ /**
247
+ * The mouse moves: a press under way follows it (or lifts, when its button came up out of sight), the dots follow it
248
+ * between presses, and Shift held fixes the two-finger centre.
249
+ *
250
+ * @param state - the simulation's state.
251
+ * @param event - the real pointer's move.
252
+ */
253
+ const pointerMove = (state, event) => {
254
+ const { press } = state;
255
+ if (press !== undefined && (event.buttons & 1) === 0) {
256
+ // the button came up where the frame could not see it (outside the window): the finger lifts here
257
+ state.mouse = { x: event.clientX, y: event.clientY };
258
+ pressUp(state, press, false, event.timeStamp);
259
+ }
260
+ else if (press !== undefined)
261
+ pressMove(state, press, event);
262
+ else {
263
+ // Shift read from the pointer, which carries it even when the frame has no focus (the shell usually does): held,
264
+ // it fixes the two-finger centre beside the mouse
265
+ if (!event.shiftKey)
266
+ state.center = undefined;
267
+ else
268
+ state.center ??= shiftCenter(state.mouse ?? { x: event.clientX, y: event.clientY });
269
+ state.mouse = { x: event.clientX, y: event.clientY };
270
+ drawDots(state);
271
+ }
272
+ };
273
+ /**
274
+ * What the simulation does with one real pointer event: the press, the move and the lift of the fingers, the dots
275
+ * between presses.
276
+ *
277
+ * @param state - the simulation's state.
278
+ * @param event - the real pointer event.
279
+ */
280
+ const pointerInput = (state, event) => {
281
+ const { press } = state;
282
+ if (event.type === "pointermove")
283
+ pointerMove(state, event);
284
+ else if (event.type === "pointerout" && event.relatedTarget === null && press === undefined) {
285
+ state.mouse = undefined;
286
+ drawDots(state);
287
+ }
288
+ else if (event.type === "pointerdown" && event.button === 0 && press === undefined)
289
+ pressDown(state, event);
290
+ else if ((event.type === "pointerup" || event.type === "pointercancel") && press !== undefined) {
291
+ state.mouse = { x: event.clientX, y: event.clientY };
292
+ pressUp(state, press, event.type === "pointercancel", event.timeStamp);
293
+ }
294
+ };
295
+ /**
296
+ * What the simulation does with one real event, before the story sees it: the story never sees a real one.
297
+ *
298
+ * @param state - the simulation's state.
299
+ * @param event - the real event (the story's own dispatched events are left alone).
300
+ */
301
+ const intercept = (state, event) => {
302
+ if (!event.isTrusted || handledApart(state, event))
303
+ return;
304
+ event.stopImmediatePropagation();
305
+ if (event instanceof PointerEvent)
306
+ pointerInput(state, event);
307
+ };
308
+ /**
309
+ * Makes the frame say it is a touch device, and lets the story capture a simulated pointer.
310
+ *
311
+ * @param state - the simulation's state.
312
+ * @returns what puts the frame back as it was.
313
+ */
314
+ const pretendTouch = (state) => {
315
+ const view = state.document.defaultView;
316
+ if (view === null)
317
+ return () => undefined;
318
+ Object.defineProperty(view.navigator, "maxTouchPoints", { configurable: true, get: () => 5 });
319
+ Object.defineProperty(view, "ontouchstart", { configurable: true, writable: true, value: null });
320
+ const proto = view.Element.prototype;
321
+ const native = {
322
+ set: proto.setPointerCapture,
323
+ release: proto.releasePointerCapture,
324
+ has: proto.hasPointerCapture
325
+ };
326
+ const fingerOf = (id) => state.press?.fingers.find((finger) => finger.id === id);
327
+ // a simulated pointer's id never reaches the browser, which knows no such pointer: once its finger lifted, setting its
328
+ // capture fails as the browser fails it, releasing it does nothing
329
+ const isSimulated = (id) => FINGER_IDS.some((each) => each === id);
330
+ proto.setPointerCapture = function setPointerCapture(id) {
331
+ const finger = fingerOf(id);
332
+ if (finger === undefined && isSimulated(id))
333
+ throw new DOMException("No active pointer with the given id is found.", "NotFoundError");
334
+ if (finger === undefined) {
335
+ native.set.call(this, id);
336
+ return;
337
+ }
338
+ finger.captureTarget = this;
339
+ sendPointer("gotpointercapture", finger, true);
340
+ };
341
+ proto.releasePointerCapture = function releasePointerCapture(id) {
342
+ const finger = fingerOf(id);
343
+ if (finger === undefined) {
344
+ if (!isSimulated(id))
345
+ native.release.call(this, id);
346
+ return;
347
+ }
348
+ sendPointer("lostpointercapture", finger, true);
349
+ finger.captureTarget = finger.startTarget;
350
+ };
351
+ proto.hasPointerCapture = function hasPointerCapture(id) {
352
+ const finger = fingerOf(id);
353
+ if (finger === undefined)
354
+ return isSimulated(id) ? false : native.has.call(this, id);
355
+ return finger.captureTarget === this;
356
+ };
357
+ return () => {
358
+ Reflect.deleteProperty(view.navigator, "maxTouchPoints");
359
+ Reflect.deleteProperty(view, "ontouchstart");
360
+ proto.setPointerCapture = native.set;
361
+ proto.releasePointerCapture = native.release;
362
+ proto.hasPointerCapture = native.has;
363
+ };
364
+ };
365
+ /** The events the simulation catches, on the window, before the story. */
366
+ const CAUGHT = [
367
+ "pointerdown",
368
+ "pointermove",
369
+ "pointerup",
370
+ "pointercancel",
371
+ ...SWALLOWED_POINTER,
372
+ ...SWALLOWED,
373
+ "click",
374
+ "contextmenu",
375
+ "selectstart",
376
+ "dragstart"
377
+ ];
378
+ /**
379
+ * Starts the simulation in a frame.
380
+ *
381
+ * @param document - the frame's document.
382
+ * @returns what stops it.
383
+ */
384
+ const startTouch = (document) => {
385
+ const state = {
386
+ document,
387
+ dots: touchDots(document),
388
+ mouse: undefined,
389
+ center: undefined,
390
+ press: undefined,
391
+ tapper: undefined,
392
+ clickTimer: undefined,
393
+ stopFling: () => undefined
394
+ };
395
+ const restore = pretendTouch(state);
396
+ const onEvent = (event) => intercept(state, event);
397
+ // Shift fixes the two-finger centre where the mouse is, and shows where the second finger will be
398
+ const onKey = (event) => {
399
+ if (event.key !== "Shift" || state.press !== undefined)
400
+ return;
401
+ state.center =
402
+ event.type === "keydown" && state.mouse !== undefined ? shiftCenter(state.mouse) : undefined;
403
+ drawDots(state);
404
+ };
405
+ const view = document.defaultView;
406
+ for (const type of CAUGHT)
407
+ view?.addEventListener(type, onEvent, { capture: true });
408
+ view?.addEventListener("keydown", onKey);
409
+ view?.addEventListener("keyup", onKey);
410
+ return () => {
411
+ // a press under way is cancelled, as the browser cancels a touch it takes over: its timers, its scroll's snapping
412
+ // and a tap's click to come end with it
413
+ if (state.press !== undefined)
414
+ pressUp(state, state.press, true, performance.now());
415
+ window.clearTimeout(state.clickTimer);
416
+ state.tapper = undefined;
417
+ for (const type of CAUGHT)
418
+ view?.removeEventListener(type, onEvent, { capture: true });
419
+ view?.removeEventListener("keydown", onKey);
420
+ view?.removeEventListener("keyup", onKey);
421
+ state.stopFling();
422
+ restore();
423
+ state.dots.remove();
424
+ };
425
+ };
426
+ /**
427
+ * Follows the root's touch attribute from now on: the simulation runs while it is set.
428
+ *
429
+ * @param document - the frame's document.
430
+ */
431
+ export const followTouch = (document) => {
432
+ let stop;
433
+ // in Chromium's real touch window the pages see real touch: simulating it on top would send every touch twice
434
+ const view = document.defaultView;
435
+ if (view !== null && isRealTouchWindow(view))
436
+ return;
437
+ const update = () => {
438
+ const isOn = document.documentElement.hasAttribute(TOUCH_ATTRIBUTE);
439
+ if (isOn && stop === undefined)
440
+ stop = startTouch(document);
441
+ else if (!isOn && stop !== undefined) {
442
+ stop();
443
+ stop = undefined;
444
+ }
445
+ };
446
+ new MutationObserver(update).observe(document.documentElement, { attributeFilter: [TOUCH_ATTRIBUTE] });
447
+ update();
448
+ };
449
+ //# sourceMappingURL=touchLayer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"touchLayer.js","sourceRoot":"","sources":["../../../src/frame/touchLayer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAkB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAe,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,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CAAC,QAAQ,CAAC,eAAe,EAAE,EAAE,eAAe,EAAE,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;IACvG,MAAM,EAAE,CAAC;AACX,CAAC,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * A simulated finger's scrolling: the container a drag scrolls, on the axes the `touch-action` on the way allows, and
3
+ * the fling that carries on after the finger lifts.
4
+ *
5
+ * @remarks
6
+ * An approximation of the browser's own scrolling, which a page cannot start: no rubber band at the ends, the fling
7
+ * slows down at one fixed rate (`flungSpeed`), and a container that snaps snaps once the finger lifts. The scroll keeps to the drag's axis; the container is the nearest
8
+ * ancestor that scrolls on it, up to the document's own scrolling element.
9
+ *
10
+ * @module
11
+ */
12
+ import { type PanAxes, type Point } from "./touchGesture.ts";
13
+ /** A scroll a finger drives. */
14
+ export type Pan = {
15
+ /** The element it scrolls. */
16
+ readonly scroller: Element;
17
+ /** The axes it scrolls on. */
18
+ readonly axes: PanAxes;
19
+ /**
20
+ * For a container that snaps, its own `scroll-snap-type` (inline) while the drag pauses its snapping, put back when
21
+ * the finger lifts; none for one that does not snap.
22
+ */
23
+ readonly pausedSnap: string | undefined;
24
+ };
25
+ /**
26
+ * The scroll a drag drives along its axis, or none when the `touch-action` on the way forbids that axis (a horizontal
27
+ * swipe on a `pan-y` row stays the row's) or nothing on the way scrolls on it.
28
+ *
29
+ * @param target - the element the finger went down on.
30
+ * @param axis - the drag's axis.
31
+ */
32
+ export declare const panOf: (target: Element, axis: "x" | "y") => Pan | undefined;
33
+ /**
34
+ * Scrolls by a finger's move: the content follows the finger.
35
+ *
36
+ * @param pan - the scroll.
37
+ * @param from - where the finger was.
38
+ * @param to - where it is.
39
+ */
40
+ export declare const panBy: (pan: Pan, from: Point, to: Point) => void;
41
+ /**
42
+ * A drag's scroll ends as the finger lifts: a container that snaps snaps again, to the item nearest where the finger
43
+ * aimed (its place now plus its last speed, at most half the container ahead, so a flick goes to the next item and
44
+ * never past it), with the browser's smooth scroll; any other flings on. The returned function stops a fling (a new
45
+ * touch does).
46
+ *
47
+ * @param pan - the scroll.
48
+ * @param speed - the finger's last speed, in CSS px per ms, per axis.
49
+ */
50
+ export declare const endPan: (pan: Pan, speed: Point) => (() => void);
51
+ //# sourceMappingURL=touchScroll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"touchScroll.d.ts","sourceRoot":"","sources":["../../../src/frame/touchScroll.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAA0B,KAAK,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAErF,gCAAgC;AAChC,MAAM,MAAM,GAAG,GAAG;IAChB,8BAA8B;IAC9B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,8BAA8B;IAC9B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CACzC,CAAC;AA0CF;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,GAAI,QAAQ,OAAO,EAAE,MAAM,GAAG,GAAG,GAAG,KAAG,GAAG,GAAG,SAQ9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,GAAI,KAAK,GAAG,EAAE,MAAM,KAAK,EAAE,IAAI,KAAK,KAAG,IAKrD,CAAC;AAkDL;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,GAAI,KAAK,GAAG,EAAE,OAAO,KAAK,KAAG,CAAC,MAAM,IAAI,CAkB1D,CAAC"}