labellife-design-tool 2.3.5 → 2.3.6

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/esm/index.js CHANGED
@@ -1971,7 +1971,7 @@ var Store = types.model('Store', {
1971
1971
  _toCanvas: function _toCanvas() {
1972
1972
  var _arguments = arguments;
1973
1973
  return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
1974
- var _ref4, _ref4$pixelRatio, pixelRatio, pageId, _ref4$mimeType, mimeType, stage, page, layer, prevX, prevY, prevScaleX, prevScaleY, displayOnlyNodes, transformerNodes, rawCanvas, finalCanvas, ctx;
1974
+ var _ref4, _ref4$pixelRatio, pixelRatio, pageId, _ref4$mimeType, mimeType, stage, page, layer, fontFamilies, _collectFonts, prevX, prevY, prevScaleX, prevScaleY, prevStageWidth, prevStageHeight, displayOnlyNodes, transformerNodes, rawCanvas, finalCanvas, ctx;
1975
1975
  return _regenerator().w(function (_context) {
1976
1976
  while (1) switch (_context.n) {
1977
1977
  case 0:
@@ -2002,10 +2002,39 @@ var Store = types.model('Store', {
2002
2002
  }
2003
2003
  throw new Error('No layer found in stage for export.');
2004
2004
  case 3:
2005
+ // Ensure all fonts used in text elements are fully loaded before rendering.
2006
+ // _autoLoadFonts fires them asynchronously after loadJSON; without this
2007
+ // await the export can run before they arrive, causing the fallback font to
2008
+ // be used which produces garbled / mis-sized text in the output image.
2009
+ fontFamilies = new Set();
2010
+ _collectFonts = function collectFonts(elements) {
2011
+ elements.forEach(function (el) {
2012
+ if (el.type === 'text' && el.fontFamily) fontFamilies.add(el.fontFamily);
2013
+ if (Array.isArray(el.children)) _collectFonts(el.children);
2014
+ });
2015
+ };
2016
+ _collectFonts(page.children || []);
2017
+ if (!(fontFamilies.size > 0)) {
2018
+ _context.n = 4;
2019
+ break;
2020
+ }
2021
+ _context.n = 4;
2022
+ return Promise.allSettled(_toConsumableArray(fontFamilies).flatMap(function (f) {
2023
+ return [document.fonts.load("16px \"".concat(f, "\"")), document.fonts.load("bold 16px \"".concat(f, "\""))];
2024
+ }));
2025
+ case 4:
2005
2026
  prevX = layer.x();
2006
2027
  prevY = layer.y();
2007
2028
  prevScaleX = layer.scaleX();
2008
- prevScaleY = layer.scaleY();
2029
+ prevScaleY = layer.scaleY(); // Temporarily resize the stage to the exact design dimensions.
2030
+ // The viewport (stage) is usually smaller than the design when the design is
2031
+ // taller/wider than the screen. layer.draw() renders to the stage canvas, so
2032
+ // without this resize any element below stageSize.height would be clipped in
2033
+ // the internal canvas and potentially bleed into the export.
2034
+ prevStageWidth = stage.width();
2035
+ prevStageHeight = stage.height();
2036
+ stage.width(self.width);
2037
+ stage.height(self.height);
2009
2038
  layer.x(0);
2010
2039
  layer.y(0);
2011
2040
  layer.scaleX(1);
@@ -2037,17 +2066,19 @@ var Store = types.model('Store', {
2037
2066
  return n.show();
2038
2067
  });
2039
2068
 
2040
- // Restore layer transform
2069
+ // Restore layer transform and stage dimensions
2041
2070
  layer.x(prevX);
2042
2071
  layer.y(prevY);
2043
2072
  layer.scaleX(prevScaleX);
2044
2073
  layer.scaleY(prevScaleY);
2074
+ stage.width(prevStageWidth);
2075
+ stage.height(prevStageHeight);
2045
2076
  layer.draw();
2046
2077
 
2047
2078
  // For JPEG, composite onto a white canvas to eliminate any remaining transparency
2048
2079
  // (avoids black areas and reduces file size vs checkerboard patterns)
2049
2080
  if (!(mimeType === 'image/jpeg')) {
2050
- _context.n = 4;
2081
+ _context.n = 5;
2051
2082
  break;
2052
2083
  }
2053
2084
  finalCanvas = document.createElement('canvas');
@@ -2058,7 +2089,7 @@ var Store = types.model('Store', {
2058
2089
  ctx.fillRect(0, 0, finalCanvas.width, finalCanvas.height);
2059
2090
  ctx.drawImage(rawCanvas, 0, 0);
2060
2091
  return _context.a(2, finalCanvas);
2061
- case 4:
2092
+ case 5:
2062
2093
  return _context.a(2, rawCanvas);
2063
2094
  }
2064
2095
  }, _callee);