@canvas-harness/core 0.1.12 → 0.1.14

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
@@ -5519,6 +5519,7 @@ var createRenderer = (opts) => {
5519
5519
  stats: () => loop.stats(),
5520
5520
  lastDrawCount: () => lastDrawn,
5521
5521
  getOverlaySet: () => [...overlaySet],
5522
+ getAssetCache: () => assetCache,
5522
5523
  dispose() {
5523
5524
  loop.stop();
5524
5525
  unsubChange();
@@ -5853,8 +5854,13 @@ var hitTestAny = (store, worldPoint, cameraZ, selectedNodes = /* @__PURE__ */ ne
5853
5854
  }
5854
5855
  }
5855
5856
  const nodeHit = hitTestPoint(store, worldPoint, cameraZ, selectedNodes);
5856
- if (nodeHit) return nodeHit;
5857
- return hitTestEdge(store, worldPoint, cameraZ);
5857
+ const edgeHit = hitTestEdge(store, worldPoint, cameraZ);
5858
+ if (nodeHit && edgeHit && "edgeId" in edgeHit) {
5859
+ const nodeZ = store.getNode(nodeHit.nodeId)?.z ?? 0;
5860
+ const edgeZ = store.getEdge(edgeHit.edgeId)?.z ?? 0;
5861
+ return edgeZ >= nodeZ ? edgeHit : nodeHit;
5862
+ }
5863
+ return nodeHit ?? edgeHit;
5858
5864
  };
5859
5865
  var marqueeNodes = (store, rect) => {
5860
5866
  const candidates = store.querySpatial({ rect }).nodes;
@@ -6109,9 +6115,14 @@ var makeContext = (cssW, cssH, scale, opts) => {
6109
6115
  };
6110
6116
  var paintScene = (ctx, store, nodes, scale, opts, edges) => {
6111
6117
  const theme = opts.theme;
6118
+ const assetCache = opts.assetCache;
6112
6119
  for (const node of nodes) {
6113
6120
  drawWithNodeTransform(ctx, node, () => {
6114
6121
  if (isDrawablePrimitive(node.type)) drawShape(ctx, node, scale, theme);
6122
+ if (assetCache) {
6123
+ if (node.type === "image") paintImageNode(ctx, node, assetCache, theme);
6124
+ else if (node.type === "icon") paintIconNode(ctx, node, assetCache, scale, theme);
6125
+ }
6115
6126
  paintContent(ctx, node);
6116
6127
  });
6117
6128
  }
@@ -6223,10 +6234,30 @@ var renderNodeSvg = (node) => {
6223
6234
  const strokeWidth = node.style?.strokeWidth ?? 1.5;
6224
6235
  const opacity = node.style?.opacity ?? 1;
6225
6236
  const rotate = node.angle !== 0 ? ` transform="rotate(${node.angle * 180 / Math.PI} ${node.x + node.w / 2} ${node.y + node.h / 2})"` : "";
6226
- const shape = renderShapeSvg(node, fill, stroke, strokeWidth, opacity);
6227
6237
  const text = renderTextSvg(node);
6238
+ if (node.type === "image") {
6239
+ return `<g${rotate}>${renderImageNodeSvg(node, opacity)}${text}</g>`;
6240
+ }
6241
+ if (node.type === "icon") {
6242
+ return `<g${rotate}>${renderIconNodeSvg(node, opacity)}${text}</g>`;
6243
+ }
6244
+ const shape = renderShapeSvg(node, fill, stroke, strokeWidth, opacity);
6228
6245
  return `<g${rotate}>${shape}${text}</g>`;
6229
6246
  };
6247
+ var renderImageNodeSvg = (node, opacity) => {
6248
+ const data = node.data;
6249
+ if (!data?.src) return "";
6250
+ return `<image href="${escapeAttr(data.src)}" x="${node.x}" y="${node.y}" width="${node.w}" height="${node.h}" preserveAspectRatio="none" opacity="${opacity}" />`;
6251
+ };
6252
+ var renderIconNodeSvg = (node, opacity) => {
6253
+ const data = node.data;
6254
+ if (!data?.src) return "";
6255
+ const colored = node.style?.iconColor ? applySvgColor(data.src, node.style.iconColor) : data.src;
6256
+ const dim = extractSvgDimensions(colored);
6257
+ const sx = node.w / dim.w;
6258
+ const sy = node.h / dim.h;
6259
+ return `<g transform="translate(${node.x} ${node.y}) scale(${sx} ${sy})" opacity="${opacity}">${colored}</g>`;
6260
+ };
6230
6261
  var renderShapeSvg = (node, fill, stroke, strokeWidth, opacity) => {
6231
6262
  const attrs = (extra) => `fill="${escapeAttr(fill)}" stroke="${escapeAttr(stroke)}" stroke-width="${strokeWidth}" opacity="${opacity}"${extra}`;
6232
6263
  switch (node.type) {
@@ -6648,6 +6679,7 @@ exports.clipSamples = clipSamples;
6648
6679
  exports.computeAutoFitHeight = computeAutoFitHeight;
6649
6680
  exports.computeEdgeGeometry = computeEdgeGeometry;
6650
6681
  exports.copy = copy;
6682
+ exports.createAssetCache = createAssetCache;
6651
6683
  exports.createCanvasStore = createCanvasStore;
6652
6684
  exports.createDefaultTextareaEditor = createDefaultTextareaEditor;
6653
6685
  exports.createFrameLoop = createFrameLoop;
@@ -6724,6 +6756,8 @@ exports.onMathJaxReady = onMathJaxReady;
6724
6756
  exports.opSchemas = opSchemas;
6725
6757
  exports.opSchemasAsAnthropicTools = opSchemasAsAnthropicTools;
6726
6758
  exports.paintBackground = paintBackground;
6759
+ exports.paintIconNode = paintIconNode;
6760
+ exports.paintImageNode = paintImageNode;
6727
6761
  exports.panByScreen = panByScreen;
6728
6762
  exports.paste = paste;
6729
6763
  exports.pointInNode = pointInNode;