@capgo/capacitor-screen-orientation 8.1.21 → 8.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,33 @@ 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, status: null };
106
+ }
107
+ async getReservedRegions() {
108
+ return { regions: [] };
109
+ }
110
+ async getBarPlacement() {
111
+ return { verticalBarEdge: null, inset: 0 };
112
+ }
113
+ async setVerticalBarBehavior() {
114
+ return { applied: false };
115
+ }
116
+ async getSizeClass() {
117
+ return this.readSizeClass();
118
+ }
70
119
  async getPluginVersion() {
71
120
  return { version: this.pluginVersion };
72
121
  }
122
+ readSizeClass() {
123
+ return sizeClassOf(window.innerWidth, window.innerHeight);
124
+ }
73
125
  mapOrientationType(type) {
74
126
  if (type.includes('portrait-primary') || type === 'portrait-primary') {
75
127
  return 'portrait-primary';
@@ -89,7 +141,8 @@ class CapacitorScreenOrientationWeb extends core.WebPlugin {
89
141
 
90
142
  var web = /*#__PURE__*/Object.freeze({
91
143
  __proto__: null,
92
- CapacitorScreenOrientationWeb: CapacitorScreenOrientationWeb
144
+ CapacitorScreenOrientationWeb: CapacitorScreenOrientationWeb,
145
+ sizeClassOf: sizeClassOf
93
146
  });
94
147
 
95
148
  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,i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M,mBAAmB,GAAG;AAChC,QAAQ,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE;AAC1D,QAAQ,OAAO;AACf,YAAY,MAAM,EAAE,KAAK;AACzB,YAAY,aAAa,EAAE,iBAAiB,CAAC,IAAI;AACjD,SAAS;AACT,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE;AAC9C,IAAI;AACJ,IAAI,kBAAkB,CAAC,IAAI,EAAE;AAC7B,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,IAAI,KAAK,kBAAkB,EAAE;AAC9E,YAAY,OAAO,kBAAkB;AACrC,QAAQ;AACR,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,oBAAoB,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, status: null };\n }\n async getReservedRegions() {\n return { regions: [] };\n }\n async getBarPlacement() {\n return { verticalBarEdge: null, inset: 0 };\n }\n async setVerticalBarBehavior() {\n return { applied: false };\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,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O,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,33 @@ 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, status: null };
105
+ }
106
+ async getReservedRegions() {
107
+ return { regions: [] };
108
+ }
109
+ async getBarPlacement() {
110
+ return { verticalBarEdge: null, inset: 0 };
111
+ }
112
+ async setVerticalBarBehavior() {
113
+ return { applied: false };
114
+ }
115
+ async getSizeClass() {
116
+ return this.readSizeClass();
117
+ }
69
118
  async getPluginVersion() {
70
119
  return { version: this.pluginVersion };
71
120
  }
