index.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import type { TLOffset } from '@tldraw/core'
  2. export * from './types'
  3. export * from './lib'
  4. export * from './hooks'
  5. export * from './components/HTMLContainer'
  6. export * from './components/SVGContainer'
  7. export * from './components/App'
  8. export * from './components/AppProvider'
  9. export * from './components/AppCanvas'
  10. export { useMinimapEvents } from './hooks/useMinimapEvents'
  11. export function getContextBarTranslation(barSize: number[], offset: TLOffset) {
  12. let x = 0
  13. let y = 0
  14. if (offset.top < 116) {
  15. // Show on bottom
  16. y = offset.height / 2 + 72
  17. // Too far down, move up
  18. if (offset.bottom < 140) {
  19. y += offset.bottom - 140
  20. }
  21. } else {
  22. // Show on top
  23. y = -(offset.height / 2 + 40)
  24. }
  25. // Too far right, move left
  26. if (offset.left + offset.width / 2 - barSize[0] / 2 < 16) {
  27. x += -(offset.left + offset.width / 2 - barSize[0] / 2 - 16)
  28. } else if (offset.right + offset.width / 2 - barSize[0] / 2 < 16) {
  29. x += offset.right + offset.width / 2 - barSize[0] / 2 - 16
  30. }
  31. return [x, y]
  32. }