@molecule/app-pointer-events-dom 0.0.1-stage → 1.2.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.
package/README.md CHANGED
@@ -3,17 +3,20 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-11-25T14:48:10.019Z
6
+ Generated: 2026-11-27T20:36:32.142Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-pointer-events-dom
10
10
 
11
- DOM pointer drag gestures for the Molecule web UI kits.
11
+ Shared DOM drag, hover, and focal zoom gestures for the Molecule web UI kits.
12
12
 
13
- Use the renderer's drag binding with `ElementDrag` from `@molecule/app-ui`.
13
+ Use the renderer's drag binding with `ElementDrag` or pass `{ drag, zoom }` from
14
+ `@molecule/app-ui` on a surface with focal wheel zoom and two-finger pinch.
14
15
  All web kits share press ownership, pointer capture, touch intent, and
15
16
  cancellation on pointer cancel, lost capture, window blur, and host removal.
16
17
  Use `markPressTarget` for custom controls that must keep their own presses.
18
+ Use `bindWebHover` for one mouse or pen transition per boundary and
19
+ `bindWebWheelZoom` to handle Ctrl-wheel steps on a surface.
17
20
 
18
21
  > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
19
22
  > It is written to be read by coding agents as much as by people, and is generated from this
@@ -54,9 +57,15 @@ interface WebDrag {
54
57
  /**
55
58
  * Updates the callbacks used by the gesture. Removing the handlers cancels the contact.
56
59
  *
57
- * @param drag - The current handlers, or undefined to disable dragging.
60
+ * @param options - The current handlers, or undefined to disable the surface.
58
61
  */
59
- update(drag: ElementDrag | undefined): void
62
+ update(options: WebDragOptions | undefined): void
63
+ /**
64
+ * Attaches touch reservation and focal wheel input to the current host.
65
+ *
66
+ * @param host - The host receiving wheel events, or null on detach.
67
+ */
68
+ attach(host: DragHost | null): void
60
69
  /**
61
70
  * Offers a pointer press to this host.
62
71
  *
@@ -71,7 +80,7 @@ interface WebDrag {
71
80
  drag?: ElementDrag,
72
81
  target?: EventTarget | null,
73
82
  ): void
74
- /** Cancels the active contact, if any. */
83
+ /** Cancels the active input, if any. */
75
84
  cancel(): void
76
85
  }
77
86
  ```
@@ -85,14 +94,79 @@ interface WebDragBinding {
85
94
  /**
86
95
  * Updates the handlers for this host.
87
96
  *
88
- * @param drag - The current handlers, or undefined to disable dragging.
97
+ * @param options - The current handlers, or undefined to disable the surface.
89
98
  */
90
- update(drag: ElementDrag | undefined): void
99
+ update(options: WebDragOptions | undefined): void
91
100
  /** Removes the pointer listener and cancels any active contact. */
92
101
  destroy(): void
93
102
  }
94
103
  ```
95
104
 
105
+ #### `WebHoverHandlers`
106
+
107
+ Callbacks for the shared hover transition.
108
+
109
+ ```typescript
110
+ interface WebHoverHandlers {
111
+ /** Runs when a mouse or pen enters the host. */
112
+ onEnter?: (event: MouseEvent) => void
113
+ /** Runs when the hovering mouse or pen leaves the host. */
114
+ onLeave?: (event: MouseEvent) => void
115
+ }
116
+ ```
117
+
118
+ #### `WebHoverBinding`
119
+
120
+ The lifecycle of a hover attached to a DOM element.
121
+
122
+ ```typescript
123
+ interface WebHoverBinding {
124
+ /**
125
+ * Updates the callbacks. Pass undefined to disable hover.
126
+ *
127
+ * @param handlers - The current hover callbacks.
128
+ */
129
+ update(handlers: WebHoverHandlers | undefined): void
130
+ /** Removes the event listeners. */
131
+ destroy(): void
132
+ }
133
+ ```
134
+
135
+ #### `WebWheelZoomBinding`
136
+
137
+ The lifecycle of the Ctrl-wheel shortcut on a surface.
138
+
139
+ ```typescript
140
+ interface WebWheelZoomBinding {
141
+ /**
142
+ * Updates the callback. Pass undefined to leave wheel input to the browser.
143
+ *
144
+ * @param onStep - The current zoom callback.
145
+ */
146
+ update(onStep: WebWheelZoomHandler | undefined): void
147
+ /** Removes the wheel listener. */
148
+ destroy(): void
149
+ }
150
+ ```
151
+
152
+ ### Types
153
+
154
+ #### `WebDragOptions`
155
+
156
+ Accepts a standalone drag or the element's combined drag and zoom options.
157
+
158
+ ```typescript
159
+ type WebDragOptions = ElementDrag | ElementDragProps
160
+ ```
161
+
162
+ #### `WebWheelZoomHandler`
163
+
164
+ Called with the direction of one Ctrl-wheel step.
165
+
166
+ ```typescript
167
+ type WebWheelZoomHandler = (direction: 'in' | 'out') => void
168
+ ```
169
+
96
170
  ### Functions
97
171
 
98
172
  #### `markPressTarget(host)`
@@ -105,38 +179,102 @@ function markPressTarget(host: Element): void
105
179
 
106
180
  - `host` — The element that owns the activation.
107
181
 
108
- #### `createWebDrag(initialDrag)`
182
+ #### `createWebDrag(initial)`
109
183
 
110
184
  Acquires a press on the deepest drag host and follows its pointer until release or interruption.
111
185
 
112
186
  ```typescript
113
- function createWebDrag(initialDrag?: ElementDrag): WebDrag
187
+ function createWebDrag(initial?: WebDragOptions): WebDrag
114
188
  ```
115
189
 
116
- - `initialDrag` — The initial handlers, if the host starts enabled.
190
+ - `initial` — The initial handlers, if the host starts enabled.
117
191
 
118
192
  **Returns:** The controls a renderer uses to handle pointerdown, updates and unmount.
119
193
 
120
- #### `bindWebDrag(host, drag)`
194
+ #### `bindWebDrag(host, options)`
121
195
 
122
196
  Binds a drag to a native bubbling pointerdown listener.
123
197
 
124
198
  ```typescript
125
- function bindWebDrag(host: HTMLElement | SVGElement, drag?: ElementDrag): WebDragBinding
199
+ function bindWebDrag(host: DragHost, options?: WebDragOptions): WebDragBinding
126
200
  ```
