native-fn 1.2.0 → 1.2.2

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