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
|
@@ -1255,6 +1255,16 @@ function syncHeightKeepingCenter(element, newHeight) {
|
|
|
1255
1255
|
});
|
|
1256
1256
|
}
|
|
1257
1257
|
|
|
1258
|
+
// Safari doesn't make a webfont available to canvas (not even to measureText) until some
|
|
1259
|
+
// canvas has actually drawn text with it, so loading alone isn't enough: draw once on a
|
|
1260
|
+
// hidden canvas to activate the face, then measure.
|
|
1261
|
+
var _scratchCtx = null;
|
|
1262
|
+
function primeCanvasFont(font, text) {
|
|
1263
|
+
if (!_scratchCtx) _scratchCtx = document.createElement('canvas').getContext('2d');
|
|
1264
|
+
_scratchCtx.font = font;
|
|
1265
|
+
_scratchCtx.fillText(text || 'Hamburgefonstiv', 0, 0);
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1258
1268
|
// Safari can resolve document.fonts.load() (and fire loadingdone) before the canvas
|
|
1259
1269
|
// actually renders with the new face, so a re-measure at that moment still gets
|
|
1260
1270
|
// fallback-font widths. Poll until canvas text width differs from the plain fallback's
|
|
@@ -1272,6 +1282,7 @@ function waitForCanvasFont(fontSpec, family, sample, isCancelled) {
|
|
|
1272
1282
|
var frames = 0;
|
|
1273
1283
|
var _check = function check() {
|
|
1274
1284
|
if (isCancelled() || frames >= FONT_READY_MAX_FRAMES) return resolve();
|
|
1285
|
+
primeCanvasFont("".concat(fontSpec, " \"").concat(family, "\", serif"), text);
|
|
1275
1286
|
var withFont = widthWith("".concat(fontSpec, " \"").concat(family, "\", serif"));
|
|
1276
1287
|
var withFallbackSerif = widthWith("".concat(fontSpec, " serif"));
|
|
1277
1288
|
var withFallbackSans = widthWith("".concat(fontSpec, " sans-serif"));
|
|
@@ -1282,6 +1293,28 @@ function waitForCanvasFont(fontSpec, family, sample, isCancelled) {
|
|
|
1282
1293
|
_check();
|
|
1283
1294
|
});
|
|
1284
1295
|
}
|
|
1296
|
+
|
|
1297
|
+
// TEMPORARY font-timing diagnostics. Enable in the browser console with
|
|
1298
|
+
// window.__labellifeFontDebug = true
|
|
1299
|
+
// before loading a template, then copy the "[font-debug]" lines. Remove once Safari is sorted.
|
|
1300
|
+
function fontDebug(label, element, node) {
|
|
1301
|
+
if (typeof window === 'undefined' || !window.__labellifeFontDebug) return;
|
|
1302
|
+
try {
|
|
1303
|
+
var family = element.fontFamily;
|
|
1304
|
+
var faces = [];
|
|
1305
|
+
document.fonts.forEach(function (f) {
|
|
1306
|
+
if (f.family.replace(/["']/g, '') === family) faces.push("".concat(f.weight, "/").concat(f.status, "/").concat(f.unicodeRange.slice(0, 18)));
|
|
1307
|
+
});
|
|
1308
|
+
var lines = node && node.textArr ? node.textArr.map(function (l) {
|
|
1309
|
+
return Math.round(l.width);
|
|
1310
|
+
}) : null;
|
|
1311
|
+
// eslint-disable-next-line no-console
|
|
1312
|
+
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 : '-'));
|
|
1313
|
+
} catch (e) {
|
|
1314
|
+
// eslint-disable-next-line no-console
|
|
1315
|
+
console.log('[font-debug] failed', e);
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1285
1318
|
var TextElementComponent = mobxReactLite.observer(function (_ref) {
|
|
1286
1319
|
var _element$backgroundOp;
|
|
1287
1320
|
var element = _ref.element;
|
|
@@ -1309,6 +1342,7 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
|
|
|
1309
1342
|
var _node$getLayer2;
|
|
1310
1343
|
var node = textRef.current;
|
|
1311
1344
|
if (!node) return;
|
|
1345
|
+
fontDebug('relayout:before', element, node);
|
|
1312
1346
|
|
|
1313
1347
|
// CurvedText's sceneFunc re-measures glyphs via ctx.measureText on
|
|
1314
1348
|
// every draw (no internal cached layout like Konva.Text has), so
|
|
@@ -1319,9 +1353,21 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
|
|
|
1319
1353
|
(_node$getLayer = node.getLayer()) === null || _node$getLayer === void 0 || _node$getLayer.batchDraw();
|
|
1320
1354
|
return;
|
|
1321
1355
|
}
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1356
|
+
|
|
1357
|
+
// Re-run Konva's own layout directly — what changing `align` does, which is the manual
|
|
1358
|
+
// workaround that fixes this in Safari. Toggling fontFamily is the fallback if the
|
|
1359
|
+
// private method is ever removed.
|
|
1360
|
+
if (typeof node._getContextFont === 'function') {
|
|
1361
|
+
primeCanvasFont(node._getContextFont(), node.text());
|
|
1362
|
+
}
|
|
1363
|
+
if (typeof node._setTextData === 'function') {
|
|
1364
|
+
node._setTextData();
|
|
1365
|
+
} else {
|
|
1366
|
+
var f = node.fontFamily();
|
|
1367
|
+
node.fontFamily('serif');
|
|
1368
|
+
node.fontFamily(f);
|
|
1369
|
+
}
|
|
1370
|
+
fontDebug('relayout:after', element, node);
|
|
1325
1371
|
var h = node.height();
|
|
1326
1372
|
if (h > 0) {
|
|
1327
1373
|
setTextHeight(h);
|
|
@@ -1333,12 +1379,16 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
|
|
|
1333
1379
|
}
|
|
1334
1380
|
(_node$getLayer2 = node.getLayer()) === null || _node$getLayer2 === void 0 || _node$getLayer2.batchDraw();
|
|
1335
1381
|
};
|
|
1382
|
+
React.useEffect(function () {
|
|
1383
|
+
fontDebug('mount', element, textRef.current);
|
|
1384
|
+
}, []);
|
|
1336
1385
|
|
|
1337
1386
|
// Any font finishing a load (covers fonts requested elsewhere, e.g. store.loadFont).
|
|
1338
1387
|
React.useEffect(function () {
|
|
1339
1388
|
// Two frames' delay: Safari's canvas can still be on the fallback at event time.
|
|
1340
1389
|
var onFontLoaded = function onFontLoaded() {
|
|
1341
|
-
|
|
1390
|
+
fontDebug('loadingdone', element, textRef.current);
|
|
1391
|
+
requestAnimationFrame(function () {
|
|
1342
1392
|
return requestAnimationFrame(function () {
|
|
1343
1393
|
var _relayoutRef$current;
|
|
1344
1394
|
return (_relayoutRef$current = relayoutRef.current) === null || _relayoutRef$current === void 0 ? void 0 : _relayoutRef$current.call(relayoutRef);
|
|
@@ -1369,8 +1419,17 @@ var TextElementComponent = mobxReactLite.observer(function (_ref) {
|
|
|
1369
1419
|
var _relayoutRef$current2;
|
|
1370
1420
|
if (!cancelled) (_relayoutRef$current2 = relayoutRef.current) === null || _relayoutRef$current2 === void 0 || _relayoutRef$current2.call(relayoutRef);
|
|
1371
1421
|
})["catch"](function () {});
|
|
1422
|
+
// Safari can still be on fallback metrics after the checks above, and re-measuring is
|
|
1423
|
+
// idempotent, so repeat a few times while the page settles.
|
|
1424
|
+
var retryTimers = [300, 1000, 2500].map(function (ms) {
|
|
1425
|
+
return setTimeout(function () {
|
|
1426
|
+
var _relayoutRef$current3;
|
|
1427
|
+
if (!cancelled) (_relayoutRef$current3 = relayoutRef.current) === null || _relayoutRef$current3 === void 0 || _relayoutRef$current3.call(relayoutRef);
|
|
1428
|
+
}, ms);
|
|
1429
|
+
});
|
|
1372
1430
|
return function () {
|
|
1373
1431
|
cancelled = true;
|
|
1432
|
+
retryTimers.forEach(clearTimeout);
|
|
1374
1433
|
};
|
|
1375
1434
|
}, [element.fontFamily, element.fontWeight, element.fontStyle]);
|
|
1376
1435
|
|