@erkamyaman/capacitor-foldable 7.0.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.
Files changed (43) hide show
  1. package/ErkamyamanCapacitorFoldable.podspec +17 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +28 -0
  4. package/README.md +457 -0
  5. package/android/build.gradle +71 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/kotlin/io/github/erkamyaman/foldable/DisplayModes.kt +115 -0
  8. package/android/src/main/kotlin/io/github/erkamyaman/foldable/Foldable.kt +189 -0
  9. package/android/src/main/kotlin/io/github/erkamyaman/foldable/FoldablePlugin.kt +333 -0
  10. package/android/src/main/res/.gitkeep +0 -0
  11. package/dist/docs.json +584 -0
  12. package/dist/esm/css.d.ts +8 -0
  13. package/dist/esm/css.js +29 -0
  14. package/dist/esm/css.js.map +1 -0
  15. package/dist/esm/definitions.d.ts +267 -0
  16. package/dist/esm/definitions.js +2 -0
  17. package/dist/esm/definitions.js.map +1 -0
  18. package/dist/esm/index.d.ts +5 -0
  19. package/dist/esm/index.js +9 -0
  20. package/dist/esm/index.js.map +1 -0
  21. package/dist/esm/polyfill.d.ts +19 -0
  22. package/dist/esm/polyfill.js +76 -0
  23. package/dist/esm/polyfill.js.map +1 -0
  24. package/dist/esm/segments.d.ts +8 -0
  25. package/dist/esm/segments.js +26 -0
  26. package/dist/esm/segments.js.map +1 -0
  27. package/dist/esm/size-class.d.ts +2 -0
  28. package/dist/esm/size-class.js +33 -0
  29. package/dist/esm/size-class.js.map +1 -0
  30. package/dist/esm/web.d.ts +21 -0
  31. package/dist/esm/web.js +46 -0
  32. package/dist/esm/web.js.map +1 -0
  33. package/dist/plugin.cjs.js +222 -0
  34. package/dist/plugin.cjs.js.map +1 -0
  35. package/dist/plugin.js +225 -0
  36. package/dist/plugin.js.map +1 -0
  37. package/ios/Sources/FoldablePlugin/Foldable.swift +156 -0
  38. package/ios/Sources/FoldablePlugin/FoldablePlugin.swift +194 -0
  39. package/ios/Sources/FoldablePlugin/ReservedRegionFoldProvider.swift +69 -0
  40. package/ios/Sources/FoldablePlugin/UIKitFoldSource.swift +53 -0
  41. package/ios/Tests/FoldablePluginTests/FoldableTests.swift +104 -0
  42. package/ios/Tests/FoldablePluginTests/ReservedRegionFoldProviderTests.swift +143 -0
  43. package/package.json +96 -0
