import { readText } from '../../util'
import { createApp } from 'vue'
import CodeViewer from './CodeViewer.vue'

/**
 * 渲染文本
 * @param buffer 文本二进制内容
 * @param target 目标
 */
export default async function renderText (buffer, target) {
  const text = await readText(buffer)
  const app = createApp(CodeViewer, { value: text })
  app.mount(target)
  return {
    $el: target,
    $destroy() {
      app.unmount()
    }
  }
}
