@capgo/capacitor-screen-orientation 8.1.20 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -107,6 +107,153 @@ 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, iOS, and web resolve to a flat state.
147
+ *
148
+ * @since 8.2.0
149
+ */
150
+ export interface FoldState {
151
+ /**
152
+ * Posture of the fold.
153
+ *
154
+ * @since 8.2.0
155
+ */
156
+ state: FoldStateValue;
157
+ /**
158
+ * Whether the fold splits the web view into two areas.
159
+ *
160
+ * @since 8.2.0
161
+ */
162
+ isSeparating: boolean;
163
+ /**
164
+ * How the device is held.
165
+ *
166
+ * @since 8.2.0
167
+ */
168
+ posture: FoldPosture;
169
+ /**
170
+ * Direction of the hinge. Omitted when there is no fold.
171
+ *
172
+ * @since 8.2.0
173
+ */
174
+ hingeOrientation?: HingeOrientation;
175
+ /**
176
+ * Position of the fold in CSS pixels. Omitted when there is no fold.
177
+ *
178
+ * @since 8.2.0
179
+ */
180
+ hingeBounds?: FoldBounds;
181
+ /**
182
+ * Area the hinge covers. Present when the hinge has a physical gap.
183
+ *
184
+ * @since 8.2.0
185
+ */
186
+ occludedBounds?: FoldBounds;
187
+ }
188
+ /**
189
+ * Whether this device can fold.
190
+ *
191
+ * @since 8.2.0
192
+ */
193
+ export interface DeviceFoldableResult {
194
+ /**
195
+ * Whether the device has a fold.
196
+ *
197
+ * @since 8.2.0
198
+ */
199
+ foldable: boolean;
200
+ /**
201
+ * Whether it can stand half-open like a laptop.
202
+ *
203
+ * @since 8.2.0
204
+ */
205
+ supportsTabletop: boolean;
206
+ }
207
+ /**
208
+ * Angle between the two halves of a foldable, in degrees.
209
+ *
210
+ * `0` is closed and `180` is flat. `angle` is `null` when the device has no hinge sensor.
211
+ *
212
+ * @since 8.2.0
213
+ */
214
+ export interface HingeAngleResult {
215
+ /**
216
+ * Hinge angle in degrees, or `null` when no sensor is available.
217
+ *
218
+ * @since 8.2.0
219
+ */
220
+ angle: number | null;
221
+ }
222
+ /**
223
+ * Window size classes.
224
+ *
225
+ * `horizontal` and `vertical` follow Apple's compact/regular split.
226
+ * On Android and web, `regular` starts at 600 CSS pixels wide and 480 tall.
227
+ * `widthClass` and `heightClass` follow Material window size classes.
228
+ *
229
+ * @since 8.2.0
230
+ */
231
+ export interface SizeClass {
232
+ /**
233
+ * 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.
234
+ *
235
+ * @since 8.2.0
236
+ */
237
+ horizontal: 'compact' | 'regular';
238
+ /**
239
+ * Height size class. `regular` starts at 480 CSS pixels.
240
+ *
241
+ * @since 8.2.0
242
+ */
243
+ vertical: 'compact' | 'regular';
244
+ /**
245
+ * Material window width class.
246
+ *
247
+ * @since 8.2.0
248
+ */
249
+ widthClass: 'compact' | 'medium' | 'expanded' | 'large' | 'extraLarge';
250
+ /**
251
+ * Material window height class.
252
+ *
253
+ * @since 8.2.0
254
+ */
255
+ heightClass: 'compact' | 'medium' | 'expanded';
256
+ }
110
257
  /**
111
258
  * Capacitor Screen Orientation Plugin interface.
112
259
  *
@@ -267,7 +414,94 @@ export interface CapacitorScreenOrientationPlugin {
267
414
  * await listener.remove();
268
415
  * ```
269
416
  */
