@mintlify/og 0.0.129 → 0.0.131

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.
@@ -0,0 +1,4 @@
1
+ export declare const ogAssetSources: () => Record<string, string>;
2
+ export declare const setOgAssetDir: (dir: string) => void;
3
+ export declare const fontAssetPath: (url: URL) => string | URL;
4
+ export declare const resvgWasmPath: () => string;
package/dist/assets.js ADDED
@@ -0,0 +1,14 @@
1
+ import { createRequire } from 'node:module';
2
+ import { basename, join } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { DEFAULT_FONT_URLS, MONO_FONT_URL } from './inputs/default-font-urls.js';
5
+ const require = createRequire(import.meta.url);
6
+ const RESVG_WASM = 'resvg.wasm';
7
+ const FONT_URLS = [...Object.values(DEFAULT_FONT_URLS), MONO_FONT_URL];
8
+ let assetDir;
9
+ export const ogAssetSources = () => (Object.assign(Object.assign({}, Object.fromEntries(FONT_URLS.map((url) => [basename(url.pathname), fileURLToPath(url)]))), { [RESVG_WASM]: require.resolve('@resvg/resvg-wasm/index_bg.wasm') }));
10
+ export const setOgAssetDir = (dir) => {
11
+ assetDir = dir;
12
+ };
13
+ export const fontAssetPath = (url) => assetDir ? join(assetDir, basename(url.pathname)) : url;
14
+ export const resvgWasmPath = () => assetDir ? join(assetDir, RESVG_WASM) : require.resolve('@resvg/resvg-wasm/index_bg.wasm');
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { readFile } from 'node:fs/promises';
11
+ import { fontAssetPath } from '../assets.js';
11
12
  import { DEFAULT_FONT_FAMILY, MONO_FONT_FAMILY } from '../constants.js';
12
13
  import { DEFAULT_FONT_URLS, MONO_FONT_URL } from './default-font-urls.js';
13
14
  const FONT_WEIGHTS = [400, 500, 600, 700];
@@ -22,21 +23,21 @@ let monoFontPromise;
22
23
  const readDefaultFontFace = (weight) => __awaiter(void 0, void 0, void 0, function* () {
23
24
  return ({
24
25
  weight,
25
- data: yield readFile(DEFAULT_FONT_URLS[weight]),
26
+ data: yield readFile(fontAssetPath(DEFAULT_FONT_URLS[weight])),
26
27
  });
27
28
  });
28
29
  export const loadDefaultFont = () => {
29
- defaultFontPromise !== null && defaultFontPromise !== void 0 ? defaultFontPromise : (defaultFontPromise = Promise.all(FONT_WEIGHTS.map(readDefaultFontFace)).then((faces) => ({
30
- family: DEFAULT_FONT_FAMILY,
31
- faces,
32
- })));
30
+ defaultFontPromise !== null && defaultFontPromise !== void 0 ? defaultFontPromise : (defaultFontPromise = Promise.all(FONT_WEIGHTS.map(readDefaultFontFace)).then((faces) => ({ family: DEFAULT_FONT_FAMILY, faces }), (error) => {
31
+ defaultFontPromise = undefined;
32
+ throw error;
33
+ }));
33
34
  return defaultFontPromise;
34
35
  };
35
36
  export const loadMonoFont = () => {
36
- monoFontPromise !== null && monoFontPromise !== void 0 ? monoFontPromise : (monoFontPromise = readFile(MONO_FONT_URL).then((data) => ({
37
- family: MONO_FONT_FAMILY,
38
- faces: [{ weight: 400, data }],
39
- })));
37
+ monoFontPromise !== null && monoFontPromise !== void 0 ? monoFontPromise : (monoFontPromise = readFile(fontAssetPath(MONO_FONT_URL)).then((data) => ({ family: MONO_FONT_FAMILY, faces: [{ weight: 400, data }] }), (error) => {
38
+ monoFontPromise = undefined;
39
+ throw error;
40
+ }));
40
41
  return monoFontPromise;
41
42
  };
42
43
  const getGoogleFontCssUrl = (family, text, weight) => {
@@ -1,10 +1,9 @@
1
1
  import { initWasm } from '@resvg/resvg-wasm';
2
2
  import { readFile } from 'node:fs/promises';
3
- import { createRequire } from 'node:module';
4
- const require = createRequire(import.meta.url);
3
+ import { resvgWasmPath } from '../assets.js';
5
4
  let resvgReady;
6
5
  export const initResvg = () => {
7
- resvgReady !== null && resvgReady !== void 0 ? resvgReady : (resvgReady = initWasm(readFile(require.resolve('@resvg/resvg-wasm/index_bg.wasm'))).catch((error) => {
6
+ resvgReady !== null && resvgReady !== void 0 ? resvgReady : (resvgReady = initWasm(readFile(resvgWasmPath())).catch((error) => {
8
7
  resvgReady = undefined;
9
8
  throw error;
10
9
  }));