native-fn 1.1.9 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/README.md +488 -146
  2. package/dist/index.d.ts +130 -117
  3. package/dist/native.cjs +581 -563
  4. package/dist/native.min.cjs +1 -1
  5. package/dist/native.min.mjs +1 -1
  6. package/dist/native.mjs +581 -563
  7. package/dist/native.umd.js +581 -563
  8. package/dist/native.umd.min.js +1 -1
  9. package/dist/plugin/appearance/src/errors/invalid-state-error.d.ts +2 -0
  10. package/dist/plugin/appearance/src/plugin/badge/types/badge.d.ts +1 -1
  11. package/dist/plugin/appearance/src/plugin/battery/types/battery.d.ts +1 -1
  12. package/dist/plugin/appearance/src/plugin/fullscreen/cores/index.d.ts +3 -3
  13. package/dist/plugin/appearance/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  14. package/dist/plugin/appearance/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  15. package/dist/plugin/appearance/src/plugin/open/types/open.d.ts +1 -1
  16. package/dist/plugin/appearance/src/plugin/permission/types/permission.d.ts +1 -0
  17. package/dist/plugin/appearance/src/plugin/pip/cores/index.d.ts +6 -6
  18. package/dist/plugin/appearance/src/plugin/pip/types/pip.d.ts +12 -6
  19. package/dist/plugin/appearance/src/plugin/vibration/types/vibration.d.ts +1 -1
  20. package/dist/plugin/badge/index.cjs +2 -2
  21. package/dist/plugin/badge/index.d.ts +1 -1
  22. package/dist/plugin/badge/index.mjs +2 -2
  23. package/dist/plugin/badge/src/errors/invalid-state-error.d.ts +2 -0
  24. package/dist/plugin/badge/src/plugin/badge/types/badge.d.ts +1 -1
  25. package/dist/plugin/badge/src/plugin/battery/types/battery.d.ts +1 -1
  26. package/dist/plugin/badge/src/plugin/fullscreen/cores/index.d.ts +3 -3
  27. package/dist/plugin/badge/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  28. package/dist/plugin/badge/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  29. package/dist/plugin/badge/src/plugin/open/types/open.d.ts +1 -1
  30. package/dist/plugin/badge/src/plugin/permission/types/permission.d.ts +1 -0
  31. package/dist/plugin/badge/src/plugin/pip/cores/index.d.ts +6 -6
  32. package/dist/plugin/badge/src/plugin/pip/types/pip.d.ts +12 -6
  33. package/dist/plugin/badge/src/plugin/vibration/types/vibration.d.ts +1 -1
  34. package/dist/plugin/battery/index.cjs +3 -3
  35. package/dist/plugin/battery/index.d.ts +1 -1
  36. package/dist/plugin/battery/index.mjs +3 -3
  37. package/dist/plugin/battery/src/errors/invalid-state-error.d.ts +2 -0
  38. package/dist/plugin/battery/src/plugin/badge/types/badge.d.ts +1 -1
  39. package/dist/plugin/battery/src/plugin/battery/types/battery.d.ts +1 -1
  40. package/dist/plugin/battery/src/plugin/fullscreen/cores/index.d.ts +3 -3
  41. package/dist/plugin/battery/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  42. package/dist/plugin/battery/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  43. package/dist/plugin/battery/src/plugin/open/types/open.d.ts +1 -1
  44. package/dist/plugin/battery/src/plugin/permission/types/permission.d.ts +1 -0
  45. package/dist/plugin/battery/src/plugin/pip/cores/index.d.ts +6 -6
  46. package/dist/plugin/battery/src/plugin/pip/types/pip.d.ts +12 -6
  47. package/dist/plugin/battery/src/plugin/vibration/types/vibration.d.ts +1 -1
  48. package/dist/plugin/clipboard/src/errors/invalid-state-error.d.ts +2 -0
  49. package/dist/plugin/clipboard/src/plugin/badge/types/badge.d.ts +1 -1
  50. package/dist/plugin/clipboard/src/plugin/battery/types/battery.d.ts +1 -1
  51. package/dist/plugin/clipboard/src/plugin/fullscreen/cores/index.d.ts +3 -3
  52. package/dist/plugin/clipboard/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  53. package/dist/plugin/clipboard/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  54. package/dist/plugin/clipboard/src/plugin/open/types/open.d.ts +1 -1
  55. package/dist/plugin/clipboard/src/plugin/permission/types/permission.d.ts +1 -0
  56. package/dist/plugin/clipboard/src/plugin/pip/cores/index.d.ts +6 -6
  57. package/dist/plugin/clipboard/src/plugin/pip/types/pip.d.ts +12 -6
  58. package/dist/plugin/clipboard/src/plugin/vibration/types/vibration.d.ts +1 -1
  59. package/dist/plugin/dimension/src/errors/invalid-state-error.d.ts +2 -0
  60. package/dist/plugin/dimension/src/plugin/badge/types/badge.d.ts +1 -1
  61. package/dist/plugin/dimension/src/plugin/battery/types/battery.d.ts +1 -1
  62. package/dist/plugin/dimension/src/plugin/fullscreen/cores/index.d.ts +3 -3
  63. package/dist/plugin/dimension/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  64. package/dist/plugin/dimension/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  65. package/dist/plugin/dimension/src/plugin/open/types/open.d.ts +1 -1
  66. package/dist/plugin/dimension/src/plugin/permission/types/permission.d.ts +1 -0
  67. package/dist/plugin/dimension/src/plugin/pip/cores/index.d.ts +6 -6
  68. package/dist/plugin/dimension/src/plugin/pip/types/pip.d.ts +12 -6
  69. package/dist/plugin/dimension/src/plugin/vibration/types/vibration.d.ts +1 -1
  70. package/dist/plugin/fullscreen/index.cjs +499 -265
  71. package/dist/plugin/fullscreen/index.d.ts +14 -7
  72. package/dist/plugin/fullscreen/index.mjs +499 -265
  73. package/dist/plugin/fullscreen/src/errors/invalid-state-error.d.ts +2 -0
  74. package/dist/plugin/fullscreen/src/plugin/badge/types/badge.d.ts +1 -1
  75. package/dist/plugin/fullscreen/src/plugin/battery/types/battery.d.ts +1 -1
  76. package/dist/plugin/fullscreen/src/plugin/fullscreen/cores/index.d.ts +3 -3
  77. package/dist/plugin/fullscreen/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  78. package/dist/plugin/fullscreen/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  79. package/dist/plugin/fullscreen/src/plugin/open/types/open.d.ts +1 -1
  80. package/dist/plugin/fullscreen/src/plugin/permission/types/permission.d.ts +1 -0
  81. package/dist/plugin/fullscreen/src/plugin/pip/cores/index.d.ts +6 -6
  82. package/dist/plugin/fullscreen/src/plugin/pip/types/pip.d.ts +12 -6
  83. package/dist/plugin/fullscreen/src/plugin/vibration/types/vibration.d.ts +1 -1
  84. package/dist/plugin/geolocation/index.cjs +6 -0
  85. package/dist/plugin/geolocation/index.d.ts +1 -1
  86. package/dist/plugin/geolocation/index.mjs +6 -0
  87. package/dist/plugin/geolocation/src/errors/invalid-state-error.d.ts +2 -0
  88. package/dist/plugin/geolocation/src/plugin/badge/types/badge.d.ts +1 -1
  89. package/dist/plugin/geolocation/src/plugin/battery/types/battery.d.ts +1 -1
  90. package/dist/plugin/geolocation/src/plugin/fullscreen/cores/index.d.ts +3 -3
  91. package/dist/plugin/geolocation/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  92. package/dist/plugin/geolocation/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  93. package/dist/plugin/geolocation/src/plugin/open/types/open.d.ts +1 -1
  94. package/dist/plugin/geolocation/src/plugin/permission/types/permission.d.ts +1 -0
  95. package/dist/plugin/geolocation/src/plugin/pip/cores/index.d.ts +6 -6
  96. package/dist/plugin/geolocation/src/plugin/pip/types/pip.d.ts +12 -6
  97. package/dist/plugin/geolocation/src/plugin/vibration/types/vibration.d.ts +1 -1
  98. package/dist/plugin/notification/index.cjs +6 -0
  99. package/dist/plugin/notification/index.mjs +6 -0
  100. package/dist/plugin/notification/src/errors/invalid-state-error.d.ts +2 -0
  101. package/dist/plugin/notification/src/plugin/badge/types/badge.d.ts +1 -1
  102. package/dist/plugin/notification/src/plugin/battery/types/battery.d.ts +1 -1
  103. package/dist/plugin/notification/src/plugin/fullscreen/cores/index.d.ts +3 -3
  104. package/dist/plugin/notification/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  105. package/dist/plugin/notification/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  106. package/dist/plugin/notification/src/plugin/open/types/open.d.ts +1 -1
  107. package/dist/plugin/notification/src/plugin/permission/types/permission.d.ts +1 -0
  108. package/dist/plugin/notification/src/plugin/pip/cores/index.d.ts +6 -6
  109. package/dist/plugin/notification/src/plugin/pip/types/pip.d.ts +12 -6
  110. package/dist/plugin/notification/src/plugin/vibration/types/vibration.d.ts +1 -1
  111. package/dist/plugin/open/index.cjs +120 -120
  112. package/dist/plugin/open/index.d.ts +35 -35
  113. package/dist/plugin/open/index.mjs +120 -120
  114. package/dist/plugin/open/src/errors/invalid-state-error.d.ts +2 -0
  115. package/dist/plugin/open/src/plugin/badge/types/badge.d.ts +1 -1
  116. package/dist/plugin/open/src/plugin/battery/types/battery.d.ts +1 -1
  117. package/dist/plugin/open/src/plugin/fullscreen/cores/index.d.ts +3 -3
  118. package/dist/plugin/open/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  119. package/dist/plugin/open/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  120. package/dist/plugin/open/src/plugin/open/types/open.d.ts +1 -1
  121. package/dist/plugin/open/src/plugin/permission/types/permission.d.ts +1 -0
  122. package/dist/plugin/open/src/plugin/pip/cores/index.d.ts +6 -6
  123. package/dist/plugin/open/src/plugin/pip/types/pip.d.ts +12 -6
  124. package/dist/plugin/open/src/plugin/vibration/types/vibration.d.ts +1 -1
  125. package/dist/plugin/permission/index.cjs +6 -0
  126. package/dist/plugin/permission/index.d.ts +1 -0
  127. package/dist/plugin/permission/index.mjs +6 -0
  128. package/dist/plugin/permission/src/errors/invalid-state-error.d.ts +2 -0
  129. package/dist/plugin/permission/src/plugin/badge/types/badge.d.ts +1 -1
  130. package/dist/plugin/permission/src/plugin/battery/types/battery.d.ts +1 -1
  131. package/dist/plugin/permission/src/plugin/fullscreen/cores/index.d.ts +3 -3
  132. package/dist/plugin/permission/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  133. package/dist/plugin/permission/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  134. package/dist/plugin/permission/src/plugin/open/types/open.d.ts +1 -1
  135. package/dist/plugin/permission/src/plugin/permission/types/permission.d.ts +1 -0
  136. package/dist/plugin/permission/src/plugin/pip/cores/index.d.ts +6 -6
  137. package/dist/plugin/permission/src/plugin/pip/types/pip.d.ts +12 -6
  138. package/dist/plugin/permission/src/plugin/vibration/types/vibration.d.ts +1 -1
  139. package/dist/plugin/pip/index.cjs +255 -273
  140. package/dist/plugin/pip/index.d.ts +20 -13
  141. package/dist/plugin/pip/index.mjs +255 -273
  142. package/dist/plugin/pip/src/errors/invalid-state-error.d.ts +2 -0
  143. package/dist/plugin/pip/src/plugin/badge/types/badge.d.ts +1 -1
  144. package/dist/plugin/pip/src/plugin/battery/types/battery.d.ts +1 -1
  145. package/dist/plugin/pip/src/plugin/fullscreen/cores/index.d.ts +3 -3
  146. package/dist/plugin/pip/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  147. package/dist/plugin/pip/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  148. package/dist/plugin/pip/src/plugin/open/types/open.d.ts +1 -1
  149. package/dist/plugin/pip/src/plugin/permission/types/permission.d.ts +1 -0
  150. package/dist/plugin/pip/src/plugin/pip/cores/index.d.ts +6 -6
  151. package/dist/plugin/pip/src/plugin/pip/types/pip.d.ts +12 -6
  152. package/dist/plugin/pip/src/plugin/vibration/types/vibration.d.ts +1 -1
  153. package/dist/plugin/platform/index.d.ts +5 -5
  154. package/dist/plugin/platform/src/errors/invalid-state-error.d.ts +2 -0
  155. package/dist/plugin/platform/src/plugin/badge/types/badge.d.ts +1 -1
  156. package/dist/plugin/platform/src/plugin/battery/types/battery.d.ts +1 -1
  157. package/dist/plugin/platform/src/plugin/fullscreen/cores/index.d.ts +3 -3
  158. package/dist/plugin/platform/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  159. package/dist/plugin/platform/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  160. package/dist/plugin/platform/src/plugin/open/types/open.d.ts +1 -1
  161. package/dist/plugin/platform/src/plugin/permission/types/permission.d.ts +1 -0
  162. package/dist/plugin/platform/src/plugin/pip/cores/index.d.ts +6 -6
  163. package/dist/plugin/platform/src/plugin/pip/types/pip.d.ts +12 -6
  164. package/dist/plugin/platform/src/plugin/vibration/types/vibration.d.ts +1 -1
  165. package/dist/plugin/theme/src/errors/invalid-state-error.d.ts +2 -0
  166. package/dist/plugin/theme/src/plugin/badge/types/badge.d.ts +1 -1
  167. package/dist/plugin/theme/src/plugin/battery/types/battery.d.ts +1 -1
  168. package/dist/plugin/theme/src/plugin/fullscreen/cores/index.d.ts +3 -3
  169. package/dist/plugin/theme/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  170. package/dist/plugin/theme/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  171. package/dist/plugin/theme/src/plugin/open/types/open.d.ts +1 -1
  172. package/dist/plugin/theme/src/plugin/permission/types/permission.d.ts +1 -0
  173. package/dist/plugin/theme/src/plugin/pip/cores/index.d.ts +6 -6
  174. package/dist/plugin/theme/src/plugin/pip/types/pip.d.ts +12 -6
  175. package/dist/plugin/theme/src/plugin/vibration/types/vibration.d.ts +1 -1
  176. package/dist/plugin/vibration/index.cjs +5 -5
  177. package/dist/plugin/vibration/index.d.ts +1 -1
  178. package/dist/plugin/vibration/index.mjs +5 -5
  179. package/dist/plugin/vibration/src/errors/invalid-state-error.d.ts +2 -0
  180. package/dist/plugin/vibration/src/plugin/badge/types/badge.d.ts +1 -1
  181. package/dist/plugin/vibration/src/plugin/battery/types/battery.d.ts +1 -1
  182. package/dist/plugin/vibration/src/plugin/fullscreen/cores/index.d.ts +3 -3
  183. package/dist/plugin/vibration/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  184. package/dist/plugin/vibration/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  185. package/dist/plugin/vibration/src/plugin/open/types/open.d.ts +1 -1
  186. package/dist/plugin/vibration/src/plugin/permission/types/permission.d.ts +1 -0
  187. package/dist/plugin/vibration/src/plugin/pip/cores/index.d.ts +6 -6
  188. package/dist/plugin/vibration/src/plugin/pip/types/pip.d.ts +12 -6
  189. package/dist/plugin/vibration/src/plugin/vibration/types/vibration.d.ts +1 -1
  190. package/dist/src/errors/invalid-state-error.d.ts +2 -0
  191. package/dist/src/plugin/badge/types/badge.d.ts +1 -1
  192. package/dist/src/plugin/battery/types/battery.d.ts +1 -1
  193. package/dist/src/plugin/fullscreen/cores/index.d.ts +3 -3
  194. package/dist/src/plugin/fullscreen/types/fullscreen.d.ts +9 -3
  195. package/dist/src/plugin/geolocation/types/geolocation.d.ts +1 -1
  196. package/dist/src/plugin/open/types/open.d.ts +1 -1
  197. package/dist/src/plugin/permission/types/permission.d.ts +1 -0
  198. package/dist/src/plugin/pip/cores/index.d.ts +6 -6
  199. package/dist/src/plugin/pip/types/pip.d.ts +12 -6
  200. package/dist/src/plugin/vibration/types/vibration.d.ts +1 -1
  201. package/package.json +21 -13
