mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 19:06:18 +00:00
Implement shape attrs transformation as reduce function.
This commit is contained in:
parent
cab871fc95
commit
1924570ea1
@ -6,26 +6,27 @@
|
|||||||
[uxbox.util.data :refer (remove-nil-vals)]))
|
[uxbox.util.data :refer (remove-nil-vals)]))
|
||||||
|
|
||||||
(defn- transform-attr
|
(defn- transform-attr
|
||||||
[data [key value :as pair]]
|
[acc key value]
|
||||||
(case key
|
(case key
|
||||||
:view-box
|
:view-box
|
||||||
[key (apply str (interpose " " value))]
|
(assoc! acc key (apply str (interpose " " value)))
|
||||||
|
|
||||||
:lock
|
:lock
|
||||||
[:preserveAspectRatio (if value "xMidYMid" "none")]
|
(assoc! acc :preserveAspectRatio (if value "xMidYMid" "none"))
|
||||||
|
|
||||||
:rotation
|
:rotation
|
||||||
(let [width (nth (:view-box data) 3)
|
(let [width (nth (:view-box data) 3)
|
||||||
center-x (+ (:x data) (/ (:width data) 2))
|
center-x (+ (:x data) (/ (:width data) 2))
|
||||||
center-y (+ (:y data) (/ (:height data) 2))]
|
center-y (+ (:y data) (/ (:height data) 2))]
|
||||||
[:transform (str/format "rotate(%s %s %s)" value center-x center-y)])
|
(assoc! acc :transform (str/format "rotate(%s %s %s)"
|
||||||
|
value center-x center-y)))
|
||||||
|
|
||||||
pair))
|
(assoc! acc key value)))
|
||||||
|
|
||||||
(defn- transform-attrs
|
(defn- transform-attrs
|
||||||
[data]
|
[data]
|
||||||
(let [xf (map (partial transform-attr data))]
|
(persistent!
|
||||||
(into {} xf data)))
|
(reduce-kv transform-attr (transient {}) data)))
|
||||||
|
|
||||||
(defn- extract-attrs
|
(defn- extract-attrs
|
||||||
"Extract predefinet attrs from shapes."
|
"Extract predefinet attrs from shapes."
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user