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