🐛 Fix problem with stroke-cap migration (#10019)

This commit is contained in:
Alonso Torres 2026-06-04 11:38:46 +02:00 committed by GitHub
parent 785b07313b
commit ccc734055f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 17 deletions

View File

@ -1839,18 +1839,32 @@
;; This will fix incorrectly created strokes from SVG imports ;; This will fix incorrectly created strokes from SVG imports
;; that have the stroke-cap at the shape level instead of at the stroke level ;; 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 _] [data _]
(letfn [(fix-shape [shape] (letfn [(check-strokes [strokes]
(let [cap-start (get shape :stroke-cap-start) (->> strokes
cap-end (get shape :stroke-cap-end)] (mapv (fn [stroke]
(if (or (some? cap-start) (some? cap-end)) (cond-> stroke
(cond-> (dissoc shape :stroke-cap-start :stroke-cap-end) (string? (:stroke-cap-start stroke))
(and (some? cap-start) (seq (:strokes shape))) (update :stroke-cap-start keyword)
(assoc-in [:strokes 0 :stroke-cap-start] cap-start) (string? (:stroke-cap-end stroke))
(update :stroke-cap-end keyword))))))
(and (some? cap-end) (seq (:strokes shape))) (fix-shape [shape]
(assoc-in [:strokes 0 :stroke-cap-end] cap-end)) (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))) shape)))
(update-container [container] (update-container [container]
@ -1941,4 +1955,4 @@
"0021-fix-shape-svg-attrs" "0021-fix-shape-svg-attrs"
"0022-normalize-component-root-and-resync" "0022-normalize-component-root-and-resync"
"0023-repair-token-themes-with-inexistent-sets" "0023-repair-token-themes-with-inexistent-sets"
"0024-fix-stroke-cap-placement"])) "0024b-fix-stroke-cap-placement"]))

View File

@ -28,7 +28,7 @@
(t/is (= cfm/available-migrations (:migrations file'))) (t/is (= cfm/available-migrations (:migrations file')))
(t/is (= 3 (:sum (:data 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) (let [shape-id (uuid/next)
page-id (uuid/next) page-id (uuid/next)
data {:pages-index data {:pages-index
@ -36,19 +36,27 @@
{:objects {:objects
{shape-id {:id shape-id {shape-id {:id shape-id
:type :path :type :path
:stroke-cap-start :round :stroke-cap-start "round"
:stroke-cap-end :round :stroke-cap-end "round"
:strokes [{:stroke-color "#000000" :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-opacity 1
:stroke-style :svg :stroke-style :svg
:stroke-width 2}]}}}}} :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])] (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-start shape)) "top-level cap removed")
(t/is (nil? (:stroke-cap-end 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-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 (t/deftest migration-0024-fix-stroke-cap-no-strokes
(let [shape-id (uuid/next) (let [shape-id (uuid/next)
@ -61,7 +69,7 @@
:stroke-cap-start :round :stroke-cap-start :round
:stroke-cap-end :round :stroke-cap-end :round
:strokes []}}}}} :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])] (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") (t/is (nil? (:stroke-cap-start shape)) "top-level cap removed even with no strokes")