@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.
Files changed (91) hide show
  1. package/LICENSE.MD +202 -0
  2. package/README.md +45 -0
  3. package/lib/cjs/index.js +2 -0
  4. package/lib/cjs/index.js.map +7 -0
  5. package/lib/cjs/package.json +67 -0
  6. package/lib/cjs/src/DeviceOsInfo.js +2 -0
  7. package/lib/cjs/src/DeviceOsInfo.js.map +7 -0
  8. package/lib/cjs/src/DeviceScreen.js +2 -0
  9. package/lib/cjs/src/DeviceScreen.js.map +7 -0
  10. package/lib/cjs/src/DeviceScreenButtons.js +2 -0
  11. package/lib/cjs/src/DeviceScreenButtons.js.map +7 -0
  12. package/lib/cjs/src/DeviceScreenImage.js +2 -0
  13. package/lib/cjs/src/DeviceScreenImage.js.map +7 -0
  14. package/lib/cjs/src/MockServerDevice.js +2 -0
  15. package/lib/cjs/src/MockServerDevice.js.map +7 -0
  16. package/lib/cjs/src/ScreenFrame.js +2 -0
  17. package/lib/cjs/src/ScreenFrame.js.map +7 -0
  18. package/lib/cjs/src/deviceModels.js +2 -0
  19. package/lib/cjs/src/deviceModels.js.map +7 -0
  20. package/lib/cjs/src/index.js +2 -0
  21. package/lib/cjs/src/index.js.map +7 -0
  22. package/lib/cjs/src/mockServerScreenApi.js +2 -0
  23. package/lib/cjs/src/mockServerScreenApi.js.map +7 -0
  24. package/lib/cjs/src/mockServerScreenApi.test.js +2 -0
  25. package/lib/cjs/src/mockServerScreenApi.test.js.map +7 -0
  26. package/lib/cjs/src/types.js +2 -0
  27. package/lib/cjs/src/types.js.map +7 -0
  28. package/lib/cjs/src/useMockServerDevice.js +2 -0
  29. package/lib/cjs/src/useMockServerDevice.js.map +7 -0
  30. package/lib/cjs/src/useScreenPolling.js +2 -0
  31. package/lib/cjs/src/useScreenPolling.js.map +7 -0
  32. package/lib/esm/index.js +2 -0
  33. package/lib/esm/index.js.map +7 -0
  34. package/lib/esm/package.json +67 -0
  35. package/lib/esm/src/DeviceOsInfo.js +2 -0
  36. package/lib/esm/src/DeviceOsInfo.js.map +7 -0
  37. package/lib/esm/src/DeviceScreen.js +2 -0
  38. package/lib/esm/src/DeviceScreen.js.map +7 -0
  39. package/lib/esm/src/DeviceScreenButtons.js +2 -0
  40. package/lib/esm/src/DeviceScreenButtons.js.map +7 -0
  41. package/lib/esm/src/DeviceScreenImage.js +2 -0
  42. package/lib/esm/src/DeviceScreenImage.js.map +7 -0
  43. package/lib/esm/src/MockServerDevice.js +2 -0
  44. package/lib/esm/src/MockServerDevice.js.map +7 -0
  45. package/lib/esm/src/ScreenFrame.js +2 -0
  46. package/lib/esm/src/ScreenFrame.js.map +7 -0
  47. package/lib/esm/src/deviceModels.js +2 -0
  48. package/lib/esm/src/deviceModels.js.map +7 -0
  49. package/lib/esm/src/index.js +2 -0
  50. package/lib/esm/src/index.js.map +7 -0
  51. package/lib/esm/src/mockServerScreenApi.js +2 -0
  52. package/lib/esm/src/mockServerScreenApi.js.map +7 -0
  53. package/lib/esm/src/mockServerScreenApi.test.js +2 -0
  54. package/lib/esm/src/mockServerScreenApi.test.js.map +7 -0
  55. package/lib/esm/src/types.js +1 -0
  56. package/lib/esm/src/types.js.map +7 -0
  57. package/lib/esm/src/useMockServerDevice.js +2 -0
  58. package/lib/esm/src/useMockServerDevice.js.map +7 -0
  59. package/lib/esm/src/useScreenPolling.js +2 -0
  60. package/lib/esm/src/useScreenPolling.js.map +7 -0
  61. package/lib/types/index.d.ts +2 -0
  62. package/lib/types/index.d.ts.map +1 -0
  63. package/lib/types/src/DeviceOsInfo.d.ts +12 -0
  64. package/lib/types/src/DeviceOsInfo.d.ts.map +1 -0
  65. package/lib/types/src/DeviceScreen.d.ts +17 -0
  66. package/lib/types/src/DeviceScreen.d.ts.map +1 -0
  67. package/lib/types/src/DeviceScreenButtons.d.ts +8 -0
  68. package/lib/types/src/DeviceScreenButtons.d.ts.map +1 -0
  69. package/lib/types/src/DeviceScreenImage.d.ts +10 -0
  70. package/lib/types/src/DeviceScreenImage.d.ts.map +1 -0
  71. package/lib/types/src/MockServerDevice.d.ts +10 -0
  72. package/lib/types/src/MockServerDevice.d.ts.map +1 -0
  73. package/lib/types/src/ScreenFrame.d.ts +12 -0
  74. package/lib/types/src/ScreenFrame.d.ts.map +1 -0
  75. package/lib/types/src/deviceModels.d.ts +14 -0
  76. package/lib/types/src/deviceModels.d.ts.map +1 -0
  77. package/lib/types/src/index.d.ts +7 -0
  78. package/lib/types/src/index.d.ts.map +1 -0
  79. package/lib/types/src/mockServerScreenApi.d.ts +4 -0
  80. package/lib/types/src/mockServerScreenApi.d.ts.map +1 -0
  81. package/lib/types/src/mockServerScreenApi.test.d.ts +2 -0
  82. package/lib/types/src/mockServerScreenApi.test.d.ts.map +1 -0
  83. package/lib/types/src/types.d.ts +41 -0
  84. package/lib/types/src/types.d.ts.map +1 -0
  85. package/lib/types/src/useMockServerDevice.d.ts +7 -0
  86. package/lib/types/src/useMockServerDevice.d.ts.map +1 -0
  87. package/lib/types/src/useScreenPolling.d.ts +3 -0
  88. package/lib/types/src/useScreenPolling.d.ts.map +1 -0
  89. package/lib/types/tsconfig.prod.tsbuildinfo +1 -0
  90. package/package.json +67 -0
  91. package/tailwind.css +2 -0
