child expands container v1

by ShaCP

HTML

<div id="container">
  <div class="one">
  <span>Hello</span>
  </div>
  </div>

CSS

.one {
  width: 100px;
  height: 100px;
  background-color: lightskyblue;
  position: absolute;
  animation: 3s linear forwards;
  /* margin-top: 100px; */
  writing-mode: vertical-lr;
  text-orientation: upright;
  letter-spacing: -1px;
  user-select: none;
  /* transform-origin: center; */
}

body {
  margin: 0;
  width: 100vw;
  height: 100vh;
}

#container {
  border: 1px solid;
  width: max-content;
  position: relative;
  width: 100px;
  height: 100px;
top: 25%;
  left: 50%;
}

JavaScript

const elements = [...document.getElementsByClassName("one")];

elements.forEach((one) => {
const originalCoordinates = getCoords(one);
const containerWidth = getComputedStyle(container).width;
const containerHeight = getComputedStyle(container).height;
let currentCoordinates = originalCoordinates;


//Where inside the element did the click happen?
let innerOffset = {
  x: 0,
  y: 0
};

const moveElement = evt => {
  const {
    pageX,
    pageY
  } = evt;

  const XCoordinate = pageX - originalCoordinates.left - innerOffset.x;
  const YCoordinate = pageY - originalCoordinates.top - innerOffset.y;
  const anim = one.animate({
    /*     width: `${Math.abs(XCoordinate)}px`,
        height: `${Math.abs(YCoordinate)}px`, */
    transform: `translate(${XCoordinate > 0 ? XCoordinate : 0}px, ${YCoordinate > 0 ? YCoordinate : 0}px`,
  }, {
    duration: 0,
    fill: 'forwards',
    easing: "linear"
  });

  anim.commitStyles();
  
    currentCoordinates = {
    top: originalCoordinates.top + YCoordinate,
    right: originalCoordinates.right + XCoordinate,
    bottom: originalCoordinates.bottom + YCoordinate,
    left: originalCoordinates.left + XCoordinate
  }
  
  const anim2 = container.animate({
    /*     width: `${Math.abs(XCoordinate)}px`,
        height: `${Math.abs(YCoordinate)}px`, */
    width: `${parseInt(containerWidth) + Math.abs(XCoordinate)}px`,
    height: `${parseInt(containerHeight) + Math.abs(YCoordinate)}px`,
    transform: `translate(${XCoordinate < 0 ? XCoordinate : 0}px, ${YCoordinate < 0 ? YCoordinate : 0}px`,
    backgroundColor: "red"
  }, {
    duration: 0,
    fill: 'forwards',
    easing: "linear"
  });
  
  anim2.commitStyles();
}

const moveElementSetup = evt => {
  const {
    pageX,
    pageY
  } = evt;
  innerOffset.x = pageX - currentCoordinates.left;
  innerOffset.y = pageY - currentCoordinates.top;
  document.body.addEventListener('mousemove', moveElement);
}

const removeMoveEventHandler = evt => {
 ...