native-fn 1.2.2 → 1.3.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 (151) hide show
  1. package/README.md +32 -8
  2. package/dist/index.d.ts +42 -21
  3. package/dist/native.cjs +412 -110
  4. package/dist/native.min.cjs +1 -1
  5. package/dist/native.min.mjs +1 -1
  6. package/dist/native.mjs +412 -110
  7. package/dist/native.umd.js +412 -110
  8. package/dist/native.umd.min.js +1 -1
  9. package/dist/plugin/appearance/index.cjs +16 -18
  10. package/dist/plugin/appearance/index.d.ts +2 -2
  11. package/dist/plugin/appearance/index.mjs +17 -19
  12. package/dist/plugin/appearance/src/plugin/appearance/constants/index.d.ts +1 -1
  13. package/dist/plugin/appearance/src/plugin/dimension/constants/index.d.ts +2 -3
  14. package/dist/plugin/appearance/src/plugin/dimension/cores/index.d.ts +15 -0
  15. package/dist/plugin/appearance/src/plugin/dimension/types/dimensions.d.ts +26 -20
  16. package/dist/plugin/appearance/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  17. package/dist/plugin/appearance/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  18. package/dist/plugin/appearance/src/plugin/platform/constants/index.d.ts +1 -1
  19. package/dist/plugin/appearance/src/utils/insert-sort.d.ts +1 -0
  20. package/dist/plugin/badge/src/plugin/appearance/constants/index.d.ts +1 -1
  21. package/dist/plugin/badge/src/plugin/dimension/constants/index.d.ts +2 -3
  22. package/dist/plugin/badge/src/plugin/dimension/cores/index.d.ts +15 -0
  23. package/dist/plugin/badge/src/plugin/dimension/types/dimensions.d.ts +26 -20
  24. package/dist/plugin/badge/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  25. package/dist/plugin/badge/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  26. package/dist/plugin/badge/src/plugin/platform/constants/index.d.ts +1 -1
  27. package/dist/plugin/badge/src/utils/insert-sort.d.ts +1 -0
  28. package/dist/plugin/battery/index.cjs +4 -6
  29. package/dist/plugin/battery/index.mjs +4 -6
  30. package/dist/plugin/battery/src/plugin/appearance/constants/index.d.ts +1 -1
  31. package/dist/plugin/battery/src/plugin/dimension/constants/index.d.ts +2 -3
  32. package/dist/plugin/battery/src/plugin/dimension/cores/index.d.ts +15 -0
  33. package/dist/plugin/battery/src/plugin/dimension/types/dimensions.d.ts +26 -20
  34. package/dist/plugin/battery/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  35. package/dist/plugin/battery/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  36. package/dist/plugin/battery/src/plugin/platform/constants/index.d.ts +1 -1
  37. package/dist/plugin/battery/src/utils/insert-sort.d.ts +1 -0
  38. package/dist/plugin/clipboard/src/plugin/appearance/constants/index.d.ts +1 -1
  39. package/dist/plugin/clipboard/src/plugin/dimension/constants/index.d.ts +2 -3
  40. package/dist/plugin/clipboard/src/plugin/dimension/cores/index.d.ts +15 -0
  41. package/dist/plugin/clipboard/src/plugin/dimension/types/dimensions.d.ts +26 -20
  42. package/dist/plugin/clipboard/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  43. package/dist/plugin/clipboard/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  44. package/dist/plugin/clipboard/src/plugin/platform/constants/index.d.ts +1 -1
  45. package/dist/plugin/clipboard/src/utils/insert-sort.d.ts +1 -0
  46. package/dist/plugin/dimension/index.cjs +456 -97
  47. package/dist/plugin/dimension/index.d.ts +45 -24
  48. package/dist/plugin/dimension/index.mjs +457 -97
  49. package/dist/plugin/dimension/src/plugin/appearance/constants/index.d.ts +1 -1
  50. package/dist/plugin/dimension/src/plugin/dimension/constants/index.d.ts +2 -3
  51. package/dist/plugin/dimension/src/plugin/dimension/cores/index.d.ts +15 -0
  52. package/dist/plugin/dimension/src/plugin/dimension/types/dimensions.d.ts +26 -20
  53. package/dist/plugin/dimension/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  54. package/dist/plugin/dimension/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  55. package/dist/plugin/dimension/src/plugin/platform/constants/index.d.ts +1 -1
  56. package/dist/plugin/dimension/src/utils/insert-sort.d.ts +1 -0
  57. package/dist/plugin/fullscreen/index.cjs +9 -11
  58. package/dist/plugin/fullscreen/index.mjs +9 -11
  59. package/dist/plugin/fullscreen/src/plugin/appearance/constants/index.d.ts +1 -1
  60. package/dist/plugin/fullscreen/src/plugin/dimension/constants/index.d.ts +2 -3
  61. package/dist/plugin/fullscreen/src/plugin/dimension/cores/index.d.ts +15 -0
  62. package/dist/plugin/fullscreen/src/plugin/dimension/types/dimensions.d.ts +26 -20
  63. package/dist/plugin/fullscreen/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  64. package/dist/plugin/fullscreen/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  65. package/dist/plugin/fullscreen/src/plugin/platform/constants/index.d.ts +1 -1
  66. package/dist/plugin/fullscreen/src/utils/insert-sort.d.ts +1 -0
  67. package/dist/plugin/geolocation/index.cjs +4 -6
  68. package/dist/plugin/geolocation/index.mjs +4 -6
  69. package/dist/plugin/geolocation/src/plugin/appearance/constants/index.d.ts +1 -1
  70. package/dist/plugin/geolocation/src/plugin/dimension/constants/index.d.ts +2 -3
  71. package/dist/plugin/geolocation/src/plugin/dimension/cores/index.d.ts +15 -0
  72. package/dist/plugin/geolocation/src/plugin/dimension/types/dimensions.d.ts +26 -20
  73. package/dist/plugin/geolocation/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  74. package/dist/plugin/geolocation/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  75. package/dist/plugin/geolocation/src/plugin/platform/constants/index.d.ts +1 -1
  76. package/dist/plugin/geolocation/src/utils/insert-sort.d.ts +1 -0
  77. package/dist/plugin/notification/src/plugin/appearance/constants/index.d.ts +1 -1
  78. package/dist/plugin/notification/src/plugin/dimension/constants/index.d.ts +2 -3
  79. package/dist/plugin/notification/src/plugin/dimension/cores/index.d.ts +15 -0
  80. package/dist/plugin/notification/src/plugin/dimension/types/dimensions.d.ts +26 -20
  81. package/dist/plugin/notification/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  82. package/dist/plugin/notification/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  83. package/dist/plugin/notification/src/plugin/platform/constants/index.d.ts +1 -1
  84. package/dist/plugin/notification/src/utils/insert-sort.d.ts +1 -0
  85. package/dist/plugin/open/index.cjs +6 -6
  86. package/dist/plugin/open/index.d.ts +16 -0
  87. package/dist/plugin/open/index.mjs +6 -6
  88. package/dist/plugin/open/src/plugin/appearance/constants/index.d.ts +1 -1
  89. package/dist/plugin/open/src/plugin/dimension/constants/index.d.ts +2 -3
  90. package/dist/plugin/open/src/plugin/dimension/cores/index.d.ts +15 -0
  91. package/dist/plugin/open/src/plugin/dimension/types/dimensions.d.ts +26 -20
  92. package/dist/plugin/open/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  93. package/dist/plugin/open/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  94. package/dist/plugin/open/src/plugin/platform/constants/index.d.ts +1 -1
  95. package/dist/plugin/open/src/utils/insert-sort.d.ts +1 -0
  96. package/dist/plugin/permission/src/plugin/appearance/constants/index.d.ts +1 -1
  97. package/dist/plugin/permission/src/plugin/dimension/constants/index.d.ts +2 -3
  98. package/dist/plugin/permission/src/plugin/dimension/cores/index.d.ts +15 -0
  99. package/dist/plugin/permission/src/plugin/dimension/types/dimensions.d.ts +26 -20
  100. package/dist/plugin/permission/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  101. package/dist/plugin/permission/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  102. package/dist/plugin/permission/src/plugin/platform/constants/index.d.ts +1 -1
  103. package/dist/plugin/permission/src/utils/insert-sort.d.ts +1 -0
  104. package/dist/plugin/pip/index.cjs +9 -11
  105. package/dist/plugin/pip/index.mjs +9 -11
  106. package/dist/plugin/pip/src/plugin/appearance/constants/index.d.ts +1 -1
  107. package/dist/plugin/pip/src/plugin/dimension/constants/index.d.ts +2 -3
  108. package/dist/plugin/pip/src/plugin/dimension/cores/index.d.ts +15 -0
  109. package/dist/plugin/pip/src/plugin/dimension/types/dimensions.d.ts +26 -20
  110. package/dist/plugin/pip/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  111. package/dist/plugin/pip/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  112. package/dist/plugin/pip/src/plugin/platform/constants/index.d.ts +1 -1
  113. package/dist/plugin/pip/src/utils/insert-sort.d.ts +1 -0
  114. package/dist/plugin/platform/index.cjs +11 -12
  115. package/dist/plugin/platform/index.d.ts +17 -1
  116. package/dist/plugin/platform/index.mjs +5 -5
  117. package/dist/plugin/platform/src/plugin/appearance/constants/index.d.ts +1 -1
  118. package/dist/plugin/platform/src/plugin/dimension/constants/index.d.ts +2 -3
  119. package/dist/plugin/platform/src/plugin/dimension/cores/index.d.ts +15 -0
  120. package/dist/plugin/platform/src/plugin/dimension/types/dimensions.d.ts +26 -20
  121. package/dist/plugin/platform/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  122. package/dist/plugin/platform/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  123. package/dist/plugin/platform/src/plugin/platform/constants/index.d.ts +1 -1
  124. package/dist/plugin/platform/src/utils/insert-sort.d.ts +1 -0
  125. package/dist/plugin/theme/index.cjs +5 -5
  126. package/dist/plugin/theme/index.mjs +5 -5
  127. package/dist/plugin/theme/src/plugin/appearance/constants/index.d.ts +1 -1
  128. package/dist/plugin/theme/src/plugin/dimension/constants/index.d.ts +2 -3
  129. package/dist/plugin/theme/src/plugin/dimension/cores/index.d.ts +15 -0
  130. package/dist/plugin/theme/src/plugin/dimension/types/dimensions.d.ts +26 -20
  131. package/dist/plugin/theme/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  132. package/dist/plugin/theme/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  133. package/dist/plugin/theme/src/plugin/platform/constants/index.d.ts +1 -1
  134. package/dist/plugin/theme/src/utils/insert-sort.d.ts +1 -0
  135. package/dist/plugin/vibration/src/plugin/appearance/constants/index.d.ts +1 -1
  136. package/dist/plugin/vibration/src/plugin/dimension/constants/index.d.ts +2 -3
  137. package/dist/plugin/vibration/src/plugin/dimension/cores/index.d.ts +15 -0
  138. package/dist/plugin/vibration/src/plugin/dimension/types/dimensions.d.ts +26 -20
  139. package/dist/plugin/vibration/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  140. package/dist/plugin/vibration/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  141. package/dist/plugin/vibration/src/plugin/platform/constants/index.d.ts +1 -1
  142. package/dist/plugin/vibration/src/utils/insert-sort.d.ts +1 -0
  143. package/dist/src/plugin/appearance/constants/index.d.ts +1 -1
  144. package/dist/src/plugin/dimension/constants/index.d.ts +2 -3
  145. package/dist/src/plugin/dimension/cores/index.d.ts +15 -0
  146. package/dist/src/plugin/dimension/types/dimensions.d.ts +26 -20
  147. package/dist/src/plugin/dimension/utils/create-env-observer.d.ts +16 -7
  148. package/dist/src/plugin/dimension/utils/create-environment-observer.d.ts +33 -0
  149. package/dist/src/plugin/platform/constants/index.d.ts +1 -1
  150. package/dist/src/utils/insert-sort.d.ts +1 -0
  151. package/package.json +1 -1
