forked from ddrilling/asb_cloud_front
Добавлен метод для конвертации SVG в DataURL
This commit is contained in:
parent
9eb6ab4fa6
commit
8db3476c0e
@ -3,6 +3,8 @@ export * from './arrayOrDefault'
|
||||
export * from './datetime'
|
||||
export type { RawDate, TimezoneId, timeInS } from './datetime'
|
||||
|
||||
export * from './chart'
|
||||
|
||||
export * from './min_max_filter'
|
||||
export type { KeyType } from './min_max_filter'
|
||||
|
||||
@ -21,5 +23,7 @@ export type { StorageNames, DataDashboardNNB } from './storage'
|
||||
|
||||
export * from './string'
|
||||
|
||||
export * from './svg'
|
||||
|
||||
export * from './table_settings'
|
||||
export type { TableColumnSettings, TableSettings, TableSettingsStore } from './table_settings'
|
||||
|
18
src/utils/functions/svg.ts
Normal file
18
src/utils/functions/svg.ts
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
export const svgToDataURL = (svg: SVGSVGElement) => {
|
||||
const serializer = new XMLSerializer()
|
||||
let source = serializer.serializeToString(svg)
|
||||
|
||||
if(!source.match(/^<svg[^>]+xmlns="http\:\/\/www\.w3\.org\/2000\/svg"/))
|
||||
source = source.replace(/^<svg/, '<svg xmlns="http://www.w3.org/2000/svg"')
|
||||
|
||||
if(!source.match(/^<svg[^>]+"http\:\/\/www\.w3\.org\/1999\/xlink"/))
|
||||
source = source.replace(/^<svg/, '<svg xmlns:xlink="http://www.w3.org/1999/xlink"')
|
||||
|
||||
source =
|
||||
'data:image/svg+xml;charset=utf-8,' +
|
||||
'<?xml version="1.0" standalone="no"?>\r\n' +
|
||||
encodeURIComponent(source)
|
||||
|
||||
return source
|
||||
}
|
Loading…
Reference in New Issue
Block a user