127
201
 
128
202
  - `host` — The element that can own the press.
129
- - `drag` — The initial handlers, if the host starts enabled.
203
+ - `options` — The initial handlers, if the host starts enabled.
204
+
205
+ **Returns:** The binding to update or destroy with the host.
206
+
207
+ #### `createWebHover()`
208
+
209
+ Creates one enter/leave transition for a host. Touch and its compatibility
210
+ mouse events never hover. A later mouse or pen pointer resumes hover.
211
+
212
+ ```typescript
213
+ function createWebHover(): (entered: boolean, event: HoverEvent) => boolean
214
+ ```
215
+
216
+ **Returns:** A function that reports whether an event changes the host's hover state.
217
+
218
+ #### `bindWebHover(host, initialHandlers)`
219
+
220
+ Binds shared hover to a DOM element. The bubbling over/out events and the
221
+ direct enter/leave events use the same transition. Moving between a host's
222
+ descendants leaves its hover state alone.
223
+
224
+ ```typescript
225
+ function bindWebHover(
226
+ host: HTMLElement | SVGElement,
227
+ initialHandlers?: WebHoverHandlers,
228
+ ): WebHoverBinding
229
+ ```
230
+
231
+ - `host` — The HTML or SVG element that receives hover.
232
+ - `initialHandlers` — The callbacks to use until the first update.
130
233
 
131
234
  **Returns:** The binding to update or destroy with the host.
132
235
 
236
+ #### `bindWebWheelZoom(host, initialStep)`
237
+
238
+ Listens non-passively for Ctrl-wheel with a finite, nonzero vertical delta.
239
+ The handled event is consumed so the browser leaves page zoom alone.
240
+
241
+ ```typescript
242
+ function bindWebWheelZoom(
243
+ host: Partial<EventTarget>,
244
+ initialStep?: WebWheelZoomHandler,
245
+ ): WebWheelZoomBinding
246
+ ```
247
+
248
+ - `host` — The surface receiving wheel events. A handle without DOM listeners is inert.
249
+ - `initialStep` — The zoom callback to use until the first update.
250
+
251
+ **Returns:** The binding to update or destroy with the host.
252
+
253
+ #### `bindWebFocalWheelZoom(host, frame, current)`
254
+
255
+ Binds a non-passive focal wheel listener to a gesture surface.
256
+
257
+ ```typescript
258
+ function bindWebFocalWheelZoom(
259
+ host: Element,
260
+ frame: () => Element,
261
+ current: () => ElementZoom | undefined,
262
+ ): () => void
263
+ ```
264
+
265
+ - `host` — The wheel event host.
266
+ - `frame` — Reads the untransformed outer frame after the host mounts.
267
+ - `current` — Reads the enabled zoom callback when the surface is free to accept a wheel.
268
+
269
+ **Returns:** Removes the wheel listener.
270
+
133
271
  ## Injection Notes
134
272
 
135
273
  ### Requirements
136
274
 
137
275
  Peer dependencies:
138
276
 
139
- - `@molecule/app-ui` ^1.9.0
277
+ - `@molecule/app-ui` ^1.16.0
140
278
 
141
279
  ### Runtime Dependencies
142
280
 
package/dist/index.d.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  /**
2
- * DOM pointer drag gestures for the Molecule web UI kits.
2
+ * Shared DOM drag, hover, and focal zoom gestures for the Molecule web UI kits.
3
3
  *
4
- * Use the renderer's drag binding with `ElementDrag` from `@molecule/app-ui`.
4
+ * Use the renderer's drag binding with `ElementDrag` or pass `{ drag, zoom }` from
5
+ * `@molecule/app-ui` on a surface with focal wheel zoom and two-finger pinch.
5
6
  * All web kits share press ownership, pointer capture, touch intent, and
6
7
  * cancellation on pointer cancel, lost capture, window blur, and host removal.
7
8
  * Use `markPressTarget` for custom controls that must keep their own presses.
9
+ * Use `bindWebHover` for one mouse or pen transition per boundary and
10
+ * `bindWebWheelZoom` to handle Ctrl-wheel steps on a surface.
8
11
  *
9
12
  * @example
10
13
  * ```ts
@@ -20,4 +23,6 @@
20
23
  * @module
21
24
  */
22
25
  export * from './web-drag.js';
26
+ export * from './web-hover.js';
27
+ export * from './web-wheel-zoom.js';
23
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA"}
package/dist/index.js CHANGED
@@ -1,10 +1,13 @@
1
1
  /**
2
- * DOM pointer drag gestures for the Molecule web UI kits.
2
+ * Shared DOM drag, hover, and focal zoom gestures for the Molecule web UI kits.
3
3
  *
4
- * Use the renderer's drag binding with `ElementDrag` from `@molecule/app-ui`.
4
+ * Use the renderer's drag binding with `ElementDrag` or pass `{ drag, zoom }` from
5
+ * `@molecule/app-ui` on a surface with focal wheel zoom and two-finger pinch.
5
6
  * All web kits share press ownership, pointer capture, touch intent, and
6
7
  * cancellation on pointer cancel, lost capture, window blur, and host removal.
7
8
  * Use `markPressTarget` for custom controls that must keep their own presses.
9
+ * Use `bindWebHover` for one mouse or pen transition per boundary and
10
+ * `bindWebWheelZoom` to handle Ctrl-wheel steps on a surface.
8
11
  *
9
12
  * @example
10
13
  * ```ts
@@ -20,4 +23,6 @@
20
23
  * @module
21
24
  */
22
25
  export * from './web-drag.js';
26
+ export * from './web-hover.js';
27
+ export * from './web-wheel-zoom.js';
23
28
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,eAAe,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA"}
@@ -1,4 +1,7 @@
1
- import type { ElementDrag } from '@molecule/app-ui';
1
+ import type { ElementDrag, ElementDragProps } from '@molecule/app-ui';
2
+ type DragHost = HTMLElement | SVGElement;
3
+ /** Accepts a standalone drag or the element's combined drag and zoom options. */
4
+ export type WebDragOptions = ElementDrag | ElementDragProps;
2
5
  /**
3
6
  * Marks a custom press target so an enclosing drag leaves its activation alone.
4
7
  *
@@ -10,9 +13,15 @@ export interface WebDrag {
10
13
  /**
11
14
  * Updates the callbacks used by the gesture. Removing the handlers cancels the contact.
12
15
  *
13
- * @param drag - The current handlers, or undefined to disable dragging.
16
+ * @param options - The current handlers, or undefined to disable the surface.
14
17
  */
15
- update(drag: ElementDrag | undefined): void;
18
+ update(options: WebDragOptions | undefined): void;
19
+ /**
20
+ * Attaches touch reservation and focal wheel input to the current host.
21
+ *
22
+ * @param host - The host receiving wheel events, or null on detach.
23
+ */
24
+ attach(host: DragHost | null): void;
16
25
  /**
17
26
  * Offers a pointer press to this host.
18
27
  *
@@ -22,24 +31,24 @@ export interface WebDrag {
22
31
  * @param target - The renderer's normalized target, when it differs from the native target.
23
32
  */
24
33
  start(host: HTMLElement | SVGElement, down: PointerEvent, drag?: ElementDrag, target?: EventTarget | null): void;
25
- /** Cancels the active contact, if any. */
34
+ /** Cancels the active input, if any. */
26
35
  cancel(): void;
27
36
  }
28
37
  /**
29
38
  * Acquires a press on the deepest drag host and follows its pointer until release or interruption.
30
39
  *
31
- * @param initialDrag - The initial handlers, if the host starts enabled.
40
+ * @param initial - The initial handlers, if the host starts enabled.
32
41
  * @returns The controls a renderer uses to handle pointerdown, updates and unmount.
33
42
  */
34
- export declare function createWebDrag(initialDrag?: ElementDrag): WebDrag;
43
+ export declare function createWebDrag(initial?: WebDragOptions): WebDrag;
35
44
  /** The lifecycle of a drag attached to a DOM element. */
36
45
  export interface WebDragBinding {
37
46
  /**
38
47
  * Updates the handlers for this host.
39
48
  *
40
- * @param drag - The current handlers, or undefined to disable dragging.
49
+ * @param options - The current handlers, or undefined to disable the surface.
41
50
  */
42
- update(drag: ElementDrag | undefined): void;
51
+ update(options: WebDragOptions | undefined): void;
43
52
  /** Removes the pointer listener and cancels any active contact. */
44
53
  destroy(): void;
45
54
  }
