You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

useCameraCss.tsx 889B

1234567891011121314151617181920212223242526272829303132333435
  1. /* eslint-disable @typescript-eslint/no-non-null-assertion */
  2. import * as React from 'react'
  3. import type { TLPageState } from '+types'
  4. export function useCameraCss(
  5. layerRef: React.RefObject<HTMLDivElement>,
  6. containerRef: React.RefObject<HTMLDivElement>,
  7. pageState: TLPageState
  8. ) {
  9. // Update the tl-zoom CSS variable when the zoom changes
  10. const rZoom = React.useRef(pageState.camera.zoom)
  11. React.useLayoutEffect(() => {
  12. const {
  13. zoom,
  14. point: [x, y],
  15. } = pageState.camera
  16. if (zoom !== rZoom.current) {
  17. rZoom.current = zoom
  18. const container = containerRef.current
  19. if (container) {
  20. container.style.setProperty('--tl-zoom', zoom.toString())
  21. }
  22. }
  23. const layer = layerRef.current
  24. if (layer) {
  25. layer.style.setProperty('transform', `scale(${zoom}) translate(${x}px, ${y}px)`)
  26. }
  27. }, [pageState.camera])
  28. }