ef-resizable-box

Self-contained resizable and draggable bounding box.

An absolutely-positioned box with resize handles on all eight corners and edges, and a draggable body. Unlike ef-transform-handles, ef-resizable-box owns its own bounds state and constrains movement to its offsetParent. Place content inside via the default slot.

<div class="rb-scene">
  <ef-resizable-box class="rb-box">
    <div class="rb-content">Drag me</div>
  </ef-resizable-box>
</div>

<style>
  .rb-scene {
    position: relative;
    width: 100%;
    height: 220px;
    background: #0f172a;
    overflow: hidden;
  }
  .rb-box {
    --ef-resizable-box-border-color: rgba(255,255,255,0.4);
    --ef-resizable-box-handle-color: white;
  }
  .rb-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: rgba(255,255,255,0.6);
    cursor: move;
    user-select: none;
  }
</style>

bounds-change fires on every pointer move during drag or resize:

document.querySelector('ef-resizable-box').addEventListener('bounds-change', (e) => {
  const { x, y, w, h } = e.detail.bounds;
});

CSS custom properties:

PropertyDescription
--ef-resizable-box-border-colorBox outline color
--ef-resizable-box-bg-colorBox background
--ef-resizable-box-handle-colorResize handle color
--ef-resizable-box-dragging-border-colorOutline color while dragging