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
@@ -4,7 +4,7 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Native = factory());
5
5
  })(this, (function () { 'use strict';
6
6
 
7
- var version = "1.2.0";
7
+ var version = "1.2.2";
8
8
  var packageJSON = {
9
9
  version: version};
10
10
 
@@ -693,10 +693,15 @@
693
693
  parsedFromHighEntropyValuesEngine.version = brandVersion;
694
694
  }
695
695
  if (typeof platformVersion === 'string') {
696
- if (getParsedCache().os.name === OS.Windows)
697
- parsedFromHighEntropyValuesOS.version = parseInt(platformVersion.split('.')[0], 10) >= 13 ? '11' : '10';
698
- else
696
+ if (getParsedCache().os.name === OS.Windows) {
697
+ if (parseInt(platformVersion.split('.')[0], 10) >= 13)
698
+ parsedFromHighEntropyValuesOS.version = '11';
699
+ else
700
+ parsedFromHighEntropyValuesOS.version = '10';
701
+ }
702
+ else {
699
703
  parsedFromHighEntropyValuesOS.version = platformVersion;
704
+ }
700
705
  }
701
706
  if (typeof platform === 'string') {
702
707
  if (/android/i.test(platform))
@@ -1873,7 +1878,8 @@
1873
1878
 
1874
1879
  var InvalidStateError = createCustomError('InvalidStateError');
1875
1880
 
1876
- var lastIOSVideo = null;
1881
+ var videoElement$1 = null;
1882
+ var lastFallbackVideoElement$1 = null;
1877
1883
  var eventsBridged$1 = false;
1878
1884
  var FS_BRIDGE_KEY = (function () {
1879
1885
  if (typeof Symbol === 'function') {
@@ -1919,24 +1925,33 @@
1919
1925
  var onErrorSubscriptionManager$1 = createSubscriptionManager(attachOnError$1, detachOnError$1);
1920
1926
  var Fullscreen = {
1921
1927
  get supported() {
1922
- return getEnabled$1();
1928
+ return getSupported$1();
1923
1929
  },
1924
1930
  get element() {
1925
1931
  return getElement$1();
1926
1932
  },
1927
- get isFullscreen() {
1928
- return getIsFullscreen();
1933
+ get isActive() {
1934
+ return getIsActive$1();
1929
1935
  },
1930
1936
  request: request$3,
1931
1937
  exit: exit$1,
1932
- onChange: onChangeSubscriptionManager$3.subscribe,
1933
- onError: onErrorSubscriptionManager$1.subscribe,
1938
+ toggle: toggle$1,
1939
+ onChange: onChange$1,
1940
+ onError: onError$1,
1934
1941
  Constants: {},
1935
1942
  Errors: {
1936
1943
  NotSupportedError: NotSupportedError,
1937
1944
  InvalidStateError: InvalidStateError,
1938
1945
  },
1939
1946
  };
1947
+ function getHTMLVideoElement$1() {
1948
+ var selected = globalThis.document.querySelector('video');
1949
+ if (selected !== null)
1950
+ return selected;
1951
+ if (videoElement$1 === null)
1952
+ return videoElement$1 = globalThis.document.createElement('video');
1953
+ return videoElement$1;
1954
+ }
1940
1955
  function hasStandardApi$1() {
1941
1956
  return api !== null;
1942
1957
  }
@@ -1959,27 +1974,24 @@
1959
1974
  function getDefaultTarget$1() {
1960
1975
  if (Platform.os.name === OS.iOS) {
1961
1976
  var video = globalThis.document.querySelector('video');
1962
- return video !== null ? video : undefined;
1977
+ if (video !== null)
1978
+ return video;
1979
+ return undefined;
1963
1980
  }
1964
1981
  return globalThis.document.documentElement;
1965
1982
  }
1966
- function getEnabled$1() {
1983
+ function getSupported$1() {
1967
1984
  if (api !== null)
1968
1985
  return globalThis.document[api.enabled] === true;
1969
1986
  if (Platform.os.name !== OS.iOS)
1970
1987
  return false;
1971
- var video;
1972
- var selected = globalThis.document.querySelector('video');
1973
- if (selected !== null)
1974
- video = selected;
1975
- else
1976
- video = globalThis.document.createElement('video');
1988
+ var video = getHTMLVideoElement$1();
1977
1989
  return video.webkitSupportsFullscreen === true || typeof video.webkitEnterFullscreen === 'function';
1978
1990
  }
1979
1991
  function getElement$1() {
1980
1992
  if (api === null) {
1981
- if (lastIOSVideo !== null && lastIOSVideo.webkitDisplayingFullscreen === true)
1982
- return lastIOSVideo;
1993
+ if (lastFallbackVideoElement$1 !== null && lastFallbackVideoElement$1.webkitDisplayingFullscreen === true)
1994
+ return lastFallbackVideoElement$1;
1983
1995
  return null;
1984
1996
  }
1985
1997
  var currentElement = globalThis.document[api.element];
@@ -1987,43 +1999,43 @@
1987
1999
  return currentElement;
1988
2000
  return null;
1989
2001
  }
1990
- function getIsFullscreen() {
2002
+ function getIsActive$1() {
1991
2003
  return getElement$1() !== null;
1992
2004
  }
1993
- function createEventPayload(nativeEvent, element, isFullscreen) {
2005
+ function createEventPayload(nativeEvent, element, isActive) {
1994
2006
  return {
1995
2007
  nativeEvent: nativeEvent,
1996
2008
  element: element,
1997
- isFullscreen: isFullscreen,
2009
+ isActive: isActive,
1998
2010
  };
1999
2011
  }
2000
- function emitChange$1(nativeEvent, element, isFullscreen) {
2001
- onChangeSubscriptionManager$3.emit(createEventPayload(nativeEvent, element, isFullscreen));
2012
+ function emitChange$1(nativeEvent, element, isActive) {
2013
+ onChangeSubscriptionManager$3.emit(createEventPayload(nativeEvent, element, isActive));
2002
2014
  }
2003
- function emitError$1(nativeEvent, element, isFullscreen) {
2004
- onErrorSubscriptionManager$1.emit(createEventPayload(nativeEvent, element, isFullscreen));
2015
+ function emitError$1(nativeEvent, element, isActive) {
2016
+ onErrorSubscriptionManager$1.emit(createEventPayload(nativeEvent, element, isActive));
2005
2017
  }
2006
2018
  function onFullscreenChange(event) {
2007
2019
  var target = event.target;
2008
2020
  if (target instanceof globalThis.Element)
2009
- emitChange$1(event, target, getIsFullscreen());
2021
+ emitChange$1(event, target, getIsActive$1());
2010
2022
  if (target instanceof globalThis.Document)
2011
- emitChange$1(event, globalThis.document.documentElement, getIsFullscreen());
2023
+ emitChange$1(event, globalThis.document.documentElement, getIsActive$1());
2012
2024
  }
2013
2025
  function onFullscreenError(event) {
2014
2026
  var target = event.target;
2015
2027
  if (target instanceof globalThis.Element)
2016
- emitError$1(event, target, getIsFullscreen());
2028
+ emitError$1(event, target, getIsActive$1());
2017
2029
  if (target instanceof globalThis.Document)
2018
- emitError$1(event, globalThis.document.documentElement, getIsFullscreen());
2030
+ emitError$1(event, globalThis.document.documentElement, getIsActive$1());
2019
2031
  }
2020
2032
  function onIOSBeginFullscreen(event) {
2021
- lastIOSVideo = this;
2033
+ lastFallbackVideoElement$1 = this;
2022
2034
  emitChange$1(event, this, true);
2023
2035
  }
2024
2036
  function onIOSEndFullscreen(event) {
2025
- if (lastIOSVideo === this)
2026
- lastIOSVideo = null;
2037
+ if (lastFallbackVideoElement$1 === this)
2038
+ lastFallbackVideoElement$1 = null;
2027
2039
  emitChange$1(event, this, false);
2028
2040
  }
2029
2041
  function bridgeSingleVideoNode$1(video) {
@@ -2050,13 +2062,13 @@
2050
2062
  if (typeof globalThis.MutationObserver === 'undefined')
2051
2063
  return;
2052
2064
  var observer = new globalThis.MutationObserver(function (records) {
2053
- if (lastIOSVideo !== null) {
2065
+ if (lastFallbackVideoElement$1 !== null) {
2054
2066
  var removed = false;
2055
2067
  for (var i = 0; i < records.length; i++) {
2056
2068
  var removedNodes = records[i].removedNodes;
2057
2069
  for (var j = 0; j < removedNodes.length; j++) {
2058
2070
  var node = removedNodes[j];
2059
- if (node === lastIOSVideo || (node.nodeType === Node.ELEMENT_NODE && node.contains(lastIOSVideo))) {
2071
+ if (node === lastFallbackVideoElement$1 || (node.nodeType === Node.ELEMENT_NODE && node.contains(lastFallbackVideoElement$1))) {
2060
2072
  removed = true;
2061
2073
  break;
2062
2074
  }
@@ -2064,8 +2076,8 @@
2064
2076
  if (removed)
2065
2077
  break;
2066
2078
  }
2067
- if (removed && !globalThis.document.contains(lastIOSVideo))
2068
- lastIOSVideo = null;
2079
+ if (removed && !globalThis.document.contains(lastFallbackVideoElement$1))
2080
+ lastFallbackVideoElement$1 = null;
2069
2081
  }
2070
2082
  for (var i = 0; i < records.length; i++) {
2071
2083
  var addedNodes = records[i].addedNodes;
@@ -2118,8 +2130,10 @@
2118
2130
  target = getDefaultTarget$1();
2119
2131
  if (typeof target === 'undefined')
2120
2132
  return reject(new NotSupportedError('Failed to enter fullscreen mode.'));
2133
+ if (getIsActive$1() && getElement$1() !== target && Platform.browser.name === Browsers.Safari && Platform.os.name === OS.iOS)
2134
+ return reject(new NotSupportedError('There is already a Fullscreen element in this document.'));
2121
2135
  var tagName = target.tagName.toLowerCase();
2122
- var isIOSFullscreenActive = lastIOSVideo !== null && lastIOSVideo.webkitDisplayingFullscreen === true;
2136
+ var isIOSFullscreenActive = lastFallbackVideoElement$1 !== null && lastFallbackVideoElement$1.webkitDisplayingFullscreen === true;
2123
2137
  if (api !== null) {
2124
2138
  var method = target[api.request];
2125
2139
  if (typeof method === 'function' && !isIOSFullscreenActive) {
@@ -2133,7 +2147,7 @@
2133
2147
  return reject(new NotSupportedError('The "' + tagName + '" element does not support fullscreen requests.'));
2134
2148
  fallbackToIOSVideo();
2135
2149
  }
2136
- catch (_e) {
2150
+ catch (e) {
2137
2151
  reject(new NotSupportedError('The "' + tagName + '" element does not support fullscreen requests.'));
2138
2152
  }
2139
2153
  });
@@ -2152,7 +2166,8 @@
2152
2166
  video_1.play()
2153
2167
  .then(function () {
2154
2168
  try {
2155
- video_1.webkitEnterFullscreen();
2169
+ if (video_1.webkitSupportsFullscreen && typeof video_1.webkitEnterFullscreen === 'function')
2170
+ video_1.webkitEnterFullscreen();
2156
2171
  }
2157
2172
  catch (e) {
2158
2173
  return reject(new InvalidStateError('The object is in an invalid state.'));
@@ -2167,7 +2182,7 @@
2167
2182
  return reject(new InvalidStateError('The object is in an invalid state.'));
2168
2183
  }
2169
2184
  }
2170
- lastIOSVideo = video_1;
2185
+ lastFallbackVideoElement$1 = video_1;
2171
2186
  return resolve();
2172
2187
  }
2173
2188
  }
@@ -2185,16 +2200,7 @@
2185
2200
  if (typeof result !== 'undefined' && typeof result.then === 'function') {
2186
2201
  result
2187
2202
  .then(resolve)
2188
- .catch(function () {
2189
- try {
2190
- if (Platform.os.name !== OS.iOS)
2191
- return reject(new NotSupportedError('Failed to exit fullscreen mode.'));
2192
- fallbackToIOSVideo();
2193
- }
2194
- catch (_e) {
2195
- reject(new NotSupportedError('Failed to exit fullscreen mode.'));
2196
- }
2197
- });
2203
+ .catch(resolve);
2198
2204
  return;
2199
2205
  }
2200
2206
  return resolve();
@@ -2205,12 +2211,12 @@
2205
2211
  reject(new NotSupportedError('Failed to exit fullscreen mode.'));
2206
2212
  return;
2207
2213
  }
2208
- var target = lastIOSVideo;
2214
+ var target = lastFallbackVideoElement$1;
2209
2215
  if (target !== null && typeof target.webkitExitFullscreen === 'function' && target.webkitDisplayingFullscreen === true) {
2210
2216
  target.webkitExitFullscreen();
2211
2217
  if (target.webkitDisplayingFullscreen)
2212
2218
  return reject(new NotSupportedError('Failed to exit fullscreen mode.'));
2213
- lastIOSVideo = null;
2219
+ lastFallbackVideoElement$1 = null;
2214
2220
  return resolve();
2215
2221
  }
2216
2222
  var videos = globalThis.document.querySelectorAll('video');
@@ -2220,7 +2226,7 @@
2220
2226
  video.webkitExitFullscreen();
2221
2227
  if (video.webkitDisplayingFullscreen)
2222
2228
  return reject(new NotSupportedError('Failed to exit fullscreen mode.'));
2223
- lastIOSVideo = null;
2229
+ lastFallbackVideoElement$1 = null;
2224
2230
  return resolve();
2225
2231
  }
2226
2232
  }
@@ -2231,6 +2237,39 @@
2231
2237
  fallbackToIOSVideo();
2232
2238
  });
2233
2239
  }
2240
+ function toggle$1(target, options) {
2241
+ var current = getElement$1();
2242
+ if (typeof target !== 'undefined') {
2243
+ if (current === target)
2244
+ return this.exit();
2245
+ return this.request(target, options);
2246
+ }
2247
+ if (current !== null)
2248
+ return this.exit();
2249
+ return this.request(undefined, options);
2250
+ }
2251
+ function onChange$1(targetOrListener, listenerOrOptions, options) {
2252
+ if (typeof targetOrListener === 'function')
2253
+ return onChangeSubscriptionManager$3.subscribe(targetOrListener, listenerOrOptions);
2254
+ var target = targetOrListener;
2255
+ var listener = listenerOrOptions;
2256
+ function wrappedListener(payload) {
2257
+ if (payload.element === target)
2258
+ listener(payload);
2259
+ }
2260
+ return onChangeSubscriptionManager$3.subscribe(wrappedListener, options);
2261
+ }
2262
+ function onError$1(targetOrListener, listenerOrOptions, options) {
2263
+ if (typeof targetOrListener === 'function')
2264
+ return onErrorSubscriptionManager$1.subscribe(targetOrListener, listenerOrOptions);
2265
+ var target = targetOrListener;
2266
+ var listener = listenerOrOptions;
2267
+ function wrappedListener(payload) {
2268
+ if (payload.element === target)
2269
+ listener(payload);
2270
+ }
2271
+ return onErrorSubscriptionManager$1.subscribe(wrappedListener, options);
2272
+ }
2234
2273
  bridgeEvents$1();
2235
2274
 
2236
2275
  var PermissionType;
@@ -4038,7 +4077,8 @@
4038
4077
 
4039
4078
  var PIP_PRESENTATION_MODE = 'picture-in-picture';
4040
4079
  var INLINE_PRESENTATION_MODE = 'inline';
4041
- var lastPipVideo = null;
4080
+ var videoElement = null;
4081
+ var lastFallbackVideoElement = null;
4042
4082
  var eventsBridged = false;
4043
4083
  var PIP_BRIDGE_KEY = (function () {
4044
4084
  if (typeof Symbol === 'function') {
@@ -4053,43 +4093,57 @@
4053
4093
  var onErrorSubscriptionManager = createSubscriptionManager(attachOnError, detachOnError);
4054
4094
  var Pip = {
4055
4095
  get supported() {
4056
- return getEnabled();
4096
+ return getSupported();
4057
4097
  },
4058
4098
  get element() {
4059
4099
  return getElement();
4060
4100
  },
4061
- get isPip() {
4062
- return getIsPip();
4101
+ get isActive() {
4102
+ return getIsActive();
4063
4103
  },
4064
4104
  request: request,
4065
4105
  exit: exit,
4066
- onChange: onChangeSubscriptionManager$1.subscribe,
4067
- onError: onErrorSubscriptionManager.subscribe,
4106
+ toggle: toggle,
4107
+ onChange: onChange,
4108
+ onError: onError,
4068
4109
  Constants: {},
4069
4110
  Errors: {
4070
4111
  NotSupportedError: NotSupportedError,
4071
4112
  InvalidStateError: InvalidStateError,
4072
4113
  },
4073
4114
  };
4115
+ function getHTMLVideoElement() {
4116
+ var selected = globalThis.document.querySelector('video');
4117
+ if (selected !== null)
4118
+ return selected;
4119
+ if (videoElement === null)
4120
+ return videoElement = globalThis.document.createElement('video');
4121
+ return videoElement;
4122
+ }
4074
4123
  function hasStandardApi() {
4075
4124
  return typeof globalThis.document.pictureInPictureEnabled !== 'undefined';
4076
4125
  }
4126
+ function hasWebkitApi() {
4127
+ return typeof getHTMLVideoElement().webkitSetPresentationMode === 'function';
4128
+ }
4077
4129
  function getDefaultTarget() {
4078
4130
  var video = globalThis.document.querySelector('video');
4079
- return video !== null ? video : undefined;
4131
+ if (video !== null)
4132
+ return video;
4133
+ return undefined;
4080
4134
  }
4081
- function createPipEventPayload(nativeEvent, element, isPip) {
4135
+ function createPipEventPayload(nativeEvent, element, isActive) {
4082
4136
  return {
4083
4137
  nativeEvent: nativeEvent,
4084
4138
  element: element,
4085
- isPip: isPip
4139
+ isActive: isActive
4086
4140
  };
4087
4141
  }
4088
- function emitChange(nativeEvent, element, isPip) {
4089
- onChangeSubscriptionManager$1.emit(createPipEventPayload(nativeEvent, element, isPip));
4142
+ function emitChange(nativeEvent, element, isActive) {
4143
+ onChangeSubscriptionManager$1.emit(createPipEventPayload(nativeEvent, element, isActive));
4090
4144
  }
4091
- function emitError(nativeEvent, element, isPip) {
4092
- onErrorSubscriptionManager.emit(createPipEventPayload(nativeEvent, element, isPip));
4145
+ function emitError(nativeEvent, element, isActive) {
4146
+ onErrorSubscriptionManager.emit(createPipEventPayload(nativeEvent, element, isActive));
4093
4147
  }
4094
4148
  function onEnterPictureInPicture(event) {
4095
4149
  var target = event.target;
@@ -4104,16 +4158,16 @@
4104
4158
  function onPictureInPictureError(event) {
4105
4159
  var target = event.target;
4106
4160
  if (target instanceof globalThis.HTMLVideoElement)
4107
- emitError(event, target, getIsPip());
4161
+ emitError(event, target, getIsActive());
4108
4162
  }
4109
4163
  function onWebkitPresentationModeChanged(event) {
4110
4164
  if (this.webkitPresentationMode === PIP_PRESENTATION_MODE) {
4111
- lastPipVideo = this;
4165
+ lastFallbackVideoElement = this;
4112
4166
  emitChange(event, this, true);
4113
4167
  return;
4114
4168
  }
4115
- if (this.webkitPresentationMode === INLINE_PRESENTATION_MODE && lastPipVideo === this) {
4116
- lastPipVideo = null;
4169
+ if (this.webkitPresentationMode === INLINE_PRESENTATION_MODE && lastFallbackVideoElement === this) {
4170
+ lastFallbackVideoElement = null;
4117
4171
  emitChange(event, this, false);
4118
4172
  }
4119
4173
  }
@@ -4134,19 +4188,19 @@
4134
4188
  if (eventsBridged)
4135
4189
  return;
4136
4190
  eventsBridged = true;
4137
- if (hasStandardApi())
4191
+ if (hasStandardApi() && !hasWebkitApi())
4138
4192
  return;
4139
4193
  bridgeWebkitVideoEvents();
4140
4194
  if (typeof globalThis.MutationObserver === 'undefined')
4141
4195
  return;
4142
4196
  var observer = new globalThis.MutationObserver(function (records) {
4143
- if (lastPipVideo !== null) {
4197
+ if (lastFallbackVideoElement !== null) {
4144
4198
  var removed = false;
4145
4199
  for (var i = 0; i < records.length; i++) {
4146
4200
  var removedNodes = records[i].removedNodes;
4147
4201
  for (var j = 0; j < removedNodes.length; j++) {
4148
4202
  var node = removedNodes[j];
4149
- if (node === lastPipVideo || (node.nodeType === Node.ELEMENT_NODE && node.contains(lastPipVideo))) {
4203
+ if (node === lastFallbackVideoElement || (node.nodeType === Node.ELEMENT_NODE && node.contains(lastFallbackVideoElement))) {
4150
4204
  removed = true;
4151
4205
  break;
4152
4206
  }
@@ -4154,8 +4208,8 @@
4154
4208
  if (removed)
4155
4209
  break;
4156
4210
  }
4157
- if (removed && !globalThis.document.contains(lastPipVideo))
4158
- lastPipVideo = null;
4211
+ if (removed && !globalThis.document.contains(lastFallbackVideoElement))
4212
+ lastFallbackVideoElement = null;
4159
4213
  }
4160
4214
  for (var i = 0; i < records.length; i++) {
4161
4215
  var addedNodes = records[i].addedNodes;
@@ -4202,26 +4256,21 @@
4202
4256
  function detachOnError() {
4203
4257
  EventListener.remove(globalThis.document, { type: 'pictureinpictureerror', callback: onPictureInPictureError, options: false });
4204
4258
  }
4205
- function getEnabled() {
4259
+ function getSupported() {
4206
4260
  if (typeof globalThis.document.pictureInPictureEnabled === 'boolean')
4207
4261
  return globalThis.document.pictureInPictureEnabled;
4208
- var video;
4209
- var selected = globalThis.document.querySelector('video');
4210
- if (selected !== null)
4211
- video = selected;
4212
- else
4213
- video = globalThis.document.createElement('video');
4262
+ var video = getHTMLVideoElement();
4214
4263
  return typeof video.webkitSupportsPresentationMode === 'function' && video.webkitSupportsPresentationMode(PIP_PRESENTATION_MODE);
4215
4264
  }
4216
4265
  function getElement() {
4217
4266
  var currentElement = globalThis.document.pictureInPictureElement;
4218
4267
  if (currentElement !== null && typeof currentElement !== 'undefined')
4219
4268
  return currentElement;
4220
- if (lastPipVideo !== null && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE)
4221
- return lastPipVideo;
4269
+ if (lastFallbackVideoElement !== null && lastFallbackVideoElement.webkitPresentationMode === PIP_PRESENTATION_MODE)
4270
+ return lastFallbackVideoElement;
4222
4271
  return null;
4223
4272
  }
4224
- function getIsPip() {
4273
+ function getIsActive() {
4225
4274
  return getElement() !== null;
4226
4275
  }
4227
4276
  function request(target) {
@@ -4230,12 +4279,14 @@
4230
4279
  target = getDefaultTarget();
4231
4280
  if (typeof target === 'undefined')
4232
4281
  return reject(new NotSupportedError('Failed to enter Picture-in-Picture mode.'));
4282
+ if (getIsActive() && getElement() !== target && Platform.browser.name === Browsers.Safari && Platform.os.name === OS.iOS)
4283
+ return reject(new NotSupportedError('There is already a Picture-in-Picture element in this document.'));
4233
4284
  var tagName = target.tagName.toLowerCase();
4234
4285
  if (tagName !== 'video')
4235
4286
  return reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
4236
4287
  var method = target.requestPictureInPicture;
4237
- var isWebkitPipActive = lastPipVideo !== null && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE;
4238
- if (typeof method === 'function' && !isWebkitPipActive) {
4288
+ var isWebkitPipActive = lastFallbackVideoElement !== null && lastFallbackVideoElement.webkitPresentationMode === PIP_PRESENTATION_MODE;
4289
+ if (typeof method === 'function' && !hasWebkitApi() && !isWebkitPipActive) {
4239
4290
  var result = method.call(target);
4240
4291
  if (typeof result !== 'undefined' && typeof result.then === 'function') {
4241
4292
  result
@@ -4256,12 +4307,8 @@
4256
4307
  if (typeof target !== 'undefined' && typeof target.webkitSupportsPresentationMode === 'function' && target.webkitSupportsPresentationMode(PIP_PRESENTATION_MODE) && typeof target.webkitSetPresentationMode === 'function') {
4257
4308
  if (target.disablePictureInPicture)
4258
4309
  return reject(new NotSupportedError('Picture-in-Picture is disabled on this element.'));
4259
- if (!hasStandardApi())
4260
- bridgeSingleVideoNode(target);
4310
+ bridgeSingleVideoNode(target);
4261
4311
  target.webkitSetPresentationMode(PIP_PRESENTATION_MODE);
4262
- if (target.webkitPresentationMode !== PIP_PRESENTATION_MODE)
4263
- return reject(new InvalidStateError('Picture-in-Picture transition is already in progress.'));
4264
- lastPipVideo = target;
4265
4312
  return resolve();
4266
4313
  }
4267
4314
  reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
@@ -4272,7 +4319,7 @@
4272
4319
  function exit() {
4273
4320
  return new Promise(function (resolve, reject) {
4274
4321
  var method = globalThis.document.exitPictureInPicture;
4275
- if (typeof method === 'function') {
4322
+ if (typeof method === 'function' && !hasWebkitApi()) {
4276
4323
  var result = method.call(globalThis.document);
4277
4324
  if (typeof result !== 'undefined' && typeof result.then === 'function') {
4278
4325
  result
@@ -4290,9 +4337,8 @@
4290
4337
  return resolve();
4291
4338
  }
4292
4339
  function fallbackToWebkit() {
4293
- if (lastPipVideo !== null && typeof lastPipVideo.webkitSetPresentationMode === 'function' && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE) {
4294
- lastPipVideo.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
4295
- lastPipVideo = null;
4340
+ if (lastFallbackVideoElement !== null && typeof lastFallbackVideoElement.webkitSetPresentationMode === 'function') {
4341
+ lastFallbackVideoElement.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
4296
4342
  return resolve();
4297
4343
  }
4298
4344
  var videos = globalThis.document.querySelectorAll('video');
@@ -4300,17 +4346,49 @@
4300
4346
  var video = videos[i];
4301
4347
  if (typeof video.webkitSetPresentationMode === 'function' && video.webkitPresentationMode === PIP_PRESENTATION_MODE) {
4302
4348
  video.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
4303
- lastPipVideo = null;
4304
4349
  return resolve();
4305
4350
  }
4306
4351
  }
4307
- if (globalThis.document.pictureInPictureElement === null || typeof globalThis.document.pictureInPictureElement === 'undefined')
4308
- return resolve();
4309
- reject(new NotSupportedError('Failed to exit Picture-in-Picture mode.'));
4352
+ return resolve();
4310
4353
  }
4311
4354
  fallbackToWebkit();
4312
4355
  });
4313
4356
  }
4357
+ function toggle(target) {
4358
+ var current = getElement();
4359
+ if (typeof target !== 'undefined') {
4360
+ if (current === target)
4361
+ return this.exit();
4362
+ else
4363
+ return this.request(target);
4364
+ }
4365
+ if (current !== null)
4366
+ return this.exit();
4367
+ else
4368
+ return this.request(target);
4369
+ }
4370
+ function onChange(targetOrListener, listenerOrOptions, options) {
4371
+ if (typeof targetOrListener === 'function')
4372
+ return onChangeSubscriptionManager$1.subscribe(targetOrListener, listenerOrOptions);
4373
+ var target = targetOrListener;
4374
+ var listener = listenerOrOptions;
4375
+ function wrappedListener(payload) {
4376
+ if (payload.element === target)
4377
+ listener(payload);
4378
+ }
4379
+ return onChangeSubscriptionManager$1.subscribe(wrappedListener, options);
4380
+ }
4381
+ function onError(targetOrListener, listenerOrOptions, options) {
4382
+ if (typeof targetOrListener === 'function')
4383
+ return onErrorSubscriptionManager.subscribe(targetOrListener, listenerOrOptions);
4384
+ var target = targetOrListener;
4385
+ var listener = listenerOrOptions;
4386
+ function wrappedListener(payload) {
4387
+ if (payload.element === target)
4388
+ listener(payload);
4389
+ }
4390
+ return onErrorSubscriptionManager.subscribe(wrappedListener, options);
4391
+ }
4314
4392
  bridgeEvents();
4315
4393
 
4316
4394
  var Badge = {