417
+ /**
418
+ * Whether this device folds, and whether it can stand half-open like a laptop.
419
+ *
420
+ * Both flags are `false` on web and iOS.
421
+ *
422
+ * @since 8.2.0
423
+ * @returns {Promise<DeviceFoldableResult>} Fold capability of this device.
424
+ *
425
+ * @example
426
+ * ```typescript
427
+ * const { foldable, supportsTabletop } = await ScreenOrientation.isDeviceFoldable();
428
+ * ```
429
+ */
430
+ isDeviceFoldable(): Promise<DeviceFoldableResult>;
431
+ /**
432
+ * Read the current fold.
433
+ *
434
+ * Resolves to a flat state when the device has no fold.
435
+ *
436
+ * @since 8.2.0
437
+ * @returns {Promise<FoldState>} The current fold state.
438
+ *
439
+ * @example
440
+ * ```typescript
441
+ * const { posture, hingeOrientation } = await ScreenOrientation.getFoldState();
442
+ * ```
443
+ */
444
+ getFoldState(): Promise<FoldState>;
445
+ /**
446
+ * Read the hinge angle in degrees.
447
+ *
448
+ * `0` is closed and `180` is flat. `angle` is `null` without a hinge sensor.
449
+ *
450
+ * @since 8.2.0
451
+ * @returns {Promise<HingeAngleResult>} The latest hinge angle.
452
+ *
453
+ * @example
454
+ * ```typescript
455
+ * const { angle } = await ScreenOrientation.getHingeAngle();
456
+ * ```
457
+ */
458
+ getHingeAngle(): Promise<HingeAngleResult>;
459
+ /**
460
+ * Read the window size classes.
461
+ *
462
+ * @since 8.2.0
463
+ * @returns {Promise<SizeClass>} Apple and Material size classes for the current window.
464
+ *
465
+ * @example
466
+ * ```typescript
467
+ * const { horizontal, widthClass } = await ScreenOrientation.getSizeClass();
468
+ * ```
469
+ */
470
+ getSizeClass(): Promise<SizeClass>;
270
471
  addListener(eventName: 'screenOrientationChange', listenerFunc: (result: ScreenOrientationResult) => void): Promise<PluginListenerHandle>;
