
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
rectpackr-layout
Advanced tools
A web component that creates layouts by packing HTML elements as rectangles using a best-fit 2D strip-packing algorithm. Automatically measures dimensions and handles mixed content.
A web component that creates layouts by treating your HTML elements as rectangles and packing them using a best-fit 2D strip-packing algorithm.
Web browsers naturally manage elements as rectangles. rectpackr-layout leverages this by applying a best-fit strip-packing algorithm — the same approach used in industrial optimization problems — to web layout creation.
The algorithm intelligently works with whatever dimensional information is available:
npm install rectpackr-layout
yarn add rectpackr-layout
pnpm install rectpackr-layout
Then import it in your JavaScript:
// In your main.js or component file
import 'rectpackr-layout';
Or directly in your HTML:
<script type="module">
import 'rectpackr-layout';
</script>
Include it directly in your HTML via CDN:
<script type="module" src="https://unpkg.com/rectpackr-layout"></script>
<script
type="module"
src="https://cdn.jsdelivr.net/npm/rectpackr-layout"
></script>
<script type="module" src="https://esm.sh/rectpackr-layout"></script>
<rectpackr-layout>
<div>Your content here</div>
</rectpackr-layout>
positioning
Defines the CSS method used to position items.
transform (Default): Uses transform: translate(x, y)offset: Uses CSS inset property for precise positioning💡 Performance Note: The default
transformvalue typically offers better performance through hardware acceleration. Useoffsetonly when child elements already usetransformfor other purposes (animation etc.).
x-direction
Controls the horizontal packing direction.
ltr (Default): Left-to-right packingrtl: Right-to-left packingy-direction
Controls the vertical packing direction.
ttb (Default): Top-to-bottom packingbtt: Bottom-to-top packingThe x-direction and y-direction attributes control visual placement, which may create a difference between the visual arrangement and the underlying DOM order.
<rectpackr-layout>
<div>Card 1</div>
<div>Card 2</div>
<div>Card 3</div>
</rectpackr-layout>
<style>
rectpackr-layout {
container-type: inline-size;
display: block;
}
rectpackr-layout > * {
/* Fluid width based on container queries */
width: 100%;
}
@container (min-width: 400px) {
rectpackr-layout > * {
width: 50%;
}
}
@container (min-width: 800px) {
rectpackr-layout > * {
width: 33.33%;
}
}
</style>
<rectpackr-layout id="dynamic-layout">
<!-- Content can be added/removed dynamically -->
</rectpackr-layout>
<script>
// The layout automatically adjusts to content changes
document.getElementById('dynamic-layout').appendChild(newElement);
</script>
See predictable masonry-style layouts with equal-width elements
Explore optimal packing of variably-sized elements and aspect ratios
Experiment with real-time controls and dynamic content manipulation
Modern browsers with Web Components support.
If you encounter any issues or have questions, please open an issue.
This project is licensed under the MIT License.
FAQs
A web component that creates layouts by packing HTML elements as rectangles using a best-fit 2D strip-packing algorithm. Automatically measures dimensions and handles mixed content.
The npm package rectpackr-layout receives a total of 3 weekly downloads. As such, rectpackr-layout popularity was classified as not popular.
We found that rectpackr-layout demonstrated a healthy version release cadence and project activity because the last version was released less than 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
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.