mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 02:21:40 +02:00
⚡ Optimize dasharray generation
This commit is contained in:
parent
2698944ec7
commit
8b57dcf015
1 changed files with 11 additions and 11 deletions
|
@ -17,16 +17,16 @@
|
||||||
[app.util.object :as obj]
|
[app.util.object :as obj]
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str]))
|
||||||
|
|
||||||
(defn- stroke-type->dasharray
|
(defn- calculate-dasharray
|
||||||
[width style]
|
[style width]
|
||||||
(let [values (case style
|
(let [w+5 (+ 5 width)
|
||||||
:mixed [5 5 1 5]
|
w+1 (+ 1 width)
|
||||||
;; We want 0 so they are circles
|
w+10 (+ 10 width)]
|
||||||
:dotted [(- width) 5]
|
(case style
|
||||||
:dashed [10 10]
|
:mixed (str/concat "" w+5 "," w+5 "," w+1 "," w+5)
|
||||||
nil)]
|
:dotted (str/concat "" (- (* width 2)) "," w+5)
|
||||||
|
:dashed (str/concat "" w+10 "," w+10)
|
||||||
(->> values (map #(+ % width)) (str/join ","))))
|
"")))
|
||||||
|
|
||||||
(defn get-border-props
|
(defn get-border-props
|
||||||
[shape]
|
[shape]
|
||||||
|
@ -111,7 +111,7 @@
|
||||||
(obj/set! attrs "strokeOpacity" opacity)))
|
(obj/set! attrs "strokeOpacity" opacity)))
|
||||||
|
|
||||||
(when (not= style :svg)
|
(when (not= style :svg)
|
||||||
(obj/set! attrs "strokeDasharray" (stroke-type->dasharray width style)))
|
(obj/set! attrs "strokeDasharray" (calculate-dasharray style width)))
|
||||||
|
|
||||||
;; For simple line caps we use svg stroke-line-cap attribute. This
|
;; For simple line caps we use svg stroke-line-cap attribute. This
|
||||||
;; only works if all caps are the same and we are not using the tricks
|
;; only works if all caps are the same and we are not using the tricks
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue