Skip to content

Commit

Permalink
Merge pull request #28 from rescript-lang/touch-pointer
Browse files Browse the repository at this point in the history
Add PointerEvent and TouchEvent
  • Loading branch information
nojaf authored Dec 6, 2024
2 parents 8ad0d94 + 9947f79 commit 82a7689
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 13 deletions.
6 changes: 2 additions & 4 deletions src/CredentialManagementAPI/CredentialsContainer.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ open CredentialManagementAPI
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CredentialsContainer/get)
*/
@send
external get: (
credentialsContainer,
~options: credentialRequestOptions=?,
) => promise<credential> = "get"
external get: (credentialsContainer, ~options: credentialRequestOptions=?) => promise<credential> =
"get"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/CredentialsContainer/store)
Expand Down
3 changes: 1 addition & 2 deletions src/EncryptedMediaExtensionsAPI/MediaKeys.res
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ external setServerCertificate: (mediaKeys, DataView.t) => promise<bool> = "setSe
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/MediaKeys/setServerCertificate)
*/
@send
external setServerCertificate2: (mediaKeys, ArrayBuffer.t) => promise<bool> =
"setServerCertificate"
external setServerCertificate2: (mediaKeys, ArrayBuffer.t) => promise<bool> = "setServerCertificate"
3 changes: 1 addition & 2 deletions src/FileAPI/FileSystemDirectoryHandle.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ external asFileSystemHandle: fileSystemDirectoryHandle => fileSystemHandle = "%i
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/FileSystemHandle/isSameEntry)
*/
@send
external isSameEntry: (fileSystemDirectoryHandle, fileSystemHandle) => promise<bool> =
"isSameEntry"
external isSameEntry: (fileSystemDirectoryHandle, fileSystemHandle) => promise<bool> = "isSameEntry"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/FileSystemDirectoryHandle/getFileHandle)
Expand Down
205 changes: 205 additions & 0 deletions src/UIEventsAPI.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
open EventAPI
open DOMAPI

type touchType =
| @as("direct") Direct
| @as("stylus") Stylus

/**
Simple user interface events.
[See UIEvent on MDN](https://developer.mozilla.org/docs/Web/API/UIEvent)
Expand Down Expand Up @@ -296,6 +300,164 @@ type wheelEvent = {
deltaMode: int,
}

/**
A single contact point on a touch-sensitive device. The contact point is commonly a finger or stylus and the device may be a touchscreen or trackpad.
[See Touch on MDN](https://developer.mozilla.org/docs/Web/API/Touch)
*/
type touch = {
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/identifier)
*/
identifier: int,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/target)
*/
target: eventTarget,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/screenX)
*/
screenX: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/screenY)
*/
screenY: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/clientX)
*/
clientX: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/clientY)
*/
clientY: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/pageX)
*/
pageX: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/pageY)
*/
pageY: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/radiusX)
*/
radiusX: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/radiusY)
*/
radiusY: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/rotationAngle)
*/
rotationAngle: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch/force)
*/
force: float,
}

/**
A list of contact points on a touch surface. For example, if the user has three fingers on the touch surface (such as a screen or trackpad), the corresponding TouchList object would have one Touch object for each finger, for a total of three entries.
[See TouchList on MDN](https://developer.mozilla.org/docs/Web/API/TouchList)
*/
type touchList = {
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchList/length)
*/
length: int,
}

/**
An event sent when the state of contacts with a touch-sensitive surface changes. This surface can be a touch screen or trackpad, for example. The event can describe one or more points of contact with the screen and includes support for detecting movement, addition and removal of contact points, and so forth.
[See TouchEvent on MDN](https://developer.mozilla.org/docs/Web/API/TouchEvent)
*/
type touchEvent = {
...uiEvent,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchEvent/touches)
*/
touches: touchList,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchEvent/targetTouches)
*/
targetTouches: touchList,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchEvent/changedTouches)
*/
changedTouches: touchList,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchEvent/altKey)
*/
altKey: bool,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchEvent/metaKey)
*/
metaKey: bool,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchEvent/ctrlKey)
*/
ctrlKey: bool,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchEvent/shiftKey)
*/
shiftKey: bool,
}

