11import React , { useRef , useState } from "react" ;
2- import { useSpring , animated } from "react-spring " ;
2+ import styled from "@emotion/styled " ;
33import { usePinch } from "@use-gesture/react" ;
44import { Resizable } from "re-resizable" ;
5+ import { ZoomControl } from "./controller-zoom-control" ;
56
67export function InteractiveCanvas ( {
78 children,
@@ -11,14 +12,43 @@ export function InteractiveCanvas({
1112 const [ scale , setScale ] = useState ( 1 ) ;
1213
1314 return (
14- < div id = "interactive-canvas" style = { { width : "100%" , height : "100%" } } >
15+ < InteractiveCanvasWrapper id = "interactive-canvas" >
1516 < ScalableFrame onRescale = { setScale } scale = { scale } >
16- < ResizableFrame scale = { scale } > { children } </ ResizableFrame >
17+ < Controls >
18+ < ZoomControl scale = { scale } onChange = { setScale } />
19+ </ Controls >
20+ < ScalingAreaStaticRoot >
21+ < ScalingArea scale = { scale } >
22+ < ResizableFrame scale = { scale } > { children } </ ResizableFrame >
23+ </ ScalingArea >
24+ </ ScalingAreaStaticRoot >
1725 </ ScalableFrame >
18- </ div >
26+ </ InteractiveCanvasWrapper >
1927 ) ;
2028}
2129
30+ const InteractiveCanvasWrapper = styled . div `
31+ display: flex;
32+ flex-direction: column;
33+ flex: 1;
34+ ` ;
35+
36+ const Controls = styled . div `
37+ z-index: 2;
38+ display: flex;
39+ flex-direction: row;
40+ justify-content: flex-end;
41+ ` ;
42+
43+ const ScalingAreaStaticRoot = styled . div `
44+ display: flex;
45+ align-items: center;
46+ justify-content: center;
47+ align-content: flex-start;
48+ align-self: stretch;
49+ flex: 1;
50+ ` ;
51+
2252function ScalableFrame ( {
2353 children,
2454 scale,
@@ -28,14 +58,15 @@ function ScalableFrame({
2858 onRescale ?: ( scale : number ) => void ;
2959 children ?: React . ReactNode ;
3060} ) {
31- // const [{ xyzs }, set] = useSpring(() => ({ xyzs: [0, 0, 0, 100] }));
3261 const ref = useRef ( ) ;
3362
3463 usePinch (
3564 ( state ) => {
65+ const prevscale = scale ;
3666 const { offset } = state ;
37- const [ scale ] = offset ;
38- onRescale ( scale ) ;
67+ const thisscale = offset [ 0 ] ;
68+ // const newscale = thisscale - prevscale;
69+ onRescale ( thisscale ) ;
3970 } ,
4071 { target : ref }
4172 ) ;
@@ -45,26 +76,36 @@ function ScalableFrame({
4576 id = "scale-event-listener"
4677 ref = { ref }
4778 style = { {
48- width : "100%" ,
49- height : "100%" ,
79+ display : "flex" ,
80+ flexDirection : "column" ,
81+ flex : 1 ,
82+ alignItems : "center" ,
83+ alignContent : "center" ,
5084 } }
5185 >
52- < div
53- style = { {
54- transform : `scale(${ scale } )` ,
55- // xyzs
56- // .to((x, y, z, s): string => {
57- // return `translate3D(${x}px, ${y}px, 0) scale(${s / 100})`;
58- // })
59- // .get(),
60- } }
61- >
62- { children }
63- </ div >
86+ { children }
6487 </ div >
6588 ) ;
6689}
6790
91+ const ScalingArea = ( {
92+ scale,
93+ children,
94+ } : {
95+ scale : number ;
96+ children : React . ReactNode ;
97+ } ) => {
98+ return (
99+ < div
100+ style = { {
101+ transform : `scale(${ scale } )` ,
102+ } }
103+ >
104+ { children }
105+ </ div >
106+ ) ;
107+ } ;
108+
68109function ResizableFrame ( {
69110 scale,
70111 children,
0 commit comments