Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
calculate-position
Advanced tools
Calculate the optimum position for an element relative to another.
Calculates the best position (left/top coords) for a given anchor and dimensions.
Mostly useful for placing popups and tooltips correctly in the viewports.
Behind the scenes we calculate all the position positions for the popup element (TopLeft, TopRight etc) and then choose the one that has the largest overlap with the viewport (normal the window).
Calculates the best direction (e.g. BottomLeft) for a given anchor and dimensions.
Valid directions are:
TopLeft
TopRight
TopCenter
BottomLeft
BottomRight
BottomCenter
BottomRight
is the default direction.
Valid arguments:
@param anchor - anchor position that calculations will be based of
@param dimensions - width/height dimensions of popup element
@param viewport - (optional) viewport rectangle (defaults to window)
Example:
import {calculateBestDirection} from 'calculate-position'
const anchor = popupAnchorElement.getBoundingClientRect()
const dimensions = {width: popupWidth, height: popupHeight}
console.log(calculateBestDirection({anchor, dimensions}))
// => Direction.TopLeft
Returns coordinates (i.e. top
and left
) for a given anchor and dimensions.
Valid arguments:
@param anchor - anchor position that calculations will be based of. Typically an element being hovered over.
@param dimensions - width/height dimensions of popup element
@param viewport - optional viewport rectangle (defaults to window)
Example:
import {calculateBestPosition} from 'calculate-position'
const anchor = anchorElement.getBoundingClientRect()
const dimensions = {width: popupWidth, height: popupHeight}
console.log(calculateBestPosition({anchor, dimensions}))
// => {left: 200, top: 100}
FAQs
Calculate the optimum position for an element relative to another.
The npm package calculate-position receives a total of 67 weekly downloads. As such, calculate-position popularity was classified as not popular.
We found that calculate-position demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.