@imposium-hub/components 1.38.4 → 1.38.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/components/compositions/TextLayer.tsx +17 -5
- package/dist/components.js +38198 -3
- package/dist/components.js.map +1 -1
- package/package.json +1 -1
- package/services/API.ts +20 -0
|
@@ -12,6 +12,7 @@ interface ITextLayerProps {
|
|
|
12
12
|
|
|
13
13
|
interface ITextLayerState {
|
|
14
14
|
fontLoaded : boolean;
|
|
15
|
+
fontError : boolean;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export default class TextLayer extends React.PureComponent<ITextLayerProps, ITextLayerState> {
|
|
@@ -89,11 +90,15 @@ export default class TextLayer extends React.PureComponent<ITextLayerProps, ITex
|
|
|
89
90
|
if (font_type === FONT_TYPES.CUSTOM && font_size && custom_font_url) {
|
|
90
91
|
|
|
91
92
|
const fontOrigin = s3Url(custom_font_url, ASSET_DISTRO, ASSET_ORIGIN);
|
|
92
|
-
|
|
93
|
+
let fontLoaded = false;
|
|
93
94
|
// Not sure why you need to pass the size in here, but .check() throws an error without it.
|
|
94
|
-
|
|
95
|
+
try {
|
|
96
|
+
fontLoaded = document.fonts.check(`${font_size}px ${font}`);
|
|
97
|
+
} catch {
|
|
98
|
+
this.errorLoadingFont();
|
|
99
|
+
}
|
|
95
100
|
|
|
96
|
-
if (!
|
|
101
|
+
if (!fontLoaded) {
|
|
97
102
|
this.setState({
|
|
98
103
|
fontLoaded: false
|
|
99
104
|
}, () => {
|
|
@@ -158,7 +163,12 @@ export default class TextLayer extends React.PureComponent<ITextLayerProps, ITex
|
|
|
158
163
|
}
|
|
159
164
|
|
|
160
165
|
private errorLoadingFont() {
|
|
161
|
-
|
|
166
|
+
|
|
167
|
+
this.setState({
|
|
168
|
+
fontError: true
|
|
169
|
+
}, () => {
|
|
170
|
+
this.fontReady();
|
|
171
|
+
});
|
|
162
172
|
}
|
|
163
173
|
|
|
164
174
|
private fontReady() {
|
|
@@ -187,6 +197,8 @@ export default class TextLayer extends React.PureComponent<ITextLayerProps, ITex
|
|
|
187
197
|
const {options: {color, background_color, line_height, word_spacing,
|
|
188
198
|
letter_spacing, font_size, font, horizontal_alignment, vertical_alignment, text_wrap}} = this.props;
|
|
189
199
|
|
|
200
|
+
const {fontError} = this.state;
|
|
201
|
+
|
|
190
202
|
const whiteSpace = (text_wrap) ? 'normal' : 'nowrap';
|
|
191
203
|
const lS = (letter_spacing) ? `${letter_spacing}px` : 'normal';
|
|
192
204
|
const wS = (word_spacing) ? `${word_spacing}px` : 'normal';
|
|
@@ -200,7 +212,7 @@ export default class TextLayer extends React.PureComponent<ITextLayerProps, ITex
|
|
|
200
212
|
letterSpacing: lS,
|
|
201
213
|
fontSize: fS,
|
|
202
214
|
whiteSpace: whiteSpace as any,
|
|
203
|
-
fontFamily: font
|
|
215
|
+
fontFamily: (!fontError) ? font : 'Arial, helvetica, sans-serif'
|
|
204
216
|
};
|
|
205
217
|
|
|
206
218
|
const wrapperStyle = {
|