@canvas-harness/core 0.1.9 → 0.1.10

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
@@ -5959,8 +5959,30 @@ var endInside = (end, ids) => {
5959
5959
  if (!isAttached(end)) return true;
5960
5960
  return ids.has(end.nodeId);
5961
5961
  };
5962
+ var clipBboxCenter = (nodes) => {
5963
+ if (nodes.length === 0) return { x: 0, y: 0 };
5964
+ let minX = Number.POSITIVE_INFINITY;
5965
+ let minY = Number.POSITIVE_INFINITY;
5966
+ let maxX = Number.NEGATIVE_INFINITY;
5967
+ let maxY = Number.NEGATIVE_INFINITY;
5968
+ for (const n of nodes) {
5969
+ if (n.x < minX) minX = n.x;
5970
+ if (n.y < minY) minY = n.y;
5971
+ if (n.x + n.w > maxX) maxX = n.x + n.w;
5972
+ if (n.y + n.h > maxY) maxY = n.y + n.h;
5973
+ }
5974
+ return { x: (minX + maxX) / 2, y: (minY + maxY) / 2 };
5975
+ };
5962
5976
  var deserializeClipboard = (store, clip, opts = {}) => {
5963
- const offset = opts.offset ?? { x: 20, y: 20 };
5977
+ let offset;
5978
+ if (opts.offset) {
5979
+ offset = opts.offset;
5980
+ } else if (opts.at && clip.nodes.length > 0) {
5981
+ const center = clipBboxCenter(clip.nodes);
5982
+ offset = { x: opts.at.x - center.x, y: opts.at.y - center.y };
5983
+ } else {
5984
+ offset = { x: 20, y: 20 };
5985
+ }
5964
5986
  const select = opts.select ?? true;
5965
5987
  const nodeMap = /* @__PURE__ */ new Map();
5966
5988
  const edgeMap = /* @__PURE__ */ new Map();
@@ -5973,7 +5995,9 @@ var deserializeClipboard = (store, clip, opts = {}) => {
5973
5995
  y: n.y + offset.y
5974
5996
  }));
5975
5997
  const remapEnd = (end) => {
5976
- if (!isAttached(end)) return end;
5998
+ if (!isAttached(end)) {
5999
+ return { worldPoint: { x: end.worldPoint.x + offset.x, y: end.worldPoint.y + offset.y } };
6000
+ }
5977
6001
  const newId = nodeMap.get(end.nodeId);
5978
6002
  return newId ? { nodeId: newId, localOffset: end.localOffset } : end;
5979
6003
  };
@@ -6016,7 +6040,14 @@ var cut = async (store) => {
6016
6040
  var paste = async (store, payload, opts) => {
6017
6041
  const clip = payload ?? await readClipboard();
6018
6042
  if (!clip) return null;
6019
- const ids = deserializeClipboard(store, clip, opts);
6043
+ let effective = opts;
6044
+ if (!opts?.offset && !opts?.at) {
6045
+ const pointer = store.getInteractionState().pointer;
6046
+ if (pointer) {
6047
+ effective = { ...opts, at: { x: pointer.worldX, y: pointer.worldY } };
6048
+ }
6049
+ }
6050
+ const ids = deserializeClipboard(store, clip, effective);
6020
6051
  return ids;
6021
6052
  };
6022
6053
  var writeClipboard = async (clip) => {