@@ -71,8 +71,28 @@ async function cloneAsset(center){
71
71
return { is_svg, svg_img}
72
72
}
73
73
74
+ function window_url_add_pan ( x , y ) {
75
+ // Convert to integers to remove fractions and ensure the format "&pan=x33_y48"
76
+ const intX = Math . floor ( x ) ;
77
+ const intY = Math . floor ( y ) ;
78
+ console . log ( `Pan finished at (${ intX } ,${ intY } )` ) ;
79
+
80
+ const currentUrl = new URL ( window . location . href ) ;
81
+ currentUrl . searchParams . set ( 'pan' , `x${ intX } _y${ intY } ` ) ;
82
+ window . history . pushState ( { } , "" , currentUrl . toString ( ) ) ;
83
+ }
84
+
85
+ function window_url_add_zoom ( zoom ) {
86
+ // Round to two decimal places to ensure the format "&zoom=1.27"
87
+ const roundedZoom = Math . round ( zoom * 100 ) / 100 ;
88
+ console . log ( `Zoom done at (${ roundedZoom } )` ) ;
89
+
90
+ const currentUrl = new URL ( window . location . href ) ;
91
+ currentUrl . searchParams . set ( 'zoom' , roundedZoom . toString ( ) ) ;
92
+ window . history . pushState ( { } , "" , currentUrl . toString ( ) ) ;
93
+ }
74
94
function window_url_add_modal ( center ) {
75
- const container = center . parentElement . parentElement . parentElement . parentElement
95
+ const container = center . parentElement . parentElement . parentElement . parentElement
76
96
let modal_name
77
97
const data_name = container . getAttribute ( "data-name" )
78
98
if ( data_name != "diagram.svg" ) {
@@ -100,12 +120,41 @@ function is_url_modal(center){
100
120
101
121
async function handle_url_modal ( modal , is_svg , svg , pzref ) {
102
122
const params = new URL ( location . href ) . searchParams ;
123
+
124
+ // Handling text focus if applicable
103
125
const text = params . get ( 'text' )
104
126
if ( text ) {
105
127
if ( is_svg ) {
106
128
await svg_text_focus ( modal , svg , text , pzref )
107
129
}
108
130
}
131
+
132
+ // Handling pan parameter
133
+ const pan = params . get ( 'pan' ) ;
134
+ if ( pan ) {
135
+ const matches = pan . match ( / x ( - ? \d + ) _ y ( - ? \d + ) / i) ; // Adjusted regex to include negative numbers
136
+ console . log ( matches )
137
+ if ( matches ) {
138
+ const x = parseInt ( matches [ 1 ] , 10 ) ;
139
+ const y = parseInt ( matches [ 2 ] , 10 ) ;
140
+ setTimeout ( ( ) => { pzref . smoothMoveTo ( x , y ) } , 400 )
141
+ console . log ( `Moving to x: ${ x } , y: ${ y } ` ) ;
142
+ }
143
+ }
144
+
145
+ // Handling zoom parameter
146
+ const zoom = params . get ( 'zoom' ) ;
147
+ if ( zoom ) {
148
+ const scale = parseFloat ( zoom ) ;
149
+ let delay = 400
150
+ if ( pan ) {
151
+ delay = 0
152
+ }
153
+ const svg_cx = svg . getAttribute ( "width" ) . replace ( / p x $ / , '' ) / 2
154
+ const svg_cy = svg . getAttribute ( "height" ) . replace ( / p x $ / , '' ) / 2
155
+ setTimeout ( ( ) => { pzref . smoothZoom ( svg_cx , svg_cy , zoom ) } , delay )
156
+ console . log ( `Zooming to scale: ${ scale } ` ) ;
157
+ }
109
158
}
110
159
111
160
async function openModal ( event ) {
@@ -120,6 +169,13 @@ async function openModal(event){
120
169
}
121
170
const { default : panzoom } = await import ( 'panzoom' ) ;
122
171
pzref = panzoom ( svg_img , zoomOptions )
172
+ pzref . on ( 'panend' , ( ) => {
173
+ const t = pzref . getTransform ( )
174
+ window_url_add_pan ( t . x , t . y )
175
+ } ) ;
176
+ pzref . on ( 'zoom' , function ( ) {
177
+ window_url_add_zoom ( pzref . getTransform ( ) . scale )
178
+ } ) ;
123
179
124
180
close . onclick = ( ) => {
125
181
//console.log("closed click")
0 commit comments