@ledgerhq/device-mockserver-react-core 0.0.0-mockserver-rn-20261103093711
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/LICENSE.MD +202 -0
- package/README.md +29 -0
- package/lib/cjs/index.js +2 -0
- package/lib/cjs/index.js.map +7 -0
- package/lib/cjs/package.json +61 -0
- package/lib/cjs/src/deviceModels.js +2 -0
- package/lib/cjs/src/deviceModels.js.map +7 -0
- package/lib/cjs/src/deviceModels.test.js +2 -0
- package/lib/cjs/src/deviceModels.test.js.map +7 -0
- package/lib/cjs/src/index.js +2 -0
- package/lib/cjs/src/index.js.map +7 -0
- package/lib/cjs/src/mockServerScreenApi.js +2 -0
- package/lib/cjs/src/mockServerScreenApi.js.map +7 -0
- package/lib/cjs/src/mockServerScreenApi.test.js +2 -0
- package/lib/cjs/src/mockServerScreenApi.test.js.map +7 -0
- package/lib/cjs/src/types.js +2 -0
- package/lib/cjs/src/types.js.map +7 -0
- package/lib/cjs/src/useButtonHold.js +2 -0
- package/lib/cjs/src/useButtonHold.js.map +7 -0
- package/lib/cjs/src/useButtonHold.test.js +2 -0
- package/lib/cjs/src/useButtonHold.test.js.map +7 -0
- package/lib/cjs/src/useHold.js +2 -0
- package/lib/cjs/src/useHold.js.map +7 -0
- package/lib/cjs/src/useMockServerDevice.js +2 -0
- package/lib/cjs/src/useMockServerDevice.js.map +7 -0
- package/lib/cjs/src/useMockServerDevice.test.js +2 -0
- package/lib/cjs/src/useMockServerDevice.test.js.map +7 -0
- package/lib/cjs/src/useOpenApp.js +2 -0
- package/lib/cjs/src/useOpenApp.js.map +7 -0
- package/lib/cjs/src/useOpenApp.test.js +2 -0
- package/lib/cjs/src/useOpenApp.test.js.map +7 -0
- package/lib/cjs/src/useScreenPolling.js +2 -0
- package/lib/cjs/src/useScreenPolling.js.map +7 -0
- package/lib/cjs/src/useScreenPolling.test.js +2 -0
- package/lib/cjs/src/useScreenPolling.test.js.map +7 -0
- package/lib/cjs/src/useTouchHold.js +2 -0
- package/lib/cjs/src/useTouchHold.js.map +7 -0
- package/lib/cjs/src/useTouchHold.test.js +2 -0
- package/lib/cjs/src/useTouchHold.test.js.map +7 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +7 -0
- package/lib/esm/package.json +61 -0
- package/lib/esm/src/deviceModels.js +2 -0
- package/lib/esm/src/deviceModels.js.map +7 -0
- package/lib/esm/src/deviceModels.test.js +2 -0
- package/lib/esm/src/deviceModels.test.js.map +7 -0
- package/lib/esm/src/index.js +2 -0
- package/lib/esm/src/index.js.map +7 -0
- package/lib/esm/src/mockServerScreenApi.js +2 -0
- package/lib/esm/src/mockServerScreenApi.js.map +7 -0
- package/lib/esm/src/mockServerScreenApi.test.js +2 -0
- package/lib/esm/src/mockServerScreenApi.test.js.map +7 -0
- package/lib/esm/src/types.js +1 -0
- package/lib/esm/src/types.js.map +7 -0
- package/lib/esm/src/useButtonHold.js +2 -0
- package/lib/esm/src/useButtonHold.js.map +7 -0
- package/lib/esm/src/useButtonHold.test.js +2 -0
- package/lib/esm/src/useButtonHold.test.js.map +7 -0
- package/lib/esm/src/useHold.js +2 -0
- package/lib/esm/src/useHold.js.map +7 -0
- package/lib/esm/src/useMockServerDevice.js +2 -0
- package/lib/esm/src/useMockServerDevice.js.map +7 -0
- package/lib/esm/src/useMockServerDevice.test.js +2 -0
- package/lib/esm/src/useMockServerDevice.test.js.map +7 -0
- package/lib/esm/src/useOpenApp.js +2 -0
- package/lib/esm/src/useOpenApp.js.map +7 -0
- package/lib/esm/src/useOpenApp.test.js +2 -0
- package/lib/esm/src/useOpenApp.test.js.map +7 -0
- package/lib/esm/src/useScreenPolling.js +2 -0
- package/lib/esm/src/useScreenPolling.js.map +7 -0
- package/lib/esm/src/useScreenPolling.test.js +2 -0
- package/lib/esm/src/useScreenPolling.test.js.map +7 -0
- package/lib/esm/src/useTouchHold.js +2 -0
- package/lib/esm/src/useTouchHold.js.map +7 -0
- package/lib/esm/src/useTouchHold.test.js +2 -0
- package/lib/esm/src/useTouchHold.test.js.map +7 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/src/deviceModels.d.ts +12 -0
- package/lib/types/src/deviceModels.d.ts.map +1 -0
- package/lib/types/src/deviceModels.test.d.ts +2 -0
- package/lib/types/src/deviceModels.test.d.ts.map +1 -0
- package/lib/types/src/index.d.ts +10 -0
- package/lib/types/src/index.d.ts.map +1 -0
- package/lib/types/src/mockServerScreenApi.d.ts +3 -0
- package/lib/types/src/mockServerScreenApi.d.ts.map +1 -0
- package/lib/types/src/mockServerScreenApi.test.d.ts +2 -0
- package/lib/types/src/mockServerScreenApi.test.d.ts.map +1 -0
- package/lib/types/src/types.d.ts +60 -0
- package/lib/types/src/types.d.ts.map +1 -0
- package/lib/types/src/useButtonHold.d.ts +6 -0
- package/lib/types/src/useButtonHold.d.ts.map +1 -0
- package/lib/types/src/useButtonHold.test.d.ts +2 -0
- package/lib/types/src/useButtonHold.test.d.ts.map +1 -0
- package/lib/types/src/useHold.d.ts +23 -0
- package/lib/types/src/useHold.d.ts.map +1 -0
- package/lib/types/src/useMockServerDevice.d.ts +9 -0
- package/lib/types/src/useMockServerDevice.d.ts.map +1 -0
- package/lib/types/src/useMockServerDevice.test.d.ts +2 -0
- package/lib/types/src/useMockServerDevice.test.d.ts.map +1 -0
- package/lib/types/src/useOpenApp.d.ts +19 -0
- package/lib/types/src/useOpenApp.d.ts.map +1 -0
- package/lib/types/src/useOpenApp.test.d.ts +2 -0
- package/lib/types/src/useOpenApp.test.d.ts.map +1 -0
- package/lib/types/src/useScreenPolling.d.ts +3 -0
- package/lib/types/src/useScreenPolling.d.ts.map +1 -0
- package/lib/types/src/useScreenPolling.test.d.ts +2 -0
- package/lib/types/src/useScreenPolling.test.d.ts.map +1 -0
- package/lib/types/src/useTouchHold.d.ts +23 -0
- package/lib/types/src/useTouchHold.d.ts.map +1 -0
- package/lib/types/src/useTouchHold.test.d.ts +2 -0
- package/lib/types/src/useTouchHold.test.d.ts.map +1 -0
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useTouchHold.test.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, { act } from \"react\";\nimport { createRoot, type Root } from \"react-dom/client\";\n\nimport { HOLD_THRESHOLD_MS } from \"./useHold\";\nimport { toScreenPoint, type TouchHold, useTouchHold } from \"./useTouchHold\";\n\nObject.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });\n\ndescribe(\"toScreenPoint\", () => {\n const drawn = { width: 200, height: 300 };\n const screen = { width: 400, height: 600 };\n\n it(\"scales a point on the drawn screen to device pixels\", () => {\n expect(toScreenPoint(50, 150, drawn, screen)).toEqual({ x: 100, y: 300 });\n });\n\n it(\"keeps the far edges on the last pixel\", () => {\n expect(toScreenPoint(200, 300, drawn, screen)).toEqual({ x: 399, y: 599 });\n expect(toScreenPoint(-5, -5, drawn, screen)).toEqual({ x: 0, y: 0 });\n });\n\n it(\"has no point while a size is unknown\", () => {\n expect(toScreenPoint(50, 50, { width: 0, height: 0 }, screen)).toBeNull();\n expect(toScreenPoint(50, 50, drawn, { width: 0, height: 0 })).toBeNull();\n });\n});\n\ndescribe(\"useTouchHold\", () => {\n let root: Root;\n let touch: TouchHold;\n const onTouch = vi.fn();\n\n const Probe: React.FC<{ handler?: typeof onTouch }> = ({ handler }) => {\n touch = useTouchHold(handler);\n return null;\n };\n const render = (handler?: typeof onTouch) =>\n act(() => root.render(<Probe handler={handler} />));\n\n beforeEach(() => {\n vi.useFakeTimers();\n onTouch.mockReset();\n root = createRoot(document.createElement(\"div\"));\n });\n\n afterEach(() => {\n act(() => root.unmount());\n vi.useRealTimers();\n });\n\n it(\"sends a quick tap as one press-and-release\", () => {\n render(onTouch);\n\n expect(touch.hold({ x: 10, y: 20 })).toBe(true);\n expect(touch.release()).toBe(true);\n\n expect(onTouch).toHaveBeenCalledExactlyOnceWith(\n 10,\n 20,\n \"press-and-release\",\n );\n });\n\n it(\"sends a hold as a press, then a release where the finger went down\", () => {\n render(onTouch);\n\n touch.hold({ x: 10, y: 20 });\n vi.advanceTimersByTime(HOLD_THRESHOLD_MS);\n touch.release();\n\n expect(onTouch.mock.calls).toEqual([\n [10, 20, \"press\"],\n [10, 20, \"release\"],\n ]);\n });\n\n it(\"ignores a second finger while one is down\", () => {\n render(onTouch);\n touch.hold({ x: 10, y: 20 });\n\n expect(touch.hold({ x: 30, y: 40 })).toBe(false);\n touch.release();\n expect(onTouch).toHaveBeenCalledExactlyOnceWith(\n 10,\n 20,\n \"press-and-release\",\n );\n });\n\n it(\"ignores touches without a handler\", () => {\n render();\n\n expect(touch.hold({ x: 10, y: 20 })).toBe(false);\n expect(touch.release()).toBe(false);\n });\n\n it(\"releases a held finger when unmounted\", () => {\n render(onTouch);\n touch.hold({ x: 10, y: 20 });\n vi.advanceTimersByTime(HOLD_THRESHOLD_MS);\n\n act(() => root.unmount());\n root = createRoot(document.createElement(\"div\"));\n\n expect(onTouch).toHaveBeenLastCalledWith(10, 20, \"release\");\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,GAAS,OAAAC,MAAW,QAC3B,OAAS,cAAAC,MAA6B,mBAEtC,OAAS,qBAAAC,MAAyB,YAClC,OAAS,iBAAAC,EAA+B,gBAAAC,MAAoB,iBAE5D,OAAO,OAAO,WAAY,CAAE,yBAA0B,EAAK,CAAC,EAE5D,SAAS,gBAAiB,IAAM,CAC9B,MAAMC,EAAQ,CAAE,MAAO,IAAK,OAAQ,GAAI,EAClCC,EAAS,CAAE,MAAO,IAAK,OAAQ,GAAI,EAEzC,GAAG,sDAAuD,IAAM,CAC9D,OAAOH,EAAc,GAAI,IAAKE,EAAOC,CAAM,CAAC,EAAE,QAAQ,CAAE,EAAG,IAAK,EAAG,GAAI,CAAC,CAC1E,CA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K,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,EAC3B,GAAG,oBAAoBN,CAAiB,EACxCM,EAAM,QAAQ,EAEd,OAAOC,EAAQ,KAAK,KAAK,EAAE,QAAQ,CACjC,CAAC,GAAI,GAAI,OAAO,EAChB,CAAC,GAAI,GAAI,SAAS,CACpB,CAAC,CACH,CAAC,EAED,GAAG,4CAA6C,IAAM,CACpDG,EAAOH,CAAO,EACdD,EAAM,KAAK,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,EAE3B,OAAOA,EAAM,KAAK,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,CAAC,EAAE,KAAK,EAAK,EAC/CA,EAAM,QAAQ,EACd,OAAOC,CAAO,EAAE,gCACd,GACA,GACA,mBACF,CACF,CAAC,EAED,GAAG,oCAAqC,IAAM,CAC5CG,EAAO,EAEP,OAAOJ,EAAM,KAAK,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,CAAC,EAAE,KAAK,EAAK,EAC/C,OAAOA,EAAM,QAAQ,CAAC,EAAE,KAAK,EAAK,CACpC,CAAC,EAED,GAAG,wCAAyC,IAAM,CAChDI,EAAOH,CAAO,EACdD,EAAM,KAAK,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,EAC3B,GAAG,oBAAoBN,CAAiB,EAExCF,EAAI,IAAMO,EAAK,QAAQ,CAAC,EACxBA,EAAON,EAAW,SAAS,cAAc,KAAK,CAAC,EAE/C,OAAOQ,CAAO,EAAE,yBAAyB,GAAI,GAAI,SAAS,CAC5D,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["React", "act", "createRoot", "HOLD_THRESHOLD_MS", "toScreenPoint", "useTouchHold", "drawn", "screen", "root", "touch", "onTouch", "Probe", "handler", "render"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface DeviceScreenModel {
|
|
2
|
+
readonly label: string;
|
|
3
|
+
readonly touch: boolean;
|
|
4
|
+
/** Whether Speculos has an emulator for it, so it can have a screen. */
|
|
5
|
+
readonly speculos: boolean;
|
|
6
|
+
/** In device pixels. */
|
|
7
|
+
readonly screenWidth: number;
|
|
8
|
+
readonly screenHeight: number;
|
|
9
|
+
readonly lightScreen: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const findDeviceScreenModel: (deviceType: string) => DeviceScreenModel;
|
|
12
|
+
//# sourceMappingURL=deviceModels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceModels.d.ts","sourceRoot":"","sources":["../../../src/deviceModels.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,wBAAwB;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B;AA4CD,eAAO,MAAM,qBAAqB,GAAI,YAAY,MAAM,KAAG,iBAC5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deviceModels.test.d.ts","sourceRoot":"","sources":["../../../src/deviceModels.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { type DeviceScreenModel, findDeviceScreenModel } from "./deviceModels";
|
|
2
|
+
export { mockServerScreenApi } from "./mockServerScreenApi";
|
|
3
|
+
export type { DeviceScreenInput, DeviceScreenState, MockServerClient, ScreenApi, ScreenPlatform, } from "./types";
|
|
4
|
+
export { type ButtonHold, useButtonHold } from "./useButtonHold";
|
|
5
|
+
export { type Hold, HOLD_THRESHOLD_MS, useHold } from "./useHold";
|
|
6
|
+
export { useMockServerDevice } from "./useMockServerDevice";
|
|
7
|
+
export { appIconUrl, OPEN_APP_TIMEOUT_MS, openableApps, type OpenApp, useOpenApp, } from "./useOpenApp";
|
|
8
|
+
export { useScreenPolling } from "./useScreenPolling";
|
|
9
|
+
export { type ScreenPoint, type Size, toScreenPoint, type TouchHold, useTouchHold, } from "./useTouchHold";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,EACT,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,KAAK,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,KAAK,IAAI,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,YAAY,EACZ,KAAK,OAAO,EACZ,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,IAAI,EACT,aAAa,EACb,KAAK,SAAS,EACd,YAAY,GACb,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockServerScreenApi.d.ts","sourceRoot":"","sources":["../../../src/mockServerScreenApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAMhE,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,gBAAgB,EACxB,UAAU,MAAM,KACf,SA8BD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockServerScreenApi.test.d.ts","sourceRoot":"","sources":["../../../src/mockServerScreenApi.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type Device, type MockClient, type SpeculosAction, type SpeculosButton } from "@ledgerhq/device-mockserver-client";
|
|
2
|
+
/**
|
|
3
|
+
* The MockClient calls this library makes. Picking them drops the class's
|
|
4
|
+
* private fields, so a client from another copy of the package still fits.
|
|
5
|
+
*/
|
|
6
|
+
export type MockServerClient = Pick<MockClient, "getDevice" | "getScreenshot" | "pressButton" | "touchScreen" | "sendApdu">;
|
|
7
|
+
/**
|
|
8
|
+
* How the screen is reached. The mock server proxies to the Speculos instance
|
|
9
|
+
* backing a device and a Speculos transport talks to one directly, but both
|
|
10
|
+
* answer the same calls.
|
|
11
|
+
*/
|
|
12
|
+
export interface ScreenApi {
|
|
13
|
+
/** Resolves null when there is no screen to capture right now. */
|
|
14
|
+
screenshot(): Promise<Blob | null>;
|
|
15
|
+
/** What to show while `screenshot` keeps resolving null. */
|
|
16
|
+
idle?(): Promise<DeviceScreenState>;
|
|
17
|
+
pressButton(button: SpeculosButton, action: SpeculosAction): Promise<void>;
|
|
18
|
+
/** Coordinates in device screen pixels. */
|
|
19
|
+
touch(x: number, y: number, action: SpeculosAction): Promise<void>;
|
|
20
|
+
/** Omitted by apis whose device always runs an app. */
|
|
21
|
+
openApp?(appName: string): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Press and release are separate so a hold reaches the device as a hold: Stax
|
|
25
|
+
* and Flex gate their confirmations behind one.
|
|
26
|
+
*/
|
|
27
|
+
export interface DeviceScreenInput {
|
|
28
|
+
pressButton(button: SpeculosButton, action: SpeculosAction): void;
|
|
29
|
+
touch(x: number, y: number, action: SpeculosAction): void;
|
|
30
|
+
}
|
|
31
|
+
export type DeviceScreenState = {
|
|
32
|
+
kind: "loading";
|
|
33
|
+
}
|
|
34
|
+
/** No app runs, so no Speculos instance: the device record stands in. */
|
|
35
|
+
| {
|
|
36
|
+
kind: "os-info";
|
|
37
|
+
device: Device;
|
|
38
|
+
}
|
|
39
|
+
/** `src` is whatever the platform's `toImageSource` made of the frame. */
|
|
40
|
+
| {
|
|
41
|
+
kind: "image";
|
|
42
|
+
src: string;
|
|
43
|
+
input: DeviceScreenInput;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "error";
|
|
46
|
+
message: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* What a screen needs from the platform drawing it. Polling restarts whenever
|
|
50
|
+
* this object changes, so hosts pass a module-level constant.
|
|
51
|
+
*/
|
|
52
|
+
export interface ScreenPlatform {
|
|
53
|
+
/** Turns a screenshot into a source the platform's image element shows. */
|
|
54
|
+
toImageSource(screenshot: Blob): Promise<string>;
|
|
55
|
+
/** Frees a source once a newer frame or no frame replaces it. */
|
|
56
|
+
releaseImageSource?(source: string): void;
|
|
57
|
+
/** Polling skips its turn while the screen is out of sight. */
|
|
58
|
+
isHidden(): boolean;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,oCAAoC,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,CACjC,UAAU,EACV,WAAW,GAAG,eAAe,GAAG,aAAa,GAAG,aAAa,GAAG,UAAU,CAC3E,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jD,iEAAiE;IACjE,kBAAkB,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,+DAA+D;IAC/D,QAAQ,IAAI,OAAO,CAAC;CACrB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type SpeculosAction, type SpeculosButton } from "@ledgerhq/device-mockserver-client";
|
|
2
|
+
import { type Hold } from "./useHold";
|
|
3
|
+
export type ButtonHold = Hold<SpeculosButton>;
|
|
4
|
+
/** A physical button's down and up, as the actions the device gets. */
|
|
5
|
+
export declare const useButtonHold: (onPress: (button: SpeculosButton, action: SpeculosAction) => void) => ButtonHold;
|
|
6
|
+
//# sourceMappingURL=useButtonHold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useButtonHold.d.ts","sourceRoot":"","sources":["../../../src/useButtonHold.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,KAAK,IAAI,EAAW,MAAM,WAAW,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;AAE9C,uEAAuE;AACvE,eAAO,MAAM,aAAa,GACxB,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,KAAK,IAAI,KAChE,UAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useButtonHold.test.d.ts","sourceRoot":"","sources":["../../../src/useButtonHold.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type SpeculosAction } from "@ledgerhq/device-mockserver-client";
|
|
2
|
+
/**
|
|
3
|
+
* How long a button or finger stays down before the interaction counts as a
|
|
4
|
+
* hold. A click sent as a separate press and release is two requests the
|
|
5
|
+
* device can receive in either order, and the emulator only sees what is down
|
|
6
|
+
* when its event loop samples it, so a click that beats the loop is dropped:
|
|
7
|
+
* a quick tap, or a chord of both buttons. One press-and-release leaves the
|
|
8
|
+
* timing to the emulator.
|
|
9
|
+
*/
|
|
10
|
+
export declare const HOLD_THRESHOLD_MS = 150;
|
|
11
|
+
export interface Hold<T> {
|
|
12
|
+
/** Went down. False when ignored: no handler, or something is held. */
|
|
13
|
+
hold(target: T): boolean;
|
|
14
|
+
/** Went up. False when nothing was held. */
|
|
15
|
+
release(): boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Turns a button's or a finger's down and up into the actions the device
|
|
19
|
+
* gets: a quick click as one press-and-release, a longer hold as a press then
|
|
20
|
+
* a release. Whatever is still pressed on unmount is released.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useHold<T>(onAction: ((target: T, action: SpeculosAction) => void) | undefined): Hold<T>;
|
|
23
|
+
//# sourceMappingURL=useHold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHold.d.ts","sourceRoot":"","sources":["../../../src/useHold.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAOrC,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,uEAAuE;IACvE,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC;IACzB,4CAA4C;IAC5C,OAAO,IAAI,OAAO,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC,GAAG,SAAS,GAClE,IAAI,CAAC,CAAC,CAAC,CA8CT"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Device } from "@ledgerhq/device-mockserver-client";
|
|
2
|
+
import { type MockServerClient } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* The mock server's record of a device: undefined while it loads, or while no
|
|
5
|
+
* device id is given, and null while it cannot be read. A failed read is
|
|
6
|
+
* retried, so a transient error does not leave the device without its model.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useMockServerDevice(client: MockServerClient, deviceId: string): Device | null | undefined;
|
|
9
|
+
//# sourceMappingURL=useMockServerDevice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMockServerDevice.d.ts","sourceRoot":"","sources":["../../../src/useMockServerDevice.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAEjE,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAIhD;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,IAAI,GAAG,SAAS,CA8B3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMockServerDevice.test.d.ts","sourceRoot":"","sources":["../../../src/useMockServerDevice.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Device } from "@ledgerhq/device-mockserver-client";
|
|
2
|
+
export declare const OPEN_APP_TIMEOUT_MS = 10000;
|
|
3
|
+
/** The apps a device lists that the user can open. */
|
|
4
|
+
export declare const openableApps: (device: Device) => NonNullable<Device["apps"]>;
|
|
5
|
+
/** Ledger Live's app icons, keyed by the app's Manager API icon name. */
|
|
6
|
+
export declare const appIconUrl: (appName: string) => string;
|
|
7
|
+
export interface OpenApp {
|
|
8
|
+
/**
|
|
9
|
+
* The app being opened. Kept on success, until the live screen replaces the
|
|
10
|
+
* app list or the wait times out.
|
|
11
|
+
*/
|
|
12
|
+
opening: string | undefined;
|
|
13
|
+
error: string | undefined;
|
|
14
|
+
/** Ignored without a handler, or while another app is opening. */
|
|
15
|
+
open(appName: string): void;
|
|
16
|
+
}
|
|
17
|
+
/** Omitted, the apps are listed but cannot be opened. */
|
|
18
|
+
export declare function useOpenApp(onOpenApp: ((appName: string) => Promise<void>) | undefined): OpenApp;
|
|
19
|
+
//# sourceMappingURL=useOpenApp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOpenApp.d.ts","sourceRoot":"","sources":["../../../src/useOpenApp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAKjE,eAAO,MAAM,mBAAmB,QAAS,CAAC;AAE1C,sDAAsD;AACtD,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,KAAG,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CACR,CAAC;AAEjE,yEAAyE;AACzE,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,KAAG,MAC0C,CAAC;AAExF,MAAM,WAAW,OAAO;IACtB;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,kEAAkE;IAClE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,yDAAyD;AACzD,wBAAgB,UAAU,CACxB,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,GAC1D,OAAO,CA+BT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOpenApp.test.d.ts","sourceRoot":"","sources":["../../../src/useOpenApp.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScreenPolling.d.ts","sourceRoot":"","sources":["../../../src/useScreenPolling.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAajB,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,SAAS,EACd,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,cAAc,GACvB,iBAAiB,CAmHnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScreenPolling.test.d.ts","sourceRoot":"","sources":["../../../src/useScreenPolling.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type SpeculosAction } from "@ledgerhq/device-mockserver-client";
|
|
2
|
+
import { type Hold } from "./useHold";
|
|
3
|
+
export interface Size {
|
|
4
|
+
readonly width: number;
|
|
5
|
+
readonly height: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ScreenPoint {
|
|
8
|
+
readonly x: number;
|
|
9
|
+
readonly y: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Where an offset into the screen as drawn lands in device pixels, or null
|
|
13
|
+
* while either size is unknown.
|
|
14
|
+
*/
|
|
15
|
+
export declare const toScreenPoint: (offsetX: number, offsetY: number, drawn: Size, screen: Size) => ScreenPoint | null;
|
|
16
|
+
export type TouchHold = Hold<ScreenPoint>;
|
|
17
|
+
/**
|
|
18
|
+
* A finger's down and up on the screen, as the actions the device gets: a
|
|
19
|
+
* quick tap as one press-and-release, a hold as a press then a release on the
|
|
20
|
+
* spot where it went down.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useTouchHold(onTouch: ((x: number, y: number, action: SpeculosAction) => void) | undefined): TouchHold;
|
|
23
|
+
//# sourceMappingURL=useTouchHold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTouchHold.d.ts","sourceRoot":"","sources":["../../../src/useTouchHold.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,KAAK,IAAI,EAAW,MAAM,WAAW,CAAC;AAE/C,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,GACxB,SAAS,MAAM,EACf,SAAS,MAAM,EACf,OAAO,IAAI,EACX,QAAQ,IAAI,KACX,WAAW,GAAG,IAWhB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;AAE1C;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC,GAAG,SAAS,GAC5E,SAAS,CASX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTouchHold.test.d.ts","sourceRoot":"","sources":["../../../src/useTouchHold.test.tsx"],"names":[],"mappings":""}
|