@@ -61,19 +61,16 @@ var ENV_PRESETS = {
61
61
  left: 'viewport-segment-left',
62
62
  },
63
63
  };
64
- var FALLBACK_DIMENSION = {
65
- innerWidth: -1,
66
- innerHeight: -1,
67
- outerWidth: -1,
68
- outerHeight: -1,
69
- scale: 1,
70
- orientation: exports.Orientation.Unknown,
71
- };
72
- exports.MEDIA_QUERY_LIST = void 0;
64
+ exports.ORIENTATION_MEDIA_QUERY_LIST = void 0;
65
+ if (typeof globalThis.matchMedia !== 'undefined')
66
+ exports.ORIENTATION_MEDIA_QUERY_LIST = globalThis.matchMedia('(orientation: portrait)');
67
+ else
68
+ exports.ORIENTATION_MEDIA_QUERY_LIST = FALLBACK_MEDIA_QUERY_LIST;
69
+ exports.DEVICE_POSTURE_MEDIA_QUERY_LIST = void 0;
73
70
  if (typeof globalThis.matchMedia !== 'undefined')
74
- exports.MEDIA_QUERY_LIST = globalThis.matchMedia('(orientation: portrait)');
71
+ exports.DEVICE_POSTURE_MEDIA_QUERY_LIST = globalThis.matchMedia('(device-posture: folded)');
75
72
  else