@@ -47,8 +56,9 @@ export interface WebDragBinding {
47
56
  * Binds a drag to a native bubbling pointerdown listener.
48
57
  *
49
58
  * @param host - The element that can own the press.
50
- * @param drag - The initial handlers, if the host starts enabled.
59
+ * @param options - The initial handlers, if the host starts enabled.
51
60
  * @returns The binding to update or destroy with the host.
52
61
  */
53
- export declare function bindWebDrag(host: HTMLElement | SVGElement, drag?: ElementDrag): WebDragBinding;
62
+ export declare function bindWebDrag(host: DragHost, options?: WebDragOptions): WebDragBinding;
63
+ export {};
54
64
  //# sourceMappingURL=web-drag.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"web-drag.d.ts","sourceRoot":"","sources":["../src/web-drag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,kBAAkB,CAAA;AAQrE;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAEnD;AA6CD,sDAAsD;AACtD,MAAM,WAAW,OAAO;IACtB;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAAA;IAC3C;;;;;;;OAOG;IACH,KAAK,CACH,IAAI,EAAE,WAAW,GAAG,UAAU,EAC9B,IAAI,EAAE,YAAY,EAClB,IAAI,CAAC,EAAE,WAAW,EAClB,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,GAC1B,IAAI,CAAA;IACP,0CAA0C;IAC1C,MAAM,IAAI,IAAI,CAAA;CACf;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,WAAW,CAAC,EAAE,WAAW,GAAG,OAAO,CAgJhE;AAED,yDAAyD;AACzD,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAAA;IAC3C,mEAAmE;IACnE,OAAO,IAAI,IAAI,CAAA;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,UAAU,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,cAAc,CAY9F"}
1
+ {"version":3,"file":"web-drag.d.ts","sourceRoot":"","sources":["../src/web-drag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAoB,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAKvF,KAAK,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAA;AAExC,iFAAiF;AACjF,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,gBAAgB,CAAA;AAQ3D;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAEnD;AA4DD,sDAAsD;AACtD,MAAM,WAAW,OAAO;IACtB;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI,CAAA;IACjD;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAA;IACnC;;;;;;;OAOG;IACH,KAAK,CACH,IAAI,EAAE,WAAW,GAAG,UAAU,EAC9B,IAAI,EAAE,YAAY,EAClB,IAAI,CAAC,EAAE,WAAW,EAClB,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,GAC1B,IAAI,CAAA;IACP,wCAAwC;IACxC,MAAM,IAAI,IAAI,CAAA;CACf;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAoO/D;AAED,yDAAyD;AACzD,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI,CAAA;IACjD,mEAAmE;IACnE,OAAO,IAAI,IAAI,CAAA;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,cAAc,CAapF"}
package/dist/web-drag.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { trackWebPinch } from './web-pinch.js';
2
+ import { bindWebFocalWheelZoom } from './web-wheel-zoom.js';
1
3
  const claimed = new WeakSet();
2
4
  const pressTargets = new WeakSet();
3
5
  const controls = 'button, input, textarea, select, label, a[href], [role="button"], [role="link"]';
@@ -42,15 +44,47 @@ function point(viewport, down, { clientX, clientY, altKey, ctrlKey, metaKey, shi
42
44
  shiftKey,
43
45
  };
44
46
  }
47
+ /** Uses the SVG viewport rather than the bounds of a transformed group. */
48
+ function viewportFor(host) {
49
+ return host.localName === 'g' && 'ownerSVGElement' in host ? (host.ownerSVGElement ?? host) : host;
50
+ }
51
+ /** Normalizes the original drag-only binding and the combined gesture options. */
52
+ function surfaceOptions(options) {
53
+ return options && 'onStart' in options ? { drag: options } : (options ?? {});
54
+ }
45
55
  /**
46
56
  * Acquires a press on the deepest drag host and follows its pointer until release or interruption.
47
57
  *
48
- * @param initialDrag - The initial handlers, if the host starts enabled.
58
+ * @param initial - The initial handlers, if the host starts enabled.
49
59
  * @returns The controls a renderer uses to handle pointerdown, updates and unmount.
50
60
  */
51
- export function createWebDrag(initialDrag) {
52
- let handlers = initialDrag;
61
+ export function createWebDrag(initial) {
62
+ let { drag: handlers, zoom } = surfaceOptions(initial);
53
63
  let active = null;
64
+ let touch = null;
65
+ let attached = null;
66
+ let detachZoom;
67
+ /** Reserves touch input and installs focal wheel handling on the attached host. */
68
+ function attachZoom() {
69
+ if (!attached || !zoom || detachZoom)
70
+ return;
71
+ const host = attached;
72
+ const previous = host.style.touchAction;
73
+ // The touch-action decision is made at pointer down, before a second contact can register.
74
+ host.style.touchAction = 'none';
75
+ const removeWheel = bindWebFocalWheelZoom(host, () => viewportFor(host), () => (active || touch ? undefined : zoom));
76
+ detachZoom = () => {
77
+ removeWheel();
78
+ if (host.style.touchAction === 'none')
79
+ host.style.touchAction = previous ?? '';
80
+ detachZoom = undefined;
81
+ };
82
+ }
83
+ /** Closes both the contact tracker and any acquired drag. */
84
+ function cancel() {
85
+ touch?.cancel();
86
+ active?.cancel();
87
+ }
54
88
  /**
55
89
  * Claims the press and starts tracking the owning pointer.
56
90
  *
@@ -60,40 +94,78 @@ export function createWebDrag(initialDrag) {
60
94
  * @param target - The element the press hit.
61
95
  */
62
96
  function start(host, down, drag = handlers, target = down.target) {
63
- if (!drag)
97
+ if (!drag && !zoom)
64
98
  return;
65
99
  if (down.button !== undefined && down.button !== 0)
66
100
  return;
67
- // A pointer event can lack a device type when dispatched through a mouse-only host.
68
- if (down.pointerType && down.isPrimary === false)
69
- return;
70
101
  if (claimed.has(down) || insideControl(host, target))
71
102
  return;
72
103
  const ownerWindow = host.ownerDocument.defaultView;
73
104
  if (!ownerWindow)
74
105
  return;
106
+ if (down.pointerType === 'touch' && zoom) {
107
+ // A second finger cannot acquire a surface whose first contact belongs elsewhere.
108
+ if (!touch) {
109
+ if (down.isPrimary === false || active)
110
+ return;
111
+ touch = trackWebPinch(viewportFor(host), ownerWindow, {
112
+ takeOver: () => active?.takeOver(),
113
+ resume(remaining, event) {
114
+ if (handlers)
115
+ beginDrag(host, ownerWindow, remaining, handlers, true, true).move(event);
116
+ },
117
+ zoom: (sample) => zoom?.onZoom(sample),
118
+ close(cancelDrag) {
119
+ touch = null;
120
+ if (cancelDrag)
121
+ active?.cancel();
122
+ },
123
+ });
124
+ claimed.add(down);
125
+ touch.add(down);
126
+ if (drag)
127
+ beginDrag(host, ownerWindow, down, drag, true);
128
+ }
129
+ else {
130
+ claimed.add(down);
131
+ touch.add(down);
132
+ }
133
+ return;
134
+ }
135
+ if (!drag || touch || (down.pointerType && down.isPrimary === false))
136
+ return;
75
137
  claimed.add(down);
76
- const { pointerId } = down;
77
138
  // A down for the same pointer after a lost terminal event starts a new contact.
78
- if (active && active.pointerId !== pointerId)
139
+ if (active && active.pointerId !== down.pointerId)
79
140
  return;
80
141
  active?.cancel();
81
- const viewport = host.localName === 'g' && 'ownerSVGElement' in host ? (host.ownerSVGElement ?? host) : host;
142
+ beginDrag(host, ownerWindow, down, drag, false);
143
+ }
144
+ /** Starts a drag at the original contact or the surviving contact after a pinch. */
145
+ function beginDrag(host, ownerWindow, down, drag, ownsTouch, resumed = false) {
146
+ const { pointerId } = down;
147
+ const viewport = viewportFor(host);
82
148
  const touch = down.pointerType === 'touch';
83
- const longPress = touch && drag.touchStart === 'longPress';
149
+ const longPress = touch && !resumed && drag.touchStart === 'longPress';
84
150
  let timer;
85
151
  let last;
86
152
  let captured = false;
87
153
  let axisChosen = longPress ||
88
154
  (drag.axis !== 'horizontal' && drag.axis !== 'vertical') ||
89
- (touch && ownerWindow.getComputedStyle(host).touchAction === 'none');
90
- const session = { pointerId, cancel: () => finish() };
155
+ (touch && (ownsTouch || ownerWindow.getComputedStyle(host).touchAction === 'none'));
156
+ const session = {
157
+ pointerId,
158
+ move,
159
+ cancel: () => finish(),
160
+ takeOver: () => finish(undefined, true),
161
+ };
91
162
  active = session;
92
163
  /** Captures the contact when supported and delivers the first sample. */
93
164
  function acquire() {
94
165
  if (active !== session)
95
166
  return;
96
- if (host.setPointerCapture && Number.isFinite(pointerId)) {
167
+ // Touch pointers on zoom surfaces already have implicit capture. Keep it through takeover.
168
+ if (!ownsTouch && host.setPointerCapture && Number.isFinite(pointerId)) {
97
169
  try {
98
170
  host.setPointerCapture(pointerId);
99
171
  captured = true;
@@ -116,11 +188,11 @@ export function createWebDrag(initialDrag) {
116
188
  if (!last)
117
189
  return true;
118
190
  axisChosen = true;
119
- return drag?.axis === 'horizontal' ? dy > dx : dx > dy;
191
+ return drag.axis === 'horizontal' ? dy > dx : dx > dy;
120
192
  }
121
193
  /** Delivers movement from the owned pointer after scroll negotiation. */
122
194
  function move(sample) {
123
- if (sample.pointerId !== pointerId)
195
+ if (active !== session || sample.pointerId !== pointerId)
124
196
  return;
125
197
  if (shouldYield(sample.clientX, sample.clientY))
126
198
  finish();
@@ -151,7 +223,7 @@ export function createWebDrag(initialDrag) {
151
223
  finish();
152
224
  }
153
225
  /** Removes the active subscriptions before the single terminal callback. */
154
- function finish(released) {
226
+ function finish(released, takenOver = false) {
155
227
  if (active !== session)
156
228
  return;
157
229
  active = null;
@@ -174,6 +246,8 @@ export function createWebDrag(initialDrag) {
174
246
  return;
175
247
  if (released)
176
248
  handlers?.onEnd?.(point(viewport, down, released));
249
+ else if (takenOver)
250
+ (handlers?.onCancel ?? handlers?.onEnd)?.(last);
177
251
  else
178
252
  handlers?.onCancel?.(last);
179
253
  }
@@ -183,34 +257,49 @@ export function createWebDrag(initialDrag) {
183
257
  ownerWindow.addEventListener('pointercancel', cancel, true);
184
258
  ownerWindow.addEventListener('blur', session.cancel);
185
259
  host.addEventListener('lostpointercapture', cancel);
186
- if (touch)
260
+ if (touch && !ownsTouch)
187
261
  ownerWindow.addEventListener('touchmove', preventScroll, { passive: false });
188
262
  if (longPress)
189
263
  timer = setTimeout(acquire, LONG_PRESS_MS);
190
264
  else
191
265
  acquire();
266
+ return session;
192
267
  }
193
268
  return {
194
269
  start,
195
- update(drag) {
196
- if (!drag)
270
+ update(options) {
271
+ const next = surfaceOptions(options);
272
+ if (zoom && !next.zoom) {
273
+ touch?.cancel();
274
+ detachZoom?.();
275
+ }
276
+ if (!next.drag)
197
277
  active?.cancel();
198
- handlers = drag;
278
+ handlers = next.drag;
279
+ zoom = next.zoom;
280
+ attachZoom();
199
281
  },
200
- cancel() {
201
- active?.cancel();
282
+ attach(host) {
283
+ if (attached === host)
284
+ return;
285
+ cancel();
286
+ detachZoom?.();
287
+ attached = host;
288
+ attachZoom();
202
289
  },
290
+ cancel,
203
291
  };
204
292
  }
205
293
  /**
206
294
  * Binds a drag to a native bubbling pointerdown listener.
207
295
  *
208
296
  * @param host - The element that can own the press.
209
- * @param drag - The initial handlers, if the host starts enabled.
297
+ * @param options - The initial handlers, if the host starts enabled.
210
298
  * @returns The binding to update or destroy with the host.
211
299
  */
212
- export function bindWebDrag(host, drag) {
213
- const gesture = createWebDrag(drag);
300
+ export function bindWebDrag(host, options) {
301
+ const gesture = createWebDrag(options);
302
+ gesture.attach(host);
214
303
  const target = host;
215
304
  const pointerDown = (event) => gesture.start(host, event);
216
305
  target.addEventListener('pointerdown', pointerDown);
@@ -218,7 +307,7 @@ export function bindWebDrag(host, drag) {
218
307
  update: gesture.update,
219
308
  destroy() {
220
309
  target.removeEventListener('pointerdown', pointerDown);
221
- gesture.cancel();
310
+ gesture.attach(null);
222
311
  },
223
312
  };
224
313
  }
@@ -1 +1 @@
1
- {"version":3,"file":"web-drag.js","sourceRoot":"","sources":["../src/web-drag.ts"],"names":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E,EAAE,CAAA;YAChB,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,IAAI;gBAAE,MAAM,EAAE,MAAM,EAAE,CAAA;YAChC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAA;YACpB,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;YAChB,UAAU,EAAE,CAAA;QACd,CAAC;QACD,MAAM,CAAC,IAAI;YACT,IAAI,QAAQ,KAAK,IAAI;gBAAE,OAAM;YAC7B,MAAM,EAAE,CAAA;YACR,UAAU,EAAE,EAAE,CAAA;YACd,QAAQ,GAAG,IAAI,CAAA;YACf,UAAU,EAAE,CAAA;QACd,CAAC;QACD,MAAM;KACP,CAAA;AACH,CAAC;AAcD;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,IAAc,EAAE,OAAwB;IAClE,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;IACtC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACpB,MAAM,MAAM,GAAwB,IAAI,CAAA;IACxC,MAAM,WAAW,GAAG,CAAC,KAAmB,EAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAC7E,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,WAAW,CAAC,CAAA;IACnD,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,OAAO;YACL,MAAM,CAAC,mBAAmB,CAAC,aAAa,EAAE,WAAW,CAAC,CAAA;YACtD,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACtB,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,42 @@
1
+ /** The fields needed to distinguish pointer and compatibility mouse events. */
2
+ interface HoverEvent {
3
+ readonly type: string;
4
+ readonly pointerType?: string;
5
+ }
6
+ /**
7
+ * Creates one enter/leave transition for a host. Touch and its compatibility
8
+ * mouse events never hover. A later mouse or pen pointer resumes hover.
9
+ *
10
+ * @returns A function that reports whether an event changes the host's hover state.
11
+ */
12
+ export declare function createWebHover(): (entered: boolean, event: HoverEvent) => boolean;
13
+ /** Callbacks for the shared hover transition. */
14
+ export interface WebHoverHandlers {
15
+ /** Runs when a mouse or pen enters the host. */
16
+ onEnter?: (event: MouseEvent) => void;
17
+ /** Runs when the hovering mouse or pen leaves the host. */
18
+ onLeave?: (event: MouseEvent) => void;
19
+ }
20
+ /** The lifecycle of a hover attached to a DOM element. */
21
+ export interface WebHoverBinding {
22
+ /**
23
+ * Updates the callbacks. Pass undefined to disable hover.
24
+ *
25
+ * @param handlers - The current hover callbacks.
26
+ */
27
+ update(handlers: WebHoverHandlers | undefined): void;
28
+ /** Removes the event listeners. */
29
+ destroy(): void;
30
+ }
31
+ /**
32
+ * Binds shared hover to a DOM element. The bubbling over/out events and the
33
+ * direct enter/leave events use the same transition. Moving between a host's
34
+ * descendants leaves its hover state alone.
35
+ *
36
+ * @param host - The HTML or SVG element that receives hover.
37
+ * @param initialHandlers - The callbacks to use until the first update.
38
+ * @returns The binding to update or destroy with the host.
39
+ */
40
+ export declare function bindWebHover(host: HTMLElement | SVGElement, initialHandlers?: WebHoverHandlers): WebHoverBinding;
41
+ export {};
42
+ //# sourceMappingURL=web-hover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-hover.d.ts","sourceRoot":"","sources":["../src/web-hover.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,UAAU,UAAU;IAClB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,KAAK,OAAO,CAejF;AAED,iDAAiD;AACjD,MAAM,WAAW,gBAAgB;IAC/B,gDAAgD;IAChD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;IACrC,2DAA2D;IAC3D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;CACtC;AAED,0DAA0D;AAC1D,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,MAAM,CAAC,QAAQ,EAAE,gBAAgB,GAAG,SAAS,GAAG,IAAI,CAAA;IACpD,mCAAmC;IACnC,OAAO,IAAI,IAAI,CAAA;CAChB;AAeD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,WAAW,GAAG,UAAU,EAC9B,eAAe,CAAC,EAAE,gBAAgB,GACjC,eAAe,CAuCjB"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Creates one enter/leave transition for a host. Touch and its compatibility
3
+ * mouse events never hover. A later mouse or pen pointer resumes hover.
4
+ *
5
+ * @returns A function that reports whether an event changes the host's hover state.
6
+ */
7
+ export function createWebHover() {
8
+ let inside = false;
9
+ let fromTouch = false;
10
+ return (entered, event) => {
11
+ if ('pointerType' in event || event.type.startsWith('pointer')) {
12
+ fromTouch = event.pointerType === 'touch';
13
+ if (fromTouch)
14
+ return false;
15
+ }
16
+ else if (fromTouch) {
17
+ return false;
18
+ }
19
+ if (inside === entered)
20
+ return false;
21
+ inside = entered;
22
+ return true;
23
+ };
24
+ }
25
+ const enterEvents = [
26
+ 'pointerover',
27
+ 'pointerenter',
28
+ 'mouseover',
29
+ 'mouseenter',
30
+ ];
31
+ const leaveEvents = [
32
+ 'pointerout',
33
+ 'pointerleave',
34
+ 'mouseout',
35
+ 'mouseleave',
36
+ ];
37
+ /**
38
+ * Binds shared hover to a DOM element. The bubbling over/out events and the
39
+ * direct enter/leave events use the same transition. Moving between a host's
40
+ * descendants leaves its hover state alone.
41
+ *
42
+ * @param host - The HTML or SVG element that receives hover.
43
+ * @param initialHandlers - The callbacks to use until the first update.
44
+ * @returns The binding to update or destroy with the host.
45
+ */
46
+ export function bindWebHover(host, initialHandlers) {
47
+ const target = host;
48
+ const transition = createWebHover();
49
+ let handlers;
50
+ const route = (entered) => (event) => {
51
+ const Node = host.ownerDocument.defaultView?.Node;
52
+ if (Node && event.relatedTarget instanceof Node && host.contains(event.relatedTarget))
53
+ return;
54
+ if (!transition(entered, event))
55
+ return;
56
+ if (entered)
57
+ handlers?.onEnter?.(event);
58
+ else
59
+ handlers?.onLeave?.(event);
60
+ };
61
+ const enter = route(true);
62
+ const leave = route(false);
63
+ /**
64
+ * Updates the callbacks and subscribes only while at least one is active.
65
+ *
66
+ * @param next - The current callbacks.
67
+ */
68
+ function update(next) {
69
+ const wasEnabled = Boolean(handlers?.onEnter || handlers?.onLeave);
70
+ const enabled = Boolean(next?.onEnter || next?.onLeave);
71
+ handlers = next;
72
+ if (enabled === wasEnabled)
73
+ return;
74
+ if (enabled) {
75
+ for (const type of enterEvents)
76
+ target.addEventListener(type, enter);
77
+ for (const type of leaveEvents)
78
+ target.addEventListener(type, leave);
79
+ }
80
+ else {
81
+ for (const type of enterEvents)
82
+ target.removeEventListener(type, enter);
83
+ for (const type of leaveEvents)
84
+ target.removeEventListener(type, leave);
85
+ }
86
+ }
87
+ update(initialHandlers);
88
+ return { update, destroy: () => update(undefined) };
89
+ }
90
+ //# sourceMappingURL=web-hover.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-hover.js","sourceRoot":"","sources":["../src/web-hover.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,MAAM,UAAU,cAAc;IAC5B,IAAI,MAAM,GAAG,KAAK,CAAA;IAClB,IAAI,SAAS,GAAG,KAAK,CAAA;IAErB,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;QACxB,IAAI,aAAa,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAC/D,SAAS,GAAG,KAAK,CAAC,WAAW,KAAK,OAAO,CAAA;YACzC,IAAI,SAAS;gBAAE,OAAO,KAAK,CAAA;QAC7B,CAAC;aAAM,IAAI,SAAS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QAAQ,EAAE,OAAO,CAAC,CAAA;QAClE,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,OAAO,IAAI,IAAI,EAAE,OAAO,CAAC,CAAA;QACvD,QAAQ,GAAG,IAAI,CAAA;QACf,IAAI,OAAO,KAAK,UAAU;YAAE,OAAM;QAElC,IAAI,OAAO,EAAE,CAAC;YACZ,KAAK,MAAM,IAAI,IAAI,WAAW;gBAAE,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YACpE,KAAK,MAAM,IAAI,IAAI,WAAW;gBAAE,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QACtE,CAAC;aAAM,CAAC;YACN,KAAK,MAAM,IAAI,IAAI,WAAW;gBAAE,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YACvE,KAAK,MAAM,IAAI,IAAI,WAAW;gBAAE,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QACzE,CAAC;IACH,CAAC;IAED,MAAM,CAAC,eAAe,CAAC,CAAA;IACvB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAA;AACrD,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { ElementZoomSample } from '@molecule/app-ui';
2
+ type PinchSample = Extract<ElementZoomSample, {
3
+ kind: 'pinch';
4
+ }>;
5
+ /**
6
+ * Tracks the first two accepted contacts in insertion order.
7
+ *
8
+ * @param frame - The untransformed outer frame.
9
+ * @param owner - The window that receives captured movement and termination.
10
+ * @param callbacks - Ownership transitions and incremental pinch samples.
11
+ * @returns Adds accepted presses or cancels the touch sequence.
12
+ */
13
+ export declare function trackWebPinch(frame: Element, owner: Window, callbacks: {
14
+ takeOver(): void;
15
+ resume(remaining: PointerEvent, event: PointerEvent): void;
16
+ zoom(sample: PinchSample): void;
17
+ close(cancelDrag: boolean): void;
18
+ }): {
19
+ add(event: PointerEvent): void;
20
+ cancel(): void;
21
+ };
22
+ export {};
23
+ //# sourceMappingURL=web-pinch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-pinch.d.ts","sourceRoot":"","sources":["../src/web-pinch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAE3E,KAAK,WAAW,GAAG,OAAO,CAAC,iBAAiB,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAA;AAGhE;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,EACb,SAAS,EAAE;IACT,QAAQ,IAAI,IAAI,CAAA;IAChB,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,CAAA;IAC1D,IAAI,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;IAC/B,KAAK,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAAA;CACjC,GACA;IAAE,GAAG,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IAAC,MAAM,IAAI,IAAI,CAAA;CAAE,CA6FpD"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Tracks the first two accepted contacts in insertion order.
3
+ *
4
+ * @param frame - The untransformed outer frame.
5
+ * @param owner - The window that receives captured movement and termination.
6
+ * @param callbacks - Ownership transitions and incremental pinch samples.
7
+ * @returns Adds accepted presses or cancels the touch sequence.
8
+ */
9
+ export function trackWebPinch(frame, owner, callbacks) {
10
+ const contacts = new Map();
11
+ let previous;
12
+ let rebased;
13
+ /** Measures the pair in the current outer frame. */
14
+ function measure(first, second) {
15
+ const { left, top } = frame.getBoundingClientRect();
16
+ return {
17
+ at: {
18
+ x: (first.clientX + second.clientX) / 2 - left,
19
+ y: (first.clientY + second.clientY) / 2 - top,
20
+ },
21
+ distance: Math.hypot(first.clientX - second.clientX, first.clientY - second.clientY),
22
+ };
23
+ }
24
+ /** Delivers pair movement or resumes the rebased drag. */
25
+ function move(event) {
26
+ if (!contacts.has(event.pointerId))
27
+ return;
28
+ contacts.set(event.pointerId, event);
29
+ const [first, second] = contacts.values();
30
+ if (!second && rebased) {
31
+ const origin = rebased;
32
+ rebased = undefined;
33
+ callbacks.resume(origin, event);
34
+ }
35
+ if (!first || !second || (event !== first && event !== second))
36
+ return;
37
+ const next = measure(first, second);
38
+ const from = previous;
39
+ previous = next;
40
+ if (!from || !(from.distance > 0) || !(next.distance > 0))
41
+ return;
42
+ const factor = next.distance / from.distance;
43
+ if (factor !== 1 || from.at.x !== next.at.x || from.at.y !== next.at.y) {
44
+ callbacks.zoom({ kind: 'pinch', from: from.at, at: next.at, factor });
45
+ }
46
+ }
47
+ /** Rebases only when a member of the owned pair lifts. */
48
+ function up(event) {
49
+ const [first, second] = contacts.values();
50
+ if (!contacts.delete(event.pointerId))
51
+ return;
52
+ const [remaining, substitute] = contacts.values();
53
+ if (!remaining)
54
+ finish(false);
55
+ else if (second &&
56
+ (first?.pointerId === event.pointerId || second.pointerId === event.pointerId)) {
57
+ previous = substitute ? measure(remaining, substitute) : undefined;
58
+ rebased = substitute ? undefined : remaining;
59
+ }
60
+ }
61
+ /** Interrupts the sequence if the browser cancels an owned contact. */
62
+ function interrupt(event) {
63
+ if (contacts.has(event.pointerId))
64
+ finish(true);
65
+ }
66
+ /** Cancels the touch sequence through the owner. */
67
+ function cancel() {
68
+ finish(true);
69
+ }
70
+ /** Removes all observers before notifying the owner. */
71
+ function finish(cancelDrag) {
72
+ contacts.clear();
73
+ owner.removeEventListener('pointermove', move, true);
74
+ owner.removeEventListener('pointerup', up, true);
75
+ owner.removeEventListener('pointercancel', interrupt, true);
76
+ owner.removeEventListener('lostpointercapture', interrupt, true);
77
+ owner.removeEventListener('blur', cancel);
78
+ callbacks.close(cancelDrag);
79
+ }
80
+ owner.addEventListener('pointermove', move, true);
81
+ owner.addEventListener('pointerup', up, true);
82
+ owner.addEventListener('pointercancel', interrupt, true);
83
+ owner.addEventListener('lostpointercapture', interrupt, true);
84
+ owner.addEventListener('blur', cancel);
85
+ return {
86
+ add(event) {
87
+ if (contacts.has(event.pointerId))
88
+ return;
89
+ contacts.set(event.pointerId, event);
90
+ if (contacts.size !== 2)
91
+ return;
92
+ const [first, second] = contacts.values();
93
+ if (!first || !second)
94
+ return;
95
+ previous = measure(first, second);
96
+ rebased = undefined;
97
+ callbacks.takeOver();
98
+ },
99
+ cancel,
100
+ };
101
+ }
102
+ //# sourceMappingURL=web-pinch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-pinch.js","sourceRoot":"","sources":["../src/web-pinch.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAC3B,KAAc,EACd,KAAa,EACb,SAKC;IAED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAA;IAChD,IAAI,QAA0B,CAAA;IAC9B,IAAI,OAAiC,CAAA;IAErC,oDAAoD;IACpD,SAAS,OAAO,CAAC,KAAmB,EAAE,MAAoB;QACxD,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,qBAAqB,EAAE,CAAA;QACnD,OAAO;YACL,EAAE,EAAE;gBACF,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI;gBAC9C,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG;aAC9C;YACD,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;SACrF,CAAA;IACH,CAAC;IAED,0DAA0D;IAC1D,SAAS,IAAI,CAAC,KA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
+ export type WebWheelZoomHandler = (direction: 'in' | 'out') => void;
4
+ /** The lifecycle of the Ctrl-wheel shortcut on a surface. */
5
+ export interface WebWheelZoomBinding {
6
+ /**
7
+ * Updates the callback. Pass undefined to leave wheel input to the browser.
8
+ *
9
+ * @param onStep - The current zoom callback.
10
+ */
11
+ update(onStep: WebWheelZoomHandler | undefined): void;
12
+ /** Removes the wheel listener. */
13
+ destroy(): void;
14
+ }
15
+ /**
16
+ * Listens non-passively for Ctrl-wheel with a finite, nonzero vertical delta.
17
+ * The handled event is consumed so the browser leaves page zoom alone.
18
+ *
19
+ * @param host - The surface receiving wheel events. A handle without DOM listeners is inert.
20
+ * @param initialStep - The zoom callback to use until the first update.
21
+ * @returns The binding to update or destroy with the host.
22
+ */
23
+ export declare function bindWebWheelZoom(host: Partial<EventTarget>, initialStep?: WebWheelZoomHandler): WebWheelZoomBinding;
24
+ /**
25
+ * Binds a non-passive focal wheel listener to a gesture surface.
26
+ *
27
+ * @param host - The wheel event host.
28
+ * @param frame - Reads the untransformed outer frame after the host mounts.
29
+ * @param current - Reads the enabled zoom callback when the surface is free to accept a wheel.
30
+ * @returns Removes the wheel listener.
31
+ */
32
+ export declare function bindWebFocalWheelZoom(host: Element, frame: () => Element, current: () => ElementZoom | undefined): () => void;
33
+ //# sourceMappingURL=web-wheel-zoom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-wheel-zoom.d.ts","sourceRoot":"","sources":["../src/web-wheel-zoom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAqB,MAAM,kBAAkB,CAAA;AAItE,wDAAwD;AACxD,MAAM,MAAM,mBAAmB,GAAG,CAAC,SAAS,EAAE,IAAI,GAAG,KAAK,KAAK,IAAI,CAAA;AAEnE,6DAA6D;AAC7D,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,SAAS,GAAG,IAAI,CAAA;IACrD,kCAAkC;IAClC,OAAO,IAAI,IAAI,CAAA;CAChB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,EAC1B,WAAW,CAAC,EAAE,mBAAmB,GAChC,mBAAmB,CAmCrB;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,MAAM,OAAO,EACpB,OAAO,EAAE,MAAM,WAAW,GAAG,SAAS,GACrC,MAAM,IAAI,CAqCZ"}
@@ -0,0 +1,87 @@
1
+ const claimed = new WeakSet();
2
+ /**
3
+ * Listens non-passively for Ctrl-wheel with a finite, nonzero vertical delta.
4
+ * The handled event is consumed so the browser leaves page zoom alone.
5
+ *
6
+ * @param host - The surface receiving wheel events. A handle without DOM listeners is inert.
7
+ * @param initialStep - The zoom callback to use until the first update.
8
+ * @returns The binding to update or destroy with the host.
9
+ */
10
+ export function bindWebWheelZoom(host, initialStep) {
11
+ let onStep;
12
+ const wheel = (event) => {
13
+ if (!onStep ||
14
+ claimed.has(event) ||
15
+ event.defaultPrevented ||
16
+ !('ctrlKey' in event) ||
17
+ !event.ctrlKey ||
18
+ !('deltaY' in event))
19
+ return;
20
+ const delta = event.deltaY;
21
+ if (typeof delta !== 'number' || !Number.isFinite(delta) || delta === 0)
22
+ return;
23
+ claimed.add(event);
24
+ event.preventDefault();
25
+ onStep(delta < 0 ? 'in' : 'out');
26
+ };
27
+ /**
28
+ * Updates the callback and attaches or removes the listener when enabled changes.
29
+ *
30
+ * @param next - The current zoom callback.
31
+ */
32
+ function update(next) {
33
+ const wasEnabled = Boolean(onStep);
34
+ onStep = next;
35
+ if (!host.addEventListener || !host.removeEventListener)
36
+ return;
37
+ if (next && !wasEnabled)
38
+ host.addEventListener('wheel', wheel, { passive: false });
39
+ else if (!next && wasEnabled)
40
+ host.removeEventListener('wheel', wheel);
41
+ }
42
+ update(initialStep);
43
+ return { update, destroy: () => update(undefined) };
44
+ }
45
+ /**
46
+ * Binds a non-passive focal wheel listener to a gesture surface.
47
+ *
48
+ * @param host - The wheel event host.
49
+ * @param frame - Reads the untransformed outer frame after the host mounts.
50
+ * @param current - Reads the enabled zoom callback when the surface is free to accept a wheel.
51
+ * @returns Removes the wheel listener.
52
+ */
53
+ export function bindWebFocalWheelZoom(host, frame, current) {
54
+ const wheel = (event) => {
55
+ const Wheel = host.ownerDocument.defaultView?.WheelEvent;
56
+ const zoom = current();
57
+ if (!zoom ||
58
+ !Wheel ||
59
+ zoom.wheel === 'off' ||
60
+ claimed.has(event) ||
61
+ event.defaultPrevented ||
62
+ !(event instanceof Wheel) ||
63
+ (zoom.wheel === 'ctrl' && !event.ctrlKey))
64
+ return;
65
+ // Read the unit before the delta. Some browsers choose compatibility units at access time.
66
+ const { deltaMode, deltaY, clientX, clientY } = event;
67
+ if ((deltaMode !== 0 && deltaMode !== 1 && deltaMode !== 2) ||
68
+ !Number.isFinite(deltaY) ||
69
+ deltaY === 0 ||
70
+ !Number.isFinite(clientX) ||
71
+ !Number.isFinite(clientY))
72
+ return;
73
+ const { left, top } = frame().getBoundingClientRect();
74
+ const sample = {
75
+ kind: 'wheel',
76
+ at: { x: clientX - left, y: clientY - top },
77
+ deltaY,
78
+ deltaMode,
79
+ };
80
+ claimed.add(event);
81
+ event.preventDefault();
82
+ zoom.onZoom(sample);
83
+ };
84
+ host.addEventListener('wheel', wheel, { passive: false });
85
+ return () => host.removeEventListener('wheel', wheel);
86
+ }
87
+ //# sourceMappingURL=web-wheel-zoom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-wheel-zoom.js","sourceRoot":"","sources":["../src/web-wheel-zoom.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAG,IAAI,OAAO,EAAS,CAAA;AAiBpC;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAA0B,EAC1B,WAAiC;IAEjC,IAAI,MAAuC,CAAA;IAE3C,MAAM,KAAK,GAAG,CA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AI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACrB,CAAC,CAAA;IACD,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAA;IACzD,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;AACvD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-pointer-events-dom",
3
- "version": "0.0.1-stage",
3
+ "version": "1.2.0",
4
4
  "description": "DOM pointer event handling shared by Molecule web UI kits",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,10 +28,10 @@
28
28
  "license": "Apache-2.0",
29
29
  "author": "Molecule Dev, Inc. (https://molecule.dev)",
30
30
  "peerDependencies": {
31
- "@molecule/app-ui": "^1.9.0"
31
+ "@molecule/app-ui": "^1.16.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@molecule/app-ui": "1.9.0",
34
+ "@molecule/app-ui": "1.16.0",
35
35
  "@types/node": "26.6.5",
36
36
  "jsdom": "31.0.1",
37
37
  "typescript": "6.0.3",