html2canvas-pro 2.4.1 → 2.4.3

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * html2canvas-pro 2.4.1 <https://yorickshan.github.io/html2canvas-pro/>
2
+ * html2canvas-pro 2.4.3 <https://yorickshan.github.io/html2canvas-pro/>
3
3
  * Copyright (c) 2024-present yorickshan and html2canvas-pro contributors
4
4
  * Released under MIT License
5
5
  */
@@ -5328,10 +5328,15 @@ const fontFamily = {
5328
5328
  parse: (_context, tokens) => {
5329
5329
  const accumulator = [];
5330
5330
  const results = [];
5331
+ const quoted = [];
5332
+ let isQuoted = false;
5331
5333
  tokens.forEach((token) => {
5332
5334
  switch (token.type) {
5333
5335
  case 20:
5336
+ accumulator.push(token.value);
5337
+ break;
5334
5338
  case 0:
5339
+ isQuoted = true;
5335
5340
  accumulator.push(token.value);
5336
5341
  break;
5337
5342
  case 17:
@@ -5339,12 +5344,17 @@ const fontFamily = {
5339
5344
  break;
5340
5345
  case 4:
5341
5346
  results.push(accumulator.join(" "));
5347
+ quoted.push(isQuoted);
5348
+ isQuoted = false;
5342
5349
  accumulator.length = 0;
5343
5350
  break;
5344
5351
  }
5345
5352
  });
5346
- if (accumulator.length) results.push(accumulator.join(" "));
5347
- return results.map((result) => result.indexOf(" ") === -1 ? result : `'${result}'`);
5353
+ if (accumulator.length) {
5354
+ results.push(accumulator.join(" "));
5355
+ quoted.push(isQuoted);
5356
+ }
5357
+ return results.map((result, index) => quoted[index] || result.indexOf(" ") !== -1 ? `'${result.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\a ").replace(/\r/g, "\\d ").replace(/\f/g, "\\c ")}'` : result);
5348
5358
  }
5349
5359
  };
5350
5360
  //#endregion
@@ -9733,21 +9743,20 @@ var BackgroundRenderer = class {
9733
9743
  }
9734
9744
  if (rx > 0 && ry > 0) {
9735
9745
  const cacheKey = `rg|${Math.round(x)}x${Math.round(y)}|${Math.round(rx)}x${Math.round(ry)}|${JSON.stringify(backgroundImage.stops)}`;
9746
+ const stops = processColorStops(backgroundImage.stops, rx * 2);
9747
+ const lastStop = stops[stops.length - 1];
9736
9748
  let pattern = this.patternCache.get(cacheKey);
9737
9749
  if (!pattern) {
9738
- const ownerDocument = this.canvas.ownerDocument ?? document;
9739
- const size = Math.ceil(Math.max(rx, ry) * 2);
9740
- const offscreen = ownerDocument.createElement("canvas");
9741
- offscreen.width = size;
9742
- offscreen.height = size;
9750
+ const offscreen = (this.canvas.ownerDocument ?? document).createElement("canvas");
9751
+ offscreen.width = Math.ceil(rx * 2);
9752
+ offscreen.height = Math.ceil(ry * 2);
9743
9753
  const offCtx = offscreen.getContext("2d");
9744
9754
  if (offCtx) {
9745
- const offRadius = Math.max(rx, ry);
9746
- const gradient = offCtx.createRadialGradient(offRadius, offRadius, 0, offRadius, offRadius, offRadius);
9747
- processColorStops(backgroundImage.stops, offRadius * 2).forEach((s) => gradient.addColorStop(s.stop, asString(s.color)));
9755
+ const gradient = offCtx.createRadialGradient(rx, rx, 0, rx, rx, rx);
9756
+ stops.forEach((s) => gradient.addColorStop(s.stop, asString(s.color)));
9748
9757
  offCtx.fillStyle = gradient;
9749
9758
  if (rx !== ry) offCtx.scale(1, ry / rx);
9750
- offCtx.fillRect(0, 0, offRadius * 2, offRadius * 2);
9759
+ offCtx.fillRect(0, 0, rx * 2, rx * 2);
9751
9760
  pattern = this.ctx.createPattern(offscreen, "no-repeat");
9752
9761
  this.patternCache.set(cacheKey, pattern);
9753
9762
  }
@@ -9756,9 +9765,13 @@ var BackgroundRenderer = class {
9756
9765
  this.path(path);
9757
9766
  this.ctx.save();
9758
9767
  this.ctx.clip();
9759
- this.ctx.translate(left + x - Math.max(rx, ry), top + y - Math.max(rx, ry));
9768
+ if (lastStop) {
9769
+ this.ctx.fillStyle = asString(lastStop.color);
9770
+ this.ctx.fill();
9771
+ }
9772
+ this.ctx.translate(left + x - rx, top + y - ry);
9760
9773
  this.ctx.fillStyle = pattern;
9761
- this.ctx.fillRect(0, 0, Math.max(rx, ry) * 2, Math.max(rx, ry) * 2);
9774
+ this.ctx.fillRect(0, 0, rx * 2, ry * 2);
9762
9775
  this.ctx.restore();
9763
9776
  }
9764
9777
  }