@present-day/device 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +111 -2
- package/dist/core.d.mts +290 -0
- package/dist/core.d.ts +290 -0
- package/dist/core.js +257 -0
- package/dist/core.js.map +1 -0
- package/dist/core.mjs +222 -0
- package/dist/core.mjs.map +1 -0
- package/dist/index.d.mts +358 -0
- package/dist/index.d.ts +358 -0
- package/dist/index.js +535 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +495 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles.css +226 -0
- package/dist/styles.css.map +1 -0
- package/package.json +96 -4
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
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
|
+
}
|
|
24
|
+
interface DeviceButton {
|
|
25
|
+
side: 'left' | 'right' | 'top';
|
|
26
|
+
/** Where the button starts, as a fraction of that side's length. */
|
|
27
|
+
start: number;
|
|
28
|
+
/** Button length, as a fraction of that side's length. */
|
|
29
|
+
length: number;
|
|
30
|
+
}
|
|
31
|
+
interface DeviceSpec {
|
|
32
|
+
/**
|
|
33
|
+
* The CSS-pixel viewport the screen shows. A screenshot or page laid out at
|
|
34
|
+
* this size fills the screen exactly; the frame takes its shape from it.
|
|
35
|
+
*/
|
|
36
|
+
viewport: {
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
};
|
|
40
|
+
/** Bezel thickness, as a fraction of the device's outer width. */
|
|
41
|
+
bezel: number;
|
|
42
|
+
/** Screen corner radius, as a fraction of the screen width. */
|
|
43
|
+
screenRadius: number;
|
|
44
|
+
cutout: Cutout;
|
|
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;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Proportions follow the screen, not a particular model: the phone is a
|
|
70
|
+
* 390 × 844 iPhone-class screen (iPhone 12 to 14), the size most app
|
|
71
|
+
* screenshots and phone demos are laid out at; the tablet is an 1180 × 820
|
|
72
|
+
* iPad Air in landscape.
|
|
73
|
+
*/
|
|
74
|
+
declare const DEVICES: {
|
|
75
|
+
readonly phone: {
|
|
76
|
+
readonly viewport: {
|
|
77
|
+
readonly width: 390;
|
|
78
|
+
readonly height: 844;
|
|
79
|
+
};
|
|
80
|
+
readonly bezel: 0.036;
|
|
81
|
+
readonly screenRadius: number;
|
|
82
|
+
readonly cutout: "island";
|
|
83
|
+
readonly buttons: readonly [{
|
|
84
|
+
readonly side: "left";
|
|
85
|
+
readonly start: 0.175;
|
|
86
|
+
readonly length: 0.045;
|
|
87
|
+
}, {
|
|
88
|
+
readonly side: "left";
|
|
89
|
+
readonly start: 0.255;
|
|
90
|
+
readonly length: 0.085;
|
|
91
|
+
}, {
|
|
92
|
+
readonly side: "left";
|
|
93
|
+
readonly start: 0.36;
|
|
94
|
+
readonly length: 0.085;
|
|
95
|
+
}, {
|
|
96
|
+
readonly side: "right";
|
|
97
|
+
readonly start: 0.29;
|
|
98
|
+
readonly length: 0.14;
|
|
99
|
+
}];
|
|
100
|
+
};
|
|
101
|
+
readonly tablet: {
|
|
102
|
+
readonly viewport: {
|
|
103
|
+
readonly width: 1180;
|
|
104
|
+
readonly height: 820;
|
|
105
|
+
};
|
|
106
|
+
readonly bezel: 0.032;
|
|
107
|
+
readonly screenRadius: number;
|
|
108
|
+
readonly cutout: "none";
|
|
109
|
+
readonly buttons: readonly [{
|
|
110
|
+
readonly side: "top";
|
|
111
|
+
readonly start: 0.84;
|
|
112
|
+
readonly length: 0.06;
|
|
113
|
+
}];
|
|
114
|
+
};
|
|
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
|
+
}];
|
|
166
|
+
};
|
|
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
|
+
}];
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
type DeviceName = keyof typeof DEVICES;
|
|
209
|
+
declare function resolveDevice(device?: DeviceName | DeviceSpec): DeviceSpec;
|
|
210
|
+
interface DeviceGeometry {
|
|
211
|
+
width: number;
|
|
212
|
+
height: number;
|
|
213
|
+
bezel: number;
|
|
214
|
+
radius: number;
|
|
215
|
+
screen: {
|
|
216
|
+
width: number;
|
|
217
|
+
height: number;
|
|
218
|
+
radius: number;
|
|
219
|
+
};
|
|
220
|
+
island?: {
|
|
221
|
+
width: number;
|
|
222
|
+
height: number;
|
|
223
|
+
top: number;
|
|
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;
|
|
233
|
+
buttonDepth: number;
|
|
234
|
+
/** Multiply the viewport by this to fit it to the screen. */
|
|
235
|
+
scale: number;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Every measurement of a device drawn `width` units wide, in the same units.
|
|
239
|
+
* For renderers that can't use the stylesheet, such as React Native.
|
|
240
|
+
*/
|
|
241
|
+
declare function deviceGeometry(device: DeviceName | DeviceSpec, width: number, cutout?: Cutout): DeviceGeometry;
|
|
242
|
+
/**
|
|
243
|
+
* The custom properties `styles.css` draws a device from. Lengths are in
|
|
244
|
+
* percent of the device's width and become `cqi` in the stylesheet.
|
|
245
|
+
* `maxHeight` is any CSS length; the width shrinks to keep the shape.
|
|
246
|
+
*/
|
|
247
|
+
declare function deviceVars(device?: DeviceName | DeviceSpec, options?: {
|
|
248
|
+
cutout?: Cutout;
|
|
249
|
+
maxHeight?: string;
|
|
250
|
+
}): Record<`--pd-device-${string}`, string>;
|
|
251
|
+
|
|
252
|
+
interface DeviceHTMLOptions {
|
|
253
|
+
/** The screenshot. */
|
|
254
|
+
src: string;
|
|
255
|
+
alt: string;
|
|
256
|
+
device?: DeviceName | DeviceSpec;
|
|
257
|
+
/** Defaults to the device's own cutout. */
|
|
258
|
+
cutout?: Cutout;
|
|
259
|
+
maxHeight?: string;
|
|
260
|
+
className?: string;
|
|
261
|
+
/** The image's pixel size, so the page can reserve its space. */
|
|
262
|
+
width?: number;
|
|
263
|
+
height?: number;
|
|
264
|
+
/** Defaults to `lazy`. */
|
|
265
|
+
loading?: 'lazy' | 'eager';
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* A screenshot in a device frame, as an HTML string, for pages rendered
|
|
269
|
+
* without React such as Markdown output. Needs `styles.css`.
|
|
270
|
+
*/
|
|
271
|
+
declare function deviceHTML(options: DeviceHTMLOptions): string;
|
|
272
|
+
|
|
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.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/core/index.ts
|
|
21
|
+
var core_exports = {};
|
|
22
|
+
__export(core_exports, {
|
|
23
|
+
DEVICES: () => DEVICES,
|
|
24
|
+
SAFE_AREA_PARAM: () => SAFE_AREA_PARAM,
|
|
25
|
+
applySafeArea: () => applySafeArea,
|
|
26
|
+
deviceGeometry: () => deviceGeometry,
|
|
27
|
+
deviceHTML: () => deviceHTML,
|
|
28
|
+
deviceVars: () => deviceVars,
|
|
29
|
+
readSafeArea: () => readSafeArea,
|
|
30
|
+
resolveDevice: () => resolveDevice,
|
|
31
|
+
withSafeArea: () => withSafeArea
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(core_exports);
|
|
34
|
+
|
|
35
|
+
// src/core/devices.ts
|
|
36
|
+
var DEVICES = {
|
|
37
|
+
phone: {
|
|
38
|
+
viewport: { width: 390, height: 844 },
|
|
39
|
+
bezel: 0.036,
|
|
40
|
+
// Apple's 47.33 pt display corner radius on a 390 pt screen.
|
|
41
|
+
screenRadius: 47.33 / 390,
|
|
42
|
+
cutout: "island",
|
|
43
|
+
buttons: [
|
|
44
|
+
{ side: "left", start: 0.175, length: 0.045 },
|
|
45
|
+
{ side: "left", start: 0.255, length: 0.085 },
|
|
46
|
+
{ side: "left", start: 0.36, length: 0.085 },
|
|
47
|
+
{ side: "right", start: 0.29, length: 0.14 }
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
tablet: {
|
|
51
|
+
viewport: { width: 1180, height: 820 },
|
|
52
|
+
bezel: 0.032,
|
|
53
|
+
// 18 pt display corners on a 1180 pt screen.
|
|
54
|
+
screenRadius: 18 / 1180,
|
|
55
|
+
cutout: "none",
|
|
56
|
+
buttons: [{ side: "top", start: 0.84, length: 0.06 }]
|
|
57
|
+
},
|
|
58
|
+
// iOS 26.5 Simulator, iPhone 16 Pro: UIKit safeAreaInsets, the screen's
|
|
59
|
+
// exclusion area and display corner radius, and measured status bar
|
|
60
|
+
// placement. The home indicator is approximate.
|
|
61
|
+
"iphone-16-pro": {
|
|
62
|
+
viewport: { width: 402, height: 874 },
|
|
63
|
+
bezel: 0.034,
|
|
64
|
+
screenRadius: 62 / 402,
|
|
65
|
+
cutout: { type: "island", width: 125, height: 36.67, top: 14 },
|
|
66
|
+
safeArea: { top: 62, right: 0, bottom: 34, left: 0 },
|
|
67
|
+
statusBar: { time: 74, icons: 73, center: 33, fontSize: 17 },
|
|
68
|
+
homeIndicator: { width: 134, height: 5, bottom: 8 },
|
|
69
|
+
buttons: [
|
|
70
|
+
{ side: "left", start: 0.175, length: 0.045 },
|
|
71
|
+
{ side: "left", start: 0.255, length: 0.085 },
|
|
72
|
+
{ side: "left", start: 0.36, length: 0.085 },
|
|
73
|
+
{ side: "right", start: 0.29, length: 0.14 },
|
|
74
|
+
{ side: "right", start: 0.6, length: 0.07 }
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
// Android emulator pixel_9 definition: size from nexus.xml (1080 × 2424 at
|
|
78
|
+
// 420 dpi), hole and corners measured from the skin's mask. No public
|
|
79
|
+
// status bar height: the top inset is the Pixel 8 overlay's, and the bottom
|
|
80
|
+
// is the gesture bar; both approximate.
|
|
81
|
+
"pixel-9": {
|
|
82
|
+
viewport: { width: 412, height: 923 },
|
|
83
|
+
bezel: 0.034,
|
|
84
|
+
screenRadius: 54.5 / 412,
|
|
85
|
+
cutout: { type: "hole", diameter: 30.5, top: 17.5, x: 0.5 },
|
|
86
|
+
safeArea: { top: 50, right: 0, bottom: 24, left: 0 },
|
|
87
|
+
statusBar: { time: 42, icons: 50, center: 26, fontSize: 14 },
|
|
88
|
+
homeIndicator: { width: 108, height: 4, bottom: 10 },
|
|
89
|
+
buttons: [
|
|
90
|
+
{ side: "right", start: 0.22, length: 0.07 },
|
|
91
|
+
{ side: "right", start: 0.33, length: 0.14 }
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var ISLAND = { width: 126 / 393, height: 37 / 393, top: 11 / 393 };
|
|
96
|
+
var BUTTON_DEPTH = 8e-3;
|
|
97
|
+
function resolveDevice(device = "phone") {
|
|
98
|
+
return typeof device === "string" ? DEVICES[device] : device;
|
|
99
|
+
}
|
|
100
|
+
function deviceGeometry(device, width, cutout) {
|
|
101
|
+
const spec = resolveDevice(device);
|
|
102
|
+
const bezel = spec.bezel * width;
|
|
103
|
+
const screenWidth = width - bezel * 2;
|
|
104
|
+
const screenHeight = screenWidth * spec.viewport.height / spec.viewport.width;
|
|
105
|
+
const screenRadius = spec.screenRadius * screenWidth;
|
|
106
|
+
const scale = screenWidth / spec.viewport.width;
|
|
107
|
+
const shape = cutout ?? spec.cutout;
|
|
108
|
+
const island = shape === "island" ? {
|
|
109
|
+
width: ISLAND.width * screenWidth,
|
|
110
|
+
height: ISLAND.height * screenWidth,
|
|
111
|
+
top: ISLAND.top * screenWidth
|
|
112
|
+
} : typeof shape === "object" && shape.type === "island" ? {
|
|
113
|
+
width: shape.width * scale,
|
|
114
|
+
height: shape.height * scale,
|
|
115
|
+
top: shape.top * scale
|
|
116
|
+
} : void 0;
|
|
117
|
+
const hole = typeof shape === "object" && shape.type === "hole" ? {
|
|
118
|
+
diameter: shape.diameter * scale,
|
|
119
|
+
top: shape.top * scale,
|
|
120
|
+
x: shape.x ?? 0.5
|
|
121
|
+
} : void 0;
|
|
122
|
+
const safeArea = spec.safeArea && {
|
|
123
|
+
top: spec.safeArea.top * scale,
|
|
124
|
+
right: spec.safeArea.right * scale,
|
|
125
|
+
bottom: spec.safeArea.bottom * scale,
|
|
126
|
+
left: spec.safeArea.left * scale
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
width,
|
|
130
|
+
height: screenHeight + bezel * 2,
|
|
131
|
+
bezel,
|
|
132
|
+
radius: screenRadius + bezel,
|
|
133
|
+
screen: { width: screenWidth, height: screenHeight, radius: screenRadius },
|
|
134
|
+
island,
|
|
135
|
+
hole,
|
|
136
|
+
safeArea,
|
|
137
|
+
buttonDepth: BUTTON_DEPTH * width,
|
|
138
|
+
scale
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
var round = (n) => Math.round(n * 1e4) / 1e4;
|
|
142
|
+
function deviceVars(device = "phone", options = {}) {
|
|
143
|
+
const spec = resolveDevice(device);
|
|
144
|
+
const g = deviceGeometry(spec, 100, options.cutout);
|
|
145
|
+
const vars = {
|
|
146
|
+
"--pd-device-aspect": `${spec.viewport.width} / ${spec.viewport.height}`,
|
|
147
|
+
"--pd-device-bezel": `${round(g.bezel)}`,
|
|
148
|
+
"--pd-device-radius": `${round(g.radius)}`,
|
|
149
|
+
"--pd-device-screen-radius": `${round(g.screen.radius)}`,
|
|
150
|
+
"--pd-device-button-depth": `${round(g.buttonDepth)}`
|
|
151
|
+
};
|
|
152
|
+
if (g.island) {
|
|
153
|
+
vars["--pd-device-island-width"] = `${round(g.island.width)}`;
|
|
154
|
+
vars["--pd-device-island-height"] = `${round(g.island.height)}`;
|
|
155
|
+
vars["--pd-device-island-top"] = `${round(g.island.top)}`;
|
|
156
|
+
}
|
|
157
|
+
if (g.hole) {
|
|
158
|
+
vars["--pd-device-hole-size"] = `${round(g.hole.diameter)}`;
|
|
159
|
+
vars["--pd-device-hole-top"] = `${round(g.hole.top)}`;
|
|
160
|
+
vars["--pd-device-hole-x"] = `${round(g.bezel + g.hole.x * g.screen.width)}`;
|
|
161
|
+
}
|
|
162
|
+
if (g.safeArea) {
|
|
163
|
+
vars["--pd-device-safe-top"] = `${round(g.safeArea.top)}`;
|
|
164
|
+
vars["--pd-device-safe-bottom"] = `${round(g.safeArea.bottom)}`;
|
|
165
|
+
}
|
|
166
|
+
if (spec.statusBar) {
|
|
167
|
+
vars["--pd-device-status-time"] = `${round(spec.statusBar.time * g.scale)}`;
|
|
168
|
+
vars["--pd-device-status-icons"] = `${round(spec.statusBar.icons * g.scale)}`;
|
|
169
|
+
vars["--pd-device-status-center"] = `${round(spec.statusBar.center * g.scale)}`;
|
|
170
|
+
vars["--pd-device-status-font"] = `${round(spec.statusBar.fontSize * g.scale)}`;
|
|
171
|
+
}
|
|
172
|
+
if (spec.homeIndicator) {
|
|
173
|
+
vars["--pd-device-home-width"] = `${round(spec.homeIndicator.width * g.scale)}`;
|
|
174
|
+
vars["--pd-device-home-height"] = `${round(spec.homeIndicator.height * g.scale)}`;
|
|
175
|
+
vars["--pd-device-home-bottom"] = `${round(spec.homeIndicator.bottom * g.scale)}`;
|
|
176
|
+
}
|
|
177
|
+
if (options.maxHeight)
|
|
178
|
+
vars["--pd-device-max-width"] = `calc(${options.maxHeight} * ${round(g.width / g.height)})`;
|
|
179
|
+
return vars;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/core/html.ts
|
|
183
|
+
var esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
184
|
+
function deviceHTML(options) {
|
|
185
|
+
const spec = resolveDevice(options.device);
|
|
186
|
+
const cutout = options.cutout ?? spec.cutout;
|
|
187
|
+
const geometry = deviceGeometry(spec, 100, cutout);
|
|
188
|
+
const cutoutHTML = geometry.island ? '<span class="pd-device-island"></span>' : geometry.hole ? '<span class="pd-device-hole"></span>' : "";
|
|
189
|
+
const style = Object.entries(
|
|
190
|
+
deviceVars(spec, { cutout, maxHeight: options.maxHeight })
|
|
191
|
+
).map(([name, value]) => `${name}:${value}`).join(";");
|
|
192
|
+
const size = options.width && options.height ? ` width="${options.width}" height="${options.height}"` : "";
|
|
193
|
+
const buttons = spec.buttons.map(
|
|
194
|
+
(b) => `<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>`
|
|
195
|
+
).join("");
|
|
196
|
+
const className = options.className ? `pd-device ${esc(options.className)}` : "pd-device";
|
|
197
|
+
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">${cutoutHTML}</span></span></span>`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/core/safe-area.ts
|
|
201
|
+
var SAFE_AREA_PARAM = "pd-safe-area";
|
|
202
|
+
var SIDES = ["top", "right", "bottom", "left"];
|
|
203
|
+
function withSafeArea(url, insets) {
|
|
204
|
+
const scheme = /^([a-z][a-z\d+.-]*):/i.exec(url)?.[1]?.toLowerCase();
|
|
205
|
+
if (scheme && scheme !== "http" && scheme !== "https") return url;
|
|
206
|
+
const hashAt = url.indexOf("#");
|
|
207
|
+
const hash = hashAt < 0 ? "" : url.slice(hashAt);
|
|
208
|
+
const beforeHash = hashAt < 0 ? url : url.slice(0, hashAt);
|
|
209
|
+
const queryAt = beforeHash.indexOf("?");
|
|
210
|
+
const path = queryAt < 0 ? beforeHash : beforeHash.slice(0, queryAt);
|
|
211
|
+
const query = queryAt < 0 ? "" : beforeHash.slice(queryAt + 1);
|
|
212
|
+
const params = query.split("&").filter((part) => part && paramName(part) !== SAFE_AREA_PARAM);
|
|
213
|
+
params.push(
|
|
214
|
+
`${SAFE_AREA_PARAM}=${SIDES.map((side) => Math.round(insets[side])).join(",")}`
|
|
215
|
+
);
|
|
216
|
+
return `${path}?${params.join("&")}${hash}`;
|
|
217
|
+
}
|
|
218
|
+
function paramName(part) {
|
|
219
|
+
const name = part.split("=")[0] ?? "";
|
|
220
|
+
try {
|
|
221
|
+
return decodeURIComponent(name.replace(/\+/g, " "));
|
|
222
|
+
} catch {
|
|
223
|
+
return name;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function readSafeArea(search) {
|
|
227
|
+
const value = new URLSearchParams(search).get(SAFE_AREA_PARAM);
|
|
228
|
+
if (!value) return null;
|
|
229
|
+
const parts = value.split(",");
|
|
230
|
+
if (parts.length !== 4) return null;
|
|
231
|
+
const numbers = parts.map(
|
|
232
|
+
(part) => /^\d+(\.\d+)?$/.test(part) ? Number(part) : Number.NaN
|
|
233
|
+
);
|
|
234
|
+
if (numbers.some(Number.isNaN)) return null;
|
|
235
|
+
const [top, right, bottom, left] = numbers;
|
|
236
|
+
return { top, right, bottom, left };
|
|
237
|
+
}
|
|
238
|
+
function applySafeArea(target = document.documentElement, search = location.search) {
|
|
239
|
+
const insets = readSafeArea(search);
|
|
240
|
+
if (!insets) return null;
|
|
241
|
+
for (const side of SIDES)
|
|
242
|
+
target.style.setProperty(`--pd-safe-${side}`, `${insets[side]}px`);
|
|
243
|
+
return insets;
|
|
244
|
+
}
|
|
245
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
246
|
+
0 && (module.exports = {
|
|
247
|
+
DEVICES,
|
|
248
|
+
SAFE_AREA_PARAM,
|
|
249
|
+
applySafeArea,
|
|
250
|
+
deviceGeometry,
|
|
251
|
+
deviceHTML,
|
|
252
|
+
deviceVars,
|
|
253
|
+
readSafeArea,
|
|
254
|
+
resolveDevice,
|
|
255
|
+
withSafeArea
|
|
256
|
+
});
|
|
257
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/index.ts","../src/core/devices.ts","../src/core/html.ts","../src/core/safe-area.ts"],"sourcesContent":["export {\n type Cutout,\n type CutoutSpec,\n DEVICES,\n type DeviceButton,\n type DeviceGeometry,\n type DeviceName,\n type DeviceSpec,\n deviceGeometry,\n deviceVars,\n type HomeIndicatorSpec,\n resolveDevice,\n type SafeArea,\n type StatusBarSpec,\n} from './devices'\nexport { type DeviceHTMLOptions, deviceHTML } from './html'\nexport {\n applySafeArea,\n readSafeArea,\n SAFE_AREA_PARAM,\n withSafeArea,\n} from './safe-area'\n","/** A cutout's shape and place, in viewport CSS px. */\nexport type CutoutSpec =\n | { type: 'island'; width: number; height: number; top: number }\n | {\n type: 'hole'\n diameter: number\n /** Distance from the screen's top edge to the hole's top. */\n top: number\n /** The hole's center as a fraction of the screen width. Defaults to 0.5. */\n x?: number\n }\n\n/** `'island'` is the Dynamic Island in proportion to the screen width. */\nexport type Cutout = 'island' | 'none' | CutoutSpec\n\n/** Insets from each screen edge that content should clear, in viewport CSS px, portrait. */\nexport interface SafeArea {\n top: number\n right: number\n bottom: number\n left: number\n}\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 /** Hardware insets content should clear. Without it the device draws no status bar. */\n safeArea?: SafeArea\n statusBar?: StatusBarSpec\n homeIndicator?: HomeIndicatorSpec\n}\n\n/** Where the status bar sits, in viewport CSS px. */\nexport interface StatusBarSpec {\n /** The time's center, from the screen's left edge. */\n time: number\n /** The icons' center, from the screen's right edge. */\n icons: number\n /** The text's vertical center, from the screen's top edge. */\n center: number\n fontSize: number\n}\n\n/** The home indicator or gesture bar, in viewport CSS px. */\nexport interface HomeIndicatorSpec {\n width: number\n height: number\n /** Gap between the bar and the screen's bottom edge. */\n bottom: number\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 // iOS 26.5 Simulator, iPhone 16 Pro: UIKit safeAreaInsets, the screen's\n // exclusion area and display corner radius, and measured status bar\n // placement. The home indicator is approximate.\n 'iphone-16-pro': {\n viewport: { width: 402, height: 874 },\n bezel: 0.034,\n screenRadius: 62 / 402,\n cutout: { type: 'island', width: 125, height: 36.67, top: 14 },\n safeArea: { top: 62, right: 0, bottom: 34, left: 0 },\n statusBar: { time: 74, icons: 73, center: 33, fontSize: 17 },\n homeIndicator: { width: 134, height: 5, bottom: 8 },\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 { side: 'right', start: 0.6, length: 0.07 },\n ],\n },\n // Android emulator pixel_9 definition: size from nexus.xml (1080 × 2424 at\n // 420 dpi), hole and corners measured from the skin's mask. No public\n // status bar height: the top inset is the Pixel 8 overlay's, and the bottom\n // is the gesture bar; both approximate.\n 'pixel-9': {\n viewport: { width: 412, height: 923 },\n bezel: 0.034,\n screenRadius: 54.5 / 412,\n cutout: { type: 'hole', diameter: 30.5, top: 17.5, x: 0.5 },\n safeArea: { top: 50, right: 0, bottom: 24, left: 0 },\n statusBar: { time: 42, icons: 50, center: 26, fontSize: 14 },\n homeIndicator: { width: 108, height: 4, bottom: 10 },\n buttons: [\n { side: 'right', start: 0.22, length: 0.07 },\n { side: 'right', start: 0.33, length: 0.14 },\n ],\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(\n device: DeviceName | DeviceSpec = 'phone',\n): DeviceSpec {\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 island?: { width: number; height: number; top: number }\n /** `x` is the hole's center as a fraction of the screen width. */\n hole?: { diameter: number; top: number; x: number }\n /** Present when the spec has one, whatever the cutout. */\n safeArea?: SafeArea\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 const scale = screenWidth / spec.viewport.width\n const shape = cutout ?? spec.cutout\n const island =\n shape === 'island'\n ? {\n width: ISLAND.width * screenWidth,\n height: ISLAND.height * screenWidth,\n top: ISLAND.top * screenWidth,\n }\n : typeof shape === 'object' && shape.type === 'island'\n ? {\n width: shape.width * scale,\n height: shape.height * scale,\n top: shape.top * scale,\n }\n : undefined\n const hole =\n typeof shape === 'object' && shape.type === 'hole'\n ? {\n diameter: shape.diameter * scale,\n top: shape.top * scale,\n x: shape.x ?? 0.5,\n }\n : undefined\n const safeArea = spec.safeArea && {\n top: spec.safeArea.top * scale,\n right: spec.safeArea.right * scale,\n bottom: spec.safeArea.bottom * scale,\n left: spec.safeArea.left * scale,\n }\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 hole,\n safeArea,\n buttonDepth: BUTTON_DEPTH * width,\n scale,\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 (g.hole) {\n vars['--pd-device-hole-size'] = `${round(g.hole.diameter)}`\n vars['--pd-device-hole-top'] = `${round(g.hole.top)}`\n vars['--pd-device-hole-x'] = `${round(g.bezel + g.hole.x * g.screen.width)}`\n }\n if (g.safeArea) {\n vars['--pd-device-safe-top'] = `${round(g.safeArea.top)}`\n vars['--pd-device-safe-bottom'] = `${round(g.safeArea.bottom)}`\n }\n if (spec.statusBar) {\n vars['--pd-device-status-time'] = `${round(spec.statusBar.time * g.scale)}`\n vars['--pd-device-status-icons'] =\n `${round(spec.statusBar.icons * g.scale)}`\n vars['--pd-device-status-center'] =\n `${round(spec.statusBar.center * g.scale)}`\n vars['--pd-device-status-font'] =\n `${round(spec.statusBar.fontSize * g.scale)}`\n }\n if (spec.homeIndicator) {\n vars['--pd-device-home-width'] =\n `${round(spec.homeIndicator.width * g.scale)}`\n vars['--pd-device-home-height'] =\n `${round(spec.homeIndicator.height * g.scale)}`\n vars['--pd-device-home-bottom'] =\n `${round(spec.homeIndicator.bottom * g.scale)}`\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 deviceGeometry,\n deviceVars,\n resolveDevice,\n} from './devices'\n\nconst esc = (s: string) =>\n s\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\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 geometry = deviceGeometry(spec, 100, cutout)\n const cutoutHTML = geometry.island\n ? '<span class=\"pd-device-island\"></span>'\n : geometry.hole\n ? '<span class=\"pd-device-hole\"></span>'\n : ''\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\">${cutoutHTML}</span></span></span>`\n}\n","import type { SafeArea } from './devices'\n\n/** The query parameter a framed page reads its insets from: `top,right,bottom,left` in CSS px. */\nexport const SAFE_AREA_PARAM = 'pd-safe-area'\n\nconst SIDES = ['top', 'right', 'bottom', 'left'] as const\n/**\n * `url` with `pd-safe-area` set to the insets, rounded to whole pixels. The\n * rest of the URL is kept exactly as given, relative or not. URLs that aren't\n * http(s) or relative, such as `data:` and `about:blank`, come back unchanged.\n */\nexport function withSafeArea(url: string, insets: SafeArea): string {\n const scheme = /^([a-z][a-z\\d+.-]*):/i.exec(url)?.[1]?.toLowerCase()\n if (scheme && scheme !== 'http' && scheme !== 'https') return url\n const hashAt = url.indexOf('#')\n const hash = hashAt < 0 ? '' : url.slice(hashAt)\n const beforeHash = hashAt < 0 ? url : url.slice(0, hashAt)\n const queryAt = beforeHash.indexOf('?')\n const path = queryAt < 0 ? beforeHash : beforeHash.slice(0, queryAt)\n const query = queryAt < 0 ? '' : beforeHash.slice(queryAt + 1)\n const params = query\n .split('&')\n .filter((part) => part && paramName(part) !== SAFE_AREA_PARAM)\n params.push(\n `${SAFE_AREA_PARAM}=${SIDES.map((side) => Math.round(insets[side])).join(',')}`,\n )\n return `${path}?${params.join('&')}${hash}`\n}\n\nfunction paramName(part: string): string {\n const name = part.split('=')[0] ?? ''\n try {\n return decodeURIComponent(name.replace(/\\+/g, ' '))\n } catch {\n return name\n }\n}\n\n/** The insets in a query string, or null when the parameter is absent or malformed. */\nexport function readSafeArea(search: string): SafeArea | null {\n const value = new URLSearchParams(search).get(SAFE_AREA_PARAM)\n if (!value) return null\n const parts = value.split(',')\n if (parts.length !== 4) return null\n const numbers = parts.map((part) =>\n /^\\d+(\\.\\d+)?$/.test(part) ? Number(part) : Number.NaN,\n )\n if (numbers.some(Number.isNaN)) return null\n const [top, right, bottom, left] = numbers as [number, number, number, number]\n return { top, right, bottom, left }\n}\n\n/**\n * Sets `--pd-safe-top`, `--pd-safe-right`, `--pd-safe-bottom` and\n * `--pd-safe-left` on `target` from the page URL's `pd-safe-area`. Does\n * nothing when it's absent, so CSS falls back to `env(safe-area-inset-*)`.\n */\nexport function applySafeArea(\n target: HTMLElement = document.documentElement,\n search: string = location.search,\n): SafeArea | null {\n const insets = readSafeArea(search)\n if (!insets) return null\n for (const side of SIDES)\n target.style.setProperty(`--pd-safe-${side}`, `${insets[side]}px`)\n return insets\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC0EO,IAAM,UAAU;AAAA,EACrB,OAAO;AAAA,IACL,UAAU,EAAE,OAAO,KAAK,QAAQ,IAAI;AAAA,IACpC,OAAO;AAAA;AAAA,IAEP,cAAc,QAAQ;AAAA,IACtB,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,EAAE,MAAM,QAAQ,OAAO,OAAO,QAAQ,MAAM;AAAA,MAC5C,EAAE,MAAM,QAAQ,OAAO,OAAO,QAAQ,MAAM;AAAA,MAC5C,EAAE,MAAM,QAAQ,OAAO,MAAM,QAAQ,MAAM;AAAA,MAC3C,EAAE,MAAM,SAAS,OAAO,MAAM,QAAQ,KAAK;AAAA,IAC7C;AAAA,EACF;AAAA,EACA,QAAQ;AAAA,IACN,UAAU,EAAE,OAAO,MAAM,QAAQ,IAAI;AAAA,IACrC,OAAO;AAAA;AAAA,IAEP,cAAc,KAAK;AAAA,IACnB,QAAQ;AAAA,IACR,SAAS,CAAC,EAAE,MAAM,OAAO,OAAO,MAAM,QAAQ,KAAK,CAAC;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA,EAIA,iBAAiB;AAAA,IACf,UAAU,EAAE,OAAO,KAAK,QAAQ,IAAI;AAAA,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