@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/dist/core.js CHANGED
@@ -21,10 +21,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var core_exports = {};
22
22
  __export(core_exports, {
23
23
  DEVICES: () => DEVICES,
24
+ SAFE_AREA_PARAM: () => SAFE_AREA_PARAM,
25
+ applySafeArea: () => applySafeArea,
24
26
  deviceGeometry: () => deviceGeometry,
25
27
  deviceHTML: () => deviceHTML,
26
28
  deviceVars: () => deviceVars,
27
- resolveDevice: () => resolveDevice
29
+ readSafeArea: () => readSafeArea,
30
+ resolveDevice: () => resolveDevice,
31
+ withSafeArea: () => withSafeArea
28
32
  });
29
33
  module.exports = __toCommonJS(core_exports);
30
34
 
@@ -50,6 +54,42 @@ var DEVICES = {
50
54
  screenRadius: 18 / 1180,
51
55
  cutout: "none",
52
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
+ ]
53
93
  }
54
94
  };
55
95
  var ISLAND = { width: 126 / 393, height: 37 / 393, top: 11 / 393 };
@@ -63,19 +103,39 @@ function deviceGeometry(device, width, cutout) {
63
103
  const screenWidth = width - bezel * 2;
64
104
  const screenHeight = screenWidth * spec.viewport.height / spec.viewport.width;
65
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
+ };
66
128
  return {
67
129
  width,
68
130
  height: screenHeight + bezel * 2,
69
131
  bezel,
70
132
  radius: screenRadius + bezel,
71
133
  screen: { width: screenWidth, height: screenHeight, radius: screenRadius },
72
- island: (cutout ?? spec.cutout) === "island" ? {
73
- width: ISLAND.width * screenWidth,
74
- height: ISLAND.height * screenWidth,
75
- top: ISLAND.top * screenWidth
76
- } : void 0,
134
+ island,
135
+ hole,
136
+ safeArea,
77
137
  buttonDepth: BUTTON_DEPTH * width,
78
- scale: screenWidth / spec.viewport.width
138
+ scale
79
139
  };
80
140
  }
81
141
  var round = (n) => Math.round(n * 1e4) / 1e4;
@@ -94,6 +154,26 @@ function deviceVars(device = "phone", options = {}) {
94
154
  vars["--pd-device-island-height"] = `${round(g.island.height)}`;
95
155
  vars["--pd-device-island-top"] = `${round(g.island.top)}`;
96
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
+ }
97
177
  if (options.maxHeight)
98
178
  vars["--pd-device-max-width"] = `calc(${options.maxHeight} * ${round(g.width / g.height)})`;
99
179
  return vars;
