mirror of
https://github.com/purocean/yn.git
synced 2026-09-24 15:46:02 +08:00
upd: remove ctx.utils.dataURItoBlobLink method
This commit is contained in:
@@ -5,7 +5,7 @@ import type { Plugin } from '@fe/context'
|
||||
import { getColorScheme } from '@fe/services/theme'
|
||||
import { debounce } from 'lodash-es'
|
||||
import { registerHook, removeHook } from '@fe/core/hook'
|
||||
import { dataURItoBlobLink, getLogger, sleep } from '@fe/utils'
|
||||
import { downloadDataURL, getLogger, sleep } from '@fe/utils'
|
||||
import type { ExportTypes } from '@fe/types'
|
||||
|
||||
const logger = getLogger('echarts')
|
||||
@@ -95,11 +95,7 @@ const Echarts = defineComponent({
|
||||
return
|
||||
}
|
||||
|
||||
const link = document.createElement('a')
|
||||
link.href = dataURItoBlobLink(chart.getDataURL({ type, pixelRatio: 2 }))
|
||||
link.target = '_blank'
|
||||
link.download = `echarts-${Date.now()}.${type}`
|
||||
link.click()
|
||||
downloadDataURL(`echarts-${Date.now()}.${type}`, chart.getDataURL({ type, pixelRatio: 2 }))
|
||||
}
|
||||
|
||||
watch(() => props.code, () => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import mermaid from 'mermaid/dist/mermaid.js'
|
||||
import { defineComponent, h, onMounted, ref, watch } from 'vue'
|
||||
import type { Plugin } from '@fe/context'
|
||||
import { debounce } from 'lodash-es'
|
||||
import { dataURItoBlobLink, getLogger, strToBase64 } from '@fe/utils'
|
||||
import { downloadDataURL, getLogger, strToBase64 } from '@fe/utils'
|
||||
|
||||
const logger = getLogger('mermaid')
|
||||
|
||||
@@ -39,11 +39,7 @@ const Mermaid = defineComponent({
|
||||
return
|
||||
}
|
||||
|
||||
const link = document.createElement('a')
|
||||
link.href = dataURItoBlobLink('data:image/svg+xml;base64,' + strToBase64(svg))
|
||||
link.target = '_blank'
|
||||
link.download = `mermaid-${Date.now()}.svg`
|
||||
link.click()
|
||||
downloadDataURL(`mermaid-${Date.now()}.svg`, 'data:image/svg+xml;base64,' + strToBase64(svg))
|
||||
}
|
||||
|
||||
const renderDebounce = debounce(render, 100)
|
||||
|
||||
@@ -2,7 +2,7 @@ import { defineComponent, h, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { debounce } from 'lodash-es'
|
||||
import Renderer from 'markdown-it/lib/renderer'
|
||||
import { Plugin } from '@fe/context'
|
||||
import { dataURItoBlobLink, getLogger, strToBase64 } from '@fe/utils'
|
||||
import { downloadDataURL, getLogger, strToBase64 } from '@fe/utils'
|
||||
import { openWindow } from '@fe/support/env'
|
||||
import * as storage from '@fe/utils/storage'
|
||||
import { buildSrc } from '@fe/support/embed'
|
||||
@@ -276,25 +276,17 @@ const init = (ele: HTMLElement) => {
|
||||
}
|
||||
|
||||
const exportData = async (type: 'png' | 'svg' | 'km') => {
|
||||
const download = (url: string, name: string) => {
|
||||
const link = document.createElement('a')
|
||||
link.href = dataURItoBlobLink(url)
|
||||
link.target = '_blank'
|
||||
link.download = name
|
||||
link.click()
|
||||
}
|
||||
|
||||
const filename = `mindmap-${Date.now()}.${type}`
|
||||
|
||||
switch (type) {
|
||||
case 'svg':
|
||||
download('data:image/svg+xml;base64,' + strToBase64(await km.exportData('svg')), filename)
|
||||
downloadDataURL(filename, 'data:image/svg+xml;base64,' + strToBase64(await km.exportData('svg')))
|
||||
break
|
||||
case 'km':
|
||||
download('data:application/octet-stream;base64,' + strToBase64(await km.exportData('json')), filename)
|
||||
downloadDataURL(filename, 'data:application/octet-stream;base64,' + strToBase64(await km.exportData('json')))
|
||||
break
|
||||
case 'png':
|
||||
download(await km.exportData('png'), filename)
|
||||
downloadDataURL(filename, await km.exportData('png'))
|
||||
break
|
||||
default:
|
||||
break
|
||||
|
||||
@@ -23,20 +23,6 @@ export function encodeMarkdownLink (path: string) {
|
||||
.replace(/ /g, '%20')
|
||||
}
|
||||
|
||||
export function dataURItoBlobLink (dataURI: string) {
|
||||
const byteString = atob(dataURI.split(',')[1])
|
||||
const mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
|
||||
const ab = new ArrayBuffer(byteString.length)
|
||||
const ia = new Uint8Array(ab)
|
||||
|
||||
for (let i = 0; i < byteString.length; i++) {
|
||||
ia[i] = byteString.charCodeAt(i)
|
||||
}
|
||||
|
||||
const blob = new Blob([ab], { type: mimeString })
|
||||
return window.URL.createObjectURL(blob)
|
||||
}
|
||||
|
||||
export function fileToBase64URL (file: File | Blob) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
const fr = new FileReader()
|
||||
@@ -76,12 +62,13 @@ export function objectInsertAfterKey (obj: {}, key: string, content: {}) {
|
||||
return Object.fromEntries(items)
|
||||
}
|
||||
|
||||
export function downloadContent (filename: string, content: Buffer | string, type = 'application/octet-stream') {
|
||||
export function downloadContent (filename: string, content: ArrayBuffer | Buffer | string, type = 'application/octet-stream') {
|
||||
const blob = new Blob([content], { type })
|
||||
const href = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = href
|
||||
link.download = filename
|
||||
link.target = '_blank'
|
||||
link.click()
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user