native-fn 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +14 -14
  2. package/dist/index.d.ts +12 -6
  3. package/dist/native.cjs +180 -102
  4. package/dist/native.min.cjs +1 -1
  5. package/dist/native.min.mjs +1 -1
  6. package/dist/native.mjs +180 -102
  7. package/dist/native.umd.js +180 -102
  8. package/dist/native.umd.min.js +1 -1
  9. package/dist/plugin/appearance/index.cjs +8 -3
  10. package/dist/plugin/appearance/index.mjs +8 -3
  11. package/dist/plugin/appearance/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  12. package/dist/plugin/appearance/src/plugin/pip/types/pip.d.ts +5 -2
  13. package/dist/plugin/appearance/src/types/subscription-manager.d.ts +1 -1
  14. package/dist/plugin/badge/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  15. package/dist/plugin/badge/src/plugin/pip/types/pip.d.ts +5 -2
  16. package/dist/plugin/badge/src/types/subscription-manager.d.ts +1 -1
  17. package/dist/plugin/battery/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  18. package/dist/plugin/battery/src/plugin/pip/types/pip.d.ts +5 -2
  19. package/dist/plugin/battery/src/types/subscription-manager.d.ts +1 -1
  20. package/dist/plugin/clipboard/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  21. package/dist/plugin/clipboard/src/plugin/pip/types/pip.d.ts +5 -2
  22. package/dist/plugin/clipboard/src/types/subscription-manager.d.ts +1 -1
  23. package/dist/plugin/dimension/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  24. package/dist/plugin/dimension/src/plugin/pip/types/pip.d.ts +5 -2
  25. package/dist/plugin/dimension/src/types/subscription-manager.d.ts +1 -1
  26. package/dist/plugin/fullscreen/index.cjs +93 -54
  27. package/dist/plugin/fullscreen/index.d.ts +7 -4
  28. package/dist/plugin/fullscreen/index.mjs +93 -54
  29. package/dist/plugin/fullscreen/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  30. package/dist/plugin/fullscreen/src/plugin/pip/types/pip.d.ts +5 -2
  31. package/dist/plugin/fullscreen/src/types/subscription-manager.d.ts +1 -1
  32. package/dist/plugin/geolocation/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  33. package/dist/plugin/geolocation/src/plugin/pip/types/pip.d.ts +5 -2
  34. package/dist/plugin/geolocation/src/types/subscription-manager.d.ts +1 -1
  35. package/dist/plugin/notification/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  36. package/dist/plugin/notification/src/plugin/pip/types/pip.d.ts +5 -2
  37. package/dist/plugin/notification/src/types/subscription-manager.d.ts +1 -1
  38. package/dist/plugin/open/index.cjs +8 -3
  39. package/dist/plugin/open/index.mjs +8 -3
  40. package/dist/plugin/open/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  41. package/dist/plugin/open/src/plugin/pip/types/pip.d.ts +5 -2
  42. package/dist/plugin/open/src/types/subscription-manager.d.ts +1 -1
  43. package/dist/plugin/permission/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  44. package/dist/plugin/permission/src/plugin/pip/types/pip.d.ts +5 -2
  45. package/dist/plugin/permission/src/types/subscription-manager.d.ts +1 -1
  46. package/dist/plugin/pip/index.cjs +448 -47
  47. package/dist/plugin/pip/index.d.ts +5 -2
  48. package/dist/plugin/pip/index.mjs +448 -47
  49. package/dist/plugin/pip/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  50. package/dist/plugin/pip/src/plugin/pip/types/pip.d.ts +5 -2
  51. package/dist/plugin/pip/src/types/subscription-manager.d.ts +1 -1
  52. package/dist/plugin/platform/index.cjs +8 -3
  53. package/dist/plugin/platform/index.mjs +8 -3
  54. package/dist/plugin/platform/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  55. package/dist/plugin/platform/src/plugin/pip/types/pip.d.ts +5 -2
  56. package/dist/plugin/platform/src/types/subscription-manager.d.ts +1 -1
  57. package/dist/plugin/theme/index.cjs +8 -3
  58. package/dist/plugin/theme/index.mjs +8 -3
  59. package/dist/plugin/theme/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  60. package/dist/plugin/theme/src/plugin/pip/types/pip.d.ts +5 -2
  61. package/dist/plugin/theme/src/types/subscription-manager.d.ts +1 -1
  62. package/dist/plugin/vibration/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  63. package/dist/plugin/vibration/src/plugin/pip/types/pip.d.ts +5 -2
  64. package/dist/plugin/vibration/src/types/subscription-manager.d.ts +1 -1
  65. package/dist/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  66. package/dist/src/plugin/pip/types/pip.d.ts +5 -2
  67. package/dist/src/types/subscription-manager.d.ts +1 -1
  68. package/package.json +1 -1