76
- exports.MEDIA_QUERY_LIST = FALLBACK_MEDIA_QUERY_LIST;
73
+ exports.DEVICE_POSTURE_MEDIA_QUERY_LIST = FALLBACK_MEDIA_QUERY_LIST;
77
74
 
78
75
  var IE_WRAPPER_STORE = [];
79
76
  var MEDIA_QUERY_LIST_WRAPPER_STORE = [];
@@ -308,6 +305,8 @@ function createSubscriptionManager(attach, detach) {
308
305
  },
309
306
  subscribe: function (listener, options) {
310
307
  if (options === void 0) { options = {}; }
308
+ if (typeof options.signal !== 'undefined' && options.signal.aborted)
309
+ return function () { };
311
310
  var entry = { fn: listener, once: false };
312
311
  if (typeof options.once !== 'undefined')
313
312
  entry.once = options.once;
@@ -326,12 +325,8 @@ function createSubscriptionManager(attach, detach) {
326
325
  EventListener.remove(entry.signal, { type: 'abort', callback: cleanup });
327
326
  removeEntry(entry);
328
327
  };
329
- if (typeof entry.signal !== 'undefined') {
330
- if (entry.signal.aborted)
331
- removeEntry(entry);
332
- else
333
- EventListener.add(entry.signal, { type: 'abort', callback: cleanup });
334
- }
328
+ if (typeof entry.signal !== 'undefined')
329
+ EventListener.add(entry.signal, { type: 'abort', callback: cleanup });
335
330
  return function unsubscribe() {
336
331
  removeEntry(entry);
337
332
  };
@@ -368,15 +363,364 @@ function setStyle(element, styles) {
368
363
  }
369
364
  }
370
365
 
366
+ function createHiddenElement(tagName, focusable) {
367
+ if (focusable === void 0) { focusable = true; }
368
+ var element = globalThis.document.createElement(tagName);
369
+ if (typeof element.width !== 'undefined')
370
+ element.width = '0';
371
+ if (typeof element.height !== 'undefined')
372
+ element.height = '0';
373
+ if (typeof element.border !== 'undefined')
374
+ element.border = '0';
375
+ if (typeof element.frameBorder !== 'undefined')
376
+ element.frameBorder = '0';
377
+ if (typeof element.scrolling !== 'undefined')
378
+ element.scrolling = 'no';
379
+ if (typeof element.cellPadding !== 'undefined')
380
+ element.cellPadding = '0';
381
+ if (typeof element.cellSpacing !== 'undefined')
382
+ element.cellSpacing = '0';
383
+ if (typeof element.frame !== 'undefined')
384
+ element.frame = 'void';
385
+ if (typeof element.rules !== 'undefined')
386
+ element.rules = 'none';
387
+ if (typeof element.noWrap !== 'undefined')
388
+ element.noWrap = true;
389
+ element.tabIndex = -1;
390
+ element.setAttribute('role', 'presentation');
391
+ if (focusable) {
392
+ setStyle(element, {
393
+ width: '1px',
394
+ height: '1px',
395
+ });
396
+ }
397
+ else {
398
+ element.setAttribute('aria-hidden', 'true');
399
+ setStyle(element, {
400
+ width: '0',
401
+ height: '0',
402
+ zIndex: '-9999',
403
+ display: 'none',
404
+ visibility: 'hidden',
405
+ pointerEvents: 'none',
406
+ });
407
+ }
408
+ setStyle(element, {
409
+ position: 'absolute',
410
+ top: '0',
411
+ left: '0',
412
+ padding: '0',
413
+ margin: '0',
414
+ border: 'none',
415
+ outline: 'hidden',
416
+ clip: 'rect(1px, 1px, 1px, 1px)',
417
+ clipPath: 'inset(50%)',
418
+ overflow: 'hidden',
419
+ whiteSpace: 'nowrap',
420
+ });
421
+ return element;
422
+ }
423
+
424
+ var MAX_SEGMENTS_PER_AXIS = 4;
371
425
  function noop() {
372
426
  }
