mirror of
https://github.com/penpot/penpot.git
synced 2025-06-02 15:51:38 +02:00
40 lines
1.4 KiB
Clojure
40 lines
1.4 KiB
Clojure
;; 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) 2016-2020 UXBOX Labs SL
|
|
|
|
(ns app.main.ui.shapes.attrs
|
|
(:require
|
|
[cuerdas.core :as str]
|
|
[app.util.object :as obj]))
|
|
|
|
(defn- stroke-type->dasharray
|
|
[style]
|
|
(case style
|
|
:mixed "5,5,1,5"
|
|
:dotted "5,5"
|
|
:dashed "10,10"
|
|
nil))
|
|
|
|
(defn extract-style-attrs
|
|
([shape] (extract-style-attrs shape nil))
|
|
([shape gradient-id]
|
|
(let [stroke-style (:stroke-style shape :none)
|
|
attrs #js {:rx (:rx shape nil)
|
|
:ry (:ry shape nil)}
|
|
attrs (obj/merge! attrs
|
|
(if gradient-id
|
|
#js {:fill (str/format "url(#%s)" gradient-id)}
|
|
#js {:fill (or (:fill-color shape) "transparent")
|
|
:fillOpacity (:fill-opacity shape nil)}))]
|
|
(when (not= stroke-style :none)
|
|
(obj/merge! attrs
|
|
#js {:stroke (:stroke-color shape nil)
|
|
:strokeWidth (:stroke-width shape 1)
|
|
:strokeOpacity (:stroke-opacity shape nil)
|
|
:strokeDasharray (stroke-type->dasharray stroke-style)}))
|
|
attrs)))
|