mirror of
https://github.com/penpot/penpot.git
synced 2026-06-09 17:02:05 +00:00
🐛 Fix problem with stroke-cap migration (#10019)
This commit is contained in:
parent
785b07313b
commit
ccc734055f
@ -1839,18 +1839,32 @@
|
||||
|
||||
;; This will fix incorrectly created strokes from SVG imports
|
||||
;; that have the stroke-cap at the shape level instead of at the stroke level
|
||||
(defmethod migrate-data "0024-fix-stroke-cap-placement"
|
||||
(defmethod migrate-data "0024b-fix-stroke-cap-placement"
|
||||
[data _]
|
||||
(letfn [(fix-shape [shape]
|
||||
(let [cap-start (get shape :stroke-cap-start)
|
||||
cap-end (get shape :stroke-cap-end)]
|
||||
(if (or (some? cap-start) (some? cap-end))
|
||||
(cond-> (dissoc shape :stroke-cap-start :stroke-cap-end)
|
||||
(and (some? cap-start) (seq (:strokes shape)))
|
||||
(assoc-in [:strokes 0 :stroke-cap-start] cap-start)
|
||||
(letfn [(check-strokes [strokes]
|
||||
(->> strokes
|
||||
(mapv (fn [stroke]
|
||||
(cond-> stroke
|
||||
(string? (:stroke-cap-start stroke))
|
||||
(update :stroke-cap-start keyword)
|
||||
(string? (:stroke-cap-end stroke))
|
||||
(update :stroke-cap-end keyword))))))
|
||||
|
||||
(and (some? cap-end) (seq (:strokes shape)))
|
||||
(assoc-in [:strokes 0 :stroke-cap-end] cap-end))
|
||||
(fix-shape [shape]
|
||||
(let [cap-start (keyword (get shape :stroke-cap-start))
|
||||
cap-end (keyword (get shape :stroke-cap-end))]
|
||||
(if (or (some? cap-start) (some? cap-end))
|
||||
(-> shape
|
||||
(dissoc :stroke-cap-start :stroke-cap-end)
|
||||
|
||||
(cond-> (seq (:strokes shape))
|
||||
(update :strokes check-strokes)
|
||||
|
||||
(and (some? cap-start) (seq (:strokes shape)))
|
||||
(assoc-in [:strokes 0 :stroke-cap-start] cap-start)
|
||||
|
||||
(and (some? cap-end) (seq (:strokes shape)))
|
||||
(assoc-in [:strokes 0 :stroke-cap-end] cap-end)))
|
||||
shape)))
|
||||
|
||||
(update-container [container]
|
||||
@ -1941,4 +1955,4 @@
|
||||
"0021-fix-shape-svg-attrs"
|
||||
"0022-normalize-component-root-and-resync"
|
||||
"0023-repair-token-themes-with-inexistent-sets"
|
||||
"0024-fix-stroke-cap-placement"]))
|
||||
"0024b-fix-stroke-cap-placement"]))
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
(t/is (= cfm/available-migrations (:migrations file')))
|
||||
(t/is (= 3 (:sum (:data file'))))))))
|
||||
|
||||
(t/deftest migration-0024-fix-stroke-cap-placement
|
||||
(t/deftest migration-0024b-fix-stroke-cap-placement
|
||||
(let [shape-id (uuid/next)
|
||||
page-id (uuid/next)
|
||||
data {:pages-index
|
||||
@ -36,19 +36,27 @@
|
||||
{:objects
|
||||
{shape-id {:id shape-id
|
||||
:type :path
|
||||
:stroke-cap-start :round
|
||||
:stroke-cap-end :round
|
||||
:stroke-cap-start "round"
|
||||
:stroke-cap-end "round"
|
||||
:strokes [{:stroke-color "#000000"
|
||||
:stroke-opacity 1
|
||||
:stroke-style :svg
|
||||
:stroke-width 2}
|
||||
{:stroke-color "#000000"
|
||||
:stroke-cap-start "round"
|
||||
:stroke-cap-end "round"
|
||||
:stroke-opacity 1
|
||||
:stroke-style :svg
|
||||
:stroke-width 2}]}}}}}
|
||||
data' (cfm/migrate-data data "0024-fix-stroke-cap-placement")]
|
||||
data' (cfm/migrate-data data "0024b-fix-stroke-cap-placement")]
|
||||
|
||||
(let [shape (get-in data' [:pages-index page-id :objects shape-id])]
|
||||
(t/is (nil? (:stroke-cap-start shape)) "top-level cap removed")
|
||||
(t/is (nil? (:stroke-cap-end shape)) "top-level cap removed")
|
||||
(t/is (= :round (get-in shape [:strokes 0 :stroke-cap-start])) "cap moved into stroke")
|
||||
(t/is (= :round (get-in shape [:strokes 0 :stroke-cap-end])) "cap moved into stroke"))))
|
||||
(t/is (= :round (get-in shape [:strokes 0 :stroke-cap-end])) "cap moved into stroke")
|
||||
(t/is (= :round (get-in shape [:strokes 1 :stroke-cap-start])) "correct cap type")
|
||||
(t/is (= :round (get-in shape [:strokes 1 :stroke-cap-end])) "correct cap type"))))
|
||||
|
||||
(t/deftest migration-0024-fix-stroke-cap-no-strokes
|
||||
(let [shape-id (uuid/next)
|
||||
@ -61,7 +69,7 @@
|
||||
:stroke-cap-start :round
|
||||
:stroke-cap-end :round
|
||||
:strokes []}}}}}
|
||||
data' (cfm/migrate-data data "0024-fix-stroke-cap-placement")]
|
||||
data' (cfm/migrate-data data "0024b-fix-stroke-cap-placement")]
|
||||
|
||||
(let [shape (get-in data' [:pages-index page-id :objects shape-id])]
|
||||
(t/is (nil? (:stroke-cap-start shape)) "top-level cap removed even with no strokes")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user