427
+ function getSupportedEnvironment() {
428
+ if (typeof globalThis.CSS !== 'undefined' && typeof globalThis.CSS.supports === 'function') {
429
+ if (globalThis.CSS.supports('x: env(x)'))
430
+ return 'env';
431
+ if (globalThis.CSS.supports('x: constant(x)'))
432
+ return 'constant';
433
+ }
434
+ return undefined;
435
+ }
436
+ function getSegmentGrid() {
437
+ if (typeof globalThis.matchMedia !== 'function')
438
+ return { rows: 1, cols: 1 };
439
+ var cols = 1;
440
+ var rows = 1;
441
+ for (var i = MAX_SEGMENTS_PER_AXIS; i >= 2; i--) {
442
+ if (globalThis.matchMedia('(horizontal-viewport-segments: ' + i + ')').matches) {
443
+ cols = i;
444
+ break;
445
+ }
446
+ }
447
+ for (var i = MAX_SEGMENTS_PER_AXIS; i >= 2; i--) {
448
+ if (globalThis.matchMedia('(vertical-viewport-segments: ' + i + ')').matches) {
449
+ rows = i;
450
+ break;
451
+ }
452
+ }
453
+ return { rows: rows, cols: cols };
454
+ }
455
+ function buildSegmentMediaQueryLists() {
456
+ if (typeof globalThis.matchMedia !== 'function')
457
+ return [];
458
+ var mediaQueryLists = [];
459
+ for (var i = 2; i <= MAX_SEGMENTS_PER_AXIS; i++) {
460
+ mediaQueryLists.push(globalThis.matchMedia('(horizontal-viewport-segments: ' + i + ')'));
461
+ mediaQueryLists.push(globalThis.matchMedia('(vertical-viewport-segments: ' + i + ')'));
462
+ }
463
+ return mediaQueryLists;
464
+ }
465
+ function createViewportSegmentObserver() {
466
+ var viewport = globalThis.viewport;
467
+ var visualViewport = globalThis.visualViewport;
468
+ var devicePosture = globalThis.navigator.devicePosture;
469
+ var hasSegmentsAPI = typeof viewport !== 'undefined';
470
+ var hasLegacySegmentsAPI = !hasSegmentsAPI && typeof visualViewport !== 'undefined' && visualViewport !== null && typeof visualViewport.segments !== 'undefined';
471
+ var hasDevicePosture = typeof devicePosture !== 'undefined';
472
+ var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, detachOnChange);
473
+ var support = getSupportedEnvironment();
474
+ var cachedDiv = null;
475
+ var segmentMediaQueryLists = [];
476
+ var previousSegments = null;
477
+ function attachCSSFallbackListeners() {
478
+ EventListener.add(globalThis, { type: 'resize', callback: onSegmentChange });
479
+ segmentMediaQueryLists = buildSegmentMediaQueryLists();
480
+ for (var i = 0; i < segmentMediaQueryLists.length; i++)
481
+ EventListener.add(segmentMediaQueryLists[i], { type: 'change', callback: onSegmentChange });
482
+ if (exports.DEVICE_POSTURE_MEDIA_QUERY_LIST.media !== 'not all')
483
+ EventListener.add(exports.DEVICE_POSTURE_MEDIA_QUERY_LIST, { type: 'change', callback: onSegmentChange });
484
+ }
485
+ function detachCSSFallbackListeners() {
486
+ EventListener.remove(globalThis, { type: 'resize', callback: onSegmentChange });
487
+ for (var i = 0; i < segmentMediaQueryLists.length; i++)
488
+ EventListener.remove(segmentMediaQueryLists[i], { type: 'change', callback: onSegmentChange });
489
+ segmentMediaQueryLists = [];
490
+ if (exports.DEVICE_POSTURE_MEDIA_QUERY_LIST.media !== 'not all')
491
+ EventListener.remove(exports.DEVICE_POSTURE_MEDIA_QUERY_LIST, { type: 'change', callback: onSegmentChange });
492
+ }
493
+ function attachOnChange() {
494
+ if (hasSegmentsAPI) {
495
+ if (hasDevicePosture) {
496
+ EventListener.add(devicePosture, { type: 'change', callback: onSegmentChange });
497
+ EventListener.add(globalThis, { type: 'resize', callback: onSegmentChange });
498
+ }
499
+ else {
500
+ attachCSSFallbackListeners();
501
+ }
502
+ }
503
+ else if (hasLegacySegmentsAPI) {
504
+ EventListener.add(visualViewport, { type: 'resize', callback: onSegmentChange, options: { passive: true } });
505
+ if (hasSegmentsAPI)
506
+ EventListener.add(devicePosture, { type: 'change', callback: onSegmentChange });
507
+ }
508
+ else {
509
+ getOrCreateCachedDiv();
510
+ attachCSSFallbackListeners();
511
+ }
512
+ }
513
+ function detachOnChange() {
514
+ if (hasSegmentsAPI) {
515
+ if (hasDevicePosture) {
516
+ EventListener.remove(devicePosture, { type: 'change', callback: onSegmentChange });
517
+ EventListener.remove(globalThis, { type: 'resize', callback: onSegmentChange });
518
+ }
519
+ else {
520
+ detachCSSFallbackListeners();
521
+ }
522
+ }
523
+ else if (hasLegacySegmentsAPI) {
524
+ EventListener.remove(visualViewport, { type: 'resize', callback: onSegmentChange, options: { passive: true } });
525
+ if (hasSegmentsAPI)
526
+ EventListener.remove(devicePosture, { type: 'change', callback: onSegmentChange });
527
+ }
528
+ else {
529
+ detachCSSFallbackListeners();
530
+ releaseDiv();
531
+ }
532
+ }
533
+ function segmentsEqual(segments1, segments2) {
534
+ if (segments1.length !== segments2.length)
535
+ return false;
536
+ for (var i = 0; i < segments1.length; i++) {
537
+ var segment1 = segments1[i];
538
+ var segment2 = segments2[i];
539
+ if (segment1.width !== segment2.width || segment1.height !== segment2.height || segment1.top !== segment2.top || segment1.left !== segment2.left || segment1.bottom !== segment2.bottom || segment1.right !== segment2.right)
540
+ return false;
541
+ }
542
+ return true;
543
+ }
544
+ function onSegmentChange() {
545
+ var next = getValue();
546
+ if (previousSegments !== null && segmentsEqual(previousSegments, next))
547
+ return;
548
+ previousSegments = next;
549
+ onChangeSubscriptionManager.emit(next);
550
+ }
551
+ function buildDiv() {
552
+ var div = createHiddenElement('div');
553
+ div.setAttribute('data-viewport-segment-observer', '');
554
+ div.style.setProperty('position', 'fixed', 'important');
555
+ div.style.setProperty('top', '0', 'important');
556
+ div.style.setProperty('left', '0', 'important');
557
+ div.style.setProperty('visibility', 'hidden', 'important');
558
+ div.style.setProperty('pointer-events', 'none', 'important');
559
+ div.style.setProperty('z-index', '-1', 'important');
560
+ div.style.setProperty('box-sizing', 'content-box', 'important');
561
+ div.style.setProperty('padding', '0', 'important');
562
+ div.style.setProperty('margin', '0', 'important');
563
+ div.style.setProperty('border', '0', 'important');
564
+ div.style.setProperty('width', '0', 'important');
565
+ div.style.setProperty('height', '0', 'important');
566
+ div.style.setProperty('min-width', '0', 'important');
567
+ div.style.setProperty('min-height', '0', 'important');
568
+ div.style.setProperty('max-width', 'none', 'important');
569
+ div.style.setProperty('max-height', 'none', 'important');
570
+ div.style.setProperty('transition', 'none', 'important');
571
+ div.style.setProperty('animation', 'none', 'important');
572
+ div.style.setProperty('display', 'block', 'important');
573
+ div.style.setProperty('float', 'none', 'important');
574
+ div.style.setProperty('transform', 'none', 'important');
575
+ return div;
576
+ }
577
+ function getOrCreateCachedDiv() {
578
+ if (cachedDiv !== null)
579
+ return cachedDiv;
580
+ cachedDiv = buildDiv();
581
+ globalThis.document.body.appendChild(cachedDiv);
582
+ return cachedDiv;
583
+ }
584
+ function releaseDiv() {
585
+ if (cachedDiv !== null) {
586
+ if (cachedDiv.parentNode !== null)
587
+ cachedDiv.parentNode.removeChild(cachedDiv);
588
+ cachedDiv = null;
589
+ }
590
+ }
591
+ function readFromSegmentsAPI() {
592
+ var segments;
593
+ if (hasSegmentsAPI)
594
+ segments = viewport.segments;
595
+ else
596
+ segments = visualViewport.segments;
597
+ if (segments === null || typeof segments === 'undefined')
598
+ return [];
599
+ var results = [];
600
+ for (var i = 0; i < segments.length; i++) {
601
+ var segment = segments[i];
602
+ results.push({
603
+ width: segment.width,
604
+ height: segment.height,
605
+ top: segment.top,
606
+ left: segment.left,
607
+ bottom: segment.bottom,
608
+ right: segment.right,
609
+ });
610
+ }
611
+ return results;
612
+ }
613
+ function buildFullViewportSegment() {
614
+ var width = globalThis.innerWidth;
615
+ var height = globalThis.innerHeight;
616
+ return {
617
+ width: width,
618
+ height: height,
619
+ top: 0,
620
+ left: 0,
621
+ bottom: height,
622
+ right: width,
623
+ };
624
+ }
625
+ function readFromCSSEnv(div) {
626
+ var grid = getSegmentGrid();
627
+ if (grid.rows === 1 && grid.cols === 1)
628
+ return [buildFullViewportSegment()];
629
+ if (typeof support === 'undefined' || typeof div.style.setProperty === 'undefined')
630
+ return [buildFullViewportSegment()];
631
+ var results = [];
632
+ for (var row = 0; row < grid.rows; row++) {
633
+ for (var col = 0; col < grid.cols; col++) {
634
+ div.style.setProperty('width', support + '(viewport-segment-width ' + row + ' ' + col + ', -1px)', 'important');
635
+ div.style.setProperty('height', support + '(viewport-segment-height ' + row + ' ' + col + ', -1px)', 'important');
636
+ div.style.setProperty('margin-top', support + '(viewport-segment-top ' + row + ' ' + col + ', -1px)', 'important');
637
+ div.style.setProperty('margin-left', support + '(viewport-segment-left ' + row + ' ' + col + ', -1px)', 'important');
638
+ div.style.setProperty('margin-bottom', support + '(viewport-segment-bottom ' + row + ' ' + col + ', -1px)', 'important');
639
+ div.style.setProperty('margin-right', support + '(viewport-segment-right ' + row + ' ' + col + ', -1px)', 'important');
640
+ var computed = globalThis.getComputedStyle(div);
641
+ var top_1 = globalThis.parseFloat(computed.marginTop);
642
+ if (top_1 < 0)
643
+ continue;
644
+ var left = globalThis.parseFloat(computed.marginLeft);
645
+ var bottom = globalThis.parseFloat(computed.marginBottom);
646
+ var right = globalThis.parseFloat(computed.marginRight);
647
+ var width = globalThis.parseFloat(computed.width);
648
+ var height = globalThis.parseFloat(computed.height);
649
+ results.push({
650
+ width: width,
651
+ height: height,
652
+ top: top_1,
653
+ left: left,
654
+ bottom: bottom,
655
+ right: right,
656
+ });
657
+ }
658
+ }
659
+ return results;
660
+ }
661
+ function getValue() {
662
+ if (hasSegmentsAPI || hasLegacySegmentsAPI)
663
+ return readFromSegmentsAPI();
664
+ if (cachedDiv !== null)
665
+ return readFromCSSEnv(cachedDiv);
666
+ var div = buildDiv();
667
+ globalThis.document.body.appendChild(div);
668
+ var results = readFromCSSEnv(div);
669
+ globalThis.document.body.removeChild(div);
670
+ return results;
671
+ }
672
+ function useCssVariable(prefix) {
673
+ if (typeof globalThis.document === 'undefined')
674
+ return noop;
675
+ var attributes = keys(ENV_PRESETS['viewport-segment']);
676
+ var element = globalThis.document.documentElement;
677
+ var lastCount = 0;
678
+ function applySegments(segments) {
679
+ for (var i = segments.length; i < lastCount; i++) {
680
+ for (var j = 0; j < attributes.length; j++) {
681
+ element.style.removeProperty("--".concat(prefix, "-").concat(i, "-").concat(attributes[j]));
682
+ }
683
+ }
684
+ lastCount = segments.length;
685
+ for (var i = 0; i < segments.length; i++) {
686
+ var segment = segments[i];
687
+ for (var j = 0; j < attributes.length; j++) {
688
+ var attribute = attributes[j];
689
+ element.style.setProperty("--".concat(prefix, "-").concat(i, "-").concat(attribute), segment[attribute] + 'px');
690
+ }
691
+ }
692
+ }
693
+ applySegments(getValue());
694
+ var unsubscribe = onChangeSubscriptionManager.subscribe(function (segments) {
695
+ applySegments(segments);
696
+ });
697
+ return function () {
698
+ unsubscribe();
699
+ for (var i = 0; i < lastCount; i++)
700
+ for (var j = 0; j < attributes.length; j++)
701
+ element.style.removeProperty("--".concat(prefix, "-").concat(i, "-").concat(attributes[j]));
702
+ lastCount = 0;
703
+ };
704
+ }
705
+ return {
706
+ get value() {
707
+ return getValue();
708
+ },
709
+ onChange: onChangeSubscriptionManager.subscribe,
710
+ useCssVariable: useCssVariable,
711
+ };
712
+ }
373
713
  function createVirtualKeyboardObserver() {
374
714
  var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, detachOnChange);
