|
@@ -1,3 +1,4 @@
|
|
|
+import Vec from '@tldraw/vec'
|
|
|
import type { TLApp, TLPage, TLShapeModel, TLShape } from '~lib'
|
|
|
import type { TLEventMap } from '~types'
|
|
|
import { BoundsUtils } from '~utils'
|
|
@@ -132,6 +133,19 @@ export class TLApi<S extends TLShape = TLShape, K extends TLEventMap = TLEventMa
|
|
|
return this
|
|
|
}
|
|
|
|
|
|
+ cameraToCenter = (): this => {
|
|
|
+ const { shapes } = this.app.currentPage
|
|
|
+ // Viewport should be focused to existing shapes
|
|
|
+ const commonBounds = BoundsUtils.getCommonBounds(shapes.map(shape => shape.bounds))
|
|
|
+ this.app.viewport.update({
|
|
|
+ point: Vec.add(Vec.neg(BoundsUtils.getBoundsCenter(commonBounds)), [
|
|
|
+ this.app.viewport.currentView.width / 2,
|
|
|
+ this.app.viewport.currentView.height/ 2,
|
|
|
+ ]),
|
|
|
+ })
|
|
|
+ return this
|
|
|
+ }
|
|
|
+
|
|
|
/** Zoom to fit the current selection in the viewport. */
|
|
|
zoomToSelection = (): this => {
|
|
|
const { selectionBounds } = this.app
|