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