715
+ var previousOverlaysContent = false;
375
716
  function attachOnChange() {
717
+ previousOverlaysContent = globalThis.navigator.virtualKeyboard.overlaysContent;
718
+ globalThis.navigator.virtualKeyboard.overlaysContent = true;
376
719
  EventListener.add(globalThis.navigator.virtualKeyboard, { type: 'geometrychange', callback: onGeometryChange, options: { passive: true } });
377
720
  }
378
721
  function detachOnChange() {
379
722
  EventListener.remove(globalThis.navigator.virtualKeyboard, { type: 'geometrychange', callback: onGeometryChange, options: { passive: true } });
723
+ globalThis.navigator.virtualKeyboard.overlaysContent = previousOverlaysContent;
380
724
  }
381
725
  function onGeometryChange() {
382
726
  onChangeSubscriptionManager.emit(getValue());
@@ -387,16 +731,16 @@ function createVirtualKeyboardObserver() {
387
731
  var top = rect.y;
388
732
  var width = rect.width;
389
733
  var height = rect.height;
390
- var right = (function () {
391
- if (width === 0)
392
- return 0;
393
- return Math.max(0, globalThis.innerWidth - (left + width));
394
- })();
395
- var bottom = (function () {
396
- if (height === 0)
397
- return 0;
398
- return Math.max(0, globalThis.innerHeight - (top + height));
399
- })();
734
+ var right;
735
+ if (width === 0)
736
+ right = 0;
737
+ else
738
+ right = Math.max(0, globalThis.innerWidth - (left + width));
739
+ var bottom;
740
+ if (height === 0)
741
+ bottom = 0;
742
+ else
743
+ bottom = Math.max(0, globalThis.innerHeight - (top + height));
400
744
  return {
401
745
  top: top,
402
746
  right: right,
@@ -406,17 +750,43 @@ function createVirtualKeyboardObserver() {
406
750
  height: height,
407
751
  };
408
752
  }
753
+ function useCssVariable(prefix) {
754
+ if (typeof globalThis.document === 'undefined')
755
+ return noop;
756
+ var attributes = keys(ENV_PRESETS['keyboard-inset']);
757
+ var element = globalThis.document.documentElement;
758
+ function applyValues(values) {
759
+ for (var i = 0; i < attributes.length; i++) {
760
+ var attribute = attributes[i];
761
+ element.style.setProperty("--".concat(prefix, "-").concat(attribute), values[attribute] + 'px');
762
+ }
763
+ }
764
+ applyValues(getValue());
765
+ var unsubscribe = onChangeSubscriptionManager.subscribe(function (values) {
766
+ applyValues(values);
767
+ });
768
+ return function () {
769
+ unsubscribe();
770
+ for (var i = 0; i < attributes.length; i++)
771
+ element.style.removeProperty("--".concat(prefix, "-").concat(attributes[i]));
772
+ };
773
+ }
409
774
  return {
410
- get: getValue,
775
+ get value() {
776
+ return getValue();
777
+ },
411
778
  onChange: onChangeSubscriptionManager.subscribe,
779
+ useCssVariable: useCssVariable,
412
780
  };
413
781
  }
414
- function createEnvObserver(preset) {
782
+ function createEnvironmentObserver(preset) {
415
783
  if (preset === 'keyboard-inset' && typeof globalThis.navigator.virtualKeyboard !== 'undefined')
416
784
  return createVirtualKeyboardObserver();
417
- var envMap = ENV_PRESETS[preset];
418
- var attributes = keys(envMap);
419
- var support = getSupportedEnv();
785
+ if (preset === 'viewport-segment')
786
+ return createViewportSegmentObserver();
787
+ var environmentMap = ENV_PRESETS[preset];
788
+ var attributes = keys(environmentMap);
789
+ var support = getSupportedEnvironment();
420
790
  var parentReadyCallbacks = [];
421
791
  var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, detachOnChange);
422
792
  var elementComputedStyle = {};
@@ -433,15 +803,6 @@ function createEnvObserver(preset) {
433
803
  function detachOnChange() {
434
804
  removeDetector();
435
805
  }
436
- function getSupportedEnv() {
437
- if (typeof globalThis.CSS !== 'undefined' && typeof globalThis.CSS.supports === 'function') {
438
- if (globalThis.CSS.supports('x: env(x)'))
439
- return 'env';
440
- if (globalThis.CSS.supports('x: constant(x)'))
441
- return 'constant';
442
- }
443
- return undefined;
444
- }
445
806
  function isSameValues(a, b) {
446
807
  for (var i = 0; i < attributes.length; i++) {
447
808
  var key = attributes[i];
@@ -481,7 +842,7 @@ function createEnvObserver(preset) {
481
842
  parentReadyCallbacks[i]();
482
843
  }
483
844
  function addChild(parent, attribute) {
484
- var envVar = envMap[attribute];
845
+ var envVar = environmentMap[attribute];
485
846
  var p1 = globalThis.document.createElement('div');
486
847
  var p2 = globalThis.document.createElement('div');
487
848
  var c1 = globalThis.document.createElement('div');
@@ -544,9 +905,8 @@ function createEnvObserver(preset) {
544
905
  }
545
906
  function init() {
546
907
  if (typeof support === 'undefined') {
547
- for (var i = 0; i < attributes.length; i++) {
908
+ for (var i = 0; i < attributes.length; i++)
548
909
  elementComputedStyle[attributes[i]] = 0;
549
- }
550
910
  return;
551
911
  }
552
912
  elementComputedStyle = {};
@@ -590,8 +950,28 @@ function createEnvObserver(preset) {
590
950
  }
591
951
  return result;
592
952
  }
953
+ function useCssVariable(prefix) {
954
+ if (typeof support === 'undefined' || typeof globalThis.document === 'undefined')
955
+ return noop;
956
+ var element = globalThis.document.documentElement;
957
+ function applyValues(values) {
958
+ for (var i = 0; i < attributes.length; i++) {
959
+ var attribute = attributes[i];
960
+ element.style.setProperty("--".concat(prefix, "-").concat(String(attribute)), values[attribute] + 'px');
961
+ }
962
+ }
963
+ var unsubscribe = onChangeSubscriptionManager.subscribe(function (values) {
964
+ applyValues(values);
965
+ });
966
+ applyValues(readValues());
967
+ return function () {
968
+ unsubscribe();
969
+ for (var i = 0; i < attributes.length; i++)
970
+ element.style.removeProperty("--".concat(prefix, "-").concat(String(attributes[i])));
971
+ };
972
+ }
593
973
  return {
594
- get: function () {
974
+ get value() {
595
975
  if (parentDiv !== null)
596
976
  return readValues();
597
977
  init();
@@ -604,15 +984,16 @@ function createEnvObserver(preset) {
604
984
  if (typeof support === 'undefined')
605
985
  return noop;
606
986
  return onChangeSubscriptionManager.subscribe(callback, options);
607
- }
987
+ },
988
+ useCssVariable: useCssVariable
608
989
  };
609
990
  }
610
991
 
611
- var safeAreaInsetObserver = createEnvObserver('safe-area-inset');
612
- var safeAreaMaxInsetObserver = createEnvObserver('safe-area-max-inset');
613
- var keyboardInsetObserver = createEnvObserver('keyboard-inset');
614
- var titlebarAreaObserver = createEnvObserver('titlebar-area');
615
- var viewportSegmentObserver = createEnvObserver('viewport-segment');
992
+ var safeAreaInsetObserver = createEnvironmentObserver('safe-area-inset');
993
+ var safeAreaMaxInsetObserver = createEnvironmentObserver('safe-area-max-inset');
994
+ var keyboardInsetObserver = createEnvironmentObserver('keyboard-inset');
995
+ var titlebarAreaObserver = createEnvironmentObserver('titlebar-area');
996
+ var viewportSegmentObserver = createEnvironmentObserver('viewport-segment');
616
997
  var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, detachOnChange);
617
998
  var dimensionRef = null;
618
999
  var Dimension = {
@@ -647,9 +1028,9 @@ function getOrientation() {
647
1028
  return exports.Orientation.Landscape;
648
1029
  }
649
1030
  }
650
- if (exports.MEDIA_QUERY_LIST.media === 'not all')
1031
+ if (exports.ORIENTATION_MEDIA_QUERY_LIST.media === 'not all')
651
1032
  return exports.Orientation.Unknown;
652
- else if (exports.MEDIA_QUERY_LIST.matches)
1033
+ else if (exports.ORIENTATION_MEDIA_QUERY_LIST.matches)
653
1034
  return exports.Orientation.Portrait;
654
1035
  else
655
1036
  return exports.Orientation.Landscape;
@@ -661,50 +1042,29 @@ function getScale() {
661
1042
  }
662
1043
  function getEnvironment() {
663
1044
  return {
664
- safeAreaInset: {
665
- get value() {
666
- return safeAreaInsetObserver.get();
667
- },
668
- onChange: safeAreaInsetObserver.onChange,
669
- },
670
- safeAreaMaxInset: {
671
- get value() {
672
- return safeAreaMaxInsetObserver.get();
673
- },
674
- onChange: safeAreaMaxInsetObserver.onChange,
675
- },
676
- keyboardInset: {
677
- get value() {
678
- return keyboardInsetObserver.get();
679
- },
680
- onChange: keyboardInsetObserver.onChange,
681
- },
682
- titlebarArea: {
683
- get value() {
684
- return titlebarAreaObserver.get();
685
- },
686
- onChange: titlebarAreaObserver.onChange,
687
- },
688
- viewportSegment: {
689
- get value() {
690
- return viewportSegmentObserver.get();
691
- },
692
- onChange: viewportSegmentObserver.onChange,
693
- },
1045
+ safeAreaInset: safeAreaInsetObserver,
1046
+ safeAreaMaxInset: safeAreaMaxInsetObserver,
1047
+ keyboardInset: keyboardInsetObserver,
1048
+ titlebarArea: titlebarAreaObserver,
1049
+ viewportSegment: viewportSegmentObserver,
694
1050
  };
695
1051
  }
696
1052
  function getDimension() {
1053
+ var dimensions = {
1054
+ innerWidth: 0,
1055
+ innerHeight: 0,
1056
+ outerWidth: 0,
1057
+ outerHeight: 0,
1058
+ scale: getScale(),
1059
+ orientation: getOrientation(),
1060
+ };
697
1061
  if (typeof globalThis.innerWidth !== 'undefined') {
698
- return {
699
- innerWidth: globalThis.innerWidth,
700
- innerHeight: globalThis.innerHeight,
701
- outerWidth: globalThis.outerWidth,
702
- outerHeight: globalThis.outerHeight,
703
- scale: getScale(),
704
- orientation: getOrientation(),
705
- };
1062
+ dimensions.innerWidth = globalThis.innerWidth;
1063
+ dimensions.innerHeight = globalThis.innerHeight;
1064
+ dimensions.outerWidth = globalThis.outerWidth;
1065
+ dimensions.outerHeight = globalThis.outerHeight;
706
1066
  }
707
- return FALLBACK_DIMENSION;
1067
+ return dimensions;
708
1068
  }
709
1069
  function attachOnChange() {
710
1070
  dimensionRef = getDimension();
@@ -713,8 +1073,8 @@ function attachOnChange() {
713
1073
  EventListener.add(globalThis.screen.orientation, { type: 'change', callback: onResize });
714
1074
  else if (typeof globalThis.orientation !== 'undefined')
715
1075
  EventListener.add(globalThis, { type: 'orientationChange', callback: onResize });
716
- else if (exports.MEDIA_QUERY_LIST.media !== 'not all')
717
- EventListener.add(exports.MEDIA_QUERY_LIST, { type: 'change', callback: onResize });
1076
+ else if (exports.ORIENTATION_MEDIA_QUERY_LIST.media !== 'not all')
1077
+ EventListener.add(exports.ORIENTATION_MEDIA_QUERY_LIST, { type: 'change', callback: onResize });
718
1078
  }
719
1079
  function detachOnChange() {
720
1080
  dimensionRef = null;
@@ -723,8 +1083,8 @@ function detachOnChange() {
723
1083
  EventListener.remove(globalThis.screen.orientation, { type: 'change', callback: onResize });
724
1084
  else if (typeof globalThis.orientation !== 'undefined')
725
1085
  EventListener.remove(globalThis, { type: 'orientationChange', callback: onResize });
726
- else if (exports.MEDIA_QUERY_LIST.media !== 'not all')
727
- EventListener.remove(exports.MEDIA_QUERY_LIST, { type: 'change', callback: onResize });
1086
+ else if (exports.ORIENTATION_MEDIA_QUERY_LIST.media !== 'not all')
1087
+ EventListener.remove(exports.ORIENTATION_MEDIA_QUERY_LIST, { type: 'change', callback: onResize });
728
1088
  }
729
1089
  function onResize() {
730
1090
  var dimension = getDimension();
@@ -733,5 +1093,4 @@ function onResize() {
733
1093
  }
734
1094
 
735
1095
  exports.ENV_PRESETS = ENV_PRESETS;
736
- exports.FALLBACK_DIMENSION = FALLBACK_DIMENSION;
737
1096
  exports.default = Dimension;