@krainovsd/js-helpers 0.13.4 → 0.13.6
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.
- package/lib/cjs/index.cjs +229 -350
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/esm/lib/api/core.js +21 -8
- package/lib/esm/lib/api/core.js.map +1 -1
- package/lib/esm/lib/browser/get-visible-position.js +208 -342
- package/lib/esm/lib/browser/get-visible-position.js.map +1 -1
- package/lib/index.d.ts +4 -3
- package/package.json +1 -1
package/lib/cjs/index.cjs
CHANGED
|
@@ -688,36 +688,37 @@ function getVisiblePosition({ initialPosition, node, visibleArea, placement = "b
|
|
|
688
688
|
placement === "right-top" ||
|
|
689
689
|
placement === "right-center"
|
|
690
690
|
? 0
|
|
691
|
-
: 10, flex, }) {
|
|
692
|
-
|
|
693
|
-
const
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
}
|
|
691
|
+
: 10, flex, nested, }) {
|
|
692
|
+
/** Viewport Variables */
|
|
693
|
+
const viewport = visibleArea ?? document.documentElement;
|
|
694
|
+
const scrollTop = document.documentElement.scrollTop;
|
|
695
|
+
const scrollLeft = document.documentElement.scrollLeft;
|
|
696
|
+
const rect = viewport.getBoundingClientRect();
|
|
697
|
+
const viewportWidth = viewport.clientWidth;
|
|
698
|
+
const viewportHeight = viewport.clientHeight;
|
|
699
|
+
const xStart = visibleArea ? viewport.offsetLeft - viewport.scrollLeft : Math.abs(rect.left);
|
|
700
|
+
const xEnd = xStart + viewportWidth;
|
|
701
|
+
const yStart = visibleArea ? viewport.offsetTop : Math.abs(rect.top);
|
|
702
|
+
const yEnd = yStart + viewportHeight;
|
|
703
|
+
/** Target Variables */
|
|
705
704
|
let targetHeight = 0;
|
|
706
705
|
let targetWidth = 0;
|
|
707
|
-
let
|
|
706
|
+
let targetTopPosition = 0;
|
|
707
|
+
let targetLeftPosition = 0;
|
|
708
|
+
const { height: nodeHeight, width: nodeWidth } = node.getBoundingClientRect();
|
|
708
709
|
if (initialPosition?.targetNode) {
|
|
709
|
-
const { top
|
|
710
|
+
const { top, left, height, width } = initialPosition.targetNode.getBoundingClientRect();
|
|
710
711
|
targetHeight = height;
|
|
711
712
|
targetWidth = width;
|
|
712
|
-
targetTopPosition =
|
|
713
|
-
targetLeftPosition =
|
|
713
|
+
targetTopPosition = top + scrollTop;
|
|
714
|
+
targetLeftPosition = left + scrollLeft;
|
|
714
715
|
}
|
|
715
716
|
if (initialPosition?.position) {
|
|
716
717
|
if (initialPosition.position.x) {
|
|
717
|
-
targetLeftPosition = initialPosition.position.x;
|
|
718
|
+
targetLeftPosition = initialPosition.position.x + scrollLeft;
|
|
718
719
|
}
|
|
719
720
|
if (initialPosition.position.y) {
|
|
720
|
-
targetTopPosition = initialPosition.position.y;
|
|
721
|
+
targetTopPosition = initialPosition.position.y + scrollTop;
|
|
721
722
|
}
|
|
722
723
|
if (initialPosition.position.height) {
|
|
723
724
|
targetHeight = initialPosition.position.height;
|
|
@@ -726,6 +727,33 @@ function getVisiblePosition({ initialPosition, node, visibleArea, placement = "b
|
|
|
726
727
|
targetWidth = initialPosition.position.width;
|
|
727
728
|
}
|
|
728
729
|
}
|
|
730
|
+
/** Inherit Position */
|
|
731
|
+
let inheritLeft = 0;
|
|
732
|
+
let inheritTop = 0;
|
|
733
|
+
if (nested) {
|
|
734
|
+
const { left = 0, top = 0 } = node.parentElement?.getBoundingClientRect?.() ?? {};
|
|
735
|
+
inheritLeft = left + scrollLeft;
|
|
736
|
+
inheritTop = top + scrollTop;
|
|
737
|
+
}
|
|
738
|
+
/** Initial Position */
|
|
739
|
+
const targetXCenter = targetWidth ? targetLeftPosition + targetWidth / 2 : targetLeftPosition;
|
|
740
|
+
const targetYCenter = targetHeight ? targetTopPosition + targetHeight / 2 : targetTopPosition;
|
|
741
|
+
const targetYEnd = targetHeight ? targetTopPosition + targetHeight : targetTopPosition;
|
|
742
|
+
const x = {
|
|
743
|
+
insideCenter: targetXCenter - nodeWidth / 2 + stepX,
|
|
744
|
+
insideRight: targetLeftPosition + targetWidth + stepX - nodeWidth,
|
|
745
|
+
insideLeft: targetLeftPosition + stepX,
|
|
746
|
+
left: targetLeftPosition - nodeWidth - stepX,
|
|
747
|
+
right: targetLeftPosition + targetWidth + stepX,
|
|
748
|
+
};
|
|
749
|
+
const y = {
|
|
750
|
+
bottom: targetYEnd + stepY,
|
|
751
|
+
top: targetTopPosition - stepY - nodeHeight,
|
|
752
|
+
insideCenter: targetYCenter - nodeHeight / 2 + stepY,
|
|
753
|
+
insideBottom: targetTopPosition + targetHeight - nodeHeight + stepY,
|
|
754
|
+
insideTop: targetTopPosition + stepY,
|
|
755
|
+
};
|
|
756
|
+
/** Find visible position */
|
|
729
757
|
function isCompletelyVisibleX(left) {
|
|
730
758
|
const endXPosition = nodeWidth + left;
|
|
731
759
|
return xStart <= left && xEnd >= endXPosition;
|
|
@@ -734,496 +762,358 @@ function getVisiblePosition({ initialPosition, node, visibleArea, placement = "b
|
|
|
734
762
|
const endYPosition = nodeHeight + top;
|
|
735
763
|
return yStart <= top && yEnd >= endYPosition;
|
|
736
764
|
}
|
|
737
|
-
let
|
|
738
|
-
let correctTop = targetTopPosition;
|
|
739
|
-
const { x, y } = getStartPositions({
|
|
740
|
-
targetHeight,
|
|
741
|
-
targetWidth,
|
|
765
|
+
let visiblePositions = processVisiblePositions({
|
|
742
766
|
targetLeftPosition,
|
|
767
|
+
targetTopPosition,
|
|
768
|
+
x,
|
|
769
|
+
y,
|
|
770
|
+
placement,
|
|
771
|
+
flex,
|
|
743
772
|
nodeHeight,
|
|
744
773
|
nodeWidth,
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
774
|
+
xEnd,
|
|
775
|
+
xStart,
|
|
776
|
+
yEnd,
|
|
777
|
+
yStart,
|
|
778
|
+
isCompletelyVisibleX,
|
|
779
|
+
isCompletelyVisibleY,
|
|
748
780
|
});
|
|
749
|
-
|
|
781
|
+
if (flex &&
|
|
782
|
+
(!isCompletelyVisibleX(visiblePositions.left) || !isCompletelyVisibleY(visiblePositions.top))) {
|
|
783
|
+
visiblePositions = getFlexVisiblePosition({
|
|
784
|
+
initialLeft: visiblePositions.left,
|
|
785
|
+
initialTop: visiblePositions.top,
|
|
786
|
+
isCompletelyVisibleX,
|
|
787
|
+
isCompletelyVisibleY,
|
|
788
|
+
nodeHeight,
|
|
789
|
+
nodeWidth,
|
|
790
|
+
xEnd,
|
|
791
|
+
yEnd,
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
visiblePositions.left -= inheritLeft;
|
|
795
|
+
visiblePositions.top -= inheritTop;
|
|
796
|
+
return {
|
|
797
|
+
placement: visiblePositions.placement,
|
|
798
|
+
left: visiblePositions.left,
|
|
799
|
+
top: visiblePositions.top,
|
|
800
|
+
bottom: yEnd - scrollTop - (visiblePositions.top + nodeHeight),
|
|
801
|
+
right: xEnd - scrollLeft - (visiblePositions.left + nodeWidth),
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
function processVisiblePositions(opts) {
|
|
805
|
+
let correctLeft = opts.targetLeftPosition;
|
|
806
|
+
let correctTop = opts.targetTopPosition;
|
|
807
|
+
switch (opts.placement) {
|
|
750
808
|
case "bottom-center": {
|
|
751
|
-
correctLeft = x.
|
|
752
|
-
correctTop = y.bottom;
|
|
809
|
+
correctLeft = opts.x.insideCenter;
|
|
810
|
+
correctTop = opts.y.bottom;
|
|
753
811
|
let placement = "bottom-center";
|
|
754
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
755
|
-
if (isCompletelyVisibleX(x.
|
|
812
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
813
|
+
if (opts.isCompletelyVisibleX(opts.x.insideLeft)) {
|
|
756
814
|
placement = "bottom-left";
|
|
757
|
-
correctLeft = x.
|
|
815
|
+
correctLeft = opts.x.insideLeft;
|
|
758
816
|
}
|
|
759
|
-
else if (isCompletelyVisibleX(x.
|
|
817
|
+
else if (opts.isCompletelyVisibleX(opts.x.insideRight)) {
|
|
760
818
|
placement = "bottom-right";
|
|
761
|
-
correctLeft = x.
|
|
819
|
+
correctLeft = opts.x.insideRight;
|
|
762
820
|
}
|
|
763
821
|
}
|
|
764
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
765
|
-
if (isCompletelyVisibleY(y.top)) {
|
|
822
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
823
|
+
if (opts.isCompletelyVisibleY(opts.y.top)) {
|
|
766
824
|
placement = placement.replace("bottom", "top");
|
|
767
|
-
correctTop = y.top;
|
|
825
|
+
correctTop = opts.y.top;
|
|
768
826
|
}
|
|
769
827
|
}
|
|
770
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
771
|
-
return getFlexVisiblePosition({
|
|
772
|
-
initialLeft: correctLeft,
|
|
773
|
-
initialTop: correctTop,
|
|
774
|
-
isCompletelyVisibleX,
|
|
775
|
-
isCompletelyVisibleY,
|
|
776
|
-
nodeHeight,
|
|
777
|
-
nodeWidth,
|
|
778
|
-
xEnd,
|
|
779
|
-
yEnd,
|
|
780
|
-
});
|
|
781
|
-
}
|
|
782
828
|
return {
|
|
783
829
|
top: correctTop,
|
|
784
830
|
left: correctLeft,
|
|
785
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
786
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
787
831
|
placement,
|
|
788
832
|
};
|
|
789
833
|
}
|
|
790
834
|
case "bottom-left": {
|
|
791
|
-
correctLeft = x.
|
|
792
|
-
correctTop = y.bottom;
|
|
835
|
+
correctLeft = opts.x.insideLeft;
|
|
836
|
+
correctTop = opts.y.bottom;
|
|
793
837
|
let placement = "bottom-left";
|
|
794
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
795
|
-
if (isCompletelyVisibleX(x.
|
|
838
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
839
|
+
if (opts.isCompletelyVisibleX(opts.x.insideCenter)) {
|
|
796
840
|
placement = "bottom-center";
|
|
797
|
-
correctLeft = x.
|
|
841
|
+
correctLeft = opts.x.insideCenter;
|
|
798
842
|
}
|
|
799
|
-
else if (isCompletelyVisibleX(x.
|
|
843
|
+
else if (opts.isCompletelyVisibleX(opts.x.insideRight)) {
|
|
800
844
|
placement = "bottom-right";
|
|
801
|
-
correctLeft = x.
|
|
845
|
+
correctLeft = opts.x.insideRight;
|
|
802
846
|
}
|
|
803
847
|
}
|
|
804
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
805
|
-
if (isCompletelyVisibleY(y.top)) {
|
|
848
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
849
|
+
if (opts.isCompletelyVisibleY(opts.y.top)) {
|
|
806
850
|
placement = placement.replace("bottom", "top");
|
|
807
|
-
correctTop = y.top;
|
|
851
|
+
correctTop = opts.y.top;
|
|
808
852
|
}
|
|
809
853
|
}
|
|
810
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
811
|
-
return getFlexVisiblePosition({
|
|
812
|
-
initialLeft: correctLeft,
|
|
813
|
-
initialTop: correctTop,
|
|
814
|
-
isCompletelyVisibleX,
|
|
815
|
-
isCompletelyVisibleY,
|
|
816
|
-
nodeHeight,
|
|
817
|
-
nodeWidth,
|
|
818
|
-
xEnd,
|
|
819
|
-
yEnd,
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
854
|
return {
|
|
823
855
|
top: correctTop,
|
|
824
856
|
left: correctLeft,
|
|
825
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
826
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
827
857
|
placement,
|
|
828
858
|
};
|
|
829
859
|
}
|
|
830
860
|
case "bottom-right": {
|
|
831
|
-
correctLeft = x.
|
|
832
|
-
correctTop = y.bottom;
|
|
861
|
+
correctLeft = opts.x.insideRight;
|
|
862
|
+
correctTop = opts.y.bottom;
|
|
833
863
|
let placement = "bottom-right";
|
|
834
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
835
|
-
if (isCompletelyVisibleX(x.
|
|
864
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
865
|
+
if (opts.isCompletelyVisibleX(opts.x.insideCenter)) {
|
|
836
866
|
placement = "bottom-center";
|
|
837
|
-
correctLeft = x.
|
|
867
|
+
correctLeft = opts.x.insideCenter;
|
|
838
868
|
}
|
|
839
|
-
else if (isCompletelyVisibleX(x.
|
|
869
|
+
else if (opts.isCompletelyVisibleX(opts.x.insideLeft)) {
|
|
840
870
|
placement = "bottom-left";
|
|
841
|
-
correctLeft = x.
|
|
871
|
+
correctLeft = opts.x.insideLeft;
|
|
842
872
|
}
|
|
843
873
|
}
|
|
844
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
845
|
-
if (isCompletelyVisibleY(y.top)) {
|
|
874
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
875
|
+
if (opts.isCompletelyVisibleY(opts.y.top)) {
|
|
846
876
|
placement = placement.replace("bottom", "top");
|
|
847
|
-
correctTop = y.top;
|
|
877
|
+
correctTop = opts.y.top;
|
|
848
878
|
}
|
|
849
879
|
}
|
|
850
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
851
|
-
return getFlexVisiblePosition({
|
|
852
|
-
initialLeft: correctLeft,
|
|
853
|
-
initialTop: correctTop,
|
|
854
|
-
isCompletelyVisibleX,
|
|
855
|
-
isCompletelyVisibleY,
|
|
856
|
-
nodeHeight,
|
|
857
|
-
nodeWidth,
|
|
858
|
-
xEnd,
|
|
859
|
-
yEnd,
|
|
860
|
-
});
|
|
861
|
-
}
|
|
862
880
|
return {
|
|
863
881
|
top: correctTop,
|
|
864
882
|
left: correctLeft,
|
|
865
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
866
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
867
883
|
placement,
|
|
868
884
|
};
|
|
869
885
|
}
|
|
870
886
|
case "right-bottom": {
|
|
871
|
-
correctLeft = x.right;
|
|
872
|
-
correctTop = y.
|
|
887
|
+
correctLeft = opts.x.right;
|
|
888
|
+
correctTop = opts.y.insideBottom;
|
|
873
889
|
let placement = "right-bottom";
|
|
874
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
875
|
-
if (isCompletelyVisibleY(y.
|
|
890
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
891
|
+
if (opts.isCompletelyVisibleY(opts.y.insideCenter)) {
|
|
876
892
|
placement = "right-center";
|
|
877
|
-
correctTop = y.
|
|
893
|
+
correctTop = opts.y.insideCenter;
|
|
878
894
|
}
|
|
879
|
-
else if (isCompletelyVisibleY(y.
|
|
895
|
+
else if (opts.isCompletelyVisibleY(opts.y.insideTop)) {
|
|
880
896
|
placement = "right-top";
|
|
881
|
-
correctTop = y.
|
|
897
|
+
correctTop = opts.y.insideTop;
|
|
882
898
|
}
|
|
883
899
|
}
|
|
884
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
885
|
-
if (isCompletelyVisibleX(x.left)) {
|
|
900
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
901
|
+
if (opts.isCompletelyVisibleX(opts.x.left)) {
|
|
886
902
|
placement = placement.replace("right", "left");
|
|
887
|
-
correctLeft = x.left;
|
|
903
|
+
correctLeft = opts.x.left;
|
|
888
904
|
}
|
|
889
905
|
}
|
|
890
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
891
|
-
return getFlexVisiblePosition({
|
|
892
|
-
initialLeft: correctLeft,
|
|
893
|
-
initialTop: correctTop,
|
|
894
|
-
isCompletelyVisibleX,
|
|
895
|
-
isCompletelyVisibleY,
|
|
896
|
-
nodeHeight,
|
|
897
|
-
nodeWidth,
|
|
898
|
-
xEnd,
|
|
899
|
-
yEnd,
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
906
|
return {
|
|
903
907
|
top: correctTop,
|
|
904
908
|
left: correctLeft,
|
|
905
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
906
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
907
909
|
placement,
|
|
908
910
|
};
|
|
909
911
|
}
|
|
910
912
|
case "right-center": {
|
|
911
|
-
correctLeft = x.right;
|
|
912
|
-
correctTop = y.
|
|
913
|
+
correctLeft = opts.x.right;
|
|
914
|
+
correctTop = opts.y.insideCenter;
|
|
913
915
|
let placement = "right-center";
|
|
914
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
915
|
-
if (isCompletelyVisibleY(y.
|
|
916
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
917
|
+
if (opts.isCompletelyVisibleY(opts.y.insideTop)) {
|
|
916
918
|
placement = "right-top";
|
|
917
|
-
correctTop = y.
|
|
919
|
+
correctTop = opts.y.insideTop;
|
|
918
920
|
}
|
|
919
|
-
else if (isCompletelyVisibleY(y.
|
|
921
|
+
else if (opts.isCompletelyVisibleY(opts.y.insideBottom)) {
|
|
920
922
|
placement = "right-bottom";
|
|
921
|
-
correctTop = y.
|
|
923
|
+
correctTop = opts.y.insideBottom;
|
|
922
924
|
}
|
|
923
925
|
}
|
|
924
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
925
|
-
if (isCompletelyVisibleX(x.left)) {
|
|
926
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
927
|
+
if (opts.isCompletelyVisibleX(opts.x.left)) {
|
|
926
928
|
placement = placement.replace("right", "left");
|
|
927
|
-
correctLeft = x.left;
|
|
929
|
+
correctLeft = opts.x.left;
|
|
928
930
|
}
|
|
929
931
|
}
|
|
930
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
931
|
-
return getFlexVisiblePosition({
|
|
932
|
-
initialLeft: correctLeft,
|
|
933
|
-
initialTop: correctTop,
|
|
934
|
-
isCompletelyVisibleX,
|
|
935
|
-
isCompletelyVisibleY,
|
|
936
|
-
nodeHeight,
|
|
937
|
-
nodeWidth,
|
|
938
|
-
xEnd,
|
|
939
|
-
yEnd,
|
|
940
|
-
});
|
|
941
|
-
}
|
|
942
932
|
return {
|
|
943
933
|
top: correctTop,
|
|
944
934
|
left: correctLeft,
|
|
945
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
946
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
947
935
|
placement,
|
|
948
936
|
};
|
|
949
937
|
}
|
|
950
938
|
case "right-top": {
|
|
951
|
-
correctLeft = x.right;
|
|
952
|
-
correctTop = y.
|
|
939
|
+
correctLeft = opts.x.right;
|
|
940
|
+
correctTop = opts.y.insideTop;
|
|
953
941
|
let placement = "right-top";
|
|
954
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
955
|
-
if (isCompletelyVisibleY(y.
|
|
942
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
943
|
+
if (opts.isCompletelyVisibleY(opts.y.insideCenter)) {
|
|
956
944
|
placement = "right-center";
|
|
957
|
-
correctTop = y.
|
|
945
|
+
correctTop = opts.y.insideCenter;
|
|
958
946
|
}
|
|
959
|
-
else if (isCompletelyVisibleY(y.
|
|
947
|
+
else if (opts.isCompletelyVisibleY(opts.y.insideBottom)) {
|
|
960
948
|
placement = "right-bottom";
|
|
961
|
-
correctTop = y.
|
|
949
|
+
correctTop = opts.y.insideBottom;
|
|
962
950
|
}
|
|
963
951
|
}
|
|
964
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
965
|
-
if (isCompletelyVisibleX(x.left)) {
|
|
952
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
953
|
+
if (opts.isCompletelyVisibleX(opts.x.left)) {
|
|
966
954
|
placement = placement.replace("right", "left");
|
|
967
|
-
correctLeft = x.left;
|
|
955
|
+
correctLeft = opts.x.left;
|
|
968
956
|
}
|
|
969
957
|
}
|
|
970
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
971
|
-
return getFlexVisiblePosition({
|
|
972
|
-
initialLeft: correctLeft,
|
|
973
|
-
initialTop: correctTop,
|
|
974
|
-
isCompletelyVisibleX,
|
|
975
|
-
isCompletelyVisibleY,
|
|
976
|
-
nodeHeight,
|
|
977
|
-
nodeWidth,
|
|
978
|
-
xEnd,
|
|
979
|
-
yEnd,
|
|
980
|
-
});
|
|
981
|
-
}
|
|
982
958
|
return {
|
|
983
959
|
top: correctTop,
|
|
984
960
|
left: correctLeft,
|
|
985
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
986
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
987
961
|
placement,
|
|
988
962
|
};
|
|
989
963
|
}
|
|
990
964
|
case "top-center": {
|
|
991
|
-
correctLeft = x.
|
|
992
|
-
correctTop = y.top;
|
|
965
|
+
correctLeft = opts.x.insideCenter;
|
|
966
|
+
correctTop = opts.y.top;
|
|
993
967
|
let placement = "top-center";
|
|
994
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
995
|
-
if (isCompletelyVisibleX(x.
|
|
968
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
969
|
+
if (opts.isCompletelyVisibleX(opts.x.insideLeft)) {
|
|
996
970
|
placement = "top-left";
|
|
997
|
-
correctLeft = x.
|
|
971
|
+
correctLeft = opts.x.insideLeft;
|
|
998
972
|
}
|
|
999
|
-
else if (isCompletelyVisibleX(x.
|
|
973
|
+
else if (opts.isCompletelyVisibleX(opts.x.insideRight)) {
|
|
1000
974
|
placement = "top-right";
|
|
1001
|
-
correctLeft = x.
|
|
975
|
+
correctLeft = opts.x.insideRight;
|
|
1002
976
|
}
|
|
1003
977
|
}
|
|
1004
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
1005
|
-
if (isCompletelyVisibleY(y.bottom)) {
|
|
978
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
979
|
+
if (opts.isCompletelyVisibleY(opts.y.bottom)) {
|
|
1006
980
|
placement = placement.replace("top", "bottom");
|
|
1007
|
-
correctTop = y.bottom;
|
|
981
|
+
correctTop = opts.y.bottom;
|
|
1008
982
|
}
|
|
1009
983
|
}
|
|
1010
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
1011
|
-
return getFlexVisiblePosition({
|
|
1012
|
-
initialLeft: correctLeft,
|
|
1013
|
-
initialTop: correctTop,
|
|
1014
|
-
isCompletelyVisibleX,
|
|
1015
|
-
isCompletelyVisibleY,
|
|
1016
|
-
nodeHeight,
|
|
1017
|
-
nodeWidth,
|
|
1018
|
-
xEnd,
|
|
1019
|
-
yEnd,
|
|
1020
|
-
});
|
|
1021
|
-
}
|
|
1022
984
|
return {
|
|
1023
985
|
top: correctTop,
|
|
1024
986
|
left: correctLeft,
|
|
1025
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
1026
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
1027
987
|
placement,
|
|
1028
988
|
};
|
|
1029
989
|
}
|
|
1030
990
|
case "top-left": {
|
|
1031
|
-
correctLeft = x.
|
|
1032
|
-
correctTop = y.top;
|
|
991
|
+
correctLeft = opts.x.insideLeft;
|
|
992
|
+
correctTop = opts.y.top;
|
|
1033
993
|
let placement = "top-left";
|
|
1034
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
1035
|
-
if (isCompletelyVisibleX(x.
|
|
994
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
995
|
+
if (opts.isCompletelyVisibleX(opts.x.insideCenter)) {
|
|
1036
996
|
placement = "top-center";
|
|
1037
|
-
correctLeft = x.
|
|
997
|
+
correctLeft = opts.x.insideCenter;
|
|
1038
998
|
}
|
|
1039
|
-
else if (isCompletelyVisibleX(x.
|
|
999
|
+
else if (opts.isCompletelyVisibleX(opts.x.insideRight)) {
|
|
1040
1000
|
placement = "top-right";
|
|
1041
|
-
correctLeft = x.
|
|
1001
|
+
correctLeft = opts.x.insideRight;
|
|
1042
1002
|
}
|
|
1043
1003
|
}
|
|
1044
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
1045
|
-
if (isCompletelyVisibleY(y.bottom)) {
|
|
1004
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
1005
|
+
if (opts.isCompletelyVisibleY(opts.y.bottom)) {
|
|
1046
1006
|
placement = placement.replace("top", "bottom");
|
|
1047
|
-
correctTop = y.bottom;
|
|
1007
|
+
correctTop = opts.y.bottom;
|
|
1048
1008
|
}
|
|
1049
1009
|
}
|
|
1050
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
1051
|
-
return getFlexVisiblePosition({
|
|
1052
|
-
initialLeft: correctLeft,
|
|
1053
|
-
initialTop: correctTop,
|
|
1054
|
-
isCompletelyVisibleX,
|
|
1055
|
-
isCompletelyVisibleY,
|
|
1056
|
-
nodeHeight,
|
|
1057
|
-
nodeWidth,
|
|
1058
|
-
xEnd,
|
|
1059
|
-
yEnd,
|
|
1060
|
-
});
|
|
1061
|
-
}
|
|
1062
1010
|
return {
|
|
1063
1011
|
top: correctTop,
|
|
1064
1012
|
left: correctLeft,
|
|
1065
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
1066
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
1067
1013
|
placement,
|
|
1068
1014
|
};
|
|
1069
1015
|
}
|
|
1070
1016
|
case "top-right": {
|
|
1071
|
-
correctLeft = x.
|
|
1072
|
-
correctTop = y.top;
|
|
1017
|
+
correctLeft = opts.x.insideRight;
|
|
1018
|
+
correctTop = opts.y.top;
|
|
1073
1019
|
let placement = "top-right";
|
|
1074
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
1075
|
-
if (isCompletelyVisibleX(x.
|
|
1020
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
1021
|
+
if (opts.isCompletelyVisibleX(opts.x.insideCenter)) {
|
|
1076
1022
|
placement = "top-center";
|
|
1077
|
-
correctLeft = x.
|
|
1023
|
+
correctLeft = opts.x.insideCenter;
|
|
1078
1024
|
}
|
|
1079
|
-
else if (isCompletelyVisibleX(x.
|
|
1025
|
+
else if (opts.isCompletelyVisibleX(opts.x.insideLeft)) {
|
|
1080
1026
|
placement = "top-left";
|
|
1081
|
-
correctLeft = x.
|
|
1027
|
+
correctLeft = opts.x.insideLeft;
|
|
1082
1028
|
}
|
|
1083
1029
|
}
|
|
1084
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
1085
|
-
if (isCompletelyVisibleY(y.bottom)) {
|
|
1030
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
1031
|
+
if (opts.isCompletelyVisibleY(opts.y.bottom)) {
|
|
1086
1032
|
placement = placement.replace("top", "bottom");
|
|
1087
|
-
correctTop = y.bottom;
|
|
1033
|
+
correctTop = opts.y.bottom;
|
|
1088
1034
|
}
|
|
1089
1035
|
}
|
|
1090
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
1091
|
-
return getFlexVisiblePosition({
|
|
1092
|
-
initialLeft: correctLeft,
|
|
1093
|
-
initialTop: correctTop,
|
|
1094
|
-
isCompletelyVisibleX,
|
|
1095
|
-
isCompletelyVisibleY,
|
|
1096
|
-
nodeHeight,
|
|
1097
|
-
nodeWidth,
|
|
1098
|
-
xEnd,
|
|
1099
|
-
yEnd,
|
|
1100
|
-
});
|
|
1101
|
-
}
|
|
1102
1036
|
return {
|
|
1103
1037
|
top: correctTop,
|
|
1104
1038
|
left: correctLeft,
|
|
1105
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
1106
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
1107
1039
|
placement,
|
|
1108
1040
|
};
|
|
1109
1041
|
}
|
|
1110
1042
|
case "left-bottom": {
|
|
1111
|
-
correctLeft = x.left;
|
|
1112
|
-
correctTop = y.
|
|
1043
|
+
correctLeft = opts.x.left;
|
|
1044
|
+
correctTop = opts.y.insideBottom;
|
|
1113
1045
|
let placement = "left-bottom";
|
|
1114
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
1115
|
-
if (isCompletelyVisibleY(y.
|
|
1046
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
1047
|
+
if (opts.isCompletelyVisibleY(opts.y.insideCenter)) {
|
|
1116
1048
|
placement = "left-center";
|
|
1117
|
-
correctTop = y.
|
|
1049
|
+
correctTop = opts.y.insideCenter;
|
|
1118
1050
|
}
|
|
1119
|
-
else if (isCompletelyVisibleY(y.
|
|
1051
|
+
else if (opts.isCompletelyVisibleY(opts.y.insideTop)) {
|
|
1120
1052
|
placement = "left-top";
|
|
1121
|
-
correctTop = y.
|
|
1053
|
+
correctTop = opts.y.insideTop;
|
|
1122
1054
|
}
|
|
1123
1055
|
}
|
|
1124
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
1125
|
-
if (isCompletelyVisibleX(x.right)) {
|
|
1056
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
1057
|
+
if (opts.isCompletelyVisibleX(opts.x.right)) {
|
|
1126
1058
|
placement = placement.replace("left", "right");
|
|
1127
|
-
correctLeft = x.right;
|
|
1059
|
+
correctLeft = opts.x.right;
|
|
1128
1060
|
}
|
|
1129
1061
|
}
|
|
1130
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
1131
|
-
return getFlexVisiblePosition({
|
|
1132
|
-
initialLeft: correctLeft,
|
|
1133
|
-
initialTop: correctTop,
|
|
1134
|
-
isCompletelyVisibleX,
|
|
1135
|
-
isCompletelyVisibleY,
|
|
1136
|
-
nodeHeight,
|
|
1137
|
-
nodeWidth,
|
|
1138
|
-
xEnd,
|
|
1139
|
-
yEnd,
|
|
1140
|
-
});
|
|
1141
|
-
}
|
|
1142
1062
|
return {
|
|
1143
1063
|
top: correctTop,
|
|
1144
1064
|
left: correctLeft,
|
|
1145
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
1146
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
1147
1065
|
placement,
|
|
1148
1066
|
};
|
|
1149
1067
|
}
|
|
1150
1068
|
case "left-center": {
|
|
1151
|
-
correctLeft = x.left;
|
|
1152
|
-
correctTop = y.
|
|
1069
|
+
correctLeft = opts.x.left;
|
|
1070
|
+
correctTop = opts.y.insideCenter;
|
|
1153
1071
|
let placement = "left-center";
|
|
1154
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
1155
|
-
if (isCompletelyVisibleY(y.
|
|
1072
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
1073
|
+
if (opts.isCompletelyVisibleY(opts.y.insideTop)) {
|
|
1156
1074
|
placement = "left-top";
|
|
1157
|
-
correctTop = y.
|
|
1075
|
+
correctTop = opts.y.insideTop;
|
|
1158
1076
|
}
|
|
1159
|
-
else if (isCompletelyVisibleY(y.
|
|
1077
|
+
else if (opts.isCompletelyVisibleY(opts.y.insideBottom)) {
|
|
1160
1078
|
placement = "left-bottom";
|
|
1161
|
-
correctTop = y.
|
|
1079
|
+
correctTop = opts.y.insideBottom;
|
|
1162
1080
|
}
|
|
1163
1081
|
}
|
|
1164
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
1165
|
-
if (isCompletelyVisibleX(x.right)) {
|
|
1082
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
1083
|
+
if (opts.isCompletelyVisibleX(opts.x.right)) {
|
|
1166
1084
|
placement = placement.replace("left", "right");
|
|
1167
|
-
correctLeft = x.right;
|
|
1085
|
+
correctLeft = opts.x.right;
|
|
1168
1086
|
}
|
|
1169
1087
|
}
|
|
1170
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
1171
|
-
return getFlexVisiblePosition({
|
|
1172
|
-
initialLeft: correctLeft,
|
|
1173
|
-
initialTop: correctTop,
|
|
1174
|
-
isCompletelyVisibleX,
|
|
1175
|
-
isCompletelyVisibleY,
|
|
1176
|
-
nodeHeight,
|
|
1177
|
-
nodeWidth,
|
|
1178
|
-
xEnd,
|
|
1179
|
-
yEnd,
|
|
1180
|
-
});
|
|
1181
|
-
}
|
|
1182
1088
|
return {
|
|
1183
1089
|
top: correctTop,
|
|
1184
1090
|
left: correctLeft,
|
|
1185
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
1186
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
1187
1091
|
placement,
|
|
1188
1092
|
};
|
|
1189
1093
|
}
|
|
1190
1094
|
case "left-top": {
|
|
1191
|
-
correctLeft = x.left;
|
|
1192
|
-
correctTop = y.
|
|
1095
|
+
correctLeft = opts.x.left;
|
|
1096
|
+
correctTop = opts.y.insideTop;
|
|
1193
1097
|
let placement = "left-top";
|
|
1194
|
-
if (!isCompletelyVisibleY(correctTop)) {
|
|
1195
|
-
if (isCompletelyVisibleY(y.
|
|
1098
|
+
if (!opts.isCompletelyVisibleY(correctTop)) {
|
|
1099
|
+
if (opts.isCompletelyVisibleY(opts.y.insideCenter)) {
|
|
1196
1100
|
placement = "left-center";
|
|
1197
|
-
correctTop = y.
|
|
1101
|
+
correctTop = opts.y.insideCenter;
|
|
1198
1102
|
}
|
|
1199
|
-
else if (isCompletelyVisibleY(y.
|
|
1103
|
+
else if (opts.isCompletelyVisibleY(opts.y.insideBottom)) {
|
|
1200
1104
|
placement = "left-bottom";
|
|
1201
|
-
correctTop = y.
|
|
1105
|
+
correctTop = opts.y.insideBottom;
|
|
1202
1106
|
}
|
|
1203
1107
|
}
|
|
1204
|
-
if (!isCompletelyVisibleX(correctLeft)) {
|
|
1205
|
-
if (isCompletelyVisibleX(x.right)) {
|
|
1108
|
+
if (!opts.isCompletelyVisibleX(correctLeft)) {
|
|
1109
|
+
if (opts.isCompletelyVisibleX(opts.x.right)) {
|
|
1206
1110
|
placement = placement.replace("left", "right");
|
|
1207
|
-
correctLeft = x.right;
|
|
1111
|
+
correctLeft = opts.x.right;
|
|
1208
1112
|
}
|
|
1209
1113
|
}
|
|
1210
|
-
if (flex && (!isCompletelyVisibleX(correctLeft) || !isCompletelyVisibleY(correctTop))) {
|
|
1211
|
-
return getFlexVisiblePosition({
|
|
1212
|
-
initialLeft: correctLeft,
|
|
1213
|
-
initialTop: correctTop,
|
|
1214
|
-
isCompletelyVisibleX,
|
|
1215
|
-
isCompletelyVisibleY,
|
|
1216
|
-
nodeHeight,
|
|
1217
|
-
nodeWidth,
|
|
1218
|
-
xEnd,
|
|
1219
|
-
yEnd,
|
|
1220
|
-
});
|
|
1221
|
-
}
|
|
1222
1114
|
return {
|
|
1223
1115
|
top: correctTop,
|
|
1224
1116
|
left: correctLeft,
|
|
1225
|
-
right: xEnd - correctLeft - nodeWidth,
|
|
1226
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
1227
1117
|
placement,
|
|
1228
1118
|
};
|
|
1229
1119
|
}
|
|
@@ -1231,33 +1121,11 @@ function getVisiblePosition({ initialPosition, node, visibleArea, placement = "b
|
|
|
1231
1121
|
return {
|
|
1232
1122
|
top: correctTop,
|
|
1233
1123
|
left: correctLeft,
|
|
1234
|
-
|
|
1235
|
-
bottom: yEnd - correctTop - nodeHeight,
|
|
1236
|
-
placement,
|
|
1124
|
+
placement: opts.placement,
|
|
1237
1125
|
};
|
|
1238
1126
|
}
|
|
1239
1127
|
}
|
|
1240
1128
|
}
|
|
1241
|
-
function getStartPositions({ targetHeight, targetWidth, nodeHeight, nodeWidth, targetLeftPosition, targetTopPosition, stepX, stepY, }) {
|
|
1242
|
-
const childBottomCenter = targetWidth ? targetLeftPosition + targetWidth / 2 : targetLeftPosition;
|
|
1243
|
-
const childBottom = targetHeight ? targetTopPosition + targetHeight : targetTopPosition;
|
|
1244
|
-
const childRightCenter = targetHeight ? targetTopPosition + targetHeight / 2 : targetTopPosition;
|
|
1245
|
-
const x = {
|
|
1246
|
-
bottomCenter: childBottomCenter - nodeWidth / 2 + stepX,
|
|
1247
|
-
bottomRight: targetLeftPosition + targetWidth + stepX - nodeWidth,
|
|
1248
|
-
bottomLeft: targetLeftPosition + stepX,
|
|
1249
|
-
left: targetLeftPosition - nodeWidth - stepX,
|
|
1250
|
-
right: targetLeftPosition + targetWidth + stepX,
|
|
1251
|
-
};
|
|
1252
|
-
const y = {
|
|
1253
|
-
bottom: childBottom + stepY,
|
|
1254
|
-
top: targetTopPosition - stepY - nodeHeight,
|
|
1255
|
-
rightCenter: childRightCenter - nodeHeight / 2 + stepY,
|
|
1256
|
-
rightBottom: targetTopPosition + targetHeight - nodeHeight + stepY,
|
|
1257
|
-
rightTop: targetTopPosition + stepY,
|
|
1258
|
-
};
|
|
1259
|
-
return { x, y };
|
|
1260
|
-
}
|
|
1261
1129
|
function getFlexVisiblePosition({ initialLeft, initialTop, isCompletelyVisibleX, isCompletelyVisibleY, nodeHeight, nodeWidth, xEnd, yEnd, }) {
|
|
1262
1130
|
if (!isCompletelyVisibleY(initialTop)) {
|
|
1263
1131
|
initialTop = yEnd - nodeHeight;
|
|
@@ -1268,8 +1136,6 @@ function getFlexVisiblePosition({ initialLeft, initialTop, isCompletelyVisibleX,
|
|
|
1268
1136
|
return {
|
|
1269
1137
|
top: initialTop,
|
|
1270
1138
|
left: initialLeft,
|
|
1271
|
-
bottom: yEnd - initialTop - nodeHeight,
|
|
1272
|
-
right: xEnd - initialLeft - nodeWidth,
|
|
1273
1139
|
placement: "flex",
|
|
1274
1140
|
};
|
|
1275
1141
|
}
|
|
@@ -1716,6 +1582,27 @@ function createRequestClientInstance(options) {
|
|
|
1716
1582
|
throw new Error("hasn't response");
|
|
1717
1583
|
}
|
|
1718
1584
|
if (!response.ok) {
|
|
1585
|
+
if (response.status === 304) {
|
|
1586
|
+
return responseWithStatus
|
|
1587
|
+
? {
|
|
1588
|
+
data: undefined,
|
|
1589
|
+
status: response.status,
|
|
1590
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
1591
|
+
}
|
|
1592
|
+
: undefined;
|
|
1593
|
+
}
|
|
1594
|
+
if (request.defaultResponse) {
|
|
1595
|
+
const defaultResponse = typeof request.defaultResponse === "function"
|
|
1596
|
+
? request.defaultResponse()
|
|
1597
|
+
: request.defaultResponse;
|
|
1598
|
+
return responseWithStatus
|
|
1599
|
+
? {
|
|
1600
|
+
data: defaultResponse,
|
|
1601
|
+
status: response.status,
|
|
1602
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
1603
|
+
}
|
|
1604
|
+
: defaultResponse;
|
|
1605
|
+
}
|
|
1719
1606
|
let result;
|
|
1720
1607
|
try {
|
|
1721
1608
|
const contentType = response.headers.get("content-type");
|
|
@@ -1760,14 +1647,6 @@ function createRequestClientInstance(options) {
|
|
|
1760
1647
|
}
|
|
1761
1648
|
: data;
|
|
1762
1649
|
}
|
|
1763
|
-
if (request.withoutResponse)
|
|
1764
|
-
return responseWithStatus
|
|
1765
|
-
? {
|
|
1766
|
-
data: true,
|
|
1767
|
-
status: response.status,
|
|
1768
|
-
headers: Object.fromEntries(response.headers.entries()),
|
|
1769
|
-
}
|
|
1770
|
-
: true;
|
|
1771
1650
|
const contentType = response.headers.get("content-type");
|
|
1772
1651
|
let result;
|
|
1773
1652
|
if (contentType?.includes?.("text")) {
|