@canvas-harness/core 0.1.8 → 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
@@ -4990,8 +4990,7 @@ var createRenderer = (opts) => {
4990
4990
  if (excludedNodes?.has(node.id)) continue;
4991
4991
  const isEditingThis = editingNodeId === node.id;
4992
4992
  if (isDrawablePrimitive(node.type)) {
4993
- const isSolidStroke = (node.style?.strokeStyle ?? "solid") === "solid";
4994
- const useRough = isSolidStroke && roughEnabled && (node.style?.roughness ?? 0) > 0;
4993
+ const useRough = roughEnabled && (node.style?.roughness ?? 0) > 0;
4995
4994
  const roughReady = useRough ? getRoughCanvasCtor() !== null : false;
4996
4995
  const composite = isCompositePrimitive(node.type);
4997
4996
  drawWithNodeTransform(surface.ctx, node, () => {
@@ -5331,8 +5330,7 @@ var createRenderer = (opts) => {
5331
5330
  return;
5332
5331
  }
5333
5332
  if (isDrawablePrimitive(node.type)) {
5334
- const isSolidStroke = (node.style?.strokeStyle ?? "solid") === "solid";
5335
- const useRough = isSolidStroke && dragRoughEnabled && (node.style?.roughness ?? 0) > 0;
5333
+ const useRough = dragRoughEnabled && (node.style?.roughness ?? 0) > 0;
5336
5334
  const roughReady = useRough ? getRoughCanvasCtor() !== null : false;
5337
5335
  if (useRough && roughReady) {
5338
5336
  if (isCompositePrimitive(node.type)) {
@@ -5961,8 +5959,30 @@ var endInside = (end, ids) => {
5961
5959
  if (!isAttached(end)) return true;
5962
5960
  return ids.has(end.nodeId);
5963
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
+ };
5964
5976
  var deserializeClipboard = (store, clip, opts = {}) => {
5965
- 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
+ }
5966
5986
  const select = opts.select ?? true;
5967
5987
  const nodeMap = /* @__PURE__ */ new Map();
5968
5988
  const edgeMap = /* @__PURE__ */ new Map();
@@ -5975,7 +5995,9 @@ var deserializeClipboard = (store, clip, opts = {}) => {
5975
5995
  y: n.y + offset.y
5976
5996
  }));
5977
5997
  const remapEnd = (end) => {
5978
- 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
+ }
5979
6001
  const newId = nodeMap.get(end.nodeId);
5980
6002
  return newId ? { nodeId: newId, localOffset: end.localOffset } : end;
5981
6003
  };
@@ -6018,7 +6040,14 @@ var cut = async (store) => {
6018
6040
  var paste = async (store, payload, opts) => {
6019
6041
  const clip = payload ?? await readClipboard();
6020
6042
  if (!clip) return null;
6021
- 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);
6022
6051
  return ids;
6023
6052
  };
6024
6053
  var writeClipboard = async (clip) => {