@@ -104,6 +184,8 @@ var esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&
104
184
  function deviceHTML(options) {
105
185
  const spec = resolveDevice(options.device);
106
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>' : "";
107
189
  const style = Object.entries(
108
190
  deviceVars(spec, { cutout, maxHeight: options.maxHeight })
109
191
  ).map(([name, value]) => `${name}:${value}`).join(";");
@@ -112,14 +194,64 @@ function deviceHTML(options) {
112
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>`
113
195
  ).join("");
114
196
  const className = options.className ? `pd-device ${esc(options.className)}` : "pd-device";
115
- 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>`;
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;
116
244
  }
117
245
  // Annotate the CommonJS export names for ESM import in node:
118
246
  0 && (module.exports = {
119
247
  DEVICES,
248
+ SAFE_AREA_PARAM,
249
+ applySafeArea,
120
250
  deviceGeometry,
121
251
  deviceHTML,
122
252
  deviceVars,
123
- resolveDevice
253
+ readSafeArea,
254
+ resolveDevice,
255
+ withSafeArea
124
256
  });
125
257
  //# sourceMappingURL=core.js.map
package/dist/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/index.ts","../src/core/devices.ts","../src/core/html.ts"],"sourcesContent":["export {\n type Cutout,\n DEVICES,\n type DeviceButton,\n type DeviceGeometry,\n type DeviceName,\n type DeviceSpec,\n deviceGeometry,\n deviceVars,\n resolveDevice,\n} from './devices'\nexport { type DeviceHTMLOptions, deviceHTML } from './html'\n","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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC8BO,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;AACF;AAKA,IAAM,SAAS,EAAE,OAAO,MAAM,KAAK,QAAQ,KAAK,KAAK,KAAK,KAAK,IAAI;AAGnE,IAAM,eAAe;AAEd,SAAS,cAAc,SAAkC,SAAS;AACvE,SAAO,OAAO,WAAW,WAAW,QAAQ,MAAM,IAAI;AACxD;AAmBO,SAAS,eACd,QACA,OACA,QACgB;AAChB,QAAM,OAAO,cAAc,MAAM;AACjC,QAAM,QAAQ,KAAK,QAAQ;AAC3B,QAAM,cAAc,QAAQ,QAAQ;AACpC,QAAM,eACH,cAAc,KAAK,SAAS,SAAU,KAAK,SAAS;AACvD,QAAM,eAAe,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,SAAO;AACT;;;ACtIA,IAAM,MAAM,CAAC,MACX,EACG,QAAQ,MAAM,OAAO,EACrB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,MAAM,EACpB,QAAQ,MAAM,QAAQ;AAsBpB,SAAS,WAAW,SAAoC;AAC7D,QAAM,OAAO,cAAc,QAAQ,MAAM;AACzC,QAAM,SAAS,QAAQ,UAAU,KAAK;AACtC,QAAM,QAAQ,OAAO;AAAA,IACnB,WAAW,MAAM,EAAE,QAAQ,WAAW,QAAQ,UAAU,CAAC;AAAA,EAC3D,EACG,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,GAAG,IAAI,IAAI,KAAK,EAAE,EACzC,KAAK,GAAG;AACX,QAAM,OACJ,QAAQ,SAAS,QAAQ,SACrB,WAAW,QAAQ,KAAK,aAAa,QAAQ,MAAM,MACnD;AACN,QAAM,UAAU,KAAK,QAClB;AAAA,IACC,CAAC,MACC,6CAA6C,EAAE,IAAI,qCAAqC,EAAE,QAAQ,GAAG,+BAA+B,EAAE,SAAS,GAAG;AAAA,EACtJ,EACC,KAAK,EAAE;AACV,QAAM,YAAY,QAAQ,YACtB,aAAa,IAAI,QAAQ,SAAS,CAAC,KACnC;AAEJ,SAAO,gBAAgB,SAAS,YAAY,IAAI,KAAK,CAAC,kCAAkC,OAAO,mEAAmE,IAAI,QAAQ,GAAG,CAAC,UAAU,IAAI,QAAQ,GAAG,CAAC,IAAI,IAAI,aAAa,QAAQ,WAAW,MAAM,sBAAsB,WAAW,WAAW,2CAA2C,EAAE;AACrV;","names":[]}
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, '&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 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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20,6 +20,42 @@ var DEVICES = {
20
20
  screenRadius: 18 / 1180,
21
21
  cutout: "none",
22
22
  buttons: [{ side: "top", start: 0.84, length: 0.06 }]
23
+ },
24
+ // iOS 26.5 Simulator, iPhone 16 Pro: UIKit safeAreaInsets, the screen's
25
+ // exclusion area and display corner radius, and measured status bar
26
+ // placement. The home indicator is approximate.
27
+ "iphone-16-pro": {
28
+ viewport: { width: 402, height: 874 },
29
+ bezel: 0.034,
30
+ screenRadius: 62 / 402,
31
+ cutout: { type: "island", width: 125, height: 36.67, top: 14 },
32
+ safeArea: { top: 62, right: 0, bottom: 34, left: 0 },
33
+ statusBar: { time: 74, icons: 73, center: 33, fontSize: 17 },
34
+ homeIndicator: { width: 134, height: 5, bottom: 8 },
35
+ buttons: [
36
+ { side: "left", start: 0.175, length: 0.045 },
37
+ { side: "left", start: 0.255, length: 0.085 },
38
+ { side: "left", start: 0.36, length: 0.085 },
39
+ { side: "right", start: 0.29, length: 0.14 },
40
+ { side: "right", start: 0.6, length: 0.07 }
41
+ ]
42
+ },
43
+ // Android emulator pixel_9 definition: size from nexus.xml (1080 × 2424 at
44
+ // 420 dpi), hole and corners measured from the skin's mask. No public
45
+ // status bar height: the top inset is the Pixel 8 overlay's, and the bottom
46
+ // is the gesture bar; both approximate.
47
+ "pixel-9": {
48
+ viewport: { width: 412, height: 923 },
49
+ bezel: 0.034,
50
+ screenRadius: 54.5 / 412,
51
+ cutout: { type: "hole", diameter: 30.5, top: 17.5, x: 0.5 },
52
+ safeArea: { top: 50, right: 0, bottom: 24, left: 0 },
53
+ statusBar: { time: 42, icons: 50, center: 26, fontSize: 14 },
54
+ homeIndicator: { width: 108, height: 4, bottom: 10 },
55
+ buttons: [
56
+ { side: "right", start: 0.22, length: 0.07 },
57
+ { side: "right", start: 0.33, length: 0.14 }
58
+ ]
23
59
  }
