labellife-design-tool 2.5.7 → 2.5.8
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/canvas/workspace.js +63 -4
- package/dist/cjs/canvas/workspace.js.map +1 -1
- package/dist/cjs/index.js +63 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/canvas/workspace.js +63 -4
- package/dist/esm/canvas/workspace.js.map +1 -1
- package/dist/esm/index.js +63 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -11580,6 +11580,16 @@ function syncHeightKeepingCenter(element, newHeight) {
|
|
|
11580
11580
|
});
|
|
11581
11581
|
}
|
|
11582
11582
|
|
|
11583
|
+
// Safari doesn't make a webfont available to canvas (not even to measureText) until some
|
|
11584
|
+
// canvas has actually drawn text with it, so loading alone isn't enough: draw once on a
|
|
11585
|
+
// hidden canvas to activate the face, then measure.
|
|
11586
|
+
var _scratchCtx = null;
|
|
11587
|
+
function primeCanvasFont(font, text) {
|
|
11588
|
+
if (!_scratchCtx) _scratchCtx = document.createElement('canvas').getContext('2d');
|
|
11589
|
+
_scratchCtx.font = font;
|
|
11590
|
+
_scratchCtx.fillText(text || 'Hamburgefonstiv', 0, 0);
|
|
11591
|
+
}
|
|
11592
|
+
|
|
11583
11593
|
// Safari can resolve document.fonts.load() (and fire loadingdone) before the canvas
|
|
11584
11594
|
// actually renders with the new face, so a re-measure at that moment still gets
|
|
11585
11595
|
// fallback-font widths. Poll until canvas text width differs from the plain fallback's
|
|
@@ -11597,6 +11607,7 @@ function waitForCanvasFont(fontSpec, family, sample, isCancelled) {
|
|
|
11597
11607
|
var frames = 0;
|
|
11598
11608
|
var _check = function check() {
|
|
11599
11609
|
if (isCancelled() || frames >= FONT_READY_MAX_FRAMES) return resolve();
|
|
11610
|
+
primeCanvasFont("".concat(fontSpec, " \"").concat(family, "\", serif"), text);
|
|
11600
11611
|
var withFont = widthWith("".concat(fontSpec, " \"").concat(family, "\", serif"));
|
|
11601
11612
|
var withFallbackSerif = widthWith("".concat(fontSpec, " serif"));
|
|
11602
11613
|
var withFallbackSans = widthWith("".concat(fontSpec, " sans-serif"));
|
|
@@ -11607,6 +11618,28 @@ function waitForCanvasFont(fontSpec, family, sample, isCancelled) {
|
|
|
11607
11618
|
_check();
|
|
11608
11619
|
});
|
|
11609
11620
|
}
|
|
11621
|
+
|
|
11622
|
+
// TEMPORARY font-timing diagnostics. Enable in the browser console with
|
|
11623
|
+
// window.__labellifeFontDebug = true
|
|
11624
|
+
// before loading a template, then copy the "[font-debug]" lines. Remove once Safari is sorted.
|
|
11625
|
+
function fontDebug(label, element, node) {
|
|
11626
|
+
if (typeof window === 'undefined' || !window.__labellifeFontDebug) return;
|
|
11627
|
+
try {
|
|
11628
|
+
var family = element.fontFamily;
|
|
11629
|
+
var faces = [];
|
|
11630
|
+
document.fonts.forEach(function (f) {
|
|
11631
|
+
if (f.family.replace(/["']/g, '') === family) faces.push("".concat(f.weight, "/").concat(f.status, "/").concat(f.unicodeRange.slice(0, 18)));
|
|
11632
|
+
});
|
|
11633
|
+
var lines = node && node.textArr ? node.textArr.map(function (l) {
|
|
11634
|
+
return Math.round(l.width);
|
|
11635
|
+
}) : null;
|
|
11636
|
+
// eslint-disable-next-line no-console
|
|
11637
|
+
console.log("[font-debug] t=".concat(Math.round(performance.now()), " ").concat(label, " family=\"").concat(family, "\" ") + "check=".concat(document.fonts.check("16px \"".concat(family, "\"")), " faces=").concat(JSON.stringify(faces), " ") + "boxW=".concat(Math.round(element.width), " nodeW=").concat(node ? Math.round(node.width()) : '-', " ") + "lineWidths=".concat(JSON.stringify(lines), " lines=").concat(lines ? lines.length : '-'));
|
|
11638
|
+
} catch (e) {
|
|
11639
|
+
// eslint-disable-next-line no-console
|
|
11640
|
+
console.log('[font-debug] failed', e);
|
|
11641
|
+
}
|
|
11642
|
+
}
|
|
11610
11643
|
var TextElementComponent = observer(function (_ref) {
|
|
11611
11644
|
var _element$backgroundOp;
|
|
11612
11645
|
var element = _ref.element;
|
|
@@ -11634,6 +11667,7 @@ var TextElementComponent = observer(function (_ref) {
|
|
|
11634
11667
|
var _node$getLayer2;
|
|
11635
11668
|
var node = textRef.current;
|
|
11636
11669
|
if (!node) return;
|
|
11670
|
+
fontDebug('relayout:before', element, node);
|
|
11637
11671
|
|
|
11638
11672
|
// CurvedText's sceneFunc re-measures glyphs via ctx.measureText on
|
|
11639
11673
|
// every draw (no internal cached layout like Konva.Text has), so
|
|
@@ -11644,9 +11678,21 @@ var TextElementComponent = observer(function (_ref) {
|
|
|
11644
11678
|
(_node$getLayer = node.getLayer()) === null || _node$getLayer === void 0 || _node$getLayer.batchDraw();
|
|
11645
11679
|
return;
|
|
11646
11680
|
}
|
|
11647
|
-
|
|
11648
|
-
|
|
11649
|
-
|
|
11681
|
+
|
|
11682
|
+
// Re-run Konva's own layout directly — what changing `align` does, which is the manual
|
|
11683
|
+
// workaround that fixes this in Safari. Toggling fontFamily is the fallback if the
|
|
11684
|
+
// private method is ever removed.
|
|
11685
|
+
if (typeof node._getContextFont === 'function') {
|
|
11686
|
+
primeCanvasFont(node._getContextFont(), node.text());
|
|
11687
|
+
}
|
|
11688
|
+
if (typeof node._setTextData === 'function') {
|
|
11689
|
+
node._setTextData();
|
|
11690
|
+
} else {
|
|
11691
|
+
var f = node.fontFamily();
|
|
11692
|
+
node.fontFamily('serif');
|
|
11693
|
+
node.fontFamily(f);
|
|
11694
|
+
}
|
|
11695
|
+
fontDebug('relayout:after', element, node);
|
|
11650
11696
|
var h = node.height();
|
|
11651
11697
|
if (h > 0) {
|
|
11652
11698
|
setTextHeight(h);
|
|
@@ -11658,12 +11704,16 @@ var TextElementComponent = observer(function (_ref) {
|
|
|
11658
11704
|
}
|
|
11659
11705
|
(_node$getLayer2 = node.getLayer()) === null || _node$getLayer2 === void 0 || _node$getLayer2.batchDraw();
|
|
11660
11706
|
};
|
|
11707
|
+
useEffect(function () {
|
|
11708
|
+
fontDebug('mount', element, textRef.current);
|
|
11709
|
+
}, []);
|
|
11661
11710
|
|
|
11662
11711
|
// Any font finishing a load (covers fonts requested elsewhere, e.g. store.loadFont).
|
|
11663
11712
|
useEffect(function () {
|
|
11664
11713
|
// Two frames' delay: Safari's canvas can still be on the fallback at event time.
|
|
11665
11714
|
var onFontLoaded = function onFontLoaded() {
|
|
11666
|
-
|
|
11715
|
+
fontDebug('loadingdone', element, textRef.current);
|
|
11716
|
+
requestAnimationFrame(function () {
|
|
11667
11717
|
return requestAnimationFrame(function () {
|
|
11668
11718
|
var _relayoutRef$current;
|
|
11669
11719
|
return (_relayoutRef$current = relayoutRef.current) === null || _relayoutRef$current === void 0 ? void 0 : _relayoutRef$current.call(relayoutRef);
|
|
@@ -11694,8 +11744,17 @@ var TextElementComponent = observer(function (_ref) {
|
|
|
11694
11744
|
var _relayoutRef$current2;
|
|
11695
11745
|
if (!cancelled) (_relayoutRef$current2 = relayoutRef.current) === null || _relayoutRef$current2 === void 0 || _relayoutRef$current2.call(relayoutRef);
|
|
11696
11746
|
})["catch"](function () {});
|
|
11747
|
+
// Safari can still be on fallback metrics after the checks above, and re-measuring is
|
|
11748
|
+
// idempotent, so repeat a few times while the page settles.
|
|
11749
|
+
var retryTimers = [300, 1000, 2500].map(function (ms) {
|
|
11750
|
+
return setTimeout(function () {
|
|
11751
|
+
var _relayoutRef$current3;
|
|
11752
|
+
if (!cancelled) (_relayoutRef$current3 = relayoutRef.current) === null || _relayoutRef$current3 === void 0 || _relayoutRef$current3.call(relayoutRef);
|
|
11753
|
+
}, ms);
|
|
11754
|
+
});
|
|
11697
11755
|
return function () {
|
|
11698
11756
|
cancelled = true;
|
|
11757
|
+
retryTimers.forEach(clearTimeout);
|
|
11699
11758
|
};
|
|
11700
11759
|
}, [element.fontFamily, element.fontWeight, element.fontStyle]);
|
|
11701
11760
|
|