@@ -0,0 +1,267 @@
1
+ import type { PluginListenerHandle } from '@capacitor/core';
2
+ export interface FoldState {
3
+ /**
4
+ * Posture of the fold. `'closed'` is never reported today: a device shut on
5
+ * its cover display reports `'flat'`.
6
+ *
7
+ * @since 7.0.0
8
+ */
9
+ state: 'flat' | 'half-opened' | 'closed';
10
+ /**
11
+ * Whether the fold splits the web view into two areas: `true` when
12
+ * half-opened, or when the hinge has a physical gap.
13
+ *
14
+ * @since 7.0.0
15
+ */
16
+ isSeparating: boolean;
17
+ /**
18
+ * How the device is held: `'tabletop'` when half-opened with a horizontal
19
+ * hinge, like a laptop, `'book'` when half-opened with a vertical hinge, and
20
+ * `'flat'` otherwise.
21
+ *
22
+ * @since 7.0.0
23
+ */
24
+ posture: 'flat' | 'tabletop' | 'book';
25
+ /**
26
+ * Direction of the hinge relative to the window, so it flips when the device
27
+ * rotates. Omitted when there is no fold.
28
+ *
29
+ * @since 7.0.0
30
+ */
31
+ hingeOrientation?: 'horizontal' | 'vertical';
32
+ /**
33
+ * Position of the fold in CSS pixels, relative to the web view. Zero wide (or
34
+ * zero tall) on a seamless fold. Omitted when there is no fold.
35
+ *
36
+ * @since 7.0.0
37
+ */
38
+ hingeBounds?: {
39
+ x: number;
40
+ y: number;
41
+ width: number;
42
+ height: number;
43
+ };
44
+ /**
45
+ * Area of the web view the hinge covers, in CSS pixels. Only present on
46
+ * devices with a physical gap.
47
+ *
48
+ * @since 7.0.0
49
+ */
50
+ occludedBounds?: {
51
+ x: number;
52
+ y: number;
53
+ width: number;
54
+ height: number;
55
+ };
56
+ /**
57
+ * Which display is showing the app, on a device with an inner and an outer
58
+ * display such as iPhone Duo. Reported on iPhone Duo (iOS 27.1 or later) and
59
+ * omitted elsewhere.
60
+ *
61
+ * @since 7.0.0
62
+ */
63
+ activeDisplay?: 'inner' | 'outer';
64
+ /**
65
+ * Areas of the web view covered by a front-facing camera, in CSS pixels. On
66
+ * Android these are the display cutouts. On iPhone Duo they are the outer
67
+ * camera and the under-display inner camera while it is in use. Omitted when
68
+ * there are none.
69
+ *
70
+ * @since 7.0.0
71
+ */
72
+ cameraBounds?: {
73
+ x: number;
74
+ y: number;
75
+ width: number;
76
+ height: number;
77
+ }[];
78
+ }
79
+ export interface SizeClass {
80
+ /**
81
+ * Width size class of the window: `'compact'` on a phone and on the outer
82
+ * display of a foldable, `'regular'` on the inner display, tablets and wide
83
+ * windows. On Android and web `'regular'` starts at 600 CSS pixels.
84
+ *
85
+ * @since 7.0.0
86
+ */
87
+ horizontal: 'compact' | 'regular';
88
+ /**
89
+ * Height size class of the window: `'compact'` on a phone in landscape. On
90
+ * Android and web `'regular'` starts at 480 CSS pixels.
91
+ *
92
+ * @since 7.0.0
93
+ */
94
+ vertical: 'compact' | 'regular';
95
+ /**
96
+ * Material window width class, from the window width in CSS pixels:
97
+ * `'compact'` below 600, `'medium'` below 840, `'expanded'` below 1200,
98
+ * `'large'` below 1600 and `'extraLarge'` from 1600.
99
+ *
100
+ * @since 7.0.0
101
+ */
102
+ widthClass: 'compact' | 'medium' | 'expanded' | 'large' | 'extraLarge';
103
+ /**
104
+ * Material window height class, from the window height in CSS pixels:
105
+ * `'compact'` below 480, `'medium'` below 900 and `'expanded'` from 900.
106
+ *
107
+ * @since 7.0.0
108
+ */
109
+ heightClass: 'compact' | 'medium' | 'expanded';
110
+ }
111
+ export type DisplayModeStatus = 'unsupported' | 'unavailable' | 'available' | 'active';
112
+ export interface DisplayModes {
113
+ /**
114
+ * Rear display mode moves the app to the outer display, so people can frame a
115
+ * photo with the rear cameras. Only on Android foldables that offer it.
116
+ *
117
+ * @since 7.0.0
118
+ */
119
+ rearDisplay: DisplayModeStatus;
120
+ /**
121
+ * Dual-screen mode shows a second page on the outer display while the app
122
+ * stays on the inner one. Only on Android foldables that offer it.
123
+ *
124
+ * @since 7.0.0
125
+ */
126
+ dualScreen: DisplayModeStatus;
127
+ }
128
+ export interface BarPlacement {
129
+ /**
130
+ * The edge iPhone Duo moves tab bars and toolbars to when it lays them out
131
+ * vertically: `'leading'` or `'trailing'` in the reading direction, so
132
+ * `'leading'` is the left edge in left-to-right languages. `null` when bars
133
+ * stay horizontal, and always on Android, web and iOS before 27.1.
134
+ *
135
+ * @since 7.0.0
136
+ */
137
+ verticalBarEdge: 'leading' | 'trailing' | null;
138
+ }
139
+ export interface FoldablePlugin {
140
+ /**
141
+ * Whether the device has a fold at all, and whether it can be propped half
142
+ * open like a laptop. Both `false` on web, and on iOS except on iPhone Duo
143
+ * (iOS 27.1 or later).
144
+ *
145
+ * @since 7.0.0
146
+ */
147
+ isDeviceFoldable(): Promise<{
148
+ foldable: boolean;
149
+ supportsTabletop: boolean;
150
+ }>;
151
+ /**
152
+ * Read the current fold state. Resolves to
153
+ * `{ state: 'flat', isSeparating: false, posture: 'flat' }` when there is no
154
+ * fold information.
155
+ *
156
+ * @since 7.0.0
157
+ */
158
+ getFoldState(): Promise<FoldState>;
159
+ /**
160
+ * Read the angle between the two halves of the device, in degrees: `0` when
161
+ * closed, `180` when flat. Resolves to `{ angle: null }` on devices without a
162
+ * hinge angle sensor, on web, and on iOS before 27.1.
163
+ *
164
+ * @since 7.0.0
165
+ */
166
+ getHingeAngle(): Promise<{
167
+ angle: number | null;
168
+ }>;
169
+ /**
170
+ * Read the window's size classes: Apple's compact and regular, the signal its
171
+ * iPhone Duo guidelines recommend for telling the outer display from the inner
172
+ * one, and Material's width and height classes. On iOS `horizontal` and
173
+ * `vertical` are UIKit's size classes; everything else comes from the window
174
+ * size.
175
+ *
176
+ * @since 7.0.0
177
+ */
178
+ getSizeClass(): Promise<SizeClass>;
179
+ /**
180
+ * Read which of the foldable display modes the device offers right now. Both
181
+ * are `'unsupported'` on iOS and web.
182
+ *
183
+ * @since 7.0.0
184
+ */
185
+ getDisplayModes(): Promise<DisplayModes>;
186
+ /**
187
+ * Read where native bars go. Native tab bars and toolbars move to the side of
188
+ * the display on iPhone Duo, but HTML ones stay put, so use this to move your
189
+ * own tab bar too.
190
+ *
191
+ * @since 7.0.0
192
+ */
193
+ getBarPlacement(): Promise<BarPlacement>;
194
+ /**
195
+ * Move the app to the outer display. Android asks the user to confirm first,
196
+ * and the promise resolves once the app has moved. Rejects when rear display
197
+ * mode is not `'available'`. Only on Android.
198
+ *
199
+ * @since 7.0.0
200
+ */
201
+ startRearDisplay(): Promise<void>;
202
+ /**
203
+ * Move the app back to the inner display.
204
+ *
205
+ * @since 7.0.0
206
+ */
207
+ stopRearDisplay(): Promise<void>;
208
+ /**
209
+ * Show a page on the outer display while the app stays on the inner one. A
210
+ * relative `url` resolves against the app's own URL, so `'cover.html'` loads a
211
+ * page bundled with the app. The page runs in its own web view without access
212
+ * to Capacitor plugins. Calling this again while dual-screen mode is active
213
+ * replaces the page. Only on Android.
214
+ *
215
+ * @since 7.0.0
216
+ */
217
+ startDualScreen(options: {
218
+ url: string;
219
+ }): Promise<void>;
220
+ /**
221
+ * Close the page on the outer display.
222
+ *
223
+ * @since 7.0.0
224
+ */
225
+ stopDualScreen(): Promise<void>;
226
+ /**
227
+ * Listen for fold state changes. On a foldable this also fires when the
228
+ * device rotates, because `hingeOrientation` and `hingeBounds` rotate with
229
+ * the window.
230
+ *
231
+ * @since 7.0.0
232
+ */
233
+ addListener(eventName: 'foldStateChange', listenerFunc: (state: FoldState) => void): Promise<PluginListenerHandle>;
234
+ /**
235
+ * Listen for hinge angle changes. On Android the hinge sensor only runs while
236
+ * at least one of these listeners is registered. On iOS it fires on iPhone
237
+ * Duo (iOS 27.1 or later). Never fires on web.
238
+ *
239
+ * @since 7.0.0
240
+ */
241
+ addListener(eventName: 'hingeAngleChange', listenerFunc: (event: {
242
+ angle: number;
243
+ }) => void): Promise<PluginListenerHandle>;
244
+ /**
245
+ * Listen for size class changes, such as unfolding the device, rotating it or
246
+ * resizing the window. On iOS this fires when UIKit's size classes change
247
+ * (iOS 17 or later) or the device rotates, so a resize that keeps the same
248
+ * size classes may not update `widthClass` and `heightClass` until then.
249
+ *
250
+ * @since 7.0.0
251
+ */
252
+ addListener(eventName: 'sizeClassChange', listenerFunc: (sizeClass: SizeClass) => void): Promise<PluginListenerHandle>;
253
+ /**
254
+ * Listen for changes to the display modes, including a mode ending because
255
+ * the user folded or unfolded the device. Never fires on iOS and web.
256
+ *
257
+ * @since 7.0.0
258
+ */
259
+ addListener(eventName: 'displayModeChange', listenerFunc: (modes: DisplayModes) => void): Promise<PluginListenerHandle>;
260
+ /**
261
+ * Listen for bar placement changes, such as opening or rotating iPhone Duo.
262
+ * Only fires on iOS 27.1 or later.
263
+ *
264
+ * @since 7.0.0
265
+ */
266
+ addListener(eventName: 'barPlacementChange', listenerFunc: (placement: BarPlacement) => void): Promise<PluginListenerHandle>;
267
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface FoldState {\n /**\n * Posture of the fold. `'closed'` is never reported today: a device shut on\n * its cover display reports `'flat'`.\n *\n * @since 7.0.0\n */\n state: 'flat' | 'half-opened' | 'closed';\n\n /**\n * Whether the fold splits the web view into two areas: `true` when\n * half-opened, or when the hinge has a physical gap.\n *\n * @since 7.0.0\n */\n isSeparating: boolean;\n\n /**\n * How the device is held: `'tabletop'` when half-opened with a horizontal\n * hinge, like a laptop, `'book'` when half-opened with a vertical hinge, and\n * `'flat'` otherwise.\n *\n * @since 7.0.0\n */\n posture: 'flat' | 'tabletop' | 'book';\n\n /**\n * Direction of the hinge relative to the window, so it flips when the device\n * rotates. Omitted when there is no fold.\n *\n * @since 7.0.0\n */\n hingeOrientation?: 'horizontal' | 'vertical';\n\n /**\n * Position of the fold in CSS pixels, relative to the web view. Zero wide (or\n * zero tall) on a seamless fold. Omitted when there is no fold.\n *\n * @since 7.0.0\n */\n hingeBounds?: { x: number; y: number; width: number; height: number };\n\n /**\n * Area of the web view the hinge covers, in CSS pixels. Only present on\n * devices with a physical gap.\n *\n * @since 7.0.0\n */\n occludedBounds?: { x: number; y: number; width: number; height: number };\n\n /**\n * Which display is showing the app, on a device with an inner and an outer\n * display such as iPhone Duo. Reported on iPhone Duo (iOS 27.1 or later) and\n * omitted elsewhere.\n *\n * @since 7.0.0\n */\n activeDisplay?: 'inner' | 'outer';\n\n /**\n * Areas of the web view covered by a front-facing camera, in CSS pixels. On\n * Android these are the display cutouts. On iPhone Duo they are the outer\n * camera and the under-display inner camera while it is in use. Omitted when\n * there are none.\n *\n * @since 7.0.0\n */\n cameraBounds?: { x: number; y: number; width: number; height: number }[];\n}\n\nexport interface SizeClass {\n /**\n * Width size class of the window: `'compact'` on a phone and on the outer\n * display of a foldable, `'regular'` on the inner display, tablets and wide\n * windows. On Android and web `'regular'` starts at 600 CSS pixels.\n *\n * @since 7.0.0\n */\n horizontal: 'compact' | 'regular';\n\n /**\n * Height size class of the window: `'compact'` on a phone in landscape. On\n * Android and web `'regular'` starts at 480 CSS pixels.\n *\n * @since 7.0.0\n */\n vertical: 'compact' | 'regular';\n\n /**\n * Material window width class, from the window width in CSS pixels:\n * `'compact'` below 600, `'medium'` below 840, `'expanded'` below 1200,\n * `'large'` below 1600 and `'extraLarge'` from 1600.\n *\n * @since 7.0.0\n */\n widthClass: 'compact' | 'medium' | 'expanded' | 'large' | 'extraLarge';\n\n /**\n * Material window height class, from the window height in CSS pixels:\n * `'compact'` below 480, `'medium'` below 900 and `'expanded'` from 900.\n *\n * @since 7.0.0\n */\n heightClass: 'compact' | 'medium' | 'expanded';\n}\n\nexport type DisplayModeStatus = 'unsupported' | 'unavailable' | 'available' | 'active';\n\nexport interface DisplayModes {\n /**\n * Rear display mode moves the app to the outer display, so people can frame a\n * photo with the rear cameras. Only on Android foldables that offer it.\n *\n * @since 7.0.0\n */\n rearDisplay: DisplayModeStatus;\n\n /**\n * Dual-screen mode shows a second page on the outer display while the app\n * stays on the inner one. Only on Android foldables that offer it.\n *\n * @since 7.0.0\n */\n dualScreen: DisplayModeStatus;\n}\n\nexport interface BarPlacement {\n /**\n * The edge iPhone Duo moves tab bars and toolbars to when it lays them out\n * vertically: `'leading'` or `'trailing'` in the reading direction, so\n * `'leading'` is the left edge in left-to-right languages. `null` when bars\n * stay horizontal, and always on Android, web and iOS before 27.1.\n *\n * @since 7.0.0\n */\n verticalBarEdge: 'leading' | 'trailing' | null;\n}\n\nexport interface FoldablePlugin {\n /**\n * Whether the device has a fold at all, and whether it can be propped half\n * open like a laptop. Both `false` on web, and on iOS except on iPhone Duo\n * (iOS 27.1 or later).\n *\n * @since 7.0.0\n */\n isDeviceFoldable(): Promise<{ foldable: boolean; supportsTabletop: boolean }>;\n\n /**\n * Read the current fold state. Resolves to\n * `{ state: 'flat', isSeparating: false, posture: 'flat' }` when there is no\n * fold information.\n *\n * @since 7.0.0\n */\n getFoldState(): Promise<FoldState>;\n\n /**\n * Read the angle between the two halves of the device, in degrees: `0` when\n * closed, `180` when flat. Resolves to `{ angle: null }` on devices without a\n * hinge angle sensor, on web, and on iOS before 27.1.\n *\n * @since 7.0.0\n */\n getHingeAngle(): Promise<{ angle: number | null }>;\n\n /**\n * Read the window's size classes: Apple's compact and regular, the signal its\n * iPhone Duo guidelines recommend for telling the outer display from the inner\n * one, and Material's width and height classes. On iOS `horizontal` and\n * `vertical` are UIKit's size classes; everything else comes from the window\n * size.\n *\n * @since 7.0.0\n */\n getSizeClass(): Promise<SizeClass>;\n\n /**\n * Read which of the foldable display modes the device offers right now. Both\n * are `'unsupported'` on iOS and web.\n *\n * @since 7.0.0\n */\n getDisplayModes(): Promise<DisplayModes>;\n\n /**\n * Read where native bars go. Native tab bars and toolbars move to the side of\n * the display on iPhone Duo, but HTML ones stay put, so use this to move your\n * own tab bar too.\n *\n * @since 7.0.0\n */\n getBarPlacement(): Promise<BarPlacement>;\n\n /**\n * Move the app to the outer display. Android asks the user to confirm first,\n * and the promise resolves once the app has moved. Rejects when rear display\n * mode is not `'available'`. Only on Android.\n *\n * @since 7.0.0\n */\n startRearDisplay(): Promise<void>;\n\n /**\n * Move the app back to the inner display.\n *\n * @since 7.0.0\n */\n stopRearDisplay(): Promise<void>;\n\n /**\n * Show a page on the outer display while the app stays on the inner one. A\n * relative `url` resolves against the app's own URL, so `'cover.html'` loads a\n * page bundled with the app. The page runs in its own web view without access\n * to Capacitor plugins. Calling this again while dual-screen mode is active\n * replaces the page. Only on Android.\n *\n * @since 7.0.0\n */\n startDualScreen(options: { url: string }): Promise<void>;\n\n /**\n * Close the page on the outer display.\n *\n * @since 7.0.0\n */\n stopDualScreen(): Promise<void>;\n\n /**\n * Listen for fold state changes. On a foldable this also fires when the\n * device rotates, because `hingeOrientation` and `hingeBounds` rotate with\n * the window.\n *\n * @since 7.0.0\n */\n addListener(eventName: 'foldStateChange', listenerFunc: (state: FoldState) => void): Promise<PluginListenerHandle>;\n\n /**\n * Listen for hinge angle changes. On Android the hinge sensor only runs while\n * at least one of these listeners is registered. On iOS it fires on iPhone\n * Duo (iOS 27.1 or later). Never fires on web.\n *\n * @since 7.0.0\n */\n addListener(\n eventName: 'hingeAngleChange',\n listenerFunc: (event: { angle: number }) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listen for size class changes, such as unfolding the device, rotating it or\n * resizing the window. On iOS this fires when UIKit's size classes change\n * (iOS 17 or later) or the device rotates, so a resize that keeps the same\n * size classes may not update `widthClass` and `heightClass` until then.\n *\n * @since 7.0.0\n */\n addListener(\n eventName: 'sizeClassChange',\n listenerFunc: (sizeClass: SizeClass) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listen for changes to the display modes, including a mode ending because\n * the user folded or unfolded the device. Never fires on iOS and web.\n *\n * @since 7.0.0\n */\n addListener(\n eventName: 'displayModeChange',\n listenerFunc: (modes: DisplayModes) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listen for bar placement changes, such as opening or rotating iPhone Duo.\n * Only fires on iOS 27.1 or later.\n *\n * @since 7.0.0\n */\n addListener(\n eventName: 'barPlacementChange',\n listenerFunc: (placement: BarPlacement) => void,\n ): Promise<PluginListenerHandle>;\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import type { FoldablePlugin } from './definitions';
2
+ declare const Foldable: FoldablePlugin;
3
+ declare const installFoldablePolyfill: () => Promise<void>;
4
+ export * from './definitions';
5
+ export { Foldable, installFoldablePolyfill };
@@ -0,0 +1,9 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ import { install } from './polyfill';
3
+ const Foldable = registerPlugin('Foldable', {
4
+ web: () => import('./web').then((m) => new m.FoldableWeb()),
5
+ });
6
+ const installFoldablePolyfill = () => install(Foldable);
7
+ export * from './definitions';
8
+ export { Foldable, installFoldablePolyfill };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,QAAQ,GAAG,cAAc,CAAiB,UAAU,EAAE;IAC1D,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;CAC5D,CAAC,CAAC;AAEH,MAAM,uBAAuB,GAAG,GAAkB,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvE,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { FoldablePlugin } from './definitions';\nimport { install } from './polyfill';\n\nconst Foldable = registerPlugin<FoldablePlugin>('Foldable', {\n web: () => import('./web').then((m) => new m.FoldableWeb()),\n});\n\nconst installFoldablePolyfill = (): Promise<void> => install(Foldable);\n\nexport * from './definitions';\nexport { Foldable, installFoldablePolyfill };\n"]}
@@ -0,0 +1,19 @@
1
+ import type { FoldablePlugin } from './definitions';
2
+ type DevicePostureType = 'continuous' | 'folded';
3
+ declare global {
4
+ interface DevicePosture extends EventTarget {
5
+ readonly type: DevicePostureType;
6
+ onchange: ((this: DevicePosture, event: Event) => unknown) | null;
7
+ }
8
+ interface Viewport {
9
+ readonly segments: readonly DOMRect[];
10
+ }
11
+ interface Navigator {
12
+ readonly devicePosture: DevicePosture;
13
+ }
14
+ interface Window {
15
+ readonly viewport: Viewport;
16
+ }
17
+ }
18
+ export declare function install(plugin: FoldablePlugin): Promise<void>;
19
+ export {};
@@ -0,0 +1,76 @@
1
+ import { Capacitor } from '@capacitor/core';
2
+ import { BAR_CLASSES, barClassFor, CSS_CLASSES, cssFor } from './css';
3
+ import { splitViewport } from './segments';
4
+ class DevicePosturePolyfill extends EventTarget {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.onchange = null;
8
+ this.current = 'continuous';
9
+ }
10
+ get type() {
11
+ return this.current;
12
+ }
13
+ update(type) {
14
+ var _a;
15
+ if (type === this.current)
16
+ return;
17
+ this.current = type;
18
+ const event = new Event('change');
19
+ (_a = this.onchange) === null || _a === void 0 ? void 0 : _a.call(this, event);
20
+ this.dispatchEvent(event);
21
+ }
22
+ }
23
+ const postureOf = (fold) => (fold === null || fold === void 0 ? void 0 : fold.state) === 'half-opened' ? 'folded' : 'continuous';
24
+ let installation = null;
25
+ export function install(plugin) {
26
+ if (!Capacitor.isNativePlatform())
27
+ return Promise.resolve();
28
+ installation !== null && installation !== void 0 ? installation : (installation = run(plugin));
29
+ return installation;
30
+ }
31
+ async function run(plugin) {
32
+ let fold = null;
33
+ const currentSegments = () => splitViewport(fold, window.innerWidth, window.innerHeight);
34
+ if (!('Viewport' in window)) {
35
+ Object.defineProperty(window, 'viewport', {
36
+ configurable: true,
37
+ value: {
38
+ get segments() {
39
+ return Object.freeze(currentSegments().map((rect) => new DOMRect(rect.x, rect.y, rect.width, rect.height)));
40
+ },
41
+ },
42
+ });
43
+ }
44
+ const posture = 'DevicePosture' in window ? null : new DevicePosturePolyfill();
45
+ if (posture) {
46
+ Object.defineProperty(navigator, 'devicePosture', { configurable: true, value: posture });
47
+ }
48
+ const root = document.documentElement;
49
+ let variables = [];
50
+ const applyCss = () => {
51
+ const css = cssFor(currentSegments(), postureOf(fold));
52
+ for (const name of variables)
53
+ root.style.removeProperty(name);
54
+ variables = Object.keys(css.variables);
55
+ for (const name of variables)
56
+ root.style.setProperty(name, css.variables[name]);
57
+ for (const name of CSS_CLASSES)
58
+ root.classList.toggle(name, css.classes.includes(name));
59
+ };
60
+ const apply = (next) => {
61
+ fold = next;
62
+ posture === null || posture === void 0 ? void 0 : posture.update(postureOf(next));
63
+ applyCss();
64
+ };
65
+ const applyBars = ({ verticalBarEdge }) => {
66
+ const active = barClassFor(verticalBarEdge);
67
+ for (const name of BAR_CLASSES)
68
+ root.classList.toggle(name, name === active);
69
+ };
70
+ window.addEventListener('resize', applyCss);
71
+ await plugin.addListener('foldStateChange', apply);
72
+ await plugin.addListener('barPlacementChange', applyBars);
73
+ apply(await plugin.getFoldState());
74
+ applyBars(await plugin.getBarPlacement());
75
+ }
76
+ //# sourceMappingURL=polyfill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polyfill.js","sourceRoot":"","sources":["../../src/polyfill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO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,CAAC,CAAC,CAAC;QAChF,KAAK,MAAM,IAAI,IAAI,WAAW;YAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1F,CAAC,CAAC;IAEF,MAAM,KAAK,GAAG,CAAC,IAAe,EAAE,EAAE;QAChC,IAAI,GAAG,IAAI,CAAC;QACZ,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QACjC,QAAQ,EAAE,CAAC;IACb,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,CAAC,EAAE,eAAe,EAAgB,EAAE,EAAE;QACtD,MAAM,MAAM,GAAG,WAAW,CAAC,eAAe,CAAC,CAAC;QAC5C,KAAK,MAAM,IAAI,IAAI,WAAW;YAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,CAAC;IAC/E,CAAC,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC5C,MAAM,MAAM,CAAC,WAAW,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;IACnD,MAAM,MAAM,CAAC,WAAW,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;IAC1D,KAAK,CAAC,MAAM,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;IACnC,SAAS,CAAC,MAAM,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["import { Capacitor } from '@capacitor/core';\n\nimport { BAR_CLASSES, barClassFor, CSS_CLASSES, cssFor } from './css';\nimport type { BarPlacement, FoldablePlugin, FoldState } from './definitions';\nimport { splitViewport } from './segments';\n\ntype DevicePostureType = 'continuous' | 'folded';\n\ndeclare global {\n interface DevicePosture extends EventTarget {\n readonly type: DevicePostureType;\n onchange: ((this: DevicePosture, event: Event) => unknown) | null;\n }\n\n interface Viewport {\n readonly segments: readonly DOMRect[];\n }\n\n interface Navigator {\n readonly devicePosture: DevicePosture;\n }\n\n interface Window {\n readonly viewport: Viewport;\n }\n}\n\nclass DevicePosturePolyfill extends EventTarget implements DevicePosture {\n onchange: ((this: DevicePosture, event: Event) => unknown) | null = null;\n\n private current: DevicePostureType = 'continuous';\n\n get type(): DevicePostureType {\n return this.current;\n }\n\n update(type: DevicePostureType): void {\n if (type === this.current) return;\n\n this.current = type;\n const event = new Event('change');\n this.onchange?.call(this, event);\n this.dispatchEvent(event);\n }\n}\n\nconst postureOf = (fold: FoldState | null): DevicePostureType =>\n fold?.state === 'half-opened' ? 'folded' : 'continuous';\n\nlet installation: Promise<void> | null = null;\n\nexport function install(plugin: FoldablePlugin): Promise<void> {\n if (!Capacitor.isNativePlatform()) return Promise.resolve();\n\n installation ??= run(plugin);\n return installation;\n}\n\nasync function run(plugin: FoldablePlugin): Promise<void> {\n let fold: FoldState | null = null;\n const currentSegments = () => splitViewport(fold, window.innerWidth, window.innerHeight);\n\n if (!('Viewport' in window)) {\n Object.defineProperty(window, 'viewport', {\n configurable: true,\n value: {\n get segments() {\n return Object.freeze(currentSegments().map((rect) => new DOMRect(rect.x, rect.y, rect.width, rect.height)));\n },\n },\n });\n }\n\n const posture = 'DevicePosture' in window ? null : new DevicePosturePolyfill();\n if (posture) {\n Object.defineProperty(navigator, 'devicePosture', { configurable: true, value: posture });\n }\n\n const root = document.documentElement;\n let variables: string[] = [];\n\n const applyCss = () => {\n const css = cssFor(currentSegments(), postureOf(fold));\n for (const name of variables) root.style.removeProperty(name);\n variables = Object.keys(css.variables);\n for (const name of variables) root.style.setProperty(name, css.variables[name]);\n for (const name of CSS_CLASSES) root.classList.toggle(name, css.classes.includes(name));\n };\n\n const apply = (next: FoldState) => {\n fold = next;\n posture?.update(postureOf(next));\n applyCss();\n };\n\n const applyBars = ({ verticalBarEdge }: BarPlacement) => {\n const active = barClassFor(verticalBarEdge);\n for (const name of BAR_CLASSES) root.classList.toggle(name, name === active);\n };\n\n window.addEventListener('resize', applyCss);\n await plugin.addListener('foldStateChange', apply);\n await plugin.addListener('barPlacementChange', applyBars);\n apply(await plugin.getFoldState());\n applyBars(await plugin.getBarPlacement());\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { FoldState } from './definitions';
2
+ export interface SegmentRect {
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ }
8
+ export declare function splitViewport(fold: FoldState | null, width: number, height: number): SegmentRect[];
@@ -0,0 +1,26 @@
1
+ const EDGE_TOLERANCE = 1;
2
+ export function splitViewport(fold, width, height) {
3
+ const whole = [{ x: 0, y: 0, width, height }];
4
+ const hinge = fold === null || fold === void 0 ? void 0 : fold.hingeBounds;
5
+ if (!(fold === null || fold === void 0 ? void 0 : fold.isSeparating) || !hinge)
6
+ return whole;
7
+ if (fold.hingeOrientation === 'vertical') {
8
+ const right = hinge.x + hinge.width;
9
+ const spansHeight = hinge.y <= EDGE_TOLERANCE && hinge.y + hinge.height >= height - EDGE_TOLERANCE;
10
+ if (!spansHeight || hinge.x <= 0 || right >= width)
11
+ return whole;
12
+ return [
13
+ { x: 0, y: 0, width: hinge.x, height },
14
+ { x: right, y: 0, width: width - right, height },
15
+ ];
16
+ }
17
+ const bottom = hinge.y + hinge.height;
18
+ const spansWidth = hinge.x <= EDGE_TOLERANCE && hinge.x + hinge.width >= width - EDGE_TOLERANCE;
19
+ if (!spansWidth || hinge.y <= 0 || bottom >= height)
20
+ return whole;
21
+ return [
22
+ { x: 0, y: 0, width, height: hinge.y },
23
+ { x: 0, y: bottom, width, height: height - bottom },
24
+ ];
25
+ }
26
+ //# sourceMappingURL=segments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segments.js","sourceRoot":"","sources":["../../src/segments.ts"],"names":[],"mappings":"AASA,MAAM,cAAc,GAAG,CAAC,CAAC;AAEzB,MAAM,UAAU,aAAa,CAAC,IAAsB,E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AAM,IAAI,MAAM;QAAE,OAAO,KAAK,CAAC;IAElE,OAAO;QACL,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE;QACtC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;KACpD,CAAC;AACJ,CAAC","sourcesContent":["import type { FoldState } from './definitions';\n\nexport interface SegmentRect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nconst EDGE_TOLERANCE = 1;\n\nexport function splitViewport(fold: FoldState | null, width: number, height: number): SegmentRect[] {\n const whole = [{ x: 0, y: 0, width, height }];\n\n const hinge = fold?.hingeBounds;\n if (!fold?.isSeparating || !hinge) return whole;\n\n if (fold.hingeOrientation === 'vertical') {\n const right = hinge.x + hinge.width;\n const spansHeight = hinge.y <= EDGE_TOLERANCE && hinge.y + hinge.height >= height - EDGE_TOLERANCE;\n if (!spansHeight || hinge.x <= 0 || right >= width) return whole;\n\n return [\n { x: 0, y: 0, width: hinge.x, height },\n { x: right, y: 0, width: width - right, height },\n ];\n }\n\n const bottom = hinge.y + hinge.height;\n const spansWidth = hinge.x <= EDGE_TOLERANCE && hinge.x + hinge.width >= width - EDGE_TOLERANCE;\n if (!spansWidth || hinge.y <= 0 || bottom >= height) return whole;\n\n return [\n { x: 0, y: 0, width, height: hinge.y },\n { x: 0, y: bottom, width, height: height - bottom },\n ];\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import type { SizeClass } from './definitions';
2
+ export declare function sizeClassOf(width: number, height: number): SizeClass;
@@ -0,0 +1,33 @@
1
+ const MEDIUM_WIDTH = 600;
2
+ const EXPANDED_WIDTH = 840;
3
+ const LARGE_WIDTH = 1200;
4
+ const EXTRA_LARGE_WIDTH = 1600;
5
+ const MEDIUM_HEIGHT = 480;
6
+ const EXPANDED_HEIGHT = 900;
7
+ function widthClassOf(width) {
8
+ if (width >= EXTRA_LARGE_WIDTH)
9
+ return 'extraLarge';
10
+ if (width >= LARGE_WIDTH)
11
+ return 'large';
12
+ if (width >= EXPANDED_WIDTH)
13
+ return 'expanded';
14
+ if (width >= MEDIUM_WIDTH)
15
+ return 'medium';
16
+ return 'compact';
17
+ }
18
+ function heightClassOf(height) {
19
+ if (height >= EXPANDED_HEIGHT)
20
+ return 'expanded';
21
+ if (height >= MEDIUM_HEIGHT)
22
+ return 'medium';
23
+ return 'compact';
24
+ }
25
+ export function sizeClassOf(width, height) {
26
+ return {
27
+ horizontal: width >= MEDIUM_WIDTH ? 'regular' : 'compact',
28
+ vertical: height >= MEDIUM_HEIGHT ? 'regular' : 'compact',
29
+ widthClass: widthClassOf(width),
30
+ heightClass: heightClassOf(height),
31
+ };
32
+ }
33
+ //# sourceMappingURL=size-class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"size-class.js","sourceRoot":"","sources":["../../src/size-class.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,WAAW,GAAG,IAAI,CAAC;AACzB,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAC/B,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,SAAS,YAAY,CAAC,KAAa;IACjC,IAAI,KAAK,IAAI,iBAAiB;QAAE,OAAO,YAAY,CAAC;IACpD,IAAI,KAAK,IAAI,WAAW;QAAE,OAAO,OAAO,CAAC;IACzC,IAAI,KAAK,IAAI,cAAc;QAAE,OAAO,UAAU,CAAC;IAC/C,IAAI,KAAK,IAAI,YAAY;QAAE,OAAO,QAAQ,CAAC;IAC3C,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,aAAa,CAAC,MAAc;IACnC,IAAI,MAAM,IAAI,eAAe;QAAE,OAAO,UAAU,CAAC;IACjD,IAAI,MAAM,IAAI,aAAa;QAAE,OAAO,QAAQ,CAAC;IAC7C,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,MAAc;IACvD,OAAO;QACL,UAAU,EAAE,KAAK,IAAI,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QACzD,QAAQ,EAAE,MAAM,IAAI,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QACzD,UAAU,EAAE,YAAY,CAAC,KAAK,CAAC;QAC/B,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC;KACnC,CAAC;AACJ,CAAC","sourcesContent":["import type { SizeClass } from './definitions';\n\nconst MEDIUM_WIDTH = 600;\nconst EXPANDED_WIDTH = 840;\nconst LARGE_WIDTH = 1200;\nconst EXTRA_LARGE_WIDTH = 1600;\nconst MEDIUM_HEIGHT = 480;\nconst EXPANDED_HEIGHT = 900;\n\nfunction widthClassOf(width: number): SizeClass['widthClass'] {\n if (width >= EXTRA_LARGE_WIDTH) return 'extraLarge';\n if (width >= LARGE_WIDTH) return 'large';\n if (width >= EXPANDED_WIDTH) return 'expanded';\n if (width >= MEDIUM_WIDTH) return 'medium';\n return 'compact';\n}\n\nfunction heightClassOf(height: number): SizeClass['heightClass'] {\n if (height >= EXPANDED_HEIGHT) return 'expanded';\n if (height >= MEDIUM_HEIGHT) return 'medium';\n return 'compact';\n}\n\nexport function sizeClassOf(width: number, height: number): SizeClass {\n return {\n horizontal: width >= MEDIUM_WIDTH ? 'regular' : 'compact',\n vertical: height >= MEDIUM_HEIGHT ? 'regular' : 'compact',\n widthClass: widthClassOf(width),\n heightClass: heightClassOf(height),\n };\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { BarPlacement, DisplayModes, FoldablePlugin, FoldState, SizeClass } from './definitions';
3
+ export declare class FoldableWeb extends WebPlugin implements FoldablePlugin {
4
+ private sizeClass;
5
+ constructor();
6
+ isDeviceFoldable(): Promise<{
7
+ foldable: boolean;
8
+ supportsTabletop: boolean;
9
+ }>;
10
+ getFoldState(): Promise<FoldState>;
11
+ getHingeAngle(): Promise<{
12
+ angle: number | null;
13
+ }>;
14
+ getSizeClass(): Promise<SizeClass>;
15
+ getDisplayModes(): Promise<DisplayModes>;
16
+ getBarPlacement(): Promise<BarPlacement>;
17
+ startRearDisplay(): Promise<void>;
18
+ stopRearDisplay(): Promise<void>;
19
+ startDualScreen(): Promise<void>;
20
+ stopDualScreen(): Promise<void>;
21
+ }
@@ -0,0 +1,46 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import { sizeClassOf } from './size-class';
3
+ export class FoldableWeb extends WebPlugin {
4
+ constructor() {
5
+ super();
6
+ this.sizeClass = sizeClassOf(window.innerWidth, window.innerHeight);
7
+ window.addEventListener('resize', () => {
8
+ const next = sizeClassOf(window.innerWidth, window.innerHeight);
9
+ if (JSON.stringify(next) === JSON.stringify(this.sizeClass))
10
+ return;
11
+ this.sizeClass = next;
12
+ this.notifyListeners('sizeClassChange', next);
13
+ });
14
+ }
15
+ async isDeviceFoldable() {
16
+ return { foldable: false, supportsTabletop: false };
17
+ }
18
+ async getFoldState() {
19
+ return { state: 'flat', isSeparating: false, posture: 'flat' };
20
+ }
21
+ async getHingeAngle() {
22
+ return { angle: null };
23
+ }
24
+ async getSizeClass() {
25
+ return sizeClassOf(window.innerWidth, window.innerHeight);
26
+ }
27
+ async getDisplayModes() {
28
+ return { rearDisplay: 'unsupported', dualScreen: 'unsupported' };
29
+ }
30
+ async getBarPlacement() {
31
+ return { verticalBarEdge: null };
32
+ }
33
+ async startRearDisplay() {
34
+ throw this.unavailable('Rear display mode is only available on Android.');
35
+ }
36
+ stopRearDisplay() {
37
+ return Promise.resolve();
38
+ }
39
+ async startDualScreen() {
40
+ throw this.unavailable('Dual-screen mode is only available on Android.');
41
+ }
42
+ stopDualScreen() {
43
+ return Promise.resolve();
44
+ }
45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;QACnB,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,IAAI,CAAC,WAAW,CAAC,iDAAiD,CAAC,CAAC;IAC5E,CAAC;IAED,eAAe;QACb,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,IAAI,CAAC,WAAW,CAAC,gDAAgD,CAAC,CAAC;IAC3E,CAAC;IAED,cAAc;QACZ,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { BarPlacement, DisplayModes, FoldablePlugin, FoldState, SizeClass } from './definitions';\nimport { sizeClassOf } from './size-class';\n\nexport class FoldableWeb extends WebPlugin implements FoldablePlugin {\n private sizeClass = sizeClassOf(window.innerWidth, window.innerHeight);\n\n constructor() {\n super();\n window.addEventListener('resize', () => {\n const next = sizeClassOf(window.innerWidth, window.innerHeight);\n if (JSON.stringify(next) === JSON.stringify(this.sizeClass)) return;\n\n this.sizeClass = next;\n this.notifyListeners('sizeClassChange', next);\n });\n }\n\n async isDeviceFoldable(): Promise<{ foldable: boolean; supportsTabletop: boolean }> {\n return { foldable: false, supportsTabletop: false };\n }\n\n async getFoldState(): Promise<FoldState> {\n return { state: 'flat', isSeparating: false, posture: 'flat' };\n }\n\n async getHingeAngle(): Promise<{ angle: number | null }> {\n return { angle: null };\n }\n\n async getSizeClass(): Promise<SizeClass> {\n return sizeClassOf(window.innerWidth, window.innerHeight);\n }\n\n async getDisplayModes(): Promise<DisplayModes> {\n return { rearDisplay: 'unsupported', dualScreen: 'unsupported' };\n }\n\n async getBarPlacement(): Promise<BarPlacement> {\n return { verticalBarEdge: null };\n }\n\n async startRearDisplay(): Promise<void> {\n throw this.unavailable('Rear display mode is only available on Android.');\n }\n\n stopRearDisplay(): Promise<void> {\n return Promise.resolve();\n }\n\n async startDualScreen(): Promise<void> {\n throw this.unavailable('Dual-screen mode is only available on Android.');\n }\n\n stopDualScreen(): Promise<void> {\n return Promise.resolve();\n }\n}\n"]}