native-fn 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +14 -14
  2. package/dist/index.d.ts +12 -6
  3. package/dist/native.cjs +180 -102
  4. package/dist/native.min.cjs +1 -1
  5. package/dist/native.min.mjs +1 -1
  6. package/dist/native.mjs +180 -102
  7. package/dist/native.umd.js +180 -102
  8. package/dist/native.umd.min.js +1 -1
  9. package/dist/plugin/appearance/index.cjs +8 -3
  10. package/dist/plugin/appearance/index.mjs +8 -3
  11. package/dist/plugin/appearance/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  12. package/dist/plugin/appearance/src/plugin/pip/types/pip.d.ts +5 -2
  13. package/dist/plugin/appearance/src/types/subscription-manager.d.ts +1 -1
  14. package/dist/plugin/badge/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  15. package/dist/plugin/badge/src/plugin/pip/types/pip.d.ts +5 -2
  16. package/dist/plugin/badge/src/types/subscription-manager.d.ts +1 -1
  17. package/dist/plugin/battery/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  18. package/dist/plugin/battery/src/plugin/pip/types/pip.d.ts +5 -2
  19. package/dist/plugin/battery/src/types/subscription-manager.d.ts +1 -1
  20. package/dist/plugin/clipboard/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  21. package/dist/plugin/clipboard/src/plugin/pip/types/pip.d.ts +5 -2
  22. package/dist/plugin/clipboard/src/types/subscription-manager.d.ts +1 -1
  23. package/dist/plugin/dimension/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  24. package/dist/plugin/dimension/src/plugin/pip/types/pip.d.ts +5 -2
  25. package/dist/plugin/dimension/src/types/subscription-manager.d.ts +1 -1
  26. package/dist/plugin/fullscreen/index.cjs +93 -54
  27. package/dist/plugin/fullscreen/index.d.ts +7 -4
  28. package/dist/plugin/fullscreen/index.mjs +93 -54
  29. package/dist/plugin/fullscreen/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  30. package/dist/plugin/fullscreen/src/plugin/pip/types/pip.d.ts +5 -2
  31. package/dist/plugin/fullscreen/src/types/subscription-manager.d.ts +1 -1
  32. package/dist/plugin/geolocation/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  33. package/dist/plugin/geolocation/src/plugin/pip/types/pip.d.ts +5 -2
  34. package/dist/plugin/geolocation/src/types/subscription-manager.d.ts +1 -1
  35. package/dist/plugin/notification/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  36. package/dist/plugin/notification/src/plugin/pip/types/pip.d.ts +5 -2
  37. package/dist/plugin/notification/src/types/subscription-manager.d.ts +1 -1
  38. package/dist/plugin/open/index.cjs +8 -3
  39. package/dist/plugin/open/index.mjs +8 -3
  40. package/dist/plugin/open/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  41. package/dist/plugin/open/src/plugin/pip/types/pip.d.ts +5 -2
  42. package/dist/plugin/open/src/types/subscription-manager.d.ts +1 -1
  43. package/dist/plugin/permission/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  44. package/dist/plugin/permission/src/plugin/pip/types/pip.d.ts +5 -2
  45. package/dist/plugin/permission/src/types/subscription-manager.d.ts +1 -1
  46. package/dist/plugin/pip/index.cjs +448 -47
  47. package/dist/plugin/pip/index.d.ts +5 -2
  48. package/dist/plugin/pip/index.mjs +448 -47
  49. package/dist/plugin/pip/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  50. package/dist/plugin/pip/src/plugin/pip/types/pip.d.ts +5 -2
  51. package/dist/plugin/pip/src/types/subscription-manager.d.ts +1 -1
  52. package/dist/plugin/platform/index.cjs +8 -3
  53. package/dist/plugin/platform/index.mjs +8 -3
  54. package/dist/plugin/platform/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  55. package/dist/plugin/platform/src/plugin/pip/types/pip.d.ts +5 -2
  56. package/dist/plugin/platform/src/types/subscription-manager.d.ts +1 -1
  57. package/dist/plugin/theme/index.cjs +8 -3
  58. package/dist/plugin/theme/index.mjs +8 -3
  59. package/dist/plugin/theme/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  60. package/dist/plugin/theme/src/plugin/pip/types/pip.d.ts +5 -2
  61. package/dist/plugin/theme/src/types/subscription-manager.d.ts +1 -1
  62. package/dist/plugin/vibration/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  63. package/dist/plugin/vibration/src/plugin/pip/types/pip.d.ts +5 -2
  64. package/dist/plugin/vibration/src/types/subscription-manager.d.ts +1 -1
  65. package/dist/src/plugin/fullscreen/types/fullscreen.d.ts +7 -4
  66. package/dist/src/plugin/pip/types/pip.d.ts +5 -2
  67. package/dist/src/types/subscription-manager.d.ts +1 -1
  68. package/package.json +1 -1
