Add better shadow cleaning migration

This commit is contained in:
Andrey Antukh 2025-06-25 19:17:58 +02:00
parent 61109c91e3
commit bf719b587f

View file

@ -1337,32 +1337,37 @@
(update :pages-index d/update-vals update-container) (update :pages-index d/update-vals update-container)
(d/update-when :components d/update-vals update-container)))) (d/update-when :components d/update-vals update-container))))
(defmethod migrate-data "0004-clean-shadow-and-colors" (defmethod migrate-data "0004-clean-shadow-color"
[data _] [data _]
(letfn [(clean-shadow [shadow] (let [decode-color (sm/decoder types.color/schema:color sm/json-transformer)
(update shadow :color (fn [color]
(let [ref-id (get color :id)
ref-file (get color :file-id)]
(-> (d/without-qualified color)
(select-keys [:opacity :color :gradient :image :ref-id :ref-file])
(cond-> ref-id
(assoc :ref-id ref-id))
(cond-> ref-file
(assoc :ref-file ref-file)))))))
(update-object [object] clean-shadow-color
(d/update-when object :shadow #(mapv clean-shadow %))) (fn [color]
(let [ref-id (get color :id)
ref-file (get color :file-id)]
(-> (d/without-qualified color)
(select-keys [:opacity :color :gradient :image :ref-id :ref-file])
(cond-> ref-id
(assoc :ref-id ref-id))
(cond-> ref-file
(assoc :ref-file ref-file))
(decode-color))))
(update-container [container] clean-shadow
(d/update-when container :objects d/update-vals update-object)) (fn [shadow]
(update shadow :color clean-shadow-color))
(clean-library-color [color] update-object
(dissoc color :file-id))] (fn [object]
(d/update-when object :shadow #(mapv clean-shadow %)))
update-container
(fn [container]
(d/update-when container :objects d/update-vals update-object))]
(-> data (-> data
(update :pages-index d/update-vals update-container) (update :pages-index d/update-vals update-container)
(d/update-when :components d/update-vals update-container) (d/update-when :components d/update-vals update-container))))
(d/update-when :colors d/update-vals clean-library-color))))
(defmethod migrate-data "0005-deprecate-image-type" (defmethod migrate-data "0005-deprecate-image-type"
[data _] [data _]
@ -1554,7 +1559,7 @@
"0002-clean-shape-interactions" "0002-clean-shape-interactions"
"0003-fix-root-shape" "0003-fix-root-shape"
"0003-convert-path-content" "0003-convert-path-content"
"0004-clean-shadow-and-colors" "0004-clean-shadow-color"
"0005-deprecate-image-type" "0005-deprecate-image-type"
"0006-fix-old-texts-fills" "0006-fix-old-texts-fills"
"0007-clear-invalid-strokes-and-fills-v2" "0007-clear-invalid-strokes-and-fills-v2"