@canvas-harness/react 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1047,6 +1047,7 @@ function CanvasSurface({
1047
1047
  arrowDefaults,
1048
1048
  background,
1049
1049
  selectionColor,
1050
+ maxDpr,
1050
1051
  renderCustomNodeView,
1051
1052
  children
1052
1053
  }) {
@@ -1064,8 +1065,15 @@ function CanvasSurface({
1064
1065
  const interactionMode = useInteractionMode();
1065
1066
  useArrowTool(wrapRef, store, tool === "arrow", arrowDefaults);
1066
1067
  const { mountedIds, setMountedIds } = useOverlayHost();
1067
- const [camera, setCamera] = react.useState(() => store.getCamera());
1068
- react.useEffect(() => store.subscribe("camera", (c) => setCamera({ ...c })), [store]);
1068
+ react.useEffect(() => {
1069
+ const el = overlayRef.current;
1070
+ if (!el) return;
1071
+ const apply = (c) => {
1072
+ el.style.transform = `translate(${-c.x * c.z}px, ${-c.y * c.z}px) scale(${c.z})`;
1073
+ };
1074
+ apply(store.getCamera());
1075
+ return store.subscribe("camera", apply);
1076
+ }, [store]);
1069
1077
  react.useEffect(() => {
1070
1078
  if (!staticRef.current || !interactiveRef.current || w === 0 || h === 0) return;
1071
1079
  if (rendererRef.current) {
@@ -1081,6 +1089,7 @@ function CanvasSurface({
1081
1089
  height: h,
1082
1090
  background,
1083
1091
  selectionColor,
1092
+ maxDpr,
1084
1093
  onOverlayChange: (ids) => setMountedIds(ids)
1085
1094
  });
1086
1095
  r.start();
@@ -1090,7 +1099,7 @@ function CanvasSurface({
1090
1099
  r.dispose();
1091
1100
  rendererRef.current = null;
1092
1101
  };
1093
- }, [store, theme, w, h, onRenderer, setMountedIds]);
1102
+ }, [store, theme, w, h, maxDpr, onRenderer, setMountedIds]);
1094
1103
  react.useEffect(() => {
1095
1104
  rendererRef.current?.setBackground(background);
1096
1105
  }, [background]);
@@ -1112,9 +1121,9 @@ function CanvasSurface({
1112
1121
  if (toolRef.current === "select") {
1113
1122
  const rect = el.getBoundingClientRect();
1114
1123
  const screen = { x: e.clientX - rect.left, y: e.clientY - rect.top };
1115
- const camera2 = store.getCamera();
1116
- const world = core.screenToWorld(screen, camera2);
1117
- const hit = core.hitTestAny(store, world, camera2.z);
1124
+ const camera = store.getCamera();
1125
+ const world = core.screenToWorld(screen, camera);
1126
+ const hit = core.hitTestAny(store, world, camera.z);
1118
1127
  if (hit && hit.kind === "body" && "nodeId" in hit) {
1119
1128
  store.beginEdit(hit.nodeId);
1120
1129
  } else if (hit && hit.kind === "body" && "edgeId" in hit) {
@@ -1152,9 +1161,9 @@ function CanvasSurface({
1152
1161
  if (e.button !== 0) return;
1153
1162
  if (!isShapeTool(toolRef.current)) return;
1154
1163
  if (store.getInteractionState().mode === "editing") return;
1155
- const camera2 = store.getCamera();
1156
- const world = core.screenToWorld(screenFromEvent(e), camera2);
1157
- if (core.hitTestAny(store, world, camera2.z)) return;
1164
+ const camera = store.getCamera();
1165
+ const world = core.screenToWorld(screenFromEvent(e), camera);
1166
+ if (core.hitTestAny(store, world, camera.z)) return;
1158
1167
  startWorld = world;
1159
1168
  startScreen = screenFromEvent(e);
1160
1169
  activePointerId = e.pointerId;
@@ -1261,7 +1270,8 @@ function CanvasSurface({
1261
1270
  window.addEventListener("keydown", onKey);
1262
1271
  return () => window.removeEventListener("keydown", onKey);
1263
1272
  }, [store]);
1264
- const overlayTransform = `translate(${-camera.x * camera.z}px, ${-camera.y * camera.z}px) scale(${camera.z})`;
1273
+ const initialCamera = store.getCamera();
1274
+ const overlayTransform = `translate(${-initialCamera.x * initialCamera.z}px, ${-initialCamera.y * initialCamera.z}px) scale(${initialCamera.z})`;
1265
1275
  return /* @__PURE__ */ jsxRuntime.jsxs(
1266
1276
  "div",
1267
1277
  {