@@ -350,9 +350,372 @@ var NotSupportedError = createCustomError('NotSupportedError');
350
350
 
351
351
  var InvalidStateError = createCustomError('InvalidStateError');
352
352
 
353
+ function compareVersion(lhs, rhs) {
354
+ var pa = lhs.split('.');
355
+ var pb = rhs.split('.');
356
+ var length = Math.max(pa.length, pb.length);
357
+ for (var i = 0; i < length; i++) {
358
+ var a = void 0;
359
+ var b = void 0;
360
+ if (i < pa.length)
361
+ a = parseInt(pa[i], 10);
362
+ else
363
+ a = 0;
364
+ if (i < pb.length)
365
+ b = parseInt(pb[i], 10);
366
+ else
367
+ b = 0;
368
+ if (a > b)
369
+ return 1;
370
+ if (a < b)
371
+ return -1;
372
+ }
373
+ return 0;
374
+ }
375
+
376
+ function resolveWindowsVersion(string) {
377
+ if (typeof string === 'undefined')
378
+ return '';
379
+ var mapped = {
380
+ '4.90': 'ME',
381
+ 'NT3.51': 'NT 3.11',
382
+ 'NT4.0': 'NT 4.0',
383
+ 'NT 5.0': '2000',
384
+ 'NT 5.1': 'XP',
385
+ 'NT 5.2': 'XP',
386
+ 'NT 6.0': 'Vista',
387
+ 'NT 6.1': '7',
388
+ 'NT 6.2': '8',
389
+ 'NT 6.3': '8.1',
390
+ 'NT 6.4': '10',
391
+ 'NT 10.0': '10',
392
+ 'ARM': 'RT'
393
+ }[string];
394
+ if (typeof mapped !== 'undefined')
395
+ return mapped;
396
+ return string;
397
+ }
398
+ function resolveUnderscoreVersion(string) {
399
+ if (typeof string === 'undefined')
400
+ return '';
401
+ return string.replace(/_/g, '.');
402
+ }
403
+ var OS;
404
+ (function (OS) {
405
+ OS["Unknown"] = "Unknown";
406
+ OS["Android"] = "Android";
407
+ OS["iOS"] = "iOS";
408
+ OS["Windows"] = "Windows";
409
+ OS["MacOS"] = "MacOS";
410
+ })(OS || (OS = {}));
411
+ var Devices;
412
+ (function (Devices) {
413
+ Devices["Unknown"] = "Unknown";
414
+ Devices["Mobile"] = "Mobile";
415
+ Devices["Desktop"] = "Desktop";
416
+ })(Devices || (Devices = {}));
417
+ var Engines;
418
+ (function (Engines) {
419
+ Engines["Unknown"] = "Unknown";
420
+ Engines["EdgeHTML"] = "EdgeHTML";
421
+ Engines["ArkWeb"] = "ArkWeb";
422
+ Engines["Blink"] = "Blink";
423
+ Engines["Presto"] = "Presto";
424
+ Engines["WebKit"] = "WebKit";
425
+ Engines["Trident"] = "Trident";
426
+ Engines["NetFront"] = "NetFront";
427
+ Engines["KHTML"] = "KHTML";
428
+ Engines["Tasman"] = "Tasman";
429
+ Engines["Gecko"] = "Gecko";
430
+ })(Engines || (Engines = {}));
431
+ var Browsers;
432
+ (function (Browsers) {
433
+ Browsers["Unknown"] = "Unknown";
434
+ Browsers["Chrome"] = "Chrome";
435
+ Browsers["Safari"] = "Safari";
436
+ Browsers["Edge"] = "Edge";
437
+ Browsers["Firefox"] = "Firefox";
438
+ Browsers["Opera"] = "Opera";
439
+ Browsers["IE"] = "IE";
440
+ Browsers["SamsungInternet"] = "SamsungInternet";
441
+ })(Browsers || (Browsers = {}));
442
+ var USER_AGENT = (function () {
443
+ if (typeof globalThis.navigator.userAgent !== 'undefined')
444
+ return globalThis.navigator.userAgent;
445
+ return '';
446
+ })();
447
+ var HIGH_ENTROPY_BRAND_NAME_MAP = {
448
+ 'Google Chrome': 'Chrome',
449
+ 'Microsoft Edge': 'Edge',
450
+ 'Microsoft Edge WebView2': 'Edge WebView2',
451
+ 'Android WebView': 'Chrome WebView',
452
+ 'HeadlessChrome': 'Chrome Headless',
453
+ 'OperaMobile': 'Opera Mobi',
454
+ };
455
+ var OS_RESOLVER_MAP = [
456
+ [/windows nt (6\.[23]); arm/i, OS.Windows, resolveWindowsVersion],
457
+ [/windows (?:phone|mobile|iot)(?: os)?[\/ ]?([\d.]*( se)?)/i, OS.Windows, resolveWindowsVersion],
458
+ [/windows[\/ ](1[01]|2000|3\.1|7|8(\.1)?|9[58]|me|server 20\d\d( r2)?|vista|xp)/i, OS.Windows, resolveWindowsVersion],
459
+ [/windows nt ?([\d.)]*)(?!.+xbox)/i, OS.Windows, resolveWindowsVersion],
460
+ [/\bwin(?=3| ?9|n)(?:nt| 9x )?([\d.;]*)/i, OS.Windows, resolveWindowsVersion],
461
+ [/windows ce\/?([\d.]*)/i, OS.Windows, resolveWindowsVersion],
462
+ [/[adehimnop]{4,7}\b(?:.*os (\w+) like mac|; opera)/i, OS.iOS, resolveUnderscoreVersion],
463
+ [/(?:ios;fbsv|ios(?=.+ip(?:ad|hone))|ip(?:ad|hone)(?: |.+i(?:pad)?)os)[\/ ]([\w.]+)/i, OS.iOS, resolveUnderscoreVersion],
464
+ [/cfnetwork\/.+darwin/i, OS.iOS, resolveUnderscoreVersion],
465
+ [/mac os x ?([\w. ]*)/i, OS.MacOS, resolveUnderscoreVersion],
466
+ [/(?:macintosh|mac_powerpc\b)(?!.+(haiku|morphos))/i, OS.MacOS, resolveUnderscoreVersion],
467
+ [/droid ([\w.]+)\b.+(android[- ]x86)/i, OS.Android],
468
+ [/android\w*[-\/.; ]?([\d.]*)/i, OS.Android],
469
+ ];
470
+ var ENGINE_RESOLVER_MAP = [
471
+ [/windows.+ edge\/([\w.]+)/i, Engines.EdgeHTML],
472
+ [/arkweb\/([\w.]+)/i, Engines.ArkWeb],
473
+ [/webkit\/537\.36.+chrome\/(?!27)([\w.]+)/i, Engines.Blink],
474
+ [/presto\/([\w.]+)/i, Engines.Presto],
475
+ [/webkit\/([\w.]+)/i, Engines.WebKit],
476
+ [/trident\/([\w.]+)/i, Engines.Trident],
477
+ [/netfront\/([\w.]+)/i, Engines.NetFront],
478
+ [/khtml[\/ ]\(?([\w.]+)/i, Engines.KHTML],
479
+ [/tasman[\/ ]\(?([\w.]+)/i, Engines.Tasman],
480
+ [/rv:([\w.]{1,9})\b.+gecko/i, Engines.Gecko]
481
+ ];
482
+ var BROWSER_RESOLVER_MAP = [
483
+ [/\b(?:crmo|crios)\/([\w.]+)/i, Browsers.Chrome],
484
+ [/webview.+edge\/([\w.]+)/i, Browsers.Edge],
485
+ [/edg(?:e|ios|a)?\/([\w.]+)/i, Browsers.Edge],
486
+ [/opera mini\/([-\w.]+)/i, Browsers.Opera],
487
+ [/opera [mobileta]{3,6}\b.+version\/([-\w.]+)/i, Browsers.Opera],
488
+ [/opera(?:.+version\/|[\/ ]+)([\w.]+)/i, Browsers.Opera],
489
+ [/opios[\/ ]+([\w.]+)/i, Browsers.Opera],
490
+ [/\bop(?:rg)?x\/([\w.]+)/i, Browsers.Opera],
491
+ [/\bopr\/([\w.]+)/i, Browsers.Opera],
492
+ [/iemobile(?:browser|boat|jet)[\/ ]?([\d.]*)/i, Browsers.IE],
493
+ [/(?:ms|\()ie ([\w.]+)/i, Browsers.IE],
494
+ [/trident.+rv[: ]([\w.]{1,9})\b.+like gecko/i, Browsers.IE],
495
+ [/\bfocus\/([\w.]+)/i, Browsers.Firefox],
496
+ [/\bopt\/([\w.]+)/i, Browsers.Opera],
497
+ [/coast\/([\w.]+)/i, Browsers.Opera],
498
+ [/fxios\/([\w.-]+)/i, Browsers.Firefox],
499
+ [/samsungbrowser\/([\w.]+)/i, Browsers.SamsungInternet],
500
+ [/headlesschrome(?:\/([\w.]+)| )/i, Browsers.Chrome],
501
+ [/wv\).+chrome\/([\w.]+).+edgw\//i, Browsers.Edge],
502
+ [/ wv\).+(chrome)\/([\w.]+)/i, Browsers.Chrome],
503
+ [/chrome\/([\w.]+) mobile/i, Browsers.Chrome],
504
+ [/chrome\/v?([\w.]+)/i, Browsers.Chrome],
505
+ [/version\/([\w.,]+) .*mobile(?:\/\w+ | ?)safari/i, Browsers.Safari],
506
+ [/iphone .*mobile(?:\/\w+ | ?)safari/i, Browsers.Safari],
507
+ [/version\/([\w.,]+) .*safari/i, Browsers.Safari],
508
+ [/webkit.+?(?:mobile ?safari|safari)(\/[\w.]+)/i, Browsers.Safari, '1'],
509
+ [/(?:mobile|tablet);.*firefox\/([\w.-]+)/i, Browsers.Firefox],
510
+ [/mobile vr; rv:([\w.]+)\).+firefox/i, Browsers.Firefox],
511
+ [/firefox\/([\w.]+)/i, Browsers.Firefox],
512
+ ];
513
+
514
+ var currentUserAgent = USER_AGENT;
515
+ var parsedCache = null;
516
+ var parsedFromHighEntropyValuesOS = {};
517
+ var parsedFromHighEntropyValuesBrowser = {};
518
+ var parsedFromHighEntropyValuesEngine = {};
519
+ var parsedFromHighEntropyValuesDevice = null;
520
+ function resolveVersion(string, resolver) {
521
+ if (typeof resolver === 'function')
522
+ return resolver(string);
523
+ if (typeof resolver === 'string')
524
+ return resolver;
525
+ if (typeof string === 'undefined')
526
+ return '';
527
+ return string;
528
+ }
529
+ function normalizeBrand(entry) {
530
+ if (entry === null || typeof entry === 'undefined')
531
+ return { brand: '', version: '' };
532
+ if (typeof entry === 'string')
533
+ return { brand: entry, version: '' };
534
+ return { brand: entry.brand, version: entry.version };
535
+ }
536
+ function getParsedCache() {
537
+ if (parsedCache !== null && parsedCache.userAgent === currentUserAgent)
538
+ return parsedCache;
539
+ parsedCache = {
540
+ userAgent: currentUserAgent,
541
+ os: parseOS(),
542
+ browser: parseBrowser(),
543
+ engine: parseEngine(),
544
+ };
545
+ return parsedCache;
546
+ }
547
+ function parseOS() {
548
+ var result = { name: OS.Unknown, version: '' };
549
+ for (var i = 0; i < OS_RESOLVER_MAP.length; i++) {
550
+ var map = OS_RESOLVER_MAP[i];
551
+ var matched = currentUserAgent.match(map[0]);
552
+ if (matched !== null) {
553
+ result.name = map[1];
554
+ result.version = resolveVersion(matched[1], map[2]);
555
+ break;
556
+ }
557
+ }
558
+ if (result.name === OS.iOS && compareVersion(result.version, '18.6') === 0) {
559
+ var version = /\) Version\/([\d.]+)/.exec(currentUserAgent);
560
+ if (version !== null) {
561
+ var major = parseInt(version[1].split('.')[0], 10);
562
+ if (major >= 26)
563
+ result.version = version[1];
564
+ }
565
+ }
566
+ if (currentUserAgent === USER_AGENT) {
567
+ if (typeof parsedFromHighEntropyValuesOS.name !== 'undefined')
568
+ result.name = parsedFromHighEntropyValuesOS.name;
569
+ if (typeof parsedFromHighEntropyValuesOS.version !== 'undefined')
570
+ result.version = parsedFromHighEntropyValuesOS.version;
571
+ if (result.name === OS.MacOS && typeof globalThis.navigator.standalone !== 'undefined' && globalThis.navigator.maxTouchPoints > 2)
572
+ result.name = OS.iOS;
573
+ }
574
+ return result;
575
+ }
576
+ function parseBrowser() {
577
+ var result = { name: Browsers.Unknown, version: '' };
578
+ for (var i = 0; i < BROWSER_RESOLVER_MAP.length; i++) {
579
+ var map = BROWSER_RESOLVER_MAP[i];
580
+ var matched = currentUserAgent.match(map[0]);
581
+ if (matched !== null) {
582
+ result.name = map[1];
583
+ result.version = resolveVersion(matched[1], map[2]);
584
+ break;
585
+ }
586
+ }
587
+ if (currentUserAgent === USER_AGENT) {
588
+ if (typeof parsedFromHighEntropyValuesBrowser.name !== 'undefined')
589
+ result.name = parsedFromHighEntropyValuesBrowser.name;
590
+ if (typeof parsedFromHighEntropyValuesBrowser.version !== 'undefined')
591
+ result.version = parsedFromHighEntropyValuesBrowser.version;
592
+ }
593
+ return result;
594
+ }
595
+ function parseEngine() {
596
+ var result = { name: Engines.Unknown, version: '' };
597
+ for (var i = 0; i < ENGINE_RESOLVER_MAP.length; i++) {
598
+ var map = ENGINE_RESOLVER_MAP[i];
599
+ var matched = currentUserAgent.match(map[0]);
600
+ if (matched !== null) {
601
+ result.name = map[1];
602
+ result.version = resolveVersion(matched[1], map[2]);
603
+ break;
604
+ }
605
+ }
606
+ if (currentUserAgent === USER_AGENT) {
607
+ if (typeof parsedFromHighEntropyValuesEngine.name !== 'undefined')
608
+ result.name = parsedFromHighEntropyValuesEngine.name;
609
+ if (typeof parsedFromHighEntropyValuesEngine.version !== 'undefined')
610
+ result.version = parsedFromHighEntropyValuesEngine.version;
611
+ }
612
+ return result;
613
+ }
614
+ function parseFromHighEntropyValues() {
615
+ if (typeof globalThis.navigator === 'undefined' || typeof globalThis.navigator.userAgentData === 'undefined' || typeof globalThis.navigator.userAgentData.getHighEntropyValues === 'undefined')
616
+ return Promise.resolve();
617
+ return globalThis.navigator.userAgentData
618
+ .getHighEntropyValues(['brands', 'fullVersionList', 'mobile', 'model', 'platform', 'platformVersion', 'architecture', 'formFactors', 'bitness', 'uaFullVersion', 'wow64'])
619
+ .then(function (result) {
620
+ try {
621
+ var brands = result.fullVersionList || result.brands || [];
622
+ var platformVersion = result.platformVersion;
623
+ var platform = result.platform;
624
+ var browserName = getParsedCache().browser.name;
625
+ var prevBrandName = null;
626
+ for (var i = 0; i < brands.length; i++) {
627
+ var brand = normalizeBrand(brands[i]);
628
+ var brandVersion = brand.version;
629
+ var brandName = brand.brand;
630
+ if (/not.a.brand/i.test(brandName))
631
+ continue;
632
+ if (prevBrandName === null || (/Chrom/.test(prevBrandName) && brandName !== 'Chromium') || (prevBrandName === 'Edge' && /WebView2/.test(brandName))) {
633
+ brandName = HIGH_ENTROPY_BRAND_NAME_MAP[brandName] || brandName;
634
+ prevBrandName = browserName;
635
+ if (prevBrandName === null || /Chrom/.test(prevBrandName) || !/Chrom/.test(brandName)) {
636
+ browserName = brandName;
637
+ if (browserName === 'Chrome' || browserName === 'Chrome WebView' || browserName === 'Chrome Headless')
638
+ parsedFromHighEntropyValuesBrowser.name = Browsers.Chrome;
639
+ else if (browserName === 'Edge' || browserName === 'Edge WebView2')
640
+ parsedFromHighEntropyValuesBrowser.name = Browsers.Edge;
641
+ else if (browserName === 'Opera Mobi')
642
+ parsedFromHighEntropyValuesBrowser.name = Browsers.Opera;
643
+ parsedFromHighEntropyValuesBrowser.version = brandVersion;
644
+ }
645
+ prevBrandName = brandName;
646
+ }
647
+ if (brandName === 'Chromium')
648
+ parsedFromHighEntropyValuesEngine.version = brandVersion;
649
+ }
650
+ if (typeof platformVersion === 'string') {
651
+ if (getParsedCache().os.name === OS.Windows) {
652
+ if (parseInt(platformVersion.split('.')[0], 10) >= 13)
653
+ parsedFromHighEntropyValuesOS.version = '11';
654
+ else
655
+ parsedFromHighEntropyValuesOS.version = '10';
656
+ }
657
+ else {
658
+ parsedFromHighEntropyValuesOS.version = platformVersion;
659
+ }
660
+ }
661
+ if (typeof platform === 'string') {
662
+ if (/android/i.test(platform))
663
+ parsedFromHighEntropyValuesOS.name = OS.Android;
664
+ else if (/ios|iphone|ipad/i.test(platform))
665
+ parsedFromHighEntropyValuesOS.name = OS.iOS;
666
+ else if (/windows|win32/i.test(platform))
667
+ parsedFromHighEntropyValuesOS.name = OS.Windows;
668
+ else if (/macos|macintel/i.test(platform))
669
+ parsedFromHighEntropyValuesOS.name = OS.MacOS;
670
+ }
671
+ if (result.mobile === true)
672
+ parsedFromHighEntropyValuesDevice = Devices.Mobile;
673
+ parsedCache = null;
674
+ }
675
+ catch (_) {
676
+ }
677
+ })
678
+ .catch(function () {
679
+ });
680
+ }
681
+ function parseFromNavigatorGPU() {
682
+ if (typeof globalThis.navigator === 'undefined' || typeof globalThis.navigator.gpu === 'undefined')
683
+ return Promise.resolve();
684
+ return globalThis.navigator.gpu
685
+ .requestAdapter()
686
+ .then(function (adapter) {
687
+ if (adapter !== null) {
688
+ var info = adapter.info;
689
+ info.architecture;
690
+ info.description;
691
+ info.device;
692
+ info.vendor;
693
+ }
694
+ })
695
+ .catch(function () {
696
+ });
697
+ }
698
+ Promise.all([
699
+ parseFromHighEntropyValues(),
700
+ parseFromNavigatorGPU(),
701
+ ]).then(function () {
702
+ });
703
+ EventListener.add(globalThis, {
704
+ type: 'languagechange', callback: function () {
705
+ }
706
+ });
707
+ var Platform = {
708
+ get os() {
709
+ return getParsedCache().os;
710
+ },
711
+ get browser() {
712
+ return getParsedCache().browser;
713
+ }};
714
+
353
715
  var PIP_PRESENTATION_MODE = 'picture-in-picture';
