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 +36 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/model/store.js +36 -5
- package/dist/cjs/model/store.js.map +1 -1
- package/dist/esm/index.js +36 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/model/store.js +36 -5
- package/dist/esm/model/store.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/model/store.js
CHANGED
|
@@ -1897,7 +1897,7 @@ var Store = types.model('Store', {
|
|
|
1897
1897
|
_toCanvas: function _toCanvas() {
|
|
1898
1898
|
var _arguments = arguments;
|
|
1899
1899
|
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
1900
|
-
var _ref4, _ref4$pixelRatio, pixelRatio, pageId, _ref4$mimeType, mimeType, stage, page, layer, prevX, prevY, prevScaleX, prevScaleY, displayOnlyNodes, transformerNodes, rawCanvas, finalCanvas, ctx;
|
|
1900
|
+
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;
|
|
1901
1901
|
return _regenerator().w(function (_context) {
|
|
1902
1902
|
while (1) switch (_context.n) {
|
|
1903
1903
|
case 0:
|
|
@@ -1928,10 +1928,39 @@ var Store = types.model('Store', {
|
|
|
1928
1928
|
}
|
|
1929
1929
|
throw new Error('No layer found in stage for export.');
|
|
1930
1930
|
case 3:
|
|
1931
|
+
// Ensure all fonts used in text elements are fully loaded before rendering.
|
|
1932
|
+
// _autoLoadFonts fires them asynchronously after loadJSON; without this
|
|
1933
|
+
// await the export can run before they arrive, causing the fallback font to
|
|
1934
|
+
// be used which produces garbled / mis-sized text in the output image.
|
|
1935
|
+
fontFamilies = new Set();
|
|
1936
|
+
_collectFonts = function collectFonts(elements) {
|
|
1937
|
+
elements.forEach(function (el) {
|
|
1938
|
+
if (el.type === 'text' && el.fontFamily) fontFamilies.add(el.fontFamily);
|
|
1939
|
+
if (Array.isArray(el.children)) _collectFonts(el.children);
|
|
1940
|
+
});
|
|
1941
|
+
};
|
|
1942
|
+
_collectFonts(page.children || []);
|
|
1943
|
+
if (!(fontFamilies.size > 0)) {
|
|
1944
|
+
_context.n = 4;
|
|
1945
|
+
break;
|
|
1946
|
+
}
|
|
1947
|
+
_context.n = 4;
|
|
1948
|
+
return Promise.allSettled(_toConsumableArray(fontFamilies).flatMap(function (f) {
|
|
1949
|
+
return [document.fonts.load("16px \"".concat(f, "\"")), document.fonts.load("bold 16px \"".concat(f, "\""))];
|
|
1950
|
+
}));
|
|
1951
|
+
case 4:
|
|
1931
1952
|
prevX = layer.x();
|
|
1932
1953
|
prevY = layer.y();
|
|
1933
1954
|
prevScaleX = layer.scaleX();
|
|
1934
|
-
prevScaleY = layer.scaleY();
|
|
1955
|
+
prevScaleY = layer.scaleY(); // Temporarily resize the stage to the exact design dimensions.
|
|
1956
|
+
// The viewport (stage) is usually smaller than the design when the design is
|
|
1957
|
+
// taller/wider than the screen. layer.draw() renders to the stage canvas, so
|
|
1958
|
+
// without this resize any element below stageSize.height would be clipped in
|
|
1959
|
+
// the internal canvas and potentially bleed into the export.
|
|
1960
|
+
prevStageWidth = stage.width();
|
|
1961
|
+
prevStageHeight = stage.height();
|
|
1962
|
+
stage.width(self.width);
|
|
1963
|
+
stage.height(self.height);
|
|
1935
1964
|
layer.x(0);
|
|
1936
1965
|
layer.y(0);
|
|
1937
1966
|
layer.scaleX(1);
|
|
@@ -1963,17 +1992,19 @@ var Store = types.model('Store', {
|
|
|
1963
1992
|
return n.show();
|
|
1964
1993
|
});
|
|
1965
1994
|
|
|
1966
|
-
// Restore layer transform
|
|
1995
|
+
// Restore layer transform and stage dimensions
|
|
1967
1996
|
layer.x(prevX);
|
|
1968
1997
|
layer.y(prevY);
|
|
1969
1998
|
layer.scaleX(prevScaleX);
|
|
1970
1999
|
layer.scaleY(prevScaleY);
|
|
2000
|
+
stage.width(prevStageWidth);
|
|
2001
|
+
stage.height(prevStageHeight);
|
|
1971
2002
|
layer.draw();
|
|
1972
2003
|
|
|
1973
2004
|
// For JPEG, composite onto a white canvas to eliminate any remaining transparency
|
|
1974
2005
|
// (avoids black areas and reduces file size vs checkerboard patterns)
|
|
1975
2006
|
if (!(mimeType === 'image/jpeg')) {
|
|
1976
|
-
_context.n =
|
|
2007
|
+
_context.n = 5;
|
|
1977
2008
|
break;
|
|
1978
2009
|
}
|
|
1979
2010
|
finalCanvas = document.createElement('canvas');
|
|
@@ -1984,7 +2015,7 @@ var Store = types.model('Store', {
|
|
|
1984
2015
|
ctx.fillRect(0, 0, finalCanvas.width, finalCanvas.height);
|
|
1985
2016
|
ctx.drawImage(rawCanvas, 0, 0);
|
|
1986
2017
|
return _context.a(2, finalCanvas);
|
|
1987
|
-
case
|
|
2018
|
+
case 5:
|
|
1988
2019
|
return _context.a(2, rawCanvas);
|
|
1989
2020
|
}
|
|
1990
2021
|
}, _callee);
|