get-window-offset
Advanced tools
Comparing version 0.9.2 to 0.10.0
"use strict"; | ||
var _interopRequireWildcard = require("reshow-runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("reshow-runtime/helpers/interopRequireDefault"); | ||
@@ -7,3 +8,3 @@ exports.__esModule = true; | ||
var _objectSpread2 = _interopRequireDefault(require("reshow-runtime/helpers/objectSpread2")); | ||
var _getScrollInfo = _interopRequireDefault(require("get-scroll-info")); | ||
var _getScrollInfo = _interopRequireWildcard(require("get-scroll-info")); | ||
var _isOnScreen = _interopRequireDefault(require("./isOnScreen.js")); | ||
@@ -48,8 +49,27 @@ var _getDomPositionInfo2 = _interopRequireDefault(require("./getDomPositionInfo.js")); | ||
/** | ||
* @param {HTMLElement} overflowNode | ||
* @param {ScrollInfoType} overflowScrollInfo | ||
* @returns {ScrollInfoType=} | ||
*/ | ||
var getVisibleArea = function getVisibleArea(overflowNode, overflowScrollInfo) { | ||
if (!overflowNode.parentNode) { | ||
return; | ||
} | ||
var root = /**@type HTMLElement*/overflowNode.parentNode; | ||
var rect = overflowNode.getBoundingClientRect(); | ||
var viewportWidth = root.offsetWidth; | ||
var viewportHeight = root.offsetHeight; | ||
var visibleWidth = Math.min(rect.right - rect.left, viewportWidth); | ||
var visibleHeight = Math.min(rect.bottom - rect.top, viewportHeight); | ||
overflowScrollInfo.right = overflowScrollInfo.left + visibleWidth; | ||
overflowScrollInfo.bottom = overflowScrollInfo.top + visibleHeight; | ||
return overflowScrollInfo; | ||
}; | ||
/** | ||
* @param {DomInfoType} domInfo | ||
* @param {import("get-scroll-info").ScrollInfoType} scrollInfo | ||
* @returns {CalWindowOffsetResult} | ||
* @returns {SimplePosType} | ||
*/ | ||
var calWindowOffset = function calWindowOffset(domInfo, scrollInfo) { | ||
var _distanceFlip; | ||
var calDistance = function calDistance(domInfo, scrollInfo) { | ||
var distance = { | ||
@@ -61,2 +81,11 @@ top: domInfo.top - scrollInfo.top, | ||
}; | ||
return distance; | ||
}; | ||
/** | ||
* @param {SimplePosType} distance | ||
* @returns {CalWindowOffsetResult} | ||
*/ | ||
var calWindowOffset = function calWindowOffset(distance) { | ||
var _distanceFlip; | ||
var maxDistance = Math.max(distance.top, distance.right, distance.bottom, distance.left); | ||
@@ -107,18 +136,29 @@ var distanceFlip = (_distanceFlip = {}, _distanceFlip[distance.top] = T, _distanceFlip[distance.right] = R, _distanceFlip[distance.bottom] = B, _distanceFlip[distance.left] = L, _distanceFlip); | ||
cookScrollInfo.left = fixedScrollInfo.left; | ||
} else if (overflowNode) { | ||
var overflowNodeScrollInfo = (0, _getScrollInfo["default"])(overflowNode); | ||
cookScrollInfo.top += overflowNodeScrollInfo.top; | ||
/** | ||
* @type number | ||
*/ | ||
cookScrollInfo.right += overflowNodeScrollInfo.left; | ||
/** | ||
* @type number | ||
*/ | ||
cookScrollInfo.bottom += overflowNodeScrollInfo.top; | ||
cookScrollInfo.left += overflowNodeScrollInfo.left; | ||
} | ||
var domInfoWithScreen = (0, _isOnScreen["default"])(domInfo, cookScrollInfo, margin); | ||
var domOverflowInfoWithScreen = (0, _isOnScreen["default"])(domOverflowInfo, (0, _getScrollInfo["default"])(domOverflowInfo.domScroller), margin); | ||
domInfoWithScreen.isOnScreen = domInfoWithScreen.isOnScreen && domOverflowInfoWithScreen.isOnScreen; | ||
var distance = calDistance(domInfo, cookScrollInfo); | ||
/** | ||
* @type WindowOffsetType | ||
*/ | ||
var result = (0, _objectSpread2["default"])({ | ||
domInfo: domInfoWithScreen, | ||
domOverflowInfo: null, | ||
scrollInfo: scrollInfo | ||
}, calWindowOffset(distance)); | ||
var domOverflowInfoWithScreen; | ||
if (overflowNode) { | ||
var domOverflowScrollInfo = (0, _getScrollInfo["default"])(domOverflowInfo.domScroller); | ||
domOverflowInfoWithScreen = (0, _isOnScreen["default"])(domOverflowInfo, domOverflowScrollInfo, margin); | ||
domInfoWithScreen.isOnScreen = domInfoWithScreen.isOnScreen && domOverflowInfoWithScreen.isOnScreen; | ||
var overflowDistance = calDistance(domOverflowInfo, getVisibleArea(overflowNode, domOverflowScrollInfo) || domOverflowScrollInfo); | ||
distance.top += overflowDistance.top; | ||
distance.right += overflowDistance.right; | ||
distance.bottom += overflowDistance.bottom; | ||
distance.left += overflowDistance.left; | ||
var overflowNodeWindowOffset = calWindowOffset(overflowDistance); | ||
result.domOverflowInfo = domOverflowInfoWithScreen; | ||
result.locs = overflowNodeWindowOffset.locs; | ||
result.firstKey = overflowNodeWindowOffset.firstKey; | ||
result.secondKey = overflowNodeWindowOffset.secondKey; | ||
} | ||
if (!domInfoWithScreen.isOnScreen && false !== debug || true === debug) { | ||
@@ -131,10 +171,11 @@ // should not break function here | ||
scrollInfo: scrollInfo, | ||
cookScrollInfo: cookScrollInfo | ||
cookScrollInfo: cookScrollInfo, | ||
overflowNode: overflowNode, | ||
domOverflowInfo: domOverflowInfo, | ||
domInfoWithScreen: domInfoWithScreen, | ||
domOverflowInfoWithScreen: domOverflowInfoWithScreen, | ||
result: result, | ||
distance: distance | ||
}); | ||
} | ||
var result = (0, _objectSpread2["default"])({ | ||
domInfo: domInfoWithScreen, | ||
domOverflowInfo: domOverflowInfoWithScreen, | ||
scrollInfo: scrollInfo | ||
}, calWindowOffset(domInfo, cookScrollInfo)); | ||
return result; | ||
@@ -141,0 +182,0 @@ }; |
@@ -28,3 +28,5 @@ "use strict"; | ||
atLeft: domInfo.right <= scrollInfo.left + margin, | ||
isOnScreen: false | ||
isOnScreen: false, | ||
scrollInfo: scrollInfo, | ||
margin: margin | ||
}); | ||
@@ -31,0 +33,0 @@ nextDomInfo.isOnScreen = !(nextDomInfo.atTop || nextDomInfo.atRight || nextDomInfo.atBottom || nextDomInfo.atLeft); |
@@ -7,6 +7,7 @@ "use strict"; | ||
var _getStyle = _interopRequireDefault(require("get-style")); | ||
var _getScrollInfo = _interopRequireDefault(require("get-scroll-info")); | ||
// @ts-check | ||
/** | ||
* @typedef {import("./type").MaybeHTMLElement} MaybeHTMLElement | ||
* @typedef {import("./type").MaybeHTMLElement} MaybeHTMLElement | ||
*/ | ||
@@ -23,6 +24,9 @@ | ||
} | ||
if (!node.parentNode) { | ||
return false; | ||
} | ||
/** | ||
* @type any | ||
*/ | ||
var thisParent = node; | ||
var thisParent = node.parentNode; | ||
while (thisParent.nodeName != "BODY") { | ||
@@ -32,3 +36,6 @@ var overflowX = (0, _getStyle["default"])(thisParent, "overflow-x"); | ||
if ("visible" !== overflowY || "visible" !== overflowX) { | ||
return thisParent; | ||
var oScroll = (0, _getScrollInfo["default"])(thisParent); | ||
if (oScroll.top || oScroll.left) { | ||
return thisParent; | ||
} | ||
} | ||
@@ -35,0 +42,0 @@ thisParent = thisParent.parentNode; |
@@ -134,7 +134,8 @@ "use strict"; | ||
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "atLeft", void 0); | ||
/** | ||
* @type number | ||
*/ | ||
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "margin", void 0); | ||
return _this2; | ||
} | ||
/** | ||
* @type boolean | ||
*/ | ||
return (0, _createClass2["default"])(IsOnScreenType); | ||
@@ -187,3 +188,3 @@ }(DomInfoType); | ||
/** | ||
* @type IsOnScreenType | ||
* @type {?IsOnScreenType} | ||
*/ | ||
@@ -190,0 +191,0 @@ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this3), "domOverflowInfo", void 0); |
{ | ||
"version": "0.9.2", | ||
"version": "0.10.0", | ||
"name": "get-window-offset", | ||
@@ -4,0 +4,0 @@ "repository": { |
@@ -96,2 +96,6 @@ /** | ||
atLeft: boolean; | ||
/** | ||
* @type number | ||
*/ | ||
margin: number; | ||
} | ||
@@ -132,5 +136,5 @@ export class DomPositionInfoType { | ||
/** | ||
* @type IsOnScreenType | ||
* @type {?IsOnScreenType} | ||
*/ | ||
domOverflowInfo: IsOnScreenType; | ||
domOverflowInfo: IsOnScreenType | null; | ||
/** | ||
@@ -137,0 +141,0 @@ * @type IsOnScreenType |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73033
2321