mirror of
https://github.com/penpot/penpot.git
synced 2025-05-18 18:26:11 +02:00
🐛 Fixed problem with old svgs
This commit is contained in:
parent
17d28ed9bc
commit
bb04181abf
3 changed files with 49 additions and 35 deletions
|
@ -18,7 +18,7 @@
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[potok.core :as ptk]
|
[potok.core :as ptk]
|
||||||
|
[app.util.svg :as usvg]
|
||||||
[app.util.geom.path :as ugp]))
|
[app.util.geom.path :as ugp]))
|
||||||
|
|
||||||
(defn- svg-dimensions [data]
|
(defn- svg-dimensions [data]
|
||||||
|
@ -30,37 +30,6 @@
|
||||||
height (d/parse-integer height-str)]
|
height (d/parse-integer height-str)]
|
||||||
[width height]))
|
[width height]))
|
||||||
|
|
||||||
|
|
||||||
(defn clean-attrs
|
|
||||||
"Transforms attributes to their react equivalent"
|
|
||||||
[attrs]
|
|
||||||
(letfn [(transform-key [key]
|
|
||||||
(-> (name key)
|
|
||||||
(str/replace ":" "-")
|
|
||||||
(str/camel)
|
|
||||||
(keyword)))
|
|
||||||
|
|
||||||
(format-styles [style-str]
|
|
||||||
(->> (str/split style-str ";")
|
|
||||||
(map str/trim)
|
|
||||||
(map #(str/split % ":"))
|
|
||||||
(group-by first)
|
|
||||||
(map (fn [[key val]]
|
|
||||||
(vector
|
|
||||||
(transform-key key)
|
|
||||||
(second (first val)))))
|
|
||||||
(into {})))
|
|
||||||
|
|
||||||
(map-fn [[key val]]
|
|
||||||
(cond
|
|
||||||
(= key :class) [:className val]
|
|
||||||
(= key :style) [key (format-styles val)]
|
|
||||||
:else (vector (transform-key key) val)))]
|
|
||||||
|
|
||||||
(->> attrs
|
|
||||||
(map map-fn)
|
|
||||||
(into {}))))
|
|
||||||
|
|
||||||
(defn tag-name [{:keys [tag]}]
|
(defn tag-name [{:keys [tag]}]
|
||||||
(cond (string? tag) tag
|
(cond (string? tag) tag
|
||||||
(keyword? tag) (name tag)
|
(keyword? tag) (name tag)
|
||||||
|
@ -103,7 +72,7 @@
|
||||||
:height height
|
:height height
|
||||||
:x x
|
:x x
|
||||||
:y y
|
:y y
|
||||||
:content (if (map? data) (update data :attrs clean-attrs) data)}
|
:content (if (map? data) (update data :attrs usvg/clean-attrs) data)}
|
||||||
(gsh/setup-selrect)))
|
(gsh/setup-selrect)))
|
||||||
|
|
||||||
(defn parse-path [name frame-id {:keys [attrs] :as data}]
|
(defn parse-path [name frame-id {:keys [attrs] :as data}]
|
||||||
|
|
|
@ -9,14 +9,15 @@
|
||||||
|
|
||||||
(ns app.main.ui.shapes.svg-raw
|
(ns app.main.ui.shapes.svg-raw
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.data :as cd]
|
||||||
[app.common.geom.matrix :as gmt]
|
[app.common.geom.matrix :as gmt]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
|
[app.common.uuid :as uuid]
|
||||||
[app.main.ui.shapes.attrs :as usa]
|
[app.main.ui.shapes.attrs :as usa]
|
||||||
[app.util.data :as ud]
|
[app.util.data :as ud]
|
||||||
[app.common.data :as cd]
|
|
||||||
[app.common.uuid :as uuid]
|
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
|
[app.util.svg :as usvg]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[rumext.alpha :as mf]))
|
[rumext.alpha :as mf]))
|
||||||
|
|
||||||
|
@ -49,6 +50,8 @@
|
||||||
|
|
||||||
(defn set-styles [attrs shape]
|
(defn set-styles [attrs shape]
|
||||||
(let [custom-attrs (usa/extract-style-attrs shape)
|
(let [custom-attrs (usa/extract-style-attrs shape)
|
||||||
|
attrs (cond-> attrs
|
||||||
|
(string? (:style attrs)) usvg/clean-attrs)
|
||||||
style (obj/merge! (clj->js (:style attrs {}))
|
style (obj/merge! (clj->js (:style attrs {}))
|
||||||
(obj/get custom-attrs "style"))]
|
(obj/get custom-attrs "style"))]
|
||||||
(-> (clj->js attrs)
|
(-> (clj->js attrs)
|
||||||
|
|
42
frontend/src/app/util/svg.cljs
Normal file
42
frontend/src/app/util/svg.cljs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2020-2021 UXBOX Labs SL
|
||||||
|
|
||||||
|
(ns app.util.svg
|
||||||
|
(:require
|
||||||
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
|
(defn clean-attrs
|
||||||
|
"Transforms attributes to their react equivalent"
|
||||||
|
[attrs]
|
||||||
|
(letfn [(transform-key [key]
|
||||||
|
(-> (name key)
|
||||||
|
(str/replace ":" "-")
|
||||||
|
(str/camel)
|
||||||
|
(keyword)))
|
||||||
|
|
||||||
|
(format-styles [style-str]
|
||||||
|
(->> (str/split style-str ";")
|
||||||
|
(map str/trim)
|
||||||
|
(map #(str/split % ":"))
|
||||||
|
(group-by first)
|
||||||
|
(map (fn [[key val]]
|
||||||
|
(vector
|
||||||
|
(transform-key key)
|
||||||
|
(second (first val)))))
|
||||||
|
(into {})))
|
||||||
|
|
||||||
|
(map-fn [[key val]]
|
||||||
|
(cond
|
||||||
|
(= key :class) [:className val]
|
||||||
|
(and (= key :style) (string? val)) [key (format-styles val)]
|
||||||
|
:else (vector (transform-key key) val)))]
|
||||||
|
|
||||||
|
(->> attrs
|
||||||
|
(map map-fn)
|
||||||
|
(into {}))))
|
Loading…
Add table
Add a link
Reference in a new issue