Resizer.js 986 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { UIElement } from './libs/ui.js';
  2. function Resizer( editor ) {
  3. const signals = editor.signals;
  4. const dom = document.createElement( 'div' );
  5. dom.id = 'resizer';
  6. let isPointerDown = false;
  7. dom.addEventListener( 'pointerdown', function ( event ) {
  8. if ( event.isPrimary ) isPointerDown = true;
  9. } );
  10. dom.ownerDocument.addEventListener( 'pointermove', function ( event ) {
  11. if ( event.isPrimary && isPointerDown ) {
  12. const rect = dom.getBoundingClientRect();
  13. const x = ( document.body.offsetWidth - rect.right ) - event.movementX;
  14. dom.style.right = x + 'px';
  15. document.getElementById( 'sidebar' ).style.width = ( x + rect.width ) + 'px';
  16. document.getElementById( 'viewport' ).style.right = ( x + rect.width ) + 'px';
  17. signals.windowResize.dispatch();
  18. }
  19. } );
  20. dom.ownerDocument.addEventListener( 'pointerup', function ( event ) {
  21. if ( event.isPrimary ) isPointerDown = false;
  22. } );
  23. return new UIElement( dom );
  24. }
  25. export { Resizer };