@@ -348,301 +348,283 @@ function createCustomError(name, Base) {
348
348
 
349
349
  var NotSupportedError = createCustomError('NotSupportedError');
350
350
 
351
- var PIP_BRIDGED_KEY = Symbol('pipBridged');
351
+ var InvalidStateError = createCustomError('InvalidStateError');
352
+
352
353
  var PIP_PRESENTATION_MODE = 'picture-in-picture';
353
354
  var INLINE_PRESENTATION_MODE = 'inline';
354
- function hasStandardPipEvents() {
355
+ var lastPipVideo = null;
356
+ var eventsBridged = false;
357
+ var PIP_BRIDGE_KEY = (function () {
358
+ if (typeof Symbol === 'function') {
359
+ var existing = globalThis.__nativeFnPipBridgeKey__;
360
+ if (typeof existing === 'symbol')
361
+ return existing;
362
+ return globalThis.__nativeFnPipBridgeKey__ = Symbol('native.fn.pip.bridged');
363
+ }
364
+ return '__nativeFnPipBridged__';
365
+ }());
366
+ var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, detachOnChange);
367
+ var onErrorSubscriptionManager = createSubscriptionManager(attachOnError, detachOnError);
368
+ var Pip = {
369
+ get supported() {
370
+ return getEnabled();
371
+ },
372
+ get element() {
373
+ return getElement();
374
+ },
375
+ get isPip() {
376
+ return getIsPip();
377
+ },
378
+ request: request,
379
+ exit: exit,
380
+ onChange: onChangeSubscriptionManager.subscribe,
381
+ onError: onErrorSubscriptionManager.subscribe,
382
+ Constants: {},
383
+ Errors: {
384
+ NotSupportedError: NotSupportedError,
385
+ InvalidStateError: InvalidStateError,
386
+ },
387
+ };
388
+ function hasStandardApi() {
355
389
  return typeof globalThis.document.pictureInPictureEnabled !== 'undefined';
356
390
  }
357
- function createPip() {
358
- var lastPipVideo = null;
359
- var eventsBridged = false;
360
- var activeOperation = null;
361
- var pendingQueue = [];
362
- var lastIntendedOperation = 'exit';
363
- var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, detachOnChange);
364
- var onErrorSubscriptionManager = createSubscriptionManager(attachOnError, detachOnError);
365
- function getEnabled() {
366
- if (typeof globalThis.document.pictureInPictureEnabled === 'boolean')
367
- return globalThis.document.pictureInPictureEnabled;
368
- if (typeof HTMLVideoElement === 'undefined')
369
- return false;
370
- var videos = globalThis.document.querySelectorAll('video');
371
- for (var i = 0; i < videos.length; i++) {
372
- var video = videos[i];
373
- if (typeof video.webkitSupportsPresentationMode === 'function' && video.webkitSupportsPresentationMode(PIP_PRESENTATION_MODE))
374
- return true;
375
- }
376
- return false;
377
- }
378
- function getElement() {
379
- var currentElement = globalThis.document.pictureInPictureElement;
380
- if (currentElement !== null && typeof currentElement !== 'undefined')
381
- return currentElement;
382
- if (lastPipVideo !== null && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE)
383
- return lastPipVideo;
384
- return null;
385
- }
386
- function getIsPip() {
387
- return getElement() !== null;
388
- }
389
- function getDefaultTarget() {
390
- var video = globalThis.document.querySelector('video');
391
- if (video === null)
392
- return undefined;
393
- return video;
391
+ function getDefaultTarget() {
392
+ var video = globalThis.document.querySelector('video');
393
+ return video !== null ? video : undefined;
394
+ }
395
+ function createPipEventPayload(nativeEvent, element, isPip) {
396
+ return {
397
+ nativeEvent: nativeEvent,
398
+ element: element,
399
+ isPip: isPip
400
+ };
401
+ }
402
+ function emitChange(nativeEvent, element, isPip) {
403
+ onChangeSubscriptionManager.emit(createPipEventPayload(nativeEvent, element, isPip));
404
+ }
405
+ function emitError(nativeEvent, element, isPip) {
406
+ onErrorSubscriptionManager.emit(createPipEventPayload(nativeEvent, element, isPip));
407
+ }
408
+ function onEnterPictureInPicture(event) {
409
+ var target = event.target;
410
+ if (target instanceof globalThis.HTMLVideoElement)
411
+ emitChange(event, target, true);
412
+ }
413
+ function onLeavePictureInPicture(event) {
414
+ var target = event.target;
415
+ if (target instanceof globalThis.HTMLVideoElement)
416
+ emitChange(event, target, false);
417
+ }
418
+ function onPictureInPictureError(event) {
419
+ var target = event.target;
420
+ if (target instanceof globalThis.HTMLVideoElement)
421
+ emitError(event, target, getIsPip());
422
+ }
423
+ function onWebkitPresentationModeChanged(event) {
424
+ if (this.webkitPresentationMode === PIP_PRESENTATION_MODE) {
425
+ lastPipVideo = this;
426
+ emitChange(event, this, true);
427
+ return;
394
428
  }
395
- function onWebkitPresentationModeChanged(event) {
396
- if (this.webkitPresentationMode === PIP_PRESENTATION_MODE || (this.webkitPresentationMode === INLINE_PRESENTATION_MODE && lastPipVideo === this))
397
- onChangeSubscriptionManager.emit(event);
429
+ if (this.webkitPresentationMode === INLINE_PRESENTATION_MODE && lastPipVideo === this) {
430
+ lastPipVideo = null;
431
+ emitChange(event, this, false);
398
432
  }
399
- function bridgeEvents() {
400
- if (eventsBridged)
401
- return;
402
- eventsBridged = true;
403
- if (!hasStandardPipEvents()) {
404
- bridgeWebkitVideoEvents();
405
- if (typeof globalThis.MutationObserver !== 'undefined') {
406
- var observer = new MutationObserver(function () {
407
- bridgeWebkitVideoEvents();
408
- });
409
- observer.observe(globalThis.document.documentElement, {
410
- childList: true,
411
- subtree: true,
412
- });
433
+ }
434
+ function bridgeSingleVideoNode(video) {
435
+ if (video[PIP_BRIDGE_KEY])
436
+ return;
437
+ if (typeof video.webkitSetPresentationMode === 'undefined' && typeof video.onwebkitpresentationmodechanged === 'undefined')
438
+ return;
439
+ EventListener.add(video, { type: 'webkitpresentationmodechanged', callback: onWebkitPresentationModeChanged, options: false });
440
+ video[PIP_BRIDGE_KEY] = true;
441
+ }
442
+ function bridgeWebkitVideoEvents() {
443
+ var videos = globalThis.document.querySelectorAll('video');
444
+ for (var i = 0; i < videos.length; i++)
445
+ bridgeSingleVideoNode(videos[i]);
446
+ }
447
+ function bridgeEvents() {
448
+ if (eventsBridged)
449
+ return;
450
+ eventsBridged = true;
451
+ if (hasStandardApi())
452
+ return;
453
+ bridgeWebkitVideoEvents();
454
+ if (typeof globalThis.MutationObserver === 'undefined')
455
+ return;
456
+ var observer = new globalThis.MutationObserver(function (records) {
457
+ if (lastPipVideo !== null) {
458
+ var removed = false;
459
+ for (var i = 0; i < records.length; i++) {
460
+ var removedNodes = records[i].removedNodes;
461
+ for (var j = 0; j < removedNodes.length; j++) {
462
+ var node = removedNodes[j];
463
+ if (node === lastPipVideo || (node.nodeType === Node.ELEMENT_NODE && node.contains(lastPipVideo))) {
464
+ removed = true;
465
+ break;
466
+ }
467
+ }
468
+ if (removed)
469
+ break;
413
470
  }
471
+ if (removed && !globalThis.document.contains(lastPipVideo))
472
+ lastPipVideo = null;
414
473
  }
415
- }
416
- function bridgeWebkitVideoEvents() {
417
- if (typeof globalThis.document === 'undefined')
418
- return;
419
- var videos = globalThis.document.querySelectorAll('video');
420
- videos.forEach(function (video) {
421
- if (video[PIP_BRIDGED_KEY] === true || !(typeof video.webkitSetPresentationMode !== 'undefined' || typeof video.onwebkitpresentationmodechanged !== 'undefined'))
422
- return;
423
- EventListener.add(video, {
424
- type: 'webkitpresentationmodechanged',
425
- callback: onWebkitPresentationModeChanged,
426
- options: false,
427
- });
428
- video[PIP_BRIDGED_KEY] = true;
429
- });
430
- }
431
- function attachOnChange() {
432
- if (hasStandardPipEvents()) {
433
- var changeEvents = ['enterpictureinpicture', 'leavepictureinpicture'];
434
- for (var i = 0; i < changeEvents.length; i++) {
435
- EventListener.add(globalThis.document, {
436
- type: changeEvents[i],
437
- callback: onChangeSubscriptionManager.emit,
438
- options: false,
439
- });
474
+ for (var i = 0; i < records.length; i++) {
475
+ var addedNodes = records[i].addedNodes;
476
+ for (var j = 0; j < addedNodes.length; j++) {
477
+ var node = addedNodes[j];
478
+ if (node.nodeType !== Node.ELEMENT_NODE)
479
+ continue;
480
+ var element = node;
481
+ if (element.tagName === 'VIDEO') {
482
+ bridgeSingleVideoNode(element);
483
+ continue;
484
+ }
485
+ var nested = element.querySelectorAll('video');
486
+ for (var k = 0; k < nested.length; k++)
487
+ bridgeSingleVideoNode(nested[k]);
440
488
  }
441
- return;
442
489
  }
443
- bridgeWebkitVideoEvents();
490
+ });
491
+ observer.observe(globalThis.document.documentElement, { childList: true, subtree: true });
492
+ }
493
+ function attachOnChange() {
494
+ if (hasStandardApi()) {
495
+ EventListener.add(globalThis.document, { type: 'enterpictureinpicture', callback: onEnterPictureInPicture, options: false });
496
+ EventListener.add(globalThis.document, { type: 'leavepictureinpicture', callback: onLeavePictureInPicture, options: false });
497
+ return;
498
+ }
499
+ bridgeWebkitVideoEvents();
500
+ }
501
+ function detachOnChange() {
502
+ if (hasStandardApi()) {
503
+ EventListener.remove(globalThis.document, { type: 'enterpictureinpicture', callback: onEnterPictureInPicture, options: false });
504
+ EventListener.remove(globalThis.document, { type: 'leavepictureinpicture', callback: onLeavePictureInPicture, options: false });
505
+ return;
444
506
  }
445
- function detachOnChange() {
446
- if (hasStandardPipEvents()) {
447
- var changeEvents = ['enterpictureinpicture', 'leavepictureinpicture'];
448
- for (var i = 0; i < changeEvents.length; i++) {
449
- EventListener.remove(globalThis.document, {
450
- type: changeEvents[i],
451
- callback: onChangeSubscriptionManager.emit,
452
- options: false,
507
+ var videos = globalThis.document.querySelectorAll('video');
508
+ for (var i = 0; i < videos.length; i++) {
509
+ EventListener.remove(videos[i], { type: 'webkitpresentationmodechanged', callback: onWebkitPresentationModeChanged, options: false });
510
+ videos[i][PIP_BRIDGE_KEY] = false;
511
+ }
512
+ }
513
+ function attachOnError() {
514
+ EventListener.add(globalThis.document, { type: 'pictureinpictureerror', callback: onPictureInPictureError, options: false });
515
+ }
516
+ function detachOnError() {
517
+ EventListener.remove(globalThis.document, { type: 'pictureinpictureerror', callback: onPictureInPictureError, options: false });
518
+ }
519
+ function getEnabled() {
520
+ if (typeof globalThis.document.pictureInPictureEnabled === 'boolean')
521
+ return globalThis.document.pictureInPictureEnabled;
522
+ var video;
523
+ var selected = globalThis.document.querySelector('video');
524
+ if (selected !== null)
525
+ video = selected;
526
+ else
527
+ video = globalThis.document.createElement('video');
528
+ return typeof video.webkitSupportsPresentationMode === 'function' && video.webkitSupportsPresentationMode(PIP_PRESENTATION_MODE);
529
+ }
530
+ function getElement() {
531
+ var currentElement = globalThis.document.pictureInPictureElement;
532
+ if (currentElement !== null && typeof currentElement !== 'undefined')
533
+ return currentElement;
534
+ if (lastPipVideo !== null && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE)
535
+ return lastPipVideo;
536
+ return null;
537
+ }
538
+ function getIsPip() {
539
+ return getElement() !== null;
540
+ }
541
+ function request(target) {
542
+ return new Promise(function (resolve, reject) {
543
+ if (typeof target === 'undefined')
544
+ target = getDefaultTarget();
545
+ if (typeof target === 'undefined')
546
+ return reject(new NotSupportedError('Failed to enter Picture-in-Picture mode.'));
547
+ var tagName = target.tagName.toLowerCase();
548
+ if (tagName !== 'video')
549
+ return reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
550
+ var method = target.requestPictureInPicture;
551
+ var isWebkitPipActive = lastPipVideo !== null && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE;
552
+ if (typeof method === 'function' && !isWebkitPipActive) {
553
+ var result = method.call(target);
554
+ if (typeof result !== 'undefined' && typeof result.then === 'function') {
555
+ result
556
+ .then(resolve)
557
+ .catch(function () {
558
+ try {
559
+ fallbackToWebkit();
560
+ }
561
+ catch (e) {
562
+ reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
563
+ }
453
564
  });
565
+ return;
454
566
  }
455
- return;
567
+ return resolve();
456
568
  }
457
- var videos = globalThis.document.querySelectorAll('video');
458
- videos.forEach(function (video) {
459
- EventListener.remove(video, {
460
- type: 'webkitpresentationmodechanged',
461
- callback: onWebkitPresentationModeChanged,
462
- options: false,
463
- });
464
- try {
465
- delete video[PIP_BRIDGED_KEY];
466
- }
467
- catch (_) {
468
- video[PIP_BRIDGED_KEY] = undefined;
569
+ function fallbackToWebkit() {
570
+ if (typeof target !== 'undefined' && typeof target.webkitSupportsPresentationMode === 'function' && target.webkitSupportsPresentationMode(PIP_PRESENTATION_MODE) && typeof target.webkitSetPresentationMode === 'function') {
571
+ if (target.disablePictureInPicture)
572
+ return reject(new NotSupportedError('Picture-in-Picture is disabled on this element.'));
573
+ if (!hasStandardApi())
574
+ bridgeSingleVideoNode(target);
575
+ target.webkitSetPresentationMode(PIP_PRESENTATION_MODE);
576
+ if (target.webkitPresentationMode !== PIP_PRESENTATION_MODE)
577
+ return reject(new InvalidStateError('Picture-in-Picture transition is already in progress.'));
578
+ lastPipVideo = target;
579
+ return resolve();
469
580
  }
470
- });
471
- }
472
- function attachOnError() {
473
- EventListener.add(globalThis.document, {
474
- type: 'pictureinpictureerror',
475
- callback: onErrorSubscriptionManager.emit,
476
- options: false,
477
- });
478
- }
479
- function detachOnError() {
480
- EventListener.remove(globalThis.document, {
481
- type: 'pictureinpictureerror',
482
- callback: onErrorSubscriptionManager.emit,
483
- options: false,
484
- });
485
- }
486
- function drainPendingOperation() {
487
- var entry = pendingQueue.shift();
488
- if (typeof entry === 'undefined') {
489
- activeOperation = null;
490
- return;
581
+ reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
491
582
  }
492
- var next;
493
- if (entry.operation === 'request')
494
- next = requestImmediately(entry.target);
495
- else
496
- next = exitImmediately();
497
- activeOperation = next
498
- .then(function () {
499
- entry.resolve();
500
- drainPendingOperation();
501
- })
502
- .catch(function (error) {
503
- entry.reject(error);
504
- drainPendingOperation();
505
- });
506
- }
507
- function request(target) {
508
- lastIntendedOperation = 'request';
509
- if (activeOperation === null) {
510
- var next = requestImmediately(target);
511
- activeOperation = next
512
- .then(drainPendingOperation)
513
- .catch(drainPendingOperation);
514
- return next;
515
- }
516
- return new Promise(function (resolve, reject) {
517
- pendingQueue.push({
518
- operation: 'request',
519
- target: target,
520
- resolve: resolve,
521
- reject: reject,
522
- });
523
- });
524
- }
525
- function exit() {
526
- lastIntendedOperation = 'exit';
527
- if (activeOperation === null) {
528
- var next = exitImmediately();
529
- activeOperation = next
530
- .then(drainPendingOperation)
531
- .catch(drainPendingOperation);
532
- return next;
533
- }
534
- return new Promise(function (resolve, reject) {
535
- pendingQueue.push({
536
- operation: 'exit',
537
- target: undefined,
538
- resolve: resolve,
539
- reject: reject,
540
- });
541
- });
542
- }
543
- function requestImmediately(target) {
544
- return new Promise(function (resolve, reject) {
545
- if (typeof target === 'undefined')
546
- target = getDefaultTarget();
547
- if (typeof target === 'undefined')
548
- return reject(new NotSupportedError('Failed to enter Picture-in-Picture mode.'));
549
- var tagName = target.tagName.toLowerCase();
550
- if (tagName !== 'video')
551
- return reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
552
- function fallbackToWebkitVideo() {
553
- if (typeof target !== 'undefined' && typeof target.webkitSupportsPresentationMode === 'function' && target.webkitSupportsPresentationMode(PIP_PRESENTATION_MODE) && typeof target.webkitSetPresentationMode === 'function') {
554
- if (target.disablePictureInPicture)
555
- return reject(new NotSupportedError('Picture-in-Picture is disabled on this video element.'));
556
- lastPipVideo = target;
557
- bridgeWebkitVideoEvents();
558
- target.webkitSetPresentationMode(PIP_PRESENTATION_MODE);
559
- return resolve();
560
- }
561
- reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
583
+ fallbackToWebkit();
584
+ });
585
+ }
586
+ function exit() {
587
+ return new Promise(function (resolve, reject) {
588
+ var method = globalThis.document.exitPictureInPicture;
589
+ if (typeof method === 'function') {
590
+ var result = method.call(globalThis.document);
591
+ if (typeof result !== 'undefined' && typeof result.then === 'function') {
592
+ result
593
+ .then(resolve)
594
+ .catch(function () {
595
+ try {
596
+ fallbackToWebkit();
597
+ }
598
+ catch (e) {
599
+ reject(new NotSupportedError('Failed to exit Picture-in-Picture mode.'));
600
+ }
601
+ });
602
+ return;
562
603
  }
563
- var method = target.requestPictureInPicture;
564
- if (typeof method === 'function') {
565
- var result = method.call(target);
566
- if (typeof result !== 'undefined' && typeof result.then === 'function') {
567
- result
568
- .then(function () {
569
- resolve();
570
- })
571
- .catch(function () {
572
- fallbackToWebkitVideo();
573
- });
574
- return;
575
- }
604
+ return resolve();
605
+ }
606
+ function fallbackToWebkit() {
607
+ if (lastPipVideo !== null && typeof lastPipVideo.webkitSetPresentationMode === 'function' && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE) {
608
+ lastPipVideo.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
609
+ lastPipVideo = null;
576
610
  return resolve();
577
611
  }
578
- fallbackToWebkitVideo();
579
- });
580
- }
581
- function exitImmediately() {
582
- return new Promise(function (resolve, reject) {
583
- if (getElement() === null && lastPipVideo === null)
584
- return resolve();
585
- function fallbackToWebkitVideo() {
586
- var candidates;
587
- if (lastPipVideo !== null && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE)
588
- candidates = [lastPipVideo];
589
- else
590
- candidates = globalThis.document.querySelectorAll('video');
591
- for (var i = 0; i < candidates.length; i++) {
592
- var video = candidates[i];
593
- if (typeof video.webkitSetPresentationMode === 'function' && video.webkitPresentationMode === PIP_PRESENTATION_MODE) {
594
- video.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
595
- lastPipVideo = null;
596
- return resolve();
597
- }
598
- }
599
- if (getElement() === null)
612
+ var videos = globalThis.document.querySelectorAll('video');
613
+ for (var i = 0; i < videos.length; i++) {
614
+ var video = videos[i];
615
+ if (typeof video.webkitSetPresentationMode === 'function' && video.webkitPresentationMode === PIP_PRESENTATION_MODE) {
616
+ video.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
617
+ lastPipVideo = null;
600
618
  return resolve();
601
- reject(new NotSupportedError('Failed to exit Picture-in-Picture mode.'));
602
- }
603
- var method = globalThis.document.exitPictureInPicture;
604
- if (typeof method === 'function') {
605
- var result = method.call(globalThis.document);
606
- if (typeof result !== 'undefined' && typeof result.then === 'function') {
607
- result
608
- .then(resolve)
609
- .catch(function () {
610
- fallbackToWebkitVideo();
611
- });
612
- return;
613
619
  }
614
- return resolve();
615
620
  }
616
- fallbackToWebkitVideo();
617
- });
618
- }
619
- function toggle(target) {
620
- if (lastIntendedOperation === 'request')
621
- return exit();
622
- return request(target);
623
- }
624
- bridgeEvents();
625
- return {
626
- get supported() {
627
- return getEnabled();
628
- },
629
- get element() {
630
- return getElement();
631
- },
632
- get isPip() {
633
- return getIsPip();
634
- },
635
- request: request,
636
- exit: exit,
637
- toggle: toggle,
638
- onChange: onChangeSubscriptionManager.subscribe,
639
- onError: onErrorSubscriptionManager.subscribe,
640
- Constants: {},
641
- Errors: {
642
- NotSupportedError: NotSupportedError,
643
- },
644
- };
621
+ if (globalThis.document.pictureInPictureElement === null || typeof globalThis.document.pictureInPictureElement === 'undefined')
622
+ return resolve();
623
+ reject(new NotSupportedError('Failed to exit Picture-in-Picture mode.'));
624
+ }
625
+ fallbackToWebkit();
626
+ });
645
627
  }
646
- var Pip = createPip();
628
+ bridgeEvents();
647
629
 
648
630
  module.exports = Pip;
@@ -1,30 +1,37 @@
1
1
  declare const NotSupportedError: ErrorConstructor;
2
2
 
3
+ declare const InvalidStateError: ErrorConstructor;
4
+
3
5
  declare interface PipInstance {
4
- supported: boolean;
5
- element: HTMLVideoElement | null;
6
- isPip: boolean;
6
+ get supported(): boolean;
7
+ get element(): HTMLVideoElement | null;
8
+ get isPip(): boolean;
7
9
  request(target?: HTMLVideoElement): Promise<void>;
8
10
  exit(): Promise<void>;
9
- toggle(target?: HTMLVideoElement): Promise<void>;
10
- onChange(listener: (event: Event) => void, options?: AddEventListenerOptions): () => void;
11
- onError(listener: (event: Event) => void, options?: AddEventListenerOptions): () => void;
11
+ onChange(listener: (payload: PipEventPayload) => void, options?: AddEventListenerOptions): () => void;
12
+ onError(listener: (payload: PipEventPayload) => void, options?: AddEventListenerOptions): () => void;
12
13
  Constants: {};
13
14
  Errors: {
14
15
  NotSupportedError: typeof NotSupportedError;
16
+ InvalidStateError: typeof InvalidStateError;
15
17
  };
16
18
  }
19
+ declare interface PipEventPayload {
20
+ nativeEvent: Event;
21
+ element: HTMLVideoElement;
22
+ isPip: boolean;
23
+ }
17
24
 
18
25
  declare global {
19
26
  interface HTMLVideoElement {
20
- webkitSupportsPresentationMode?: (mode: string) => boolean;
21
- webkitSetPresentationMode?: (mode: string) => void;
27
+ webkitSupportsPresentationMode?(mode: string): boolean;
28
+ webkitSetPresentationMode?(mode: string): void;
22
29
  webkitPresentationMode?: string;
23
- onwebkitpresentationmodechanged?: ((this: HTMLVideoElement, ev: Event) => any) | null;
24
- [key: symbol]: boolean | undefined;
30
+ onwebkitpresentationmodechanged?: ((this: Element, ev: Event) => any) | null;
25
31
  }
32
+ var __nativeFnPipBridgeKey__: symbol | undefined;
26
33
  }
27
- declare const _default: PipInstance;
34
+ declare const Pip: PipInstance;
28
35
 
29
- export { _default as default };
30
- export type { PipInstance };
36
+ export { Pip as default };
37
+ export type { PipEventPayload, PipInstance };