From 8db3476c0e4af42319a6156b3e6171a230d789d8 Mon Sep 17 00:00:00 2001 From: goodmice Date: Sat, 25 Jun 2022 15:47:13 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20SVG=20=D0=B2=20DataURL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/functions/index.ts | 4 ++++ src/utils/functions/svg.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/utils/functions/svg.ts diff --git a/src/utils/functions/index.ts b/src/utils/functions/index.ts index eaa20d8..69fcf3c 100644 --- a/src/utils/functions/index.ts +++ b/src/utils/functions/index.ts @@ -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' diff --git a/src/utils/functions/svg.ts b/src/utils/functions/svg.ts new file mode 100644 index 0000000..7ec6902 --- /dev/null +++ b/src/utils/functions/svg.ts @@ -0,0 +1,18 @@ + +export const svgToDataURL = (svg: SVGSVGElement) => { + const serializer = new XMLSerializer() + let source = serializer.serializeToString(svg) + + if(!source.match(/^]+xmlns="http\:\/\/www\.w3\.org\/2000\/svg"/)) + source = source.replace(/^]+"http\:\/\/www\.w3\.org\/1999\/xlink"/)) + source = source.replace(/^\r\n' + + encodeURIComponent(source) + + return source +}