59bb7fbc12
This is once again a huge commit, but its mostly performance improvements along with some bug fixes and refactoring. It also includes changes to the theming systems. I'm still not 100% happy with the theming system, but its better than before. Model fetching has been dramatically improved! Nearly all the important computation and pre-processing has been moved to the server. This has also somehow fixed the way model details are loaded, which was causing many models to be missing their details despite models.dev having them. The markdown renderer has once again been changed, but I'm mostly certain that this is the last time major changes will be made to it. The renderer is not spamming components, bloating memory usage, and its not using a bug prone custom written chunking system. There's also a lot more that I haven't mentioned and honestly forgot. I need to get better commit hygiene tbh.
26 lines
737 B
TypeScript
26 lines
737 B
TypeScript
import { createShiki } from '~/utils/shiki'
|
|
import { type HighlighterCore } from 'shiki/core'
|
|
|
|
import { expose } from 'comlink'
|
|
|
|
let shiki: HighlighterCore | null = null
|
|
|
|
const api = {
|
|
async init() {
|
|
if (shiki) return
|
|
shiki = await createShiki()
|
|
},
|
|
async codeToHtml(code: string, options: { lang: string, themes: { light: string, dark: string } }) {
|
|
if (!shiki) throw new Error('shiki not initialized')
|
|
return shiki.codeToHtml(code, options)
|
|
},
|
|
async getLanguage(lang: string) {
|
|
if (!shiki) throw new Error('shiki not initialized')
|
|
const grammar = shiki.getLanguage(lang);
|
|
return { name: grammar.name }
|
|
}
|
|
}
|
|
|
|
expose(api)
|
|
export type ShikiWorker = typeof api
|