package/LICENSE.MD ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2024-present Ledger
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # @ledgerhq/device-mockserver-react
2
+
3
+ The live screen of a [device mock server](https://github.com/LedgerHQ/device-sdk-ts/tree/develop/apps/device-mock-server) device,
4
+ with the controls to drive it: touch for Stax, Flex and Apex, left / right /
5
+ both buttons for the Nano. A device that runs no app has no Speculos instance,
6
+ so its record from the mock server is shown instead.
7
+
8
+ Built with [Lumen](https://www.npmjs.com/package/@ledgerhq/lumen-ui-react), so
9
+ the host renders it inside a Lumen `ThemeProvider` and a Tailwind build.
10
+
11
+ ## Usage
12
+
13
+ ```tsx
14
+ import { MockServerDevice } from "@ledgerhq/device-mockserver-react";
15
+
16
+ <MockServerDevice
17
+ url="http://127.0.0.1:9752"
18
+ token={sessionToken}
19
+ deviceId={deviceId}
20
+ floating
21
+ />;
22
+ ```
23
+
24
+ | Prop | Description |
25
+ | ------------------ | ------------------------------------------------------------------------------------ |
26
+ | `url` | Mock server URL. |
27
+ | `token` | Session token. Omitted, the client opens a session of its own. |
28
+ | `deviceId` | Mock server device id. |
29
+ | `floating` | A window over the page, dragged by its header and collapsed to it. Inline otherwise. |
30
+ | `defaultCollapsed` | Whether the floating window starts collapsed. |
31
+
32
+ `DeviceScreen` renders the same screen from any `ScreenApi`, for instance one
33
+ that talks to Speculos directly. `mockServerScreenApi(client, deviceId)` is the
34
+ one `MockServerDevice` uses, for hosts that already hold a `MockClient`, and
35
+ `findDeviceScreenModel(deviceType)` gives a model's label for their own header.
36
+
37
+ ## Styles
38
+
39
+ Tailwind skips `node_modules`, so register the package next to Lumen in the
40
+ host stylesheet:
41
+
42
+ ```css
43
+ @import "@ledgerhq/lumen-ui-react/tailwind.css";
44
+ @import "@ledgerhq/device-mockserver-react/tailwind.css";
45
+ ```
@@ -0,0 +1,2 @@
1
+ "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(r,o,f,x)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of c(o))!d.call(r,e)&&e!==f&&a(r,e,{get:()=>o[e],enumerable:!(x=b(o,e))||x.enumerable});return r},t=(r,o,f)=>(p(r,o,"default"),f&&p(f,o,"default"));var g=r=>p(a({},"__esModule",{value:!0}),r);var m={};module.exports=g(m);t(m,require("./src"),module.exports);0&&(module.exports={...require("./src")});
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../index.ts"],
4
+ "sourcesContent": ["export * from \"./src\";\n"],
5
+ "mappings": "iaAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAAAE,EAAAF,EAAc,iBAAd",
6
+ "names": ["index_exports", "__toCommonJS", "__reExport"]
7
+ }
@@ -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
+ "use strict";var x=Object.create;var a=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var N=(t,n)=>{for(var r in n)a(t,r,{get:n[r],enumerable:!0})},f=(t,n,r,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of y(n))!q.call(t,i)&&i!==r&&a(t,i,{get:()=>n[i],enumerable:!(l=h(n,i))||l.enumerable});return t};var $=(t,n,r)=>(r=t!=null?x(k(t)):{},f(n||!t||!t.__esModule?a(r,"default",{value:t,enumerable:!0}):r,t)),S=t=>f(a({},"__esModule",{value:!0}),t);var I={};N(I,{DeviceOsInfo:()=>E});module.exports=S(I);var e=$(require("react")),w=require("./ScreenFrame");const O="BOLOS",_=1e4,P="[&::-webkit-scrollbar]:size-[6px] [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:rounded-full",D=t=>`https://cdn.live.ledger.com/icons/${t.toLowerCase().replace(/ /g,"_")}.png`,g=({name:t})=>{const[n,r]=(0,e.useState)(!1);return n?e.default.createElement("span",{className:"text-muted bg-muted flex size-[12.5cqw] items-center justify-center rounded-full text-[length:6cqw] font-semibold"},t.charAt(0)):e.default.createElement("img",{src:D(t),alt:"",draggable:!1,className:"size-[12.5cqw] rounded-full",onError:()=>r(!0)})},E=({device:t,model:n,onOpenApp:r})=>{const l=(t.apps??[]).filter(({name:s})=>s!==O),[i,d]=(0,e.useState)(),[b,u]=(0,e.useState)(),o=n.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"},c=n.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=(0,e.useRef)(void 0);(0,e.useEffect)(()=>()=>clearTimeout(m.current),[]);const v=s=>{!r||i||(d(s),u(void 0),r(s).then(()=>{m.current=setTimeout(()=>{d(void 0),u(`${s} opened but its screen never showed up`)},_)},p=>{d(void 0),u(p instanceof Error?p.message:String(p))}))};return e.default.createElement("div",{className:"flex flex-col gap-8","data-testid":"container_device-os-info"},e.default.createElement(w.ScreenFrame,null,e.default.createElement("div",{className:`${o.background} ${c.scroll} ${P} ${o.scrollbar} p-[3cqw]`,style:{aspectRatio:n.screenWidth/n.screenHeight},"data-testid":"list_device-apps"},l.length===0?e.default.createElement("p",{className:`text-[length:5.5cqw] ${o.text} flex h-full w-full items-center justify-center opacity-60`},"No apps installed"):e.default.createElement("div",{className:c.list},l.map(s=>e.default.createElement("button",{key:s.name,type:"button",title:`${s.name} ${s.version}`,disabled:!r||i!==void 0,onClick:()=>v(s.name),className:`${o.text} ${c.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-${s.name}`},e.default.createElement(g,{name:s.name}),e.default.createElement("span",{className:"w-full truncate text-center text-[length:4.7cqw] leading-[1.3]"},s.name))))),i!==void 0?e.default.createElement("div",{className:`${o.text} ${o.overlay} ${c.opening} pointer-events-none absolute inset-0 flex items-center justify-center gap-[3cqw] backdrop-blur-[1cqw]`,"data-testid":"spinner_opening-app-screen"},e.default.createElement("div",{className:"relative flex size-[18cqw] shrink-0 items-center justify-center"},e.default.createElement("span",{className:"absolute inset-0 rounded-full border-[0.8cqw] border-current opacity-15"}),e.default.createElement("span",{className:"absolute inset-0 animate-spin rounded-full border-[0.8cqw] border-transparent border-t-current"}),e.default.createElement(g,{name:i})),e.default.createElement("span",{className:"animate-pulse text-[length:4.7cqw] font-semibold"},"Opening ",i)):null),b?e.default.createElement("p",{className:"body-4 text-error text-center"},b):null)};0&&(module.exports={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": "0jBAAA,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AAC,QAAK,UAAU,0EAA0E,EAC1F,EAAAA,QAAA,cAAC,QAAK,UAAU,iGAAiG,EACjH,EAAAA,QAAA,cAACJ,EAAA,CAAQ,KAAMS,EAAS,CAC1B,EACA,EAAAL,QAAA,cAAC,QAAK,UAAU,oDAAmD,WACxDK,CACX,CACF,EACE,IACN,EACCE,EAAQ,EAAAP,QAAA,cAAC,KAAE,UAAU,iCAAiCO,CAAM,EAAO,IACtE,CAEJ",
6
+ "names": ["DeviceOsInfo_exports", "__export", "DeviceOsInfo", "__toCommonJS", "import_react", "import_ScreenFrame", "OS_APP_NAME", "OPEN_TIMEOUT_MS", "SCROLLBAR", "iconUrl", "appName", "AppIcon", "name", "missing", "setMissing", "React", "device", "model", "onOpenApp", "apps", "opening", "setOpening", "error", "setError", "screen", "layout", "openTimer", "open", "cause", "app"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var F=Object.create;var f=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var X=Object.getPrototypeOf,U=Object.prototype.hasOwnProperty;var k=(n,t)=>{for(var r in t)f(n,r,{get:t[r],enumerable:!0})},S=(n,t,r,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of L(t))!U.call(n,s)&&s!==r&&f(n,s,{get:()=>t[s],enumerable:!(l=B(t,s))||l.enumerable});return n};var $=(n,t,r)=>(r=n!=null?F(X(n)):{},S(t||!n||!n.__esModule?f(r,"default",{value:n,enumerable:!0}):r,n)),j=n=>S(f({},"__esModule",{value:!0}),n);var K={};k(K,{DeviceScreen:()=>q});module.exports=j(K);var e=$(require("react")),v=require("@ledgerhq/lumen-ui-react"),h=require("@ledgerhq/lumen-ui-react/symbols"),y=require("./deviceModels"),C=require("./DeviceOsInfo"),T=require("./DeviceScreenButtons"),E=require("./DeviceScreenImage"),N=require("./ScreenFrame"),_=require("./useScreenPolling");const w=16,G=224,O=200,Y=(n,t)=>t?`${n} - ${t}`:n,q=({api:n,deviceType:t,firmwareVersion:r,floating:l=!1,defaultCollapsed:s=!1})=>{const c=(0,y.findDeviceScreenModel)(t),[u,p]=(0,e.useState)(s),m=(0,_.useScreenPolling)(n,!l||!u);return l?e.default.createElement(J,{title:Y(c.label,r),model:c,collapsed:u,onToggle:()=>p(x=>!x)},M(m,c,n)):e.default.createElement("div",{className:"mx-auto flex w-full max-w-[420px] flex-col gap-8","data-testid":"container_device-screen"},M(m,c,n))},J=({title:n,model:t,collapsed:r,onToggle:l,children:s})=>{const c=(0,e.useRef)(null),[u,p]=(0,e.useState)(),[m,x]=(0,e.useState)(G),a=(0,e.useRef)(null),d=(0,e.useRef)(null),z=o=>{const i=c.current?.getBoundingClientRect();!i||o.button!==0||o.target.closest("button")||(o.currentTarget.setPointerCapture(o.pointerId),a.current={dx:o.clientX-i.left,dy:o.clientY-i.top})},H=o=>{const i=c.current?.getBoundingClientRect();if(!a.current||!i)return;const g=(b,A)=>Math.min(Math.max(b,0),Math.max(A,0));p({left:g(o.clientX-a.current.dx,window.innerWidth-i.width),top:g(o.clientY-a.current.dy,window.innerHeight-i.height)})},P=()=>{a.current=null},I=o=>{const i=c.current?.getBoundingClientRect();!i||o.button!==0||(o.currentTarget.setPointerCapture(o.pointerId),p({left:i.left,top:i.top}),d.current={x:o.clientX,width:i.width})},W=o=>{const i=c.current?.getBoundingClientRect();if(!d.current||!i)return;const g=d.current.width+o.clientX-d.current.x,b=window.innerWidth-i.left-w;x(Math.max(O,Math.min(g,b)))},D=()=>{d.current=null};return e.default.createElement("div",{ref:c,className:"bg-base border-muted fixed flex max-w-[calc(100vw-32px)] flex-col rounded-lg border shadow-lg",style:{zIndex:1e3,width:m,...u??{right:w,bottom:w}},"data-testid":"container_device-screen"},e.default.createElement("div",{className:"flex cursor-move items-center gap-8 px-12 py-8 select-none",style:{touchAction:"none"},onPointerDown:z,onPointerMove:H,onPointerUp:P,onPointerCancel:P},e.default.createElement(t.icon,{size:16}),e.default.createElement("span",{className:"body-3-semi-bold text-base flex-1"},n),e.default.createElement(v.IconButton,{appearance:"no-background",size:"xs",icon:r?h.ChevronUp:h.ChevronDown,"aria-label":r?"Expand device screen":"Collapse device screen",onClick:l,"data-testid":"button_toggle-device-screen"})),r?null:e.default.createElement(e.default.Fragment,null,e.default.createElement("div",{className:"flex flex-col gap-8 px-12 pb-12"},s),e.default.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:I,onPointerMove:W,onPointerUp:D,onPointerCancel:D,"aria-hidden":!0,"data-testid":"handle_resize-device-screen"},e.default.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 M(n,t,r){switch(n.kind){case"loading":return e.default.createElement(N.ScreenFrame,null,e.default.createElement("div",{className:`${t.lightScreen?"bg-white text-black":"bg-black text-white"} flex items-center justify-center`,style:{aspectRatio:t.screenWidth/t.screenHeight},"data-testid":"placeholder_device-screen-loading"},e.default.createElement("span",{className:"animate-pulse opacity-60"},e.default.createElement(t.icon,{size:32}))));case"error":return e.default.createElement(v.Banner,{appearance:"error",title:"Screen unavailable",description:n.message});case"os-info":return e.default.createElement(C.DeviceOsInfo,{device:n.device,model:t,onOpenApp:t.speculos?r.openApp:void 0});case"image":return e.default.createElement(e.default.Fragment,null,e.default.createElement(E.DeviceScreenImage,{src:n.src,onTouch:t.touch?n.input.touch:void 0}),t.touch?null:e.default.createElement(T.DeviceScreenButtons,{onPress:n.input.pressButton}))}}0&&(module.exports={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": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAwC,oBACxCC,EAAmC,oCACnCC,EAAuC,4CAEvCC,EAA8D,0BAC9DC,EAA6B,0BAC7BC,EAAoC,iCACpCC,EAAkC,+BAClCC,EAA4B,yBAE5BC,EAAiC,8BAqBjC,MAAMC,EAAiB,GACjBC,EAAmB,IACnBC,EAAe,IAEfC,EAAoB,CAACC,EAAeC,IACxCA,EAAkB,GAAGD,CAAK,MAAMC,CAAe,GAAKD,EAEzCf,EAA4C,CAAC,CACxD,IAAAiB,EACA,WAAAC,EACA,gBAAAF,EACA,SAAAG,EAAW,GACX,iBAAAC,EAAmB,EACrB,IAAM,CACJ,MAAMC,KAAQ,yBAAsBH,CAAU,EACxC,CAACI,EAAWC,CAAY,KAAI,YAASH,CAAgB,EACrDI,KAAQ,oBAAiBP,EAAK,CAACE,GAAY,CAACG,CAAS,EAE3D,OAAKH,EAYH,EAAAM,QAAA,cAACC,EAAA,CACC,MAAOZ,EAAkBO,EAAM,MAAOL,CAAe,EACrD,MAAOK,EACP,UAAWC,EACX,SAAU,IAAMC,EAAcI,GAAU,CAACA,CAAK,GAE7CC,EAAaJ,EAAOH,EAAOJ,CAAG,CACjC,EAjBE,EAAAQ,QAAA,cAAC,OACC,UAAU,mDACV,cAAY,2BAEXG,EAAaJ,EAAO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ACvI,CACF,CAEJ,CAEJ,EAEA,SAASG,EACPJ,EACAH,EACAJ,EACA,CACA,OAAQO,EAAM,KAAM,CAClB,IAAK,UACH,OACE,EAAAC,QAAA,cAAC,mBACC,EAAAA,QAAA,cAAC,OACC,UAAW,GAAGJ,EAAM,YAAc,sBAAwB,qBAAqB,oCAC/E,MAAO,CAAE,YAAaA,EAAM,YAAcA,EAAM,YAAa,EAC7D,cAAY,qCAEZ,EAAAI,QAAA,cAAC,QAAK,UAAU,4BACd,EAAAA,QAAA,cAACJ,EAAM,KAAN,CAAW,KAAM,GAAI,CACxB,CACF,CACF,EAEJ,IAAK,QACH,OACE,EAAAI,QAAA,cAAC,UACC,WAAW,QACX,MAAM,qBACN,YAAaD,EAAM,QACrB,EAEJ,IAAK,UACH,OACE,EAAAC,QAAA,cAAC,gBACC,OAAQD,EAAM,OACd,MAAOH,EACP,UAAWA,EAAM,SAAWJ,EAAI,QAAU,OAC5C,EAEJ,IAAK,QACH,OACE,EAAAQ,QAAA,gBAAAA,QAAA,cACE,EAAAA,QAAA,cAAC,qBACC,IAAKD,EAAM,IACX,QAASH,EAAM,MAAQG,EAAM,MAAM,MAAQ,OAC7C,EACCH,EAAM,MAAQ,KACb,EAAAI,QAAA,cAAC,uBAAoB,QAASD,EAAM,MAAM,YAAa,CAE3D,CAEN,CACF",
6
+ "names": ["DeviceScreen_exports", "__export", "DeviceScreen", "__toCommonJS", "import_react", "import_lumen_ui_react", "import_symbols", "import_deviceModels", "import_DeviceOsInfo", "import_DeviceScreenButtons", "import_DeviceScreenImage", "import_ScreenFrame", "import_useScreenPolling", "EDGE_MARGIN_PX", "DEFAULT_WIDTH_PX", "MIN_WIDTH_PX", "deviceScreenTitle", "label", "firmwareVersion", "api", "deviceType", "floating", "defaultCollapsed", "model", "collapsed", "setCollapsed", "state", "React", "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
+ "use strict";var f=Object.create;var i=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var B=(e,t)=>{for(var r in t)i(e,r,{get:t[r],enumerable:!0})},d=(e,t,r,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of m(t))!v.call(e,s)&&s!==r&&i(e,s,{get:()=>t[s],enumerable:!(c=y(t,s))||c.enumerable});return e};var T=(e,t,r)=>(r=e!=null?f(S(e)):{},d(t||!e||!e.__esModule?i(r,"default",{value:e,enumerable:!0}):r,e)),g=e=>d(i({},"__esModule",{value:!0}),e);var P={};B(P,{DeviceScreenButtons:()=>H});module.exports=g(P);var o=T(require("react"));const h=[{button:"left",label:"Left"},{button:"both",label:"Both"},{button:"right",label:"Right"}],b=e=>e===" "||e==="Enter",D=150,H=({onPress:e})=>{const t=(0,o.useRef)(null),r=(0,o.useRef)(null),c=(0,o.useRef)(e);c.current=e;const s=(0,o.useCallback)(()=>{r.current&&(clearTimeout(r.current),r.current=null)},[]),p=(0,o.useCallback)(n=>{if(t.current)return;const l={button:n,pressed:!1};t.current=l,r.current=setTimeout(()=>{l.pressed=!0,c.current(n,"press")},D)},[]),a=(0,o.useCallback)(()=>{const n=t.current;n&&(t.current=null,s(),c.current(n.button,n.pressed?"release":"press-and-release"))},[s]);return(0,o.useEffect)(()=>()=>{const n=t.current;t.current=null,s(),n?.pressed&&c.current(n.button,"release")},[s]),o.default.createElement("div",{className:"flex gap-8"},h.map(({button:n,label:l})=>o.default.createElement("button",{key:n,type:"button","aria-label":`${l} button`,onPointerDown:u=>{u.button===0&&(u.currentTarget.setPointerCapture(u.pointerId),p(n))},onPointerUp:a,onPointerCancel:a,onKeyDown:u=>{b(u.key)&&(u.preventDefault(),p(n))},onKeyUp:u=>b(u.key)&&a(),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-${n}`},l)))};0&&(module.exports={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": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAsD,oBAMtD,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,IAWbN,EAA0D,CAAC,CACtE,QAAAO,CACF,IAAM,CACJ,MAAMC,KAAO,UAAoB,IAAI,EAC/BC,KAAY,UAA6C,IAAI,EAC7DC,KAAW,UAAOH,CAAO,EAC/BG,EAAS,QAAU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1CI,CACH,CACD,CACH,CAEJ",
6
+ "names": ["DeviceScreenButtons_exports", "__export", "DeviceScreenButtons", "__toCommonJS", "import_react", "BUTTONS", "isActivationKey", "key", "HOLD_THRESHOLD_MS", "onPress", "held", "holdTimer", "pressRef", "clearHoldTimer", "hold", "button", "entry", "release", "React", "label", "event"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var v=Object.create;var s=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var H=(t,e)=>{for(var o in e)s(t,o,{get:e[o],enumerable:!0})},p=(t,e,o,u)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of I(e))!D.call(t,i)&&i!==o&&s(t,i,{get:()=>e[i],enumerable:!(u=E(e,i))||u.enumerable});return t};var M=(t,e,o)=>(o=t!=null?v(S(t)):{},p(e||!t||!t.__esModule?s(o,"default",{value:t,enumerable:!0}):o,t)),R=t=>p(s({},"__esModule",{value:!0}),t);var w={};H(w,{DeviceScreenImage:()=>C});module.exports=R(w);var r=M(require("react")),f=require("./ScreenFrame");const C=({src:t,onTouch:e})=>{const o=(0,r.useRef)(null),[u,i]=(0,r.useState)(!1),c=(0,r.useRef)(null),m=(0,r.useRef)(e);m.current=e,(0,r.useEffect)(()=>i(!1),[t]);const h=a=>{const n=o.current;if(!n?.naturalWidth||!n.naturalHeight)return null;const l=n.getBoundingClientRect();if(!l.width||!l.height)return null;const g=(x,y)=>Math.min(Math.max(Math.round(x),0),y-1);return{x:g((a.clientX-l.left)/l.width*n.naturalWidth,n.naturalWidth),y:g((a.clientY-l.top)/l.height*n.naturalHeight,n.naturalHeight)}},b=a=>{if(!e||c.current||a.button!==0)return;const n=h(a);n&&(o.current?.setPointerCapture(a.pointerId),c.current=n,e(n.x,n.y,"press"))},d=a=>{const n=c.current;!e||!n||(c.current=null,o.current?.releasePointerCapture(a.pointerId),e(n.x,n.y,"release"))};(0,r.useEffect)(()=>()=>{const a=c.current;a&&(c.current=null,m.current?.(a.x,a.y,"release"))},[]);const P=(0,r.useCallback)(()=>i(!0),[]);return u?r.default.createElement("p",{className:"body-4 text-error text-center","data-testid":"text_device-screen-undecodable"},"Screenshot could not be decoded"):r.default.createElement(f.ScreenFrame,null,r.default.createElement("img",{ref:o,src:t,alt:"Device screen",draggable:!1,onError:P,onPointerDown:b,onPointerUp:d,onPointerCancel:d,className:`block w-full bg-black select-none ${e?"cursor-pointer":""}`,style:{imageRendering:"pixelated",touchAction:"none"},"data-testid":"image_device-screen"}))};0&&(module.exports={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": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAgE,oBAGhEC,EAA4B,yBAarB,MAAMH,EAAsD,CAAC,CAClE,IAAAI,EACA,QAAAC,CACF,IA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,EAAM,EAAG,SAAS,EAChD,EACA,CAAC,CACH,EAEA,MAAME,KAAc,eAAY,IAAMb,EAAe,EAAI,EAAG,CAAC,CAAC,EAE9D,OAAID,EAEA,EAAAe,QAAA,cAAC,KACC,UAAU,gCACV,cAAY,kCACb,iCAED,EAKF,EAAAA,QAAA,cAAC,mBACC,EAAAA,QAAA,cAAC,OACC,IAAKhB,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": ["DeviceScreenImage_exports", "__export", "DeviceScreenImage", "__toCommonJS", "import_react", "import_ScreenFrame", "src", "onTouch", "imageRef", "undecodable", "setUndecodable", "held", "touchRef", "toDevicePoint", "event", "image", "rect", "clamp", "value", "size", "handlePointerDown", "point", "handlePointerUp", "handleError", "React"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var l=Object.create;var n=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var d=(e,r)=>{for(var o in r)n(e,o,{get:r[o],enumerable:!0})},s=(e,r,o,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of u(r))!M.call(e,i)&&i!==o&&n(e,i,{get:()=>r[i],enumerable:!(t=k(r,i))||t.enumerable});return e};var P=(e,r,o)=>(o=e!=null?l(D(e)):{},s(r||!e||!e.__esModule?n(o,"default",{value:e,enumerable:!0}):o,e)),g=e=>s(n({},"__esModule",{value:!0}),e);var w={};d(w,{MockServerDevice:()=>y});module.exports=g(w);var c=P(require("react")),v=require("@ledgerhq/device-mockserver-client"),m=require("./DeviceScreen"),f=require("./mockServerScreenApi"),S=require("./useMockServerDevice");const y=({url:e,token:r,deviceId:o,...t})=>{const i=(0,c.useMemo)(()=>new v.MockClient(e,{token:r}),[e,r]),a=(0,c.useMemo)(()=>(0,f.mockServerScreenApi)(i,o),[i,o]),p=(0,S.useMockServerDevice)(i,o);return p===void 0?null:c.default.createElement(m.DeviceScreen,{api:a,deviceType:p?.device_type??"",firmwareVersion:p?.firmware_version,...t})};0&&(module.exports={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": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA+B,oBAC/BC,EAA2B,8CAE3BC,EAAqD,0BACrDC,EAAoC,iCACpCC,EAAoC,iCAY7B,MAAMN,EAAoD,CAAC,CAChE,IAAAO,EACA,MAAAC,EACA,SAAAC,EACA,GAAGC,CACL,IAAM,CACJ,MAAMC,KAAS,WAAQ,IAAM,IAAI,aAAWJ,EAAK,CAAE,MAAAC,CAAM,CAAC,EAAG,CAACD,EAAKC,CAAK,CAAC,EACnEI,KAAM,WACV,OAAM,uBAAoBD,EAAQF,CAAQ,EAC1C,CAACE,EAAQF,CAAQ,CACnB,EACMI,KAAS,uBAAoBF,EAAQF,CAAQ,EAInD,OAAII,IAAW,OAAkB,KAG/B,EAAAC,QAAA,cAAC,gBACC,IAAKF,EACL,WAAYC,GAAQ,aAAe,GACnC,gBAAiBA,GAAQ,iBACxB,GAAGH,EACN,CAEJ",
6
+ "names": ["MockServerDevice_exports", "__export", "MockServerDevice", "__toCommonJS", "import_react", "import_device_mockserver_client", "import_DeviceScreen", "import_mockServerScreenApi", "import_useMockServerDevice", "url", "token", "deviceId", "props", "client", "api", "device", "React"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var m=Object.create;var a=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var s=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty;var v=(e,r)=>{for(var o in r)a(e,o,{get:r[o],enumerable:!0})},t=(e,r,o,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let d of p(r))!l.call(e,d)&&d!==o&&a(e,d,{get:()=>r[d],enumerable:!(c=i(r,d))||c.enumerable});return e};var F=(e,r,o)=>(o=e!=null?m(s(e)):{},t(r||!e||!e.__esModule?a(o,"default",{value:e,enumerable:!0}):o,e)),R=e=>t(a({},"__esModule",{value:!0}),e);var b={};v(b,{ScreenFrame:()=>S});module.exports=R(b);var n=F(require("react"));const S=({children:e})=>n.default.createElement("div",{className:"border-muted @container relative overflow-hidden rounded-md border"},e);0&&(module.exports={ScreenFrame});
2
+ //# sourceMappingURL=ScreenFrame.js.map
@@ -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": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAWX,MAAMF,EAA0C,CAAC,CAAE,SAAAG,CAAS,IACjE,EAAAC,QAAA,cAAC,OAAI,UAAU,sEACZD,CACH",
6
+ "names": ["ScreenFrame_exports", "__export", "ScreenFrame", "__toCommonJS", "import_react", "children", "React"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var l=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var d=(e,n)=>{for(var c in n)l(e,c,{get:n[c],enumerable:!0})},h=(e,n,c,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of a(n))!u.call(e,r)&&r!==c&&l(e,r,{get:()=>n[r],enumerable:!(s=i(n,r))||s.enumerable});return e};var S=e=>h(l({},"__esModule",{value:!0}),e);var b={};d(b,{findDeviceScreenModel:()=>x});module.exports=S(b);var o=require("@ledgerhq/lumen-ui-react/symbols");const t=(e,n)=>({label:e,icon:o.Nano,touch:!1,speculos:!0,screenWidth:128,screenHeight:n,lightScreen:!1}),p={nanoS:{...t("Nano S",32),speculos:!1},nanoSP:t("Nano S Plus",64),nanoX:t("Nano X",64),stax:{label:"Stax",icon:o.Stax,touch:!0,speculos:!0,screenWidth:400,screenHeight:672,lightScreen:!0},flex:{label:"Flex",icon:o.Flex,touch:!0,speculos:!0,screenWidth:480,screenHeight:600,lightScreen:!0},apexp:{label:"Apex",icon:o.Apex,touch:!0,speculos:!0,screenWidth:300,screenHeight:400,lightScreen:!0}},g=t("Device",64),x=e=>p[e]??g;0&&(module.exports={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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAuC,4CAcvC,MAAMC,EAAO,CAACC,EAAeC,KAA6C,CACxE,MAAAD,EACA,KAAM,OACN,MAAO,GACP,SAAU,GACV,YAAa,IACb,aAAAC,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,KAAM,OACN,MAAO,GACP,SAAU,GACV,YAAa,IACb,aAAc,IACd,YAAa,EACf,EACA,KAAM,CACJ,MAAO,OACP,KAAM,OACN,MAAO,GACP,SAAU,GACV,YAAa,IACb,aAAc,IACd,YAAa,EACf,EACA,MAAO,CACL,MAAO,OACP,KAAM,OACN,MAAO,GACP,SAAU,GACV,YAAa,IACb,aAAc,IACd,YAAa,EACf,CACF,EAEMI,EAA6BJ,EAAK,SAAU,EAAE,EAEvCH,EAAyBQ,GACpCF,EAAOE,CAAU,GAAKD",
6
+ "names": ["deviceModels_exports", "__export", "findDeviceScreenModel", "__toCommonJS", "import_symbols", "nano", "label", "screenHeight", "MODELS", "UNKNOWN", "deviceType"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var p=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var y=(r,e)=>{for(var c in e)p(r,c,{get:e[c],enumerable:!0})},M=(r,e,c,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of m(e))!x.call(r,o)&&o!==c&&p(r,o,{get:()=>e[o],enumerable:!(t=f(e,o))||t.enumerable});return r};var k=r=>M(p({},"__esModule",{value:!0}),r);var s={};y(s,{DeviceScreen:()=>S.DeviceScreen,MockServerDevice:()=>i.MockServerDevice,findDeviceScreenModel:()=>v.findDeviceScreenModel,mockServerScreenApi:()=>n.mockServerScreenApi,useMockServerDevice:()=>D.useMockServerDevice});module.exports=k(s);var v=require("./deviceModels"),S=require("./DeviceScreen"),i=require("./MockServerDevice"),n=require("./mockServerScreenApi"),D=require("./useMockServerDevice");0&&(module.exports={DeviceScreen,MockServerDevice,findDeviceScreenModel,mockServerScreenApi,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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wOAAAE,EAAAF,GAAA,IAAAG,EAA8D,0BAC9DC,EAAqD,0BACrDC,EAGO,8BACPC,EAAoC,iCAEpCC,EAAoC",
6
+ "names": ["src_exports", "__export", "__toCommonJS", "import_deviceModels", "import_DeviceScreen", "import_MockServerDevice", "import_mockServerScreenApi", "import_useMockServerDevice"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var s=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var i=(n,o)=>{for(var t in o)s(n,t,{get:o[t],enumerable:!0})},w=(n,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of p(o))!u.call(n,e)&&e!==t&&s(n,e,{get:()=>o[e],enumerable:!(r=a(o,e))||r.enumerable});return n};var h=n=>w(s({},"__esModule",{value:!0}),n);var x={};i(x,{mockServerScreenApi:()=>l});module.exports=h(x);const f=n=>n?.status===409,l=(n,o)=>({screenshot:async()=>{try{return await n.getScreenshot(o)}catch(t){if(f(t))return null;throw t}},idle:async()=>({kind:"os-info",device:await n.getDevice(o)}),pressButton:(t,r)=>n.pressButton(o,t,r),touch:(t,r,e)=>n.touchScreen(o,t,r,e),openApp:async t=>{const r=new TextEncoder().encode(t);if(r.length>255)throw new Error(`App name too long to open: ${t}`);const{response:e}=await n.sendApdu(o,Uint8Array.from([224,216,0,0,r.length,...r])),c=e.slice(-4);if(c!=="9000")throw new Error(`Could not open ${t} (${c})`)}});0&&(module.exports={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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yBAAAE,IAAA,eAAAC,EAAAH,GAKA,MAAMI,EAAgBC,GACnBA,GAAuC,SAAW,IAExCH,EAAsB,CACjCI,EACAC,KACe,CACf,WAAY,SAAY,CACtB,GAAI,CACF,OAAO,MAAMD,EAAO,cAAcC,CAAQ,CAC5C,OAASF,EAAO,CACd,GAAID,EAAaC,CAAK,EAAG,OAAO,KAChC,MAAMA,CACR,CACF,EACA,KAAM,UAAa,CACjB,KAAM,UACN,OAAQ,MAAMC,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": ["mockServerScreenApi_exports", "__export", "mockServerScreenApi", "__toCommonJS", "isNoInstance", "error", "client", "deviceId", "button", "action", "x", "y", "appName", "name", "response", "statusWord"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var o=require("./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((0,o.mockServerScreenApi)(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((0,o.mockServerScreenApi)(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((0,o.mockServerScreenApi)(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((0,o.mockServerScreenApi)(t,"device-1").idle?.()).resolves.toEqual({kind:"os-info",device:e})}),it("forwards buttons and touches to the device",async()=>{const e=n({}),t=(0,o.mockServerScreenApi)(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(0,o.mockServerScreenApi)(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=(0,o.mockServerScreenApi)(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=(0,o.mockServerScreenApi)(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,IAAAA,EAAoC,iCAEpC,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,UACJ,uBAAoBC,EAAQ,UAAU,EAAE,WAAW,CACrD,EAAE,SAAS,KAAKD,CAAI,EACpB,OAAOC,EAAO,aAAa,EAAE,qBAAqB,UAAU,CAC9D,CAAC,EAED,GAAG,kEAAmE,SAAY,CAChF,MAA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