@present-day/device 0.1.0 → 0.2.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.
package/dist/index.d.mts CHANGED
@@ -1,7 +1,29 @@
1
1
  import * as react from 'react';
2
2
  import { CSSProperties, ImgHTMLAttributes, IframeHTMLAttributes, ReactNode } from 'react';
3
3
 
4
- type Cutout = 'island' | 'none';
4
+ /** A cutout's shape and place, in viewport CSS px. */
5
+ type CutoutSpec = {
6
+ type: 'island';
7
+ width: number;
8
+ height: number;
9
+ top: number;
10
+ } | {
11
+ type: 'hole';
12
+ diameter: number;
13
+ /** Distance from the screen's top edge to the hole's top. */
14
+ top: number;
15
+ /** The hole's center as a fraction of the screen width. Defaults to 0.5. */
16
+ x?: number;
17
+ };
18
+ /** `'island'` is the Dynamic Island in proportion to the screen width. */
19
+ type Cutout = 'island' | 'none' | CutoutSpec;
20
+ /** Insets from each screen edge that content should clear, in viewport CSS px, portrait. */
21
+ interface SafeArea {
22
+ top: number;
23
+ right: number;
24
+ bottom: number;
25
+ left: number;
26
+ }
5
27
  interface DeviceButton {
6
28
  side: 'left' | 'right' | 'top';
7
29
  /** Where the button starts, as a fraction of that side's length. */
@@ -24,6 +46,27 @@ interface DeviceSpec {
24
46
  screenRadius: number;
25
47
  cutout: Cutout;
26
48
  buttons: readonly DeviceButton[];
49
+ /** Hardware insets content should clear. Without it the device draws no status bar. */
50
+ safeArea?: SafeArea;
51
+ statusBar?: StatusBarSpec;
52
+ homeIndicator?: HomeIndicatorSpec;
53
+ }
54
+ /** Where the status bar sits, in viewport CSS px. */
55
+ interface StatusBarSpec {
56
+ /** The time's center, from the screen's left edge. */
57
+ time: number;
58
+ /** The icons' center, from the screen's right edge. */
59
+ icons: number;
60
+ /** The text's vertical center, from the screen's top edge. */
61
+ center: number;
62
+ fontSize: number;
63
+ }
64
+ /** The home indicator or gesture bar, in viewport CSS px. */
65
+ interface HomeIndicatorSpec {
66
+ width: number;
67
+ height: number;
68
+ /** Gap between the bar and the screen's bottom edge. */
69
+ bottom: number;
27
70
  }
28
71
  /**
29
72
  * Proportions follow the screen, not a particular model: the phone is a
@@ -72,47 +115,101 @@ declare const DEVICES: {
72
115
  readonly length: 0.06;
73
116
  }];
74
117
  };
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;
118
+ readonly 'iphone-16-pro': {
119
+ readonly viewport: {
120
+ readonly width: 402;
121
+ readonly height: 874;
122
+ };
123
+ readonly bezel: 0.034;
124
+ readonly screenRadius: number;
125
+ readonly cutout: {
126
+ readonly type: "island";
127
+ readonly width: 125;
128
+ readonly height: 36.67;
129
+ readonly top: 14;
130
+ };
131
+ readonly safeArea: {
132
+ readonly top: 62;
133
+ readonly right: 0;
134
+ readonly bottom: 34;
135
+ readonly left: 0;
136
+ };
137
+ readonly statusBar: {
138
+ readonly time: 74;
139
+ readonly icons: 73;
140
+ readonly center: 33;
141
+ readonly fontSize: 17;
142
+ };
143
+ readonly homeIndicator: {
144
+ readonly width: 134;
145
+ readonly height: 5;
146
+ readonly bottom: 8;
147
+ };
148
+ readonly buttons: readonly [{
149
+ readonly side: "left";
150
+ readonly start: 0.175;
151
+ readonly length: 0.045;
152
+ }, {
153
+ readonly side: "left";
154
+ readonly start: 0.255;
155
+ readonly length: 0.085;
156
+ }, {
157
+ readonly side: "left";
158
+ readonly start: 0.36;
159
+ readonly length: 0.085;
160
+ }, {
161
+ readonly side: "right";
162
+ readonly start: 0.29;
163
+ readonly length: 0.14;
164
+ }, {
165
+ readonly side: "right";
166
+ readonly start: 0.6;
167
+ readonly length: 0.07;
168
+ }];
81
169
  };
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;
170
+ readonly 'pixel-9': {
171
+ readonly viewport: {
172
+ readonly width: 412;
173
+ readonly height: 923;
174
+ };
175
+ readonly bezel: 0.034;
176
+ readonly screenRadius: number;
177
+ readonly cutout: {
178
+ readonly type: "hole";
179
+ readonly diameter: 30.5;
180
+ readonly top: 17.5;
181
+ readonly x: 0.5;
182
+ };
183
+ readonly safeArea: {
184
+ readonly top: 50;
185
+ readonly right: 0;
186
+ readonly bottom: 24;
187
+ readonly left: 0;
188
+ };
189
+ readonly statusBar: {
190
+ readonly time: 42;
191
+ readonly icons: 50;
192
+ readonly center: 26;
193
+ readonly fontSize: 14;
194
+ };
195
+ readonly homeIndicator: {
196
+ readonly width: 108;
197
+ readonly height: 4;
198
+ readonly bottom: 10;
199
+ };
200
+ readonly buttons: readonly [{
201
+ readonly side: "right";
202
+ readonly start: 0.22;
203
+ readonly length: 0.07;
204
+ }, {
205
+ readonly side: "right";
206
+ readonly start: 0.33;
207
+ readonly length: 0.14;
208
+ }];
106
209
  };
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
210
  };
211
+ type DeviceName = keyof typeof DEVICES;
212
+ declare function resolveDevice(device?: DeviceName | DeviceSpec): DeviceSpec;
116
213
  interface DeviceGeometry {
117
214
  width: number;
118
215
  height: number;
@@ -123,12 +220,19 @@ interface DeviceGeometry {
123
220
  height: number;
124
221
  radius: number;
125
222
  };
126
- /** Absent when the cutout is `none`. */
127
223
  island?: {
128
224
  width: number;
129
225
  height: number;
130
226
  top: number;
131
227
  };
228
+ /** `x` is the hole's center as a fraction of the screen width. */
229
+ hole?: {
230
+ diameter: number;
231
+ top: number;
232
+ x: number;
233
+ };
234
+ /** Present when the spec has one, whatever the cutout. */
235
+ safeArea?: SafeArea;
132
236
  buttonDepth: number;
133
237
  /** Multiply the viewport by this to fit it to the screen. */
134
238
  scale: number;
@@ -169,13 +273,43 @@ interface DeviceHTMLOptions {
169
273
  */
170
274
  declare function deviceHTML(options: DeviceHTMLOptions): string;
171
275
 
276
+ /** The query parameter a framed page reads its insets from: `top,right,bottom,left` in CSS px. */
277
+ declare const SAFE_AREA_PARAM = "pd-safe-area";
278
+ /**
279
+ * `url` with `pd-safe-area` set to the insets, rounded to whole pixels. The
280
+ * rest of the URL is kept exactly as given, relative or not. URLs that aren't
281
+ * http(s) or relative, such as `data:` and `about:blank`, come back unchanged.
282
+ */
283
+ declare function withSafeArea(url: string, insets: SafeArea): string;
284
+ /** The insets in a query string, or null when the parameter is absent or malformed. */
285
+ declare function readSafeArea(search: string): SafeArea | null;
286
+ /**
287
+ * Sets `--pd-safe-top`, `--pd-safe-right`, `--pd-safe-bottom` and
288
+ * `--pd-safe-left` on `target` from the page URL's `pd-safe-area`. Does
289
+ * nothing when it's absent, so CSS falls back to `env(safe-area-inset-*)`.
290
+ */
291
+ declare function applySafeArea(target?: HTMLElement, search?: string): SafeArea | null;
292
+
172
293
  type DeviceStatus = 'loading' | 'ready' | 'failed';
294
+ type SafeAreaMode = 'expose' | 'reserve' | 'none';
173
295
  interface DeviceProps {
174
296
  /** A preset or your own spec. Defaults to `phone`. */
175
297
  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. */
298
+ /** Defaults to the device's own cutout. On a device without a safe area
299
+ * (`phone`) it's hidden over an iframe, which would have no way to clear it.
300
+ * `none` hides the drawing; the insets still come from the device. */
178
301
  cutout?: Cutout;
302
+ /**
303
+ * How content meets the cutout, on devices with a safe area:
304
+ * `expose` runs content edge to edge and gives it the insets as
305
+ * `--pd-safe-*` (children) or a `pd-safe-area` URL parameter (iframes);
306
+ * `reserve` draws solid bars and lays content out between them;
307
+ * `none` draws no status bar. Defaults to `reserve` for iframes and
308
+ * children and `none` for screenshots.
309
+ */
310
+ safeArea?: SafeAreaMode;
311
+ /** `dark` (default) draws dark text for light content. */
312
+ statusBarStyle?: 'dark' | 'light';
179
313
  /** Any CSS length. The width shrinks so the whole device fits. */
180
314
  maxHeight?: string;
181
315
  className?: string;
@@ -219,6 +353,6 @@ interface DeviceProps {
219
353
  * in CSS from the proportions in `DEVICES`. Give it a width (or `maxHeight`);
220
354
  * the height follows from the device's shape.
221
355
  */
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;
356
+ declare function Device({ device, cutout, safeArea, statusBarStyle, maxHeight, className, style, src, alt, imgProps, iframe, title, iframeProps, children, fit, interactive, overlay, fallback, loadTimeout, ready, failed, onStatusChange, }: DeviceProps): react.JSX.Element;
223
357
 
224
- export { type Cutout, DEVICES, Device, type DeviceButton, type DeviceGeometry, type DeviceHTMLOptions, type DeviceName, type DeviceProps, type DeviceSpec, type DeviceStatus, deviceGeometry, deviceHTML, deviceVars, resolveDevice };
358
+ export { type Cutout, type CutoutSpec, DEVICES, Device, type DeviceButton, type DeviceGeometry, type DeviceHTMLOptions, type DeviceName, type DeviceProps, type DeviceSpec, type DeviceStatus, type HomeIndicatorSpec, SAFE_AREA_PARAM, type SafeArea, type SafeAreaMode, type StatusBarSpec, applySafeArea, deviceGeometry, deviceHTML, deviceVars, readSafeArea, resolveDevice, withSafeArea };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,29 @@
1
1
  import * as react from 'react';
2
2
  import { CSSProperties, ImgHTMLAttributes, IframeHTMLAttributes, ReactNode } from 'react';
3
3
 
4
- type Cutout = 'island' | 'none';
4
+ /** A cutout's shape and place, in viewport CSS px. */
5
+ type CutoutSpec = {
6
+ type: 'island';
7
+ width: number;
8
+ height: number;
9
+ top: number;
10
+ } | {
11
+ type: 'hole';
12
+ diameter: number;
13
+ /** Distance from the screen's top edge to the hole's top. */
14
+ top: number;
15
+ /** The hole's center as a fraction of the screen width. Defaults to 0.5. */
16
+ x?: number;
17
+ };
18
+ /** `'island'` is the Dynamic Island in proportion to the screen width. */
19
+ type Cutout = 'island' | 'none' | CutoutSpec;
20
+ /** Insets from each screen edge that content should clear, in viewport CSS px, portrait. */
21
+ interface SafeArea {
22
+ top: number;
23
+ right: number;
24
+ bottom: number;
25
+ left: number;
26
+ }
5
27
  interface DeviceButton {
6
28
  side: 'left' | 'right' | 'top';
7
29
  /** Where the button starts, as a fraction of that side's length. */
@@ -24,6 +46,27 @@ interface DeviceSpec {
24
46
  screenRadius: number;
25
47
  cutout: Cutout;
26
48
  buttons: readonly DeviceButton[];
49
+ /** Hardware insets content should clear. Without it the device draws no status bar. */
50
+ safeArea?: SafeArea;
51
+ statusBar?: StatusBarSpec;
52
+ homeIndicator?: HomeIndicatorSpec;
53
+ }
54
+ /** Where the status bar sits, in viewport CSS px. */
55
+ interface StatusBarSpec {
56
+ /** The time's center, from the screen's left edge. */
57
+ time: number;
58
+ /** The icons' center, from the screen's right edge. */
59
+ icons: number;
60
+ /** The text's vertical center, from the screen's top edge. */
61
+ center: number;
62
+ fontSize: number;
63
+ }
64
+ /** The home indicator or gesture bar, in viewport CSS px. */
65
+ interface HomeIndicatorSpec {
66
+ width: number;
67
+ height: number;
68
+ /** Gap between the bar and the screen's bottom edge. */
69
+ bottom: number;
27
70
  }
28
71
  /**
29
72
  * Proportions follow the screen, not a particular model: the phone is a
@@ -72,47 +115,101 @@ declare const DEVICES: {
72
115
  readonly length: 0.06;
73
116
  }];
74
117
  };
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;
118
+ readonly 'iphone-16-pro': {
119
+ readonly viewport: {
120
+ readonly width: 402;
121
+ readonly height: 874;
122
+ };
123
+ readonly bezel: 0.034;
124
+ readonly screenRadius: number;
125
+ readonly cutout: {
126
+ readonly type: "island";
127
+ readonly width: 125;
128
+ readonly height: 36.67;
129
+ readonly top: 14;
130
+ };
131
+ readonly safeArea: {
132
+ readonly top: 62;
133
+ readonly right: 0;
134
+ readonly bottom: 34;
135
+ readonly left: 0;
136
+ };
137
+ readonly statusBar: {
138
+ readonly time: 74;
139
+ readonly icons: 73;
140
+ readonly center: 33;
141
+ readonly fontSize: 17;
142
+ };
143
+ readonly homeIndicator: {
144
+ readonly width: 134;
145
+ readonly height: 5;
146
+ readonly bottom: 8;
147
+ };
148
+ readonly buttons: readonly [{
149
+ readonly side: "left";
150
+ readonly start: 0.175;
151
+ readonly length: 0.045;
152
+ }, {
153
+ readonly side: "left";
154
+ readonly start: 0.255;
155
+ readonly length: 0.085;
156
+ }, {
157
+ readonly side: "left";
158
+ readonly start: 0.36;
159
+ readonly length: 0.085;
160
+ }, {
161
+ readonly side: "right";
162
+ readonly start: 0.29;
163
+ readonly length: 0.14;
164
+ }, {
165
+ readonly side: "right";
166
+ readonly start: 0.6;
167
+ readonly length: 0.07;
168
+ }];
81
169
  };
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;
170
+ readonly 'pixel-9': {
171
+ readonly viewport: {
172
+ readonly width: 412;
173
+ readonly height: 923;
174
+ };
175
+ readonly bezel: 0.034;
176
+ readonly screenRadius: number;
177
+ readonly cutout: {
178
+ readonly type: "hole";
179
+ readonly diameter: 30.5;
180
+ readonly top: 17.5;
181
+ readonly x: 0.5;
182
+ };
183
+ readonly safeArea: {
184
+ readonly top: 50;
185
+ readonly right: 0;
186
+ readonly bottom: 24;
187
+ readonly left: 0;
188
+ };
189
+ readonly statusBar: {
190
+ readonly time: 42;
191
+ readonly icons: 50;
192
+ readonly center: 26;
193
+ readonly fontSize: 14;
194
+ };
195
+ readonly homeIndicator: {
196
+ readonly width: 108;
197
+ readonly height: 4;
198
+ readonly bottom: 10;
199
+ };
200
+ readonly buttons: readonly [{
201
+ readonly side: "right";
202
+ readonly start: 0.22;
203
+ readonly length: 0.07;
204
+ }, {
205
+ readonly side: "right";
206
+ readonly start: 0.33;
207
+ readonly length: 0.14;
208
+ }];
106
209
  };
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
210
  };
211
+ type DeviceName = keyof typeof DEVICES;
212
+ declare function resolveDevice(device?: DeviceName | DeviceSpec): DeviceSpec;
116
213
  interface DeviceGeometry {
117
214
  width: number;
118
215
  height: number;
@@ -123,12 +220,19 @@ interface DeviceGeometry {
123
220
  height: number;
124
221
  radius: number;
125
222
  };
126
- /** Absent when the cutout is `none`. */
127
223
  island?: {
128
224
  width: number;
129
225
  height: number;
130
226
  top: number;
131
227
  };
228
+ /** `x` is the hole's center as a fraction of the screen width. */
229
+ hole?: {
230
+ diameter: number;
231
+ top: number;
232
+ x: number;
233
+ };
234
+ /** Present when the spec has one, whatever the cutout. */
235
+ safeArea?: SafeArea;
132
236
  buttonDepth: number;
133
237
  /** Multiply the viewport by this to fit it to the screen. */
134
238
  scale: number;
@@ -169,13 +273,43 @@ interface DeviceHTMLOptions {
169
273
  */
170
274
  declare function deviceHTML(options: DeviceHTMLOptions): string;
171
275
 
276
+ /** The query parameter a framed page reads its insets from: `top,right,bottom,left` in CSS px. */
277
+ declare const SAFE_AREA_PARAM = "pd-safe-area";
278
+ /**
279
+ * `url` with `pd-safe-area` set to the insets, rounded to whole pixels. The
280
+ * rest of the URL is kept exactly as given, relative or not. URLs that aren't
281
+ * http(s) or relative, such as `data:` and `about:blank`, come back unchanged.
282
+ */
283
+ declare function withSafeArea(url: string, insets: SafeArea): string;
284
+ /** The insets in a query string, or null when the parameter is absent or malformed. */
285
+ declare function readSafeArea(search: string): SafeArea | null;
286
+ /**
287
+ * Sets `--pd-safe-top`, `--pd-safe-right`, `--pd-safe-bottom` and
288
+ * `--pd-safe-left` on `target` from the page URL's `pd-safe-area`. Does
289
+ * nothing when it's absent, so CSS falls back to `env(safe-area-inset-*)`.
290
+ */
291
+ declare function applySafeArea(target?: HTMLElement, search?: string): SafeArea | null;
292
+
172
293
  type DeviceStatus = 'loading' | 'ready' | 'failed';
294
+ type SafeAreaMode = 'expose' | 'reserve' | 'none';
173
295
  interface DeviceProps {
174
296
  /** A preset or your own spec. Defaults to `phone`. */
175
297
  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. */
298
+ /** Defaults to the device's own cutout. On a device without a safe area
299
+ * (`phone`) it's hidden over an iframe, which would have no way to clear it.
300
+ * `none` hides the drawing; the insets still come from the device. */
178
301
  cutout?: Cutout;
302
+ /**
303
+ * How content meets the cutout, on devices with a safe area:
304
+ * `expose` runs content edge to edge and gives it the insets as
305
+ * `--pd-safe-*` (children) or a `pd-safe-area` URL parameter (iframes);
306
+ * `reserve` draws solid bars and lays content out between them;
307
+ * `none` draws no status bar. Defaults to `reserve` for iframes and
308
+ * children and `none` for screenshots.
309
+ */
310
+ safeArea?: SafeAreaMode;
311
+ /** `dark` (default) draws dark text for light content. */
312
+ statusBarStyle?: 'dark' | 'light';
179
313
  /** Any CSS length. The width shrinks so the whole device fits. */
180
314
  maxHeight?: string;
181
315
  className?: string;
@@ -219,6 +353,6 @@ interface DeviceProps {
219
353
  * in CSS from the proportions in `DEVICES`. Give it a width (or `maxHeight`);
220
354
  * the height follows from the device's shape.
221
355
  */
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;
356
+ declare function Device({ device, cutout, safeArea, statusBarStyle, maxHeight, className, style, src, alt, imgProps, iframe, title, iframeProps, children, fit, interactive, overlay, fallback, loadTimeout, ready, failed, onStatusChange, }: DeviceProps): react.JSX.Element;
223
357
 
224
- export { type Cutout, DEVICES, Device, type DeviceButton, type DeviceGeometry, type DeviceHTMLOptions, type DeviceName, type DeviceProps, type DeviceSpec, type DeviceStatus, deviceGeometry, deviceHTML, deviceVars, resolveDevice };
358
+ export { type Cutout, type CutoutSpec, DEVICES, Device, type DeviceButton, type DeviceGeometry, type DeviceHTMLOptions, type DeviceName, type DeviceProps, type DeviceSpec, type DeviceStatus, type HomeIndicatorSpec, SAFE_AREA_PARAM, type SafeArea, type SafeAreaMode, type StatusBarSpec, applySafeArea, deviceGeometry, deviceHTML, deviceVars, readSafeArea, resolveDevice, withSafeArea };