@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.
- package/dist/entry.node.cjs +15 -3
- package/dist/entry.node.cjs.map +1 -1
- package/dist/entry.node.js +15 -3
- package/dist/entry.node.js.map +1 -1
- package/dist/entry.web.js +13 -1
- package/dist/entry.web.js.map +1 -1
- package/package.json +1 -1
package/dist/entry.node.cjs
CHANGED
|
@@ -1248,6 +1248,7 @@ async function createNodePainter(opts) {
|
|
|
1248
1248
|
if (!ctx) throw new Error("2D context unavailable in Node (canvas).");
|
|
1249
1249
|
const offscreenCanvas = createCanvas(canvas.width, canvas.height);
|
|
1250
1250
|
const offscreenCtx = offscreenCanvas.getContext("2d");
|
|
1251
|
+
const gradientCache = /* @__PURE__ */ new Map();
|
|
1251
1252
|
const api = {
|
|
1252
1253
|
async render(ops) {
|
|
1253
1254
|
const globalBox = computeGlobalTextBounds(ops);
|
|
@@ -1309,11 +1310,22 @@ async function createNodePainter(opts) {
|
|
|
1309
1310
|
context.translate(fillOp.x, fillOp.y);
|
|
1310
1311
|
const s = fillOp.scale ?? 1;
|
|
1311
1312
|
context.scale(s, -s);
|
|
1312
|
-
context.beginPath();
|
|
1313
|
-
drawSvgPathOnCtx(context, fillOp.path);
|
|
1314
1313
|
const bbox = fillOp.gradientBBox ?? globalBox;
|
|
1315
|
-
const
|
|
1314
|
+
const localBBox = {
|
|
1315
|
+
x: (bbox.x - fillOp.x) / s,
|
|
1316
|
+
y: -(bbox.y - fillOp.y) / s,
|
|
1317
|
+
w: bbox.w / s,
|
|
1318
|
+
h: bbox.h / s
|
|
1319
|
+
};
|
|
1320
|
+
const cacheKey = JSON.stringify({ fill: fillOp.fill, bbox: localBBox });
|
|
1321
|
+
let fill = gradientCache.get(cacheKey);
|
|
1322
|
+
if (!fill) {
|
|
1323
|
+
fill = makeGradientFromBBox(context, fillOp.fill, localBBox);
|
|
1324
|
+
gradientCache.set(cacheKey, fill);
|
|
1325
|
+
}
|
|
1316
1326
|
context.fillStyle = fill;
|
|
1327
|
+
context.beginPath();
|
|
1328
|
+
drawSvgPathOnCtx(context, fillOp.path);
|
|
1317
1329
|
context.fill();
|
|
1318
1330
|
context.restore();
|
|
1319
1331
|
});
|