/**
The state of a DOM event produced by a pointer such as the geometry of the contact point, the device type that generated the event, the amount of pressure that was applied on the contact surface, etc.
[See PointerEvent on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent)
*/
type pointerEvent = {
...mouseEvent,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/pointerId)
*/
pointerId: int,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/width)
*/
width: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/height)
*/
height: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/pressure)
*/
pressure: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/tangentialPressure)
*/
tangentialPressure: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/tiltX)
*/
tiltX: int,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/tiltY)
*/
tiltY: int,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/twist)
*/
twist: int,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/altitudeAngle)
*/
altitudeAngle: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/azimuthAngle)
*/
azimuthAngle: float,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/pointerType)
*/
pointerType: string,
/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/isPrimary)
*/
isPrimary: bool,
}

type uiEventInit = {
...eventInit,
mutable view?: Null.t<window>,
Expand Down Expand Up @@ -371,3 +533,46 @@ type inputEventInit = {
mutable dataTransfer?: Null.t<dataTransfer>,
mutable targetRanges?: array<staticRange>,
}

type touchInit = {
mutable identifier: int,
mutable target: eventTarget,
mutable clientX?: float,
mutable clientY?: float,
mutable screenX?: float,
mutable screenY?: float,
mutable pageX?: float,
mutable pageY?: float,
mutable radiusX?: float,
mutable radiusY?: float,
mutable rotationAngle?: float,
mutable force?: float,
mutable altitudeAngle?: float,
mutable azimuthAngle?: float,
mutable touchType?: touchType,
}

type pointerEventInit = {
...mouseEventInit,
mutable pointerId?: int,
mutable width?: float,
mutable height?: float,
mutable pressure?: float,
mutable tangentialPressure?: float,
mutable tiltX?: int,
mutable tiltY?: int,
mutable twist?: int,
mutable altitudeAngle?: float,
mutable azimuthAngle?: float,
mutable pointerType?: string,
mutable isPrimary?: bool,
mutable coalescedEvents?: array<pointerEvent>,
mutable predictedEvents?: array<pointerEvent>,
}

type touchEventInit = {
...eventModifierInit,
mutable touches?: array<touch>,
mutable targetTouches?: array<touch>,
mutable changedTouches?: array<touch>,
}
7 changes: 7 additions & 0 deletions src/UIEventsAPI/PointerEvent.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions src/UIEventsAPI/PointerEvent.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
open UIEventsAPI

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent)
*/
@new
external make: (~type_: string, ~eventInitDict: pointerEventInit=?) => pointerEvent = "PointerEvent"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/getCoalescedEvents)
*/
@send
external getCoalescedEvents: pointerEvent => array<pointerEvent> = "getCoalescedEvents"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/PointerEvent/getPredictedEvents)
*/
@send
external getPredictedEvents: pointerEvent => array<pointerEvent> = "getPredictedEvents"

include MouseEvent.Impl({
type t = pointerEvent
})
2 changes: 2 additions & 0 deletions src/UIEventsAPI/Touch.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/UIEventsAPI/Touch.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
open UIEventsAPI

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Touch)
*/
@new
external make: touchInit => touch = "Touch"
7 changes: 7 additions & 0 deletions src/UIEventsAPI/TouchEvent.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/UIEventsAPI/TouchEvent.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
open UIEventsAPI

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchEvent)
*/
@new
external make: (~type_: string, ~eventInitDict: touchEventInit=?) => touchEvent = "TouchEvent"

include UIEvent.Impl({
type t = touchEvent
})
2 changes: 2 additions & 0 deletions src/UIEventsAPI/TouchList.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/UIEventsAPI/TouchList.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
open UIEventsAPI

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/TouchList/item)
*/
@send
external item: (touchList, int) => touch = "item"
7 changes: 2 additions & 5 deletions src/WebLocksAPI/LockManager.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ open WebLocksAPI
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/LockManager/request)
*/
@send
external request: (
lockManager,
~name: string,
~callback: lockGrantedCallback,
) => promise<JSON.t> = "request"
external request: (lockManager, ~name: string, ~callback: lockGrantedCallback) => promise<JSON.t> =
"request"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/LockManager/request)
Expand Down

0 comments on commit 82a7689

Please sign in to comment.