@present-day/device 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -15
- package/dist/core.d.mts +162 -41
- package/dist/core.d.ts +162 -41
- package/dist/core.js +141 -9
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +136 -8
- package/dist/core.mjs.map +1 -1
- package/dist/index.d.mts +178 -44
- package/dist/index.d.ts +178 -44
- package/dist/index.js +232 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +228 -19
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +134 -0
- package/dist/styles.css.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Phone and tablet frames for screenshots, embedded pages and live content. Every frame is drawn in CSS from one set of proportions in [`src/core/devices.ts`](src/core/devices.ts), so a change there reaches every site that uses the package.
|
|
4
4
|
|
|
5
|
-
The frame takes its shape from the content: the phone screen is 390 × 844 CSS pixels (an iPhone 12 to 14), so a screenshot or a page laid out at that size fills it exactly.
|
|
5
|
+
The frame takes its shape from the content: the phone screen is 390 × 844 CSS pixels (an iPhone 12 to 14), so a screenshot or a page laid out at that size fills it exactly. The real-phone presets also draw the status bar and tell the content where the cutout is, the way a phone's safe area does.
|
|
6
|
+
|
|
7
|
+
<table>
|
|
8
|
+
<tr>
|
|
9
|
+
<td align="center"><img src="https://raw.githubusercontent.com/present-day/device/main/.github/readme/phone.webp" alt="The phone preset showing a screenshot" width="160"><br><code>phone</code></td>
|
|
10
|
+
<td align="center"><img src="https://raw.githubusercontent.com/present-day/device/main/.github/readme/iphone-16-pro.webp" alt="The iPhone 16 Pro preset with its Dynamic Island and status bar" width="160"><br><code>iphone-16-pro</code></td>
|
|
11
|
+
<td align="center"><img src="https://raw.githubusercontent.com/present-day/device/main/.github/readme/pixel-9.webp" alt="The Pixel 9 preset with its punch-hole camera" width="160"><br><code>pixel-9</code></td>
|
|
12
|
+
<td align="center"><img src="https://raw.githubusercontent.com/present-day/device/main/.github/readme/tablet.webp" alt="The tablet preset showing a screenshot" width="320"><br><code>tablet</code></td>
|
|
13
|
+
</tr>
|
|
14
|
+
</table>
|
|
6
15
|
|
|
7
16
|
```sh
|
|
8
17
|
npm i @present-day/device
|
|
@@ -27,20 +36,67 @@ import { Device } from '@present-day/device'
|
|
|
27
36
|
|
|
28
37
|
The stylesheet is imported for you. Give the device a width, or a `maxHeight` (any CSS length); its height follows from the shape.
|
|
29
38
|
|
|
30
|
-
| Prop | Default |
|
|
31
|
-
| -------------------------------- | --------------- |
|
|
32
|
-
| `device` | `'phone'` |
|
|
33
|
-
| `cutout` | the device's | `'island'` or `'
|
|
34
|
-
| `
|
|
35
|
-
| `
|
|
36
|
-
| `
|
|
37
|
-
| `
|
|
38
|
-
| `
|
|
39
|
-
| `
|
|
40
|
-
| `
|
|
41
|
-
| `
|
|
42
|
-
| `
|
|
43
|
-
| `
|
|
39
|
+
| Prop | Default | |
|
|
40
|
+
| -------------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
41
|
+
| `device` | `'phone'` | A preset (below) or your own `DeviceSpec` |
|
|
42
|
+
| `cutout` | the device's | `'island'`, `'none'`, or a shape: `{ type: 'island', width, height, top }` or `{ type: 'hole', diameter, top, x }`. Lengths are viewport px; a hole's `x` is its center as a fraction of the screen width (default `0.5`). On `phone` it defaults to `'none'` over an iframe. `'none'` hides the drawing; the insets still come from the device |
|
|
43
|
+
| `safeArea` | see below | `'expose'`, `'reserve'` or `'none'`, on presets with a safe area |
|
|
44
|
+
| `statusBarStyle` | `'dark'` | `'dark'` text for light content, `'light'` for dark |
|
|
45
|
+
| `maxHeight` | | Any CSS length; the width shrinks to keep the whole device in it |
|
|
46
|
+
| `src`, `alt`, `imgProps` | | A screenshot, drawn at the screen's size |
|
|
47
|
+
| `iframe`, `title`, `iframeProps` | | A page laid out at the viewport and scaled to the screen. Wins over `src` and `children` |
|
|
48
|
+
| `children`, `fit` | `fit: 'screen'` | Any content. `fit: 'viewport'` lays it out at the viewport and scales it like an iframe |
|
|
49
|
+
| `interactive` | `false` | Lets pointer events reach the screen. Off, an iframe also leaves the tab order, so it never traps a scroll |
|
|
50
|
+
| `overlay` | | Drawn over the screen and stays interactive, e.g. a poster until the page has drawn |
|
|
51
|
+
| `fallback` | | Replaces the iframe, laid out at the viewport, once it has failed |
|
|
52
|
+
| `loadTimeout` | | Milliseconds the iframe gets after it first scrolls into view before it counts as failed |
|
|
53
|
+
| `ready`, `failed` | | Outside signals, e.g. from `postMessage`, since `load` can fire before hydration |
|
|
54
|
+
| `onStatusChange` | | `'loading'`, `'ready'` or `'failed'` |
|
|
55
|
+
|
|
56
|
+
## Presets
|
|
57
|
+
|
|
58
|
+
| `device` | Viewport | Cutout | Safe area (top, bottom) |
|
|
59
|
+
| --------------- | ---------- | --------------------------------- | ----------------------- |
|
|
60
|
+
| `phone` | 390 × 844 | Dynamic Island | none |
|
|
61
|
+
| `tablet` | 1180 × 820 | none | none |
|
|
62
|
+
| `iphone-16-pro` | 402 × 874 | Dynamic Island, 125 × 36.67 | 62, 34 |
|
|
63
|
+
| `pixel-9` | 412 × 923 | Punch hole, 30.5 across, centered | 50, 24 |
|
|
64
|
+
|
|
65
|
+
The iPhone 16 Pro numbers come from the iOS Simulator; the Pixel 9's from the Android emulator's device definition and skin. The Pixel's insets are approximate, since its status bar height isn't published.
|
|
66
|
+
|
|
67
|
+
## The safe area
|
|
68
|
+
|
|
69
|
+
On a preset with a safe area, `safeArea` decides how the content meets the cutout:
|
|
70
|
+
|
|
71
|
+
| Mode | Default for | What happens |
|
|
72
|
+
| --------- | ----------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
73
|
+
| `reserve` | `iframe` and `children` | Solid status bar and home bands; the content gets the screen between them. Works with any content |
|
|
74
|
+
| `expose` | | Content runs edge to edge under a transparent status bar and gets the insets, so it can clear the cutout itself |
|
|
75
|
+
| `none` | `src` | No status bar or insets; a screenshot carries its own |
|
|
76
|
+
|
|
77
|
+
<table>
|
|
78
|
+
<tr>
|
|
79
|
+
<td align="center"><img src="https://raw.githubusercontent.com/present-day/device/main/.github/readme/safe-area-reserve.webp" alt="Reserve: solid status bar and home bands around the content" width="180"><br><code>reserve</code></td>
|
|
80
|
+
<td align="center"><img src="https://raw.githubusercontent.com/present-day/device/main/.github/readme/iphone-16-pro.webp" alt="Expose: content runs edge to edge and clears the Dynamic Island itself" width="180"><br><code>expose</code></td>
|
|
81
|
+
<td align="center"><img src="https://raw.githubusercontent.com/present-day/device/main/.github/readme/safe-area-none.webp" alt="None: no status bar or insets, so the header sits under the Dynamic Island" width="180"><br><code>none</code></td>
|
|
82
|
+
</tr>
|
|
83
|
+
</table>
|
|
84
|
+
|
|
85
|
+
In `expose`, content reads four CSS variables, `--pd-safe-top`, `--pd-safe-right`, `--pd-safe-bottom` and `--pd-safe-left`. Fall back to `env()` and the same CSS works on a real phone:
|
|
86
|
+
|
|
87
|
+
```css
|
|
88
|
+
padding-top: var(--pd-safe-top, env(safe-area-inset-top, 0px));
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
React children get the variables on their wrapper. An iframe gets them through its URL: the frame adds `pd-safe-area=top,right,bottom,left` (CSS px), and the page applies it once at startup:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { applySafeArea } from '@present-day/device/core'
|
|
95
|
+
|
|
96
|
+
applySafeArea() // sets --pd-safe-* on <html>; does nothing without the parameter
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`withSafeArea(url, insets)` builds the same URL yourself. Changing the device or mode changes the URL, which reloads the iframe.
|
|
44
100
|
|
|
45
101
|
## Without React
|
|
46
102
|
|
|
@@ -62,6 +118,7 @@ deviceHTML({ src: '/shots/map.webp', alt: 'The map', width: 390, height: 844 })
|
|
|
62
118
|
| `--pd-device-screen-color` | `#000` (behind content while it loads) |
|
|
63
119
|
| `--pd-device-edge` | `hsl(0 0% 50% / 0.25)` (hairline that keeps the body visible on dark pages) |
|
|
64
120
|
| `--pd-device-shadow` | `0 24px 48px -24px rgb(0 0 0 / 0.45)` |
|
|
121
|
+
| `--pd-device-status-color` | `#fff`, or `#000` with `statusBarStyle="light"` (the bands in `reserve`) |
|
|
65
122
|
|
|
66
123
|
## Development
|
|
67
124
|
|
package/dist/core.d.mts
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
/** A cutout's shape and place, in viewport CSS px. */
|
|
2
|
+
type CutoutSpec = {
|
|
3
|
+
type: 'island';
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
top: number;
|
|
7
|
+
} | {
|
|
8
|
+
type: 'hole';
|
|
9
|
+
diameter: number;
|
|
10
|
+
/** Distance from the screen's top edge to the hole's top. */
|
|
11
|
+
top: number;
|
|
12
|
+
/** The hole's center as a fraction of the screen width. Defaults to 0.5. */
|
|
13
|
+
x?: number;
|
|
14
|
+
};
|
|
15
|
+
/** `'island'` is the Dynamic Island in proportion to the screen width. */
|
|
16
|
+
type Cutout = 'island' | 'none' | CutoutSpec;
|
|
17
|
+
/** Insets from each screen edge that content should clear, in viewport CSS px, portrait. */
|
|
18
|
+
interface SafeArea {
|
|
19
|
+
top: number;
|
|
20
|
+
right: number;
|
|
21
|
+
bottom: number;
|
|
22
|
+
left: number;
|
|
23
|
+
}
|
|
2
24
|
interface DeviceButton {
|
|
3
25
|
side: 'left' | 'right' | 'top';
|
|
4
26
|
/** Where the button starts, as a fraction of that side's length. */
|
|
@@ -21,6 +43,27 @@ interface DeviceSpec {
|
|
|
21
43
|
screenRadius: number;
|
|
22
44
|
cutout: Cutout;
|
|
23
45
|
buttons: readonly DeviceButton[];
|
|
46
|
+
/** Hardware insets content should clear. Without it the device draws no status bar. */
|
|
47
|
+
safeArea?: SafeArea;
|
|
48
|
+
statusBar?: StatusBarSpec;
|
|
49
|
+
homeIndicator?: HomeIndicatorSpec;
|
|
50
|
+
}
|
|
51
|
+
/** Where the status bar sits, in viewport CSS px. */
|
|
52
|
+
interface StatusBarSpec {
|
|
53
|
+
/** The time's center, from the screen's left edge. */
|
|
54
|
+
time: number;
|
|
55
|
+
/** The icons' center, from the screen's right edge. */
|
|
56
|
+
icons: number;
|
|
57
|
+
/** The text's vertical center, from the screen's top edge. */
|
|
58
|
+
center: number;
|
|
59
|
+
fontSize: number;
|
|
60
|
+
}
|
|
61
|
+
/** The home indicator or gesture bar, in viewport CSS px. */
|
|
62
|
+
interface HomeIndicatorSpec {
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
/** Gap between the bar and the screen's bottom edge. */
|
|
66
|
+
bottom: number;
|
|
24
67
|
}
|
|
25
68
|
/**
|
|
26
69
|
* Proportions follow the screen, not a particular model: the phone is a
|
|
@@ -69,47 +112,101 @@ declare const DEVICES: {
|
|
|
69
112
|
readonly length: 0.06;
|
|
70
113
|
}];
|
|
71
114
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
readonly
|
|
115
|
+
readonly 'iphone-16-pro': {
|
|
116
|
+
readonly viewport: {
|
|
117
|
+
readonly width: 402;
|
|
118
|
+
readonly height: 874;
|
|
119
|
+
};
|
|
120
|
+
readonly bezel: 0.034;
|
|
121
|
+
readonly screenRadius: number;
|
|
122
|
+
readonly cutout: {
|
|
123
|
+
readonly type: "island";
|
|
124
|
+
readonly width: 125;
|
|
125
|
+
readonly height: 36.67;
|
|
126
|
+
readonly top: 14;
|
|
127
|
+
};
|
|
128
|
+
readonly safeArea: {
|
|
129
|
+
readonly top: 62;
|
|
130
|
+
readonly right: 0;
|
|
131
|
+
readonly bottom: 34;
|
|
132
|
+
readonly left: 0;
|
|
133
|
+
};
|
|
134
|
+
readonly statusBar: {
|
|
135
|
+
readonly time: 74;
|
|
136
|
+
readonly icons: 73;
|
|
137
|
+
readonly center: 33;
|
|
138
|
+
readonly fontSize: 17;
|
|
139
|
+
};
|
|
140
|
+
readonly homeIndicator: {
|
|
141
|
+
readonly width: 134;
|
|
142
|
+
readonly height: 5;
|
|
143
|
+
readonly bottom: 8;
|
|
144
|
+
};
|
|
145
|
+
readonly buttons: readonly [{
|
|
146
|
+
readonly side: "left";
|
|
147
|
+
readonly start: 0.175;
|
|
148
|
+
readonly length: 0.045;
|
|
149
|
+
}, {
|
|
150
|
+
readonly side: "left";
|
|
151
|
+
readonly start: 0.255;
|
|
152
|
+
readonly length: 0.085;
|
|
153
|
+
}, {
|
|
154
|
+
readonly side: "left";
|
|
155
|
+
readonly start: 0.36;
|
|
156
|
+
readonly length: 0.085;
|
|
157
|
+
}, {
|
|
158
|
+
readonly side: "right";
|
|
159
|
+
readonly start: 0.29;
|
|
160
|
+
readonly length: 0.14;
|
|
161
|
+
}, {
|
|
162
|
+
readonly side: "right";
|
|
163
|
+
readonly start: 0.6;
|
|
164
|
+
readonly length: 0.07;
|
|
165
|
+
}];
|
|
78
166
|
};
|
|
79
|
-
readonly
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
readonly
|
|
85
|
-
readonly
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
readonly
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
167
|
+
readonly 'pixel-9': {
|
|
168
|
+
readonly viewport: {
|
|
169
|
+
readonly width: 412;
|
|
170
|
+
readonly height: 923;
|
|
171
|
+
};
|
|
172
|
+
readonly bezel: 0.034;
|
|
173
|
+
readonly screenRadius: number;
|
|
174
|
+
readonly cutout: {
|
|
175
|
+
readonly type: "hole";
|
|
176
|
+
readonly diameter: 30.5;
|
|
177
|
+
readonly top: 17.5;
|
|
178
|
+
readonly x: 0.5;
|
|
179
|
+
};
|
|
180
|
+
readonly safeArea: {
|
|
181
|
+
readonly top: 50;
|
|
182
|
+
readonly right: 0;
|
|
183
|
+
readonly bottom: 24;
|
|
184
|
+
readonly left: 0;
|
|
185
|
+
};
|
|
186
|
+
readonly statusBar: {
|
|
187
|
+
readonly time: 42;
|
|
188
|
+
readonly icons: 50;
|
|
189
|
+
readonly center: 26;
|
|
190
|
+
readonly fontSize: 14;
|
|
191
|
+
};
|
|
192
|
+
readonly homeIndicator: {
|
|
193
|
+
readonly width: 108;
|
|
194
|
+
readonly height: 4;
|
|
195
|
+
readonly bottom: 10;
|
|
196
|
+
};
|
|
197
|
+
readonly buttons: readonly [{
|
|
198
|
+
readonly side: "right";
|
|
199
|
+
readonly start: 0.22;
|
|
200
|
+
readonly length: 0.07;
|
|
201
|
+
}, {
|
|
202
|
+
readonly side: "right";
|
|
203
|
+
readonly start: 0.33;
|
|
204
|
+
readonly length: 0.14;
|
|
205
|
+
}];
|
|
103
206
|
};
|
|
104
|
-
readonly bezel: 0.032;
|
|
105
|
-
readonly screenRadius: number;
|
|
106
|
-
readonly cutout: "none";
|
|
107
|
-
readonly buttons: readonly [{
|
|
108
|
-
readonly side: "top";
|
|
109
|
-
readonly start: 0.84;
|
|
110
|
-
readonly length: 0.06;
|
|
111
|
-
}];
|
|
112
207
|
};
|
|
208
|
+
type DeviceName = keyof typeof DEVICES;
|
|
209
|
+
declare function resolveDevice(device?: DeviceName | DeviceSpec): DeviceSpec;
|
|
113
210
|
interface DeviceGeometry {
|
|
114
211
|
width: number;
|
|
115
212
|
height: number;
|
|
@@ -120,12 +217,19 @@ interface DeviceGeometry {
|
|
|
120
217
|
height: number;
|
|
121
218
|
radius: number;
|
|
122
219
|
};
|
|
123
|
-
/** Absent when the cutout is `none`. */
|
|
124
220
|
island?: {
|
|
125
221
|
width: number;
|
|
126
222
|
height: number;
|
|
127
223
|
top: number;
|
|
128
224
|
};
|
|
225
|
+
/** `x` is the hole's center as a fraction of the screen width. */
|
|
226
|
+
hole?: {
|
|
227
|
+
diameter: number;
|
|
228
|
+
top: number;
|
|
229
|
+
x: number;
|
|
230
|
+
};
|
|
231
|
+
/** Present when the spec has one, whatever the cutout. */
|
|
232
|
+
safeArea?: SafeArea;
|
|
129
233
|
buttonDepth: number;
|
|
130
234
|
/** Multiply the viewport by this to fit it to the screen. */
|
|
131
235
|
scale: number;
|
|
@@ -166,4 +270,21 @@ interface DeviceHTMLOptions {
|
|
|
166
270
|
*/
|
|
167
271
|
declare function deviceHTML(options: DeviceHTMLOptions): string;
|
|
168
272
|
|
|
169
|
-
|
|
273
|
+
/** The query parameter a framed page reads its insets from: `top,right,bottom,left` in CSS px. */
|
|
274
|
+
declare const SAFE_AREA_PARAM = "pd-safe-area";
|
|
275
|
+
/**
|
|
276
|
+
* `url` with `pd-safe-area` set to the insets, rounded to whole pixels. The
|
|
277
|
+
* rest of the URL is kept exactly as given, relative or not. URLs that aren't
|
|
278
|
+
* http(s) or relative, such as `data:` and `about:blank`, come back unchanged.
|
|
279
|
+
*/
|
|
280
|
+
declare function withSafeArea(url: string, insets: SafeArea): string;
|
|
281
|
+
/** The insets in a query string, or null when the parameter is absent or malformed. */
|
|
282
|
+
declare function readSafeArea(search: string): SafeArea | null;
|
|
283
|
+
/**
|
|
284
|
+
* Sets `--pd-safe-top`, `--pd-safe-right`, `--pd-safe-bottom` and
|
|
285
|
+
* `--pd-safe-left` on `target` from the page URL's `pd-safe-area`. Does
|
|
286
|
+
* nothing when it's absent, so CSS falls back to `env(safe-area-inset-*)`.
|
|
287
|
+
*/
|
|
288
|
+
declare function applySafeArea(target?: HTMLElement, search?: string): SafeArea | null;
|
|
289
|
+
|
|
290
|
+
export { type Cutout, type CutoutSpec, DEVICES, type DeviceButton, type DeviceGeometry, type DeviceHTMLOptions, type DeviceName, type DeviceSpec, type HomeIndicatorSpec, SAFE_AREA_PARAM, type SafeArea, type StatusBarSpec, applySafeArea, deviceGeometry, deviceHTML, deviceVars, readSafeArea, resolveDevice, withSafeArea };
|
package/dist/core.d.ts
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
/** A cutout's shape and place, in viewport CSS px. */
|
|
2
|
+
type CutoutSpec = {
|
|
3
|
+
type: 'island';
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
top: number;
|
|
7
|
+
} | {
|
|
8
|
+
type: 'hole';
|
|
9
|
+
diameter: number;
|
|
10
|
+
/** Distance from the screen's top edge to the hole's top. */
|
|
11
|
+
top: number;
|
|
12
|
+
/** The hole's center as a fraction of the screen width. Defaults to 0.5. */
|
|
13
|
+
x?: number;
|
|
14
|
+
};
|
|
15
|
+
/** `'island'` is the Dynamic Island in proportion to the screen width. */
|
|
16
|
+
type Cutout = 'island' | 'none' | CutoutSpec;
|
|
17
|
+
/** Insets from each screen edge that content should clear, in viewport CSS px, portrait. */
|
|
18
|
+
interface SafeArea {
|
|
19
|
+
top: number;
|
|
20
|
+
right: number;
|
|
21
|
+
bottom: number;
|
|
22
|
+
left: number;
|
|
23
|
+
}
|
|
2
24
|
interface DeviceButton {
|
|
3
25
|
side: 'left' | 'right' | 'top';
|
|
4
26
|
/** Where the button starts, as a fraction of that side's length. */
|
|
@@ -21,6 +43,27 @@ interface DeviceSpec {
|
|
|
21
43
|
screenRadius: number;
|
|
22
44
|
cutout: Cutout;
|
|
23
45
|
buttons: readonly DeviceButton[];
|
|
46
|
+
/** Hardware insets content should clear. Without it the device draws no status bar. */
|
|
47
|
+
safeArea?: SafeArea;
|
|
48
|
+
statusBar?: StatusBarSpec;
|
|
49
|
+
homeIndicator?: HomeIndicatorSpec;
|
|
50
|
+
}
|
|
51
|
+
/** Where the status bar sits, in viewport CSS px. */
|
|
52
|
+
interface StatusBarSpec {
|
|
53
|
+
/** The time's center, from the screen's left edge. */
|
|
54
|
+
time: number;
|
|
55
|
+
/** The icons' center, from the screen's right edge. */
|
|
56
|
+
icons: number;
|
|
57
|
+
/** The text's vertical center, from the screen's top edge. */
|
|
58
|
+
center: number;
|
|
59
|
+
fontSize: number;
|
|
60
|
+
}
|
|
61
|
+
/** The home indicator or gesture bar, in viewport CSS px. */
|
|
62
|
+
interface HomeIndicatorSpec {
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
/** Gap between the bar and the screen's bottom edge. */
|
|
66
|
+
bottom: number;
|
|
24
67
|
}
|
|
25
68
|
/**
|
|
26
69
|
* Proportions follow the screen, not a particular model: the phone is a
|
|
@@ -69,47 +112,101 @@ declare const DEVICES: {
|
|
|
69
112
|
readonly length: 0.06;
|
|
70
113
|
}];
|
|
71
114
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
readonly
|
|
115
|
+
readonly 'iphone-16-pro': {
|
|
116
|
+
readonly viewport: {
|
|
117
|
+
readonly width: 402;
|
|
118
|
+
readonly height: 874;
|
|
119
|
+
};
|
|
120
|
+
readonly bezel: 0.034;
|
|
121
|
+
readonly screenRadius: number;
|
|
122
|
+
readonly cutout: {
|
|
123
|
+
readonly type: "island";
|
|
124
|
+
readonly width: 125;
|
|
125
|
+
readonly height: 36.67;
|
|
126
|
+
readonly top: 14;
|
|
127
|
+
};
|
|
128
|
+
readonly safeArea: {
|
|
129
|
+
readonly top: 62;
|
|
130
|
+
readonly right: 0;
|
|
131
|
+
readonly bottom: 34;
|
|
132
|
+
readonly left: 0;
|
|
133
|
+
};
|
|
134
|
+
readonly statusBar: {
|
|
135
|
+
readonly time: 74;
|
|
136
|
+
readonly icons: 73;
|
|
137
|
+
readonly center: 33;
|
|
138
|
+
readonly fontSize: 17;
|
|
139
|
+
};
|
|
140
|
+
readonly homeIndicator: {
|
|
141
|
+
readonly width: 134;
|
|
142
|
+
readonly height: 5;
|
|
143
|
+
readonly bottom: 8;
|
|
144
|
+
};
|
|
145
|
+
readonly buttons: readonly [{
|
|
146
|
+
readonly side: "left";
|
|
147
|
+
readonly start: 0.175;
|
|
148
|
+
readonly length: 0.045;
|
|
149
|
+
}, {
|
|
150
|
+
readonly side: "left";
|
|
151
|
+
readonly start: 0.255;
|
|
152
|
+
readonly length: 0.085;
|
|
153
|
+
}, {
|
|
154
|
+
readonly side: "left";
|
|
155
|
+
readonly start: 0.36;
|
|
156
|
+
readonly length: 0.085;
|
|
157
|
+
}, {
|
|
158
|
+
readonly side: "right";
|
|
159
|
+
readonly start: 0.29;
|
|
160
|
+
readonly length: 0.14;
|
|
161
|
+
}, {
|
|
162
|
+
readonly side: "right";
|
|
163
|
+
readonly start: 0.6;
|
|
164
|
+
readonly length: 0.07;
|
|
165
|
+
}];
|
|
78
166
|
};
|
|
79
|
-
readonly
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
readonly
|
|
85
|
-
readonly
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
readonly
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
167
|
+
readonly 'pixel-9': {
|
|
168
|
+
readonly viewport: {
|
|
169
|
+
readonly width: 412;
|
|
170
|
+
readonly height: 923;
|
|
171
|
+
};
|
|
172
|
+
readonly bezel: 0.034;
|
|
173
|
+
readonly screenRadius: number;
|
|
174
|
+
readonly cutout: {
|
|
175
|
+
readonly type: "hole";
|
|
176
|
+
readonly diameter: 30.5;
|
|
177
|
+
readonly top: 17.5;
|
|
178
|
+
readonly x: 0.5;
|
|
179
|
+
};
|
|
180
|
+
readonly safeArea: {
|
|
181
|
+
readonly top: 50;
|
|
182
|
+
readonly right: 0;
|
|
183
|
+
readonly bottom: 24;
|
|
184
|
+
readonly left: 0;
|
|
185
|
+
};
|
|
186
|
+
readonly statusBar: {
|
|
187
|
+
readonly time: 42;
|
|
188
|
+
readonly icons: 50;
|
|
189
|
+
readonly center: 26;
|
|
190
|
+
readonly fontSize: 14;
|
|
191
|
+
};
|
|
192
|
+
readonly homeIndicator: {
|
|
193
|
+
readonly width: 108;
|
|
194
|
+
readonly height: 4;
|
|
195
|
+
readonly bottom: 10;
|
|
196
|
+
};
|
|
197
|
+
readonly buttons: readonly [{
|
|
198
|
+
readonly side: "right";
|
|
199
|
+
readonly start: 0.22;
|
|
200
|
+
readonly length: 0.07;
|
|
201
|
+
}, {
|
|
202
|
+
readonly side: "right";
|
|
203
|
+
readonly start: 0.33;
|
|
204
|
+
readonly length: 0.14;
|
|
205
|
+
}];
|
|
103
206
|
};
|
|
104
|
-
readonly bezel: 0.032;
|
|
105
|
-
readonly screenRadius: number;
|
|
106
|
-
readonly cutout: "none";
|
|
107
|
-
readonly buttons: readonly [{
|
|
108
|
-
readonly side: "top";
|
|
109
|
-
readonly start: 0.84;
|
|
110
|
-
readonly length: 0.06;
|
|
111
|
-
}];
|
|
112
207
|
};
|
|
208
|
+
type DeviceName = keyof typeof DEVICES;
|
|
209
|
+
declare function resolveDevice(device?: DeviceName | DeviceSpec): DeviceSpec;
|
|
113
210
|
interface DeviceGeometry {
|
|
114
211
|
width: number;
|
|
115
212
|
height: number;
|
|
@@ -120,12 +217,19 @@ interface DeviceGeometry {
|
|
|
120
217
|
height: number;
|
|
121
218
|
radius: number;
|
|
122
219
|
};
|
|
123
|
-
/** Absent when the cutout is `none`. */
|
|
124
220
|
island?: {
|
|
125
221
|
width: number;
|
|
126
222
|
height: number;
|
|
127
223
|
top: number;
|
|
128
224
|
};
|
|
225
|
+
/** `x` is the hole's center as a fraction of the screen width. */
|
|
226
|
+
hole?: {
|
|
227
|
+
diameter: number;
|
|
228
|
+
top: number;
|
|
229
|
+
x: number;
|
|
230
|
+
};
|
|
231
|
+
/** Present when the spec has one, whatever the cutout. */
|
|
232
|
+
safeArea?: SafeArea;
|
|
129
233
|
buttonDepth: number;
|
|
130
234
|
/** Multiply the viewport by this to fit it to the screen. */
|
|
131
235
|
scale: number;
|
|
@@ -166,4 +270,21 @@ interface DeviceHTMLOptions {
|
|
|
166
270
|
*/
|
|
167
271
|
declare function deviceHTML(options: DeviceHTMLOptions): string;
|
|
168
272
|
|
|
169
|
-
|
|
273
|
+
/** The query parameter a framed page reads its insets from: `top,right,bottom,left` in CSS px. */
|
|
274
|
+
declare const SAFE_AREA_PARAM = "pd-safe-area";
|
|
275
|
+
/**
|
|
276
|
+
* `url` with `pd-safe-area` set to the insets, rounded to whole pixels. The
|
|
277
|
+
* rest of the URL is kept exactly as given, relative or not. URLs that aren't
|
|
278
|
+
* http(s) or relative, such as `data:` and `about:blank`, come back unchanged.
|
|
279
|
+
*/
|
|
280
|
+
declare function withSafeArea(url: string, insets: SafeArea): string;
|
|
281
|
+
/** The insets in a query string, or null when the parameter is absent or malformed. */
|
|
282
|
+
declare function readSafeArea(search: string): SafeArea | null;
|
|
283
|
+
/**
|
|
284
|
+
* Sets `--pd-safe-top`, `--pd-safe-right`, `--pd-safe-bottom` and
|
|
285
|
+
* `--pd-safe-left` on `target` from the page URL's `pd-safe-area`. Does
|
|
286
|
+
* nothing when it's absent, so CSS falls back to `env(safe-area-inset-*)`.
|
|
287
|
+
*/
|
|
288
|
+
declare function applySafeArea(target?: HTMLElement, search?: string): SafeArea | null;
|
|
289
|
+
|
|
290
|
+
export { type Cutout, type CutoutSpec, DEVICES, type DeviceButton, type DeviceGeometry, type DeviceHTMLOptions, type DeviceName, type DeviceSpec, type HomeIndicatorSpec, SAFE_AREA_PARAM, type SafeArea, type StatusBarSpec, applySafeArea, deviceGeometry, deviceHTML, deviceVars, readSafeArea, resolveDevice, withSafeArea };
|