472
+ /**
473
+ * Listen for fold changes.
474
+ *
475
+ * On a foldable this also fires when the device rotates, because the hinge
476
+ * bounds rotate with the window.
477
+ *
478
+ * @since 8.2.0
479
+ * @param eventName The event name. Must be 'foldStateChange'.
480
+ * @param listenerFunc Callback invoked with the new fold state.
481
+ * @returns {Promise<PluginListenerHandle>} A promise that resolves to a listener handle.
482
+ */
483
+ addListener(eventName: 'foldStateChange', listenerFunc: (state: FoldState) => void): Promise<PluginListenerHandle>;
484
+ /**
485
+ * Listen for hinge angle changes.
486
+ *
487
+ * On Android the hinge sensor runs only while at least one listener is registered.
488
+ * Never fires on web or iOS.
489
+ *
490
+ * @since 8.2.0
491
+ * @param eventName The event name. Must be 'hingeAngleChange'.
492
+ * @param listenerFunc Callback invoked with the angle in degrees.
493
+ * @returns {Promise<PluginListenerHandle>} A promise that resolves to a listener handle.
494
+ */
495
+ addListener(eventName: 'hingeAngleChange', listenerFunc: (event: HingeAngleResult) => void): Promise<PluginListenerHandle>;
496
+ /**
497
+ * Listen for size class changes, such as unfolding, rotating, or resizing.
498
+ *
499
+ * @since 8.2.0
500
+ * @param eventName The event name. Must be 'sizeClassChange'.
501
+ * @param listenerFunc Callback invoked with the new size class.
502
+ * @returns {Promise<PluginListenerHandle>} A promise that resolves to a listener handle.
503
+ */
504
+ addListener(eventName: 'sizeClassChange', listenerFunc: (sizeClass: SizeClass) => void): Promise<PluginListenerHandle>;
271
505
  /**
272
506
  * Remove all listeners for this plugin.
273
507
  *
@@ -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, iOS, and web resolve to a flat state.\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/**\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/**\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 and iOS.\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 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 * Never fires on web or iOS.\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 { CapacitorScreenOrientationPlugin, DeviceFoldableResult, FoldState, HingeAngleResult, 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,13 @@ 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
+ getSizeClass(): Promise<SizeClass>;
16
22
  getPluginVersion(): Promise<{
17
23
  version: string;
18
24
  }>;
25
+ private readSizeClass;
19
26
  private mapOrientationType;
20
27
  }
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,24 @@ 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 };
99
+ }
100
+ async getSizeClass() {
101
+ return this.readSizeClass();
102
+ }
63
103
  async getPluginVersion() {
64
104
  return { version: this.pluginVersion };
65
105
  }
106
+ readSizeClass() {
107
+ return sizeClassOf(window.innerWidth, window.innerHeight);
108
+ }
66
109
  mapOrientationType(type) {
67
110
  if (type.includes('portrait-primary') || type === 'portrait-primary') {
68
111
  return 'portrait-primary';
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAU5C,MAAM,OAAO,6BAA8B,SAAQ,SAAS;IAG1D;;QACE,KAAK,EAAE,CAAC;QAHO,kBAAa,GAAG,OAAO,CAAC;QAIvC,IAAI,MAAA,MAAM,CAAC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AqB,CAAC;QAC/B,CAAC;QACD,OAAO,kBAAkB,CAAC,CAAC,mBAAmB;IAChD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CapacitorScreenOrientationPlugin,\n OrientationLockOptions,\n OrientationType,\n ScreenOrientationResult,\n StartOrientationTrackingOptions,\n} from './definitions';\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 }\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 getPluginVersion(): Promise<{ version: string }> {\n return { version: this.pluginVersion };\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"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAc5C,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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,CAAC,gBAAgB;QACpB,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,aAAa;QACjB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC;IACzC,CAAC;IAEO,aAAa;QACnB,OAAO,WAAW,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IAC5D,CAAC;IAEO,kBAAkB,CAAC,IAAY;QACrC,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,IAAI,KAAK,kBAAkB,EAAE,CAAC;YACrE,OAAO,kBAAkB,CAAC;QAC5B,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,IAAI,IAAI,KAAK,oBAAoB,EAAE,CAAC;YACzE,OAAO,oBAAoB,CAAC;QAC9B,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,IAAI,KAAK,mBAAmB,EAAE,CAAC;YACvE,OAAO,mBAAmB,CAAC;QAC7B,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,IAAI,IAAI,KAAK,qBAAqB,EAAE,CAAC;YAC3E,OAAO,qBAAqB,CAAC;QAC/B,CAAC;QACD,OAAO,kBAAkB,CAAC,CAAC,mBAAmB;IAChD,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CapacitorScreenOrientationPlugin,\n DeviceFoldableResult,\n FoldState,\n HingeAngleResult,\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 };\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"]}
@@ -6,11 +6,31 @@ const ScreenOrientation = core.registerPlugin('CapacitorScreenOrientation', {
6
6
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorScreenOrientationWeb()),
7
7
  });
8
8
 
9
+ const FLAT_FOLD = { state: 'flat', isSeparating: false, posture: 'flat' };
10
+ function sizeClassOf(width, height) {
11
+ const widthClass = width >= 1600
12
+ ? 'extraLarge'
13
+ : width >= 1200
14
+ ? 'large'
15
+ : width >= 840
16
+ ? 'expanded'
17
+ : width >= 600
18
+ ? 'medium'
19
+ : 'compact';
20
+ const heightClass = height >= 900 ? 'expanded' : height >= 480 ? 'medium' : 'compact';
21
+ return {
22
+ horizontal: width >= 600 ? 'regular' : 'compact',
23
+ vertical: height >= 480 ? 'regular' : 'compact',
24
+ widthClass,
25
+ heightClass,
26
+ };
27
+ }
9
28
  class CapacitorScreenOrientationWeb extends core.WebPlugin {
10
29
  constructor() {
11
30
  var _a;
12
31
  super();
13
32
  this.pluginVersion = '1.0.0';
33
+ this.lastSizeClass = null;
14
34
  if ((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation) {
15
35
  window.screen.orientation.addEventListener('change', () => {
16
36
  this.notifyListeners('screenOrientationChange', {
@@ -18,6 +38,14 @@ class CapacitorScreenOrientationWeb extends core.WebPlugin {
18
38
  });
19
39
  });
20
40
  }
41
+ window.addEventListener('resize', () => {
42
+ const next = this.readSizeClass();
43
+ const previous = JSON.stringify(this.lastSizeClass);
44
+ if (previous === JSON.stringify(next))
45
+ return;
46
+ this.lastSizeClass = next;
47
+ this.notifyListeners('sizeClassChange', next);
48
+ });
21
49
  }
22
50
  async orientation() {
23
51
  var _a;
@@ -67,9 +95,24 @@ class CapacitorScreenOrientationWeb extends core.WebPlugin {
67
95
  uiOrientation: orientationResult.type,
68
96
  };
69
97
  }
98
+ async isDeviceFoldable() {
99
+ return { foldable: false, supportsTabletop: false };
100
+ }
101
+ async getFoldState() {
102
+ return FLAT_FOLD;
103
+ }
104
+ async getHingeAngle() {
105
+ return { angle: null };
106
+ }
107
+ async getSizeClass() {
108
+ return this.readSizeClass();
109
+ }
70
110
  async getPluginVersion() {
71
111
  return { version: this.pluginVersion };
72
112
  }
113
+ readSizeClass() {
114
+ return sizeClassOf(window.innerWidth, window.innerHeight);
115
+ }
73
116
  mapOrientationType(type) {
74
117
  if (type.includes('portrait-primary') || type === 'portrait-primary') {
75
118
  return 'portrait-primary';
@@ -89,7 +132,8 @@ class CapacitorScreenOrientationWeb extends core.WebPlugin {
89
132
 
90
133
  var web = /*#__PURE__*/Object.freeze({
91
134
  __proto__: null,
92
- CapacitorScreenOrientationWeb: CapacitorScreenOrientationWeb
135
+ CapacitorScreenOrientationWeb: CapacitorScreenOrientationWeb,
136
+ sizeClassOf: sizeClassOf
93
137
  });
