@shotstack/shotstack-canvas 1.1.8 → 1.2.0

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.
@@ -1210,6 +1210,7 @@ async function createNodePainter(opts) {
1210
1210
  if (!ctx) throw new Error("2D context unavailable in Node (canvas).");
1211
1211
  const offscreenCanvas = createCanvas(canvas.width, canvas.height);
1212
1212
  const offscreenCtx = offscreenCanvas.getContext("2d");
1213
+ const gradientCache = /* @__PURE__ */ new Map();
1213
1214
  const api = {
1214
1215
  async render(ops) {
1215
1216
  const globalBox = computeGlobalTextBounds(ops);
@@ -1271,11 +1272,22 @@ async function createNodePainter(opts) {
1271
1272
  context.translate(fillOp.x, fillOp.y);
1272
1273
  const s = fillOp.scale ?? 1;
1273
1274
  context.scale(s, -s);
1274
- context.beginPath();
1275
- drawSvgPathOnCtx(context, fillOp.path);
1276
1275
  const bbox = fillOp.gradientBBox ?? globalBox;
1277
- const fill = makeGradientFromBBox(context, fillOp.fill, bbox);
1276
+ const localBBox = {
1277
+ x: (bbox.x - fillOp.x) / s,
1278
+ y: -(bbox.y - fillOp.y) / s,
1279
+ w: bbox.w / s,
1280
+ h: bbox.h / s
1281
+ };
1282
+ const cacheKey = JSON.stringify({ fill: fillOp.fill, bbox: localBBox });
1283
+ let fill = gradientCache.get(cacheKey);
1284
+ if (!fill) {
1285
+ fill = makeGradientFromBBox(context, fillOp.fill, localBBox);
1286
+ gradientCache.set(cacheKey, fill);
1287
+ }
1278
1288
  context.fillStyle = fill;
1289
+ context.beginPath();
1290
+ drawSvgPathOnCtx(context, fillOp.path);
1279
1291
  context.fill();
1280
1292
  context.restore();
1281
1293
  });