0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 23:18:48 -05:00

🐛 Add migration for fix path shapes with invalid curve segment params

This commit is contained in:
Andrey Antukh 2024-06-26 19:46:29 +02:00
parent 16a0e1f578
commit f393ce9273
4 changed files with 53 additions and 3 deletions

View file

@ -6,4 +6,4 @@
(ns app.common.files.defaults)
(def version 49)
(def version 50)

View file

@ -957,6 +957,54 @@
(update data :pages-index update-vals update-page)))
(defn migrate-up-50
"This migration mainly fixes paths with curve-to segments
without :c1x :c1y :c2x :c2y properties. Additionally, we found a
case where the params instead to be plain hash-map, is a points
instance. This migration normalizes all params to plain map."
[data]
(let [update-segment
(fn [{:keys [command params] :as segment}]
(let [params (into {} params)
params (cond
(= :curve-to command)
(let [x (get params :x)
y (get params :y)]
(cond-> params
(nil? (:c1x params))
(assoc :c1x x)
(nil? (:c1y params))
(assoc :c1y y)
(nil? (:c2x params))
(assoc :c2x x)
(nil? (:c2y params))
(assoc :c2y y)))
:else
params)]
(assoc segment :params params)))
update-shape
(fn [shape]
(if (cfh/path-shape? shape)
(d/update-when shape :content (fn [content] (mapv update-segment content)))
shape))
update-container
(fn [page]
(d/update-when page :objects update-vals update-shape))]
(-> data
(update :pages-index update-vals update-container)
(update :components update-vals update-container))))
(def migrations
"A vector of all applicable migrations"
[{:id 2 :migrate-up migrate-up-2}
@ -997,4 +1045,5 @@
{:id 46 :migrate-up migrate-up-46}
{:id 47 :migrate-up migrate-up-47}
{:id 48 :migrate-up migrate-up-48}
{:id 49 :migrate-up migrate-up-49}])
{:id 49 :migrate-up migrate-up-49}
{:id 50 :migrate-up migrate-up-50}])

View file

@ -1046,7 +1046,6 @@
(str/includes? data "<!DOCTYPE")
(str/replace #"<\!DOCTYPE[^>]*>" "")))
(defn parse
[text]
#?(:cljs (tubax/xml->clj text)

View file

@ -10,6 +10,8 @@
[app.common.svg.path.subpath :refer [pt=]]
[app.util.array :as arr]))
;; TODO: move to common
(def path-precision 3)
(defn- join-params