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
@@ -57,19 +57,16 @@ var ENV_PRESETS = {
57
57
  left: 'viewport-segment-left',
58
58
  },
59
59
  };
60
- var FALLBACK_DIMENSION = {
61
- innerWidth: -1,
62
- innerHeight: -1,
63
- outerWidth: -1,
64
- outerHeight: -1,
65
- scale: 1,
66
- orientation: Orientation.Unknown,
67
- };
68
- var MEDIA_QUERY_LIST;
60
+ var ORIENTATION_MEDIA_QUERY_LIST;
61
+ if (typeof globalThis.matchMedia !== 'undefined')
62
+ ORIENTATION_MEDIA_QUERY_LIST = globalThis.matchMedia('(orientation: portrait)');
63
+ else
64
+ ORIENTATION_MEDIA_QUERY_LIST = FALLBACK_MEDIA_QUERY_LIST;
65
+ var DEVICE_POSTURE_MEDIA_QUERY_LIST;
69
66
  if (typeof globalThis.matchMedia !== 'undefined')
70
- MEDIA_QUERY_LIST = globalThis.matchMedia('(orientation: portrait)');
67
+ DEVICE_POSTURE_MEDIA_QUERY_LIST = globalThis.matchMedia('(device-posture: folded)');
71
68
  else
72
- MEDIA_QUERY_LIST = FALLBACK_MEDIA_QUERY_LIST;
69
+ DEVICE_POSTURE_MEDIA_QUERY_LIST = FALLBACK_MEDIA_QUERY_LIST;
73
70
 
74
71
  var IE_WRAPPER_STORE = [];
75
72
  var MEDIA_QUERY_LIST_WRAPPER_STORE = [];
@@ -304,6 +301,8 @@ function createSubscriptionManager(attach, detach) {
304
301
  },
305
302
  subscribe: function (listener, options) {
306
303
  if (options === void 0) { options = {}; }
304
+ if (typeof options.signal !== 'undefined' && options.signal.aborted)
305
+ return function () { };
307
306
  var entry = { fn: listener, once: false };
308
307
  if (typeof options.once !== 'undefined')
309
308
  entry.once = options.once;
@@ -322,12 +321,8 @@ function createSubscriptionManager(attach, detach) {
322
321
  EventListener.remove(entry.signal, { type: 'abort', callback: cleanup });
323
322
  removeEntry(entry);
324
323
  };
325
- if (typeof entry.signal !== 'undefined') {
326
- if (entry.signal.aborted)
327
- removeEntry(entry);
328
- else
329
- EventListener.add(entry.signal, { type: 'abort', callback: cleanup });
330
- }
324
+ if (typeof entry.signal !== 'undefined')
325
+ EventListener.add(entry.signal, { type: 'abort', callback: cleanup });
331
326
  return function unsubscribe() {
332
327
  removeEntry(entry);
333
328
  };
@@ -364,15 +359,364 @@ function setStyle(element, styles) {
364
359
  }
365
360
  }
366
361
 