94
138
 
95
139
  exports.ScreenOrientation = ScreenOrientation;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst ScreenOrientation = registerPlugin('CapacitorScreenOrientation', {\n web: () => import('./web').then((m) => new m.CapacitorScreenOrientationWeb()),\n});\nexport * from './definitions';\nexport { ScreenOrientation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorScreenOrientationWeb extends WebPlugin {\n constructor() {\n var _a;\n super();\n this.pluginVersion = '1.0.0';\n if ((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation) {\n window.screen.orientation.addEventListener('change', () => {\n this.notifyListeners('screenOrientationChange', {\n type: this.mapOrientationType(window.screen.orientation.type),\n });\n });\n }\n }\n async orientation() {\n var _a;\n if (!((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation)) {\n throw this.unavailable('Screen Orientation API not available');\n }\n return {\n type: this.mapOrientationType(window.screen.orientation.type),\n };\n }\n async lock(options) {\n var _a;\n const screenOrientation = (_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation;\n if (!(screenOrientation === null || screenOrientation === void 0 ? void 0 : screenOrientation.lock)) {\n throw this.unavailable('Screen Orientation lock not available');\n }\n // bypassOrientationLock is only supported on iOS native platform\n // Silently ignore it on web\n try {\n await screenOrientation.lock(options.orientation);\n }\n catch (error) {\n throw new Error(`Failed to lock orientation: ${error}`);\n }\n }\n async unlock() {\n var _a;\n const screenOrientation = (_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation;\n if (!(screenOrientation === null || screenOrientation === void 0 ? void 0 : screenOrientation.unlock)) {\n throw this.unavailable('Screen Orientation unlock not available');\n }\n screenOrientation.unlock();\n }\n async startOrientationTracking(_options) {\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 async stopOrientationTracking() {\n // Motion-based orientation tracking is only supported on iOS\n // Silently ignore on web\n }\n async isOrientationLocked() {\n const orientationResult = await this.orientation();\n return {\n locked: false,\n uiOrientation: orientationResult.type,\n };\n }\n async getPluginVersion() {\n return { version: this.pluginVersion };\n }\n mapOrientationType(type) {\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//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,iBAAiB,GAAGA,mBAAc,CAAC,4BAA4B,EAAE;AACvE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,6BAA6B,EAAE,CAAC;AACjF,CAAC;;ACFM,MAAM,6BAA6B,SAASC,cAAS,CAAC;AAC7D,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,EAAE;AACd,QAAQ,KAAK,EAAE;AACf,QAAQ,IAAI,CAAC,aAAa,GAAG,OAAO;AACpC,QAAQ,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,WAAW,EAAE;AACtF,YAAY,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,QAAQ,EAA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CAAC,IAAI,IAAI,KAAK,oBAAoB,EAAE;AAClF,YAAY,OAAO,oBAAoB;AACvC,QAAQ;AACR,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,IAAI,KAAK,mBAAmB,EAAE;AAChF,YAAY,OAAO,mBAAmB;AACtC,QAAQ;AACR,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,IAAI,IAAI,KAAK,qBAAqB,EAAE;AACpF,YAAY,OAAO,qBAAqB;AACxC,QAAQ;AACR,QAAQ,OAAO,kBAAkB,CAAC;AAClC,IAAI;AACJ;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst ScreenOrientation = registerPlugin('CapacitorScreenOrientation', {\n web: () => import('./web').then((m) => new m.CapacitorScreenOrientationWeb()),\n});\nexport * from './definitions';\nexport { ScreenOrientation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nconst FLAT_FOLD = { state: 'flat', isSeparating: false, posture: 'flat' };\nexport function sizeClassOf(width, height) {\n const widthClass = 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}\nexport class CapacitorScreenOrientationWeb extends WebPlugin {\n constructor() {\n var _a;\n super();\n this.pluginVersion = '1.0.0';\n this.lastSizeClass = null;\n if ((_a = window.screen) === null || _a === void 0 ? void 0 : _a.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))\n return;\n this.lastSizeClass = next;\n this.notifyListeners('sizeClassChange', next);\n });\n }\n async orientation() {\n var _a;\n if (!((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation)) {\n throw this.unavailable('Screen Orientation API not available');\n }\n return {\n type: this.mapOrientationType(window.screen.orientation.type),\n };\n }\n async lock(options) {\n var _a;\n const screenOrientation = (_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation;\n if (!(screenOrientation === null || screenOrientation === void 0 ? void 0 : screenOrientation.lock)) {\n throw this.unavailable('Screen Orientation lock not available');\n }\n // bypassOrientationLock is only supported on iOS native platform\n // Silently ignore it on web\n try {\n await screenOrientation.lock(options.orientation);\n }\n catch (error) {\n throw new Error(`Failed to lock orientation: ${error}`);\n }\n }\n async unlock() {\n var _a;\n const screenOrientation = (_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation;\n if (!(screenOrientation === null || screenOrientation === void 0 ? void 0 : screenOrientation.unlock)) {\n throw this.unavailable('Screen Orientation unlock not available');\n }\n screenOrientation.unlock();\n }\n async startOrientationTracking(_options) {\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 async stopOrientationTracking() {\n // Motion-based orientation tracking is only supported on iOS\n // Silently ignore on web\n }\n async isOrientationLocked() {\n const orientationResult = await this.orientation();\n return {\n locked: false,\n uiOrientation: orientationResult.type,\n };\n }\n async isDeviceFoldable() {\n return { foldable: false, supportsTabletop: false };\n }\n async getFoldState() {\n return FLAT_FOLD;\n }\n async getHingeAngle() {\n return { angle: null };\n }\n async getSizeClass() {\n return this.readSizeClass();\n }\n async getPluginVersion() {\n return { version: this.pluginVersion };\n }\n readSizeClass() {\n return sizeClassOf(window.innerWidth, window.innerHeight);\n }\n mapOrientationType(type) {\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//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,iBAAiB,GAAGA,mBAAc,CAAC,4BAA4B,EAAE;AACvE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,6BAA6B,EAAE,CAAC;AACjF,CAAC;;ACFD,MAAM,SAAS,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE;AAClE,SAAS,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE;AAC3C,IAAI,MAAM,UAAU,GAAG,KAAK,IAAI;AAChC,UAAU;AACV,UAAU,KAAK,IAAI;AACnB,cAAc;AACd,cAAc,KAAK,IAAI;AACvB,kBAAkB;AAClB,kBAAkB,KAAK,IAAI;AAC3B,sBAAsB;AACtB,sBAAsB,SAAS;AAC/B,IAAI,MAAM,WAAW,GAAG,MAAM,IAAI,GAAG,GAAG,UAAU,GAAG,MAAM,IAAI,GAAG,GAAG,QAAQ,GAAG,SAAS;AACzF,IAAI,OAAO;AACX,QAAQ,UAAU,EAAE,KAAK,IAAI,GAAG,GAAG,SAAS,GAAG,SAAS;AACxD,QAAQ,QAAQ,EAAE,MAAM,IAAI,GAAG,GAAG,SAAS,GAAG,SAAS;AACvD,QAAQ,UAAU;AAClB,QAAQ,WAAW;AACnB,KAAK;AACL;AACO,MAAM,6BAA6B,SAASC,cAAS,CAAC;AAC7D,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,EAAE;AACd,QAAQ,KAAK,EAAE;AACf,QAAQ,IAAI,CAAC,aAAa,GAAG,OAAO;AACpC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,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,IAAI,KAAK,mBAAmB,EAAE;AAChF,YAAY,OAAO,mBAAmB;AACtC,QAAQ;AACR,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,IAAI,IAAI,KAAK,qBAAqB,EAAE;AACpF,YAAY,OAAO,qBAAqB;AACxC,QAAQ;AACR,QAAQ,OAAO,kBAAkB,CAAC;AAClC,IAAI;AACJ;;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -5,11 +5,31 @@ var capacitorScreenOrientation = (function (exports, core) {
5
5
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorScreenOrientationWeb()),
6
6
  });
7
7
 
8
+ const FLAT_FOLD = { state: 'flat', isSeparating: false, posture: 'flat' };
9
+ function sizeClassOf(width, height) {
10
+ const widthClass = width >= 1600
11
+ ? 'extraLarge'
12
+ : width >= 1200
13
+ ? 'large'
14
+ : width >= 840
15
+ ? 'expanded'
16
+ : width >= 600
17
+ ? 'medium'
18
+ : 'compact';
19
+ const heightClass = height >= 900 ? 'expanded' : height >= 480 ? 'medium' : 'compact';
20
+ return {
21
+ horizontal: width >= 600 ? 'regular' : 'compact',
22
+ vertical: height >= 480 ? 'regular' : 'compact',
23
+ widthClass,
24
+ heightClass,
25
+ };
26
+ }
8
27
  class CapacitorScreenOrientationWeb extends core.WebPlugin {
9
28
  constructor() {
10
29
  var _a;
11
30
  super();
12
31
  this.pluginVersion = '1.0.0';
32
+ this.lastSizeClass = null;
13
33
  if ((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation) {
14
34
  window.screen.orientation.addEventListener('change', () => {
15
35
  this.notifyListeners('screenOrientationChange', {
@@ -17,6 +37,14 @@ var capacitorScreenOrientation = (function (exports, core) {
17
37
  });
18
38
  });
19
39
  }
40
+ window.addEventListener('resize', () => {
41
+ const next = this.readSizeClass();
42
+ const previous = JSON.stringify(this.lastSizeClass);
43
+ if (previous === JSON.stringify(next))
44
+ return;
45
+ this.lastSizeClass = next;
46
+ this.notifyListeners('sizeClassChange', next);
47
+ });
20
48
  }
21
49
  async orientation() {
22
50
  var _a;
@@ -66,9 +94,24 @@ var capacitorScreenOrientation = (function (exports, core) {
66
94
  uiOrientation: orientationResult.type,
67
95
  };
68
96
  }
97
+ async isDeviceFoldable() {
98
+ return { foldable: false, supportsTabletop: false };
99
+ }
100
+ async getFoldState() {
101
+ return FLAT_FOLD;
102
+ }
103
+ async getHingeAngle() {
104
+ return { angle: null };
105
+ }
106
+ async getSizeClass() {
107
+ return this.readSizeClass();
108
+ }
69
109
  async getPluginVersion() {
70
110
  return { version: this.pluginVersion };
71
111
  }
112
+ readSizeClass() {
113
+ return sizeClassOf(window.innerWidth, window.innerHeight);
114
+ }
72
115
  mapOrientationType(type) {
73
116
  if (type.includes('portrait-primary') || type === 'portrait-primary') {
74
117
  return 'portrait-primary';
@@ -88,7 +131,8 @@ var capacitorScreenOrientation = (function (exports, core) {
88
131
 
89
132
  var web = /*#__PURE__*/Object.freeze({
90
133
  __proto__: null,
91
- CapacitorScreenOrientationWeb: CapacitorScreenOrientationWeb
134
+ CapacitorScreenOrientationWeb: CapacitorScreenOrientationWeb,
135
+ sizeClassOf: sizeClassOf
92
136
  });
93
137
 
94
138
  exports.ScreenOrientation = ScreenOrientation;