From 2ddd30e7bb3bbb5e9bde22da9e136d27aa29aa85 Mon Sep 17 00:00:00 2001 From: xsxx03-art <你的邮箱@example.com> Date: Fri, 5 Jun 2026 20:32:16 +0800 Subject: [PATCH] update canvas.html --- frontend/canvas.html | 61 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/frontend/canvas.html b/frontend/canvas.html index e3e3b48..9135751 100644 --- a/frontend/canvas.html +++ b/frontend/canvas.html @@ -1720,8 +1720,40 @@ Organization : OptiHK Limited bottom: Position.Bottom }; const componentSize = normalizeBoxSize({ box_size: data.boxSize }, DEFAULT_COMPONENT_BOX_SIZE); + const flippedPorts = useMemo( + () => { + const result = {}; + const ports = Object.entries(data.ports || {}).filter(([name]) => name !== 'a0' && name !== 'b0'); + if (ports.length === 0) return result; + let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity; + ports.forEach(([, info]) => { + const x = Number(info.x || 0); + const y = Number(info.y || 0); + if (x < minX) minX = x; + if (x > maxX) maxX = x; + if (y < minY) minY = y; + if (y > maxY) maxY = y; + }); + ports.forEach(([name, info]) => { + let x = Number(info.x || 0); + let y = Number(info.y || 0); + let a = Number(info.a || 0); + if (data.flip) { + y = minY + maxY - y; + a = -a; + } + if (data.flop) { + x = minX + maxX - x; + a = normalizeAngle(180 - a); + } + result[name] = { ...info, x, y, a: normalizeAngle(a) }; + }); + return result; + }, + [data.ports, data.flip, data.flop] + ); const portHandles = useMemo( - () => buildPortHandles(data.ports, { rotation: data.rotation || 0, flip: Boolean(data.flip), flop: Boolean(data.flop), boxSize: componentSize }), + () => buildPortHandles(flippedPorts, { rotation: 0, boxSize: componentSize }), [data.ports, data.rotation, data.flip, data.flop, componentSize] ); const portDirectionMap = useMemo( @@ -1731,20 +1763,22 @@ Organization : OptiHK Limited const isAnchorElement = data.elementType === 'anchor'; const isBasicCompactComponent = isBasicComponent(data.componentName) && ['waveguide', 'taper', '90 bend'].includes(data.componentName); const visualSize = isAnchorElement ? { width: PORT_NODE_SIZE, height: PORT_NODE_SIZE } : componentSize; - const componentVisualTransform = `rotate(${data.rotation || 0}deg) scaleX(${data.flop ? -1 : 1}) scaleY(${data.flip ? -1 : 1})`; + const componentVisualTransform = `rotate(${data.rotation || 0}deg)`; + const componentBodyTransform = `rotate(${data.rotation || 0}deg) scaleX(${data.flop ? -1 : 1}) scaleY(${data.flip ? -1 : 1})`; const iconSize = createComponentSymbolMetrics(componentSize); const portLabelStyle = (portHandle) => { const base = { ...portHandle.style }; + const unrotate = `rotate(${-(data.rotation || 0)}deg)`; if (portHandle.position === 'left') { - return { ...base, left: 'auto', right: 'calc(100% + 8px)', transform: 'translateY(-50%)', textAlign: 'right' }; + return { ...base, left: 'auto', right: 'calc(100% + 8px)', transform: `${unrotate} translateY(-50%)`, textAlign: 'right' }; } if (portHandle.position === 'right') { - return { ...base, left: 'calc(100% + 8px)', right: 'auto', transform: 'translateY(-50%)', textAlign: 'left' }; + return { ...base, left: 'calc(100% + 8px)', right: 'auto', transform: `${unrotate} translateY(-50%)`, textAlign: 'left' }; } if (portHandle.position === 'top') { - return { ...base, top: 'auto', bottom: 'calc(100% + 8px)', transform: 'translateX(-50%)', textAlign: 'center' }; + return { ...base, top: 'auto', bottom: 'calc(100% + 8px)', transform: `${unrotate} translateX(-50%)`, textAlign: 'center' }; } - return { ...base, top: 'calc(100% + 8px)', bottom: 'auto', transform: 'translateX(-50%)', textAlign: 'center' }; + return { ...base, top: 'calc(100% + 8px)', bottom: 'auto', transform: `${unrotate} translateX(-50%)`, textAlign: 'center' }; }; return ( @@ -1768,7 +1802,7 @@ Organization : OptiHK Limited ...(visualSize.height < 50 && !isAnchorElement ? { padding: '2px 4px' } : {}), border: selected ? '2px solid var(--accent)' : '1px solid var(--border)', boxShadow: selected ? '0 0 15px rgba(56, 189, 248, 0.2)' : '0 4px 6px rgba(0,0,0,0.3)', - transform: componentVisualTransform, + transform: componentBodyTransform, transformOrigin: 'center center', ...(isBasicCompactComponent ? { padding: 0, @@ -1806,6 +1840,8 @@ Organization : OptiHK Limited top: 0, left: 0, width: componentSize.width, height: visualSize.height, + transform: componentVisualTransform, + transformOrigin: 'center center', pointerEvents: 'none' }}> {portHandles.map((portHandle) => ( @@ -1826,15 +1862,12 @@ Organization : OptiHK Limited /> ))} - - - {portHandles.map((portHandle) => ( - - + {portHandles.map((portHandle) => ( + {portHandle.name} - - ))} + ))} + ); }, (prevProps, nextProps) => { -- 2.52.0