362
+ function createHiddenElement(tagName, focusable) {
363
+ if (focusable === void 0) { focusable = true; }
364
+ var element = globalThis.document.createElement(tagName);
365
+ if (typeof element.width !== 'undefined')
366
+ element.width = '0';
367
+ if (typeof element.height !== 'undefined')
368
+ element.height = '0';
369
+ if (typeof element.border !== 'undefined')
370
+ element.border = '0';
371
+ if (typeof element.frameBorder !== 'undefined')
372
+ element.frameBorder = '0';
373
+ if (typeof element.scrolling !== 'undefined')
374
+ element.scrolling = 'no';
375
+ if (typeof element.cellPadding !== 'undefined')
376
+ element.cellPadding = '0';
377
+ if (typeof element.cellSpacing !== 'undefined')
378
+ element.cellSpacing = '0';
379
+ if (typeof element.frame !== 'undefined')
380
+ element.frame = 'void';
381
+ if (typeof element.rules !== 'undefined')
382
+ element.rules = 'none';
383
+ if (typeof element.noWrap !== 'undefined')
384
+ element.noWrap = true;
385
+ element.tabIndex = -1;
386
+ element.setAttribute('role', 'presentation');
387
+ if (focusable) {
388
+ setStyle(element, {
389
+ width: '1px',
390
+ height: '1px',
391
+ });
392
+ }
393
+ else {
394
+ element.setAttribute('aria-hidden', 'true');
395
+ setStyle(element, {
396
+ width: '0',
397
+ height: '0',
398
+ zIndex: '-9999',
399
+ display: 'none',
400
+ visibility: 'hidden',
401
+ pointerEvents: 'none',
402
+ });
403
+ }
404
+ setStyle(element, {
405
+ position: 'absolute',
406
+ top: '0',
407
+ left: '0',
408
+ padding: '0',
409
+ margin: '0',
410
+ border: 'none',
411
+ outline: 'hidden',
412
+ clip: 'rect(1px, 1px, 1px, 1px)',
413
+ clipPath: 'inset(50%)',
414
+ overflow: 'hidden',
415
+ whiteSpace: 'nowrap',
416
+ });
417
+ return element;
418
+ }
419
+
420
+ var MAX_SEGMENTS_PER_AXIS = 4;
367
421
  function noop() {
368
422
  }
