embroidery-qc-image 1.0.33 → 1.0.34

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/index.js CHANGED
@@ -143,18 +143,30 @@ const loadFont = (fontName) => {
143
143
  }
144
144
  }
145
145
  return new Promise((resolve) => {
146
- const fontUrl = `${BASE_URLS.FONT}/${encodeURIComponent(fontName)}.woff2`;
147
- const fontFace = new FontFace(fontName, `url(${fontUrl})`);
148
- fontFace
149
- .load()
150
- .then((loadedFont) => {
151
- document.fonts.add(loadedFont);
152
- resolve();
153
- })
154
- .catch(() => {
155
- console.warn(`Could not load font ${fontName} from CDN`);
156
- resolve();
157
- });
146
+ const fontFormats = ['woff2', 'ttf', 'otf'];
147
+ let currentFormatIndex = 0;
148
+ const tryLoadFont = () => {
149
+ if (currentFormatIndex >= fontFormats.length) {
150
+ console.warn(`Could not load font ${fontName} from CDN (tried all formats)`);
151
+ resolve();
152
+ return;
153
+ }
154
+ const format = fontFormats[currentFormatIndex];
155
+ const fontUrl = `${BASE_URLS.FONT}/${encodeURIComponent(fontName)}.${format}`;
156
+ const fontFace = new FontFace(fontName, `url(${fontUrl})`);
157
+ fontFace
158
+ .load()
159
+ .then((loadedFont) => {
160
+ document.fonts.add(loadedFont);
161
+ resolve();
162
+ })
163
+ .catch(() => {
164
+ // Try next format
165
+ currentFormatIndex++;
166
+ tryLoadFont();
167
+ });
168
+ };
169
+ tryLoadFont();
158
170
  });
159
171
  };
160
172
  const getImageUrl = (type, value) => {