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