mirror of
https://github.com/penpot/penpot.git
synced 2025-02-10 17:18:21 -05:00
♻️ Refactor svg to data-uri code
This commit is contained in:
parent
df1c56da2d
commit
4068413f9f
2 changed files with 13 additions and 15 deletions
|
@ -7,7 +7,6 @@
|
|||
(ns app.main.ui.workspace.viewport.pixel-overlay
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.modal :as modal]
|
||||
|
@ -50,13 +49,7 @@
|
|||
[svg]
|
||||
(let [svg-clone (.cloneNode svg true)]
|
||||
(->> (resolve-svg-images! svg-clone)
|
||||
(rx/map (fn [_]
|
||||
(let [xml (-> (js/XMLSerializer.)
|
||||
(.serializeToString ^js svg-clone)
|
||||
(js/encodeURIComponent)
|
||||
(js/unescape)
|
||||
(js/btoa))]
|
||||
(dm/str "data:image/svg+xml;base64," xml)))))))
|
||||
(rx/map (fn [_] (dom/svg-node->data-uri svg-clone))))))
|
||||
|
||||
(defn format-viewbox [vbox]
|
||||
(str/join " " [(:x vbox 0)
|
||||
|
|
|
@ -410,14 +410,19 @@
|
|||
(-> (js/XMLSerializer.)
|
||||
(.serializeToString node))))
|
||||
|
||||
(defn svg->data-uri
|
||||
[svg]
|
||||
(assert (string? svg))
|
||||
(let [b64 (-> svg
|
||||
js/encodeURIComponent
|
||||
js/unescape
|
||||
(defn str->data-uri
|
||||
[str type]
|
||||
(assert (string? str))
|
||||
(let [b64 (-> str
|
||||
js/btoa)]
|
||||
(dm/str "data:image/svg+xml;base64," b64)))
|
||||
(dm/str "data:" type ";base64," b64)))
|
||||
|
||||
(defn svg-node->data-uri
|
||||
[svg-node]
|
||||
(let [xml (-> (js/XMLSerializer.)
|
||||
(.serializeToString svg-node))
|
||||
data-uri (str->data-uri xml "image/svg+xml")]
|
||||
data-uri))
|
||||
|
||||
(defn set-property! [^js node property value]
|
||||
(when (some? node)
|
||||
|
|
Loading…
Add table
Reference in a new issue