423
+ function getSupportedEnvironment() {
424
+ if (typeof globalThis.CSS !== 'undefined' && typeof globalThis.CSS.supports === 'function') {
425
+ if (globalThis.CSS.supports('x: env(x)'))
426
+ return 'env';
427
+ if (globalThis.CSS.supports('x: constant(x)'))
428
+ return 'constant';
429
+ }
430
+ return undefined;
431
+ }
432
+ function getSegmentGrid() {
433
+ if (typeof globalThis.matchMedia !== 'function')
434
+ return { rows: 1, cols: 1 };
435
+ var cols = 1;
436
+ var rows = 1;
437
+ for (var i = MAX_SEGMENTS_PER_AXIS; i >= 2; i--) {
438
+ if (globalThis.matchMedia('(horizontal-viewport-segments: ' + i + ')').matches) {
439
+ cols = i;
440
+ break;
441
+ }
442
+ }
443
+ for (var i = MAX_SEGMENTS_PER_AXIS; i >= 2; i--) {
444
+ if (globalThis.matchMedia('(vertical-viewport-segments: ' + i + ')').matches) {
445
+ rows = i;
446
+ break;
447
+ }
448
+ }
449
+ return { rows: rows, cols: cols };
450
+ }
451
+ function buildSegmentMediaQueryLists() {
452
+ if (typeof globalThis.matchMedia !== 'function')
453
+ return [];
454
+ var mediaQueryLists = [];
455
+ for (var i = 2; i <= MAX_SEGMENTS_PER_AXIS; i++) {
456
+ mediaQueryLists.push(globalThis.matchMedia('(horizontal-viewport-segments: ' + i + ')'));
457
+ mediaQueryLists.push(globalThis.matchMedia('(vertical-viewport-segments: ' + i + ')'));
458
+ }
459
+ return mediaQueryLists;
460
+ }
461
+ function createViewportSegmentObserver() {
462
+ var viewport = globalThis.viewport;
463
+ var visualViewport = globalThis.visualViewport;
464
+ var devicePosture = globalThis.navigator.devicePosture;
465
+ var hasSegmentsAPI = typeof viewport !== 'undefined';
466
+ var hasLegacySegmentsAPI = !hasSegmentsAPI && typeof visualViewport !== 'undefined' && visualViewport !== null && typeof visualViewport.segments !== 'undefined';
467
+ var hasDevicePosture = typeof devicePosture !== 'undefined';
468
+ var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, detachOnChange);
469
+ var support = getSupportedEnvironment();
470
+ var cachedDiv = null;
471
+ var segmentMediaQueryLists = [];
472
+ var previousSegments = null;
473
+ function attachCSSFallbackListeners() {
474
+ EventListener.add(globalThis, { type: 'resize', callback: onSegmentChange });
475
+ segmentMediaQueryLists = buildSegmentMediaQueryLists();
476
+ for (var i = 0; i < segmentMediaQueryLists.length; i++)
477
+ EventListener.add(segmentMediaQueryLists[i], { type: 'change', callback: onSegmentChange });
478
+ if (DEVICE_POSTURE_MEDIA_QUERY_LIST.media !== 'not all')
479
+ EventListener.add(DEVICE_POSTURE_MEDIA_QUERY_LIST, { type: 'change', callback: onSegmentChange });
480
+ }
481
+ function detachCSSFallbackListeners() {
482
+ EventListener.remove(globalThis, { type: 'resize', callback: onSegmentChange });
483
+ for (var i = 0; i < segmentMediaQueryLists.length; i++)
484
+ EventListener.remove(segmentMediaQueryLists[i], { type: 'change', callback: onSegmentChange });
485
+ segmentMediaQueryLists = [];
486
+ if (DEVICE_POSTURE_MEDIA_QUERY_LIST.media !== 'not all')
487
+ EventListener.remove(DEVICE_POSTURE_MEDIA_QUERY_LIST, { type: 'change', callback: onSegmentChange });
488
+ }
489
+ function attachOnChange() {
490
+ if (hasSegmentsAPI) {
491
+ if (hasDevicePosture) {
492
+ EventListener.add(devicePosture, { type: 'change', callback: onSegmentChange });
493
+ EventListener.add(globalThis, { type: 'resize', callback: onSegmentChange });
494
+ }
495
+ else {
496
+ attachCSSFallbackListeners();
497
+ }
498
+ }
499
+ else if (hasLegacySegmentsAPI) {
500
+ EventListener.add(visualViewport, { type: 'resize', callback: onSegmentChange, options: { passive: true } });
501
+ if (hasSegmentsAPI)
502
+ EventListener.add(devicePosture, { type: 'change', callback: onSegmentChange });
503
+ }
504
+ else {
505
+ getOrCreateCachedDiv();
506
+ attachCSSFallbackListeners();
507
+ }
508
+ }
509
+ function detachOnChange() {
510
+ if (hasSegmentsAPI) {
511
+ if (hasDevicePosture) {
512
+ EventListener.remove(devicePosture, { type: 'change', callback: onSegmentChange });
513
+ EventListener.remove(globalThis, { type: 'resize', callback: onSegmentChange });
514
+ }
515
+ else {
516
+ detachCSSFallbackListeners();
517
+ }
518
+ }
519
+ else if (hasLegacySegmentsAPI) {
520
+ EventListener.remove(visualViewport, { type: 'resize', callback: onSegmentChange, options: { passive: true } });
521
+ if (hasSegmentsAPI)
522
+ EventListener.remove(devicePosture, { type: 'change', callback: onSegmentChange });
523
+ }
524
+ else {
525
+ detachCSSFallbackListeners();
526
+ releaseDiv();
527
+ }
528
+ }
529
+ function segmentsEqual(segments1, segments2) {
530
+ if (segments1.length !== segments2.length)
531
+ return false;
532
+ for (var i = 0; i < segments1.length; i++) {
533
+ var segment1 = segments1[i];
534
+ var segment2 = segments2[i];
535
+ 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)
536
+ return false;
537
+ }
538
+ return true;
539
+ }
540
+ function onSegmentChange() {
541
+ var next = getValue();
542
+ if (previousSegments !== null && segmentsEqual(previousSegments, next))
543
+ return;
544
+ previousSegments = next;
545
+ onChangeSubscriptionManager.emit(next);
546
+ }
547
+ function buildDiv() {
548
+ var div = createHiddenElement('div');
549
+ div.setAttribute('data-viewport-segment-observer', '');
550
+ div.style.setProperty('position', 'fixed', 'important');
551
+ div.style.setProperty('top', '0', 'important');
552
+ div.style.setProperty('left', '0', 'important');
553
+ div.style.setProperty('visibility', 'hidden', 'important');
554
+ div.style.setProperty('pointer-events', 'none', 'important');
555
+ div.style.setProperty('z-index', '-1', 'important');
556
+ div.style.setProperty('box-sizing', 'content-box', 'important');
557
+ div.style.setProperty('padding', '0', 'important');
558
+ div.style.setProperty('margin', '0', 'important');
559
+ div.style.setProperty('border', '0', 'important');
560
+ div.style.setProperty('width', '0', 'important');
561
+ div.style.setProperty('height', '0', 'important');
562
+ div.style.setProperty('min-width', '0', 'important');
563
+ div.style.setProperty('min-height', '0', 'important');
564
+ div.style.setProperty('max-width', 'none', 'important');
565
+ div.style.setProperty('max-height', 'none', 'important');
566
+ div.style.setProperty('transition', 'none', 'important');
567
+ div.style.setProperty('animation', 'none', 'important');
568
+ div.style.setProperty('display', 'block', 'important');
569
+ div.style.setProperty('float', 'none', 'important');
570
+ div.style.setProperty('transform', 'none', 'important');
571
+ return div;
572
+ }
573
+ function getOrCreateCachedDiv() {
574
+ if (cachedDiv !== null)
575
+ return cachedDiv;
576
+ cachedDiv = buildDiv();
577
+ globalThis.document.body.appendChild(cachedDiv);
578
+ return cachedDiv;
579
+ }
580
+ function releaseDiv() {
581
+ if (cachedDiv !== null) {
582
+ if (cachedDiv.parentNode !== null)
583
+ cachedDiv.parentNode.removeChild(cachedDiv);
584
+ cachedDiv = null;
585
+ }
586
+ }
587
+ function readFromSegmentsAPI() {
588
+ var segments;
589
+ if (hasSegmentsAPI)
590
+ segments = viewport.segments;
591
+ else
592
+ segments = visualViewport.segments;
593
+ if (segments === null || typeof segments === 'undefined')
594
+ return [];
595
+ var results = [];
596
+ for (var i = 0; i < segments.length; i++) {
597
+ var segment = segments[i];
598
+ results.push({
599
+ width: segment.width,
600
+ height: segment.height,
601
+ top: segment.top,
602
+ left: segment.left,
603
+ bottom: segment.bottom,
604
+ right: segment.right,
605
+ });
606
+ }
607
+ return results;
608
+ }
609
+ function buildFullViewportSegment() {
610
+ var width = globalThis.innerWidth;
611
+ var height = globalThis.innerHeight;
612
+ return {
613
+ width: width,
614
+ height: height,
615
+ top: 0,
616
+ left: 0,
617
+ bottom: height,
618
+ right: width,
619
+ };
620
+ }
621
+ function readFromCSSEnv(div) {
622
+ var grid = getSegmentGrid();
623
+ if (grid.rows === 1 && grid.cols === 1)
624
+ return [buildFullViewportSegment()];
625
+ if (typeof support === 'undefined' || typeof div.style.setProperty === 'undefined')
626
+ return [buildFullViewportSegment()];
627
+ var results = [];
628
+ for (var row = 0; row < grid.rows; row++) {
629
+ for (var col = 0; col < grid.cols; col++) {
630
+ div.style.setProperty('width', support + '(viewport-segment-width ' + row + ' ' + col + ', -1px)', 'important');
631
+ div.style.setProperty('height', support + '(viewport-segment-height ' + row + ' ' + col + ', -1px)', 'important');
632
+ div.style.setProperty('margin-top', support + '(viewport-segment-top ' + row + ' ' + col + ', -1px)', 'important');
633
+ div.style.setProperty('margin-left', support + '(viewport-segment-left ' + row + ' ' + col + ', -1px)', 'important');
634
+ div.style.setProperty('margin-bottom', support + '(viewport-segment-bottom ' + row + ' ' + col + ', -1px)', 'important');
635
+ div.style.setProperty('margin-right', support + '(viewport-segment-right ' + row + ' ' + col + ', -1px)', 'important');
636
+ var computed = globalThis.getComputedStyle(div);
637
+ var top_1 = globalThis.parseFloat(computed.marginTop);
638
+ if (top_1 < 0)
639
+ continue;
640
+ var left = globalThis.parseFloat(computed.marginLeft);
641
+ var bottom = globalThis.parseFloat(computed.marginBottom);
642
+ var right = globalThis.parseFloat(computed.marginRight);
643
+ var width = globalThis.parseFloat(computed.width);
644
+ var height = globalThis.parseFloat(computed.height);
645
+ results.push({
646
+ width: width,
647
+ height: height,
648
+ top: top_1,
649
+ left: left,
650
+ bottom: bottom,
651
+ right: right,
652
+ });
653
+ }
654
+ }
655
+ return results;
656
+ }
657
+ function getValue() {
658
+ if (hasSegmentsAPI || hasLegacySegmentsAPI)
659
+ return readFromSegmentsAPI();
660
+ if (cachedDiv !== null)
661
+ return readFromCSSEnv(cachedDiv);
662
+ var div = buildDiv();
663
+ globalThis.document.body.appendChild(div);
664
+ var results = readFromCSSEnv(div);
665
+ globalThis.document.body.removeChild(div);
666
+ return results;
667
+ }
668
+ function useCssVariable(prefix) {
669
+ if (typeof globalThis.document === 'undefined')
670
+ return noop;
671
+ var attributes = keys(ENV_PRESETS['viewport-segment']);
672
+ var element = globalThis.document.documentElement;
673
+ var lastCount = 0;
674
+ function applySegments(segments) {
675
+ for (var i = segments.length; i < lastCount; i++) {
676
+ for (var j = 0; j < attributes.length; j++) {
677
+ element.style.removeProperty("--".concat(prefix, "-").concat(i, "-").concat(attributes[j]));
678
+ }
679
+ }
680
+ lastCount = segments.length;
681
+ for (var i = 0; i < segments.length; i++) {
682
+ var segment = segments[i];
683
+ for (var j = 0; j < attributes.length; j++) {
684
+ var attribute = attributes[j];
685
+ element.style.setProperty("--".concat(prefix, "-").concat(i, "-").concat(attribute), segment[attribute] + 'px');
686
+ }
687
+ }
688
+ }
689
+ applySegments(getValue());
690
+ var unsubscribe = onChangeSubscriptionManager.subscribe(function (segments) {
691
+ applySegments(segments);
692
+ });
693
+ return function () {
694
+ unsubscribe();
695
+ for (var i = 0; i < lastCount; i++)
696
+ for (var j = 0; j < attributes.length; j++)
697
+ element.style.removeProperty("--".concat(prefix, "-").concat(i, "-").concat(attributes[j]));
698
+ lastCount = 0;
699
+ };
700
+ }
701
+ return {
702
+ get value() {
703
+ return getValue();
704
+ },
705
+ onChange: onChangeSubscriptionManager.subscribe,
706
+ useCssVariable: useCssVariable,
707
+ };
708
+ }
369
709
  function createVirtualKeyboardObserver() {
370
710
  var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, detachOnChange);
