@capgo/capacitor-screen-orientation 8.1.21 → 8.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +347 -9
- package/android/build.gradle +2 -0
- package/android/src/main/java/ee/forgr/capacitor/screenorientation/CapacitorScreenOrientationPlugin.java +211 -1
- package/android/src/main/java/ee/forgr/capacitor/screenorientation/FoldLayout.java +176 -0
- package/dist/docs.json +809 -37
- package/dist/esm/definitions.d.ts +375 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +15 -1
- package/dist/esm/web.js +52 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +54 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +54 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapacitorScreenOrientationPlugin/CapacitorScreenOrientationPlugin.swift +128 -1
- package/ios/Sources/CapacitorScreenOrientationPlugin/IPhoneDuoFold.swift +258 -0
- package/package.json +1 -1
|
@@ -107,6 +107,258 @@ export interface StartOrientationTrackingOptions {
|
|
|
107
107
|
*/
|
|
108
108
|
bypassOrientationLock?: boolean;
|
|
109
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* How open a foldable is.
|
|
112
|
+
*
|
|
113
|
+
* `closed` is reserved. A device shut onto its cover display reports `flat`.
|
|
114
|
+
*
|
|
115
|
+
* @since 8.2.0
|
|
116
|
+
*/
|
|
117
|
+
export type FoldStateValue = 'flat' | 'half-opened';
|
|
118
|
+
/**
|
|
119
|
+
* How a half-open foldable is held.
|
|
120
|
+
*
|
|
121
|
+
* `tabletop` is a horizontal hinge, like a laptop. `book` is a vertical hinge.
|
|
122
|
+
*
|
|
123
|
+
* @since 8.2.0
|
|
124
|
+
*/
|
|
125
|
+
export type FoldPosture = 'flat' | 'tabletop' | 'book';
|
|
126
|
+
/**
|
|
127
|
+
* Direction of the hinge relative to the window.
|
|
128
|
+
*
|
|
129
|
+
* @since 8.2.0
|
|
130
|
+
*/
|
|
131
|
+
export type HingeOrientation = 'horizontal' | 'vertical';
|
|
132
|
+
/**
|
|
133
|
+
* A rectangle in CSS pixels, relative to the web view.
|
|
134
|
+
*
|
|
135
|
+
* @since 8.2.0
|
|
136
|
+
*/
|
|
137
|
+
export interface FoldBounds {
|
|
138
|
+
x: number;
|
|
139
|
+
y: number;
|
|
140
|
+
width: number;
|
|
141
|
+
height: number;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Current fold of the window.
|
|
145
|
+
*
|
|
146
|
+
* Phones that do not fold, and iOS before 27.1, resolve to a flat state.
|
|
147
|
+
* iPhone Duo reports `book`, `tabletop`, or `flat`, and which display is in front.
|
|
148
|
+
*
|
|
149
|
+
* @since 8.2.0
|
|
150
|
+
*/
|
|
151
|
+
export interface FoldState {
|
|
152
|
+
/**
|
|
153
|
+
* Posture of the fold.
|
|
154
|
+
*
|
|
155
|
+
* @since 8.2.0
|
|
156
|
+
*/
|
|
157
|
+
state: FoldStateValue;
|
|
158
|
+
/**
|
|
159
|
+
* Whether the fold splits the web view into two areas.
|
|
160
|
+
*
|
|
161
|
+
* @since 8.2.0
|
|
162
|
+
*/
|
|
163
|
+
isSeparating: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* How the device is held.
|
|
166
|
+
*
|
|
167
|
+
* @since 8.2.0
|
|
168
|
+
*/
|
|
169
|
+
posture: FoldPosture;
|
|
170
|
+
/**
|
|
171
|
+
* Direction of the hinge. Omitted when there is no fold.
|
|
172
|
+
*
|
|
173
|
+
* @since 8.2.0
|
|
174
|
+
*/
|
|
175
|
+
hingeOrientation?: HingeOrientation;
|
|
176
|
+
/**
|
|
177
|
+
* Position of the fold in CSS pixels. Omitted when there is no fold.
|
|
178
|
+
*
|
|
179
|
+
* @since 8.2.0
|
|
180
|
+
*/
|
|
181
|
+
hingeBounds?: FoldBounds;
|
|
182
|
+
/**
|
|
183
|
+
* Area the hinge covers. Present when the hinge has a physical gap.
|
|
184
|
+
*
|
|
185
|
+
* @since 8.2.0
|
|
186
|
+
*/
|
|
187
|
+
occludedBounds?: FoldBounds;
|
|
188
|
+
/**
|
|
189
|
+
* Which display is showing the app on iPhone Duo. Omitted on Android, web, and iOS before 27.1.
|
|
190
|
+
*
|
|
191
|
+
* @since 8.2.0
|
|
192
|
+
*/
|
|
193
|
+
activeDisplay?: 'inner' | 'outer';
|
|
194
|
+
/**
|
|
195
|
+
* Space the system keeps clear around the fold, in CSS pixels. iPhone Duo reports 20 on each side of a vertical fold.
|
|
196
|
+
*
|
|
197
|
+
* @since 8.2.0
|
|
198
|
+
*/
|
|
199
|
+
hingeMargins?: {
|
|
200
|
+
top: number;
|
|
201
|
+
right: number;
|
|
202
|
+
bottom: number;
|
|
203
|
+
left: number;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Areas covering the display, such as the iPhone Duo camera. Omitted when there are none.
|
|
207
|
+
*
|
|
208
|
+
* @since 8.2.0
|
|
209
|
+
*/
|
|
210
|
+
cameraBounds?: FoldBounds[];
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Whether this device can fold.
|
|
214
|
+
*
|
|
215
|
+
* @since 8.2.0
|
|
216
|
+
*/
|
|
217
|
+
export interface DeviceFoldableResult {
|
|
218
|
+
/**
|
|
219
|
+
* Whether the device has a fold.
|
|
220
|
+
*
|
|
221
|
+
* @since 8.2.0
|
|
222
|
+
*/
|
|
223
|
+
foldable: boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Whether it can stand half-open like a laptop.
|
|
226
|
+
*
|
|
227
|
+
* @since 8.2.0
|
|
228
|
+
*/
|
|
229
|
+
supportsTabletop: boolean;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Angle between the two halves of a foldable, in degrees.
|
|
233
|
+
*
|
|
234
|
+
* `0` is closed and `180` is flat. `angle` is `null` when the device has no hinge sensor.
|
|
235
|
+
*
|
|
236
|
+
* @since 8.2.0
|
|
237
|
+
*/
|
|
238
|
+
export interface HingeAngleResult {
|
|
239
|
+
/**
|
|
240
|
+
* Hinge angle in degrees, or `null` when no sensor is available.
|
|
241
|
+
*
|
|
242
|
+
* @since 8.2.0
|
|
243
|
+
*/
|
|
244
|
+
angle: number | null;
|
|
245
|
+
/**
|
|
246
|
+
* How far open iPhone Duo is, as the system sees it. `null` on Android and web.
|
|
247
|
+
*
|
|
248
|
+
* @since 8.2.0
|
|
249
|
+
*/
|
|
250
|
+
status?: 'closed' | 'partiallyOpen' | 'fullyOpen' | null;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* A region the system reserves on iPhone Duo.
|
|
254
|
+
*
|
|
255
|
+
* `division` is the fold. `occlusion` is something covering the display, such as the camera.
|
|
256
|
+
*
|
|
257
|
+
* @since 8.2.0
|
|
258
|
+
*/
|
|
259
|
+
export interface ReservedRegion {
|
|
260
|
+
/**
|
|
261
|
+
* What the region is.
|
|
262
|
+
*
|
|
263
|
+
* @since 8.2.0
|
|
264
|
+
*/
|
|
265
|
+
kind: 'division' | 'occlusion';
|
|
266
|
+
/**
|
|
267
|
+
* Whether the region applies right now. An inactive division is a flat fold.
|
|
268
|
+
*
|
|
269
|
+
* @since 8.2.0
|
|
270
|
+
*/
|
|
271
|
+
isActive: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* Left edge, in CSS pixels.
|
|
274
|
+
*
|
|
275
|
+
* @since 8.2.0
|
|
276
|
+
*/
|
|
277
|
+
x: number;
|
|
278
|
+
/**
|
|
279
|
+
* Top edge, in CSS pixels.
|
|
280
|
+
*
|
|
281
|
+
* @since 8.2.0
|
|
282
|
+
*/
|
|
283
|
+
y: number;
|
|
284
|
+
/**
|
|
285
|
+
* Width in CSS pixels.
|
|
286
|
+
*
|
|
287
|
+
* @since 8.2.0
|
|
288
|
+
*/
|
|
289
|
+
width: number;
|
|
290
|
+
/**
|
|
291
|
+
* Height in CSS pixels.
|
|
292
|
+
*
|
|
293
|
+
* @since 8.2.0
|
|
294
|
+
*/
|
|
295
|
+
height: number;
|
|
296
|
+
/**
|
|
297
|
+
* Space to keep clear around the region, in CSS pixels.
|
|
298
|
+
*
|
|
299
|
+
* @since 8.2.0
|
|
300
|
+
*/
|
|
301
|
+
margins: {
|
|
302
|
+
top: number;
|
|
303
|
+
right: number;
|
|
304
|
+
bottom: number;
|
|
305
|
+
left: number;
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Where iPhone Duo places native bars.
|
|
310
|
+
*
|
|
311
|
+
* @since 8.2.0
|
|
312
|
+
*/
|
|
313
|
+
export interface BarPlacement {
|
|
314
|
+
/**
|
|
315
|
+
* The edge the system moves tab bars and toolbars to. `null` when they stay horizontal.
|
|
316
|
+
*
|
|
317
|
+
* @since 8.2.0
|
|
318
|
+
*/
|
|
319
|
+
verticalBarEdge: 'leading' | 'trailing' | null;
|
|
320
|
+
/**
|
|
321
|
+
* How much room the vertical bar takes, in points. `0` when bars stay horizontal.
|
|
322
|
+
*
|
|
323
|
+
* @since 8.2.0
|
|
324
|
+
*/
|
|
325
|
+
inset: number;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Window size classes.
|
|
329
|
+
*
|
|
330
|
+
* `horizontal` and `vertical` follow Apple's compact/regular split.
|
|
331
|
+
* On Android and web, `regular` starts at 600 CSS pixels wide and 480 tall.
|
|
332
|
+
* `widthClass` and `heightClass` follow Material window size classes.
|
|
333
|
+
*
|
|
334
|
+
* @since 8.2.0
|
|
335
|
+
*/
|
|
336
|
+
export interface SizeClass {
|
|
337
|
+
/**
|
|
338
|
+
* Width size class. `compact` on a phone, `regular` on the inner display of a foldable, a tablet, or a window at least 600 CSS pixels wide.
|
|
339
|
+
*
|
|
340
|
+
* @since 8.2.0
|
|
341
|
+
*/
|
|
342
|
+
horizontal: 'compact' | 'regular';
|
|
343
|
+
/**
|
|
344
|
+
* Height size class. `regular` starts at 480 CSS pixels.
|
|
345
|
+
*
|
|
346
|
+
* @since 8.2.0
|
|
347
|
+
*/
|
|
348
|
+
vertical: 'compact' | 'regular';
|
|
349
|
+
/**
|
|
350
|
+
* Material window width class.
|
|
351
|
+
*
|
|
352
|
+
* @since 8.2.0
|
|
353
|
+
*/
|
|
354
|
+
widthClass: 'compact' | 'medium' | 'expanded' | 'large' | 'extraLarge';
|
|
355
|
+
/**
|
|
356
|
+
* Material window height class.
|
|
357
|
+
*
|
|
358
|
+
* @since 8.2.0
|
|
359
|
+
*/
|
|
360
|
+
heightClass: 'compact' | 'medium' | 'expanded';
|
|
361
|
+
}
|
|
110
362
|
/**
|
|
111
363
|
* Capacitor Screen Orientation Plugin interface.
|
|
112
364
|
*
|
|
@@ -267,7 +519,130 @@ export interface CapacitorScreenOrientationPlugin {
|
|
|
267
519
|
* await listener.remove();
|
|
268
520
|
* ```
|
|
269
521
|
*/
|
|
522
|
+
/**
|
|
523
|
+
* Whether this device folds, and whether it can stand half-open like a laptop.
|
|
524
|
+
*
|
|
525
|
+
* Both flags are `false` on web, on Android phones that do not fold, and on iOS except iPhone Duo (iOS 27.1 or later).
|
|
526
|
+
*
|
|
527
|
+
* @since 8.2.0
|
|
528
|
+
* @returns {Promise<DeviceFoldableResult>} Fold capability of this device.
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```typescript
|
|
532
|
+
* const { foldable, supportsTabletop } = await ScreenOrientation.isDeviceFoldable();
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
isDeviceFoldable(): Promise<DeviceFoldableResult>;
|
|
536
|
+
/**
|
|
537
|
+
* Read the current fold.
|
|
538
|
+
*
|
|
539
|
+
* Resolves to a flat state when the device has no fold.
|
|
540
|
+
*
|
|
541
|
+
* @since 8.2.0
|
|
542
|
+
* @returns {Promise<FoldState>} The current fold state.
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* ```typescript
|
|
546
|
+
* const { posture, hingeOrientation } = await ScreenOrientation.getFoldState();
|
|
547
|
+
* ```
|
|
548
|
+
*/
|
|
549
|
+
getFoldState(): Promise<FoldState>;
|
|
550
|
+
/**
|
|
551
|
+
* Read the hinge angle in degrees.
|
|
552
|
+
*
|
|
553
|
+
* `0` is closed and `180` is flat. `angle` is `null` without a hinge sensor.
|
|
554
|
+
*
|
|
555
|
+
* @since 8.2.0
|
|
556
|
+
* @returns {Promise<HingeAngleResult>} The latest hinge angle.
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```typescript
|
|
560
|
+
* const { angle } = await ScreenOrientation.getHingeAngle();
|
|
561
|
+
* ```
|
|
562
|
+
*/
|
|
563
|
+
getHingeAngle(): Promise<HingeAngleResult>;
|
|
564
|
+
/**
|
|
565
|
+
* Read the fold and anything covering the screen.
|
|
566
|
+
*
|
|
567
|
+
* iPhone Duo reports the fold, the vertical status bar area, and the under-display camera.
|
|
568
|
+
* Resolves to an empty list on Android, web, and iOS before 27.1.
|
|
569
|
+
*
|
|
570
|
+
* @since 8.2.0
|
|
571
|
+
* @returns {Promise<{ regions: ReservedRegion[] }>} The reserved regions.
|
|
572
|
+
*/
|
|
573
|
+
getReservedRegions(): Promise<{
|
|
574
|
+
regions: ReservedRegion[];
|
|
575
|
+
}>;
|
|
576
|
+
/**
|
|
577
|
+
* Read where iPhone Duo puts native tab bars and toolbars.
|
|
578
|
+
*
|
|
579
|
+
* `verticalBarEdge` is `null` when bars stay horizontal, and always on Android and web.
|
|
580
|
+
*
|
|
581
|
+
* @since 8.2.0
|
|
582
|
+
* @returns {Promise<BarPlacement>} The current bar placement.
|
|
583
|
+
*/
|
|
584
|
+
getBarPlacement(): Promise<BarPlacement>;
|
|
585
|
+
/**
|
|
586
|
+
* Choose whether iPhone Duo may move this app's bars to the side.
|
|
587
|
+
*
|
|
588
|
+
* Resolves to `{ applied: false }` unless the app's bridge view controller opts in.
|
|
589
|
+
* Android and web always resolve to `{ applied: false }`.
|
|
590
|
+
*
|
|
591
|
+
* @since 8.2.0
|
|
592
|
+
* @param options `automatic` lets the system move bars. `disabled` keeps them horizontal.
|
|
593
|
+
* @returns {Promise<{ applied: boolean }>} Whether the app applied the choice.
|
|
594
|
+
*/
|
|
595
|
+
setVerticalBarBehavior(options: {
|
|
596
|
+
behavior: 'automatic' | 'disabled';
|
|
597
|
+
}): Promise<{
|
|
598
|
+
applied: boolean;
|
|
599
|
+
}>;
|
|
600
|
+
/**
|
|
601
|
+
* Read the window size classes.
|
|
602
|
+
*
|
|
603
|
+
* @since 8.2.0
|
|
604
|
+
* @returns {Promise<SizeClass>} Apple and Material size classes for the current window.
|
|
605
|
+
*
|
|
606
|
+
* @example
|
|
607
|
+
* ```typescript
|
|
608
|
+
* const { horizontal, widthClass } = await ScreenOrientation.getSizeClass();
|
|
609
|
+
* ```
|
|
610
|
+
*/
|
|
611
|
+
getSizeClass(): Promise<SizeClass>;
|
|
270
612
|
addListener(eventName: 'screenOrientationChange', listenerFunc: (result: ScreenOrientationResult) => void): Promise<PluginListenerHandle>;
|
|
613
|
+
/**
|
|
614
|
+
* Listen for fold changes.
|
|
615
|
+
*
|
|
616
|
+
* On a foldable this also fires when the device rotates, because the hinge
|
|
617
|
+
* bounds rotate with the window.
|
|
618
|
+
*
|
|
619
|
+
* @since 8.2.0
|
|
620
|
+
* @param eventName The event name. Must be 'foldStateChange'.
|
|
621
|
+
* @param listenerFunc Callback invoked with the new fold state.
|
|
622
|
+
* @returns {Promise<PluginListenerHandle>} A promise that resolves to a listener handle.
|
|
623
|
+
*/
|
|
624
|
+
addListener(eventName: 'foldStateChange', listenerFunc: (state: FoldState) => void): Promise<PluginListenerHandle>;
|
|
625
|
+
/**
|
|
626
|
+
* Listen for hinge angle changes.
|
|
627
|
+
*
|
|
628
|
+
* On Android the hinge sensor runs only while at least one listener is registered.
|
|
629
|
+
* On iOS this fires on iPhone Duo (iOS 27.1 or later). Never fires on web.
|
|
630
|
+
*
|
|
631
|
+
* @since 8.2.0
|
|
632
|
+
* @param eventName The event name. Must be 'hingeAngleChange'.
|
|
633
|
+
* @param listenerFunc Callback invoked with the angle in degrees.
|
|
634
|
+
* @returns {Promise<PluginListenerHandle>} A promise that resolves to a listener handle.
|
|
635
|
+
*/
|
|
636
|
+
addListener(eventName: 'hingeAngleChange', listenerFunc: (event: HingeAngleResult) => void): Promise<PluginListenerHandle>;
|
|
637
|
+
/**
|
|
638
|
+
* Listen for size class changes, such as unfolding, rotating, or resizing.
|
|
639
|
+
*
|
|
640
|
+
* @since 8.2.0
|
|
641
|
+
* @param eventName The event name. Must be 'sizeClassChange'.
|
|
642
|
+
* @param listenerFunc Callback invoked with the new size class.
|
|
643
|
+
* @returns {Promise<PluginListenerHandle>} A promise that resolves to a listener handle.
|
|
644
|
+
*/
|
|
645
|
+
addListener(eventName: 'sizeClassChange', listenerFunc: (sizeClass: SizeClass) => void): Promise<PluginListenerHandle>;
|
|
271
646
|
/**
|
|
272
647
|
* Remove all listeners for this plugin.
|
|
273
648
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * Orientation type that describes the orientation state of the device.\n *\n * @since 1.0.0\n */\nexport type OrientationType = 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';\n\n/**\n * Orientation lock type that can be used to lock the device orientation.\n *\n * @since 1.0.0\n */\nexport type OrientationLockType =\n | 'any'\n | 'natural'\n | 'landscape'\n | 'portrait'\n | 'portrait-primary'\n | 'portrait-secondary'\n | 'landscape-primary'\n | 'landscape-secondary';\n\n/**\n * Result returned by the orientation() method.\n *\n * @since 1.0.0\n */\nexport interface ScreenOrientationResult {\n /**\n * The current orientation type.\n *\n * @since 1.0.0\n */\n type: OrientationType;\n}\n\n/**\n * Result returned by the isOrientationLocked() method.\n *\n * @since 1.0.0\n */\nexport interface OrientationLockStatusResult {\n /**\n * Whether the device orientation lock is currently enabled.\n *\n * This is determined by comparing the physical device orientation\n * (from motion sensors) with the UI orientation. If they differ,\n * orientation lock is enabled.\n *\n * Available on iOS (Core Motion) and Android (Accelerometer) when motion tracking is active.\n *\n * @since 1.0.0\n */\n locked: boolean;\n\n /**\n * The physical orientation of the device from motion sensors.\n * Available when motion tracking is active (iOS and Android).\n *\n * @since 1.0.0\n */\n physicalOrientation?: OrientationType;\n\n /**\n * The current UI orientation reported by the system.\n *\n * @since 1.0.0\n */\n uiOrientation: OrientationType;\n}\n\n/**\n * Options for locking the screen orientation.\n *\n * @since 1.0.0\n */\nexport interface OrientationLockOptions {\n /**\n * The orientation type to lock to.\n *\n * @since 1.0.0\n */\n orientation: OrientationLockType;\n\n /**\n * Whether to track physical device orientation using motion sensors.\n * When true, uses device motion sensors to detect the true physical\n * orientation of the device, even when the device orientation lock is enabled.\n *\n * **Important:** This does NOT bypass the UI orientation lock.\n * The screen will still respect the user's orientation lock setting.\n * This option only affects orientation detection/tracking - you'll receive\n * orientation change events based on how the device is physically held,\n * but the UI will not rotate if orientation lock is enabled.\n *\n * Supported on iOS (Core Motion) and Android (Accelerometer).\n *\n * @default false\n * @since 1.0.0\n */\n bypassOrientationLock?: boolean;\n}\n\n/**\n * Options for starting orientation tracking using motion sensors.\n *\n * @since 1.0.0\n */\nexport interface StartOrientationTrackingOptions {\n /**\n * Whether to track physical device orientation using motion sensors.\n * When true, uses device motion sensors to detect the true physical\n * orientation of the device, even when the device orientation lock is enabled.\n *\n * **Important:** This does NOT bypass the UI orientation lock.\n * This only enables detection of the physical orientation.\n *\n * Supported on iOS (Core Motion) and Android (Accelerometer).\n *\n * @default false\n * @since 1.0.0\n */\n bypassOrientationLock?: boolean;\n}\n\n/**\n * Capacitor Screen Orientation Plugin interface.\n *\n * Provides methods to detect and control screen orientation,\n * with support for detecting true physical device orientation using motion sensors.\n *\n * @since 1.0.0\n */\nexport interface CapacitorScreenOrientationPlugin {\n /**\n * Get the current screen orientation.\n *\n * Returns the current orientation of the device screen.\n *\n * @since 1.0.0\n * @returns {Promise<ScreenOrientationResult>} A promise that resolves with the current orientation.\n *\n * @example\n * ```typescript\n * const result = await ScreenOrientation.orientation();\n * console.log('Current orientation:', result.type);\n * ```\n */\n orientation(): Promise<ScreenOrientationResult>;\n\n /**\n * Lock the screen orientation to a specific type.\n *\n * Locks the screen to the specified orientation.\n * On iOS, if bypassOrientationLock is true, it will also start\n * tracking physical device orientation using motion sensors.\n *\n * Note: The UI will still respect the user's orientation lock setting.\n * Motion tracking allows you to detect how the device is physically held\n * even when the UI doesn't rotate.\n *\n * @since 1.0.0\n * @param options Options for locking the orientation.\n * @returns {Promise<void>} A promise that resolves when the orientation is locked.\n *\n * @example\n * ```typescript\n * // Standard lock\n * await ScreenOrientation.lock({ orientation: 'landscape' });\n *\n * // Lock with motion tracking on iOS\n * await ScreenOrientation.lock({\n * orientation: 'portrait',\n * bypassOrientationLock: true\n * });\n * ```\n */\n lock(options: OrientationLockOptions): Promise<void>;\n\n /**\n * Unlock the screen orientation.\n *\n * Allows the screen to rotate freely based on device position.\n * Also stops any motion-based orientation tracking if it was enabled.\n *\n * @since 1.0.0\n * @returns {Promise<void>} A promise that resolves when the orientation is unlocked.\n *\n * @example\n * ```typescript\n * await ScreenOrientation.unlock();\n * ```\n */\n unlock(): Promise<void>;\n\n /**\n * Start tracking device orientation using motion sensors.\n *\n * This method is useful when you want to track the device's physical\n * orientation independently from the screen orientation lock.\n * It uses Core Motion on iOS to detect orientation changes.\n *\n * @since 1.0.0\n * @param options Options for starting orientation tracking.\n * @returns {Promise<void>} A promise that resolves when tracking starts.\n *\n * @example\n * ```typescript\n * await ScreenOrientation.startOrientationTracking({\n * bypassOrientationLock: true\n * });\n *\n * // Listen for changes\n * ScreenOrientation.addListener('screenOrientationChange', (result) => {\n * console.log('Orientation changed:', result.type);\n * });\n * ```\n */\n startOrientationTracking(options?: StartOrientationTrackingOptions): Promise<void>;\n\n /**\n * Stop tracking device orientation using motion sensors.\n *\n * Stops the motion-based orientation tracking if it was started.\n *\n * @since 1.0.0\n * @returns {Promise<void>} A promise that resolves when tracking stops.\n *\n * @example\n * ```typescript\n * await ScreenOrientation.stopOrientationTracking();\n * ```\n */\n stopOrientationTracking(): Promise<void>;\n\n /**\n * Check if device orientation lock is currently enabled.\n *\n * This method compares the physical device orientation (from motion sensors)\n * with the UI orientation. If they differ, orientation lock is enabled.\n *\n * Note: This requires motion tracking to be active via\n * startOrientationTracking() or lock() with bypassOrientationLock: true.\n * Works on both iOS (Core Motion) and Android (Accelerometer).\n *\n * @since 1.0.0\n * @returns {Promise<OrientationLockStatusResult>} A promise that resolves with the lock status.\n *\n * @example\n * ```typescript\n * // Start motion tracking first\n * await ScreenOrientation.startOrientationTracking({\n * bypassOrientationLock: true\n * });\n *\n * // Check lock status\n * const status = await ScreenOrientation.isOrientationLocked();\n * if (status.locked) {\n * console.log('Orientation lock is ON');\n * console.log('Physical:', status.physicalOrientation);\n * console.log('UI:', status.uiOrientation);\n * }\n * ```\n */\n isOrientationLocked(): Promise<OrientationLockStatusResult>;\n\n /**\n * Listen for screen orientation changes.\n *\n * Registers a listener that will be called whenever the screen orientation changes.\n * If motion-based tracking is enabled, this will also fire for orientation changes\n * detected by motion sensors even when orientation lock is enabled.\n *\n * @since 1.0.0\n * @param eventName The event name. Must be 'screenOrientationChange'.\n * @param listenerFunc Callback function invoked when orientation changes.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves to a listener handle.\n *\n * @example\n * ```typescript\n * const listener = await ScreenOrientation.addListener(\n * 'screenOrientationChange',\n * (result) => {\n * console.log('New orientation:', result.type);\n * }\n * );\n *\n * // To remove the listener:\n * await listener.remove();\n * ```\n */\n addListener(\n eventName: 'screenOrientationChange',\n listenerFunc: (result: ScreenOrientationResult) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Remove all listeners for this plugin.\n *\n * Removes all registered event listeners.\n *\n * @since 1.0.0\n * @returns {Promise<void>} A promise that resolves when all listeners are removed.\n *\n * @example\n * ```typescript\n * await ScreenOrientation.removeAllListeners();\n * ```\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Get the native plugin version.\n *\n * Returns the current version of the native plugin implementation.\n *\n * @since 1.0.0\n * @returns {Promise<{ version: string }>} A promise that resolves with the version string.\n *\n * @example\n * ```typescript\n * const { version } = await ScreenOrientation.getPluginVersion();\n * console.log('Plugin version:', version);\n * ```\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * Orientation type that describes the orientation state of the device.\n *\n * @since 1.0.0\n */\nexport type OrientationType = 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';\n\n/**\n * Orientation lock type that can be used to lock the device orientation.\n *\n * @since 1.0.0\n */\nexport type OrientationLockType =\n | 'any'\n | 'natural'\n | 'landscape'\n | 'portrait'\n | 'portrait-primary'\n | 'portrait-secondary'\n | 'landscape-primary'\n | 'landscape-secondary';\n\n/**\n * Result returned by the orientation() method.\n *\n * @since 1.0.0\n */\nexport interface ScreenOrientationResult {\n /**\n * The current orientation type.\n *\n * @since 1.0.0\n */\n type: OrientationType;\n}\n\n/**\n * Result returned by the isOrientationLocked() method.\n *\n * @since 1.0.0\n */\nexport interface OrientationLockStatusResult {\n /**\n * Whether the device orientation lock is currently enabled.\n *\n * This is determined by comparing the physical device orientation\n * (from motion sensors) with the UI orientation. If they differ,\n * orientation lock is enabled.\n *\n * Available on iOS (Core Motion) and Android (Accelerometer) when motion tracking is active.\n *\n * @since 1.0.0\n */\n locked: boolean;\n\n /**\n * The physical orientation of the device from motion sensors.\n * Available when motion tracking is active (iOS and Android).\n *\n * @since 1.0.0\n */\n physicalOrientation?: OrientationType;\n\n /**\n * The current UI orientation reported by the system.\n *\n * @since 1.0.0\n */\n uiOrientation: OrientationType;\n}\n\n/**\n * Options for locking the screen orientation.\n *\n * @since 1.0.0\n */\nexport interface OrientationLockOptions {\n /**\n * The orientation type to lock to.\n *\n * @since 1.0.0\n */\n orientation: OrientationLockType;\n\n /**\n * Whether to track physical device orientation using motion sensors.\n * When true, uses device motion sensors to detect the true physical\n * orientation of the device, even when the device orientation lock is enabled.\n *\n * **Important:** This does NOT bypass the UI orientation lock.\n * The screen will still respect the user's orientation lock setting.\n * This option only affects orientation detection/tracking - you'll receive\n * orientation change events based on how the device is physically held,\n * but the UI will not rotate if orientation lock is enabled.\n *\n * Supported on iOS (Core Motion) and Android (Accelerometer).\n *\n * @default false\n * @since 1.0.0\n */\n bypassOrientationLock?: boolean;\n}\n\n/**\n * Options for starting orientation tracking using motion sensors.\n *\n * @since 1.0.0\n */\nexport interface StartOrientationTrackingOptions {\n /**\n * Whether to track physical device orientation using motion sensors.\n * When true, uses device motion sensors to detect the true physical\n * orientation of the device, even when the device orientation lock is enabled.\n *\n * **Important:** This does NOT bypass the UI orientation lock.\n * This only enables detection of the physical orientation.\n *\n * Supported on iOS (Core Motion) and Android (Accelerometer).\n *\n * @default false\n * @since 1.0.0\n */\n bypassOrientationLock?: boolean;\n}\n\n/**\n * How open a foldable is.\n *\n * `closed` is reserved. A device shut onto its cover display reports `flat`.\n *\n * @since 8.2.0\n */\nexport type FoldStateValue = 'flat' | 'half-opened';\n\n/**\n * How a half-open foldable is held.\n *\n * `tabletop` is a horizontal hinge, like a laptop. `book` is a vertical hinge.\n *\n * @since 8.2.0\n */\nexport type FoldPosture = 'flat' | 'tabletop' | 'book';\n\n/**\n * Direction of the hinge relative to the window.\n *\n * @since 8.2.0\n */\nexport type HingeOrientation = 'horizontal' | 'vertical';\n\n/**\n * A rectangle in CSS pixels, relative to the web view.\n *\n * @since 8.2.0\n */\nexport interface FoldBounds {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * Current fold of the window.\n *\n * Phones that do not fold, and iOS before 27.1, resolve to a flat state.\n * iPhone Duo reports `book`, `tabletop`, or `flat`, and which display is in front.\n *\n * @since 8.2.0\n */\nexport interface FoldState {\n /**\n * Posture of the fold.\n *\n * @since 8.2.0\n */\n state: FoldStateValue;\n\n /**\n * Whether the fold splits the web view into two areas.\n *\n * @since 8.2.0\n */\n isSeparating: boolean;\n\n /**\n * How the device is held.\n *\n * @since 8.2.0\n */\n posture: FoldPosture;\n\n /**\n * Direction of the hinge. Omitted when there is no fold.\n *\n * @since 8.2.0\n */\n hingeOrientation?: HingeOrientation;\n\n /**\n * Position of the fold in CSS pixels. Omitted when there is no fold.\n *\n * @since 8.2.0\n */\n hingeBounds?: FoldBounds;\n\n /**\n * Area the hinge covers. Present when the hinge has a physical gap.\n *\n * @since 8.2.0\n */\n occludedBounds?: FoldBounds;\n\n /**\n * Which display is showing the app on iPhone Duo. Omitted on Android, web, and iOS before 27.1.\n *\n * @since 8.2.0\n */\n activeDisplay?: 'inner' | 'outer';\n\n /**\n * Space the system keeps clear around the fold, in CSS pixels. iPhone Duo reports 20 on each side of a vertical fold.\n *\n * @since 8.2.0\n */\n hingeMargins?: { top: number; right: number; bottom: number; left: number };\n\n /**\n * Areas covering the display, such as the iPhone Duo camera. Omitted when there are none.\n *\n * @since 8.2.0\n */\n cameraBounds?: FoldBounds[];\n}\n\n/**\n * Whether this device can fold.\n *\n * @since 8.2.0\n */\nexport interface DeviceFoldableResult {\n /**\n * Whether the device has a fold.\n *\n * @since 8.2.0\n */\n foldable: boolean;\n\n /**\n * Whether it can stand half-open like a laptop.\n *\n * @since 8.2.0\n */\n supportsTabletop: boolean;\n}\n\n/**\n * Angle between the two halves of a foldable, in degrees.\n *\n * `0` is closed and `180` is flat. `angle` is `null` when the device has no hinge sensor.\n *\n * @since 8.2.0\n */\nexport interface HingeAngleResult {\n /**\n * Hinge angle in degrees, or `null` when no sensor is available.\n *\n * @since 8.2.0\n */\n angle: number | null;\n\n /**\n * How far open iPhone Duo is, as the system sees it. `null` on Android and web.\n *\n * @since 8.2.0\n */\n status?: 'closed' | 'partiallyOpen' | 'fullyOpen' | null;\n}\n\n/**\n * A region the system reserves on iPhone Duo.\n *\n * `division` is the fold. `occlusion` is something covering the display, such as the camera.\n *\n * @since 8.2.0\n */\nexport interface ReservedRegion {\n /**\n * What the region is.\n *\n * @since 8.2.0\n */\n kind: 'division' | 'occlusion';\n\n /**\n * Whether the region applies right now. An inactive division is a flat fold.\n *\n * @since 8.2.0\n */\n isActive: boolean;\n\n /**\n * Left edge, in CSS pixels.\n *\n * @since 8.2.0\n */\n x: number;\n\n /**\n * Top edge, in CSS pixels.\n *\n * @since 8.2.0\n */\n y: number;\n\n /**\n * Width in CSS pixels.\n *\n * @since 8.2.0\n */\n width: number;\n\n /**\n * Height in CSS pixels.\n *\n * @since 8.2.0\n */\n height: number;\n\n /**\n * Space to keep clear around the region, in CSS pixels.\n *\n * @since 8.2.0\n */\n margins: { top: number; right: number; bottom: number; left: number };\n}\n\n/**\n * Where iPhone Duo places native bars.\n *\n * @since 8.2.0\n */\nexport interface BarPlacement {\n /**\n * The edge the system moves tab bars and toolbars to. `null` when they stay horizontal.\n *\n * @since 8.2.0\n */\n verticalBarEdge: 'leading' | 'trailing' | null;\n\n /**\n * How much room the vertical bar takes, in points. `0` when bars stay horizontal.\n *\n * @since 8.2.0\n */\n inset: number;\n}\n\n/**\n * Window size classes.\n *\n * `horizontal` and `vertical` follow Apple's compact/regular split.\n * On Android and web, `regular` starts at 600 CSS pixels wide and 480 tall.\n * `widthClass` and `heightClass` follow Material window size classes.\n *\n * @since 8.2.0\n */\nexport interface SizeClass {\n /**\n * Width size class. `compact` on a phone, `regular` on the inner display of a foldable, a tablet, or a window at least 600 CSS pixels wide.\n *\n * @since 8.2.0\n */\n horizontal: 'compact' | 'regular';\n\n /**\n * Height size class. `regular` starts at 480 CSS pixels.\n *\n * @since 8.2.0\n */\n vertical: 'compact' | 'regular';\n\n /**\n * Material window width class.\n *\n * @since 8.2.0\n */\n widthClass: 'compact' | 'medium' | 'expanded' | 'large' | 'extraLarge';\n\n /**\n * Material window height class.\n *\n * @since 8.2.0\n */\n heightClass: 'compact' | 'medium' | 'expanded';\n}\n\n/**\n * Capacitor Screen Orientation Plugin interface.\n *\n * Provides methods to detect and control screen orientation,\n * with support for detecting true physical device orientation using motion sensors.\n *\n * @since 1.0.0\n */\nexport interface CapacitorScreenOrientationPlugin {\n /**\n * Get the current screen orientation.\n *\n * Returns the current orientation of the device screen.\n *\n * @since 1.0.0\n * @returns {Promise<ScreenOrientationResult>} A promise that resolves with the current orientation.\n *\n * @example\n * ```typescript\n * const result = await ScreenOrientation.orientation();\n * console.log('Current orientation:', result.type);\n * ```\n */\n orientation(): Promise<ScreenOrientationResult>;\n\n /**\n * Lock the screen orientation to a specific type.\n *\n * Locks the screen to the specified orientation.\n * On iOS, if bypassOrientationLock is true, it will also start\n * tracking physical device orientation using motion sensors.\n *\n * Note: The UI will still respect the user's orientation lock setting.\n * Motion tracking allows you to detect how the device is physically held\n * even when the UI doesn't rotate.\n *\n * @since 1.0.0\n * @param options Options for locking the orientation.\n * @returns {Promise<void>} A promise that resolves when the orientation is locked.\n *\n * @example\n * ```typescript\n * // Standard lock\n * await ScreenOrientation.lock({ orientation: 'landscape' });\n *\n * // Lock with motion tracking on iOS\n * await ScreenOrientation.lock({\n * orientation: 'portrait',\n * bypassOrientationLock: true\n * });\n * ```\n */\n lock(options: OrientationLockOptions): Promise<void>;\n\n /**\n * Unlock the screen orientation.\n *\n * Allows the screen to rotate freely based on device position.\n * Also stops any motion-based orientation tracking if it was enabled.\n *\n * @since 1.0.0\n * @returns {Promise<void>} A promise that resolves when the orientation is unlocked.\n *\n * @example\n * ```typescript\n * await ScreenOrientation.unlock();\n * ```\n */\n unlock(): Promise<void>;\n\n /**\n * Start tracking device orientation using motion sensors.\n *\n * This method is useful when you want to track the device's physical\n * orientation independently from the screen orientation lock.\n * It uses Core Motion on iOS to detect orientation changes.\n *\n * @since 1.0.0\n * @param options Options for starting orientation tracking.\n * @returns {Promise<void>} A promise that resolves when tracking starts.\n *\n * @example\n * ```typescript\n * await ScreenOrientation.startOrientationTracking({\n * bypassOrientationLock: true\n * });\n *\n * // Listen for changes\n * ScreenOrientation.addListener('screenOrientationChange', (result) => {\n * console.log('Orientation changed:', result.type);\n * });\n * ```\n */\n startOrientationTracking(options?: StartOrientationTrackingOptions): Promise<void>;\n\n /**\n * Stop tracking device orientation using motion sensors.\n *\n * Stops the motion-based orientation tracking if it was started.\n *\n * @since 1.0.0\n * @returns {Promise<void>} A promise that resolves when tracking stops.\n *\n * @example\n * ```typescript\n * await ScreenOrientation.stopOrientationTracking();\n * ```\n */\n stopOrientationTracking(): Promise<void>;\n\n /**\n * Check if device orientation lock is currently enabled.\n *\n * This method compares the physical device orientation (from motion sensors)\n * with the UI orientation. If they differ, orientation lock is enabled.\n *\n * Note: This requires motion tracking to be active via\n * startOrientationTracking() or lock() with bypassOrientationLock: true.\n * Works on both iOS (Core Motion) and Android (Accelerometer).\n *\n * @since 1.0.0\n * @returns {Promise<OrientationLockStatusResult>} A promise that resolves with the lock status.\n *\n * @example\n * ```typescript\n * // Start motion tracking first\n * await ScreenOrientation.startOrientationTracking({\n * bypassOrientationLock: true\n * });\n *\n * // Check lock status\n * const status = await ScreenOrientation.isOrientationLocked();\n * if (status.locked) {\n * console.log('Orientation lock is ON');\n * console.log('Physical:', status.physicalOrientation);\n * console.log('UI:', status.uiOrientation);\n * }\n * ```\n */\n isOrientationLocked(): Promise<OrientationLockStatusResult>;\n\n /**\n * Listen for screen orientation changes.\n *\n * Registers a listener that will be called whenever the screen orientation changes.\n * If motion-based tracking is enabled, this will also fire for orientation changes\n * detected by motion sensors even when orientation lock is enabled.\n *\n * @since 1.0.0\n * @param eventName The event name. Must be 'screenOrientationChange'.\n * @param listenerFunc Callback function invoked when orientation changes.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves to a listener handle.\n *\n * @example\n * ```typescript\n * const listener = await ScreenOrientation.addListener(\n * 'screenOrientationChange',\n * (result) => {\n * console.log('New orientation:', result.type);\n * }\n * );\n *\n * // To remove the listener:\n * await listener.remove();\n * ```\n */\n /**\n * Whether this device folds, and whether it can stand half-open like a laptop.\n *\n * Both flags are `false` on web, on Android phones that do not fold, and on iOS except iPhone Duo (iOS 27.1 or later).\n *\n * @since 8.2.0\n * @returns {Promise<DeviceFoldableResult>} Fold capability of this device.\n *\n * @example\n * ```typescript\n * const { foldable, supportsTabletop } = await ScreenOrientation.isDeviceFoldable();\n * ```\n */\n isDeviceFoldable(): Promise<DeviceFoldableResult>;\n\n /**\n * Read the current fold.\n *\n * Resolves to a flat state when the device has no fold.\n *\n * @since 8.2.0\n * @returns {Promise<FoldState>} The current fold state.\n *\n * @example\n * ```typescript\n * const { posture, hingeOrientation } = await ScreenOrientation.getFoldState();\n * ```\n */\n getFoldState(): Promise<FoldState>;\n\n /**\n * Read the hinge angle in degrees.\n *\n * `0` is closed and `180` is flat. `angle` is `null` without a hinge sensor.\n *\n * @since 8.2.0\n * @returns {Promise<HingeAngleResult>} The latest hinge angle.\n *\n * @example\n * ```typescript\n * const { angle } = await ScreenOrientation.getHingeAngle();\n * ```\n */\n getHingeAngle(): Promise<HingeAngleResult>;\n\n /**\n * Read the fold and anything covering the screen.\n *\n * iPhone Duo reports the fold, the vertical status bar area, and the under-display camera.\n * Resolves to an empty list on Android, web, and iOS before 27.1.\n *\n * @since 8.2.0\n * @returns {Promise<{ regions: ReservedRegion[] }>} The reserved regions.\n */\n getReservedRegions(): Promise<{ regions: ReservedRegion[] }>;\n\n /**\n * Read where iPhone Duo puts native tab bars and toolbars.\n *\n * `verticalBarEdge` is `null` when bars stay horizontal, and always on Android and web.\n *\n * @since 8.2.0\n * @returns {Promise<BarPlacement>} The current bar placement.\n */\n getBarPlacement(): Promise<BarPlacement>;\n\n /**\n * Choose whether iPhone Duo may move this app's bars to the side.\n *\n * Resolves to `{ applied: false }` unless the app's bridge view controller opts in.\n * Android and web always resolve to `{ applied: false }`.\n *\n * @since 8.2.0\n * @param options `automatic` lets the system move bars. `disabled` keeps them horizontal.\n * @returns {Promise<{ applied: boolean }>} Whether the app applied the choice.\n */\n setVerticalBarBehavior(options: { behavior: 'automatic' | 'disabled' }): Promise<{ applied: boolean }>;\n\n /**\n * Read the window size classes.\n *\n * @since 8.2.0\n * @returns {Promise<SizeClass>} Apple and Material size classes for the current window.\n *\n * @example\n * ```typescript\n * const { horizontal, widthClass } = await ScreenOrientation.getSizeClass();\n * ```\n */\n getSizeClass(): Promise<SizeClass>;\n\n addListener(\n eventName: 'screenOrientationChange',\n listenerFunc: (result: ScreenOrientationResult) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listen for fold changes.\n *\n * On a foldable this also fires when the device rotates, because the hinge\n * bounds rotate with the window.\n *\n * @since 8.2.0\n * @param eventName The event name. Must be 'foldStateChange'.\n * @param listenerFunc Callback invoked with the new fold state.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves to a listener handle.\n */\n addListener(eventName: 'foldStateChange', listenerFunc: (state: FoldState) => void): Promise<PluginListenerHandle>;\n\n /**\n * Listen for hinge angle changes.\n *\n * On Android the hinge sensor runs only while at least one listener is registered.\n * On iOS this fires on iPhone Duo (iOS 27.1 or later). Never fires on web.\n *\n * @since 8.2.0\n * @param eventName The event name. Must be 'hingeAngleChange'.\n * @param listenerFunc Callback invoked with the angle in degrees.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves to a listener handle.\n */\n addListener(\n eventName: 'hingeAngleChange',\n listenerFunc: (event: HingeAngleResult) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Listen for size class changes, such as unfolding, rotating, or resizing.\n *\n * @since 8.2.0\n * @param eventName The event name. Must be 'sizeClassChange'.\n * @param listenerFunc Callback invoked with the new size class.\n * @returns {Promise<PluginListenerHandle>} A promise that resolves to a listener handle.\n */\n addListener(\n eventName: 'sizeClassChange',\n listenerFunc: (sizeClass: SizeClass) => void,\n ): Promise<PluginListenerHandle>;\n\n /**\n * Remove all listeners for this plugin.\n *\n * Removes all registered event listeners.\n *\n * @since 1.0.0\n * @returns {Promise<void>} A promise that resolves when all listeners are removed.\n *\n * @example\n * ```typescript\n * await ScreenOrientation.removeAllListeners();\n * ```\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Get the native plugin version.\n *\n * Returns the current version of the native plugin implementation.\n *\n * @since 1.0.0\n * @returns {Promise<{ version: string }>} A promise that resolves with the version string.\n *\n * @example\n * ```typescript\n * const { version } = await ScreenOrientation.getPluginVersion();\n * console.log('Plugin version:', version);\n * ```\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type { CapacitorScreenOrientationPlugin, OrientationLockOptions, OrientationType, ScreenOrientationResult, StartOrientationTrackingOptions } from './definitions';
|
|
2
|
+
import type { BarPlacement, CapacitorScreenOrientationPlugin, DeviceFoldableResult, FoldState, HingeAngleResult, ReservedRegion, OrientationLockOptions, OrientationType, ScreenOrientationResult, SizeClass, StartOrientationTrackingOptions } from './definitions';
|
|
3
|
+
export declare function sizeClassOf(width: number, height: number): SizeClass;
|
|
3
4
|
export declare class CapacitorScreenOrientationWeb extends WebPlugin implements CapacitorScreenOrientationPlugin {
|
|
4
5
|
private readonly pluginVersion;
|
|
5
6
|
constructor();
|
|
7
|
+
private lastSizeClass;
|
|
6
8
|
orientation(): Promise<ScreenOrientationResult>;
|
|
7
9
|
lock(options: OrientationLockOptions): Promise<void>;
|
|
8
10
|
unlock(): Promise<void>;
|
|
@@ -13,8 +15,20 @@ export declare class CapacitorScreenOrientationWeb extends WebPlugin implements
|
|
|
13
15
|
physicalOrientation?: OrientationType;
|
|
14
16
|
uiOrientation: OrientationType;
|
|
15
17
|
}>;
|
|
18
|
+
isDeviceFoldable(): Promise<DeviceFoldableResult>;
|
|
19
|
+
getFoldState(): Promise<FoldState>;
|
|
20
|
+
getHingeAngle(): Promise<HingeAngleResult>;
|
|
21
|
+
getReservedRegions(): Promise<{
|
|
22
|
+
regions: ReservedRegion[];
|
|
23
|
+
}>;
|
|
24
|
+
getBarPlacement(): Promise<BarPlacement>;
|
|
25
|
+
setVerticalBarBehavior(): Promise<{
|
|
26
|
+
applied: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
getSizeClass(): Promise<SizeClass>;
|
|
16
29
|
getPluginVersion(): Promise<{
|
|
17
30
|
version: string;
|
|
18
31
|
}>;
|
|
32
|
+
private readSizeClass;
|
|
19
33
|
private mapOrientationType;
|
|
20
34
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
const FLAT_FOLD = { state: 'flat', isSeparating: false, posture: 'flat' };
|
|
3
|
+
export function sizeClassOf(width, height) {
|
|
4
|
+
const widthClass = width >= 1600
|
|
5
|
+
? 'extraLarge'
|
|
6
|
+
: width >= 1200
|
|
7
|
+
? 'large'
|
|
8
|
+
: width >= 840
|
|
9
|
+
? 'expanded'
|
|
10
|
+
: width >= 600
|
|
11
|
+
? 'medium'
|
|
12
|
+
: 'compact';
|
|
13
|
+
const heightClass = height >= 900 ? 'expanded' : height >= 480 ? 'medium' : 'compact';
|
|
14
|
+
return {
|
|
15
|
+
horizontal: width >= 600 ? 'regular' : 'compact',
|
|
16
|
+
vertical: height >= 480 ? 'regular' : 'compact',
|
|
17
|
+
widthClass,
|
|
18
|
+
heightClass,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
2
21
|
export class CapacitorScreenOrientationWeb extends WebPlugin {
|
|
3
22
|
constructor() {
|
|
4
23
|
var _a;
|
|
5
24
|
super();
|
|
6
25
|
this.pluginVersion = '1.0.0';
|
|
26
|
+
this.lastSizeClass = null;
|
|
7
27
|
if ((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation) {
|
|
8
28
|
window.screen.orientation.addEventListener('change', () => {
|
|
9
29
|
this.notifyListeners('screenOrientationChange', {
|
|
@@ -11,6 +31,14 @@ export class CapacitorScreenOrientationWeb extends WebPlugin {
|
|
|
11
31
|
});
|
|
12
32
|
});
|
|
13
33
|
}
|
|
34
|
+
window.addEventListener('resize', () => {
|
|
35
|
+
const next = this.readSizeClass();
|
|
36
|
+
const previous = JSON.stringify(this.lastSizeClass);
|
|
37
|
+
if (previous === JSON.stringify(next))
|
|
38
|
+
return;
|
|
39
|
+
this.lastSizeClass = next;
|
|
40
|
+
this.notifyListeners('sizeClassChange', next);
|
|
41
|
+
});
|
|
14
42
|
}
|
|
15
43
|
async orientation() {
|
|
16
44
|
var _a;
|
|
@@ -60,9 +88,33 @@ export class CapacitorScreenOrientationWeb extends WebPlugin {
|
|
|
60
88
|
uiOrientation: orientationResult.type,
|
|
61
89
|
};
|
|
62
90
|
}
|
|
91
|
+
async isDeviceFoldable() {
|
|
92
|
+
return { foldable: false, supportsTabletop: false };
|
|
93
|
+
}
|
|
94
|
+
async getFoldState() {
|
|
95
|
+
return FLAT_FOLD;
|
|
96
|
+
}
|
|
97
|
+
async getHingeAngle() {
|
|
98
|
+
return { angle: null, status: null };
|
|
99
|
+
}
|
|
100
|
+
async getReservedRegions() {
|
|
101
|
+
return { regions: [] };
|
|
102
|
+
}
|
|
103
|
+
async getBarPlacement() {
|
|
104
|
+
return { verticalBarEdge: null, inset: 0 };
|
|
105
|
+
}
|
|
106
|
+
async setVerticalBarBehavior() {
|
|
107
|
+
return { applied: false };
|
|
108
|
+
}
|
|
109
|
+
async getSizeClass() {
|
|
110
|
+
return this.readSizeClass();
|
|
111
|
+
}
|
|
63
112
|
async getPluginVersion() {
|
|
64
113
|
return { version: this.pluginVersion };
|
|
65
114
|
}
|
|
115
|
+
readSizeClass() {
|
|
116
|
+
return sizeClassOf(window.innerWidth, window.innerHeight);
|
|
117
|
+
}
|
|
66
118
|
mapOrientationType(type) {
|
|
67
119
|
if (type.includes('portrait-primary') || type === 'portrait-primary') {
|
|
68
120
|
return 'portrait-primary';
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAgB5C,MAAM,SAAS,GAAc,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAErF,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,MAAc;IACvD,MAAM,UAAU,GACd,KAAK,IAAI,IAAI;QACX,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,KAAK,IAAI,IAAI;YACb,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,KAAK,IAAI,GAAG;gBACZ,CAAC,CAAC,UAAU;gBACZ,CAAC,CAAC,KAAK,IAAI,GAAG;oBACZ,CAAC,CAAC,QAAQ;oBACV,CAAC,CAAC,SAAS,CAAC;IACtB,MAAM,WAAW,GAAG,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IACtF,OAAO;QACL,UAAU,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QAChD,QAAQ,EAAE,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QAC/C,UAAU;QACV,WAAW;KACZ,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,6BAA8B,SAAQ,SAAS;IAG1D;;QACE,KAAK,EAAE,CAAC;QAHO,kBAAa,GAAG,OAAO,CAAC;QAoBjC,kBAAa,GAAqB,IAAI,CAAC;QAhB7C,IAAI,MAAA,MAAM,CAAC,MAAM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} from '@capacitor/core';\n\nimport type {\n BarPlacement,\n CapacitorScreenOrientationPlugin,\n DeviceFoldableResult,\n FoldState,\n HingeAngleResult,\n ReservedRegion,\n OrientationLockOptions,\n OrientationType,\n ScreenOrientationResult,\n SizeClass,\n StartOrientationTrackingOptions,\n} from './definitions';\n\nconst FLAT_FOLD: FoldState = { state: 'flat', isSeparating: false, posture: 'flat' };\n\nexport function sizeClassOf(width: number, height: number): SizeClass {\n const widthClass =\n width >= 1600\n ? 'extraLarge'\n : width >= 1200\n ? 'large'\n : width >= 840\n ? 'expanded'\n : width >= 600\n ? 'medium'\n : 'compact';\n const heightClass = height >= 900 ? 'expanded' : height >= 480 ? 'medium' : 'compact';\n return {\n horizontal: width >= 600 ? 'regular' : 'compact',\n vertical: height >= 480 ? 'regular' : 'compact',\n widthClass,\n heightClass,\n };\n}\n\nexport class CapacitorScreenOrientationWeb extends WebPlugin implements CapacitorScreenOrientationPlugin {\n private readonly pluginVersion = '1.0.0';\n\n constructor() {\n super();\n if (window.screen?.orientation) {\n window.screen.orientation.addEventListener('change', () => {\n this.notifyListeners('screenOrientationChange', {\n type: this.mapOrientationType(window.screen.orientation.type),\n });\n });\n }\n window.addEventListener('resize', () => {\n const next = this.readSizeClass();\n const previous = JSON.stringify(this.lastSizeClass);\n if (previous === JSON.stringify(next)) return;\n this.lastSizeClass = next;\n this.notifyListeners('sizeClassChange', next);\n });\n }\n\n private lastSizeClass: SizeClass | null = null;\n\n async orientation(): Promise<ScreenOrientationResult> {\n if (!window.screen?.orientation) {\n throw this.unavailable('Screen Orientation API not available');\n }\n return {\n type: this.mapOrientationType(window.screen.orientation.type),\n };\n }\n\n async lock(options: OrientationLockOptions): Promise<void> {\n const screenOrientation = window.screen?.orientation as any;\n if (!screenOrientation?.lock) {\n throw this.unavailable('Screen Orientation lock not available');\n }\n\n // bypassOrientationLock is only supported on iOS native platform\n // Silently ignore it on web\n\n try {\n await screenOrientation.lock(options.orientation);\n } catch (error) {\n throw new Error(`Failed to lock orientation: ${error}`);\n }\n }\n\n async unlock(): Promise<void> {\n const screenOrientation = window.screen?.orientation as any;\n if (!screenOrientation?.unlock) {\n throw this.unavailable('Screen Orientation unlock not available');\n }\n screenOrientation.unlock();\n }\n\n async startOrientationTracking(_options?: StartOrientationTrackingOptions): Promise<void> {\n // Motion-based orientation tracking is only supported on iOS\n // Silently ignore on web\n console.warn('Motion-based orientation tracking is not available on web platform', _options);\n }\n\n async stopOrientationTracking(): Promise<void> {\n // Motion-based orientation tracking is only supported on iOS\n // Silently ignore on web\n }\n\n async isOrientationLocked(): Promise<{\n locked: boolean;\n physicalOrientation?: OrientationType;\n uiOrientation: OrientationType;\n }> {\n const orientationResult = await this.orientation();\n return {\n locked: false,\n uiOrientation: orientationResult.type,\n };\n }\n\n async isDeviceFoldable(): Promise<DeviceFoldableResult> {\n return { foldable: false, supportsTabletop: false };\n }\n\n async getFoldState(): Promise<FoldState> {\n return FLAT_FOLD;\n }\n\n async getHingeAngle(): Promise<HingeAngleResult> {\n return { angle: null, status: null };\n }\n\n async getReservedRegions(): Promise<{ regions: ReservedRegion[] }> {\n return { regions: [] };\n }\n\n async getBarPlacement(): Promise<BarPlacement> {\n return { verticalBarEdge: null, inset: 0 };\n }\n\n async setVerticalBarBehavior(): Promise<{ applied: boolean }> {\n return { applied: false };\n }\n\n async getSizeClass(): Promise<SizeClass> {\n return this.readSizeClass();\n }\n\n async getPluginVersion(): Promise<{ version: string }> {\n return { version: this.pluginVersion };\n }\n\n private readSizeClass(): SizeClass {\n return sizeClassOf(window.innerWidth, window.innerHeight);\n }\n\n private mapOrientationType(type: string): OrientationType {\n if (type.includes('portrait-primary') || type === 'portrait-primary') {\n return 'portrait-primary';\n }\n if (type.includes('portrait-secondary') || type === 'portrait-secondary') {\n return 'portrait-secondary';\n }\n if (type.includes('landscape-primary') || type === 'landscape-primary') {\n return 'landscape-primary';\n }\n if (type.includes('landscape-secondary') || type === 'landscape-secondary') {\n return 'landscape-secondary';\n }\n return 'portrait-primary'; // default fallback\n }\n}\n"]}
|