121
+ readSizeClass() {
122
+ return sizeClassOf(window.innerWidth, window.innerHeight);
123
+ }
72
124
  mapOrientationType(type) {
73
125
  if (type.includes('portrait-primary') || type === 'portrait-primary') {
74
126
  return 'portrait-primary';
@@ -88,7 +140,8 @@ var capacitorScreenOrientation = (function (exports, core) {
88
140
 
89
141
  var web = /*#__PURE__*/Object.freeze({
90
142
  __proto__: null,
91
- CapacitorScreenOrientationWeb: CapacitorScreenOrientationWeb
143
+ CapacitorScreenOrientationWeb: CapacitorScreenOrientationWeb,
144
+ sizeClassOf: sizeClassOf
92
145
  });
93
146
 
94
147
  exports.ScreenOrientation = ScreenOrientation;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.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,UAAC,iBAAiB,GAAGA,mBAAc,CAAC,4BAA4B,EAAE;IACvE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAA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AAQ,OAAO;IACf,YAAY,MAAM,EAAE,KAAK;IACzB,YAAY,aAAa,EAAE,iBAAiB,CAAC,IAAI;IACjD,SAAS;IACT,IAAI;IACJ,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE;IAC9C,IAAI;IACJ,IAAI,kBAAkB,CAAC,IAAI,EAAE;IAC7B,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,IAAI,KAAK,kBAAkB,EAAE;IAC9E,YAAY,OAAO,kBAAkB;IACrC,QAAQ;IACR,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,IAAI,IAAI,KAAK,oBAAoB,EAAE;IAClF,YAAY,OAAO,oBAAoB;IACvC,QAAQ;IACR,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,IAAI,KAAK,mBAAmB,EAAE;IAChF,YAAY,OAAO,mBAAmB;IACtC,QAAQ;IACR,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,IAAI,IAAI,KAAK,qBAAqB,EAAE;IACpF,YAAY,OAAO,qBAAqB;IACxC,QAAQ;IACR,QAAQ,OAAO,kBAAkB,CAAC;IAClC,IAAI;IACJ;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.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, status: null };\n }\n async getReservedRegions() {\n return { regions: [] };\n }\n async getBarPlacement() {\n return { verticalBarEdge: null, inset: 0 };\n }\n async setVerticalBarBehavior() {\n return { applied: false };\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,UAAC,iBAAiB,GAAGA,mBAAc,CAAC,4BAA4B,EAAE;IACvE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,6BAA6B,EAAE,CAAC;IACjF,CAAC;;ICFD,MAAM,SAAS,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE;IAClE,SAAS,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE;IAC3C,IAAI,MAAM,UAAU,GAAG,KAAK,IAAI;IAChC,UAAU;IACV,UAAU,KAAK,IAAI;IACnB,cAAc;IACd,cAAc,KAAK,IAAI;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  */
12
12
  @objc(CapacitorScreenOrientationPlugin)
13
13
  public class CapacitorScreenOrientationPlugin: CAPPlugin, CAPBridgedPlugin {
14
- private let pluginVersion: String = "8.1.21"
14
+ private let pluginVersion: String = "8.3.0"
15
15
  public let identifier = "CapacitorScreenOrientationPlugin"
16
16
  public let jsName = "CapacitorScreenOrientation"
17
17
  public let pluginMethods: [CAPPluginMethod] = [
@@ -21,6 +21,13 @@ public class CapacitorScreenOrientationPlugin: CAPPlugin, CAPBridgedPlugin {
21
21
  CAPPluginMethod(name: "startOrientationTracking", returnType: CAPPluginReturnPromise),
22
22
  CAPPluginMethod(name: "stopOrientationTracking", returnType: CAPPluginReturnPromise),
23
23
  CAPPluginMethod(name: "isOrientationLocked", returnType: CAPPluginReturnPromise),
24
+ CAPPluginMethod(name: "isDeviceFoldable", returnType: CAPPluginReturnPromise),
25
+ CAPPluginMethod(name: "getFoldState", returnType: CAPPluginReturnPromise),
26
+ CAPPluginMethod(name: "getHingeAngle", returnType: CAPPluginReturnPromise),
27
+ CAPPluginMethod(name: "getReservedRegions", returnType: CAPPluginReturnPromise),
28
+ CAPPluginMethod(name: "getBarPlacement", returnType: CAPPluginReturnPromise),
29
+ CAPPluginMethod(name: "setVerticalBarBehavior", returnType: CAPPluginReturnPromise),
30
+ CAPPluginMethod(name: "getSizeClass", returnType: CAPPluginReturnPromise),
24
31
  CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise)
25
32
  ]
26
33
 
@@ -30,6 +37,17 @@ public class CapacitorScreenOrientationPlugin: CAPPlugin, CAPBridgedPlugin {
30
37
  private var lastNotifiedOrientation: String?
31
38
  private var capViewController: CAPBridgeViewController?
32
39
  private var defaultSupportedOrientations: [Int] = []
40
+ private var lastSizeClassKey: String?
41
+ private var sizeClassProbe: SizeClassProbe?
42
+
43
+ private final class SizeClassProbe: UIView {
44
+ var onLayout: (() -> Void)?
45
+
46
+ override func layoutSubviews() {
47
+ super.layoutSubviews()
48
+ onLayout?()
49
+ }
50
+ }
33
51
 
34
52
  override public func load() {
35
53
  // Listen for device orientation changes from system
@@ -47,15 +65,28 @@ public class CapacitorScreenOrientationPlugin: CAPPlugin, CAPBridgedPlugin {
47
65
  self.capViewController = viewController
48
66
  self.defaultSupportedOrientations = viewController.supportedOrientations
49
67
  }
68
+ DispatchQueue.main.async {
69
+ self.attachSizeClassProbe()
70
+ self.notifySizeClassIfChanged()
71
+ if let view = self.bridge?.webView {
72
+ IPhoneDuoFold.shared.observe(in: view) { [weak self] in
73
+ self?.notifyListeners("hingeAngleChange", data: IPhoneDuoFold.shared.hingeAngle())
74
+ self?.notifyListeners("foldStateChange", data: IPhoneDuoFold.shared.foldState(in: view))
75
+ }
76
+ }
77
+ }
50
78
  }
51
79
 
52
80
  deinit {
53
81
  stopMotionTracking()
82
+ sizeClassProbe?.removeFromSuperview()
54
83
  UIDevice.current.endGeneratingDeviceOrientationNotifications()
55
84
  NotificationCenter.default.removeObserver(self)
56
85
  }
57
86
 
58
87
  @objc private func orientationDidChange() {
88
+ notifySizeClassIfChanged()
89
+
59
90
  // Skip system orientation changes when motion tracking is active
60
91
  // to avoid duplicate events
61
92
  guard !isTrackingWithMotion else { return }
@@ -66,6 +97,47 @@ public class CapacitorScreenOrientationPlugin: CAPPlugin, CAPBridgedPlugin {
66
97
  }
67
98
  }
68
99
 
100
+ @objc func isDeviceFoldable(_ call: CAPPluginCall) {
101
+ DispatchQueue.main.async {
102
+ let foldable = IPhoneDuoFold.shared.isFoldable(in: self.bridge?.webView)
103
+ call.resolve(["foldable": foldable, "supportsTabletop": foldable])
104
+ }
105
+ }
106
+
107
+ @objc func getFoldState(_ call: CAPPluginCall) {
108
+ DispatchQueue.main.async {
109
+ call.resolve(IPhoneDuoFold.shared.foldState(in: self.bridge?.webView))
110
+ }
111
+ }
112
+
113
+ @objc func getHingeAngle(_ call: CAPPluginCall) {
114
+ DispatchQueue.main.async {
115
+ call.resolve(IPhoneDuoFold.shared.hingeAngle())
116
+ }
117
+ }
118
+
119
+ @objc func getReservedRegions(_ call: CAPPluginCall) {
120
+ DispatchQueue.main.async {
121
+ call.resolve(IPhoneDuoFold.shared.reservedRegions(in: self.bridge?.webView))
122
+ }
123
+ }
124
+
125
+ @objc func getBarPlacement(_ call: CAPPluginCall) {
126
+ DispatchQueue.main.async {
127
+ call.resolve(IPhoneDuoFold.shared.barPlacement(in: self.bridge?.webView))
128
+ }
129
+ }
130
+
131
+ @objc func setVerticalBarBehavior(_ call: CAPPluginCall) {
132
+ call.resolve(["applied": false])
133
+ }
134
+
135
+ @objc func getSizeClass(_ call: CAPPluginCall) {
136
+ DispatchQueue.main.async {
137
+ call.resolve(self.currentSizeClass())
138
+ }
139
+ }
140
+
69
141
  @objc func orientation(_ call: CAPPluginCall) {
70
142
  let orientationType = getCurrentOrientationType()
71
143
  call.resolve(["type": orientationType])
@@ -316,6 +388,61 @@ public class CapacitorScreenOrientationPlugin: CAPPlugin, CAPBridgedPlugin {
316
388
  }
317
389
  }
318
390
 
391
+ private func currentSizeClass() -> [String: Any] {
392
+ let view = self.bridge?.webView
393
+ let width = Double(view?.bounds.width ?? UIScreen.main.bounds.width)
394
+ let height = Double(view?.bounds.height ?? UIScreen.main.bounds.height)
395
+ let traits = view?.traitCollection
396
+ let horizontal = sizeName(traits?.horizontalSizeClass, points: width, regularAt: 600)
397
+ let vertical = sizeName(traits?.verticalSizeClass, points: height, regularAt: 480)
398
+ return [
399
+ "horizontal": horizontal,
400
+ "vertical": vertical,
401
+ "widthClass": materialWidth(width),
402
+ "heightClass": height >= 900 ? "expanded" : height >= 480 ? "medium" : "compact"
403
+ ]
404
+ }
405
+
406
+ private func attachSizeClassProbe() {
407
+ guard sizeClassProbe == nil, let webView = bridge?.webView else { return }
408
+ let probe = SizeClassProbe(frame: webView.bounds)
409
+ probe.autoresizingMask = [.flexibleWidth, .flexibleHeight]
410
+ probe.isUserInteractionEnabled = false
411
+ probe.backgroundColor = .clear
412
+ probe.onLayout = { [weak self] in
413
+ self?.notifySizeClassIfChanged()
414
+ }
415
+ webView.addSubview(probe)
416
+ sizeClassProbe = probe
417
+ }
418
+
419
+ private func notifySizeClassIfChanged() {
420
+ let sizeClass = currentSizeClass()
421
+ let key = "\(sizeClass["horizontal"] ?? "")-\(sizeClass["vertical"] ?? "")-\(sizeClass["widthClass"] ?? "")-\(sizeClass["heightClass"] ?? "")"
422
+ guard key != lastSizeClassKey else { return }
423
+ lastSizeClassKey = key
424
+ notifyListeners("sizeClassChange", data: sizeClass)
425
+ }
426
+
427
+ private func sizeName(_ sizeClass: UIUserInterfaceSizeClass?, points: Double, regularAt: Double) -> String {
428
+ switch sizeClass {
429
+ case .some(.regular):
430
+ return "regular"
431
+ case .some(.compact):
432
+ return "compact"
433
+ default:
434
+ return points >= regularAt ? "regular" : "compact"
435
+ }
436
+ }
437
+
438
+ private func materialWidth(_ width: Double) -> String {
439
+ if width >= 1600 { return "extraLarge" }
440
+ if width >= 1200 { return "large" }
441
+ if width >= 840 { return "expanded" }
442
+ if width >= 600 { return "medium" }
443
+ return "compact"
444
+ }
445
+
319
446
  private func getOrientationMask(from orientationString: String) -> UIInterfaceOrientationMask? {
320
447
  switch orientationString {
321
448
  case "any":