@capgo/capacitor-screen-orientation 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,302 @@
1
+ import type { PluginListenerHandle } from '@capacitor/core';
2
+ /**
3
+ * Orientation type that describes the orientation state of the device.
4
+ *
5
+ * @since 1.0.0
6
+ */
7
+ export type OrientationType = 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';
8
+ /**
9
+ * Orientation lock type that can be used to lock the device orientation.
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ export type OrientationLockType = 'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';
14
+ /**
15
+ * Result returned by the orientation() method.
16
+ *
17
+ * @since 1.0.0
18
+ */
19
+ export interface ScreenOrientationResult {
20
+ /**
21
+ * The current orientation type.
22
+ *
23
+ * @since 1.0.0
24
+ */
25
+ type: OrientationType;
26
+ }
27
+ /**
28
+ * Result returned by the isOrientationLocked() method.
29
+ *
30
+ * @since 1.0.0
31
+ */
32
+ export interface OrientationLockStatusResult {
33
+ /**
34
+ * Whether the device orientation lock is currently enabled.
35
+ *
36
+ * This is determined by comparing the physical device orientation
37
+ * (from motion sensors) with the UI orientation. If they differ,
38
+ * orientation lock is enabled.
39
+ *
40
+ * Available on iOS (Core Motion) and Android (Accelerometer) when motion tracking is active.
41
+ *
42
+ * @since 1.0.0
43
+ */
44
+ locked: boolean;
45
+ /**
46
+ * The physical orientation of the device from motion sensors.
47
+ * Available when motion tracking is active (iOS and Android).
48
+ *
49
+ * @since 1.0.0
50
+ */
51
+ physicalOrientation?: OrientationType;
52
+ /**
53
+ * The current UI orientation reported by the system.
54
+ *
55
+ * @since 1.0.0
56
+ */
57
+ uiOrientation: OrientationType;
58
+ }
59
+ /**
60
+ * Options for locking the screen orientation.
61
+ *
62
+ * @since 1.0.0
63
+ */
64
+ export interface OrientationLockOptions {
65
+ /**
66
+ * The orientation type to lock to.
67
+ *
68
+ * @since 1.0.0
69
+ */
70
+ orientation: OrientationLockType;
71
+ /**
72
+ * Whether to track physical device orientation using motion sensors.
73
+ * When true, uses device motion sensors to detect the true physical
74
+ * orientation of the device, even when the device orientation lock is enabled.
75
+ *
76
+ * **Important:** This does NOT bypass the UI orientation lock.
77
+ * The screen will still respect the user's orientation lock setting.
78
+ * This option only affects orientation detection/tracking - you'll receive
79
+ * orientation change events based on how the device is physically held,
80
+ * but the UI will not rotate if orientation lock is enabled.
81
+ *
82
+ * Supported on iOS (Core Motion) and Android (Accelerometer).
83
+ *
84
+ * @default false
85
+ * @since 1.0.0
86
+ */
87
+ bypassOrientationLock?: boolean;
88
+ }
89
+ /**
90
+ * Options for starting orientation tracking using motion sensors.
91
+ *
92
+ * @since 1.0.0
93
+ */
94
+ export interface StartOrientationTrackingOptions {
95
+ /**
96
+ * Whether to track physical device orientation using motion sensors.
97
+ * When true, uses device motion sensors to detect the true physical
98
+ * orientation of the device, even when the device orientation lock is enabled.
99
+ *
100
+ * **Important:** This does NOT bypass the UI orientation lock.
101
+ * This only enables detection of the physical orientation.
102
+ *
103
+ * Supported on iOS (Core Motion) and Android (Accelerometer).
104
+ *
105
+ * @default false
106
+ * @since 1.0.0
107
+ */
108
+ bypassOrientationLock?: boolean;
109
+ }
110
+ /**
111
+ * Capacitor Screen Orientation Plugin interface.
112
+ *
113
+ * Provides methods to detect and control screen orientation,
114
+ * with support for detecting true physical device orientation using motion sensors.
115
+ *
116
+ * @since 1.0.0
117
+ */
118
+ export interface CapacitorScreenOrientationPlugin {
119
+ /**
120
+ * Get the current screen orientation.
121
+ *
122
+ * Returns the current orientation of the device screen.
123
+ *
124
+ * @since 1.0.0
125
+ * @returns {Promise<ScreenOrientationResult>} A promise that resolves with the current orientation.
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const result = await ScreenOrientation.orientation();
130
+ * console.log('Current orientation:', result.type);
131
+ * ```
132
+ */
133
+ orientation(): Promise<ScreenOrientationResult>;
134
+ /**
135
+ * Lock the screen orientation to a specific type.
136
+ *
137
+ * Locks the screen to the specified orientation.
138
+ * On iOS, if bypassOrientationLock is true, it will also start
139
+ * tracking physical device orientation using motion sensors.
140
+ *
141
+ * Note: The UI will still respect the user's orientation lock setting.
142
+ * Motion tracking allows you to detect how the device is physically held
143
+ * even when the UI doesn't rotate.
144
+ *
145
+ * @since 1.0.0
146
+ * @param options Options for locking the orientation.
147
+ * @returns {Promise<void>} A promise that resolves when the orientation is locked.
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * // Standard lock
152
+ * await ScreenOrientation.lock({ orientation: 'landscape' });
153
+ *
154
+ * // Lock with motion tracking on iOS
155
+ * await ScreenOrientation.lock({
156
+ * orientation: 'portrait',
157
+ * bypassOrientationLock: true
158
+ * });
159
+ * ```
160
+ */
161
+ lock(options: OrientationLockOptions): Promise<void>;
162
+ /**
163
+ * Unlock the screen orientation.
164
+ *
165
+ * Allows the screen to rotate freely based on device position.
166
+ * Also stops any motion-based orientation tracking if it was enabled.
167
+ *
168
+ * @since 1.0.0
169
+ * @returns {Promise<void>} A promise that resolves when the orientation is unlocked.
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * await ScreenOrientation.unlock();
174
+ * ```
175
+ */
176
+ unlock(): Promise<void>;
177
+ /**
178
+ * Start tracking device orientation using motion sensors.
179
+ *
180
+ * This method is useful when you want to track the device's physical
181
+ * orientation independently from the screen orientation lock.
182
+ * It uses Core Motion on iOS to detect orientation changes.
183
+ *
184
+ * @since 1.0.0
185
+ * @param options Options for starting orientation tracking.
186
+ * @returns {Promise<void>} A promise that resolves when tracking starts.
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * await ScreenOrientation.startOrientationTracking({
191
+ * bypassOrientationLock: true
192
+ * });
193
+ *
194
+ * // Listen for changes
195
+ * ScreenOrientation.addListener('screenOrientationChange', (result) => {
196
+ * console.log('Orientation changed:', result.type);
197
+ * });
198
+ * ```
199
+ */
200
+ startOrientationTracking(options?: StartOrientationTrackingOptions): Promise<void>;
201
+ /**
202
+ * Stop tracking device orientation using motion sensors.
203
+ *
204
+ * Stops the motion-based orientation tracking if it was started.
205
+ *
206
+ * @since 1.0.0
207
+ * @returns {Promise<void>} A promise that resolves when tracking stops.
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * await ScreenOrientation.stopOrientationTracking();
212
+ * ```
213
+ */
214
+ stopOrientationTracking(): Promise<void>;
215
+ /**
216
+ * Check if device orientation lock is currently enabled.
217
+ *
218
+ * This method compares the physical device orientation (from motion sensors)
219
+ * with the UI orientation. If they differ, orientation lock is enabled.
220
+ *
221
+ * Note: This requires motion tracking to be active via
222
+ * startOrientationTracking() or lock() with bypassOrientationLock: true.
223
+ * Works on both iOS (Core Motion) and Android (Accelerometer).
224
+ *
225
+ * @since 1.0.0
226
+ * @returns {Promise<OrientationLockStatusResult>} A promise that resolves with the lock status.
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * // Start motion tracking first
231
+ * await ScreenOrientation.startOrientationTracking({
232
+ * bypassOrientationLock: true
233
+ * });
234
+ *
235
+ * // Check lock status
236
+ * const status = await ScreenOrientation.isOrientationLocked();
237
+ * if (status.locked) {
238
+ * console.log('Orientation lock is ON');
239
+ * console.log('Physical:', status.physicalOrientation);
240
+ * console.log('UI:', status.uiOrientation);
241
+ * }
242
+ * ```
243
+ */
244
+ isOrientationLocked(): Promise<OrientationLockStatusResult>;
245
+ /**
246
+ * Listen for screen orientation changes.
247
+ *
248
+ * Registers a listener that will be called whenever the screen orientation changes.
249
+ * If motion-based tracking is enabled, this will also fire for orientation changes
250
+ * detected by motion sensors even when orientation lock is enabled.
251
+ *
252
+ * @since 1.0.0
253
+ * @param eventName The event name. Must be 'screenOrientationChange'.
254
+ * @param listenerFunc Callback function invoked when orientation changes.
255
+ * @returns {Promise<PluginListenerHandle>} A promise that resolves to a listener handle.
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * const listener = await ScreenOrientation.addListener(
260
+ * 'screenOrientationChange',
261
+ * (result) => {
262
+ * console.log('New orientation:', result.type);
263
+ * }
264
+ * );
265
+ *
266
+ * // To remove the listener:
267
+ * await listener.remove();
268
+ * ```
269
+ */
270
+ addListener(eventName: 'screenOrientationChange', listenerFunc: (result: ScreenOrientationResult) => void): Promise<PluginListenerHandle>;
271
+ /**
272
+ * Remove all listeners for this plugin.
273
+ *
274
+ * Removes all registered event listeners.
275
+ *
276
+ * @since 1.0.0
277
+ * @returns {Promise<void>} A promise that resolves when all listeners are removed.
278
+ *
279
+ * @example
280
+ * ```typescript
281
+ * await ScreenOrientation.removeAllListeners();
282
+ * ```
283
+ */
284
+ removeAllListeners(): Promise<void>;
285
+ /**
286
+ * Get the native plugin version.
287
+ *
288
+ * Returns the current version of the native plugin implementation.
289
+ *
290
+ * @since 1.0.0
291
+ * @returns {Promise<{ version: string }>} A promise that resolves with the version string.
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * const { version } = await ScreenOrientation.getPluginVersion();
296
+ * console.log('Plugin version:', version);
297
+ * ```
298
+ */
299
+ getPluginVersion(): Promise<{
300
+ version: string;
301
+ }>;
302
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\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"]}
@@ -0,0 +1,4 @@
1
+ import type { CapacitorScreenOrientationPlugin } from './definitions';
2
+ declare const ScreenOrientation: CapacitorScreenOrientationPlugin;
3
+ export * from './definitions';
4
+ export { ScreenOrientation };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const ScreenOrientation = registerPlugin('CapacitorScreenOrientation', {
3
+ web: () => import('./web').then((m) => new m.CapacitorScreenOrientationWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { ScreenOrientation };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,iBAAiB,GAAG,cAAc,CAAmC,4BAA4B,EAAE;IACvG,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,6BAA6B,EAAE,CAAC;CAC9E,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { CapacitorScreenOrientationPlugin } from './definitions';\n\nconst ScreenOrientation = registerPlugin<CapacitorScreenOrientationPlugin>('CapacitorScreenOrientation', {\n web: () => import('./web').then((m) => new m.CapacitorScreenOrientationWeb()),\n});\n\nexport * from './definitions';\nexport { ScreenOrientation };\n"]}
@@ -0,0 +1,20 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { CapacitorScreenOrientationPlugin, OrientationLockOptions, OrientationType, ScreenOrientationResult, StartOrientationTrackingOptions } from './definitions';
3
+ export declare class CapacitorScreenOrientationWeb extends WebPlugin implements CapacitorScreenOrientationPlugin {
4
+ private readonly pluginVersion;
5
+ constructor();
6
+ orientation(): Promise<ScreenOrientationResult>;
7
+ lock(options: OrientationLockOptions): Promise<void>;
8
+ unlock(): Promise<void>;
9
+ startOrientationTracking(_options?: StartOrientationTrackingOptions): Promise<void>;
10
+ stopOrientationTracking(): Promise<void>;
11
+ isOrientationLocked(): Promise<{
12
+ locked: boolean;
13
+ physicalOrientation?: OrientationType;
14
+ uiOrientation: OrientationType;
15
+ }>;
16
+ getPluginVersion(): Promise<{
17
+ version: string;
18
+ }>;
19
+ private mapOrientationType;
20
+ }
@@ -0,0 +1,81 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class CapacitorScreenOrientationWeb extends WebPlugin {
3
+ constructor() {
4
+ var _a;
5
+ super();
6
+ this.pluginVersion = '1.0.0';
7
+ if ((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation) {
8
+ window.screen.orientation.addEventListener('change', () => {
9
+ this.notifyListeners('screenOrientationChange', {
10
+ type: this.mapOrientationType(window.screen.orientation.type),
11
+ });
12
+ });
13
+ }
14
+ }
15
+ async orientation() {
16
+ var _a;
17
+ if (!((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation)) {
18
+ throw this.unavailable('Screen Orientation API not available');
19
+ }
20
+ return {
21
+ type: this.mapOrientationType(window.screen.orientation.type),
22
+ };
23
+ }
24
+ async lock(options) {
25
+ var _a;
26
+ const screenOrientation = (_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation;
27
+ if (!(screenOrientation === null || screenOrientation === void 0 ? void 0 : screenOrientation.lock)) {
28
+ throw this.unavailable('Screen Orientation lock not available');
29
+ }
30
+ // bypassOrientationLock is only supported on iOS native platform
31
+ // Silently ignore it on web
32
+ try {
33
+ await screenOrientation.lock(options.orientation);
34
+ }
35
+ catch (error) {
36
+ throw new Error(`Failed to lock orientation: ${error}`);
37
+ }
38
+ }
39
+ async unlock() {
40
+ var _a;
41
+ const screenOrientation = (_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation;
42
+ if (!(screenOrientation === null || screenOrientation === void 0 ? void 0 : screenOrientation.unlock)) {
43
+ throw this.unavailable('Screen Orientation unlock not available');
44
+ }
45
+ screenOrientation.unlock();
46
+ }
47
+ async startOrientationTracking(_options) {
48
+ // Motion-based orientation tracking is only supported on iOS
49
+ // Silently ignore on web
50
+ }
51
+ async stopOrientationTracking() {
52
+ // Motion-based orientation tracking is only supported on iOS
53
+ // Silently ignore on web
54
+ }
55
+ async isOrientationLocked() {
56
+ const orientationResult = await this.orientation();
57
+ return {
58
+ locked: false,
59
+ uiOrientation: orientationResult.type,
60
+ };
61
+ }
62
+ async getPluginVersion() {
63
+ return { version: this.pluginVersion };
64
+ }
65
+ mapOrientationType(type) {
66
+ if (type.includes('portrait-primary') || type === 'portrait-primary') {
67
+ return 'portrait-primary';
68
+ }
69
+ if (type.includes('portrait-secondary') || type === 'portrait-secondary') {
70
+ return 'portrait-secondary';
71
+ }
72
+ if (type.includes('landscape-primary') || type === 'landscape-primary') {
73
+ return 'landscape-primary';
74
+ }
75
+ if (type.includes('landscape-secondary') || type === 'landscape-secondary') {
76
+ return 'landscape-secondary';
77
+ }
78
+ return 'portrait-primary'; // default fallback
79
+ }
80
+ }
81
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"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,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 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 }\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"]}
@@ -0,0 +1,95 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const ScreenOrientation = core.registerPlugin('CapacitorScreenOrientation', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorScreenOrientationWeb()),
7
+ });
8
+
9
+ class CapacitorScreenOrientationWeb extends core.WebPlugin {
10
+ constructor() {
11
+ var _a;
12
+ super();
13
+ this.pluginVersion = '1.0.0';
14
+ if ((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation) {
15
+ window.screen.orientation.addEventListener('change', () => {
16
+ this.notifyListeners('screenOrientationChange', {
17
+ type: this.mapOrientationType(window.screen.orientation.type),
18
+ });
19
+ });
20
+ }
21
+ }
22
+ async orientation() {
23
+ var _a;
24
+ if (!((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation)) {
25
+ throw this.unavailable('Screen Orientation API not available');
26
+ }
27
+ return {
28
+ type: this.mapOrientationType(window.screen.orientation.type),
29
+ };
30
+ }
31
+ async lock(options) {
32
+ var _a;
33
+ const screenOrientation = (_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation;
34
+ if (!(screenOrientation === null || screenOrientation === void 0 ? void 0 : screenOrientation.lock)) {
35
+ throw this.unavailable('Screen Orientation lock not available');
36
+ }
37
+ // bypassOrientationLock is only supported on iOS native platform
38
+ // Silently ignore it on web
39
+ try {
40
+ await screenOrientation.lock(options.orientation);
41
+ }
42
+ catch (error) {
43
+ throw new Error(`Failed to lock orientation: ${error}`);
44
+ }
45
+ }
46
+ async unlock() {
47
+ var _a;
48
+ const screenOrientation = (_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation;
49
+ if (!(screenOrientation === null || screenOrientation === void 0 ? void 0 : screenOrientation.unlock)) {
50
+ throw this.unavailable('Screen Orientation unlock not available');
51
+ }
52
+ screenOrientation.unlock();
53
+ }
54
+ async startOrientationTracking(_options) {
55
+ // Motion-based orientation tracking is only supported on iOS
56
+ // Silently ignore on web
57
+ }
58
+ async stopOrientationTracking() {
59
+ // Motion-based orientation tracking is only supported on iOS
60
+ // Silently ignore on web
61
+ }
62
+ async isOrientationLocked() {
63
+ const orientationResult = await this.orientation();
64
+ return {
65
+ locked: false,
66
+ uiOrientation: orientationResult.type,
67
+ };
68
+ }
69
+ async getPluginVersion() {
70
+ return { version: this.pluginVersion };
71
+ }
72
+ mapOrientationType(type) {
73
+ if (type.includes('portrait-primary') || type === 'portrait-primary') {
74
+ return 'portrait-primary';
75
+ }
76
+ if (type.includes('portrait-secondary') || type === 'portrait-secondary') {
77
+ return 'portrait-secondary';
78
+ }
79
+ if (type.includes('landscape-primary') || type === 'landscape-primary') {
80
+ return 'landscape-primary';
81
+ }
82
+ if (type.includes('landscape-secondary') || type === 'landscape-secondary') {
83
+ return 'landscape-secondary';
84
+ }
85
+ return 'portrait-primary'; // default fallback
86
+ }
87
+ }
88
+
89
+ var web = /*#__PURE__*/Object.freeze({
90
+ __proto__: null,
91
+ CapacitorScreenOrientationWeb: CapacitorScreenOrientationWeb
92
+ });
93
+
94
+ exports.ScreenOrientation = ScreenOrientation;
95
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +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 }\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,EAAE,MAAM;AACvE,gBAAgB,IAAI,CAAC,eAAe,CAAC,yBAAyB,EAAE;AAChE,oBAAoB,IAAI,EAAE,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;AACjF,iBAAiB,CAAC;AAClB,YAAY,CAAC,CAAC;AACd,QAAQ;AACR,IAAI;AACJ,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,IAAI,EAAE;AACd,QAAQ,IAAI,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,MAAM,IAAI,IAAI,EAAE,K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