2222 <div v-html =" safeSvgHtml" ></div >
2323
2424 <!-- Selection Outline -->
25- <!-- < div
25+ <div
2626 v-if =" selectionBox"
27+ ref =" selectionBoxElement"
2728 class =" selection-outline"
2829 :style =" selectionStyle"
2930 data-test =" selection-outline"
3031 @mousedown.stop =" onSelectionMouseDown"
31- /> -->
32+ />
3233
3334 <!-- Rubber Band -->
3435 <!-- <div
@@ -105,14 +106,8 @@ const canvasBackground = ref(null)
105106const svgContainer = ref (null )
106107
107108// Canvas dimensions and zoom
108- const canvasWidth = computed (() => {
109- console .log (' Canvas width computed:' , store .canvasWidth )
110- return store .canvasWidth
111- })
112- const canvasHeight = computed (() => {
113- console .log (' Canvas height computed:' , store .canvasHeight )
114- return store .canvasHeight
115- })
109+ const canvasWidth = computed (() => store .canvasWidth )
110+ const canvasHeight = computed (() => store .canvasHeight )
116111
117112// Pan and zoom state
118113const panX = ref (0 )
@@ -132,8 +127,8 @@ const scrollY = ref(0)
132127
133128// Computed styles
134129const canvasWrapperStyle = computed (() => ({
135- width: ` ${ canvasWidth .value * props .zoom } px` ,
136- height: ` ${ canvasHeight .value * props .zoom } px` ,
130+ width: ` ${ canvasWidth .value * props .zoom } px` ,
131+ height: ` ${ canvasHeight .value * props .zoom } px` ,
137132 position: ' absolute' ,
138133 top: ' 50%' ,
139134 left: ' 50%' ,
@@ -143,8 +138,8 @@ const canvasWrapperStyle = computed(() => ({
143138}))
144139
145140const canvasBackgroundStyle = computed (() => ({
146- width: ` ${ canvasWidth .value * props .zoom } px` ,
147- height: ` ${ canvasHeight .value * props .zoom } px` ,
141+ width: ` ${ canvasWidth .value * props .zoom } px` ,
142+ height: ` ${ canvasHeight .value * props .zoom } px` ,
148143 position: ' relative' ,
149144 background: ' #f8f9fa' ,
150145 // border: '10px solid #e0e0e0',
@@ -180,27 +175,25 @@ const svgContainerStyle = computed(() => ({
180175 zIndex: 2 ,
181176}))
182177
183- // Commented out for simple canvas - no selection functionality
184- // const selectionBox = computed(() => {
185- // if (!store.selectedId) return null
186- // const rect = store.getRectById(store.selectedId)
187- // return rect
188- // })
189-
190- // Commented out for simple canvas
191- // const selectionStyle = computed(() => {
192- // if (!selectionBox.value) return {}
193- // const { x, y, width, height } = selectionBox.value
194- // return {
195- // position: 'absolute',
196- // left: `${x * props.zoom}px`,
197- // top: `${y * props.zoom}px`,
198- // width: `${width * props.zoom}px`,
199- // height: `${height * props.zoom}px`,
200- // pointerEvents: 'auto',
201- // zIndex: 3,
202- // }
203- // })
178+ // Selection box computation
179+ const selectionBox = computed (() => (store .selectedId ? store .getBBoxById (store .selectedId ) : null ))
180+ const selectionBoxElement = ref (null )
181+
182+ // Selection style computation
183+ const selectionStyle = computed (() => {
184+ if (! selectionBox .value ) return {}
185+ const { x , y , width , height } = selectionBox .value
186+
187+ return {
188+ position: ' absolute' ,
189+ left: ` ${ x * props .zoom } px` ,
190+ top: ` ${ y * props .zoom } px` ,
191+ width: ` ${ width * props .zoom } px` ,
192+ height: ` ${ height * props .zoom } px` ,
193+ pointerEvents: ' auto' ,
194+ zIndex: 3 ,
195+ }
196+ })
204197
205198// Commented out for simple canvas
206199// const rubberBand = computed(() => {
@@ -230,22 +223,16 @@ const svgContainerStyle = computed(() => ({
230223
231224// Zoom functions are now handled by parent component
232225
233- function updateCanvasSize () {
234- // Update SVG viewBox to match canvas dimensions
235- // store.updateSvgViewBox()
236- console .log (' updateCanvasSize' )
237- }
238-
239- // Coordinate conversion - commented out for simple canvas
240- // function toLocalCoords(evt) {
241- // const svgEl = svgContainer.value
242- // if (!svgEl) return { x: 0, y: 0 }
226+ // Coordinate conversion
227+ function toLocalCoords (evt ) {
228+ const svgEl = svgContainer .value
229+ if (! svgEl) return { x: 0 , y: 0 }
243230
244- // const rect = svgEl.getBoundingClientRect()
245- // const x = (evt.clientX - rect.left) / props.zoom
246- // const y = (evt.clientY - rect.top) / props.zoom
247- // return { x, y }
248- // }
231+ const rect = svgEl .getBoundingClientRect ()
232+ const x = (evt .clientX - rect .left ) / props .zoom
233+ const y = (evt .clientY - rect .top ) / props .zoom
234+ return { x, y }
235+ }
249236
250237// Event handlers
251238function onScroll () {
@@ -366,20 +353,22 @@ function onKeyUp(evt) {
366353 }
367354}
368355
369- function onClick () {
370- // Commented out for simple canvas - no selection functionality
371- // if (store.activeTool !== 'select') return
372- // const p = toLocalCoords(evt)
373- // store.setSelectionByPoint(p.x, p.y)
356+ function onClick (evt ) {
357+ const p = toLocalCoords (evt)
358+ const selectedId = store .setSelectionByPoint (p .x , p .y )
359+
360+ console .info (' Canvas clicked, active tool:' , store .activeTool , p)
361+ if (selectedId) {
362+ console .info (' Selection result:' , selectedId)
363+ }
364+
365+ if (store .activeTool !== ' select' ) return
374366}
375367
376- // Commented out for simple canvas - no selection functionality
377- // function onSelectionMouseDown(evt) {
378- // if (store.activeTool !== 'select' || !selectionBox.value) return
379- // const p = toLocalCoords(evt)
380- // dragOffset.value = { dx: p.x - selectionBox.value.x, dy: p.y - selectionBox.value.y }
381- // draggingSelection.value = true
382- // }
368+ function onSelectionMouseDown (evt ) {
369+ // Prevent the click from propagating to the canvas behind the selection
370+ evt .stopPropagation ()
371+ }
383372
384373// Watch for canvas dimension changes and reset pan position
385374watch ([canvasWidth, canvasHeight], () => {
@@ -395,12 +384,6 @@ let resizeObserver = null
395384
396385// Initialize canvas
397386onMounted (() => {
398- updateCanvasSize ()
399-
400- // if(store.json) {
401- // console.log('Initial JSON:', store.json)
402- // }
403-
404387 // Set up resize observer
405388 if (scrollContainer .value ) {
406389 resizeObserver = new ResizeObserver (() => {
0 commit comments