@canvas-harness/core 0.1.13 → 0.1.15

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
@@ -4344,8 +4344,10 @@ var drawAtomic = (ctx, type, w, h, style, scale, theme, opts) => {
4344
4344
  if (strokeVisible && !opts?.skipStroke) {
4345
4345
  ctx.strokeStyle = stroke;
4346
4346
  ctx.lineWidth = Math.max(strokeWidth, 1 / scale);
4347
- ctx.setLineDash(dashPatternFor(style?.strokeStyle, strokeWidth));
4347
+ const dash = dashPatternFor(style?.strokeStyle, strokeWidth);
4348
+ ctx.setLineDash(dash);
4348
4349
  ctx.stroke();
4350
+ if (dash.length > 0) ctx.setLineDash([]);
4349
4351
  }
4350
4352
  if (needsScope) ctx.restore();
4351
4353
  };
@@ -5519,6 +5521,7 @@ var createRenderer = (opts) => {
5519
5521
  stats: () => loop.stats(),
5520
5522
  lastDrawCount: () => lastDrawn,
5521
5523
  getOverlaySet: () => [...overlaySet],
5524
+ getAssetCache: () => assetCache,
5522
5525
  dispose() {
5523
5526
  loop.stop();
5524
5527
  unsubChange();
@@ -6114,9 +6117,14 @@ var makeContext = (cssW, cssH, scale, opts) => {
6114
6117
  };
6115
6118
  var paintScene = (ctx, store, nodes, scale, opts, edges) => {
6116
6119
  const theme = opts.theme;
6120
+ const assetCache = opts.assetCache;
6117
6121
  for (const node of nodes) {
6118
6122
  drawWithNodeTransform(ctx, node, () => {
6119
6123
  if (isDrawablePrimitive(node.type)) drawShape(ctx, node, scale, theme);
6124
+ if (assetCache) {
6125
+ if (node.type === "image") paintImageNode(ctx, node, assetCache, theme);
6126
+ else if (node.type === "icon") paintIconNode(ctx, node, assetCache, scale, theme);
6127
+ }
6120
6128
  paintContent(ctx, node);
6121
6129
  });
6122
6130
  }
@@ -6228,10 +6236,30 @@ var renderNodeSvg = (node) => {
6228
6236
  const strokeWidth = node.style?.strokeWidth ?? 1.5;
6229
6237
  const opacity = node.style?.opacity ?? 1;
6230
6238
  const rotate = node.angle !== 0 ? ` transform="rotate(${node.angle * 180 / Math.PI} ${node.x + node.w / 2} ${node.y + node.h / 2})"` : "";
6231
- const shape = renderShapeSvg(node, fill, stroke, strokeWidth, opacity);
6232
6239
  const text = renderTextSvg(node);
6240
+ if (node.type === "image") {
6241
+ return `<g${rotate}>${renderImageNodeSvg(node, opacity)}${text}</g>`;
6242
+ }
6243
+ if (node.type === "icon") {
6244
+ return `<g${rotate}>${renderIconNodeSvg(node, opacity)}${text}</g>`;
6245
+ }
6246
+ const shape = renderShapeSvg(node, fill, stroke, strokeWidth, opacity);
6233
6247
  return `<g${rotate}>${shape}${text}</g>`;
6234
6248
  };
6249
+ var renderImageNodeSvg = (node, opacity) => {
6250
+ const data = node.data;
6251
+ if (!data?.src) return "";
6252
+ return `<image href="${escapeAttr(data.src)}" x="${node.x}" y="${node.y}" width="${node.w}" height="${node.h}" preserveAspectRatio="none" opacity="${opacity}" />`;
6253
+ };
6254
+ var renderIconNodeSvg = (node, opacity) => {
6255
+ const data = node.data;
6256
+ if (!data?.src) return "";
6257
+ const colored = node.style?.iconColor ? applySvgColor(data.src, node.style.iconColor) : data.src;
6258
+ const dim = extractSvgDimensions(colored);
6259
+ const sx = node.w / dim.w;
6260
+ const sy = node.h / dim.h;
6261
+ return `<g transform="translate(${node.x} ${node.y}) scale(${sx} ${sy})" opacity="${opacity}">${colored}</g>`;
6262
+ };
6235
6263
  var renderShapeSvg = (node, fill, stroke, strokeWidth, opacity) => {
6236
6264
  const attrs = (extra) => `fill="${escapeAttr(fill)}" stroke="${escapeAttr(stroke)}" stroke-width="${strokeWidth}" opacity="${opacity}"${extra}`;
6237
6265
  switch (node.type) {
@@ -6653,6 +6681,7 @@ exports.clipSamples = clipSamples;
6653
6681
  exports.computeAutoFitHeight = computeAutoFitHeight;
6654
6682
  exports.computeEdgeGeometry = computeEdgeGeometry;
6655
6683
  exports.copy = copy;
6684
+ exports.createAssetCache = createAssetCache;
6656
6685
  exports.createCanvasStore = createCanvasStore;
6657
6686
  exports.createDefaultTextareaEditor = createDefaultTextareaEditor;
6658
6687
  exports.createFrameLoop = createFrameLoop;
@@ -6729,6 +6758,8 @@ exports.onMathJaxReady = onMathJaxReady;
6729
6758
  exports.opSchemas = opSchemas;
6730
6759
  exports.opSchemasAsAnthropicTools = opSchemasAsAnthropicTools;
6731
6760
  exports.paintBackground = paintBackground;
6761
+ exports.paintIconNode = paintIconNode;
6762
+ exports.paintImageNode = paintImageNode;
6732
6763
  exports.panByScreen = panByScreen;
6733
6764
  exports.paste = paste;
6734
6765
  exports.pointInNode = pointInNode;