package/dist/native.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var version = "1.2.0";
3
+ var version = "1.2.1";
4
4
  var packageJSON = {
5
5
  version: version};
6
6
 
@@ -689,10 +689,15 @@ function parseFromHighEntropyValues() {
689
689
  parsedFromHighEntropyValuesEngine.version = brandVersion;
690
690
  }
691
691
  if (typeof platformVersion === 'string') {
692
- if (getParsedCache().os.name === OS.Windows)
693
- parsedFromHighEntropyValuesOS.version = parseInt(platformVersion.split('.')[0], 10) >= 13 ? '11' : '10';
694
- else
692
+ if (getParsedCache().os.name === OS.Windows) {
693
+ if (parseInt(platformVersion.split('.')[0], 10) >= 13)
694
+ parsedFromHighEntropyValuesOS.version = '11';
695
+ else
696
+ parsedFromHighEntropyValuesOS.version = '10';
697
+ }
698
+ else {
695
699
  parsedFromHighEntropyValuesOS.version = platformVersion;
700
+ }
696
701
  }
697
702
  if (typeof platform === 'string') {
698
703
  if (/android/i.test(platform))
@@ -1869,7 +1874,8 @@ var NotSupportedError = createCustomError('NotSupportedError');
1869
1874
 
1870
1875
  var InvalidStateError = createCustomError('InvalidStateError');
1871
1876
 
1872
- var lastIOSVideo = null;
1877
+ var videoElement$1 = null;
1878
+ var lastFallbackVideoElement$1 = null;
1873
1879
  var eventsBridged$1 = false;
1874
1880
  var FS_BRIDGE_KEY = (function () {
1875
1881
  if (typeof Symbol === 'function') {
@@ -1915,24 +1921,33 @@ var onChangeSubscriptionManager$3 = createSubscriptionManager(attachOnChange$3,
1915
1921
  var onErrorSubscriptionManager$1 = createSubscriptionManager(attachOnError$1, detachOnError$1);
1916
1922
  var Fullscreen = {
1917
1923
  get supported() {
1918
- return getEnabled$1();
1924
+ return getSupported$1();
1919
1925
  },
1920
1926
  get element() {
1921
1927
  return getElement$1();
1922
1928
  },
1923
- get isFullscreen() {
1924
- return getIsFullscreen();
1929
+ get isActive() {
1930
+ return getIsActive$1();
1925
1931
  },
1926
1932
  request: request$3,
1927
1933
  exit: exit$1,
1928
- onChange: onChangeSubscriptionManager$3.subscribe,
1929
- onError: onErrorSubscriptionManager$1.subscribe,
1934
+ toggle: toggle$1,
1935
+ onChange: onChange$1,
1936
+ onError: onError$1,
1930
1937
  Constants: {},
1931
1938
  Errors: {
1932
1939
  NotSupportedError: NotSupportedError,
1933
1940
  InvalidStateError: InvalidStateError,
1934
1941
  },
1935
1942
  };
1943
+ function getHTMLVideoElement$1() {
1944
+ var selected = globalThis.document.querySelector('video');
1945
+ if (selected !== null)
1946
+ return selected;
1947
+ if (videoElement$1 === null)
1948
+ return videoElement$1 = globalThis.document.createElement('video');
1949
+ return videoElement$1;
1950
+ }
1936
1951
  function hasStandardApi$1() {
1937
1952
  return api !== null;
1938
1953
  }
@@ -1955,27 +1970,24 @@ function detectApi() {
1955
1970
  function getDefaultTarget$1() {
1956
1971
  if (Platform.os.name === OS.iOS) {
1957
1972
  var video = globalThis.document.querySelector('video');
1958
- return video !== null ? video : undefined;
1973
+ if (video !== null)
1974
+ return video;
1975
+ return undefined;
1959
1976
  }
1960
1977
  return globalThis.document.documentElement;
1961
1978
  }
1962
- function getEnabled$1() {
1979
+ function getSupported$1() {
1963
1980
  if (api !== null)
1964
1981
  return globalThis.document[api.enabled] === true;
1965
1982
  if (Platform.os.name !== OS.iOS)
1966
1983
  return false;
1967
- var video;
1968
- var selected = globalThis.document.querySelector('video');
1969
- if (selected !== null)
1970
- video = selected;
1971
- else
1972
- video = globalThis.document.createElement('video');
1984
+ var video = getHTMLVideoElement$1();
1973
1985
  return video.webkitSupportsFullscreen === true || typeof video.webkitEnterFullscreen === 'function';
1974
1986
  }
1975
1987
  function getElement$1() {
1976
1988
  if (api === null) {
1977
- if (lastIOSVideo !== null && lastIOSVideo.webkitDisplayingFullscreen === true)
1978
- return lastIOSVideo;
1989
+ if (lastFallbackVideoElement$1 !== null && lastFallbackVideoElement$1.webkitDisplayingFullscreen === true)
1990
+ return lastFallbackVideoElement$1;
1979
1991
  return null;
1980
1992
  }
1981
1993
  var currentElement = globalThis.document[api.element];
@@ -1983,43 +1995,43 @@ function getElement$1() {
1983
1995
  return currentElement;
1984
1996
  return null;
1985
1997
  }
1986
- function getIsFullscreen() {
1998
+ function getIsActive$1() {
1987
1999
  return getElement$1() !== null;
1988
2000
  }
1989
- function createEventPayload(nativeEvent, element, isFullscreen) {
2001
+ function createEventPayload(nativeEvent, element, isActive) {
1990
2002
  return {
1991
2003
  nativeEvent: nativeEvent,
1992
2004
  element: element,
1993
- isFullscreen: isFullscreen,
2005
+ isActive: isActive,
1994
2006
  };
1995
2007
  }
1996
- function emitChange$1(nativeEvent, element, isFullscreen) {
1997
- onChangeSubscriptionManager$3.emit(createEventPayload(nativeEvent, element, isFullscreen));
2008
+ function emitChange$1(nativeEvent, element, isActive) {
2009
+ onChangeSubscriptionManager$3.emit(createEventPayload(nativeEvent, element, isActive));
1998
2010
  }
1999
- function emitError$1(nativeEvent, element, isFullscreen) {
2000
- onErrorSubscriptionManager$1.emit(createEventPayload(nativeEvent, element, isFullscreen));
2011
+ function emitError$1(nativeEvent, element, isActive) {
2012
+ onErrorSubscriptionManager$1.emit(createEventPayload(nativeEvent, element, isActive));
2001
2013
  }
2002
2014
  function onFullscreenChange(event) {
2003
2015
  var target = event.target;
2004
2016
  if (target instanceof globalThis.Element)
2005
- emitChange$1(event, target, getIsFullscreen());
2017
+ emitChange$1(event, target, getIsActive$1());
2006
2018
  if (target instanceof globalThis.Document)
2007
- emitChange$1(event, globalThis.document.documentElement, getIsFullscreen());
2019
+ emitChange$1(event, globalThis.document.documentElement, getIsActive$1());
2008
2020
  }
2009
2021
  function onFullscreenError(event) {
2010
2022
  var target = event.target;
2011
2023
  if (target instanceof globalThis.Element)
2012
- emitError$1(event, target, getIsFullscreen());
2024
+ emitError$1(event, target, getIsActive$1());
2013
2025
  if (target instanceof globalThis.Document)
2014
- emitError$1(event, globalThis.document.documentElement, getIsFullscreen());
2026
+ emitError$1(event, globalThis.document.documentElement, getIsActive$1());
2015
2027
  }
2016
2028
  function onIOSBeginFullscreen(event) {
2017
- lastIOSVideo = this;
2029
+ lastFallbackVideoElement$1 = this;
2018
2030
  emitChange$1(event, this, true);
2019
2031
  }
2020
2032
  function onIOSEndFullscreen(event) {
2021
- if (lastIOSVideo === this)
2022
- lastIOSVideo = null;
2033
+ if (lastFallbackVideoElement$1 === this)
2034
+ lastFallbackVideoElement$1 = null;
2023
2035
  emitChange$1(event, this, false);
2024
2036
  }
2025
2037
  function bridgeSingleVideoNode$1(video) {
@@ -2046,13 +2058,13 @@ function bridgeEvents$1() {
2046
2058
  if (typeof globalThis.MutationObserver === 'undefined')
2047
2059
  return;
2048
2060
  var observer = new globalThis.MutationObserver(function (records) {
2049
- if (lastIOSVideo !== null) {
2061
+ if (lastFallbackVideoElement$1 !== null) {
2050
2062
  var removed = false;
2051
2063
  for (var i = 0; i < records.length; i++) {
2052
2064
  var removedNodes = records[i].removedNodes;
2053
2065
  for (var j = 0; j < removedNodes.length; j++) {
2054
2066
  var node = removedNodes[j];
2055
- if (node === lastIOSVideo || (node.nodeType === Node.ELEMENT_NODE && node.contains(lastIOSVideo))) {
2067
+ if (node === lastFallbackVideoElement$1 || (node.nodeType === Node.ELEMENT_NODE && node.contains(lastFallbackVideoElement$1))) {
2056
2068
  removed = true;
2057
2069
  break;
2058
2070
  }
@@ -2060,8 +2072,8 @@ function bridgeEvents$1() {
2060
2072
  if (removed)
2061
2073
  break;
2062
2074
  }
2063
- if (removed && !globalThis.document.contains(lastIOSVideo))
2064
- lastIOSVideo = null;
2075
+ if (removed && !globalThis.document.contains(lastFallbackVideoElement$1))
2076
+ lastFallbackVideoElement$1 = null;
2065
2077
  }
2066
2078
  for (var i = 0; i < records.length; i++) {
2067
2079
  var addedNodes = records[i].addedNodes;
@@ -2114,8 +2126,10 @@ function request$3(target, options) {
2114
2126
  target = getDefaultTarget$1();
2115
2127
  if (typeof target === 'undefined')
2116
2128
  return reject(new NotSupportedError('Failed to enter fullscreen mode.'));
2129
+ if (getIsActive$1() && getElement$1() !== target && Platform.browser.name === Browsers.Safari && Platform.os.name === OS.iOS)
2130
+ return reject(new NotSupportedError('There is already a Fullscreen element in this document.'));
2117
2131
  var tagName = target.tagName.toLowerCase();
2118
- var isIOSFullscreenActive = lastIOSVideo !== null && lastIOSVideo.webkitDisplayingFullscreen === true;
2132
+ var isIOSFullscreenActive = lastFallbackVideoElement$1 !== null && lastFallbackVideoElement$1.webkitDisplayingFullscreen === true;
2119
2133
  if (api !== null) {
2120
2134
  var method = target[api.request];
2121
2135
  if (typeof method === 'function' && !isIOSFullscreenActive) {
@@ -2129,7 +2143,7 @@ function request$3(target, options) {
2129
2143
  return reject(new NotSupportedError('The "' + tagName + '" element does not support fullscreen requests.'));
2130
2144
  fallbackToIOSVideo();
2131
2145
  }
2132
- catch (_e) {
2146
+ catch (e) {
2133
2147
  reject(new NotSupportedError('The "' + tagName + '" element does not support fullscreen requests.'));
2134
2148
  }
2135
2149
  });
@@ -2148,7 +2162,8 @@ function request$3(target, options) {
2148
2162
  video_1.play()
2149
2163
  .then(function () {
2150
2164
  try {
2151
- video_1.webkitEnterFullscreen();
2165
+ if (video_1.webkitSupportsFullscreen && typeof video_1.webkitEnterFullscreen === 'function')
2166
+ video_1.webkitEnterFullscreen();
2152
2167
  }
2153
2168
  catch (e) {
2154
2169
  return reject(new InvalidStateError('The object is in an invalid state.'));
@@ -2163,7 +2178,7 @@ function request$3(target, options) {
2163
2178
  return reject(new InvalidStateError('The object is in an invalid state.'));
2164
2179
  }
2165
2180
  }
2166
- lastIOSVideo = video_1;
2181
+ lastFallbackVideoElement$1 = video_1;
2167
2182
  return resolve();
2168
2183
  }
2169
2184
  }
@@ -2181,16 +2196,7 @@ function exit$1() {
2181
2196
  if (typeof result !== 'undefined' && typeof result.then === 'function') {
2182
2197
  result
2183
2198
  .then(resolve)
2184
- .catch(function () {
2185
- try {
2186
- if (Platform.os.name !== OS.iOS)
2187
- return reject(new NotSupportedError('Failed to exit fullscreen mode.'));
2188
- fallbackToIOSVideo();
2189
- }
2190
- catch (_e) {
2191
- reject(new NotSupportedError('Failed to exit fullscreen mode.'));
2192
- }
2193
- });
2199
+ .catch(resolve);
2194
2200
  return;
2195
2201
  }
2196
2202
  return resolve();
@@ -2201,12 +2207,12 @@ function exit$1() {
2201
2207
  reject(new NotSupportedError('Failed to exit fullscreen mode.'));
2202
2208
  return;
2203
2209
  }
2204
- var target = lastIOSVideo;
2210
+ var target = lastFallbackVideoElement$1;
2205
2211
  if (target !== null && typeof target.webkitExitFullscreen === 'function' && target.webkitDisplayingFullscreen === true) {
2206
2212
  target.webkitExitFullscreen();
2207
2213
  if (target.webkitDisplayingFullscreen)
2208
2214
  return reject(new NotSupportedError('Failed to exit fullscreen mode.'));
2209
- lastIOSVideo = null;
2215
+ lastFallbackVideoElement$1 = null;
2210
2216
  return resolve();
2211
2217
  }
2212
2218
  var videos = globalThis.document.querySelectorAll('video');
@@ -2216,7 +2222,7 @@ function exit$1() {
2216
2222
  video.webkitExitFullscreen();
2217
2223
  if (video.webkitDisplayingFullscreen)
2218
2224
  return reject(new NotSupportedError('Failed to exit fullscreen mode.'));
2219
- lastIOSVideo = null;
2225
+ lastFallbackVideoElement$1 = null;
2220
2226
  return resolve();
2221
2227
  }
2222
2228
  }
@@ -2227,6 +2233,39 @@ function exit$1() {
2227
2233
  fallbackToIOSVideo();
2228
2234
  });
2229
2235
  }
2236
+ function toggle$1(target, options) {
2237
+ var current = getElement$1();
2238
+ if (typeof target !== 'undefined') {
2239
+ if (current === target)
2240
+ return this.exit();
2241
+ return this.request(target, options);
2242
+ }
2243
+ if (current !== null)
2244
+ return this.exit();
2245
+ return this.request(undefined, options);
2246
+ }
2247
+ function onChange$1(targetOrListener, listenerOrOptions, options) {
2248
+ if (typeof targetOrListener === 'function')
2249
+ return onChangeSubscriptionManager$3.subscribe(targetOrListener, listenerOrOptions);
2250
+ var target = targetOrListener;
2251
+ var listener = listenerOrOptions;
2252
+ function wrappedListener(payload) {
2253
+ if (payload.element === target)
2254
+ listener(payload);
2255
+ }
2256
+ return onChangeSubscriptionManager$3.subscribe(wrappedListener, options);
2257
+ }
2258
+ function onError$1(targetOrListener, listenerOrOptions, options) {
2259
+ if (typeof targetOrListener === 'function')
2260
+ return onErrorSubscriptionManager$1.subscribe(targetOrListener, listenerOrOptions);
2261
+ var target = targetOrListener;
2262
+ var listener = listenerOrOptions;
2263
+ function wrappedListener(payload) {
2264
+ if (payload.element === target)
2265
+ listener(payload);
2266
+ }
2267
+ return onErrorSubscriptionManager$1.subscribe(wrappedListener, options);
2268
+ }
2230
2269
  bridgeEvents$1();
2231
2270
 
2232
2271
  var PermissionType;
@@ -4034,7 +4073,8 @@ function stop() {
4034
4073
 
4035
4074
  var PIP_PRESENTATION_MODE = 'picture-in-picture';
4036
4075
  var INLINE_PRESENTATION_MODE = 'inline';
4037
- var lastPipVideo = null;
4076
+ var videoElement = null;
4077
+ var lastFallbackVideoElement = null;
4038
4078
  var eventsBridged = false;
4039
4079
  var PIP_BRIDGE_KEY = (function () {
4040
4080
  if (typeof Symbol === 'function') {
@@ -4049,43 +4089,57 @@ var onChangeSubscriptionManager$1 = createSubscriptionManager(attachOnChange$1,
4049
4089
  var onErrorSubscriptionManager = createSubscriptionManager(attachOnError, detachOnError);
4050
4090
  var Pip = {
4051
4091
  get supported() {
4052
- return getEnabled();
4092
+ return getSupported();
4053
4093
  },
4054
4094
  get element() {
4055
4095
  return getElement();
4056
4096
  },
4057
- get isPip() {
4058
- return getIsPip();
4097
+ get isActive() {
4098
+ return getIsActive();
4059
4099
  },
4060
4100
  request: request,
4061
4101
  exit: exit,
4062
- onChange: onChangeSubscriptionManager$1.subscribe,
4063
- onError: onErrorSubscriptionManager.subscribe,
4102
+ toggle: toggle,
4103
+ onChange: onChange,
4104
+ onError: onError,
4064
4105
  Constants: {},
4065
4106
  Errors: {
4066
4107
  NotSupportedError: NotSupportedError,
4067
4108
  InvalidStateError: InvalidStateError,
4068
4109
  },
4069
4110
  };
4111
+ function getHTMLVideoElement() {
4112
+ var selected = globalThis.document.querySelector('video');
4113
+ if (selected !== null)
4114
+ return selected;
4115
+ if (videoElement === null)
4116
+ return videoElement = globalThis.document.createElement('video');
4117
+ return videoElement;
4118
+ }
4070
4119
  function hasStandardApi() {
4071
4120
  return typeof globalThis.document.pictureInPictureEnabled !== 'undefined';
4072
4121
  }
4122
+ function hasWebkitApi() {
4123
+ return typeof getHTMLVideoElement().webkitSetPresentationMode === 'function';
4124
+ }
4073
4125
  function getDefaultTarget() {
4074
4126
  var video = globalThis.document.querySelector('video');
4075
- return video !== null ? video : undefined;
4127
+ if (video !== null)
4128
+ return video;
4129
+ return undefined;
4076
4130
  }
4077
- function createPipEventPayload(nativeEvent, element, isPip) {
4131
+ function createPipEventPayload(nativeEvent, element, isActive) {
4078
4132
  return {
4079
4133
  nativeEvent: nativeEvent,
4080
4134
  element: element,
4081
- isPip: isPip
4135
+ isActive: isActive
4082
4136
  };
4083
4137
  }
4084
- function emitChange(nativeEvent, element, isPip) {
4085
- onChangeSubscriptionManager$1.emit(createPipEventPayload(nativeEvent, element, isPip));
4138
+ function emitChange(nativeEvent, element, isActive) {
4139
+ onChangeSubscriptionManager$1.emit(createPipEventPayload(nativeEvent, element, isActive));
4086
4140
  }
4087
- function emitError(nativeEvent, element, isPip) {
4088
- onErrorSubscriptionManager.emit(createPipEventPayload(nativeEvent, element, isPip));
4141
+ function emitError(nativeEvent, element, isActive) {
4142
+ onErrorSubscriptionManager.emit(createPipEventPayload(nativeEvent, element, isActive));
4089
4143
  }
4090
4144
  function onEnterPictureInPicture(event) {
4091
4145
  var target = event.target;
@@ -4100,16 +4154,16 @@ function onLeavePictureInPicture(event) {
4100
4154
  function onPictureInPictureError(event) {
4101
4155
  var target = event.target;
4102
4156
  if (target instanceof globalThis.HTMLVideoElement)
4103
- emitError(event, target, getIsPip());
4157
+ emitError(event, target, getIsActive());
4104
4158
  }
4105
4159
  function onWebkitPresentationModeChanged(event) {
4106
4160
  if (this.webkitPresentationMode === PIP_PRESENTATION_MODE) {
4107
- lastPipVideo = this;
4161
+ lastFallbackVideoElement = this;
4108
4162
  emitChange(event, this, true);
4109
4163
  return;
4110
4164
  }
4111
- if (this.webkitPresentationMode === INLINE_PRESENTATION_MODE && lastPipVideo === this) {
4112
- lastPipVideo = null;
4165
+ if (this.webkitPresentationMode === INLINE_PRESENTATION_MODE && lastFallbackVideoElement === this) {
4166
+ lastFallbackVideoElement = null;
4113
4167
  emitChange(event, this, false);
4114
4168
  }
4115
4169
  }
@@ -4130,19 +4184,19 @@ function bridgeEvents() {
4130
4184
  if (eventsBridged)
4131
4185
  return;
4132
4186
  eventsBridged = true;
4133
- if (hasStandardApi())
4187
+ if (hasStandardApi() && !hasWebkitApi())
4134
4188
  return;
4135
4189
  bridgeWebkitVideoEvents();
4136
4190
  if (typeof globalThis.MutationObserver === 'undefined')
4137
4191
  return;
4138
4192
  var observer = new globalThis.MutationObserver(function (records) {
4139
- if (lastPipVideo !== null) {
4193
+ if (lastFallbackVideoElement !== null) {
4140
4194
  var removed = false;
4141
4195
  for (var i = 0; i < records.length; i++) {
4142
4196
  var removedNodes = records[i].removedNodes;
4143
4197
  for (var j = 0; j < removedNodes.length; j++) {
4144
4198
  var node = removedNodes[j];
4145
- if (node === lastPipVideo || (node.nodeType === Node.ELEMENT_NODE && node.contains(lastPipVideo))) {
4199
+ if (node === lastFallbackVideoElement || (node.nodeType === Node.ELEMENT_NODE && node.contains(lastFallbackVideoElement))) {
4146
4200
  removed = true;
4147
4201
  break;
4148
4202
  }
@@ -4150,8 +4204,8 @@ function bridgeEvents() {
4150
4204
  if (removed)
4151
4205
  break;
4152
4206
  }
4153
- if (removed && !globalThis.document.contains(lastPipVideo))
4154
- lastPipVideo = null;
4207
+ if (removed && !globalThis.document.contains(lastFallbackVideoElement))
4208
+ lastFallbackVideoElement = null;
4155
4209
  }
4156
4210
  for (var i = 0; i < records.length; i++) {
4157
4211
  var addedNodes = records[i].addedNodes;
@@ -4198,26 +4252,21 @@ function attachOnError() {
4198
4252
  function detachOnError() {
4199
4253
  EventListener.remove(globalThis.document, { type: 'pictureinpictureerror', callback: onPictureInPictureError, options: false });
4200
4254
  }
4201
- function getEnabled() {
4255
+ function getSupported() {
4202
4256
  if (typeof globalThis.document.pictureInPictureEnabled === 'boolean')
4203
4257
  return globalThis.document.pictureInPictureEnabled;
4204
- var video;
4205
- var selected = globalThis.document.querySelector('video');
4206
- if (selected !== null)
4207
- video = selected;
4208
- else
4209
- video = globalThis.document.createElement('video');
4258
+ var video = getHTMLVideoElement();
4210
4259
  return typeof video.webkitSupportsPresentationMode === 'function' && video.webkitSupportsPresentationMode(PIP_PRESENTATION_MODE);
4211
4260
  }
4212
4261
  function getElement() {
4213
4262
  var currentElement = globalThis.document.pictureInPictureElement;
4214
4263
  if (currentElement !== null && typeof currentElement !== 'undefined')
4215
4264
  return currentElement;
4216
- if (lastPipVideo !== null && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE)
4217
- return lastPipVideo;
4265
+ if (lastFallbackVideoElement !== null && lastFallbackVideoElement.webkitPresentationMode === PIP_PRESENTATION_MODE)
4266
+ return lastFallbackVideoElement;
4218
4267
  return null;
4219
4268
  }
4220
- function getIsPip() {
4269
+ function getIsActive() {
4221
4270
  return getElement() !== null;
4222
4271
  }
4223
4272
  function request(target) {
@@ -4226,12 +4275,14 @@ function request(target) {
4226
4275
  target = getDefaultTarget();
4227
4276
  if (typeof target === 'undefined')
4228
4277
  return reject(new NotSupportedError('Failed to enter Picture-in-Picture mode.'));
4278
+ if (getIsActive() && getElement() !== target && Platform.browser.name === Browsers.Safari && Platform.os.name === OS.iOS)
4279
+ return reject(new NotSupportedError('There is already a Picture-in-Picture element in this document.'));
4229
4280
  var tagName = target.tagName.toLowerCase();
4230
4281
  if (tagName !== 'video')
4231
4282
  return reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
4232
4283
  var method = target.requestPictureInPicture;
4233
- var isWebkitPipActive = lastPipVideo !== null && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE;
4234
- if (typeof method === 'function' && !isWebkitPipActive) {
4284
+ var isWebkitPipActive = lastFallbackVideoElement !== null && lastFallbackVideoElement.webkitPresentationMode === PIP_PRESENTATION_MODE;
4285
+ if (typeof method === 'function' && !hasWebkitApi() && !isWebkitPipActive) {
4235
4286
  var result = method.call(target);
4236
4287
  if (typeof result !== 'undefined' && typeof result.then === 'function') {
4237
4288
  result
@@ -4252,12 +4303,8 @@ function request(target) {
4252
4303
  if (typeof target !== 'undefined' && typeof target.webkitSupportsPresentationMode === 'function' && target.webkitSupportsPresentationMode(PIP_PRESENTATION_MODE) && typeof target.webkitSetPresentationMode === 'function') {
4253
4304
  if (target.disablePictureInPicture)
4254
4305
  return reject(new NotSupportedError('Picture-in-Picture is disabled on this element.'));
4255
- if (!hasStandardApi())
4256
- bridgeSingleVideoNode(target);
4306
+ bridgeSingleVideoNode(target);
4257
4307
  target.webkitSetPresentationMode(PIP_PRESENTATION_MODE);
4258
- if (target.webkitPresentationMode !== PIP_PRESENTATION_MODE)
4259
- return reject(new InvalidStateError('Picture-in-Picture transition is already in progress.'));
4260
- lastPipVideo = target;
4261
4308
  return resolve();
4262
4309
  }
4263
4310
  reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
@@ -4268,7 +4315,7 @@ function request(target) {
4268
4315
  function exit() {
4269
4316
  return new Promise(function (resolve, reject) {
4270
4317
  var method = globalThis.document.exitPictureInPicture;
4271
- if (typeof method === 'function') {
4318
+ if (typeof method === 'function' && !hasWebkitApi()) {
4272
4319
  var result = method.call(globalThis.document);
4273
4320
  if (typeof result !== 'undefined' && typeof result.then === 'function') {
4274
4321
  result
@@ -4286,9 +4333,8 @@ function exit() {
4286
4333
  return resolve();
4287
4334
  }
4288
4335
  function fallbackToWebkit() {
4289
- if (lastPipVideo !== null && typeof lastPipVideo.webkitSetPresentationMode === 'function' && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE) {
4290
- lastPipVideo.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
4291
- lastPipVideo = null;
4336
+ if (lastFallbackVideoElement !== null && typeof lastFallbackVideoElement.webkitSetPresentationMode === 'function') {
4337
+ lastFallbackVideoElement.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
4292
4338
  return resolve();
4293
4339
  }
4294
4340
  var videos = globalThis.document.querySelectorAll('video');
@@ -4296,17 +4342,49 @@ function exit() {
4296
4342
  var video = videos[i];
4297
4343
  if (typeof video.webkitSetPresentationMode === 'function' && video.webkitPresentationMode === PIP_PRESENTATION_MODE) {
4298
4344
  video.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
4299
- lastPipVideo = null;
4300
4345
  return resolve();
4301
4346
  }
4302
4347
  }
4303
- if (globalThis.document.pictureInPictureElement === null || typeof globalThis.document.pictureInPictureElement === 'undefined')
4304
- return resolve();
4305
- reject(new NotSupportedError('Failed to exit Picture-in-Picture mode.'));
4348
+ return resolve();
4306
4349
  }
4307
4350
  fallbackToWebkit();
4308
4351
  });
4309
4352
  }
4353
+ function toggle(target) {
4354
+ var current = getElement();
4355
+ if (typeof target !== 'undefined') {
4356
+ if (current === target)
4357
+ return this.exit();
4358
+ else
4359
+ return this.request(target);
4360
+ }
4361
+ if (current !== null)
4362
+ return this.exit();
4363
+ else
4364
+ return this.request(target);
4365
+ }
4366
+ function onChange(targetOrListener, listenerOrOptions, options) {
4367
+ if (typeof targetOrListener === 'function')
4368
+ return onChangeSubscriptionManager$1.subscribe(targetOrListener, listenerOrOptions);
4369
+ var target = targetOrListener;
4370
+ var listener = listenerOrOptions;
4371
+ function wrappedListener(payload) {
4372
+ if (payload.element === target)
4373
+ listener(payload);
4374
+ }
4375
+ return onChangeSubscriptionManager$1.subscribe(wrappedListener, options);
4376
+ }
4377
+ function onError(targetOrListener, listenerOrOptions, options) {
4378
+ if (typeof targetOrListener === 'function')
4379
+ return onErrorSubscriptionManager.subscribe(targetOrListener, listenerOrOptions);
4380
+ var target = targetOrListener;
4381
+ var listener = listenerOrOptions;
4382
+ function wrappedListener(payload) {
4383
+ if (payload.element === target)
4384
+ listener(payload);
4385
+ }
4386
+ return onErrorSubscriptionManager.subscribe(wrappedListener, options);
4387
+ }
4310
4388
  bridgeEvents();
4311
4389
 
4312
4390
  var Badge = {