diff --git a/frontend/canvas-helpers.js b/frontend/canvas-helpers.js
index b10c6c1..1d200d1 100644
--- a/frontend/canvas-helpers.js
+++ b/frontend/canvas-helpers.js
@@ -27,6 +27,8 @@
const DEFAULT_COMPONENT_BOX_SIZE = { width: 132, height: 82 };
// Default editable canvas dimensions in micrometers.
const DEFAULT_CANVAS_SIZE = { width: 5000, height: 5000 };
+ // Default canvas bounds as a four-wall rectangle (xmin, xmax, ymin, ymax).
+ const DEFAULT_CANVAS_BOUNDS = { xmin: 0, xmax: 5000, ymin: 0, ymax: 5000 };
// Base visual diameter and hit area used for port and anchor handles.
const PORT_NODE_SIZE = 11;
const FREE_WIRES_BUNDLE_GROUP = 'free_wires';
@@ -314,15 +316,35 @@
height: positiveNumber(size && size.height) || DEFAULT_CANVAS_SIZE.height
});
+ // Resolve valid canvas bounds (four-wall rectangle) from saved project metadata.
+ // Accepts either legacy {width, height} or new {xmin, xmax, ymin, ymax}.
+ const normalizeCanvasBounds = (bounds) => {
+ if (!bounds) return { ...DEFAULT_CANVAS_BOUNDS };
+ // New-style four-wall rectangle.
+ if (bounds.xmin != null || bounds.xmax != null || bounds.ymin != null || bounds.ymax != null) {
+ return {
+ xmin: Number.isFinite(Number(bounds.xmin)) ? Number(bounds.xmin) : DEFAULT_CANVAS_BOUNDS.xmin,
+ xmax: Number.isFinite(Number(bounds.xmax)) ? Number(bounds.xmax) : DEFAULT_CANVAS_BOUNDS.xmax,
+ ymin: Number.isFinite(Number(bounds.ymin)) ? Number(bounds.ymin) : DEFAULT_CANVAS_BOUNDS.ymin,
+ ymax: Number.isFinite(Number(bounds.ymax)) ? Number(bounds.ymax) : DEFAULT_CANVAS_BOUNDS.ymax
+ };
+ }
+ // Legacy width/height format: treat as rectangle from (0,0).
+ const w = positiveNumber(bounds.width) || DEFAULT_CANVAS_SIZE.width;
+ const h = positiveNumber(bounds.height) || DEFAULT_CANVAS_SIZE.height;
+ return { xmin: 0, xmax: w, ymin: 0, ymax: h };
+ };
+
// Keep dragged or pasted nodes inside the active canvas bounds.
+ // Accepts either legacy {width,height} or new {xmin,xmax,ymin,ymax} canvasSize.
const clampPositionToCanvas = (position, canvasSize, boxSize) => {
- const size = normalizeCanvasSize(canvasSize);
+ const bounds = normalizeCanvasBounds(canvasSize);
const box = normalizeBoxSize({ box_size: [boxSize && boxSize.width, boxSize && boxSize.height] });
- const maxX = Math.max(0, size.width - box.width);
- const maxY = Math.max(0, size.height - box.height);
+ const maxX = Math.max(bounds.xmin, bounds.xmax - box.width);
+ const maxY = Math.max(bounds.ymin, bounds.ymax - box.height);
return {
- x: Math.min(maxX, Math.max(0, Number(position && position.x) || 0)),
- y: Math.min(maxY, Math.max(0, Number(position && position.y) || 0))
+ x: Math.min(maxX, Math.max(bounds.xmin, Number(position && position.x) || 0)),
+ y: Math.min(maxY, Math.max(bounds.ymin, Number(position && position.y) || 0))
};
};
@@ -375,8 +397,8 @@
});
if (points.length === 0) {
- const size = normalizeCanvasSize(page.canvasSize || DEFAULT_CANVAS_SIZE);
- points.push({ x: 0, y: 0 }, { x: size.width, y: size.height });
+ const bounds = normalizeCanvasBounds(page.canvasSize || page.canvasBounds);
+ points.push({ x: bounds.xmin, y: bounds.ymin }, { x: bounds.xmax, y: bounds.ymax });
}
const minX = roundBoundsValue(Math.min(...points.map(point => point.x)));
@@ -1321,6 +1343,7 @@ bundles:${groupsYaml ? `\n${groupsYaml}` : ' {}'}`;
FORGE_COMPONENT_TYPE,
DEFAULT_COMPONENT_BOX_SIZE,
DEFAULT_CANVAS_SIZE,
+ DEFAULT_CANVAS_BOUNDS,
PORT_NODE_SIZE,
DEFAULT_ELEMENT_PITCH,
ELEMENT_COMPONENTS,
@@ -1351,6 +1374,7 @@ bundles:${groupsYaml ? `\n${groupsYaml}` : ' {}'}`;
normalizeBoxSize,
chooseCategoryComponent,
normalizeCanvasSize,
+ normalizeCanvasBounds,
clampPositionToCanvas,
calculateLayoutBounds,
calculateCompositeBoxSize,
diff --git a/frontend/canvas.html b/frontend/canvas.html
index 60bc66b..367cedb 100644
--- a/frontend/canvas.html
+++ b/frontend/canvas.html
@@ -830,6 +830,98 @@ Organization : OptiHK Limited
transform: translate(-50%, -50%);
}
+ .origin-pick-panel {
+ position: absolute;
+ left: 50%;
+ bottom: 60px;
+ transform: translateX(-50%);
+ z-index: 13;
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ padding: 9px 16px;
+ border: 1px solid var(--border);
+ border-radius: 7px;
+ background: rgba(6, 34, 32, 0.95);
+ box-shadow: 0 14px 28px var(--shadow);
+ backdrop-filter: blur(14px);
+ font: 600 0.78rem/1 'IBM Plex Mono', Consolas, Monaco, monospace;
+ white-space: nowrap;
+ }
+
+ .origin-pick-panel label {
+ color: var(--text-main);
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ }
+
+ .origin-pick-panel input {
+ width: 128px;
+ padding: 6px 8px;
+ border: 1px solid rgba(45, 212, 191, 0.3);
+ border-radius: 5px;
+ background: rgba(45, 212, 191, 0.05);
+ color: var(--text-main);
+ font: inherit;
+ font-size: 0.78rem;
+ text-align: right;
+ }
+
+ .origin-pick-panel input:focus {
+ outline: none;
+ border-color: var(--accent-green);
+ box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.2);
+ }
+
+ .origin-pick-panel button {
+ padding: 6px 14px;
+ border: 1px solid var(--accent-green);
+ border-radius: 5px;
+ background: rgba(45, 212, 191, 0.1);
+ color: var(--accent-green);
+ font: inherit;
+ font-size: 0.72rem;
+ cursor: pointer;
+ transition: background 0.2s;
+ }
+
+ .origin-pick-panel .cancel-btn {
+ border-color: var(--border);
+ background: transparent;
+ color: var(--text-muted);
+ margin-left: 2px;
+ }
+
+ .origin-pick-panel button:hover {
+ background: rgba(45, 212, 191, 0.18);
+ }
+
+ .origin-pick-panel .cancel-btn:hover {
+ background: rgba(255, 255, 255, 0.06);
+ }
+
+ body.light-mode .origin-pick-panel {
+ background: rgba(235, 252, 249, 0.96);
+ border-color: rgba(30, 48, 69, 0.16);
+ box-shadow: 0 14px 28px rgba(18, 32, 51, 0.12);
+ }
+
+ body.light-mode .origin-pick-panel input {
+ border-color: rgba(13, 148, 136, 0.3);
+ background: rgba(13, 148, 136, 0.04);
+ color: #132033;
+ }
+
+ body.light-mode .origin-pick-panel input:focus {
+ border-color: #0d9488;
+ box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.18);
+ }
+
+ body.light-mode .origin-pick-panel .cancel-btn:hover {
+ background: rgba(18, 32, 51, 0.06);
+ }
+
.build-layout-btn {
position: absolute;
bottom: 20px;
@@ -1518,33 +1610,32 @@ Organization : OptiHK Limited
}
.origin-marker-node {
- width: 16px;
- height: 16px;
transform: translate(-50%, -50%);
pointer-events: none;
position: relative;
+ width: 20px;
+ height: 20px;
}
- .origin-marker-node::before,
- .origin-marker-node::after {
- content: '';
- position: absolute;
- top: 50%;
- left: 50%;
- background: #ef4444;
- box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
- }
-
- .origin-marker-node::before {
+ .origin-marker-node svg {
+ display: block;
width: 100%;
- height: 2px;
- transform: translate(-50%, -50%) rotate(45deg);
+ height: 100%;
+ overflow: visible;
}
- .origin-marker-node::after {
- width: 100%;
- height: 2px;
- transform: translate(-50%, -50%) rotate(-45deg);
+ .origin-marker-node .origin-circle {
+ fill: none;
+ stroke: rgba(239, 68, 68, 0.42);
+ stroke-width: 1;
+ vector-effect: non-scaling-stroke;
+ }
+
+ .origin-marker-node .origin-x {
+ stroke: rgba(239, 68, 68, 0.36);
+ stroke-width: 1;
+ vector-effect: non-scaling-stroke;
+ stroke-linecap: round;
}
.ruler-point-node {
@@ -1643,6 +1734,7 @@ Organization : OptiHK Limited
FORGE_COMPONENT_TYPE,
DEFAULT_COMPONENT_BOX_SIZE,
DEFAULT_CANVAS_SIZE,
+ DEFAULT_CANVAS_BOUNDS,
PORT_NODE_SIZE,
DEFAULT_ELEMENT_PITCH,
ELEMENT_COMPONENTS,
@@ -1654,6 +1746,7 @@ Organization : OptiHK Limited
normalizeBoxSize,
chooseCategoryComponent,
normalizeCanvasSize,
+ normalizeCanvasBounds,
clampPositionToCanvas,
calculateLayoutBounds,
calculateCompositeBoxSize,
@@ -2218,14 +2311,24 @@ Organization : OptiHK Limited
});
// Draws the non-interactive canvas extent marker used by React Flow.
- const CanvasBoundaryNode = memo(({ data }) => (
-
@@ -4187,6 +4310,9 @@ Organization : OptiHK Limited
const [mouseScreenPoint, setMouseScreenPoint] = useState(null);
const [canvasOrigin, setCanvasOrigin] = useState({ x: 0, y: 0 });
const [originPickMode, setOriginPickMode] = useState(false);
+ const [originPickInputX, setOriginPickInputX] = useState('');
+ const [originPickInputY, setOriginPickInputY] = useState('');
+ const [originInputFocused, setOriginInputFocused] = useState(false);
const [projectTechnology, setProjectTechnology] = useState('');
const [technologyManifest, setTechnologyManifest] = useState(FALLBACK_TECHNOLOGY_MANIFEST);
const [currentLinkXsection, setCurrentLinkXsection] = useState('strip');
@@ -4202,17 +4328,17 @@ Organization : OptiHK Limited
const compositePageNameSet = useMemo(() => new Set(compositePageNames), [compositePageNames]);
const currentNodes = activePage && Array.isArray(activePage.nodes) ? activePage.nodes : [];
const currentEdges = activePage && Array.isArray(activePage.edges) ? activePage.edges : [];
- const activeCanvasSize = useMemo(() => normalizeCanvasSize(activePage?.canvasSize), [activePage?.canvasSize]);
+ const activeCanvasBounds = useMemo(() => normalizeCanvasBounds(activePage?.canvasBounds || activePage?.canvasSize), [activePage?.canvasBounds, activePage?.canvasSize]);
// Track viewport dimensions to compute dynamic zoom limits.
const [canvasViewportSize, setCanvasViewportSize] = React.useState({ width: 1200, height: 800 });
- // Set origin from the active page's saved value, or default to (500, H-500).
+ // Set origin from the active page's saved value, or default to (500, ymax-500).
useEffect(() => {
if (activePage?.origin) {
setCanvasOrigin({ x: activePage.origin.x, y: activePage.origin.y });
} else if (activePage) {
- setCanvasOrigin({ x: 500, y: activeCanvasSize.height - 500 });
+ setCanvasOrigin({ x: 500, y: activeCanvasBounds.ymax - 500 });
}
- }, [activePage?.id, activePage?.origin?.x, activePage?.origin?.y, activeCanvasSize.height]);
+ }, [activePage?.id, activePage?.origin?.x, activePage?.origin?.y, activeCanvasBounds.ymax]);
// Observe viewport size changes to recalculate minZoom.
useEffect(() => {
@@ -4275,16 +4401,15 @@ Organization : OptiHK Limited
setCurrentLinkXsection(linkXsectionChoices[0] || 'strip');
}
}, [linkXsectionChoices, currentLinkXsection]);
- const canvasNodeExtent = useMemo(() => [[0, 0], [activeCanvasSize.width, activeCanvasSize.height]], [activeCanvasSize.width, activeCanvasSize.height]);
// Dynamic minZoom: viewport can show at most 120% of canvas size.
const canvasMinZoom = useMemo(() => {
- const cw = activeCanvasSize.width;
- const ch = activeCanvasSize.height;
+ const cw = activeCanvasBounds.xmax - activeCanvasBounds.xmin;
+ const ch = activeCanvasBounds.ymax - activeCanvasBounds.ymin;
const vw = canvasViewportSize.width;
const vh = canvasViewportSize.height;
if (!cw || !ch || !vw || !vh) return 0.05;
return Math.min(vw / cw, vh / ch) / 1.2;
- }, [activeCanvasSize.width, activeCanvasSize.height, canvasViewportSize.width, canvasViewportSize.height]);
+ }, [activeCanvasBounds.xmin, activeCanvasBounds.xmax, activeCanvasBounds.ymin, activeCanvasBounds.ymax, canvasViewportSize.width, canvasViewportSize.height]);
const rulerActiveEndPoint = rulerEndPoint || rulerPreviewPoint;
const rulerMeasurement = useMemo(
() => createRulerMeasurement(rulerStartPoint, rulerActiveEndPoint),
@@ -4435,16 +4560,18 @@ Organization : OptiHK Limited
// Combines real nodes with boundary, ruler, and hidden route helper nodes for display.
const renderNodes = useMemo(() => {
if (!activePage || activePage.type === 'layoutPreview') return currentNodes;
+ const bw = activeCanvasBounds.xmax - activeCanvasBounds.xmin;
+ const bh = activeCanvasBounds.ymax - activeCanvasBounds.ymin;
return [{
id: '__canvas-boundary__',
type: 'canvasBoundaryNode',
- position: { x: 0, y: 0 },
- data: { size: activeCanvasSize },
+ position: { x: activeCanvasBounds.xmin, y: activeCanvasBounds.ymin },
+ data: { bounds: activeCanvasBounds },
draggable: false,
selectable: false,
deletable: false,
focusable: false,
- style: { width: activeCanvasSize.width, height: activeCanvasSize.height, zIndex: -1, pointerEvents: 'none' }
+ style: { width: bw, height: bh, zIndex: -1, pointerEvents: 'none' }
}, {
id: '__origin-marker__',
type: 'originMarkerNode',
@@ -4456,7 +4583,7 @@ Organization : OptiHK Limited
focusable: false,
style: { zIndex: 10, pointerEvents: 'none' }
}, ...currentNodes, ...freeRouteEndpointNodes, ...rulerNodes];
- }, [activePage, currentNodes, activeCanvasSize, canvasOrigin, freeRouteEndpointNodes, rulerNodes]);
+ }, [activePage, currentNodes, activeCanvasBounds, canvasOrigin, freeRouteEndpointNodes, rulerNodes]);
// Resolves rotated anchor handle direction so connected canvas links exit the correct side.
const getAnchorHandleRouteDirection = useCallback((node, handleId) => {
if (!node || !handleId || !(node.type === 'anchorNode' || node.data?.elementType === 'anchor')) return null;
@@ -4755,7 +4882,7 @@ Organization : OptiHK Limited
const boxSize = node.type === 'rotatableNode'
? normalizeBoxSize({ box_size: node.data?.boxSize }, DEFAULT_COMPONENT_BOX_SIZE)
: { width: 30, height: 30 };
- return { ...node, position: clampPositionToCanvas(node.position, p.canvasSize || activeCanvasSize, boxSize) };
+ return { ...node, position: clampPositionToCanvas(node.position, p.canvasBounds || p.canvasSize || activeCanvasBounds, boxSize) };
});
// Sync ruler label position and text when endpoints are dragged.
const rulerUpdates = new Map();
@@ -4798,7 +4925,7 @@ Organization : OptiHK Limited
}
return { ...p, nodes: newNodes, edges: newEdges, port: newPort };
}));
- }, [activePageId, activePage, activeCanvasSize]);
+ }, [activePageId, activePage, activeCanvasBounds]);
// Apply React Flow edge changes while preserving route style and selection state.
// Also cascades ruler group deletion when a ruler edge is removed.
@@ -4860,7 +4987,7 @@ Organization : OptiHK Limited
: { width: 30, height: 30 };
return {
...n,
- position: update.position != null ? clampPositionToCanvas(nextPosition, p.canvasSize || activeCanvasSize, boxSize) : nextPosition,
+ position: update.position != null ? clampPositionToCanvas(nextPosition, p.canvasSize || activeCanvasBounds, boxSize) : nextPosition,
data: nextData
};
}
@@ -4875,28 +5002,26 @@ Organization : OptiHK Limited
}
return { ...p, nodes: newNodes, port: newPort };
}));
- }, [activePageId, activeCanvasSize]);
+ }, [activePageId, activeCanvasBounds]);
- // Update active canvas dimensions and clamp existing node positions inside the new bounds.
- const handleCanvasSizeChange = useCallback((axis, value) => {
+ // Update active canvas bounds (four-wall rectangle) and clamp existing node positions inside the new bounds.
+ const handleCanvasBoundsChange = useCallback((field, value) => {
if (!activePageId) return;
const numericValue = Number(value);
- if (!Number.isFinite(numericValue) || numericValue <= 0) return;
+ if (!Number.isFinite(numericValue) || numericValue < 0) return;
setPages(prev => prev.map(page => {
if (page.id !== activePageId) return page;
- const nextCanvasSize = normalizeCanvasSize({
- ...(page.canvasSize || DEFAULT_CANVAS_SIZE),
- [axis]: numericValue
- });
+ const prevBounds = normalizeCanvasBounds(page.canvasBounds || page.canvasSize);
+ const nextCanvasBounds = { ...prevBounds, [field]: numericValue };
return {
...page,
- canvasSize: nextCanvasSize,
+ canvasBounds: nextCanvasBounds,
nodes: page.nodes.map(node => {
if (!node.position || node.id === 'page-port') return node;
const boxSize = node.type === 'rotatableNode'
? normalizeBoxSize({ box_size: node.data?.boxSize }, DEFAULT_COMPONENT_BOX_SIZE)
: { width: 30, height: 30 };
- return { ...node, position: clampPositionToCanvas(node.position, nextCanvasSize, boxSize) };
+ return { ...node, position: clampPositionToCanvas(node.position, nextCanvasBounds, boxSize) };
})
};
}));
@@ -5497,7 +5622,7 @@ Organization : OptiHK Limited
id: newPageId,
name: newPageName,
type: isProject ? 'project' : 'composite',
- canvasSize: normalizeCanvasSize(doc.canvas_size || doc.canvasSize),
+ canvasBounds: normalizeCanvasBounds(doc.canvas_bounds || doc.canvas_size || doc.canvasSize), canvasSize: normalizeCanvasSize(doc.canvas_size || doc.canvasSize),
nodes: isProject ? newNodes : [
{
id: 'page-port',
@@ -5603,7 +5728,7 @@ Organization : OptiHK Limited
}
],
edges: [],
- canvasSize: DEFAULT_CANVAS_SIZE,
+ canvasBounds: DEFAULT_CANVAS_BOUNDS, canvasSize: DEFAULT_CANVAS_SIZE,
port: { x: 600, y: 4400, a: 0 }
});
@@ -5736,7 +5861,7 @@ Organization : OptiHK Limited
id: `cell-${Date.now()}-${Math.random().toString(36).substr(2, 5)}`,
name: doc.name || cellName,
type: doc.type === 'project' ? 'project' : 'composite',
- canvasSize: normalizeCanvasSize(doc.canvas_size || doc.canvasSize),
+ canvasBounds: normalizeCanvasBounds(doc.canvas_bounds || doc.canvas_size || doc.canvasSize), canvasSize: normalizeCanvasSize(doc.canvas_size || doc.canvasSize),
nodes,
edges,
port: pagePort || { x: 0, y: 0, a: 0 },
@@ -5850,12 +5975,12 @@ Organization : OptiHK Limited
});
} else {
reactFlowInstance.fitBounds(
- { x: 0, y: 0, width: activeCanvasSize.width, height: activeCanvasSize.height },
+ { x: activeCanvasBounds.xmin, y: activeCanvasBounds.ymin, width: activeCanvasBounds.xmax - activeCanvasBounds.xmin, height: activeCanvasBounds.ymax - activeCanvasBounds.ymin },
{ padding: 0.12, duration: 0 }
);
}
}
- }, [activePage?.id, activePage?.viewport, activeCanvasSize.width, activeCanvasSize.height, reactFlowInstance]);
+ }, [activePage?.id, activePage?.viewport, activeCanvasBounds.xmin, activeCanvasBounds.xmax, activeCanvasBounds.ymin, activeCanvasBounds.ymax, reactFlowInstance]);
useEffect(() => {
setRulerStartPoint(null);
@@ -6014,7 +6139,7 @@ Organization : OptiHK Limited
}
],
edges: [],
- canvasSize: DEFAULT_CANVAS_SIZE,
+ canvasBounds: DEFAULT_CANVAS_BOUNDS, canvasSize: DEFAULT_CANVAS_SIZE,
port: { x: 600, y: 4400, a: 0 }
};
setActivePageId(newProjectPage.id);
@@ -6046,7 +6171,7 @@ Organization : OptiHK Limited
name: name,
type: 'composite',
isClosed: false,
- canvasSize: DEFAULT_CANVAS_SIZE,
+ canvasBounds: DEFAULT_CANVAS_BOUNDS, canvasSize: DEFAULT_CANVAS_SIZE,
nodes: [
{
id: 'page-port',
@@ -6138,7 +6263,7 @@ Organization : OptiHK Limited
name: cellName,
type: 'composite',
isClosed: false,
- canvasSize: DEFAULT_CANVAS_SIZE,
+ canvasBounds: DEFAULT_CANVAS_BOUNDS, canvasSize: DEFAULT_CANVAS_SIZE,
nodes: [
{
id: 'page-port',
@@ -6285,7 +6410,7 @@ Organization : OptiHK Limited
const compositeBoxSize = normalizeBoxSize({ box_size: parsedData.boxSize }, DEFAULT_COMPONENT_BOX_SIZE);
const position = clampPositionToCanvas(
reactFlowInstance.screenToFlowPosition({ x: event.clientX, y: event.clientY }),
- activePage?.canvasSize || activeCanvasSize,
+ activePage?.canvasSize || activeCanvasBounds,
compositeBoxSize
);
const newNode = {
@@ -6336,7 +6461,7 @@ Organization : OptiHK Limited
const compositeBoxSize = normalizeBoxSize({ box_size: parsedData.boxSize }, DEFAULT_COMPONENT_BOX_SIZE);
const position = clampPositionToCanvas(
reactFlowInstance.screenToFlowPosition({ x: event.clientX, y: event.clientY }),
- activePage?.canvasSize || activeCanvasSize,
+ activePage?.canvasSize || activeCanvasBounds,
compositeBoxSize
);
const newNode = {
@@ -6382,7 +6507,7 @@ Organization : OptiHK Limited
}
const position = clampPositionToCanvas(
reactFlowInstance.screenToFlowPosition({ x: event.clientX, y: event.clientY }),
- activePage?.canvasSize || activeCanvasSize,
+ activePage?.canvasSize || activeCanvasBounds,
parsedData.type === 'element'
? buildElementBoxSize({ elementType: parsedData.elementType === 'anchor' ? 'anchor' : 'port', portNumber: 1, pitch: DEFAULT_ELEMENT_PITCH })
: DEFAULT_COMPONENT_BOX_SIZE
@@ -6395,7 +6520,7 @@ Organization : OptiHK Limited
const newNode = {
id: Date.now().toString(),
type: 'rotatableNode',
- position: clampPositionToCanvas(position, activePage?.canvasSize || activeCanvasSize, normalizeBoxSize(metadata)),
+ position: clampPositionToCanvas(position, activePage?.canvasSize || activeCanvasBounds, normalizeBoxSize(metadata)),
data: {
label: componentName,
componentName,
@@ -6442,7 +6567,7 @@ Organization : OptiHK Limited
: {
id: Date.now().toString(),
type: 'anchorNode',
- position: clampPositionToCanvas(position, activePage?.canvasSize || activeCanvasSize, buildElementBoxSize({ elementType: 'anchor', portNumber: 1, pitch: DEFAULT_ELEMENT_PITCH })),
+ position: clampPositionToCanvas(position, activePage?.canvasSize || activeCanvasBounds, buildElementBoxSize({ elementType: 'anchor', portNumber: 1, pitch: DEFAULT_ELEMENT_PITCH })),
data: {
label: elementName,
componentName: 'Anchor',
@@ -6536,7 +6661,7 @@ Organization : OptiHK Limited
cell: activePage?.name,
detail: { component: parsedData.name, instance: componentDisplayName, category: parsedData.category }
});
- }, [activePageId, activePage, activeCanvasSize, openPage, reactFlowInstance, generateComponentDisplayName, syncCompositePlacement, recordUserAction, currentProjectName, toBooleanFlag]);
+ }, [activePageId, activePage, activeCanvasBounds, openPage, reactFlowInstance, generateComponentDisplayName, syncCompositePlacement, recordUserAction, currentProjectName, toBooleanFlag]);
// Expand all library tree nodes.
const expandAll = useCallback(() => {
@@ -6609,15 +6734,15 @@ Organization : OptiHK Limited
setOriginPickMode(false);
}, []);
- // Convert a pane click or pointer event into canvas coordinates.
+ // Convert a pane click or pointer event into canvas coordinates (raw, no clamp).
const eventToCanvasPoint = useCallback((event) => {
if (!reactFlowInstance || !event) return null;
const rawPoint = reactFlowInstance.screenToFlowPosition({ x: event.clientX, y: event.clientY });
return {
- x: Number(Math.min(activeCanvasSize.width, Math.max(0, rawPoint.x)).toFixed(3)),
- y: Number(Math.min(activeCanvasSize.height, Math.max(0, rawPoint.y)).toFixed(3))
+ x: Number(rawPoint.x.toFixed(3)),
+ y: Number(rawPoint.y.toFixed(3))
};
- }, [reactFlowInstance, activeCanvasSize.width, activeCanvasSize.height]);
+ }, [reactFlowInstance]);
const updateMouseCanvasPoint = useCallback((event) => {
if (!activePage || activePage.type === 'layoutPreview') return null;
@@ -6642,11 +6767,63 @@ Organization : OptiHK Limited
setRulerStartPoint(null);
setRulerEndPoint(null);
setRulerPreviewPoint(null);
+ } else {
+ setOriginPickInputX('');
+ setOriginPickInputY('');
+ setOriginInputFocused(false);
}
return next;
});
}, []);
+ // Sync mouse position to origin pick inputs during pick mode (only when inputs are not focused).
+ useEffect(() => {
+ if (!originPickMode || originInputFocused || !mouseCanvasPoint) return;
+ setOriginPickInputX(mouseCanvasPoint.x.toFixed(3));
+ setOriginPickInputY(mouseCanvasPoint.y.toFixed(3));
+ }, [originPickMode, mouseCanvasPoint, originInputFocused]);
+
+ // Apply manually entered origin coordinates from the input panel.
+ const handleApplyOriginInput = useCallback(() => {
+ const x = parseFloat(originPickInputX);
+ const y = parseFloat(originPickInputY);
+ if (Number.isFinite(x) && Number.isFinite(y)) {
+ // Origin always snaps to 10 um grid (no canvas clamp — origin may be outside bounds).
+ const snapped = {
+ x: Math.round(x / 10) * 10,
+ y: Math.round(y / 10) * 10
+ };
+ setCanvasOrigin(snapped);
+ setPages(prev => prev.map(p => p.id === activePage.id ? { ...p, origin: snapped } : p));
+ setOriginPickMode(false);
+ setOriginPickInputX('');
+ setOriginPickInputY('');
+ setOriginInputFocused(false);
+ addLog(`Canvas origin: (${snapped.x.toFixed(3)}, ${snapped.y.toFixed(3)}) um (manual)`);
+ }
+ }, [originPickInputX, originPickInputY, activePage, setPages, addLog]);
+
+ // Live-preview origin as the user edits the input fields (grid-snapped).
+ const handleOriginInputChange = useCallback((axis, rawValue) => {
+ const val = parseFloat(rawValue);
+ if (!Number.isFinite(val)) {
+ if (axis === 'x') setOriginPickInputX(rawValue);
+ else setOriginPickInputY(rawValue);
+ return;
+ }
+ const otherAxis = axis === 'x' ? 'y' : 'x';
+ const otherVal = parseFloat(axis === 'x' ? originPickInputY : originPickInputX);
+ const xRaw = axis === 'x' ? val : (Number.isFinite(otherVal) ? otherVal : canvasOrigin.x);
+ const yRaw = axis === 'y' ? val : (Number.isFinite(otherVal) ? otherVal : canvasOrigin.y);
+ const snapped = {
+ x: Math.round(xRaw / 10) * 10,
+ y: Math.round(yRaw / 10) * 10
+ };
+ if (axis === 'x') setOriginPickInputX(rawValue);
+ else setOriginPickInputY(rawValue);
+ setCanvasOrigin(snapped);
+ }, [originPickInputX, originPickInputY, canvasOrigin.x, canvasOrigin.y]);
+
// Set ruler endpoints from canvas clicks. First click sets start, second click persists measurement and exits ruler mode.
const handleRulerPaneClick = useCallback((event) => {
if (!rulerMode || !reactFlowInstance || !activePage || activePage.type === 'layoutPreview') return;
@@ -6709,7 +6886,7 @@ Organization : OptiHK Limited
type: 'rulerEdge',
selectable: true,
focusable: true,
- data: { ruler: true, rulerGroupId, canvasSize: activePage.canvasSize || activeCanvasSize },
+ data: { ruler: true, rulerGroupId, canvasBounds: activePage.canvasBounds || activePage.canvasSize || activeCanvasBounds },
style: {
stroke: '#2dd4bf',
strokeWidth: 2
@@ -6745,11 +6922,20 @@ Organization : OptiHK Limited
if (!nextPoint) return false;
event.preventDefault();
event.stopPropagation();
- setCanvasOrigin(nextPoint);
+ // Origin always snaps to 10 um grid regardless of Snap to Grid toggle.
+ const snapped = {
+ x: Math.round(nextPoint.x / 10) * 10,
+ y: Math.round(nextPoint.y / 10) * 10
+ };
+ setCanvasOrigin(snapped);
+ setPages(prev => prev.map(p => p.id === activePage.id ? { ...p, origin: snapped } : p));
setOriginPickMode(false);
- addLog(`Canvas origin: (${nextPoint.x.toFixed(3)}, ${nextPoint.y.toFixed(3)}) um`);
+ setOriginPickInputX('');
+ setOriginPickInputY('');
+ setOriginInputFocused(false);
+ addLog(`Canvas origin: (${snapped.x.toFixed(3)}, ${snapped.y.toFixed(3)}) um`);
return true;
- }, [originPickMode, activePage, updateMouseCanvasPoint, eventToCanvasPoint, addLog]);
+ }, [originPickMode, activePage, updateMouseCanvasPoint, eventToCanvasPoint, setPages, addLog]);
const handleCanvasMouseMove = useCallback((event) => {
updateMouseCanvasPoint(event);
@@ -7011,9 +7197,14 @@ Organization : OptiHK Limited
schema_version: "2.0.0"
kind: cell
coordinate_system: gds_y_up
+canvas_bounds:
+ xmin: ${Number(page.canvasBounds?.xmin ?? 0)}
+ xmax: ${Number(page.canvasBounds?.xmax ?? DEFAULT_CANVAS_BOUNDS.xmax)}
+ ymin: ${Number(page.canvasBounds?.ymin ?? 0)}
+ ymax: ${Number(page.canvasBounds?.ymax ?? DEFAULT_CANVAS_BOUNDS.ymax)}
canvas_size:
- width: ${Number(page.canvasSize?.width || DEFAULT_CANVAS_SIZE.width)}
- height: ${Number(page.canvasSize?.height || DEFAULT_CANVAS_SIZE.height)}
+ width: ${Number(page.canvasSize?.width || page.canvasBounds ? (page.canvasBounds.xmax - page.canvasBounds.xmin) : DEFAULT_CANVAS_SIZE.width)}
+ height: ${Number(page.canvasSize?.height || page.canvasBounds ? (page.canvasBounds.ymax - page.canvasBounds.ymin) : DEFAULT_CANVAS_SIZE.height)}
origin:
x: ${Number(canvasOrigin.x).toFixed(1)}
y: ${Number(canvasOrigin.y).toFixed(1)}
@@ -7222,8 +7413,8 @@ ${bundlesBlock}`;
onProjectToggle={handleProjectToggle}
projectTreeRef={projectTreeContainerRef}
projectTreeKey={projectTreeKey}
- canvasSize={activeCanvasSize}
- onCanvasSizeChange={handleCanvasSizeChange}
+ canvasBounds={activeCanvasBounds}
+ onCanvasBoundsChange={handleCanvasBoundsChange}
/>
@@ -7359,6 +7550,37 @@ ${bundlesBlock}`;
/>
)}
+ {originPickMode && activePage?.type !== 'layoutPreview' && (
+
+
+
+
+
+
+ )}
+
{activePage && activePage.type !== 'layoutPreview' && (