354
716
  var INLINE_PRESENTATION_MODE = 'inline';
355
- var lastPipVideo = null;
717
+ var videoElement = null;
718
+ var lastFallbackVideoElement = null;
356
719
  var eventsBridged = false;
357
720
  var PIP_BRIDGE_KEY = (function () {
358
721
  if (typeof Symbol === 'function') {
@@ -367,43 +730,57 @@ var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, deta
367
730
  var onErrorSubscriptionManager = createSubscriptionManager(attachOnError, detachOnError);
368
731
  var Pip = {
369
732
  get supported() {
370
- return getEnabled();
733
+ return getSupported();
371
734
  },
372
735
  get element() {
373
736
  return getElement();
374
737
  },
375
- get isPip() {
376
- return getIsPip();
738
+ get isActive() {
739
+ return getIsActive();
377
740
  },
378
741
  request: request,
379
742
  exit: exit,
380
- onChange: onChangeSubscriptionManager.subscribe,
381
- onError: onErrorSubscriptionManager.subscribe,
743
+ toggle: toggle,
744
+ onChange: onChange,
745
+ onError: onError,
382
746
  Constants: {},
383
747
  Errors: {
384
748
  NotSupportedError: NotSupportedError,
385
749
  InvalidStateError: InvalidStateError,
386
750
  },
387
751
  };
752
+ function getHTMLVideoElement() {
753
+ var selected = globalThis.document.querySelector('video');
754
+ if (selected !== null)
755
+ return selected;
756
+ if (videoElement === null)
757
+ return videoElement = globalThis.document.createElement('video');
758
+ return videoElement;
759
+ }
388
760
  function hasStandardApi() {
389
761
  return typeof globalThis.document.pictureInPictureEnabled !== 'undefined';
390
762
  }
763
+ function hasWebkitApi() {
764
+ return typeof getHTMLVideoElement().webkitSetPresentationMode === 'function';
765
+ }
391
766
  function getDefaultTarget() {
392
767
  var video = globalThis.document.querySelector('video');
393
- return video !== null ? video : undefined;
768
+ if (video !== null)
769
+ return video;
770
+ return undefined;
394
771
  }
395
- function createPipEventPayload(nativeEvent, element, isPip) {
772
+ function createPipEventPayload(nativeEvent, element, isActive) {
396
773
  return {
397
774
  nativeEvent: nativeEvent,
398
775
  element: element,
399
- isPip: isPip
776
+ isActive: isActive
400
777
  };
401
778
  }
402
- function emitChange(nativeEvent, element, isPip) {
403
- onChangeSubscriptionManager.emit(createPipEventPayload(nativeEvent, element, isPip));
779
+ function emitChange(nativeEvent, element, isActive) {
780
+ onChangeSubscriptionManager.emit(createPipEventPayload(nativeEvent, element, isActive));
404
781
  }
405
- function emitError(nativeEvent, element, isPip) {
406
- onErrorSubscriptionManager.emit(createPipEventPayload(nativeEvent, element, isPip));
782
+ function emitError(nativeEvent, element, isActive) {
783
+ onErrorSubscriptionManager.emit(createPipEventPayload(nativeEvent, element, isActive));
407
784
  }
408
785
  function onEnterPictureInPicture(event) {
409
786
  var target = event.target;
@@ -418,16 +795,16 @@ function onLeavePictureInPicture(event) {
418
795
  function onPictureInPictureError(event) {
419
796
  var target = event.target;
420
797
  if (target instanceof globalThis.HTMLVideoElement)
421
- emitError(event, target, getIsPip());
798
+ emitError(event, target, getIsActive());
422
799
  }
423
800
  function onWebkitPresentationModeChanged(event) {
424
801
  if (this.webkitPresentationMode === PIP_PRESENTATION_MODE) {
425
- lastPipVideo = this;
802
+ lastFallbackVideoElement = this;
426
803
  emitChange(event, this, true);
427
804
  return;
428
805
  }
429
- if (this.webkitPresentationMode === INLINE_PRESENTATION_MODE && lastPipVideo === this) {
430
- lastPipVideo = null;
806
+ if (this.webkitPresentationMode === INLINE_PRESENTATION_MODE && lastFallbackVideoElement === this) {
807
+ lastFallbackVideoElement = null;
431
808
  emitChange(event, this, false);
432
809
  }
433
810
  }
@@ -448,19 +825,19 @@ function bridgeEvents() {
448
825
  if (eventsBridged)
449
826
  return;
450
827
  eventsBridged = true;
451
- if (hasStandardApi())
828
+ if (hasStandardApi() && !hasWebkitApi())
452
829
  return;
453
830
  bridgeWebkitVideoEvents();
454
831
  if (typeof globalThis.MutationObserver === 'undefined')
455
832
  return;
456
833
  var observer = new globalThis.MutationObserver(function (records) {
457
- if (lastPipVideo !== null) {
834
+ if (lastFallbackVideoElement !== null) {
458
835
  var removed = false;
459
836
  for (var i = 0; i < records.length; i++) {
460
837
  var removedNodes = records[i].removedNodes;
461
838
  for (var j = 0; j < removedNodes.length; j++) {
462
839
  var node = removedNodes[j];
463
- if (node === lastPipVideo || (node.nodeType === Node.ELEMENT_NODE && node.contains(lastPipVideo))) {
840
+ if (node === lastFallbackVideoElement || (node.nodeType === Node.ELEMENT_NODE && node.contains(lastFallbackVideoElement))) {
464
841
  removed = true;
465
842
  break;
466
843
  }
@@ -468,8 +845,8 @@ function bridgeEvents() {
468
845
  if (removed)
469
846
  break;
470
847
  }
471
- if (removed && !globalThis.document.contains(lastPipVideo))
472
- lastPipVideo = null;
848
+ if (removed && !globalThis.document.contains(lastFallbackVideoElement))
849
+ lastFallbackVideoElement = null;
473
850
  }
474
851
  for (var i = 0; i < records.length; i++) {
475
852
  var addedNodes = records[i].addedNodes;
@@ -516,26 +893,21 @@ function attachOnError() {
516
893
  function detachOnError() {
517
894
  EventListener.remove(globalThis.document, { type: 'pictureinpictureerror', callback: onPictureInPictureError, options: false });
518
895
  }
519
- function getEnabled() {
896
+ function getSupported() {
520
897
  if (typeof globalThis.document.pictureInPictureEnabled === 'boolean')
521
898
  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');
899
+ var video = getHTMLVideoElement();
528
900
  return typeof video.webkitSupportsPresentationMode === 'function' && video.webkitSupportsPresentationMode(PIP_PRESENTATION_MODE);
529
901
  }
530
902
  function getElement() {
531
903
  var currentElement = globalThis.document.pictureInPictureElement;
532
904
  if (currentElement !== null && typeof currentElement !== 'undefined')
533
905
  return currentElement;
534
- if (lastPipVideo !== null && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE)
535
- return lastPipVideo;
906
+ if (lastFallbackVideoElement !== null && lastFallbackVideoElement.webkitPresentationMode === PIP_PRESENTATION_MODE)
907
+ return lastFallbackVideoElement;
536
908
  return null;
537
909
  }
538
- function getIsPip() {
910
+ function getIsActive() {
539
911
  return getElement() !== null;
540
912
  }
541
913
  function request(target) {
@@ -544,12 +916,14 @@ function request(target) {
544
916
  target = getDefaultTarget();
545
917
  if (typeof target === 'undefined')
546
918
  return reject(new NotSupportedError('Failed to enter Picture-in-Picture mode.'));
919
+ if (getIsActive() && getElement() !== target && Platform.browser.name === Browsers.Safari && Platform.os.name === OS.iOS)
920
+ return reject(new NotSupportedError('There is already a Picture-in-Picture element in this document.'));
547
921
  var tagName = target.tagName.toLowerCase();
548
922
  if (tagName !== 'video')
549
923
  return reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
550
924
  var method = target.requestPictureInPicture;
551
- var isWebkitPipActive = lastPipVideo !== null && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE;
552
- if (typeof method === 'function' && !isWebkitPipActive) {
925
+ var isWebkitPipActive = lastFallbackVideoElement !== null && lastFallbackVideoElement.webkitPresentationMode === PIP_PRESENTATION_MODE;
926
+ if (typeof method === 'function' && !hasWebkitApi() && !isWebkitPipActive) {
553
927
  var result = method.call(target);
554
928
  if (typeof result !== 'undefined' && typeof result.then === 'function') {
555
929
  result
@@ -570,12 +944,8 @@ function request(target) {
570
944
  if (typeof target !== 'undefined' && typeof target.webkitSupportsPresentationMode === 'function' && target.webkitSupportsPresentationMode(PIP_PRESENTATION_MODE) && typeof target.webkitSetPresentationMode === 'function') {
571
945
  if (target.disablePictureInPicture)
572
946
  return reject(new NotSupportedError('Picture-in-Picture is disabled on this element.'));
573
- if (!hasStandardApi())
574
- bridgeSingleVideoNode(target);
947
+ bridgeSingleVideoNode(target);
575
948
  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
949
  return resolve();
580
950
  }
581
951
  reject(new NotSupportedError('The "' + tagName + '" element does not support Picture-in-Picture requests.'));
@@ -586,7 +956,7 @@ function request(target) {
586
956
  function exit() {
587
957
  return new Promise(function (resolve, reject) {
588
958
  var method = globalThis.document.exitPictureInPicture;
589
- if (typeof method === 'function') {
959
+ if (typeof method === 'function' && !hasWebkitApi()) {
590
960
  var result = method.call(globalThis.document);
591
961
  if (typeof result !== 'undefined' && typeof result.then === 'function') {
592
962
  result
@@ -604,9 +974,8 @@ function exit() {
604
974
  return resolve();
605
975
  }
606
976
  function fallbackToWebkit() {
607
- if (lastPipVideo !== null && typeof lastPipVideo.webkitSetPresentationMode === 'function' && lastPipVideo.webkitPresentationMode === PIP_PRESENTATION_MODE) {
608
- lastPipVideo.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
609
- lastPipVideo = null;
977
+ if (lastFallbackVideoElement !== null && typeof lastFallbackVideoElement.webkitSetPresentationMode === 'function') {
978
+ lastFallbackVideoElement.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
610
979
  return resolve();
611
980
  }
612
981
  var videos = globalThis.document.querySelectorAll('video');
@@ -614,17 +983,49 @@ function exit() {
614
983
  var video = videos[i];
615
984
  if (typeof video.webkitSetPresentationMode === 'function' && video.webkitPresentationMode === PIP_PRESENTATION_MODE) {
616
985
  video.webkitSetPresentationMode(INLINE_PRESENTATION_MODE);
617
- lastPipVideo = null;
618
986
  return resolve();
619
987
  }
620
988
  }
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.'));
989
+ return resolve();
624
990
  }
625
991
  fallbackToWebkit();
626
992
  });
627
993
  }
994
+ function toggle(target) {
995
+ var current = getElement();
996
+ if (typeof target !== 'undefined') {
997
+ if (current === target)
998
+ return this.exit();
999
+ else
1000
+ return this.request(target);
1001
+ }
1002
+ if (current !== null)
1003
+ return this.exit();
1004
+ else
1005
+ return this.request(target);
1006
+ }
1007
+ function onChange(targetOrListener, listenerOrOptions, options) {
1008
+ if (typeof targetOrListener === 'function')
1009
+ return onChangeSubscriptionManager.subscribe(targetOrListener, listenerOrOptions);
1010
+ var target = targetOrListener;
1011
+ var listener = listenerOrOptions;
1012
+ function wrappedListener(payload) {
1013
+ if (payload.element === target)
1014
+ listener(payload);
1015
+ }
1016
+ return onChangeSubscriptionManager.subscribe(wrappedListener, options);
1017
+ }
1018
+ function onError(targetOrListener, listenerOrOptions, options) {
1019
+ if (typeof targetOrListener === 'function')
1020
+ return onErrorSubscriptionManager.subscribe(targetOrListener, listenerOrOptions);
1021
+ var target = targetOrListener;
1022
+ var listener = listenerOrOptions;
1023
+ function wrappedListener(payload) {
1024
+ if (payload.element === target)
1025
+ listener(payload);
1026
+ }
1027
+ return onErrorSubscriptionManager.subscribe(wrappedListener, options);
1028
+ }
628
1029
  bridgeEvents();
629
1030
 
630
1031
  module.exports = Pip;
@@ -5,11 +5,14 @@ declare const InvalidStateError: ErrorConstructor;
5
5
  declare interface PipInstance {
6
6
  get supported(): boolean;
7
7
  get element(): HTMLVideoElement | null;
8
- get isPip(): boolean;
8
+ get isActive(): boolean;
9
9
  request(target?: HTMLVideoElement): Promise<void>;
10
10
  exit(): Promise<void>;
11
+ toggle(target?: HTMLVideoElement): Promise<void>;
11
12
  onChange(listener: (payload: PipEventPayload) => void, options?: AddEventListenerOptions): () => void;
13
+ onChange(target: HTMLVideoElement, listener: (payload: PipEventPayload) => void, options?: AddEventListenerOptions): () => void;
12
14
  onError(listener: (payload: PipEventPayload) => void, options?: AddEventListenerOptions): () => void;
15
+ onError(target: HTMLVideoElement, listener: (payload: PipEventPayload) => void, options?: AddEventListenerOptions): () => void;
13
16
  Constants: {};
14
17
  Errors: {
15
18
  NotSupportedError: typeof NotSupportedError;
@@ -19,7 +22,7 @@ declare interface PipInstance {
19
22
  declare interface PipEventPayload {
20
23
  nativeEvent: Event;
21
24
  element: HTMLVideoElement;
22
- isPip: boolean;
25
+ isActive: boolean;
23
26
  }
24
27
 
25
28
  declare global {