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