@canvas-harness/core 0.1.13 → 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 +30 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -3
- package/dist/index.d.ts +52 -3
- package/dist/index.js +28 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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();
|
|
@@ -6114,9 +6115,14 @@ var makeContext = (cssW, cssH, scale, opts) => {
|
|
|
6114
6115
|
};
|
|
6115
6116
|
var paintScene = (ctx, store, nodes, scale, opts, edges) => {
|
|
6116
6117
|
const theme = opts.theme;
|
|
6118
|
+
const assetCache = opts.assetCache;
|
|
6117
6119
|
for (const node of nodes) {
|
|
6118
6120
|
drawWithNodeTransform(ctx, node, () => {
|
|
6119
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
|
+
}
|
|
6120
6126
|
paintContent(ctx, node);
|
|
6121
6127
|
});
|
|
6122
6128
|
}
|
|
@@ -6228,10 +6234,30 @@ var renderNodeSvg = (node) => {
|
|
|
6228
6234
|
const strokeWidth = node.style?.strokeWidth ?? 1.5;
|
|
6229
6235
|
const opacity = node.style?.opacity ?? 1;
|
|
6230
6236
|
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
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);
|
|
6233
6245
|
return `<g${rotate}>${shape}${text}</g>`;
|
|
6234
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
|
+
};
|
|
6235
6261
|
var renderShapeSvg = (node, fill, stroke, strokeWidth, opacity) => {
|
|
6236
6262
|
const attrs = (extra) => `fill="${escapeAttr(fill)}" stroke="${escapeAttr(stroke)}" stroke-width="${strokeWidth}" opacity="${opacity}"${extra}`;
|
|
6237
6263
|
switch (node.type) {
|
|
@@ -6653,6 +6679,7 @@ exports.clipSamples = clipSamples;
|
|
|
6653
6679
|
exports.computeAutoFitHeight = computeAutoFitHeight;
|
|
6654
6680
|
exports.computeEdgeGeometry = computeEdgeGeometry;
|
|
6655
6681
|
exports.copy = copy;
|
|
6682
|
+
exports.createAssetCache = createAssetCache;
|
|
6656
6683
|
exports.createCanvasStore = createCanvasStore;
|
|
6657
6684
|
exports.createDefaultTextareaEditor = createDefaultTextareaEditor;
|
|
6658
6685
|
exports.createFrameLoop = createFrameLoop;
|
|
@@ -6729,6 +6756,8 @@ exports.onMathJaxReady = onMathJaxReady;
|
|
|
6729
6756
|
exports.opSchemas = opSchemas;
|
|
6730
6757
|
exports.opSchemasAsAnthropicTools = opSchemasAsAnthropicTools;
|
|
6731
6758
|
exports.paintBackground = paintBackground;
|
|
6759
|
+
exports.paintIconNode = paintIconNode;
|
|
6760
|
+
exports.paintImageNode = paintImageNode;
|
|
6732
6761
|
exports.panByScreen = panByScreen;
|
|
6733
6762
|
exports.paste = paste;
|
|
6734
6763
|
exports.pointInNode = pointInNode;
|