@ledgerhq/device-mockserver-react 0.0.0-mockserver-react-20260929114136
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 +45 -0
- package/lib/cjs/index.js +2 -0
- package/lib/cjs/index.js.map +7 -0
- package/lib/cjs/package.json +67 -0
- package/lib/cjs/src/DeviceOsInfo.js +2 -0
- package/lib/cjs/src/DeviceOsInfo.js.map +7 -0
- package/lib/cjs/src/DeviceScreen.js +2 -0
- package/lib/cjs/src/DeviceScreen.js.map +7 -0
- package/lib/cjs/src/DeviceScreenButtons.js +2 -0
- package/lib/cjs/src/DeviceScreenButtons.js.map +7 -0
- package/lib/cjs/src/DeviceScreenImage.js +2 -0
- package/lib/cjs/src/DeviceScreenImage.js.map +7 -0
- package/lib/cjs/src/MockServerDevice.js +2 -0
- package/lib/cjs/src/MockServerDevice.js.map +7 -0
- package/lib/cjs/src/ScreenFrame.js +2 -0
- package/lib/cjs/src/ScreenFrame.js.map +7 -0
- package/lib/cjs/src/deviceModels.js +2 -0
- package/lib/cjs/src/deviceModels.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/useMockServerDevice.js +2 -0
- package/lib/cjs/src/useMockServerDevice.js.map +7 -0
- package/lib/cjs/src/useScreenPolling.js +2 -0
- package/lib/cjs/src/useScreenPolling.js.map +7 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/index.js.map +7 -0
- package/lib/esm/package.json +67 -0
- package/lib/esm/src/DeviceOsInfo.js +2 -0
- package/lib/esm/src/DeviceOsInfo.js.map +7 -0
- package/lib/esm/src/DeviceScreen.js +2 -0
- package/lib/esm/src/DeviceScreen.js.map +7 -0
- package/lib/esm/src/DeviceScreenButtons.js +2 -0
- package/lib/esm/src/DeviceScreenButtons.js.map +7 -0
- package/lib/esm/src/DeviceScreenImage.js +2 -0
- package/lib/esm/src/DeviceScreenImage.js.map +7 -0
- package/lib/esm/src/MockServerDevice.js +2 -0
- package/lib/esm/src/MockServerDevice.js.map +7 -0
- package/lib/esm/src/ScreenFrame.js +2 -0
- package/lib/esm/src/ScreenFrame.js.map +7 -0
- package/lib/esm/src/deviceModels.js +2 -0
- package/lib/esm/src/deviceModels.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/useMockServerDevice.js +2 -0
- package/lib/esm/src/useMockServerDevice.js.map +7 -0
- package/lib/esm/src/useScreenPolling.js +2 -0
- package/lib/esm/src/useScreenPolling.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/DeviceOsInfo.d.ts +12 -0
- package/lib/types/src/DeviceOsInfo.d.ts.map +1 -0
- package/lib/types/src/DeviceScreen.d.ts +17 -0
- package/lib/types/src/DeviceScreen.d.ts.map +1 -0
- package/lib/types/src/DeviceScreenButtons.d.ts +8 -0
- package/lib/types/src/DeviceScreenButtons.d.ts.map +1 -0
- package/lib/types/src/DeviceScreenImage.d.ts +10 -0
- package/lib/types/src/DeviceScreenImage.d.ts.map +1 -0
- package/lib/types/src/MockServerDevice.d.ts +10 -0
- package/lib/types/src/MockServerDevice.d.ts.map +1 -0
- package/lib/types/src/ScreenFrame.d.ts +12 -0
- package/lib/types/src/ScreenFrame.d.ts.map +1 -0
- package/lib/types/src/deviceModels.d.ts +14 -0
- package/lib/types/src/deviceModels.d.ts.map +1 -0
- package/lib/types/src/index.d.ts +7 -0
- package/lib/types/src/index.d.ts.map +1 -0
- package/lib/types/src/mockServerScreenApi.d.ts +4 -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 +41 -0
- package/lib/types/src/types.d.ts.map +1 -0
- package/lib/types/src/useMockServerDevice.d.ts +7 -0
- package/lib/types/src/useMockServerDevice.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/tsconfig.prod.tsbuildinfo +1 -0
- package/package.json +67 -0
- package/tailwind.css +2 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var n=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var u=(o,e,c,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of p(e))!s.call(o,t)&&t!==c&&n(o,t,{get:()=>e[t],enumerable:!(i=r(e,t))||i.enumerable});return o};var S=o=>u(n({},"__esModule",{value:!0}),o);var m={};module.exports=S(m);
|
|
2
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n type Device,\n type SpeculosAction,\n type SpeculosButton,\n} from \"@ledgerhq/device-mockserver-client\";\n\n/**\n * How the screen is reached. The mock server proxies to the Speculos instance\n * backing a device and a Speculos transport talks to one directly, but both\n * answer the same calls.\n */\nexport interface ScreenApi {\n /** Resolves null when there is no screen to capture right now. */\n screenshot(): Promise<Blob | null>;\n /** What to show while `screenshot` keeps resolving null. */\n idle?(): Promise<DeviceScreenState>;\n pressButton(button: SpeculosButton, action: SpeculosAction): Promise<void>;\n /** Coordinates in device screen pixels. */\n touch(x: number, y: number, action: SpeculosAction): Promise<void>;\n /** Omitted by apis whose device always runs an app. */\n openApp?(appName: string): Promise<void>;\n}\n\n/**\n * Press and release are separate so a hold reaches the device as a hold: Stax\n * and Flex gate their confirmations behind one.\n */\nexport interface DeviceScreenInput {\n pressButton(button: SpeculosButton, action: SpeculosAction): void;\n touch(x: number, y: number, action: SpeculosAction): void;\n}\n\nexport type DeviceScreenState =\n | { kind: \"loading\" }\n /** No app runs, so no Speculos instance: the device record stands in. */\n | { kind: \"os-info\"; device: Device }\n | { kind: \"image\"; src: string; input: DeviceScreenInput }\n | { kind: \"error\"; message: string };\n"],
|
|
5
|
+
"mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
|
|
6
|
+
"names": ["types_exports", "__toCommonJS"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var i in e)u(t,i,{get:e[i],enumerable:!0})},D=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of o(e))!s.call(t,n)&&n!==i&&u(t,n,{get:()=>e[n],enumerable:!(r=l(e,n))||r.enumerable});return t};var p=t=>D(u({},"__esModule",{value:!0}),t);var m={};v(m,{useMockServerDevice:()=>a});module.exports=p(m);var c=require("react");function a(t,e){const[i,r]=(0,c.useState)();return(0,c.useEffect)(()=>{let n=!1;if(r(void 0),!!e)return t.getDevice(e).then(f=>{n||r(f)}).catch(()=>{n||r(null)}),()=>{n=!0}},[t,e]),i}0&&(module.exports={useMockServerDevice});
|
|
2
|
+
//# sourceMappingURL=useMockServerDevice.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useMockServerDevice.ts"],
|
|
4
|
+
"sourcesContent": ["import { useEffect, useState } from \"react\";\nimport {\n type Device,\n type MockClient,\n} from \"@ledgerhq/device-mockserver-client\";\n\n/**\n * The mock server's record of a device: undefined while it loads, or while no\n * device id is given, and null when it could not be read.\n */\nexport function useMockServerDevice(\n client: MockClient,\n deviceId: string,\n): Device | null | undefined {\n const [device, setDevice] = useState<Device | null>();\n\n useEffect(() => {\n let cancelled = false;\n setDevice(undefined);\n if (!deviceId) return;\n client\n .getDevice(deviceId)\n .then((record) => {\n if (!cancelled) setDevice(record);\n })\n .catch(() => {\n if (!cancelled) setDevice(null);\n });\n return () => {\n cancelled = true;\n };\n }, [client, deviceId]);\n\n return device;\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAoC,iBAU7B,SAASF,EACdG,EACAC,EAC2B,CAC3B,KAAM,CAACC,EAAQC,CAAS,KAAI,YAAwB,EAEpD,sBAAU,IAAM,CACd,IAAIC,EAAY,GAEhB,GADAD,EAAU,MAAS,EACf,EAACF,EACL,OAAAD,EACG,UAAUC,CAAQ,EAClB,KAAMI,GAAW,CACXD,GAAWD,EAAUE,CAAM,CAClC,CAAC,EACA,MAAM,IAAM,CACND,GAAWD,EAAU,IAAI,CAChC,CAAC,EACI,IAAM,CACXC,EAAY,EACd,CACF,EAAG,CAACJ,EAAQC,CAAQ,CAAC,EAEdC,CACT",
|
|
6
|
+
"names": ["useMockServerDevice_exports", "__export", "useMockServerDevice", "__toCommonJS", "import_react", "client", "deviceId", "device", "setDevice", "cancelled", "record"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var L=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var y=(e,r)=>{for(var i in r)L(e,i,{get:r[i],enumerable:!0})},E=(e,r,i,u)=>{if(r&&typeof r=="object"||typeof r=="function")for(let c of R(r))!b.call(e,c)&&c!==i&&L(e,c,{get:()=>r[c],enumerable:!(u=p(r,c))||u.enumerable});return e};var D=e=>E(L({},"__esModule",{value:!0}),e);var I={};y(I,{useScreenPolling:()=>w});module.exports=D(I);var t=require("react");const U=500,O=2e3,T=3,_=e=>e instanceof Error?e.message:String(e);function w(e,r){const[i,u]=(0,t.useState)({kind:"loading"}),c=(0,t.useRef)(null),f=(0,t.useRef)(!1),d=(0,t.useRef)(!1);d.current=i.kind==="image";const g=(0,t.useRef)(0),S=(0,t.useRef)(0),l=(0,t.useCallback)(o=>{d.current&&++g.current<=T||u({kind:"error",message:_(o)})},[]),a=(0,t.useCallback)(()=>{c.current&&(URL.revokeObjectURL(c.current),c.current=null)},[]),k=(0,t.useRef)(()=>{}),h=(0,t.useMemo)(()=>{const o=n=>void n.then(()=>k.current()).catch(l);return{pressButton:(n,s)=>o(e.pressButton(n,s)),touch:(n,s,v)=>o(e.touch(n,s,v))}},[e,l]),m=(0,t.useCallback)(async()=>{if(f.current)return;f.current=!0;const o=S.current,n=()=>o!==S.current;try{const s=await e.screenshot();if(n())return;if(g.current=0,s)a(),c.current=URL.createObjectURL(s),u({kind:"image",src:c.current,input:h});else{const v=await e.idle?.();if(n())return;a(),u(v??{kind:"error",message:"No screen to capture"})}}catch(s){n()||l(s)}finally{f.current=!1}},[e,h,l,a]);return k.current=()=>void m(),(0,t.useEffect)(()=>{if(!r){a(),u({kind:"loading"});return}let o,n=!1;const s=async()=>{document.hidden||await m(),!n&&(o=setTimeout(()=>void s(),d.current?U:O))};return s(),()=>{n=!0,clearTimeout(o),S.current++}},[r,m,a]),(0,t.useEffect)(()=>a,[a]),i}0&&(module.exports={useScreenPolling});
|
|
2
|
+
//# sourceMappingURL=useScreenPolling.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useScreenPolling.ts"],
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport {\n type DeviceScreenInput,\n type DeviceScreenState,\n type ScreenApi,\n} from \"./types\";\n\nconst SCREEN_POLL_MS = 500;\nconst IDLE_POLL_MS = 2000;\n/**\n * An app quitting fails a few calls while Speculos shuts down; the last frame\n * stays up through them rather than flashing an error before the dashboard.\n */\nconst LIVE_FAILURES_TOLERATED = 3;\n\nconst describe = (error: unknown): string =>\n error instanceof Error ? error.message : String(error);\n\nexport function useScreenPolling(\n api: ScreenApi,\n polling: boolean,\n): DeviceScreenState {\n const [state, setState] = useState<DeviceScreenState>({ kind: \"loading\" });\n\n const objectUrl = useRef<string | null>(null);\n const inFlight = useRef(false);\n const isLive = useRef(false);\n isLive.current = state.kind === \"image\";\n const liveFailures = useRef(0);\n /** Bumped when polling stops, so a response still in flight is dropped. */\n const generation = useRef(0);\n\n const fail = useCallback((error: unknown) => {\n if (isLive.current && ++liveFailures.current <= LIVE_FAILURES_TOLERATED) {\n return;\n }\n setState({ kind: \"error\", message: describe(error) });\n }, []);\n\n const releaseObjectUrl = useCallback(() => {\n if (objectUrl.current) {\n URL.revokeObjectURL(objectUrl.current);\n objectUrl.current = null;\n }\n }, []);\n\n /**\n * Input handlers refresh straight after acting. Going through a ref keeps\n * them stable, so the <img> is not remounted on every poll.\n */\n const refreshRef = useRef<() => void>(() => {});\n\n const input = useMemo<DeviceScreenInput>(() => {\n const send = (call: Promise<void>) =>\n void call.then(() => refreshRef.current()).catch(fail);\n\n return {\n pressButton: (button, action) => send(api.pressButton(button, action)),\n touch: (x, y, action) => send(api.touch(x, y, action)),\n };\n }, [api, fail]);\n\n const refresh = useCallback(async () => {\n if (inFlight.current) return;\n inFlight.current = true;\n const started = generation.current;\n const stale = () => started !== generation.current;\n try {\n const blob = await api.screenshot();\n if (stale()) return;\n liveFailures.current = 0;\n if (blob) {\n releaseObjectUrl();\n objectUrl.current = URL.createObjectURL(blob);\n setState({ kind: \"image\", src: objectUrl.current, input });\n } else {\n const idle = await api.idle?.();\n if (stale()) return;\n releaseObjectUrl();\n setState(idle ?? { kind: \"error\", message: \"No screen to capture\" });\n }\n } catch (error) {\n if (!stale()) fail(error);\n } finally {\n inFlight.current = false;\n }\n }, [api, input, fail, releaseObjectUrl]);\n refreshRef.current = () => void refresh();\n\n useEffect(() => {\n if (!polling) {\n // Drop the frame rather than keep a revoked object URL around, which\n // would flash a broken image when the panel reopens.\n releaseObjectUrl();\n setState({ kind: \"loading\" });\n return;\n }\n\n let timer: ReturnType<typeof setTimeout>;\n let cancelled = false;\n\n const tick = async () => {\n if (!document.hidden) await refresh();\n if (cancelled) return;\n timer = setTimeout(\n () => void tick(),\n isLive.current ? SCREEN_POLL_MS : IDLE_POLL_MS,\n );\n };\n void tick();\n\n return () => {\n cancelled = true;\n clearTimeout(timer);\n generation.current++;\n };\n }, [polling, refresh, releaseObjectUrl]);\n\n useEffect(() => releaseObjectUrl, [releaseObjectUrl]);\n\n return state;\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkE,iBAQlE,MAAMC,EAAiB,IACjBC,EAAe,IAKfC,EAA0B,EAE1BC,EAAYC,GAChBA,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,EAEhD,SAASP,EACdQ,EACAC,EACmB,CACnB,KAAM,CAACC,EAAOC,CAAQ,KAAI,YAA4B,CAAE,KAAM,SAAU,CAAC,EAEnEC,KAAY,UAAsB,IAAI,EACtCC,KAAW,UAAO,EAAK,EACvBC,KAAS,UAAO,EAAK,EAC3BA,EAAO,QAAUJ,EAAM,OAAS,QAChC,MAAMK,KAAe,UAAO,CAAC,EAEvBC,KAAa,UAAO,CAAC,EAErBC,KAAO,eAAaV,GAAmB,CACvCO,EAAO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,EAAKY,EAAOH,EAAMC,CAAgB,CAAC,EACvC,OAAAC,EAAW,QAAU,IAAM,KAAKQ,EAAQ,KAExC,aAAU,IAAM,CACd,GAAI,CAAClB,EAAS,CAGZS,EAAiB,EACjBP,EAAS,CAAE,KAAM,SAAU,CAAC,EAC5B,MACF,CAEA,IAAIqB,EACAC,EAAY,GAEhB,MAAMC,EAAO,SAAY,CAClB,SAAS,QAAQ,MAAMP,EAAQ,EAChC,CAAAM,IACJD,EAAQ,WACN,IAAM,KAAKE,EAAK,EAChBpB,EAAO,QAAUX,EAAiBC,CACpC,EACF,EACA,OAAK8B,EAAK,EAEH,IAAM,CACXD,EAAY,GACZ,aAAaD,CAAK,EAClBhB,EAAW,SACb,CACF,EAAG,CAACP,EAASkB,EAAST,CAAgB,CAAC,KAEvC,aAAU,IAAMA,EAAkB,CAACA,CAAgB,CAAC,EAE7CR,CACT",
|
|
6
|
+
"names": ["useScreenPolling_exports", "__export", "useScreenPolling", "__toCommonJS", "import_react", "SCREEN_POLL_MS", "IDLE_POLL_MS", "LIVE_FAILURES_TOLERATED", "describe", "error", "api", "polling", "state", "setState", "objectUrl", "inFlight", "isLive", "liveFailures", "generation", "fail", "releaseObjectUrl", "refreshRef", "input", "send", "call", "button", "action", "x", "y", "refresh", "started", "stale", "blob", "idle", "timer", "cancelled", "tick"]
|
|
7
|
+
}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"@ledgerhq/device-mockserver-client": "workspace:*"
|
|
4
|
+
},
|
|
5
|
+
"devDependencies": {
|
|
6
|
+
"@ledgerhq/device-management-kit": "workspace:*",
|
|
7
|
+
"@ledgerhq/eslint-config-dsdk": "workspace:*",
|
|
8
|
+
"@ledgerhq/ldmk-tool": "workspace:*",
|
|
9
|
+
"@ledgerhq/lumen-design-core": "0.1.26",
|
|
10
|
+
"@ledgerhq/lumen-ui-react": "0.1.55",
|
|
11
|
+
"@ledgerhq/prettier-config-dsdk": "workspace:*",
|
|
12
|
+
"@ledgerhq/tsconfig-dsdk": "workspace:*",
|
|
13
|
+
"@ledgerhq/vitest-config-dmk": "workspace:*",
|
|
14
|
+
"@types/react": "catalog:",
|
|
15
|
+
"@types/react-dom": "catalog:",
|
|
16
|
+
"react": "catalog:",
|
|
17
|
+
"react-dom": "catalog:"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./lib/esm/index.js",
|
|
22
|
+
"require": "./lib/cjs/index.js",
|
|
23
|
+
"types": "./lib/types/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./*": {
|
|
26
|
+
"import": "./lib/esm/*",
|
|
27
|
+
"require": "./lib/cjs/*",
|
|
28
|
+
"types": "./lib/types/*"
|
|
29
|
+
},
|
|
30
|
+
"./tailwind.css": "./tailwind.css"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"./lib",
|
|
34
|
+
"./tailwind.css"
|
|
35
|
+
],
|
|
36
|
+
"license": "Apache-2.0",
|
|
37
|
+
"main": "lib/index.js",
|
|
38
|
+
"name": "@ledgerhq/device-mockserver-react",
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@ledgerhq/device-management-kit": "workspace:*",
|
|
41
|
+
"@ledgerhq/lumen-ui-react": "^0.1.55",
|
|
42
|
+
"react": "catalog:",
|
|
43
|
+
"react-dom": "catalog:"
|
|
44
|
+
},
|
|
45
|
+
"private": false,
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/LedgerHQ/device-sdk-ts.git"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "pnpm ldmk-tool build --entryPoints index.ts,src/*.tsx,src/*.ts --tsconfig tsconfig.prod.json",
|
|
52
|
+
"dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
|
|
53
|
+
"lint": "eslint",
|
|
54
|
+
"lint:fix": "pnpm lint --fix",
|
|
55
|
+
"prebuild": "rimraf lib",
|
|
56
|
+
"prettier": "prettier . --check",
|
|
57
|
+
"prettier:fix": "prettier . --write",
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"test:coverage": "vitest run --coverage",
|
|
60
|
+
"test:watch": "vitest",
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/*.tsx,src/*.ts --tsconfig tsconfig.prod.json",
|
|
63
|
+
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
64
|
+
},
|
|
65
|
+
"types": "lib/index.d.ts",
|
|
66
|
+
"version": "0.0.0-mockserver-react-20260929114136"
|
|
67
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e,{useEffect as w,useRef as v,useState as u}from"react";import{ScreenFrame as x}from"./ScreenFrame";const h="BOLOS",y=1e4,k="[&::-webkit-scrollbar]:size-[6px] [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:rounded-full",q=n=>`https://cdn.live.ledger.com/icons/${n.toLowerCase().replace(/ /g,"_")}.png`,f=({name:n})=>{const[r,i]=u(!1);return r?e.createElement("span",{className:"text-muted bg-muted flex size-[12.5cqw] items-center justify-center rounded-full text-[length:6cqw] font-semibold"},n.charAt(0)):e.createElement("img",{src:q(n),alt:"",draggable:!1,className:"size-[12.5cqw] rounded-full",onError:()=>i(!0)})},S=({device:n,model:r,onOpenApp:i})=>{const p=(n.apps??[]).filter(({name:t})=>t!==h),[o,c]=u(),[b,a]=u(),s=r.lightScreen?{background:"bg-white",text:"text-black",scrollbar:"[&::-webkit-scrollbar-thumb]:bg-black/30",overlay:"bg-white/70"}:{background:"bg-black",text:"text-white",scrollbar:"[&::-webkit-scrollbar-thumb]:bg-white/30",overlay:"bg-black/70"},l=r.touch?{scroll:"overflow-y-auto",list:"grid grid-cols-3 gap-[1.5cqw]",tile:"min-w-0 py-[3cqw]",opening:"flex-col"}:{scroll:"flex items-center overflow-x-auto",list:"flex gap-[2.5cqw]",tile:"w-[28cqw] shrink-0 py-[1.5cqw]",opening:"flex-row"},m=v(void 0);w(()=>()=>clearTimeout(m.current),[]);const g=t=>{!i||o||(c(t),a(void 0),i(t).then(()=>{m.current=setTimeout(()=>{c(void 0),a(`${t} opened but its screen never showed up`)},y)},d=>{c(void 0),a(d instanceof Error?d.message:String(d))}))};return e.createElement("div",{className:"flex flex-col gap-8","data-testid":"container_device-os-info"},e.createElement(x,null,e.createElement("div",{className:`${s.background} ${l.scroll} ${k} ${s.scrollbar} p-[3cqw]`,style:{aspectRatio:r.screenWidth/r.screenHeight},"data-testid":"list_device-apps"},p.length===0?e.createElement("p",{className:`text-[length:5.5cqw] ${s.text} flex h-full w-full items-center justify-center opacity-60`},"No apps installed"):e.createElement("div",{className:l.list},p.map(t=>e.createElement("button",{key:t.name,type:"button",title:`${t.name} ${t.version}`,disabled:!i||o!==void 0,onClick:()=>g(t.name),className:`${s.text} ${l.tile} flex flex-col items-center gap-[1.5cqw] border-0 bg-transparent px-[1.5cqw] disabled:cursor-default enabled:cursor-pointer`,"data-testid":`button_open-app-${t.name}`},e.createElement(f,{name:t.name}),e.createElement("span",{className:"w-full truncate text-center text-[length:4.7cqw] leading-[1.3]"},t.name))))),o!==void 0?e.createElement("div",{className:`${s.text} ${s.overlay} ${l.opening} pointer-events-none absolute inset-0 flex items-center justify-center gap-[3cqw] backdrop-blur-[1cqw]`,"data-testid":"spinner_opening-app-screen"},e.createElement("div",{className:"relative flex size-[18cqw] shrink-0 items-center justify-center"},e.createElement("span",{className:"absolute inset-0 rounded-full border-[0.8cqw] border-current opacity-15"}),e.createElement("span",{className:"absolute inset-0 animate-spin rounded-full border-[0.8cqw] border-transparent border-t-current"}),e.createElement(f,{name:o})),e.createElement("span",{className:"animate-pulse text-[length:4.7cqw] font-semibold"},"Opening ",o)):null),b?e.createElement("p",{className:"body-4 text-error text-center"},b):null)};export{S as DeviceOsInfo};
|
|
2
|
+
//# sourceMappingURL=DeviceOsInfo.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/DeviceOsInfo.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, { useEffect, useRef, useState } from \"react\";\nimport { type Device } from \"@ledgerhq/device-mockserver-client\";\n\nimport { type DeviceScreenModel } from \"./deviceModels\";\nimport { ScreenFrame } from \"./ScreenFrame\";\n\n/** The OS reports itself as an app; it is not one the user can open. */\nconst OS_APP_NAME = \"BOLOS\";\n\nconst OPEN_TIMEOUT_MS = 10_000;\n\n/** A styled scrollbar stays visible where the OS would hide an overlay one. */\nconst SCROLLBAR =\n \"[&::-webkit-scrollbar]:size-[6px] [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:rounded-full\";\n\n/** Ledger Live's app icons, keyed by the app's Manager API icon name. */\nconst iconUrl = (appName: string) =>\n `https://cdn.live.ledger.com/icons/${appName.toLowerCase().replace(/ /g, \"_\")}.png`;\n\ntype AppIconProps = {\n name: string;\n};\n\nconst AppIcon: React.FC<AppIconProps> = ({ name }) => {\n const [missing, setMissing] = useState(false);\n\n if (missing) {\n return (\n <span className=\"text-muted bg-muted flex size-[12.5cqw] items-center justify-center rounded-full text-[length:6cqw] font-semibold\">\n {name.charAt(0)}\n </span>\n );\n }\n\n return (\n <img\n src={iconUrl(name)}\n alt=\"\"\n draggable={false}\n className=\"size-[12.5cqw] rounded-full\"\n onError={() => setMissing(true)}\n />\n );\n};\n\ntype DeviceOsInfoProps = {\n device: Device;\n model: DeviceScreenModel;\n /** Omitted, the apps are listed but cannot be opened. */\n onOpenApp?: (appName: string) => Promise<void>;\n};\n\nexport const DeviceOsInfo: React.FC<DeviceOsInfoProps> = ({\n device,\n model,\n onOpenApp,\n}) => {\n const apps = (device.apps ?? []).filter(({ name }) => name !== OS_APP_NAME);\n /** Kept on success, until the live screen replaces the grid or times out. */\n const [opening, setOpening] = useState<string>();\n const [error, setError] = useState<string>();\n const screen = model.lightScreen\n ? {\n background: \"bg-white\",\n text: \"text-black\",\n scrollbar: \"[&::-webkit-scrollbar-thumb]:bg-black/30\",\n overlay: \"bg-white/70\",\n }\n : {\n background: \"bg-black\",\n text: \"text-white\",\n scrollbar: \"[&::-webkit-scrollbar-thumb]:bg-white/30\",\n overlay: \"bg-black/70\",\n };\n const layout = model.touch\n ? {\n scroll: \"overflow-y-auto\",\n list: \"grid grid-cols-3 gap-[1.5cqw]\",\n tile: \"min-w-0 py-[3cqw]\",\n opening: \"flex-col\",\n }\n : {\n scroll: \"flex items-center overflow-x-auto\",\n list: \"flex gap-[2.5cqw]\",\n tile: \"w-[28cqw] shrink-0 py-[1.5cqw]\",\n opening: \"flex-row\",\n };\n\n const openTimer = useRef<ReturnType<typeof setTimeout> | undefined>(\n undefined,\n );\n useEffect(() => () => clearTimeout(openTimer.current), []);\n\n const open = (appName: string) => {\n if (!onOpenApp || opening) return;\n setOpening(appName);\n setError(undefined);\n onOpenApp(appName).then(\n () => {\n openTimer.current = setTimeout(() => {\n setOpening(undefined);\n setError(`${appName} opened but its screen never showed up`);\n }, OPEN_TIMEOUT_MS);\n },\n (cause: unknown) => {\n setOpening(undefined);\n setError(cause instanceof Error ? cause.message : String(cause));\n },\n );\n };\n\n return (\n <div className=\"flex flex-col gap-8\" data-testid=\"container_device-os-info\">\n <ScreenFrame>\n <div\n className={`${screen.background} ${layout.scroll} ${SCROLLBAR} ${screen.scrollbar} p-[3cqw]`}\n style={{ aspectRatio: model.screenWidth / model.screenHeight }}\n data-testid=\"list_device-apps\"\n >\n {apps.length === 0 ? (\n <p\n className={`text-[length:5.5cqw] ${screen.text} flex h-full w-full items-center justify-center opacity-60`}\n >\n No apps installed\n </p>\n ) : (\n <div className={layout.list}>\n {apps.map((app) => (\n <button\n key={app.name}\n type=\"button\"\n title={`${app.name} ${app.version}`}\n disabled={!onOpenApp || opening !== undefined}\n onClick={() => open(app.name)}\n className={`${screen.text} ${layout.tile} flex flex-col items-center gap-[1.5cqw] border-0 bg-transparent px-[1.5cqw] disabled:cursor-default enabled:cursor-pointer`}\n data-testid={`button_open-app-${app.name}`}\n >\n <AppIcon name={app.name} />\n <span className=\"w-full truncate text-center text-[length:4.7cqw] leading-[1.3]\">\n {app.name}\n </span>\n </button>\n ))}\n </div>\n )}\n </div>\n {opening !== undefined ? (\n <div\n className={`${screen.text} ${screen.overlay} ${layout.opening} pointer-events-none absolute inset-0 flex items-center justify-center gap-[3cqw] backdrop-blur-[1cqw]`}\n data-testid=\"spinner_opening-app-screen\"\n >\n <div className=\"relative flex size-[18cqw] shrink-0 items-center justify-center\">\n <span className=\"absolute inset-0 rounded-full border-[0.8cqw] border-current opacity-15\" />\n <span className=\"absolute inset-0 animate-spin rounded-full border-[0.8cqw] border-transparent border-t-current\" />\n <AppIcon name={opening} />\n </div>\n <span className=\"animate-pulse text-[length:4.7cqw] font-semibold\">\n Opening {opening}\n </span>\n </div>\n ) : null}\n </ScreenFrame>\n {error ? <p className=\"body-4 text-error text-center\">{error}</p> : null}\n </div>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,GAAS,aAAAC,EAAW,UAAAC,EAAQ,YAAAC,MAAgB,QAInD,OAAS,eAAAC,MAAmB,gBAG5B,MAAMC,EAAc,QAEdC,EAAkB,IAGlBC,EACJ,0HAGIC,EAAWC,GACf,qCAAqCA,EAAQ,YAAY,EAAE,QAAQ,KAAM,GAAG,CAAC,OAMzEC,EAAkC,CAAC,CAAE,KAAAC,CAAK,IAAM,CACpD,KAAM,CAACC,EAASC,CAAU,EAAIV,EAAS,EAAK,EAE5C,OAAIS,EAEAZ,EAAA,cAAC,QAAK,UAAU,qHACbW,EAAK,OAAO,CAAC,CAChB,EAKFX,EAAA,cAAC,OACC,IAAKQ,EAAQG,CAAI,EACjB,IAAI,GACJ,UAAW,GACX,UAAU,8BACV,QAA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Y,oBAEXE,EAAK,SAAW,EACflB,EAAA,cAAC,KACC,UAAW,wBAAwBuB,EAAO,IAAI,8DAC/C,mBAED,EAEAvB,EAAA,cAAC,OAAI,UAAWwB,EAAO,MACpBN,EAAK,IAAKU,GACT5B,EAAA,cAAC,UACC,IAAK4B,EAAI,KACT,KAAK,SACL,MAAO,GAAGA,EAAI,IAAI,IAAIA,EAAI,OAAO,GACjC,SAAU,CAACX,GAAaE,IAAY,OACpC,QAAS,IAAMO,EAAKE,EAAI,IAAI,EAC5B,UAAW,GAAGL,EAAO,IAAI,IAAIC,EAAO,IAAI,8HACxC,cAAa,mBAAmBI,EAAI,IAAI,IAExC5B,EAAA,cAACU,EAAA,CAAQ,KAAMkB,EAAI,KAAM,EACzB5B,EAAA,cAAC,QAAK,UAAU,kEACb4B,EAAI,IACP,CACF,CACD,CACH,CAEJ,EACCT,IAAY,OACXnB,EAAA,cAAC,OACC,UAAW,GAAGuB,EAAO,IAAI,IAAIA,EAAO,OAAO,IAAIC,EAAO,OAAO,yGAC7D,cAAY,8BAEZxB,EAAA,cAAC,OAAI,UAAU,mEACbA,EAAA,cAAC,QAAK,UAAU,0EAA0E,EAC1FA,EAAA,cAAC,QAAK,UAAU,iGAAiG,EACjHA,EAAA,cAACU,EAAA,CAAQ,KAAMS,EAAS,CAC1B,EACAnB,EAAA,cAAC,QAAK,UAAU,oDAAmD,WACxDmB,CACX,CACF,EACE,IACN,EACCE,EAAQrB,EAAA,cAAC,KAAE,UAAU,iCAAiCqB,CAAM,EAAO,IACtE,CAEJ",
|
|
6
|
+
"names": ["React", "useEffect", "useRef", "useState", "ScreenFrame", "OS_APP_NAME", "OPEN_TIMEOUT_MS", "SCROLLBAR", "iconUrl", "appName", "AppIcon", "name", "missing", "setMissing", "DeviceOsInfo", "device", "model", "onOpenApp", "apps", "opening", "setOpening", "error", "setError", "screen", "layout", "openTimer", "open", "cause", "app"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e,{useRef as h,useState as b}from"react";import{Banner as E,IconButton as N}from"@ledgerhq/lumen-ui-react";import{ChevronDown as _,ChevronUp as z}from"@ledgerhq/lumen-ui-react/symbols";import{findDeviceScreenModel as H}from"./deviceModels";import{DeviceOsInfo as I}from"./DeviceOsInfo";import{DeviceScreenButtons as W}from"./DeviceScreenButtons";import{DeviceScreenImage as A}from"./DeviceScreenImage";import{ScreenFrame as F}from"./ScreenFrame";import{useScreenPolling as B}from"./useScreenPolling";const x=16,L=224,X=200,U=(t,r)=>r?`${t} - ${r}`:t,V=({api:t,deviceType:r,firmwareVersion:c,floating:a=!1,defaultCollapsed:g=!1})=>{const i=H(r),[d,u]=b(g),p=B(t,!a||!d);return a?e.createElement(k,{title:U(i.label,c),model:i,collapsed:d,onToggle:()=>u(f=>!f)},D(p,i,t)):e.createElement("div",{className:"mx-auto flex w-full max-w-[420px] flex-col gap-8","data-testid":"container_device-screen"},D(p,i,t))},k=({title:t,model:r,collapsed:c,onToggle:a,children:g})=>{const i=h(null),[d,u]=b(),[p,f]=b(L),s=h(null),l=h(null),S=n=>{const o=i.current?.getBoundingClientRect();!o||n.button!==0||n.target.closest("button")||(n.currentTarget.setPointerCapture(n.pointerId),s.current={dx:n.clientX-o.left,dy:n.clientY-o.top})},M=n=>{const o=i.current?.getBoundingClientRect();if(!s.current||!o)return;const m=(v,T)=>Math.min(Math.max(v,0),Math.max(T,0));u({left:m(n.clientX-s.current.dx,window.innerWidth-o.width),top:m(n.clientY-s.current.dy,window.innerHeight-o.height)})},w=()=>{s.current=null},y=n=>{const o=i.current?.getBoundingClientRect();!o||n.button!==0||(n.currentTarget.setPointerCapture(n.pointerId),u({left:o.left,top:o.top}),l.current={x:n.clientX,width:o.width})},C=n=>{const o=i.current?.getBoundingClientRect();if(!l.current||!o)return;const m=l.current.width+n.clientX-l.current.x,v=window.innerWidth-o.left-x;f(Math.max(X,Math.min(m,v)))},P=()=>{l.current=null};return e.createElement("div",{ref:i,className:"bg-base border-muted fixed flex max-w-[calc(100vw-32px)] flex-col rounded-lg border shadow-lg",style:{zIndex:1e3,width:p,...d??{right:x,bottom:x}},"data-testid":"container_device-screen"},e.createElement("div",{className:"flex cursor-move items-center gap-8 px-12 py-8 select-none",style:{touchAction:"none"},onPointerDown:S,onPointerMove:M,onPointerUp:w,onPointerCancel:w},e.createElement(r.icon,{size:16}),e.createElement("span",{className:"body-3-semi-bold text-base flex-1"},t),e.createElement(N,{appearance:"no-background",size:"xs",icon:c?z:_,"aria-label":c?"Expand device screen":"Collapse device screen",onClick:a,"data-testid":"button_toggle-device-screen"})),c?null:e.createElement(e.Fragment,null,e.createElement("div",{className:"flex flex-col gap-8 px-12 pb-12"},g),e.createElement("div",{className:"group absolute top-0 right-[-6px] bottom-0 flex w-[12px] cursor-ew-resize items-center justify-center",style:{touchAction:"none"},onPointerDown:y,onPointerMove:C,onPointerUp:P,onPointerCancel:P,"aria-hidden":!0,"data-testid":"handle_resize-device-screen"},e.createElement("span",{className:"border-muted bg-base group-hover:bg-muted group-active:bg-muted h-40 w-[6px] rounded-full border transition-colors"}))))};function D(t,r,c){switch(t.kind){case"loading":return e.createElement(F,null,e.createElement("div",{className:`${r.lightScreen?"bg-white text-black":"bg-black text-white"} flex items-center justify-center`,style:{aspectRatio:r.screenWidth/r.screenHeight},"data-testid":"placeholder_device-screen-loading"},e.createElement("span",{className:"animate-pulse opacity-60"},e.createElement(r.icon,{size:32}))));case"error":return e.createElement(E,{appearance:"error",title:"Screen unavailable",description:t.message});case"os-info":return e.createElement(I,{device:t.device,model:r,onOpenApp:r.speculos?c.openApp:void 0});case"image":return e.createElement(e.Fragment,null,e.createElement(A,{src:t.src,onTouch:r.touch?t.input.touch:void 0}),r.touch?null:e.createElement(W,{onPress:t.input.pressButton}))}}export{V as DeviceScreen};
|
|
2
|
+
//# sourceMappingURL=DeviceScreen.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/DeviceScreen.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, { useRef, useState } from \"react\";\nimport { Banner, IconButton } from \"@ledgerhq/lumen-ui-react\";\nimport { ChevronDown, ChevronUp } from \"@ledgerhq/lumen-ui-react/symbols\";\n\nimport { type DeviceScreenModel, findDeviceScreenModel } from \"./deviceModels\";\nimport { DeviceOsInfo } from \"./DeviceOsInfo\";\nimport { DeviceScreenButtons } from \"./DeviceScreenButtons\";\nimport { DeviceScreenImage } from \"./DeviceScreenImage\";\nimport { ScreenFrame } from \"./ScreenFrame\";\nimport { type DeviceScreenState, type ScreenApi } from \"./types\";\nimport { useScreenPolling } from \"./useScreenPolling\";\n\nexport type DeviceScreenProps = {\n api: ScreenApi;\n /** The mock server's `device_type`, a DMK `DeviceModelId`. */\n deviceType: string;\n /** Shown next to the model name in the floating window's header. */\n firmwareVersion?: string;\n /**\n * Render as a window over the page that can be dragged by its header and\n * collapsed to it, rather than inline where it is placed.\n */\n floating?: boolean;\n defaultCollapsed?: boolean;\n};\n\ninterface Position {\n readonly left: number;\n readonly top: number;\n}\n\nconst EDGE_MARGIN_PX = 16;\nconst DEFAULT_WIDTH_PX = 224;\nconst MIN_WIDTH_PX = 200;\n\nconst deviceScreenTitle = (label: string, firmwareVersion?: string) =>\n firmwareVersion ? `${label} - ${firmwareVersion}` : label;\n\nexport const DeviceScreen: React.FC<DeviceScreenProps> = ({\n api,\n deviceType,\n firmwareVersion,\n floating = false,\n defaultCollapsed = false,\n}) => {\n const model = findDeviceScreenModel(deviceType);\n const [collapsed, setCollapsed] = useState(defaultCollapsed);\n const state = useScreenPolling(api, !floating || !collapsed);\n\n if (!floating) {\n return (\n <div\n className=\"mx-auto flex w-full max-w-[420px] flex-col gap-8\"\n data-testid=\"container_device-screen\"\n >\n {renderScreen(state, model, api)}\n </div>\n );\n }\n\n return (\n <FloatingWindow\n title={deviceScreenTitle(model.label, firmwareVersion)}\n model={model}\n collapsed={collapsed}\n onToggle={() => setCollapsed((value) => !value)}\n >\n {renderScreen(state, model, api)}\n </FloatingWindow>\n );\n};\n\ntype FloatingWindowProps = {\n title: string;\n model: DeviceScreenModel;\n collapsed: boolean;\n onToggle: () => void;\n children: React.ReactNode;\n};\n\nconst FloatingWindow: React.FC<FloatingWindowProps> = ({\n title,\n model,\n collapsed,\n onToggle,\n children,\n}) => {\n const windowRef = useRef<HTMLDivElement>(null);\n /** Unset until first dragged: the window starts in the bottom right corner. */\n const [position, setPosition] = useState<Position>();\n const [width, setWidth] = useState(DEFAULT_WIDTH_PX);\n const drag = useRef<{ dx: number; dy: number } | null>(null);\n const resize = useRef<{ x: number; width: number } | null>(null);\n\n const handlePointerDown = (event: React.PointerEvent<HTMLDivElement>) => {\n const rect = windowRef.current?.getBoundingClientRect();\n // A drag captures the pointer, which would steal the button's click.\n if (\n !rect ||\n event.button !== 0 ||\n (event.target as HTMLElement).closest(\"button\")\n ) {\n return;\n }\n event.currentTarget.setPointerCapture(event.pointerId);\n drag.current = {\n dx: event.clientX - rect.left,\n dy: event.clientY - rect.top,\n };\n };\n\n const handlePointerMove = (event: React.PointerEvent<HTMLDivElement>) => {\n const rect = windowRef.current?.getBoundingClientRect();\n if (!drag.current || !rect) return;\n // Keep the header on screen, or the window could not be dragged back.\n const clamp = (value: number, max: number) =>\n Math.min(Math.max(value, 0), Math.max(max, 0));\n setPosition({\n left: clamp(\n event.clientX - drag.current.dx,\n window.innerWidth - rect.width,\n ),\n top: clamp(\n event.clientY - drag.current.dy,\n window.innerHeight - rect.height,\n ),\n });\n };\n\n const handlePointerUp = () => {\n drag.current = null;\n };\n\n const handleResizeDown = (event: React.PointerEvent<HTMLDivElement>) => {\n const rect = windowRef.current?.getBoundingClientRect();\n if (!rect || event.button !== 0) return;\n event.currentTarget.setPointerCapture(event.pointerId);\n // Pin the top left corner, or growing would push the window leftwards\n // while it is still anchored to the bottom right.\n setPosition({ left: rect.left, top: rect.top });\n resize.current = { x: event.clientX, width: rect.width };\n };\n\n const handleResizeMove = (event: React.PointerEvent<HTMLDivElement>) => {\n const rect = windowRef.current?.getBoundingClientRect();\n if (!resize.current || !rect) return;\n const next = resize.current.width + event.clientX - resize.current.x;\n const max = window.innerWidth - rect.left - EDGE_MARGIN_PX;\n setWidth(Math.max(MIN_WIDTH_PX, Math.min(next, max)));\n };\n\n const handleResizeUp = () => {\n resize.current = null;\n };\n\n return (\n <div\n ref={windowRef}\n className=\"bg-base border-muted fixed flex max-w-[calc(100vw-32px)] flex-col rounded-lg border shadow-lg\"\n style={{\n zIndex: 1000,\n width,\n ...(position ?? { right: EDGE_MARGIN_PX, bottom: EDGE_MARGIN_PX }),\n }}\n data-testid=\"container_device-screen\"\n >\n <div\n className=\"flex cursor-move items-center gap-8 px-12 py-8 select-none\"\n style={{ touchAction: \"none\" }}\n onPointerDown={handlePointerDown}\n onPointerMove={handlePointerMove}\n onPointerUp={handlePointerUp}\n onPointerCancel={handlePointerUp}\n >\n <model.icon size={16} />\n <span className=\"body-3-semi-bold text-base flex-1\">{title}</span>\n <IconButton\n appearance=\"no-background\"\n size=\"xs\"\n icon={collapsed ? ChevronUp : ChevronDown}\n aria-label={\n collapsed ? \"Expand device screen\" : \"Collapse device screen\"\n }\n onClick={onToggle}\n data-testid=\"button_toggle-device-screen\"\n />\n </div>\n {collapsed ? null : (\n <>\n <div className=\"flex flex-col gap-8 px-12 pb-12\">{children}</div>\n <div\n className=\"group absolute top-0 right-[-6px] bottom-0 flex w-[12px] cursor-ew-resize items-center justify-center\"\n style={{ touchAction: \"none\" }}\n onPointerDown={handleResizeDown}\n onPointerMove={handleResizeMove}\n onPointerUp={handleResizeUp}\n onPointerCancel={handleResizeUp}\n aria-hidden\n data-testid=\"handle_resize-device-screen\"\n >\n <span className=\"border-muted bg-base group-hover:bg-muted group-active:bg-muted h-40 w-[6px] rounded-full border transition-colors\" />\n </div>\n </>\n )}\n </div>\n );\n};\n\nfunction renderScreen(\n state: DeviceScreenState,\n model: DeviceScreenModel,\n api: ScreenApi,\n) {\n switch (state.kind) {\n case \"loading\":\n return (\n <ScreenFrame>\n <div\n className={`${model.lightScreen ? \"bg-white text-black\" : \"bg-black text-white\"} flex items-center justify-center`}\n style={{ aspectRatio: model.screenWidth / model.screenHeight }}\n data-testid=\"placeholder_device-screen-loading\"\n >\n <span className=\"animate-pulse opacity-60\">\n <model.icon size={32} />\n </span>\n </div>\n </ScreenFrame>\n );\n case \"error\":\n return (\n <Banner\n appearance=\"error\"\n title=\"Screen unavailable\"\n description={state.message}\n />\n );\n case \"os-info\":\n return (\n <DeviceOsInfo\n device={state.device}\n model={model}\n onOpenApp={model.speculos ? api.openApp : undefined}\n />\n );\n case \"image\":\n return (\n <>\n <DeviceScreenImage\n src={state.src}\n onTouch={model.touch ? state.input.touch : undefined}\n />\n {model.touch ? null : (\n <DeviceScreenButtons onPress={state.input.pressButton} />\n )}\n </>\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,GAAS,UAAAC,EAAQ,YAAAC,MAAgB,QACxC,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,2BACnC,OAAS,eAAAC,EAAa,aAAAC,MAAiB,mCAEvC,OAAiC,yBAAAC,MAA6B,iBAC9D,OAAS,gBAAAC,MAAoB,iBAC7B,OAAS,uBAAAC,MAA2B,wBACpC,OAAS,qBAAAC,MAAyB,sBAClC,OAAS,eAAAC,MAAmB,gBAE5B,OAAS,oBAAAC,MAAwB,qBAqBjC,MAAMC,EAAiB,GACjBC,EAAmB,IACnBC,EAAe,IAEfC,EAAoB,CAACC,EAAeC,IACxCA,EAAkB,GAAGD,CAAK,MAAMC,CAAe,GAAKD,EAEzCE,EAA4C,CAAC,CACxD,IAAAC,EACA,WAAAC,EACA,gBAAAH,EACA,SAAAI,EAAW,GACX,iBAAAC,EAAmB,EACrB,IAAM,CACJ,MAAMC,EAAQjB,EAAsBc,CAAU,EACxC,CAACI,EAAWC,CAAY,EAAIxB,EAASqB,CAAgB,EACrDI,EAAQf,EAAiBQ,EAAK,CAACE,GAAY,C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B,EAAA,cAAAA,EAAA,cACEA,EAAA,cAAC,OAAI,UAAU,mCAAmCiC,CAAS,EAC3DjC,EAAA,cAAC,OACC,UAAU,wGACV,MAAO,CAAE,YAAa,MAAO,EAC7B,cAAegD,EACf,cAAeC,EACf,YAAaE,EACb,gBAAiBA,EACjB,cAAW,GACX,cAAY,+BAEZnD,EAAA,cAAC,QAAK,UAAU,qHAAqH,CACvI,CACF,CAEJ,CAEJ,EAEA,SAAS8B,EACPH,EACAH,EACAJ,EACA,CACA,OAAQO,EAAM,KAAM,CAClB,IAAK,UACH,OACE3B,EAAA,cAACW,EAAA,KACCX,EAAA,cAAC,OACC,UAAW,GAAGwB,EAAM,YAAc,sBAAwB,qBAAqB,oCAC/E,MAAO,CAAE,YAAaA,EAAM,YAAcA,EAAM,YAAa,EAC7D,cAAY,qCAEZxB,EAAA,cAAC,QAAK,UAAU,4BACdA,EAAA,cAACwB,EAAM,KAAN,CAAW,KAAM,GAAI,CACxB,CACF,CACF,EAEJ,IAAK,QACH,OACExB,EAAA,cAACG,EAAA,CACC,WAAW,QACX,MAAM,qBACN,YAAawB,EAAM,QACrB,EAEJ,IAAK,UACH,OACE3B,EAAA,cAACQ,EAAA,CACC,OAAQmB,EAAM,OACd,MAAOH,EACP,UAAWA,EAAM,SAAWJ,EAAI,QAAU,OAC5C,EAEJ,IAAK,QACH,OACEpB,EAAA,cAAAA,EAAA,cACEA,EAAA,cAACU,EAAA,CACC,IAAKiB,EAAM,IACX,QAASH,EAAM,MAAQG,EAAM,MAAM,MAAQ,OAC7C,EACCH,EAAM,MAAQ,KACbxB,EAAA,cAACS,EAAA,CAAoB,QAASkB,EAAM,MAAM,YAAa,CAE3D,CAEN,CACF",
|
|
6
|
+
"names": ["React", "useRef", "useState", "Banner", "IconButton", "ChevronDown", "ChevronUp", "findDeviceScreenModel", "DeviceOsInfo", "DeviceScreenButtons", "DeviceScreenImage", "ScreenFrame", "useScreenPolling", "EDGE_MARGIN_PX", "DEFAULT_WIDTH_PX", "MIN_WIDTH_PX", "deviceScreenTitle", "label", "firmwareVersion", "DeviceScreen", "api", "deviceType", "floating", "defaultCollapsed", "model", "collapsed", "setCollapsed", "state", "FloatingWindow", "value", "renderScreen", "title", "onToggle", "children", "windowRef", "position", "setPosition", "width", "setWidth", "drag", "resize", "handlePointerDown", "event", "rect", "handlePointerMove", "clamp", "max", "handlePointerUp", "handleResizeDown", "handleResizeMove", "next", "handleResizeUp"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import d,{useCallback as i,useEffect as f,useRef as a}from"react";const y=[{button:"left",label:"Left"},{button:"both",label:"Both"},{button:"right",label:"Right"}],b=r=>r===" "||r==="Enter",m=150,v=({onPress:r})=>{const n=a(null),s=a(null),u=a(r);u.current=r;const c=i(()=>{s.current&&(clearTimeout(s.current),s.current=null)},[]),p=i(e=>{if(n.current)return;const o={button:e,pressed:!1};n.current=o,s.current=setTimeout(()=>{o.pressed=!0,u.current(e,"press")},m)},[]),l=i(()=>{const e=n.current;e&&(n.current=null,c(),u.current(e.button,e.pressed?"release":"press-and-release"))},[c]);return f(()=>()=>{const e=n.current;n.current=null,c(),e?.pressed&&u.current(e.button,"release")},[c]),d.createElement("div",{className:"flex gap-8"},y.map(({button:e,label:o})=>d.createElement("button",{key:e,type:"button","aria-label":`${o} button`,onPointerDown:t=>{t.button===0&&(t.currentTarget.setPointerCapture(t.pointerId),p(e))},onPointerUp:l,onPointerCancel:l,onKeyDown:t=>{b(t.key)&&(t.preventDefault(),p(e))},onKeyUp:t=>b(t.key)&&l(),className:"border-muted body-3 text-base bg-muted hover:bg-muted-pressed active:bg-active flex-1 rounded-md border py-8 select-none",style:{touchAction:"none"},"data-testid":`button_device-screen-${e}`},o)))};export{v as DeviceScreenButtons};
|
|
2
|
+
//# sourceMappingURL=DeviceScreenButtons.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/DeviceScreenButtons.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, { useCallback, useEffect, useRef } from \"react\";\nimport {\n type SpeculosAction,\n type SpeculosButton,\n} from \"@ledgerhq/device-mockserver-client\";\n\nconst BUTTONS: { button: SpeculosButton; label: string }[] = [\n { button: \"left\", label: \"Left\" },\n { button: \"both\", label: \"Both\" },\n { button: \"right\", label: \"Right\" },\n];\n\nconst isActivationKey = (key: string) => key === \" \" || key === \"Enter\";\n\n/**\n * How long the pointer stays down before the interaction counts as a hold.\n * A click sent as a separate press and release is two requests the device can\n * receive in either order, and a chord of both buttons is only seen when they\n * are down together as its event loop samples them, so a click that beats the\n * loop is dropped. One press-and-release leaves the timing to the emulator.\n */\nconst HOLD_THRESHOLD_MS = 150;\n\ninterface Held {\n button: SpeculosButton;\n pressed: boolean;\n}\n\ntype DeviceScreenButtonsProps = {\n onPress: (button: SpeculosButton, action: SpeculosAction) => void;\n};\n\nexport const DeviceScreenButtons: React.FC<DeviceScreenButtonsProps> = ({\n onPress,\n}) => {\n const held = useRef<Held | null>(null);\n const holdTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n const pressRef = useRef(onPress);\n pressRef.current = onPress;\n\n const clearHoldTimer = useCallback(() => {\n if (!holdTimer.current) return;\n clearTimeout(holdTimer.current);\n holdTimer.current = null;\n }, []);\n\n const hold = useCallback((button: SpeculosButton) => {\n if (held.current) return;\n const entry: Held = { button, pressed: false };\n held.current = entry;\n holdTimer.current = setTimeout(() => {\n entry.pressed = true;\n pressRef.current(button, \"press\");\n }, HOLD_THRESHOLD_MS);\n }, []);\n\n const release = useCallback(() => {\n const entry = held.current;\n if (!entry) return;\n held.current = null;\n clearHoldTimer();\n pressRef.current(\n entry.button,\n entry.pressed ? \"release\" : \"press-and-release\",\n );\n }, [clearHoldTimer]);\n\n useEffect(\n () => () => {\n const entry = held.current;\n held.current = null;\n clearHoldTimer();\n if (entry?.pressed) pressRef.current(entry.button, \"release\");\n },\n [clearHoldTimer],\n );\n\n // Plain buttons: Lumen's Button does not report press and release apart,\n // and a hold needs both.\n return (\n <div className=\"flex gap-8\">\n {BUTTONS.map(({ button, label }) => (\n <button\n key={button}\n type=\"button\"\n aria-label={`${label} button`}\n onPointerDown={(event) => {\n if (event.button !== 0) return;\n // Capture so the release still arrives if the pointer wanders off.\n event.currentTarget.setPointerCapture(event.pointerId);\n hold(button);\n }}\n onPointerUp={release}\n onPointerCancel={release}\n // Keyboard activation fires no pointer events.\n onKeyDown={(event) => {\n if (!isActivationKey(event.key)) return;\n event.preventDefault();\n hold(button);\n }}\n onKeyUp={(event) => isActivationKey(event.key) && release()}\n className=\"border-muted body-3 text-base bg-muted hover:bg-muted-pressed active:bg-active flex-1 rounded-md border py-8 select-none\"\n style={{ touchAction: \"none\" }}\n data-testid={`button_device-screen-${button}`}\n >\n {label}\n </button>\n ))}\n </div>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,GAAS,eAAAC,EAAa,aAAAC,EAAW,UAAAC,MAAc,QAMtD,MAAMC,EAAuD,CAC3D,CAAE,OAAQ,OAAQ,MAAO,MAAO,EAChC,CAAE,OAAQ,OAAQ,MAAO,MAAO,EAChC,CAAE,OAAQ,QAAS,MAAO,OAAQ,CACpC,EAEMC,EAAmBC,GAAgBA,IAAQ,KAAOA,IAAQ,QAS1DC,EAAoB,IAWbC,EAA0D,CAAC,CACtE,QAAAC,CACF,IAAM,CACJ,MAAMC,EAAOP,EAAoB,IAAI,EAC/BQ,EAAYR,EAA6C,IAAI,EAC7DS,EAAWT,EAAOM,CAAO,EAC/BG,EAAS,QAAUH,EAEnB,MAAMI,EAAiBZ,EAAY,IAAM,CAClCU,EAAU,UACf,aAAaA,EAAU,OAAO,EAC9BA,EAAU,QAAU,KACtB,EAAG,CAAC,CAAC,EAECG,EAAOb,EAAac,GAA2B,CACnD,GAAIL,EAAK,QAAS,OAClB,MAAMM,EAAc,CAAE,OAAAD,EAAQ,QAAS,EAAM,EAC7CL,EAAK,QAAUM,EACfL,EAAU,QAAU,WAAW,IAAM,CACnCK,EAAM,QAAU,GAChBJ,EAAS,QAAQG,EAAQ,OAAO,CAClC,EAAGR,CAAiB,CACtB,EAAG,CAAC,CAAC,EAECU,EAAUhB,EAAY,IAAM,CAChC,MAAMe,EAAQN,EAAK,QACdM,IACLN,EAAK,QAAU,KACfG,EAAe,EACfD,EAAS,QACPI,EAAM,OACNA,EAAM,QAAU,UAAY,mBAC9B,EACF,EAAG,CAACH,CAAc,CAAC,EAEnB,OAAAX,EACE,IAAM,IAAM,CACV,MAAMc,EAAQN,EAAK,QACnBA,EAAK,QAAU,KACfG,EAAe,EACXG,GAAO,SAASJ,EAAS,QAAQI,EAAM,OAAQ,SAAS,CAC9D,EACA,CAACH,CAAc,CACjB,EAKEb,EAAA,cAAC,OAAI,UAAU,cACZI,EAAQ,IAAI,CAAC,CAAE,OAAAW,EAAQ,MAAAG,CAAM,IAC5BlB,EAAA,cAAC,UACC,IAAKe,EACL,KAAK,SACL,aAAY,GAAGG,CAAK,UACpB,cAAgBC,GAAU,CACpBA,EAAM,SAAW,IAErBA,EAAM,cAAc,kBAAkBA,EAAM,SAAS,EACrDL,EAAKC,CAAM,EACb,EACA,YAAaE,EACb,gBAAiBA,EAEjB,UAAYE,GAAU,CACfd,EAAgBc,EAAM,GAAG,IAC9BA,EAAM,eAAe,EACrBL,EAAKC,CAAM,EACb,EACA,QAAUI,GAAUd,EAAgBc,EAAM,GAAG,GAAKF,EAAQ,EAC1D,UAAU,2HACV,MAAO,CAAE,YAAa,MAAO,EAC7B,cAAa,wBAAwBF,CAAM,IAE1CG,CACH,CACD,CACH,CAEJ",
|
|
6
|
+
"names": ["React", "useCallback", "useEffect", "useRef", "BUTTONS", "isActivationKey", "key", "HOLD_THRESHOLD_MS", "DeviceScreenButtons", "onPress", "held", "holdTimer", "pressRef", "clearHoldTimer", "hold", "button", "entry", "release", "label", "event"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import i,{useCallback as y,useEffect as g,useRef as c,useState as v}from"react";import{ScreenFrame as E}from"./ScreenFrame";const D=({src:l,onTouch:n})=>{const a=c(null),[p,u]=v(!1),r=c(null),s=c(n);s.current=n,g(()=>u(!1),[l]);const f=t=>{const e=a.current;if(!e?.naturalWidth||!e.naturalHeight)return null;const o=e.getBoundingClientRect();if(!o.width||!o.height)return null;const d=(P,x)=>Math.min(Math.max(Math.round(P),0),x-1);return{x:d((t.clientX-o.left)/o.width*e.naturalWidth,e.naturalWidth),y:d((t.clientY-o.top)/o.height*e.naturalHeight,e.naturalHeight)}},h=t=>{if(!n||r.current||t.button!==0)return;const e=f(t);e&&(a.current?.setPointerCapture(t.pointerId),r.current=e,n(e.x,e.y,"press"))},m=t=>{const e=r.current;!n||!e||(r.current=null,a.current?.releasePointerCapture(t.pointerId),n(e.x,e.y,"release"))};g(()=>()=>{const t=r.current;t&&(r.current=null,s.current?.(t.x,t.y,"release"))},[]);const b=y(()=>u(!0),[]);return p?i.createElement("p",{className:"body-4 text-error text-center","data-testid":"text_device-screen-undecodable"},"Screenshot could not be decoded"):i.createElement(E,null,i.createElement("img",{ref:a,src:l,alt:"Device screen",draggable:!1,onError:b,onPointerDown:h,onPointerUp:m,onPointerCancel:m,className:`block w-full bg-black select-none ${n?"cursor-pointer":""}`,style:{imageRendering:"pixelated",touchAction:"none"},"data-testid":"image_device-screen"}))};export{D as DeviceScreenImage};
|
|
2
|
+
//# sourceMappingURL=DeviceScreenImage.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/DeviceScreenImage.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport { type SpeculosAction } from \"@ledgerhq/device-mockserver-client\";\n\nimport { ScreenFrame } from \"./ScreenFrame\";\n\ninterface Point {\n readonly x: number;\n readonly y: number;\n}\n\ntype DeviceScreenImageProps = {\n src: string;\n /** Omitted for a button-driven device. */\n onTouch?: (x: number, y: number, action: SpeculosAction) => void;\n};\n\nexport const DeviceScreenImage: React.FC<DeviceScreenImageProps> = ({\n src,\n onTouch,\n}) => {\n const imageRef = useRef<HTMLImageElement>(null);\n const [undecodable, setUndecodable] = useState(false);\n /** Where the finger went down, so the release lands on the same spot. */\n const held = useRef<Point | null>(null);\n const touchRef = useRef(onTouch);\n touchRef.current = onTouch;\n\n useEffect(() => setUndecodable(false), [src]);\n\n const toDevicePoint = (\n event: React.PointerEvent<HTMLImageElement>,\n ): Point | null => {\n const image = imageRef.current;\n if (!image?.naturalWidth || !image.naturalHeight) return null;\n const rect = image.getBoundingClientRect();\n if (!rect.width || !rect.height) return null;\n // The far edge maps to the pixel count itself, one past the last pixel.\n const clamp = (value: number, size: number) =>\n Math.min(Math.max(Math.round(value), 0), size - 1);\n return {\n x: clamp(\n ((event.clientX - rect.left) / rect.width) * image.naturalWidth,\n image.naturalWidth,\n ),\n y: clamp(\n ((event.clientY - rect.top) / rect.height) * image.naturalHeight,\n image.naturalHeight,\n ),\n };\n };\n\n const handlePointerDown = (event: React.PointerEvent<HTMLImageElement>) => {\n if (!onTouch || held.current || event.button !== 0) return;\n const point = toDevicePoint(event);\n if (!point) return;\n // Capture so the release still arrives if the pointer wanders off the\n // image mid-hold; without it the device would stay pressed forever.\n imageRef.current?.setPointerCapture(event.pointerId);\n held.current = point;\n onTouch(point.x, point.y, \"press\");\n };\n\n const handlePointerUp = (event: React.PointerEvent<HTMLImageElement>) => {\n const point = held.current;\n if (!onTouch || !point) return;\n held.current = null;\n imageRef.current?.releasePointerCapture(event.pointerId);\n onTouch(point.x, point.y, \"release\");\n };\n\n useEffect(\n () => () => {\n const point = held.current;\n if (!point) return;\n held.current = null;\n touchRef.current?.(point.x, point.y, \"release\");\n },\n [],\n );\n\n const handleError = useCallback(() => setUndecodable(true), []);\n\n if (undecodable) {\n return (\n <p\n className=\"body-4 text-error text-center\"\n data-testid=\"text_device-screen-undecodable\"\n >\n Screenshot could not be decoded\n </p>\n );\n }\n\n return (\n <ScreenFrame>\n <img\n ref={imageRef}\n src={src}\n alt=\"Device screen\"\n draggable={false}\n onError={handleError}\n onPointerDown={handlePointerDown}\n onPointerUp={handlePointerUp}\n onPointerCancel={handlePointerUp}\n className={`block w-full bg-black select-none ${\n onTouch ? \"cursor-pointer\" : \"\"\n }`}\n // Device screens are tiny; smoothing them turns text to mush, and a\n // hold must not start a native image drag.\n style={{ imageRendering: \"pixelated\", touchAction: \"none\" }}\n data-testid=\"image_device-screen\"\n />\n </ScreenFrame>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,GAAS,eAAAC,EAAa,aAAAC,EAAW,UAAAC,EAAQ,YAAAC,MAAgB,QAGhE,OAAS,eAAAC,MAAmB,gBAarB,MAAMC,EAAsD,CAAC,CAClE,IAAAC,EACA,QAAAC,CACF,IAAM,CACJ,MAAMC,EAAWN,EAAyB,IAAI,EACxC,CAACO,EAAaC,CAAc,EAAIP,EAAS,EAAK,EAE9CQ,EAAOT,EAAqB,IAAI,EAChCU,EAAWV,EAAOK,CAAO,EAC/BK,EAAS,QAAUL,EAEnBN,EAAU,IAAMS,EAAe,EAAK,EAAG,CAACJ,CAAG,CAAC,EAE5C,MAAMO,EACJC,GACiB,CACjB,MAAMC,EAAQP,EAAS,QACvB,GAAI,CAACO,GAAO,cAAgB,CAACA,EAAM,cAAe,OAAO,KACzD,MAAMC,EAAOD,EAAM,sBAAsB,EACzC,GAAI,CAACC,EAAK,OAAS,CAACA,EAAK,OAAQ,OAAO,KAExC,MAAMC,EAAQ,CAACC,EAAeC,IAC5B,KAAK,IAAI,KAAK,IAAI,KAAK,MAAMD,CAAK,EAAG,CAAC,EAAGC,EAAO,CAAC,EACnD,MAAO,CACL,EAAGF,GACCH,EAAM,QAAUE,EAAK,MAAQA,EAAK,MAASD,EAAM,aACnDA,EAAM,YACR,EACA,EAAGE,GACCH,EAAM,QAAUE,EAAK,KAAOA,EAAK,OAAUD,EAAM,cACnDA,EAAM,aACR,CACF,CACF,EAEMK,EAAqBN,GAAgD,CACzE,GAAI,CAACP,GAAWI,EAAK,SAAWG,EAAM,SAAW,EAAG,OACpD,MAAMO,EAAQR,EAAcC,CAAK,EAC5BO,IAGLb,EAAS,SAAS,kBAAkBM,EAAM,SAAS,EACnDH,EAAK,QAAUU,EACfd,EAAQc,EAAM,EAAGA,EAAM,EAAG,OAAO,EACnC,EAEMC,EAAmBR,GAAgD,CACvE,MAAMO,EAAQV,EAAK,QACf,CAACJ,GAAW,CAACc,IACjBV,EAAK,QAAU,KACfH,EAAS,SAAS,sBAAsBM,EAAM,SAAS,EACvDP,EAAQc,EAAM,EAAGA,EAAM,EAAG,SAAS,EACrC,EAEApB,EACE,IAAM,IAAM,CACV,MAAMoB,EAAQV,EAAK,QACdU,IACLV,EAAK,QAAU,KACfC,EAAS,UAAUS,EAAM,EAAGA,EAAM,EAAG,SAAS,EAChD,EACA,CAAC,CACH,EAEA,MAAME,EAAcvB,EAAY,IAAMU,EAAe,EAAI,EAAG,CAAC,CAAC,EAE9D,OAAID,EAEAV,EAAA,cAAC,KACC,UAAU,gCACV,cAAY,kCACb,iCAED,EAKFA,EAAA,cAACK,EAAA,KACCL,EAAA,cAAC,OACC,IAAKS,EACL,IAAKF,EACL,IAAI,gBACJ,UAAW,GACX,QAASiB,EACT,cAAeH,EACf,YAAaE,EACb,gBAAiBA,EACjB,UAAW,qCACTf,EAAU,iBAAmB,EAC/B,GAGA,MAAO,CAAE,eAAgB,YAAa,YAAa,MAAO,EAC1D,cAAY,sBACd,CACF,CAEJ",
|
|
6
|
+
"names": ["React", "useCallback", "useEffect", "useRef", "useState", "ScreenFrame", "DeviceScreenImage", "src", "onTouch", "imageRef", "undecodable", "setUndecodable", "held", "touchRef", "toDevicePoint", "event", "image", "rect", "clamp", "value", "size", "handlePointerDown", "point", "handlePointerUp", "handleError"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import s,{useMemo as t}from"react";import{MockClient as v}from"@ledgerhq/device-mockserver-client";import{DeviceScreen as m}from"./DeviceScreen";import{mockServerScreenApi as f}from"./mockServerScreenApi";import{useMockServerDevice as S}from"./useMockServerDevice";const M=({url:i,token:c,deviceId:e,...n})=>{const r=t(()=>new v(i,{token:c}),[i,c]),p=t(()=>f(r,e),[r,e]),o=S(r,e);return o===void 0?null:s.createElement(m,{api:p,deviceType:o?.device_type??"",firmwareVersion:o?.firmware_version,...n})};export{M as MockServerDevice};
|
|
2
|
+
//# sourceMappingURL=MockServerDevice.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/MockServerDevice.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, { useMemo } from \"react\";\nimport { MockClient } from \"@ledgerhq/device-mockserver-client\";\n\nimport { DeviceScreen, type DeviceScreenProps } from \"./DeviceScreen\";\nimport { mockServerScreenApi } from \"./mockServerScreenApi\";\nimport { useMockServerDevice } from \"./useMockServerDevice\";\n\nexport type MockServerDeviceProps = Pick<\n DeviceScreenProps,\n \"floating\" | \"defaultCollapsed\"\n> & {\n url: string;\n /** Omitted, the client opens a session of its own. */\n token?: string;\n deviceId: string;\n};\n\nexport const MockServerDevice: React.FC<MockServerDeviceProps> = ({\n url,\n token,\n deviceId,\n ...props\n}) => {\n const client = useMemo(() => new MockClient(url, { token }), [url, token]);\n const api = useMemo(\n () => mockServerScreenApi(client, deviceId),\n [client, deviceId],\n );\n const device = useMockServerDevice(client, deviceId);\n\n // Decides touch or buttons, so nothing renders until it is known. An\n // unreadable record still shows the screen, and its errors.\n if (device === undefined) return null;\n\n return (\n <DeviceScreen\n api={api}\n deviceType={device?.device_type ?? \"\"}\n firmwareVersion={device?.firmware_version}\n {...props}\n />\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,GAAS,WAAAC,MAAe,QAC/B,OAAS,cAAAC,MAAkB,qCAE3B,OAAS,gBAAAC,MAA4C,iBACrD,OAAS,uBAAAC,MAA2B,wBACpC,OAAS,uBAAAC,MAA2B,wBAY7B,MAAMC,EAAoD,CAAC,CAChE,IAAAC,EACA,MAAAC,EACA,SAAAC,EACA,GAAGC,CACL,IAAM,CACJ,MAAMC,EAASV,EAAQ,IAAM,IAAIC,EAAWK,EAAK,CAAE,MAAAC,CAAM,CAAC,EAAG,CAACD,EAAKC,CAAK,CAAC,EACnEI,EAAMX,EACV,IAAMG,EAAoBO,EAAQF,CAAQ,EAC1C,CAACE,EAAQF,CAAQ,CACnB,EACMI,EAASR,EAAoBM,EAAQF,CAAQ,EAInD,OAAII,IAAW,OAAkB,KAG/Bb,EAAA,cAACG,EAAA,CACC,IAAKS,EACL,WAAYC,GAAQ,aAAe,GACnC,gBAAiBA,GAAQ,iBACxB,GAAGH,EACN,CAEJ",
|
|
6
|
+
"names": ["React", "useMemo", "MockClient", "DeviceScreen", "mockServerScreenApi", "useMockServerDevice", "MockServerDevice", "url", "token", "deviceId", "props", "client", "api", "device"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/ScreenFrame.tsx"],
|
|
4
|
+
"sourcesContent": ["import React from \"react\";\n\ntype ScreenFrameProps = {\n children: React.ReactNode;\n};\n\n/**\n * The bezel around whatever stands in for the screen. The border lives here,\n * outside the content, so the live frame and the app list inside it take\n * exactly the screen's size.\n */\nexport const ScreenFrame: React.FC<ScreenFrameProps> = ({ children }) => (\n <div className=\"border-muted @container relative overflow-hidden rounded-md border\">\n {children}\n </div>\n);\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAW,QAWX,MAAMC,EAA0C,CAAC,CAAE,SAAAC,CAAS,IACjEF,EAAA,cAAC,OAAI,UAAU,sEACZE,CACH",
|
|
6
|
+
"names": ["React", "ScreenFrame", "children"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Apex as r,Flex as c,Nano as t,Stax as l}from"@ledgerhq/lumen-ui-react/symbols";const e=(n,o)=>({label:n,icon:t,touch:!1,speculos:!0,screenWidth:128,screenHeight:o,lightScreen:!1}),s={nanoS:{...e("Nano S",32),speculos:!1},nanoSP:e("Nano S Plus",64),nanoX:e("Nano X",64),stax:{label:"Stax",icon:l,touch:!0,speculos:!0,screenWidth:400,screenHeight:672,lightScreen:!0},flex:{label:"Flex",icon:c,touch:!0,speculos:!0,screenWidth:480,screenHeight:600,lightScreen:!0},apexp:{label:"Apex",icon:r,touch:!0,speculos:!0,screenWidth:300,screenHeight:400,lightScreen:!0}},i=e("Device",64),u=n=>s[n]??i;export{u as findDeviceScreenModel};
|
|
2
|
+
//# sourceMappingURL=deviceModels.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/deviceModels.ts"],
|
|
4
|
+
"sourcesContent": ["import { Apex, Flex, Nano, Stax } from \"@ledgerhq/lumen-ui-react/symbols\";\n\nexport interface DeviceScreenModel {\n readonly label: string;\n readonly icon: typeof Nano;\n readonly touch: boolean;\n /** Whether Speculos has an emulator for it, so it can have a screen. */\n readonly speculos: boolean;\n /** In device pixels. */\n readonly screenWidth: number;\n readonly screenHeight: number;\n readonly lightScreen: boolean;\n}\n\nconst nano = (label: string, screenHeight: number): DeviceScreenModel => ({\n label,\n icon: Nano,\n touch: false,\n speculos: true,\n screenWidth: 128,\n screenHeight,\n lightScreen: false,\n});\n\n/** Keyed by the mock server's `device_type`, a DMK `DeviceModelId`. */\nconst MODELS: Record<string, DeviceScreenModel> = {\n nanoS: { ...nano(\"Nano S\", 32), speculos: false },\n nanoSP: nano(\"Nano S Plus\", 64),\n nanoX: nano(\"Nano X\", 64),\n stax: {\n label: \"Stax\",\n icon: Stax,\n touch: true,\n speculos: true,\n screenWidth: 400,\n screenHeight: 672,\n lightScreen: true,\n },\n flex: {\n label: \"Flex\",\n icon: Flex,\n touch: true,\n speculos: true,\n screenWidth: 480,\n screenHeight: 600,\n lightScreen: true,\n },\n apexp: {\n label: \"Apex\",\n icon: Apex,\n touch: true,\n speculos: true,\n screenWidth: 300,\n screenHeight: 400,\n lightScreen: true,\n },\n};\n\nconst UNKNOWN: DeviceScreenModel = nano(\"Device\", 64);\n\nexport const findDeviceScreenModel = (deviceType: string): DeviceScreenModel =>\n MODELS[deviceType] ?? UNKNOWN;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,QAAAC,EAAM,QAAAC,EAAM,QAAAC,MAAY,mCAcvC,MAAMC,EAAO,CAACC,EAAeC,KAA6C,CACxE,MAAAD,EACA,KAAMH,EACN,MAAO,GACP,SAAU,GACV,YAAa,IACb,aAAAI,EACA,YAAa,EACf,GAGMC,EAA4C,CAChD,MAAO,CAAE,GAAGH,EAAK,SAAU,EAAE,EAAG,SAAU,EAAM,EAChD,OAAQA,EAAK,cAAe,EAAE,EAC9B,MAAOA,EAAK,SAAU,EAAE,EACxB,KAAM,CACJ,MAAO,OACP,KAAMD,EACN,MAAO,GACP,SAAU,GACV,YAAa,IACb,aAAc,IACd,YAAa,EACf,EACA,KAAM,CACJ,MAAO,OACP,KAAMF,EACN,MAAO,GACP,SAAU,GACV,YAAa,IACb,aAAc,IACd,YAAa,EACf,EACA,MAAO,CACL,MAAO,OACP,KAAMD,EACN,MAAO,GACP,SAAU,GACV,YAAa,IACb,aAAc,IACd,YAAa,EACf,CACF,EAEMQ,EAA6BJ,EAAK,SAAU,EAAE,EAEvCK,EAAyBC,GACpCH,EAAOG,CAAU,GAAKF",
|
|
6
|
+
"names": ["Apex", "Flex", "Nano", "Stax", "nano", "label", "screenHeight", "MODELS", "UNKNOWN", "findDeviceScreenModel", "deviceType"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{findDeviceScreenModel as o}from"./deviceModels";import{DeviceScreen as p}from"./DeviceScreen";import{MockServerDevice as v}from"./MockServerDevice";import{mockServerScreenApi as i}from"./mockServerScreenApi";import{useMockServerDevice as D}from"./useMockServerDevice";export{p as DeviceScreen,v as MockServerDevice,o as findDeviceScreenModel,i as mockServerScreenApi,D as useMockServerDevice};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["export { type DeviceScreenModel, findDeviceScreenModel } from \"./deviceModels\";\nexport { DeviceScreen, type DeviceScreenProps } from \"./DeviceScreen\";\nexport {\n MockServerDevice,\n type MockServerDeviceProps,\n} from \"./MockServerDevice\";\nexport { mockServerScreenApi } from \"./mockServerScreenApi\";\nexport type { DeviceScreenState, ScreenApi } from \"./types\";\nexport { useMockServerDevice } from \"./useMockServerDevice\";\n"],
|
|
5
|
+
"mappings": "AAAA,OAAiC,yBAAAA,MAA6B,iBAC9D,OAAS,gBAAAC,MAA4C,iBACrD,OACE,oBAAAC,MAEK,qBACP,OAAS,uBAAAC,MAA2B,wBAEpC,OAAS,uBAAAC,MAA2B",
|
|
6
|
+
"names": ["findDeviceScreenModel", "DeviceScreen", "MockServerDevice", "mockServerScreenApi", "useMockServerDevice"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const c=o=>o?.status===409,a=(o,r)=>({screenshot:async()=>{try{return await o.getScreenshot(r)}catch(n){if(c(n))return null;throw n}},idle:async()=>({kind:"os-info",device:await o.getDevice(r)}),pressButton:(n,t)=>o.pressButton(r,n,t),touch:(n,t,e)=>o.touchScreen(r,n,t,e),openApp:async n=>{const t=new TextEncoder().encode(n);if(t.length>255)throw new Error(`App name too long to open: ${n}`);const{response:e}=await o.sendApdu(r,Uint8Array.from([224,216,0,0,t.length,...t])),s=e.slice(-4);if(s!=="9000")throw new Error(`Could not open ${n} (${s})`)}});export{a as mockServerScreenApi};
|
|
2
|
+
//# sourceMappingURL=mockServerScreenApi.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/mockServerScreenApi.ts"],
|
|
4
|
+
"sourcesContent": ["import { type MockClient } from \"@ledgerhq/device-mockserver-client\";\n\nimport { type ScreenApi } from \"./types\";\n\n/** The proxy answers 409 when the device has no Speculos instance. */\nconst isNoInstance = (error: unknown): boolean =>\n (error as { status?: unknown } | null)?.status === 409;\n\nexport const mockServerScreenApi = (\n client: MockClient,\n deviceId: string,\n): ScreenApi => ({\n screenshot: async () => {\n try {\n return await client.getScreenshot(deviceId);\n } catch (error) {\n if (isNoInstance(error)) return null;\n throw error;\n }\n },\n idle: async () => ({\n kind: \"os-info\",\n device: await client.getDevice(deviceId),\n }),\n pressButton: (button, action) => client.pressButton(deviceId, button, action),\n touch: (x, y, action) => client.touchScreen(deviceId, x, y, action),\n openApp: async (appName) => {\n const name = new TextEncoder().encode(appName);\n // Lc is a single byte.\n if (name.length > 0xff) {\n throw new Error(`App name too long to open: ${appName}`);\n }\n const { response } = await client.sendApdu(\n deviceId,\n Uint8Array.from([0xe0, 0xd8, 0x00, 0x00, name.length, ...name]),\n );\n const statusWord = response.slice(-4);\n if (statusWord !== \"9000\") {\n throw new Error(`Could not open ${appName} (${statusWord})`);\n }\n },\n});\n"],
|
|
5
|
+
"mappings": "AAKA,MAAMA,EAAgBC,GACnBA,GAAuC,SAAW,IAExCC,EAAsB,CACjCC,EACAC,KACe,CACf,WAAY,SAAY,CACtB,GAAI,CACF,OAAO,MAAMD,EAAO,cAAcC,CAAQ,CAC5C,OAASH,EAAO,CACd,GAAID,EAAaC,CAAK,EAAG,OAAO,KAChC,MAAMA,CACR,CACF,EACA,KAAM,UAAa,CACjB,KAAM,UACN,OAAQ,MAAME,EAAO,UAAUC,CAAQ,CACzC,GACA,YAAa,CAACC,EAAQC,IAAWH,EAAO,YAAYC,EAAUC,EAAQC,CAAM,EAC5E,MAAO,CAACC,EAAGC,EAAGF,IAAWH,EAAO,YAAYC,EAAUG,EAAGC,EAAGF,CAAM,EAClE,QAAS,MAAOG,GAAY,CAC1B,MAAMC,EAAO,IAAI,YAAY,EAAE,OAAOD,CAAO,EAE7C,GAAIC,EAAK,OAAS,IAChB,MAAM,IAAI,MAAM,8BAA8BD,CAAO,EAAE,EAEzD,KAAM,CAAE,SAAAE,CAAS,EAAI,MAAMR,EAAO,SAChCC,EACA,WAAW,KAAK,CAAC,IAAM,IAAM,EAAM,EAAMM,EAAK,OAAQ,GAAGA,CAAI,CAAC,CAChE,EACME,EAAaD,EAAS,MAAM,EAAE,EACpC,GAAIC,IAAe,OACjB,MAAM,IAAI,MAAM,kBAAkBH,CAAO,KAAKG,CAAU,GAAG,CAE/D,CACF",
|
|
6
|
+
"names": ["isNoInstance", "error", "mockServerScreenApi", "client", "deviceId", "button", "action", "x", "y", "appName", "name", "response", "statusWord"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{mockServerScreenApi as o}from"./mockServerScreenApi";const n=e=>({getScreenshot:vi.fn(),getDevice:vi.fn(),pressButton:vi.fn(()=>Promise.resolve()),touchScreen:vi.fn(()=>Promise.resolve()),...e});describe("mockServerScreenApi",()=>{it("resolves the screenshot of the device",async()=>{const e=new Blob(["png"]),t=n({getScreenshot:vi.fn(()=>Promise.resolve(e))});await expect(o(t,"device-1").screenshot()).resolves.toBe(e),expect(t.getScreenshot).toHaveBeenCalledWith("device-1")}),it("resolves no screenshot when the device has no Speculos instance",async()=>{const e=n({getScreenshot:vi.fn(()=>Promise.reject({status:409}))});await expect(o(e,"device-1").screenshot()).resolves.toBeNull()}),it("rethrows any other screenshot failure",async()=>{const e=Object.assign(new Error("boom"),{status:500}),t=n({getScreenshot:vi.fn(()=>Promise.reject(e))});await expect(o(t,"device-1").screenshot()).rejects.toBe(e)}),it("shows the device record while idle",async()=>{const e={id:"device-1",device_type:"nanoX"},t=n({getDevice:vi.fn(()=>Promise.resolve(e))});await expect(o(t,"device-1").idle?.()).resolves.toEqual({kind:"os-info",device:e})}),it("forwards buttons and touches to the device",async()=>{const e=n({}),t=o(e,"device-1");await t.pressButton("left","press"),await t.touch(10,20,"release"),expect(e.pressButton).toHaveBeenCalledWith("device-1","left","press"),expect(e.touchScreen).toHaveBeenCalledWith("device-1",10,20,"release")}),it("opens an app by name",async()=>{const e=vi.fn(()=>Promise.resolve({response:"9000"}));await o(n({sendApdu:e}),"device-1").openApp?.("Bitcoin"),expect(e).toHaveBeenCalledWith("device-1",Uint8Array.from([224,216,0,0,7,...new TextEncoder().encode("Bitcoin")]))}),it("fails to open an app the device refuses",async()=>{const e=vi.fn(()=>Promise.resolve({response:"6807"})),t=o(n({sendApdu:e}),"device-1");await expect(t.openApp?.("Bitcoin")).rejects.toThrow("6807")}),it("refuses an app name too long for one APDU",async()=>{const e=vi.fn(()=>Promise.resolve({response:"9000"})),t=o(n({sendApdu:e}),"device-1");await expect(t.openApp?.("a".repeat(256))).rejects.toThrow("too long"),expect(e).not.toHaveBeenCalled()})});
|
|
2
|
+
//# sourceMappingURL=mockServerScreenApi.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/mockServerScreenApi.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { type MockClient } from \"@ledgerhq/device-mockserver-client\";\n\nimport { mockServerScreenApi } from \"./mockServerScreenApi\";\n\nconst aClient = (overrides: Partial<Record<keyof MockClient, unknown>>) =>\n ({\n getScreenshot: vi.fn(),\n getDevice: vi.fn(),\n pressButton: vi.fn(() => Promise.resolve()),\n touchScreen: vi.fn(() => Promise.resolve()),\n ...overrides,\n }) as unknown as MockClient;\n\ndescribe(\"mockServerScreenApi\", () => {\n it(\"resolves the screenshot of the device\", async () => {\n const blob = new Blob([\"png\"]);\n const client = aClient({\n getScreenshot: vi.fn(() => Promise.resolve(blob)),\n });\n\n await expect(\n mockServerScreenApi(client, \"device-1\").screenshot(),\n ).resolves.toBe(blob);\n expect(client.getScreenshot).toHaveBeenCalledWith(\"device-1\");\n });\n\n it(\"resolves no screenshot when the device has no Speculos instance\", async () => {\n const client = aClient({\n getScreenshot: vi.fn(() => Promise.reject({ status: 409 })),\n });\n\n await expect(\n mockServerScreenApi(client, \"device-1\").screenshot(),\n ).resolves.toBeNull();\n });\n\n it(\"rethrows any other screenshot failure\", async () => {\n const error = Object.assign(new Error(\"boom\"), { status: 500 });\n const client = aClient({\n getScreenshot: vi.fn(() => Promise.reject(error)),\n });\n\n await expect(\n mockServerScreenApi(client, \"device-1\").screenshot(),\n ).rejects.toBe(error);\n });\n\n it(\"shows the device record while idle\", async () => {\n const device = { id: \"device-1\", device_type: \"nanoX\" };\n const client = aClient({ getDevice: vi.fn(() => Promise.resolve(device)) });\n\n await expect(\n mockServerScreenApi(client, \"device-1\").idle?.(),\n ).resolves.toEqual({\n kind: \"os-info\",\n device,\n });\n });\n\n it(\"forwards buttons and touches to the device\", async () => {\n const client = aClient({});\n const api = mockServerScreenApi(client, \"device-1\");\n\n await api.pressButton(\"left\", \"press\");\n await api.touch(10, 20, \"release\");\n\n expect(client.pressButton).toHaveBeenCalledWith(\n \"device-1\",\n \"left\",\n \"press\",\n );\n expect(client.touchScreen).toHaveBeenCalledWith(\n \"device-1\",\n 10,\n 20,\n \"release\",\n );\n });\n\n it(\"opens an app by name\", async () => {\n const sendApdu = vi.fn(() => Promise.resolve({ response: \"9000\" }));\n const api = mockServerScreenApi(aClient({ sendApdu }), \"device-1\");\n\n await api.openApp?.(\"Bitcoin\");\n\n expect(sendApdu).toHaveBeenCalledWith(\n \"device-1\",\n Uint8Array.from([\n 0xe0,\n 0xd8,\n 0x00,\n 0x00,\n 0x07,\n ...new TextEncoder().encode(\"Bitcoin\"),\n ]),\n );\n });\n\n it(\"fails to open an app the device refuses\", async () => {\n const sendApdu = vi.fn(() => Promise.resolve({ response: \"6807\" }));\n const api = mockServerScreenApi(aClient({ sendApdu }), \"device-1\");\n\n await expect(api.openApp?.(\"Bitcoin\")).rejects.toThrow(\"6807\");\n });\n\n it(\"refuses an app name too long for one APDU\", async () => {\n const sendApdu = vi.fn(() => Promise.resolve({ response: \"9000\" }));\n const api = mockServerScreenApi(aClient({ sendApdu }), \"device-1\");\n\n await expect(api.openApp?.(\"a\".repeat(256))).rejects.toThrow(\"too long\");\n expect(sendApdu).not.toHaveBeenCalled();\n });\n});\n"],
|
|
5
|
+
"mappings": "AAEA,OAAS,uBAAAA,MAA2B,wBAEpC,MAAMC,EAAWC,IACd,CACC,cAAe,GAAG,GAAG,EACrB,UAAW,GAAG,GAAG,EACjB,YAAa,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAC,EAC1C,YAAa,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAC,EAC1C,GAAGA,CACL,GAEF,SAAS,sBAAuB,IAAM,CACpC,GAAG,wCAAyC,SAAY,CACtD,MAAMC,EAAO,IAAI,KAAK,CAAC,KAAK,CAAC,EACvBC,EAASH,EAAQ,CACrB,cAAe,GAAG,GAAG,IAAM,QAAQ,QAAQE,CAAI,CAAC,CAClD,CAAC,EAED,MAAM,OACJH,EAAoBI,EAAQ,UAAU,EAAE,WAAW,CACrD,EAAE,SAAS,KAAKD,CAAI,EACpB,OAAOC,EAAO,aAAa,EAAE,qBAAqB,UAAU,CAC9D,CAAC,EAED,GAAG,kEAAmE,SAAY,CAChF,MAAMA,EAASH,EAAQ,CACrB,cAAe,GAAG,GAAG,IAAM,QAAQ,OAAO,CAAE,OAAQ,GAAI,CAAC,CAAC,CAC5D,CAAC,EAED,MAAM,OACJD,EAAoBI,EAAQ,UAAU,EAAE,WAAW,CACrD,EAAE,SAAS,SAAS,CACtB,CAAC,EAED,GAAG,wCAAyC,SAAY,CACtD,MAAMC,EAAQ,OAAO,OAAO,IAAI,MAAM,MAAM,EAAG,CAAE,OAAQ,GAAI,CAAC,EACxDD,EAASH,EAAQ,CACrB,cAAe,GAAG,GAAG,IAA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AG,UAAU,EAEjE,MAAM,OAAOD,EAAI,UAAU,SAAS,CAAC,EAAE,QAAQ,QAAQ,MAAM,CAC/D,CAAC,EAED,GAAG,4CAA6C,SAAY,CAC1D,MAAMC,EAAW,GAAG,GAAG,IAAM,QAAQ,QAAQ,CAAE,SAAU,MAAO,CAAC,CAAC,EAC5DD,EAAMP,EAAoBC,EAAQ,CAAE,SAAAO,CAAS,CAAC,EAAG,UAAU,EAEjE,MAAM,OAAOD,EAAI,UAAU,IAAI,OAAO,GAAG,CAAC,CAAC,EAAE,QAAQ,QAAQ,UAAU,EACvE,OAAOC,CAAQ,EAAE,IAAI,iBAAiB,CACxC,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["mockServerScreenApi", "aClient", "overrides", "blob", "client", "error", "device", "api", "sendApdu"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{useEffect as u,useState as f}from"react";function o(i,e){const[r,t]=f();return u(()=>{let n=!1;if(t(void 0),!!e)return i.getDevice(e).then(c=>{n||t(c)}).catch(()=>{n||t(null)}),()=>{n=!0}},[i,e]),r}export{o as useMockServerDevice};
|
|
2
|
+
//# sourceMappingURL=useMockServerDevice.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useMockServerDevice.ts"],
|
|
4
|
+
"sourcesContent": ["import { useEffect, useState } from \"react\";\nimport {\n type Device,\n type MockClient,\n} from \"@ledgerhq/device-mockserver-client\";\n\n/**\n * The mock server's record of a device: undefined while it loads, or while no\n * device id is given, and null when it could not be read.\n */\nexport function useMockServerDevice(\n client: MockClient,\n deviceId: string,\n): Device | null | undefined {\n const [device, setDevice] = useState<Device | null>();\n\n useEffect(() => {\n let cancelled = false;\n setDevice(undefined);\n if (!deviceId) return;\n client\n .getDevice(deviceId)\n .then((record) => {\n if (!cancelled) setDevice(record);\n })\n .catch(() => {\n if (!cancelled) setDevice(null);\n });\n return () => {\n cancelled = true;\n };\n }, [client, deviceId]);\n\n return device;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,aAAAA,EAAW,YAAAC,MAAgB,QAU7B,SAASC,EACdC,EACAC,EAC2B,CAC3B,KAAM,CAACC,EAAQC,CAAS,EAAIL,EAAwB,EAEpD,OAAAD,EAAU,IAAM,CACd,IAAIO,EAAY,GAEhB,GADAD,EAAU,MAAS,EACf,EAACF,EACL,OAAAD,EACG,UAAUC,CAAQ,EAClB,KAAMI,GAAW,CACXD,GAAWD,EAAUE,CAAM,CAClC,CAAC,EACA,MAAM,IAAM,CACND,GAAWD,EAAU,IAAI,CAChC,CAAC,EACI,IAAM,CACXC,EAAY,EACd,CACF,EAAG,CAACJ,EAAQC,CAAQ,CAAC,EAEdC,CACT",
|
|
6
|
+
"names": ["useEffect", "useState", "useMockServerDevice", "client", "deviceId", "device", "setDevice", "cancelled", "record"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{useCallback as m,useEffect as p,useMemo as R,useRef as s,useState as b}from"react";const y=500,E=2e3,D=3,U=r=>r instanceof Error?r.message:String(r);function T(r,v){const[L,i]=b({kind:"loading"}),o=s(null),a=s(!1),l=s(!1);l.current=L.kind==="image";const g=s(0),f=s(0),u=m(n=>{l.current&&++g.current<=D||i({kind:"error",message:U(n)})},[]),c=m(()=>{o.current&&(URL.revokeObjectURL(o.current),o.current=null)},[]),k=s(()=>{}),h=R(()=>{const n=e=>void e.then(()=>k.current()).catch(u);return{pressButton:(e,t)=>n(r.pressButton(e,t)),touch:(e,t,S)=>n(r.touch(e,t,S))}},[r,u]),d=m(async()=>{if(a.current)return;a.current=!0;const n=f.current,e=()=>n!==f.current;try{const t=await r.screenshot();if(e())return;if(g.current=0,t)c(),o.current=URL.createObjectURL(t),i({kind:"image",src:o.current,input:h});else{const S=await r.idle?.();if(e())return;c(),i(S??{kind:"error",message:"No screen to capture"})}}catch(t){e()||u(t)}finally{a.current=!1}},[r,h,u,c]);return k.current=()=>void d(),p(()=>{if(!v){c(),i({kind:"loading"});return}let n,e=!1;const t=async()=>{document.hidden||await d(),!e&&(n=setTimeout(()=>void t(),l.current?y:E))};return t(),()=>{e=!0,clearTimeout(n),f.current++}},[v,d,c]),p(()=>c,[c]),L}export{T as useScreenPolling};
|
|
2
|
+
//# sourceMappingURL=useScreenPolling.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/useScreenPolling.ts"],
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport {\n type DeviceScreenInput,\n type DeviceScreenState,\n type ScreenApi,\n} from \"./types\";\n\nconst SCREEN_POLL_MS = 500;\nconst IDLE_POLL_MS = 2000;\n/**\n * An app quitting fails a few calls while Speculos shuts down; the last frame\n * stays up through them rather than flashing an error before the dashboard.\n */\nconst LIVE_FAILURES_TOLERATED = 3;\n\nconst describe = (error: unknown): string =>\n error instanceof Error ? error.message : String(error);\n\nexport function useScreenPolling(\n api: ScreenApi,\n polling: boolean,\n): DeviceScreenState {\n const [state, setState] = useState<DeviceScreenState>({ kind: \"loading\" });\n\n const objectUrl = useRef<string | null>(null);\n const inFlight = useRef(false);\n const isLive = useRef(false);\n isLive.current = state.kind === \"image\";\n const liveFailures = useRef(0);\n /** Bumped when polling stops, so a response still in flight is dropped. */\n const generation = useRef(0);\n\n const fail = useCallback((error: unknown) => {\n if (isLive.current && ++liveFailures.current <= LIVE_FAILURES_TOLERATED) {\n return;\n }\n setState({ kind: \"error\", message: describe(error) });\n }, []);\n\n const releaseObjectUrl = useCallback(() => {\n if (objectUrl.current) {\n URL.revokeObjectURL(objectUrl.current);\n objectUrl.current = null;\n }\n }, []);\n\n /**\n * Input handlers refresh straight after acting. Going through a ref keeps\n * them stable, so the <img> is not remounted on every poll.\n */\n const refreshRef = useRef<() => void>(() => {});\n\n const input = useMemo<DeviceScreenInput>(() => {\n const send = (call: Promise<void>) =>\n void call.then(() => refreshRef.current()).catch(fail);\n\n return {\n pressButton: (button, action) => send(api.pressButton(button, action)),\n touch: (x, y, action) => send(api.touch(x, y, action)),\n };\n }, [api, fail]);\n\n const refresh = useCallback(async () => {\n if (inFlight.current) return;\n inFlight.current = true;\n const started = generation.current;\n const stale = () => started !== generation.current;\n try {\n const blob = await api.screenshot();\n if (stale()) return;\n liveFailures.current = 0;\n if (blob) {\n releaseObjectUrl();\n objectUrl.current = URL.createObjectURL(blob);\n setState({ kind: \"image\", src: objectUrl.current, input });\n } else {\n const idle = await api.idle?.();\n if (stale()) return;\n releaseObjectUrl();\n setState(idle ?? { kind: \"error\", message: \"No screen to capture\" });\n }\n } catch (error) {\n if (!stale()) fail(error);\n } finally {\n inFlight.current = false;\n }\n }, [api, input, fail, releaseObjectUrl]);\n refreshRef.current = () => void refresh();\n\n useEffect(() => {\n if (!polling) {\n // Drop the frame rather than keep a revoked object URL around, which\n // would flash a broken image when the panel reopens.\n releaseObjectUrl();\n setState({ kind: \"loading\" });\n return;\n }\n\n let timer: ReturnType<typeof setTimeout>;\n let cancelled = false;\n\n const tick = async () => {\n if (!document.hidden) await refresh();\n if (cancelled) return;\n timer = setTimeout(\n () => void tick(),\n isLive.current ? SCREEN_POLL_MS : IDLE_POLL_MS,\n );\n };\n void tick();\n\n return () => {\n cancelled = true;\n clearTimeout(timer);\n generation.current++;\n };\n }, [polling, refresh, releaseObjectUrl]);\n\n useEffect(() => releaseObjectUrl, [releaseObjectUrl]);\n\n return state;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,WAAAC,EAAS,UAAAC,EAAQ,YAAAC,MAAgB,QAQlE,MAAMC,EAAiB,IACjBC,EAAe,IAKfC,EAA0B,EAE1BC,EAAYC,GAChBA,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAA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B,CAAI,EAC5CnB,EAAS,CAAE,KAAM,QAAS,IAAKC,EAAU,QAAS,MAAAQ,CAAM,CAAC,MACpD,CACL,MAAMW,EAAO,MAAMvB,EAAI,OAAO,EAC9B,GAAIqB,EAAM,EAAG,OACbX,EAAiB,EACjBP,EAASoB,GAAQ,CAAE,KAAM,QAAS,QAAS,sBAAuB,CAAC,CACrE,CACF,OAASzB,EAAO,CACTuB,EAAM,GAAGZ,EAAKX,CAAK,CAC1B,QAAE,CACAO,EAAS,QAAU,EACrB,CACF,EAAG,CAACL,EAAKY,EAAOH,EAAMC,CAAgB,CAAC,EACvC,OAAAC,EAAW,QAAU,IAAM,KAAKQ,EAAQ,EAExC7B,EAAU,IAAM,CACd,GAAI,CAACW,EAAS,CAGZS,EAAiB,EACjBP,EAAS,CAAE,KAAM,SAAU,CAAC,EAC5B,MACF,CAEA,IAAIqB,EACAC,EAAY,GAEhB,MAAMC,EAAO,SAAY,CAClB,SAAS,QAAQ,MAAMP,EAAQ,EAChC,CAAAM,IACJD,EAAQ,WACN,IAAM,KAAKE,EAAK,EAChBpB,EAAO,QAAUZ,EAAiBC,CACpC,EACF,EACA,OAAK+B,EAAK,EAEH,IAAM,CACXD,EAAY,GACZ,aAAaD,CAAK,EAClBhB,EAAW,SACb,CACF,EAAG,CAACP,EAASkB,EAAST,CAAgB,CAAC,EAEvCpB,EAAU,IAAMoB,EAAkB,CAACA,CAAgB,CAAC,EAE7CR,CACT",
|
|
6
|
+
"names": ["useCallback", "useEffect", "useMemo", "useRef", "useState", "SCREEN_POLL_MS", "IDLE_POLL_MS", "LIVE_FAILURES_TOLERATED", "describe", "error", "useScreenPolling", "api", "polling", "state", "setState", "objectUrl", "inFlight", "isLive", "liveFailures", "generation", "fail", "releaseObjectUrl", "refreshRef", "input", "send", "call", "button", "action", "x", "y", "refresh", "started", "stale", "blob", "idle", "timer", "cancelled", "tick"]
|
|
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
|
+
import React from "react";
|
|
2
|
+
import { type Device } from "@ledgerhq/device-mockserver-client";
|
|
3
|
+
import { type DeviceScreenModel } from "./deviceModels";
|
|
4
|
+
type DeviceOsInfoProps = {
|
|
5
|
+
device: Device;
|
|
6
|
+
model: DeviceScreenModel;
|
|
7
|
+
/** Omitted, the apps are listed but cannot be opened. */
|
|
8
|
+
onOpenApp?: (appName: string) => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export declare const DeviceOsInfo: React.FC<DeviceOsInfoProps>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=DeviceOsInfo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeviceOsInfo.d.ts","sourceRoot":"","sources":["../../../src/DeviceOsInfo.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAEjE,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AA0CxD,KAAK,iBAAiB,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,iBAAiB,CAAC;IACzB,yDAAyD;IACzD,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAiHpD,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type ScreenApi } from "./types";
|
|
3
|
+
export type DeviceScreenProps = {
|
|
4
|
+
api: ScreenApi;
|
|
5
|
+
/** The mock server's `device_type`, a DMK `DeviceModelId`. */
|
|
6
|
+
deviceType: string;
|
|
7
|
+
/** Shown next to the model name in the floating window's header. */
|
|
8
|
+
firmwareVersion?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Render as a window over the page that can be dragged by its header and
|
|
11
|
+
* collapsed to it, rather than inline where it is placed.
|
|
12
|
+
*/
|
|
13
|
+
floating?: boolean;
|
|
14
|
+
defaultCollapsed?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const DeviceScreen: React.FC<DeviceScreenProps>;
|
|
17
|
+
//# sourceMappingURL=DeviceScreen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeviceScreen.d.ts","sourceRoot":"","sources":["../../../src/DeviceScreen.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAShD,OAAO,EAA0B,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAGjE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,SAAS,CAAC;IACf,8DAA8D;IAC9D,UAAU,EAAE,MAAM,CAAC;IACnB,oEAAoE;IACpE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAcF,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAgCpD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type SpeculosAction, type SpeculosButton } from "@ledgerhq/device-mockserver-client";
|
|
3
|
+
type DeviceScreenButtonsProps = {
|
|
4
|
+
onPress: (button: SpeculosButton, action: SpeculosAction) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare const DeviceScreenButtons: React.FC<DeviceScreenButtonsProps>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=DeviceScreenButtons.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeviceScreenButtons.d.ts","sourceRoot":"","sources":["../../../src/DeviceScreenButtons.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAC9D,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,oCAAoC,CAAC;AAwB5C,KAAK,wBAAwB,GAAG;IAC9B,OAAO,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;CACnE,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CA8ElE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type SpeculosAction } from "@ledgerhq/device-mockserver-client";
|
|
3
|
+
type DeviceScreenImageProps = {
|
|
4
|
+
src: string;
|
|
5
|
+
/** Omitted for a button-driven device. */
|
|
6
|
+
onTouch?: (x: number, y: number, action: SpeculosAction) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const DeviceScreenImage: React.FC<DeviceScreenImageProps>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=DeviceScreenImage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeviceScreenImage.d.ts","sourceRoot":"","sources":["../../../src/DeviceScreenImage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,oCAAoC,CAAC;AASzE,KAAK,sBAAsB,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,0CAA0C;IAC1C,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;CAClE,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAkG9D,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type DeviceScreenProps } from "./DeviceScreen";
|
|
3
|
+
export type MockServerDeviceProps = Pick<DeviceScreenProps, "floating" | "defaultCollapsed"> & {
|
|
4
|
+
url: string;
|
|
5
|
+
/** Omitted, the client opens a session of its own. */
|
|
6
|
+
token?: string;
|
|
7
|
+
deviceId: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const MockServerDevice: React.FC<MockServerDeviceProps>;
|
|
10
|
+
//# sourceMappingURL=MockServerDevice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockServerDevice.d.ts","sourceRoot":"","sources":["../../../src/MockServerDevice.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAGvC,OAAO,EAAgB,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAItE,MAAM,MAAM,qBAAqB,GAAG,IAAI,CACtC,iBAAiB,EACjB,UAAU,GAAG,kBAAkB,CAChC,GAAG;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAyB5D,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type ScreenFrameProps = {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* The bezel around whatever stands in for the screen. The border lives here,
|
|
7
|
+
* outside the content, so the live frame and the app list inside it take
|
|
8
|
+
* exactly the screen's size.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ScreenFrame: React.FC<ScreenFrameProps>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=ScreenFrame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScreenFrame.d.ts","sourceRoot":"","sources":["../../../src/ScreenFrame.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,KAAK,gBAAgB,GAAG;IACtB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAIlD,CAAC"}
|