type FontConfig = {
  family: string;
  source: string;
  desc: {
    style: string;
    weight: string;
    variant: string;
  };
}
const fonts: FontConfig[] = [
  {
    family: 'KaTeX_AMS',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_AMS-Regular.woff")',
    desc: {
      style: 'normal',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Math',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Math-Italic.woff")',
    desc: {
      style: 'italic',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Caligraphic',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Caligraphic-Bold.woff")',
    desc: {
      style: 'normal',
      weight: '700',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Caligraphic',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Caligraphic-Regular.woff")',
    desc: {
      style: 'normal',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Fraktur',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Fraktur-Bold.woff")',
    desc: {
      style: 'normal',
      weight: '700',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Fraktur',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Fraktur-Regular.woff")',
    desc: {
      style: 'normal',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Main',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Main-Regular.woff")',
    desc: {
      style: 'normal',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Main',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Main-Bold.woff")',
    desc: {
      style: 'normal',
      weight: '700',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Main',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Main-BoldItalic.woff")',
    desc: {
      style: 'italic',
      weight: '700',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Main',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Main-Italic.woff")',
    desc: {
      style: 'italic',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Math',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Math-Italic.woff")',
    desc: {
      style: 'italic',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Math',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Math-BoldItalic.woff")',
    desc: {
      style: 'italic',
      weight: '700',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_SansSerif',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_SansSerif-Bold.woff")',
    desc: {
      style: 'normal',
      weight: '700',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_SansSerif',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_SansSerif-Regular.woff")',
    desc: {
      style: 'normal',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_SansSerif',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_SansSerif-Italic.woff")',
    desc: {
      style: 'italic',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Script',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Script-Regular.woff")',
    desc: {
      style: 'normal',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Size1',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Size1-Regular.woff")',
    desc: {
      style: 'normal',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Size2',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Size2-Regular.woff")',
    desc: {
      style: 'normal',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Size3',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Size3-Regular.woff")',
    desc: {
      style: 'normal',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Size4',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Size4-Regular.woff")',
    desc: {
      style: 'normal',
      weight: '400',
      variant: 'normal'
    }
  },
  {
    family: 'KaTeX_Typewriter',
    source: 'url("https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/ie/iePlus/fonts/KaTeX_Typewriter-Regular.woff")',
    desc: {
      style: 'normal',
      weight: '400',
      variant: 'normal'
    }
  }
];
function loadFont(font: FontConfig) {
  return new Promise((resolve, reject) => {
    uni.loadFontFace({
      family: font.family,
      source: font.source,
      desc: font.desc,
      success() {
        resolve(true);
      },
      fail(err) {
        reject(err);
      }
    });
  });
}
export function load(): Promise<number> {
  return new Promise((resolve, reject) => {
    const startTime = Date.now();
    const promises = fonts.map(font => loadFont(font));
    Promise.all(promises).then(results => {
      resolve(Date.now() - startTime);
      console.log(`字体加载成功，共加载${fonts.length}个字体，用时：${(Date.now() - startTime) / 1000}s`);
    }).catch(err => {
      reject(err);
      console.log(`字体加载失败: ${err}`);
    });
  });
}