24
60
  };
25
61
  var ISLAND = { width: 126 / 393, height: 37 / 393, top: 11 / 393 };
@@ -33,19 +69,39 @@ function deviceGeometry(device, width, cutout) {
33
69
  const screenWidth = width - bezel * 2;
34
70
  const screenHeight = screenWidth * spec.viewport.height / spec.viewport.width;
35
71
  const screenRadius = spec.screenRadius * screenWidth;
72
+ const scale = screenWidth / spec.viewport.width;
73
+ const shape = cutout ?? spec.cutout;
74
+ const island = shape === "island" ? {
75
+ width: ISLAND.width * screenWidth,
76
+ height: ISLAND.height * screenWidth,
77
+ top: ISLAND.top * screenWidth
78
+ } : typeof shape === "object" && shape.type === "island" ? {
79
+ width: shape.width * scale,
80
+ height: shape.height * scale,
81
+ top: shape.top * scale
82
+ } : void 0;
83
+ const hole = typeof shape === "object" && shape.type === "hole" ? {
84
+ diameter: shape.diameter * scale,
85
+ top: shape.top * scale,
86
+ x: shape.x ?? 0.5
87
+ } : void 0;
88
+ const safeArea = spec.safeArea && {
89
+ top: spec.safeArea.top * scale,
90
+ right: spec.safeArea.right * scale,
91
+ bottom: spec.safeArea.bottom * scale,
92
+ left: spec.safeArea.left * scale
93
+ };
36
94
  return {
37
95
  width,
38
96
  height: screenHeight + bezel * 2,
39
97
  bezel,
40
98
  radius: screenRadius + bezel,
41
99
  screen: { width: screenWidth, height: screenHeight, radius: screenRadius },
42
- island: (cutout ?? spec.cutout) === "island" ? {
43
- width: ISLAND.width * screenWidth,
44
- height: ISLAND.height * screenWidth,
45
- top: ISLAND.top * screenWidth
46
- } : void 0,
100
+ island,
101
+ hole,
102
+ safeArea,
47
103
  buttonDepth: BUTTON_DEPTH * width,
48
- scale: screenWidth / spec.viewport.width
104
+ scale
49
105
  };
50
106
  }
51
107
  var round = (n) => Math.round(n * 1e4) / 1e4;
@@ -64,6 +120,26 @@ function deviceVars(device = "phone", options = {}) {
64
120
  vars["--pd-device-island-height"] = `${round(g.island.height)}`;
65
121
  vars["--pd-device-island-top"] = `${round(g.island.top)}`;
66
122
  }
123
+ if (g.hole) {
124
+ vars["--pd-device-hole-size"] = `${round(g.hole.diameter)}`;
125
+ vars["--pd-device-hole-top"] = `${round(g.hole.top)}`;
126
+ vars["--pd-device-hole-x"] = `${round(g.bezel + g.hole.x * g.screen.width)}`;
127
+ }
128
+ if (g.safeArea) {
129
+ vars["--pd-device-safe-top"] = `${round(g.safeArea.top)}`;
130
+ vars["--pd-device-safe-bottom"] = `${round(g.safeArea.bottom)}`;
131
+ }
132
+ if (spec.statusBar) {
133
+ vars["--pd-device-status-time"] = `${round(spec.statusBar.time * g.scale)}`;
134
+ vars["--pd-device-status-icons"] = `${round(spec.statusBar.icons * g.scale)}`;
135
+ vars["--pd-device-status-center"] = `${round(spec.statusBar.center * g.scale)}`;
136
+ vars["--pd-device-status-font"] = `${round(spec.statusBar.fontSize * g.scale)}`;
137
+ }
138
+ if (spec.homeIndicator) {
139
+ vars["--pd-device-home-width"] = `${round(spec.homeIndicator.width * g.scale)}`;
140
+ vars["--pd-device-home-height"] = `${round(spec.homeIndicator.height * g.scale)}`;
141
+ vars["--pd-device-home-bottom"] = `${round(spec.homeIndicator.bottom * g.scale)}`;
142
+ }
67
143
  if (options.maxHeight)