711
+ var previousOverlaysContent = false;
371
712
  function attachOnChange() {
713
+ previousOverlaysContent = globalThis.navigator.virtualKeyboard.overlaysContent;
714
+ globalThis.navigator.virtualKeyboard.overlaysContent = true;
372
715
  EventListener.add(globalThis.navigator.virtualKeyboard, { type: 'geometrychange', callback: onGeometryChange, options: { passive: true } });
373
716
  }
374
717
  function detachOnChange() {
375
718
  EventListener.remove(globalThis.navigator.virtualKeyboard, { type: 'geometrychange', callback: onGeometryChange, options: { passive: true } });
719
+ globalThis.navigator.virtualKeyboard.overlaysContent = previousOverlaysContent;
376
720
  }
377
721
  function onGeometryChange() {
378
722
  onChangeSubscriptionManager.emit(getValue());
@@ -383,16 +727,16 @@ function createVirtualKeyboardObserver() {
383
727
  var top = rect.y;
384
728
  var width = rect.width;
385
729
  var height = rect.height;
386
- var right = (function () {
387
- if (width === 0)
388
- return 0;
389
- return Math.max(0, globalThis.innerWidth - (left + width));
390
- })();
391
- var bottom = (function () {
392
- if (height === 0)
393
- return 0;
394
- return Math.max(0, globalThis.innerHeight - (top + height));
395
- })();
730
+ var right;
731
+ if (width === 0)
732
+ right = 0;
733
+ else
734
+ right = Math.max(0, globalThis.innerWidth - (left + width));
735
+ var bottom;
736
+ if (height === 0)
737
+ bottom = 0;
738
+ else
739
+ bottom = Math.max(0, globalThis.innerHeight - (top + height));
396
740
  return {
397
741
  top: top,
398
742
  right: right,
@@ -402,17 +746,43 @@ function createVirtualKeyboardObserver() {
402
746
  height: height,
403
747
  };
404
748
  }
749
+ function useCssVariable(prefix) {
750
+ if (typeof globalThis.document === 'undefined')
751
+ return noop;
752
+ var attributes = keys(ENV_PRESETS['keyboard-inset']);
753
+ var element = globalThis.document.documentElement;
754
+ function applyValues(values) {
755
+ for (var i = 0; i < attributes.length; i++) {
756
+ var attribute = attributes[i];
757
+ element.style.setProperty("--".concat(prefix, "-").concat(attribute), values[attribute] + 'px');
758
+ }
759
+ }
760
+ applyValues(getValue());
761
+ var unsubscribe = onChangeSubscriptionManager.subscribe(function (values) {
762
+ applyValues(values);
763
+ });
764
+ return function () {
765
+ unsubscribe();
766
+ for (var i = 0; i < attributes.length; i++)
767
+ element.style.removeProperty("--".concat(prefix, "-").concat(attributes[i]));
768
+ };
769
+ }
405
770
  return {
406
- get: getValue,
771
+ get value() {
772
+ return getValue();
773
+ },
407
774
  onChange: onChangeSubscriptionManager.subscribe,
775
+ useCssVariable: useCssVariable,
408
776
  };
409
777
  }
410
- function createEnvObserver(preset) {
778
+ function createEnvironmentObserver(preset) {
411
779
  if (preset === 'keyboard-inset' && typeof globalThis.navigator.virtualKeyboard !== 'undefined')
412
780
  return createVirtualKeyboardObserver();
413
- var envMap = ENV_PRESETS[preset];
414
- var attributes = keys(envMap);
415
- var support = getSupportedEnv();
781
+ if (preset === 'viewport-segment')
782
+ return createViewportSegmentObserver();
783
+ var environmentMap = ENV_PRESETS[preset];
784
+ var attributes = keys(environmentMap);
785
+ var support = getSupportedEnvironment();
416
786
  var parentReadyCallbacks = [];
417
787
  var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, detachOnChange);
418
788
  var elementComputedStyle = {};
@@ -429,15 +799,6 @@ function createEnvObserver(preset) {
429
799
  function detachOnChange() {
430
800
  removeDetector();
431
801
  }
432
- function getSupportedEnv() {
433
- if (typeof globalThis.CSS !== 'undefined' && typeof globalThis.CSS.supports === 'function') {
434
- if (globalThis.CSS.supports('x: env(x)'))
435
- return 'env';
436
- if (globalThis.CSS.supports('x: constant(x)'))
437
- return 'constant';
438
- }
439
- return undefined;
440
- }
441
802
  function isSameValues(a, b) {
442
803
  for (var i = 0; i < attributes.length; i++) {
443
804
  var key = attributes[i];
@@ -477,7 +838,7 @@ function createEnvObserver(preset) {
477
838
  parentReadyCallbacks[i]();
478
839
  }
479
840
  function addChild(parent, attribute) {
480
- var envVar = envMap[attribute];
841
+ var envVar = environmentMap[attribute];
481
842
  var p1 = globalThis.document.createElement('div');
482
843
  var p2 = globalThis.document.createElement('div');
483
844
  var c1 = globalThis.document.createElement('div');
@@ -540,9 +901,8 @@ function createEnvObserver(preset) {
540
901
  }
541
902
  function init() {
542
903
  if (typeof support === 'undefined') {
543
- for (var i = 0; i < attributes.length; i++) {
904
+ for (var i = 0; i < attributes.length; i++)
544
905
  elementComputedStyle[attributes[i]] = 0;
545
- }
546
906
  return;
547
907
  }
548
908
  elementComputedStyle = {};
@@ -586,8 +946,28 @@ function createEnvObserver(preset) {
586
946
  }
587
947
  return result;
588
948
  }
949
+ function useCssVariable(prefix) {
950
+ if (typeof support === 'undefined' || typeof globalThis.document === 'undefined')
951
+ return noop;
952
+ var element = globalThis.document.documentElement;
953
+ function applyValues(values) {
954
+ for (var i = 0; i < attributes.length; i++) {
955
+ var attribute = attributes[i];
956
+ element.style.setProperty("--".concat(prefix, "-").concat(String(attribute)), values[attribute] + 'px');
957
+ }
958
+ }
959
+ var unsubscribe = onChangeSubscriptionManager.subscribe(function (values) {
960
+ applyValues(values);
961
+ });
962
+ applyValues(readValues());
963
+ return function () {
964
+ unsubscribe();
965
+ for (var i = 0; i < attributes.length; i++)
966
+ element.style.removeProperty("--".concat(prefix, "-").concat(String(attributes[i])));
967
+ };
968
+ }
589
969
  return {
590
- get: function () {
970
+ get value() {
591
971
  if (parentDiv !== null)
592
972
  return readValues();
593
973
  init();
@@ -600,15 +980,16 @@ function createEnvObserver(preset) {
600
980
  if (typeof support === 'undefined')
601
981
  return noop;
602
982
  return onChangeSubscriptionManager.subscribe(callback, options);
603
- }
983
+ },
984
+ useCssVariable: useCssVariable
604
985
  };
605
986
  }
606
987
 
607
- var safeAreaInsetObserver = createEnvObserver('safe-area-inset');
608
- var safeAreaMaxInsetObserver = createEnvObserver('safe-area-max-inset');
609
- var keyboardInsetObserver = createEnvObserver('keyboard-inset');
610
- var titlebarAreaObserver = createEnvObserver('titlebar-area');
611
- var viewportSegmentObserver = createEnvObserver('viewport-segment');
988
+ var safeAreaInsetObserver = createEnvironmentObserver('safe-area-inset');
989
+ var safeAreaMaxInsetObserver = createEnvironmentObserver('safe-area-max-inset');
990
+ var keyboardInsetObserver = createEnvironmentObserver('keyboard-inset');
991
+ var titlebarAreaObserver = createEnvironmentObserver('titlebar-area');
992
+ var viewportSegmentObserver = createEnvironmentObserver('viewport-segment');
612
993
  var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, detachOnChange);
613
994
  var dimensionRef = null;
614
995
  var Dimension = {
@@ -643,9 +1024,9 @@ function getOrientation() {
643
1024
  return Orientation.Landscape;
644
1025
  }
645
1026
  }
646
- if (MEDIA_QUERY_LIST.media === 'not all')
1027
+ if (ORIENTATION_MEDIA_QUERY_LIST.media === 'not all')
647
1028
  return Orientation.Unknown;
648
- else if (MEDIA_QUERY_LIST.matches)
1029
+ else if (ORIENTATION_MEDIA_QUERY_LIST.matches)
649
1030
  return Orientation.Portrait;
650
1031
  else
651
1032
  return Orientation.Landscape;
@@ -657,50 +1038,29 @@ function getScale() {
657
1038
  }
658
1039
  function getEnvironment() {
659
1040
  return {
660
- safeAreaInset: {
661
- get value() {
662
- return safeAreaInsetObserver.get();
663
- },
664
- onChange: safeAreaInsetObserver.onChange,
665
- },
666
- safeAreaMaxInset: {
667
- get value() {
668
- return safeAreaMaxInsetObserver.get();
669
- },
670
- onChange: safeAreaMaxInsetObserver.onChange,
671
- },
672
- keyboardInset: {
673
- get value() {
674
- return keyboardInsetObserver.get();
675
- },
676
- onChange: keyboardInsetObserver.onChange,
677
- },
678
- titlebarArea: {
679
- get value() {
680
- return titlebarAreaObserver.get();
681
- },
682
- onChange: titlebarAreaObserver.onChange,
683
- },
684
- viewportSegment: {
685
- get value() {
686
- return viewportSegmentObserver.get();
687
- },
688
- onChange: viewportSegmentObserver.onChange,
689
- },
1041
+ safeAreaInset: safeAreaInsetObserver,
1042
+ safeAreaMaxInset: safeAreaMaxInsetObserver,
1043
+ keyboardInset: keyboardInsetObserver,
1044
+ titlebarArea: titlebarAreaObserver,
1045
+ viewportSegment: viewportSegmentObserver,
690
1046
  };
691
1047
  }
692
1048
  function getDimension() {
1049
+ var dimensions = {
1050
+ innerWidth: 0,
1051
+ innerHeight: 0,
1052
+ outerWidth: 0,
1053
+ outerHeight: 0,
1054
+ scale: getScale(),
1055
+ orientation: getOrientation(),
1056
+ };
693
1057
  if (typeof globalThis.innerWidth !== 'undefined') {
694
- return {
695
- innerWidth: globalThis.innerWidth,
696
- innerHeight: globalThis.innerHeight,
697
- outerWidth: globalThis.outerWidth,
698
- outerHeight: globalThis.outerHeight,
699
- scale: getScale(),
700
- orientation: getOrientation(),
701
- };
1058
+ dimensions.innerWidth = globalThis.innerWidth;
1059
+ dimensions.innerHeight = globalThis.innerHeight;
1060
+ dimensions.outerWidth = globalThis.outerWidth;
1061
+ dimensions.outerHeight = globalThis.outerHeight;
702
1062
  }
703
- return FALLBACK_DIMENSION;
1063
+ return dimensions;
704
1064
  }
705
1065
  function attachOnChange() {
706
1066
  dimensionRef = getDimension();
@@ -709,8 +1069,8 @@ function attachOnChange() {
709
1069
  EventListener.add(globalThis.screen.orientation, { type: 'change', callback: onResize });
710
1070
  else if (typeof globalThis.orientation !== 'undefined')
711
1071
  EventListener.add(globalThis, { type: 'orientationChange', callback: onResize });
712
- else if (MEDIA_QUERY_LIST.media !== 'not all')
713
- EventListener.add(MEDIA_QUERY_LIST, { type: 'change', callback: onResize });
1072
+ else if (ORIENTATION_MEDIA_QUERY_LIST.media !== 'not all')
1073
+ EventListener.add(ORIENTATION_MEDIA_QUERY_LIST, { type: 'change', callback: onResize });
714
1074
  }
715
1075
  function detachOnChange() {
716
1076
  dimensionRef = null;
@@ -719,8 +1079,8 @@ function detachOnChange() {
719
1079
  EventListener.remove(globalThis.screen.orientation, { type: 'change', callback: onResize });
720
1080
  else if (typeof globalThis.orientation !== 'undefined')
721
1081
  EventListener.remove(globalThis, { type: 'orientationChange', callback: onResize });
722
- else if (MEDIA_QUERY_LIST.media !== 'not all')
723
- EventListener.remove(MEDIA_QUERY_LIST, { type: 'change', callback: onResize });
1082
+ else if (ORIENTATION_MEDIA_QUERY_LIST.media !== 'not all')
1083
+ EventListener.remove(ORIENTATION_MEDIA_QUERY_LIST, { type: 'change', callback: onResize });
724
1084
  }
725
1085
  function onResize() {
726
1086
  var dimension = getDimension();
@@ -728,4 +1088,4 @@ function onResize() {
728
1088
  onChangeSubscriptionManager.emit(dimensionRef = dimension);
729
1089
  }
730
1090
 
731
- export { ENV_PRESETS, FALLBACK_DIMENSION, MEDIA_QUERY_LIST, Orientation, Dimension as default };
1091
+ export { DEVICE_POSTURE_MEDIA_QUERY_LIST, ENV_PRESETS, ORIENTATION_MEDIA_QUERY_LIST, Orientation, Dimension as default };