AnimationResizer.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { UIElement } from './libs/ui.js';
  2. function AnimationResizer( editor ) {
  3. const signals = editor.signals;
  4. const dom = document.createElement( 'div' );
  5. dom.id = 'animation-resizer';
  6. let panelHeight = 36;
  7. let startY = 0;
  8. let startHeight = 0;
  9. function onPointerDown( event ) {
  10. if ( event.isPrimary === false ) return;
  11. startY = event.clientY;
  12. startHeight = panelHeight;
  13. dom.ownerDocument.addEventListener( 'pointermove', onPointerMove );
  14. dom.ownerDocument.addEventListener( 'pointerup', onPointerUp );
  15. }
  16. function onPointerUp( event ) {
  17. if ( event.isPrimary === false ) return;
  18. dom.ownerDocument.removeEventListener( 'pointermove', onPointerMove );
  19. dom.ownerDocument.removeEventListener( 'pointerup', onPointerUp );
  20. }
  21. function onPointerMove( event ) {
  22. if ( event.isPrimary === false ) return;
  23. const deltaY = startY - event.clientY;
  24. const newHeight = startHeight + deltaY;
  25. const maxHeight = window.innerHeight / 2;
  26. // Clamp between 36px (top bar only) and half the window height
  27. panelHeight = Math.max( 36, Math.min( maxHeight, newHeight ) );
  28. signals.animationPanelResized.dispatch( panelHeight );
  29. }
  30. dom.addEventListener( 'pointerdown', onPointerDown );
  31. // Show/hide based on animation panel visibility
  32. signals.animationPanelChanged.add( function ( height ) {
  33. if ( height === false ) {
  34. dom.style.display = 'none';
  35. } else {
  36. dom.style.display = 'block';
  37. dom.style.bottom = height + 'px';
  38. panelHeight = height;
  39. }
  40. } );
  41. return new UIElement( dom );
  42. }
  43. export { AnimationResizer };
粤ICP备19079148号