labellife-design-tool 2.4.5 → 2.5.0
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/README.md +14 -0
- package/dist/cjs/canvas/workspace.js +33 -9
- package/dist/cjs/canvas/workspace.js.map +1 -1
- package/dist/cjs/index.js +274 -132
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/model/store.js +112 -15
- package/dist/cjs/model/store.js.map +1 -1
- package/dist/cjs/toolbar/toolbar.js +26 -5
- package/dist/cjs/toolbar/toolbar.js.map +1 -1
- package/dist/esm/canvas/workspace.js +33 -9
- package/dist/esm/canvas/workspace.js.map +1 -1
- package/dist/esm/index.js +274 -132
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/model/store.js +112 -15
- package/dist/esm/model/store.js.map +1 -1
- package/dist/esm/toolbar/toolbar.js +26 -5
- package/dist/esm/toolbar/toolbar.js.map +1 -1
- package/package.json +3 -2
package/dist/cjs/model/store.js
CHANGED
|
@@ -1569,6 +1569,49 @@ var History = mobxStateTree.types.model('History', {
|
|
|
1569
1569
|
};
|
|
1570
1570
|
});
|
|
1571
1571
|
|
|
1572
|
+
// Infers the @font-face format() hint from a font file URL's extension.
|
|
1573
|
+
function inferFontFormat(url) {
|
|
1574
|
+
var ext = (url.split('?')[0].split('.').pop() || '').toLowerCase();
|
|
1575
|
+
var map = {
|
|
1576
|
+
woff2: 'woff2',
|
|
1577
|
+
woff: 'woff',
|
|
1578
|
+
ttf: 'truetype',
|
|
1579
|
+
otf: 'opentype'
|
|
1580
|
+
};
|
|
1581
|
+
return map[ext] || 'woff2';
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
// Neutralizes characters that could let a font `name` break out of the
|
|
1585
|
+
// single-quoted `font-family: '...'` CSS value (or the surrounding rule
|
|
1586
|
+
// block) when interpolated into injected CSS. This is defense-in-depth for
|
|
1587
|
+
// a published, general-purpose library that cannot assume every consumer
|
|
1588
|
+
// only ever passes trusted, admin-managed catalog data.
|
|
1589
|
+
function sanitizeFontFamilyName(name) {
|
|
1590
|
+
return String(name)
|
|
1591
|
+
// eslint-disable-next-line no-control-regex
|
|
1592
|
+
.replace(/['"\\{};\r\n\u0000-\u001f]/g, '').trim();
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
// Neutralizes characters that could let a font `file` URL break out of the
|
|
1596
|
+
// `url('...')` CSS value, and requires it to at least look like an
|
|
1597
|
+
// absolute http(s) URL or a relative path (not a full URL parser — this is
|
|
1598
|
+
// a simple guard, not the primary trust boundary).
|
|
1599
|
+
function sanitizeFontFileUrl(file) {
|
|
1600
|
+
var cleaned = String(file).replace(/['"()\s\r\n]/g, '');
|
|
1601
|
+
var looksSafe = /^(https?:\/\/|\.{0,2}\/)/i.test(cleaned);
|
|
1602
|
+
return looksSafe ? cleaned : '';
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
// Builds the @font-face CSS text for a custom font's uploaded variants.
|
|
1606
|
+
// `customFont` shape: { name: string, variants: [{ weight, style, file }] }
|
|
1607
|
+
function buildFontFaceCss(customFont) {
|
|
1608
|
+
var safeName = sanitizeFontFamilyName(customFont.name);
|
|
1609
|
+
return customFont.variants.map(function (v) {
|
|
1610
|
+
var safeFile = sanitizeFontFileUrl(v.file);
|
|
1611
|
+
return "@font-face {\n font-family: '".concat(safeName, "';\n font-weight: ").concat(v.weight, ";\n font-style: ").concat(v.style, ";\n src: url('").concat(safeFile, "') format('").concat(inferFontFormat(safeFile), "');\n font-display: swap;\n}");
|
|
1612
|
+
}).join('\n');
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1572
1615
|
var _excluded = ["mimeType", "quality", "dpi", "dpiMetadata"],
|
|
1573
1616
|
_excluded2 = ["mimeType", "quality"],
|
|
1574
1617
|
_excluded3 = ["fileName"],
|
|
@@ -1683,7 +1726,9 @@ var Store = mobxStateTree.types.model('Store', {
|
|
|
1683
1726
|
// null | { type: 'effects'|'mask', elementId: string }
|
|
1684
1727
|
_fontVersion: 0,
|
|
1685
1728
|
// incremented after each font load to trigger canvas re-render
|
|
1686
|
-
_pendingInputFields: []
|
|
1729
|
+
_pendingInputFields: [],
|
|
1730
|
+
// elements awaiting user input after loadJSON
|
|
1731
|
+
customFonts: [] // host-injected custom font catalog: [{ name, variants: [{weight,style,file}] }]
|
|
1687
1732
|
};
|
|
1688
1733
|
}).views(function (self) {
|
|
1689
1734
|
return {
|
|
@@ -2545,6 +2590,11 @@ var Store = mobxStateTree.types.model('Store', {
|
|
|
2545
2590
|
self.fonts.splice(idx, 1);
|
|
2546
2591
|
}
|
|
2547
2592
|
},
|
|
2593
|
+
// Full replace, mirroring `_setStageRef`'s plain-assignment style for volatile state.
|
|
2594
|
+
// Host app calls this with the complete active font list — no incremental add/remove.
|
|
2595
|
+
setCustomFonts: function setCustomFonts(fonts) {
|
|
2596
|
+
self.customFonts = fonts || [];
|
|
2597
|
+
},
|
|
2548
2598
|
addAudio: function addAudio(data) {
|
|
2549
2599
|
self.audios.push(_objectSpread2({
|
|
2550
2600
|
id: uuid.v4()
|
|
@@ -2560,15 +2610,24 @@ var Store = mobxStateTree.types.model('Store', {
|
|
|
2560
2610
|
},
|
|
2561
2611
|
loadFont: function loadFont(fontFamily) {
|
|
2562
2612
|
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
2563
|
-
var id, link, _t;
|
|
2613
|
+
var customFont, id, link, _t;
|
|
2564
2614
|
return _regenerator().w(function (_context8) {
|
|
2565
2615
|
while (1) switch (_context8.p = _context8.n) {
|
|
2566
2616
|
case 0:
|
|
2617
|
+
_context8.p = 1;
|
|
2618
|
+
customFont = self.customFonts.find(function (f) {
|
|
2619
|
+
return f.name === fontFamily;
|
|
2620
|
+
});
|
|
2621
|
+
if (!customFont) {
|
|
2622
|
+
_context8.n = 2;
|
|
2623
|
+
break;
|
|
2624
|
+
}
|
|
2625
|
+
return _context8.a(2, self._loadCustomFont(customFont));
|
|
2626
|
+
case 2:
|
|
2567
2627
|
// Load font via Google Fonts CSS API
|
|
2568
2628
|
id = "google-font-".concat(fontFamily.replace(/\s+/g, '-').toLowerCase());
|
|
2569
|
-
_context8.p = 1;
|
|
2570
2629
|
if (document.getElementById(id)) {
|
|
2571
|
-
_context8.n =
|
|
2630
|
+
_context8.n = 3;
|
|
2572
2631
|
break;
|
|
2573
2632
|
}
|
|
2574
2633
|
link = document.createElement('link');
|
|
@@ -2577,38 +2636,76 @@ var Store = mobxStateTree.types.model('Store', {
|
|
|
2577
2636
|
link.rel = 'stylesheet';
|
|
2578
2637
|
|
|
2579
2638
|
// Wait for the CSS stylesheet to load so @font-face rules are parsed
|
|
2580
|
-
_context8.n =
|
|
2639
|
+
_context8.n = 3;
|
|
2581
2640
|
return new Promise(function (resolve) {
|
|
2582
2641
|
link.onload = resolve;
|
|
2583
2642
|
link.onerror = resolve; // don't block on network errors
|
|
2584
2643
|
document.head.appendChild(link);
|
|
2585
2644
|
});
|
|
2586
|
-
case 2:
|
|
2587
|
-
_context8.n = 3;
|
|
2588
|
-
return document.fonts.load("16px \"".concat(fontFamily, "\""));
|
|
2589
2645
|
case 3:
|
|
2590
2646
|
_context8.n = 4;
|
|
2591
|
-
return document.fonts.load("
|
|
2647
|
+
return document.fonts.load("16px \"".concat(fontFamily, "\""));
|
|
2592
2648
|
case 4:
|
|
2593
2649
|
_context8.n = 5;
|
|
2594
|
-
return document.fonts.
|
|
2650
|
+
return document.fonts.load("bold 16px \"".concat(fontFamily, "\""));
|
|
2595
2651
|
case 5:
|
|
2652
|
+
_context8.n = 6;
|
|
2653
|
+
return document.fonts.ready;
|
|
2654
|
+
case 6:
|
|
2596
2655
|
// Bump version so MobX observers re-render with the real font
|
|
2597
2656
|
self._fontVersion += 1;
|
|
2598
2657
|
// Force Konva to redraw all text nodes with the newly loaded font
|
|
2599
2658
|
if (self._stageRef) {
|
|
2600
2659
|
self._stageRef.batchDraw();
|
|
2601
2660
|
}
|
|
2602
|
-
_context8.n =
|
|
2661
|
+
_context8.n = 8;
|
|
2603
2662
|
break;
|
|
2604
|
-
case
|
|
2605
|
-
_context8.p =
|
|
2663
|
+
case 7:
|
|
2664
|
+
_context8.p = 7;
|
|
2606
2665
|
_t = _context8.v;
|
|
2607
2666
|
console.warn("Failed to load font: ".concat(fontFamily), _t);
|
|
2608
|
-
case
|
|
2667
|
+
case 8:
|
|
2609
2668
|
return _context8.a(2);
|
|
2610
2669
|
}
|
|
2611
|
-
}, _callee8, null, [[1,
|
|
2670
|
+
}, _callee8, null, [[1, 7]]);
|
|
2671
|
+
}))();
|
|
2672
|
+
},
|
|
2673
|
+
_loadCustomFont: function _loadCustomFont(customFont) {
|
|
2674
|
+
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
|
|
2675
|
+
var id, styleEl, _t2;
|
|
2676
|
+
return _regenerator().w(function (_context9) {
|
|
2677
|
+
while (1) switch (_context9.p = _context9.n) {
|
|
2678
|
+
case 0:
|
|
2679
|
+
_context9.p = 0;
|
|
2680
|
+
id = "custom-font-".concat(customFont.name.replace(/\s+/g, '-').toLowerCase());
|
|
2681
|
+
if (!document.getElementById(id)) {
|
|
2682
|
+
styleEl = document.createElement('style');
|
|
2683
|
+
styleEl.id = id;
|
|
2684
|
+
styleEl.textContent = buildFontFaceCss(customFont);
|
|
2685
|
+
document.head.appendChild(styleEl);
|
|
2686
|
+
}
|
|
2687
|
+
_context9.n = 1;
|
|
2688
|
+
return Promise.all(customFont.variants.map(function (v) {
|
|
2689
|
+
return document.fonts.load("".concat(v.style === 'italic' ? 'italic ' : '').concat(v.weight, " 16px \"").concat(customFont.name, "\""));
|
|
2690
|
+
}));
|
|
2691
|
+
case 1:
|
|
2692
|
+
_context9.n = 2;
|
|
2693
|
+
return document.fonts.ready;
|
|
2694
|
+
case 2:
|
|
2695
|
+
self._fontVersion += 1;
|
|
2696
|
+
if (self._stageRef) {
|
|
2697
|
+
self._stageRef.batchDraw();
|
|
2698
|
+
}
|
|
2699
|
+
_context9.n = 4;
|
|
2700
|
+
break;
|
|
2701
|
+
case 3:
|
|
2702
|
+
_context9.p = 3;
|
|
2703
|
+
_t2 = _context9.v;
|
|
2704
|
+
console.warn("Failed to load custom font: ".concat(customFont.name), _t2);
|
|
2705
|
+
case 4:
|
|
2706
|
+
return _context9.a(2);
|
|
2707
|
+
}
|
|
2708
|
+
}, _callee9, null, [[0, 3]]);
|
|
2612
2709
|
}))();
|
|
2613
2710
|
},
|
|
2614
2711
|
_autoLoadFonts: function _autoLoadFonts(data) {
|