@present-day/device 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/devices.ts","../src/core/html.ts"],"sourcesContent":["export type Cutout = 'island' | 'none'\n\nexport interface DeviceButton {\n side: 'left' | 'right' | 'top'\n /** Where the button starts, as a fraction of that side's length. */\n start: number\n /** Button length, as a fraction of that side's length. */\n length: number\n}\n\nexport interface DeviceSpec {\n /**\n * The CSS-pixel viewport the screen shows. A screenshot or page laid out at\n * this size fills the screen exactly; the frame takes its shape from it.\n */\n viewport: { width: number; height: number }\n /** Bezel thickness, as a fraction of the device's outer width. */\n bezel: number\n /** Screen corner radius, as a fraction of the screen width. */\n screenRadius: number\n cutout: Cutout\n buttons: readonly DeviceButton[]\n}\n\n/**\n * Proportions follow the screen, not a particular model: the phone is a\n * 390 × 844 iPhone-class screen (iPhone 12 to 14), the size most app\n * screenshots and phone demos are laid out at; the tablet is an 1180 × 820\n * iPad Air in landscape.\n */\nexport const DEVICES = {\n phone: {\n viewport: { width: 390, height: 844 },\n bezel: 0.036,\n // Apple's 47.33 pt display corner radius on a 390 pt screen.\n screenRadius: 47.33 / 390,\n cutout: 'island',\n buttons: [\n { side: 'left', start: 0.175, length: 0.045 },\n { side: 'left', start: 0.255, length: 0.085 },\n { side: 'left', start: 0.36, length: 0.085 },\n { side: 'right', start: 0.29, length: 0.14 },\n ],\n },\n tablet: {\n viewport: { width: 1180, height: 820 },\n bezel: 0.032,\n // 18 pt display corners on a 1180 pt screen.\n screenRadius: 18 / 1180,\n cutout: 'none',\n buttons: [{ side: 'top', start: 0.84, length: 0.06 }],\n },\n} as const satisfies Record<string, DeviceSpec>\n\nexport type DeviceName = keyof typeof DEVICES\n\n/** The Dynamic Island, as fractions of the screen width (126 × 37 pt, 11 pt down, on a 393 pt screen). */\nconst ISLAND = { width: 126 / 393, height: 37 / 393, top: 11 / 393 }\n\n/** How far the side buttons stand out from the body, as a fraction of the device width. */\nconst BUTTON_DEPTH = 0.008\n\nexport function resolveDevice(device: DeviceName | DeviceSpec = 'phone') {\n return typeof device === 'string' ? DEVICES[device] : device\n}\n\nexport interface DeviceGeometry {\n width: number\n height: number\n bezel: number\n radius: number\n screen: { width: number; height: number; radius: number }\n /** Absent when the cutout is `none`. */\n island?: { width: number; height: number; top: number }\n buttonDepth: number\n /** Multiply the viewport by this to fit it to the screen. */\n scale: number\n}\n\n/**\n * Every measurement of a device drawn `width` units wide, in the same units.\n * For renderers that can't use the stylesheet, such as React Native.\n */\nexport function deviceGeometry(\n device: DeviceName | DeviceSpec,\n width: number,\n cutout?: Cutout,\n): DeviceGeometry {\n const spec = resolveDevice(device)\n const bezel = spec.bezel * width\n const screenWidth = width - bezel * 2\n const screenHeight =\n (screenWidth * spec.viewport.height) / spec.viewport.width\n const screenRadius = spec.screenRadius * screenWidth\n return {\n width,\n height: screenHeight + bezel * 2,\n bezel,\n radius: screenRadius + bezel,\n screen: { width: screenWidth, height: screenHeight, radius: screenRadius },\n island:\n (cutout ?? spec.cutout) === 'island'\n ? {\n width: ISLAND.width * screenWidth,\n height: ISLAND.height * screenWidth,\n top: ISLAND.top * screenWidth,\n }\n : undefined,\n buttonDepth: BUTTON_DEPTH * width,\n scale: screenWidth / spec.viewport.width,\n }\n}\n\nconst round = (n: number) => Math.round(n * 1e4) / 1e4\n\n/**\n * The custom properties `styles.css` draws a device from. Lengths are in\n * percent of the device's width and become `cqi` in the stylesheet.\n * `maxHeight` is any CSS length; the width shrinks to keep the shape.\n */\nexport function deviceVars(\n device: DeviceName | DeviceSpec = 'phone',\n options: { cutout?: Cutout; maxHeight?: string } = {},\n): Record<`--pd-device-${string}`, string> {\n const spec = resolveDevice(device)\n const g = deviceGeometry(spec, 100, options.cutout)\n const vars: Record<`--pd-device-${string}`, string> = {\n '--pd-device-aspect': `${spec.viewport.width} / ${spec.viewport.height}`,\n '--pd-device-bezel': `${round(g.bezel)}`,\n '--pd-device-radius': `${round(g.radius)}`,\n '--pd-device-screen-radius': `${round(g.screen.radius)}`,\n '--pd-device-button-depth': `${round(g.buttonDepth)}`,\n }\n if (g.island) {\n vars['--pd-device-island-width'] = `${round(g.island.width)}`\n vars['--pd-device-island-height'] = `${round(g.island.height)}`\n vars['--pd-device-island-top'] = `${round(g.island.top)}`\n }\n if (options.maxHeight)\n vars['--pd-device-max-width'] =\n `calc(${options.maxHeight} * ${round(g.width / g.height)})`\n return vars\n}\n","import {\n type Cutout,\n type DeviceName,\n type DeviceSpec,\n deviceVars,\n resolveDevice,\n} from './devices'\n\nconst esc = (s: string) =>\n s\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n\nexport interface DeviceHTMLOptions {\n /** The screenshot. */\n src: string\n alt: string\n device?: DeviceName | DeviceSpec\n /** Defaults to the device's own cutout. */\n cutout?: Cutout\n maxHeight?: string\n className?: string\n /** The image's pixel size, so the page can reserve its space. */\n width?: number\n height?: number\n /** Defaults to `lazy`. */\n loading?: 'lazy' | 'eager'\n}\n\n/**\n * A screenshot in a device frame, as an HTML string, for pages rendered\n * without React such as Markdown output. Needs `styles.css`.\n */\nexport function deviceHTML(options: DeviceHTMLOptions): string {\n const spec = resolveDevice(options.device)\n const cutout = options.cutout ?? spec.cutout\n const style = Object.entries(\n deviceVars(spec, { cutout, maxHeight: options.maxHeight }),\n )\n .map(([name, value]) => `${name}:${value}`)\n .join(';')\n const size =\n options.width && options.height\n ? ` width=\"${options.width}\" height=\"${options.height}\"`\n : ''\n const buttons = spec.buttons\n .map(\n (b) =>\n `<span class=\"pd-device-button\" data-side=\"${b.side}\" style=\"--pd-device-button-start:${b.start * 100}%;--pd-device-button-length:${b.length * 100}%\"></span>`,\n )\n .join('')\n const className = options.className\n ? `pd-device ${esc(options.className)}`\n : 'pd-device'\n\n return `<span class=\"${className}\" style=\"${esc(style)}\"><span class=\"pd-device-body\">${buttons}<span class=\"pd-device-screen\"><img class=\"pd-device-fill\" src=\"${esc(options.src)}\" alt=\"${esc(options.alt)}\"${size} loading=\"${options.loading ?? 'lazy'}\" decoding=\"async\">${cutout === 'island' ? '<span class=\"pd-device-island\"></span>' : ''}</span></span></span>`\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,224 @@
1
+ import * as react from 'react';
2
+ import { CSSProperties, ImgHTMLAttributes, IframeHTMLAttributes, ReactNode } from 'react';
3
+
4
+ type Cutout = 'island' | 'none';
5
+ interface DeviceButton {
6
+ side: 'left' | 'right' | 'top';
7
+ /** Where the button starts, as a fraction of that side's length. */
8
+ start: number;
9
+ /** Button length, as a fraction of that side's length. */
10
+ length: number;
11
+ }
12
+ interface DeviceSpec {
13
+ /**
14
+ * The CSS-pixel viewport the screen shows. A screenshot or page laid out at
15
+ * this size fills the screen exactly; the frame takes its shape from it.
16
+ */
17
+ viewport: {
18
+ width: number;
19
+ height: number;
20
+ };
21
+ /** Bezel thickness, as a fraction of the device's outer width. */
22
+ bezel: number;
23
+ /** Screen corner radius, as a fraction of the screen width. */
24
+ screenRadius: number;
25
+ cutout: Cutout;
26
+ buttons: readonly DeviceButton[];
27
+ }
28
+ /**
29
+ * Proportions follow the screen, not a particular model: the phone is a
30
+ * 390 × 844 iPhone-class screen (iPhone 12 to 14), the size most app
31
+ * screenshots and phone demos are laid out at; the tablet is an 1180 × 820
32
+ * iPad Air in landscape.
33
+ */
34
+ declare const DEVICES: {
35
+ readonly phone: {
36
+ readonly viewport: {
37
+ readonly width: 390;
38
+ readonly height: 844;
39
+ };
40
+ readonly bezel: 0.036;
41
+ readonly screenRadius: number;
42
+ readonly cutout: "island";
43
+ readonly buttons: readonly [{
44
+ readonly side: "left";
45
+ readonly start: 0.175;
46
+ readonly length: 0.045;
47
+ }, {
48
+ readonly side: "left";
49
+ readonly start: 0.255;
50
+ readonly length: 0.085;
51
+ }, {
52
+ readonly side: "left";
53
+ readonly start: 0.36;
54
+ readonly length: 0.085;
55
+ }, {
56
+ readonly side: "right";
57
+ readonly start: 0.29;
58
+ readonly length: 0.14;
59
+ }];
60
+ };
61
+ readonly tablet: {
62
+ readonly viewport: {
63
+ readonly width: 1180;
64
+ readonly height: 820;
65
+ };
66
+ readonly bezel: 0.032;
67
+ readonly screenRadius: number;
68
+ readonly cutout: "none";
69
+ readonly buttons: readonly [{
70
+ readonly side: "top";
71
+ readonly start: 0.84;
72
+ readonly length: 0.06;
73
+ }];
74
+ };
75
+ };
76
+ type DeviceName = keyof typeof DEVICES;
77
+ declare function resolveDevice(device?: DeviceName | DeviceSpec): DeviceSpec | {
78
+ readonly viewport: {
79
+ readonly width: 390;
80
+ readonly height: 844;
81
+ };
82
+ readonly bezel: 0.036;
83
+ readonly screenRadius: number;
84
+ readonly cutout: "island";
85
+ readonly buttons: readonly [{
86
+ readonly side: "left";
87
+ readonly start: 0.175;
88
+ readonly length: 0.045;
89
+ }, {
90
+ readonly side: "left";
91
+ readonly start: 0.255;
92
+ readonly length: 0.085;
93
+ }, {
94
+ readonly side: "left";
95
+ readonly start: 0.36;
96
+ readonly length: 0.085;
97
+ }, {
98
+ readonly side: "right";
99
+ readonly start: 0.29;
100
+ readonly length: 0.14;
101
+ }];
102
+ } | {
103
+ readonly viewport: {
104
+ readonly width: 1180;
105
+ readonly height: 820;
106
+ };
107
+ readonly bezel: 0.032;
108
+ readonly screenRadius: number;
109
+ readonly cutout: "none";
110
+ readonly buttons: readonly [{
111
+ readonly side: "top";
112
+ readonly start: 0.84;
113
+ readonly length: 0.06;
114
+ }];
115
+ };
116
+ interface DeviceGeometry {
117
+ width: number;
118
+ height: number;
119
+ bezel: number;
120
+ radius: number;
121
+ screen: {
122
+ width: number;
123
+ height: number;
124
+ radius: number;
125
+ };
126
+ /** Absent when the cutout is `none`. */
127
+ island?: {
128
+ width: number;
129
+ height: number;
130
+ top: number;
131
+ };
132
+ buttonDepth: number;
133
+ /** Multiply the viewport by this to fit it to the screen. */
134
+ scale: number;
135
+ }
136
+ /**
137
+ * Every measurement of a device drawn `width` units wide, in the same units.
138
+ * For renderers that can't use the stylesheet, such as React Native.
139
+ */
140
+ declare function deviceGeometry(device: DeviceName | DeviceSpec, width: number, cutout?: Cutout): DeviceGeometry;
141
+ /**
142
+ * The custom properties `styles.css` draws a device from. Lengths are in
143
+ * percent of the device's width and become `cqi` in the stylesheet.
144
+ * `maxHeight` is any CSS length; the width shrinks to keep the shape.
145
+ */
146
+ declare function deviceVars(device?: DeviceName | DeviceSpec, options?: {
147
+ cutout?: Cutout;
148
+ maxHeight?: string;
149
+ }): Record<`--pd-device-${string}`, string>;
150
+
151
+ interface DeviceHTMLOptions {
152
+ /** The screenshot. */
153
+ src: string;
154
+ alt: string;
155
+ device?: DeviceName | DeviceSpec;
156
+ /** Defaults to the device's own cutout. */
157
+ cutout?: Cutout;
158
+ maxHeight?: string;
159
+ className?: string;
160
+ /** The image's pixel size, so the page can reserve its space. */
161
+ width?: number;
162
+ height?: number;
163
+ /** Defaults to `lazy`. */
164
+ loading?: 'lazy' | 'eager';
165
+ }
166
+ /**
167
+ * A screenshot in a device frame, as an HTML string, for pages rendered
168
+ * without React such as Markdown output. Needs `styles.css`.
169
+ */
170
+ declare function deviceHTML(options: DeviceHTMLOptions): string;
171
+
172
+ type DeviceStatus = 'loading' | 'ready' | 'failed';
173
+ interface DeviceProps {
174
+ /** A preset or your own spec. Defaults to `phone`. */
175
+ device?: DeviceName | DeviceSpec;
176
+ /** Defaults to the device's own cutout, except over an iframe, where the
177
+ * embedded page has no safe area and the island would cover its header. */
178
+ cutout?: Cutout;
179
+ /** Any CSS length. The width shrinks so the whole device fits. */
180
+ maxHeight?: string;
181
+ className?: string;
182
+ style?: CSSProperties;
183
+ /** A screenshot, drawn at the screen's size. */
184
+ src?: string;
185
+ alt?: string;
186
+ imgProps?: ImgHTMLAttributes<HTMLImageElement>;
187
+ /** A page, laid out at the device's viewport and scaled to the screen. Takes
188
+ * precedence over `src` and `children`. */
189
+ iframe?: string;
190
+ /** Required with `iframe`; the frame's accessible name. */
191
+ title?: string;
192
+ iframeProps?: IframeHTMLAttributes<HTMLIFrameElement>;
193
+ /** Anything else on the screen. */
194
+ children?: ReactNode;
195
+ /** `screen` (default) draws children at the screen's size; `viewport` lays
196
+ * them out at the device's viewport and scales them, like an iframe. */
197
+ fit?: 'screen' | 'viewport';
198
+ /** Lets pointer events reach the screen content. Off by default, so an
199
+ * embedded page never traps a scroll gesture; an off iframe also leaves
200
+ * the tab order. */
201
+ interactive?: boolean;
202
+ /** Drawn over the screen at the screen's size, e.g. a poster until the
203
+ * embedded page has drawn. Stays interactive. */
204
+ overlay?: ReactNode;
205
+ /** Replaces the iframe, laid out at the viewport, once it has failed. */
206
+ fallback?: ReactNode;
207
+ /** Milliseconds the iframe gets to load after it first scrolls into view
208
+ * before it counts as failed. No timeout when omitted. */
209
+ loadTimeout?: number;
210
+ /** Marks the iframe loaded, for pages that report it themselves (say with
211
+ * `postMessage`) because `load` can fire before hydration. */
212
+ ready?: boolean;
213
+ /** Marks the iframe failed and shows `fallback`. */
214
+ failed?: boolean;
215
+ onStatusChange?: (status: DeviceStatus) => void;
216
+ }
217
+ /**
218
+ * A device frame around a screenshot, an embedded page or any content, drawn
219
+ * in CSS from the proportions in `DEVICES`. Give it a width (or `maxHeight`);
220
+ * the height follows from the device's shape.
221
+ */
222
+ declare function Device({ device, cutout, maxHeight, className, style, src, alt, imgProps, iframe, title, iframeProps, children, fit, interactive, overlay, fallback, loadTimeout, ready, failed, onStatusChange, }: DeviceProps): react.JSX.Element;
223
+
224
+ export { type Cutout, DEVICES, Device, type DeviceButton, type DeviceGeometry, type DeviceHTMLOptions, type DeviceName, type DeviceProps, type DeviceSpec, type DeviceStatus, deviceGeometry, deviceHTML, deviceVars, resolveDevice };
@@ -0,0 +1,224 @@
1
+ import * as react from 'react';
2
+ import { CSSProperties, ImgHTMLAttributes, IframeHTMLAttributes, ReactNode } from 'react';
3
+
4
+ type Cutout = 'island' | 'none';
5
+ interface DeviceButton {
6
+ side: 'left' | 'right' | 'top';
7
+ /** Where the button starts, as a fraction of that side's length. */
8
+ start: number;
9
+ /** Button length, as a fraction of that side's length. */
10
+ length: number;
11
+ }
12
+ interface DeviceSpec {
13
+ /**
14
+ * The CSS-pixel viewport the screen shows. A screenshot or page laid out at
15
+ * this size fills the screen exactly; the frame takes its shape from it.
16
+ */
17
+ viewport: {
18
+ width: number;
19
+ height: number;
20
+ };
21
+ /** Bezel thickness, as a fraction of the device's outer width. */
22
+ bezel: number;
23
+ /** Screen corner radius, as a fraction of the screen width. */
24
+ screenRadius: number;
25
+ cutout: Cutout;
26
+ buttons: readonly DeviceButton[];
27
+ }
28
+ /**
29
+ * Proportions follow the screen, not a particular model: the phone is a
30
+ * 390 × 844 iPhone-class screen (iPhone 12 to 14), the size most app
31
+ * screenshots and phone demos are laid out at; the tablet is an 1180 × 820
32
+ * iPad Air in landscape.
33
+ */
34
+ declare const DEVICES: {
35
+ readonly phone: {
36
+ readonly viewport: {
37
+ readonly width: 390;
38
+ readonly height: 844;
39
+ };
40
+ readonly bezel: 0.036;
41
+ readonly screenRadius: number;
42
+ readonly cutout: "island";
43
+ readonly buttons: readonly [{
44
+ readonly side: "left";
45
+ readonly start: 0.175;
46
+ readonly length: 0.045;
47
+ }, {
48
+ readonly side: "left";
49
+ readonly start: 0.255;
50
+ readonly length: 0.085;
51
+ }, {
52
+ readonly side: "left";
53
+ readonly start: 0.36;
54
+ readonly length: 0.085;
55
+ }, {
56
+ readonly side: "right";
57
+ readonly start: 0.29;
58
+ readonly length: 0.14;
59
+ }];
60
+ };
61
+ readonly tablet: {
62
+ readonly viewport: {
63
+ readonly width: 1180;
64
+ readonly height: 820;
65
+ };
66
+ readonly bezel: 0.032;
67
+ readonly screenRadius: number;
68
+ readonly cutout: "none";
69
+ readonly buttons: readonly [{
70
+ readonly side: "top";
71
+ readonly start: 0.84;
72
+ readonly length: 0.06;
73
+ }];
74
+ };
75
+ };
76
+ type DeviceName = keyof typeof DEVICES;
77
+ declare function resolveDevice(device?: DeviceName | DeviceSpec): DeviceSpec | {
78
+ readonly viewport: {
79
+ readonly width: 390;
80
+ readonly height: 844;
81
+ };
82
+ readonly bezel: 0.036;
83
+ readonly screenRadius: number;
84
+ readonly cutout: "island";
85
+ readonly buttons: readonly [{
86
+ readonly side: "left";
87
+ readonly start: 0.175;
88
+ readonly length: 0.045;
89
+ }, {
90
+ readonly side: "left";
91
+ readonly start: 0.255;
92
+ readonly length: 0.085;
93
+ }, {
94
+ readonly side: "left";
95
+ readonly start: 0.36;
96
+ readonly length: 0.085;
97
+ }, {
98
+ readonly side: "right";
99
+ readonly start: 0.29;
100
+ readonly length: 0.14;
101
+ }];
102
+ } | {
103
+ readonly viewport: {
104
+ readonly width: 1180;
105
+ readonly height: 820;
106
+ };
107
+ readonly bezel: 0.032;
108
+ readonly screenRadius: number;
109
+ readonly cutout: "none";
110
+ readonly buttons: readonly [{
111
+ readonly side: "top";
112
+ readonly start: 0.84;
113
+ readonly length: 0.06;
114
+ }];
115
+ };
116
+ interface DeviceGeometry {
117
+ width: number;
118
+ height: number;
119
+ bezel: number;
120
+ radius: number;
121
+ screen: {
122
+ width: number;
123
+ height: number;
124
+ radius: number;
125
+ };
126
+ /** Absent when the cutout is `none`. */
127
+ island?: {
128
+ width: number;
129
+ height: number;
130
+ top: number;
131
+ };
132
+ buttonDepth: number;
133
+ /** Multiply the viewport by this to fit it to the screen. */
134
+ scale: number;
135
+ }
136
+ /**
137
+ * Every measurement of a device drawn `width` units wide, in the same units.
138
+ * For renderers that can't use the stylesheet, such as React Native.
139
+ */
140
+ declare function deviceGeometry(device: DeviceName | DeviceSpec, width: number, cutout?: Cutout): DeviceGeometry;
141
+ /**
142
+ * The custom properties `styles.css` draws a device from. Lengths are in
143
+ * percent of the device's width and become `cqi` in the stylesheet.
144
+ * `maxHeight` is any CSS length; the width shrinks to keep the shape.
145
+ */
146
+ declare function deviceVars(device?: DeviceName | DeviceSpec, options?: {
147
+ cutout?: Cutout;
148
+ maxHeight?: string;
149
+ }): Record<`--pd-device-${string}`, string>;
150
+
151
+ interface DeviceHTMLOptions {
152
+ /** The screenshot. */
153
+ src: string;
154
+ alt: string;
155
+ device?: DeviceName | DeviceSpec;
156
+ /** Defaults to the device's own cutout. */
157
+ cutout?: Cutout;
158
+ maxHeight?: string;
159
+ className?: string;
160
+ /** The image's pixel size, so the page can reserve its space. */
161
+ width?: number;
162
+ height?: number;
163
+ /** Defaults to `lazy`. */
164
+ loading?: 'lazy' | 'eager';
165
+ }
166
+ /**
167
+ * A screenshot in a device frame, as an HTML string, for pages rendered
168
+ * without React such as Markdown output. Needs `styles.css`.
169
+ */
170
+ declare function deviceHTML(options: DeviceHTMLOptions): string;
171
+
172
+ type DeviceStatus = 'loading' | 'ready' | 'failed';
173
+ interface DeviceProps {
174
+ /** A preset or your own spec. Defaults to `phone`. */
175
+ device?: DeviceName | DeviceSpec;
176
+ /** Defaults to the device's own cutout, except over an iframe, where the
177
+ * embedded page has no safe area and the island would cover its header. */
178
+ cutout?: Cutout;
179
+ /** Any CSS length. The width shrinks so the whole device fits. */
180
+ maxHeight?: string;
181
+ className?: string;
182
+ style?: CSSProperties;
183
+ /** A screenshot, drawn at the screen's size. */
184
+ src?: string;
185
+ alt?: string;
186
+ imgProps?: ImgHTMLAttributes<HTMLImageElement>;
187
+ /** A page, laid out at the device's viewport and scaled to the screen. Takes
188
+ * precedence over `src` and `children`. */
189
+ iframe?: string;
190
+ /** Required with `iframe`; the frame's accessible name. */
191
+ title?: string;
192
+ iframeProps?: IframeHTMLAttributes<HTMLIFrameElement>;
193
+ /** Anything else on the screen. */
194
+ children?: ReactNode;
195
+ /** `screen` (default) draws children at the screen's size; `viewport` lays
196
+ * them out at the device's viewport and scales them, like an iframe. */
197
+ fit?: 'screen' | 'viewport';
198
+ /** Lets pointer events reach the screen content. Off by default, so an
199
+ * embedded page never traps a scroll gesture; an off iframe also leaves
200
+ * the tab order. */
201
+ interactive?: boolean;
202
+ /** Drawn over the screen at the screen's size, e.g. a poster until the
203
+ * embedded page has drawn. Stays interactive. */
204
+ overlay?: ReactNode;
205
+ /** Replaces the iframe, laid out at the viewport, once it has failed. */
206
+ fallback?: ReactNode;
207
+ /** Milliseconds the iframe gets to load after it first scrolls into view
208
+ * before it counts as failed. No timeout when omitted. */
209
+ loadTimeout?: number;
210
+ /** Marks the iframe loaded, for pages that report it themselves (say with
211
+ * `postMessage`) because `load` can fire before hydration. */
212
+ ready?: boolean;
213
+ /** Marks the iframe failed and shows `fallback`. */
214
+ failed?: boolean;
215
+ onStatusChange?: (status: DeviceStatus) => void;
216
+ }
217
+ /**
218
+ * A device frame around a screenshot, an embedded page or any content, drawn
219
+ * in CSS from the proportions in `DEVICES`. Give it a width (or `maxHeight`);
220
+ * the height follows from the device's shape.
221
+ */
222
+ declare function Device({ device, cutout, maxHeight, className, style, src, alt, imgProps, iframe, title, iframeProps, children, fit, interactive, overlay, fallback, loadTimeout, ready, failed, onStatusChange, }: DeviceProps): react.JSX.Element;
223
+
224
+ export { type Cutout, DEVICES, Device, type DeviceButton, type DeviceGeometry, type DeviceHTMLOptions, type DeviceName, type DeviceProps, type DeviceSpec, type DeviceStatus, deviceGeometry, deviceHTML, deviceVars, resolveDevice };