68
144
  vars["--pd-device-max-width"] = `calc(${options.maxHeight} * ${round(g.width / g.height)})`;
69
145
  return vars;
@@ -74,6 +150,8 @@ var esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&
74
150
  function deviceHTML(options) {
75
151
  const spec = resolveDevice(options.device);
76
152
  const cutout = options.cutout ?? spec.cutout;
153
+ const geometry = deviceGeometry(spec, 100, cutout);
154
+ const cutoutHTML = geometry.island ? '<span class="pd-device-island"></span>' : geometry.hole ? '<span class="pd-device-hole"></span>' : "";
77
155
  const style = Object.entries(
78
156
  deviceVars(spec, { cutout, maxHeight: options.maxHeight })
79
157
  ).map(([name, value]) => `${name}:${value}`).join(";");
@@ -82,13 +160,63 @@ function deviceHTML(options) {
82
160
  (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>`
83
161
  ).join("");
84
162
  const className = options.className ? `pd-device ${esc(options.className)}` : "pd-device";
85
- 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>`;
163
+ 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>`;
164
+ }
165
+
166
+ // src/core/safe-area.ts
167
+ var SAFE_AREA_PARAM = "pd-safe-area";
168
+ var SIDES = ["top", "right", "bottom", "left"];
169
+ function withSafeArea(url, insets) {
170
+ const scheme = /^([a-z][a-z\d+.-]*):/i.exec(url)?.[1]?.toLowerCase();
171
+ if (scheme && scheme !== "http" && scheme !== "https") return url;
172
+ const hashAt = url.indexOf("#");
173
+ const hash = hashAt < 0 ? "" : url.slice(hashAt);
174
+ const beforeHash = hashAt < 0 ? url : url.slice(0, hashAt);
175
+ const queryAt = beforeHash.indexOf("?");
176
+ const path = queryAt < 0 ? beforeHash : beforeHash.slice(0, queryAt);
177
+ const query = queryAt < 0 ? "" : beforeHash.slice(queryAt + 1);
178
+ const params = query.split("&").filter((part) => part && paramName(part) !== SAFE_AREA_PARAM);
179
+ params.push(
180
+ `${SAFE_AREA_PARAM}=${SIDES.map((side) => Math.round(insets[side])).join(",")}`
181
+ );
182
+ return `${path}?${params.join("&")}${hash}`;
183
+ }
184
+ function paramName(part) {
185
+ const name = part.split("=")[0] ?? "";
186
+ try {
187
+ return decodeURIComponent(name.replace(/\+/g, " "));
188
+ } catch {
189
+ return name;
190
+ }
191
+ }
192
+ function readSafeArea(search) {
193
+ const value = new URLSearchParams(search).get(SAFE_AREA_PARAM);
194
+ if (!value) return null;
195
+ const parts = value.split(",");
196
+ if (parts.length !== 4) return null;
197
+ const numbers = parts.map(
198
+ (part) => /^\d+(\.\d+)?$/.test(part) ? Number(part) : Number.NaN
199
+ );
200
+ if (numbers.some(Number.isNaN)) return null;
201
+ const [top, right, bottom, left] = numbers;
202
+ return { top, right, bottom, left };
203
+ }
204
+ function applySafeArea(target = document.documentElement, search = location.search) {
205
+ const insets = readSafeArea(search);
206
+ if (!insets) return null;
207
+ for (const side of SIDES)
208
+ target.style.setProperty(`--pd-safe-${side}`, `${insets[side]}px`);
209
+ return insets;
86
210
  }
87
211
  export {
88
212
  DEVICES,
213
+ SAFE_AREA_PARAM,
214
+ applySafeArea,
89
215
  deviceGeometry,
90
216
  deviceHTML,
91
217
  deviceVars,
92
- resolveDevice
218
+ readSafeArea,
219
+ resolveDevice,
220
+ withSafeArea
93
221
  };
94
222
  //# sourceMappingURL=core.mjs.map
package/dist/core.mjs.map CHANGED
@@ -1 +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":";AA8BO,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,CA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AAI,QAAQ,GAAG,CAAC,UAAU,IAAI,QAAQ,GAAG,CAAC,IAAI,IAAI,aAAa,QAAQ,WAAW,MAAM,sBAAsB,WAAW,WAAW,2CAA2C,EAAE;AACrV;","names":[]}
1
+ {"version":3,"sources":["../src/core/devices.ts","../src/core/html.ts","../src/core/safe-area.ts"],"sourcesContent":["/** 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, '&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 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":";AA0EO,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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