native-fn 1.3.2 → 1.3.4

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.
@@ -607,8 +607,8 @@ function createViewportSegmentObserver() {
607
607
  segments = viewport.segments;
608
608
  else
609
609
  segments = visualViewport.segments;
610
- if (segments === null || typeof segments === 'undefined')
611
- return [];
610
+ if (segments === null || typeof segments === 'undefined' || segments.length === 0)
611
+ return [buildFullViewportSegment()];
612
612
  var results = [];
613
613
  for (var i = 0; i < segments.length; i++) {
614
614
  var segment = segments[i];
@@ -725,31 +725,57 @@ function createViewportSegmentObserver() {
725
725
  }
726
726
  function createVirtualKeyboardObserver() {
727
727
  var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, detachOnChange);
728
+ var virtualKeyboard = globalThis.navigator.virtualKeyboard;
729
+ var pendingRaf = null;
728
730
  function attachOnChange() {
729
- EventListener.add(globalThis.navigator.virtualKeyboard, { type: 'geometrychange', callback: onGeometryChange, options: { passive: true } });
731
+ EventListener.add(virtualKeyboard, { type: 'geometrychange', callback: onGeometryChange, options: { passive: true } });
730
732
  }
731
733
  function detachOnChange() {
732
- EventListener.remove(globalThis.navigator.virtualKeyboard, { type: 'geometrychange', callback: onGeometryChange, options: { passive: true } });
734
+ EventListener.remove(virtualKeyboard, { type: 'geometrychange', callback: onGeometryChange, options: { passive: true } });
735
+ if (pendingRaf !== null) {
736
+ globalThis.cancelAnimationFrame(pendingRaf);
737
+ pendingRaf = null;
738
+ }
733
739
  }
734
740
  function onGeometryChange() {
735
- onChangeSubscriptionManager.emit(getValue());
741
+ if (pendingRaf !== null)
742
+ globalThis.cancelAnimationFrame(pendingRaf);
743
+ if (typeof globalThis.requestAnimationFrame === 'function') {
744
+ pendingRaf = globalThis.requestAnimationFrame(function () {
745
+ pendingRaf = null;
746
+ onChangeSubscriptionManager.emit(getValue());
747
+ });
748
+ }
749
+ else {
750
+ defer(function () {
751
+ onChangeSubscriptionManager.emit(getValue());
752
+ });
753
+ }
736
754
  }
737
755
  function getValue() {
738
- var rect = globalThis.navigator.virtualKeyboard.boundingRect;
739
- var left = rect.x;
740
- var top = rect.y;
756
+ var rect = virtualKeyboard.boundingRect;
741
757
  var width = rect.width;
742
758
  var height = rect.height;
743
- var right;
744
- if (width === 0)
745
- right = 0;
746
- else
747
- right = Math.max(0, globalThis.innerWidth - (left + width));
759
+ var top;
760
+ var left;
748
761
  var bottom;
749
- if (height === 0)
762
+ var right;
763
+ if (height === 0) {
764
+ top = 0;
750
765
  bottom = 0;
751
- else
752
- bottom = Math.max(0, globalThis.innerHeight - (top + height));
766
+ }
767
+ else {
768
+ top = rect.y;
769
+ bottom = Math.max(0, globalThis.innerHeight - rect.y);
770
+ }
771
+ if (width === 0) {
772
+ left = 0;
773
+ right = 0;
774
+ }
775
+ else {
776
+ left = rect.x;
777
+ right = Math.max(0, globalThis.innerWidth - rect.x);
778
+ }
753
779
  return {
754
780
  top: top,
755
781
  right: right,
@@ -603,8 +603,8 @@ function createViewportSegmentObserver() {
603
603
  segments = viewport.segments;
604
604
  else
605
605
  segments = visualViewport.segments;
606
- if (segments === null || typeof segments === 'undefined')
607
- return [];
606
+ if (segments === null || typeof segments === 'undefined' || segments.length === 0)
607
+ return [buildFullViewportSegment()];
608
608
  var results = [];
609
609
  for (var i = 0; i < segments.length; i++) {
610
610
  var segment = segments[i];
@@ -721,31 +721,57 @@ function createViewportSegmentObserver() {
721
721
  }
722
722
  function createVirtualKeyboardObserver() {
723
723
  var onChangeSubscriptionManager = createSubscriptionManager(attachOnChange, detachOnChange);
724
+ var virtualKeyboard = globalThis.navigator.virtualKeyboard;
725
+ var pendingRaf = null;
724
726
  function attachOnChange() {
725
- EventListener.add(globalThis.navigator.virtualKeyboard, { type: 'geometrychange', callback: onGeometryChange, options: { passive: true } });
727
+ EventListener.add(virtualKeyboard, { type: 'geometrychange', callback: onGeometryChange, options: { passive: true } });
726
728
  }
727
729
  function detachOnChange() {
728
- EventListener.remove(globalThis.navigator.virtualKeyboard, { type: 'geometrychange', callback: onGeometryChange, options: { passive: true } });
730
+ EventListener.remove(virtualKeyboard, { type: 'geometrychange', callback: onGeometryChange, options: { passive: true } });
731
+ if (pendingRaf !== null) {
732
+ globalThis.cancelAnimationFrame(pendingRaf);
733
+ pendingRaf = null;
734
+ }
729
735
  }
730
736
  function onGeometryChange() {
731
- onChangeSubscriptionManager.emit(getValue());
737
+ if (pendingRaf !== null)
738
+ globalThis.cancelAnimationFrame(pendingRaf);
739
+ if (typeof globalThis.requestAnimationFrame === 'function') {
740
+ pendingRaf = globalThis.requestAnimationFrame(function () {
741
+ pendingRaf = null;
742
+ onChangeSubscriptionManager.emit(getValue());
743
+ });
744
+ }
745
+ else {
746
+ defer(function () {
747
+ onChangeSubscriptionManager.emit(getValue());
748
+ });
749
+ }
732
750
  }
733
751
  function getValue() {
734
- var rect = globalThis.navigator.virtualKeyboard.boundingRect;
735
- var left = rect.x;
736
- var top = rect.y;
752
+ var rect = virtualKeyboard.boundingRect;
737
753
  var width = rect.width;
738
754
  var height = rect.height;
739
- var right;
740
- if (width === 0)
741
- right = 0;
742
- else
743
- right = Math.max(0, globalThis.innerWidth - (left + width));
755
+ var top;
756
+ var left;
744
757
  var bottom;
745
- if (height === 0)
758
+ var right;
759
+ if (height === 0) {
760
+ top = 0;
746
761
  bottom = 0;
747
- else
748
- bottom = Math.max(0, globalThis.innerHeight - (top + height));
762
+ }
763
+ else {
764
+ top = rect.y;
765
+ bottom = Math.max(0, globalThis.innerHeight - rect.y);
766
+ }
767
+ if (width === 0) {
768
+ left = 0;
769
+ right = 0;
770
+ }
771
+ else {
772
+ left = rect.x;
773
+ right = Math.max(0, globalThis.innerWidth - rect.x);
774
+ }
749
775
  return {
750
776
  top: top,
751
777
  right: right,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-fn",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "TypeScript library bridging Web APIs to native device capabilities — Picture-in-Picture, Fullscreen, Clipboard, Geolocation, Battery, Notifications, Vibration, Platform detection, and more.",
5
5
  "author": "Park Jungyoung <qkrwnss0509@gmail.com> (https://github.com/pjy0509)",
6
6
  "type": "module",