From a2a61e99a7458d337b5934cf63ad6008ee3aeee8 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 25 Jan 2024 16:33:53 +0100 Subject: [PATCH 1/7] :bug: Fix invalid values on colors and typografies on fdata --- backend/src/app/features/components_v2.clj | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/src/app/features/components_v2.clj b/backend/src/app/features/components_v2.clj index e5e2673f7..1aa2d9336 100644 --- a/backend/src/app/features/components_v2.clj +++ b/backend/src/app/features/components_v2.clj @@ -198,6 +198,15 @@ (update file-data :pages-index update-vals update-page))) + ;; Sometimes we found that the file has issues in the internal + ;; data structure of the local library; this function tries to + ;; fix that issues. + fix-file-data + (fn [file-data] + (-> file-data + (d/update-when :colors dissoc nil) + (d/update-when :typographies dissoc nil))) + delete-big-geometry-shapes (fn [file-data] ;; At some point in time, we had a bug that generated shapes @@ -205,12 +214,10 @@ ;; schema. Since we don't have a way to fix those shapes, we ;; simply proceed to delete it. We ignore path type shapes ;; because they have not been affected by the bug. - (letfn [(fix-container - [container] + (letfn [(fix-container [container] (d/update-when container :objects #(reduce-kv fix-shape % %))) - (fix-shape - [objects id shape] + (fix-shape [objects id shape] (cond (or (cfh/path-shape? shape) (cfh/bool-shape? shape)) @@ -649,6 +656,7 @@ (update :pages-index update-vals fix-container))))] (-> file-data + (fix-file-data) (fix-page-invalid-options) (fix-bad-children) (fix-misc-shape-issues) From 0e724ac82163501711095d982eac13406773e5dc Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 25 Jan 2024 16:43:49 +0100 Subject: [PATCH 2/7] :bug: Add better fix for parsing svg-dimensions That covers more corner cases --- common/src/app/common/svg.cljc | 17 +++++++++++++---- common/src/app/common/svg/shapes_builder.cljc | 3 +-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/common/src/app/common/svg.cljc b/common/src/app/common/svg.cljc index e0c718362..4ea6278cc 100644 --- a/common/src/app/common/svg.cljc +++ b/common/src/app/common/svg.cljc @@ -800,15 +800,24 @@ "skewX" (apply gmt/skew-matrix (format-skew-x-params params)) "skewY" (apply gmt/skew-matrix (format-skew-y-params params)))) +(def ^:private + xf-parse-numbers + (comp + (map first) + (keep not-empty) + (map d/parse-double))) + +(defn parse-numbers + [data] + (->> (re-seq number-regex data) + (into [] xf-parse-numbers))) + (defn parse-transform [transform] (if (string? transform) (->> (re-seq matrices-regex transform) (map (fn [[_ type params]] - (let [params (->> (re-seq number-regex params) - (map first) - (keep not-empty) - (map d/parse-double))] + (let [params (parse-numbers params)] (to-matrix type params)))) (reduce gmt/multiply (gmt/matrix))) diff --git a/common/src/app/common/svg/shapes_builder.cljc b/common/src/app/common/svg/shapes_builder.cljc index 343507f77..a831d3c0e 100644 --- a/common/src/app/common/svg/shapes_builder.cljc +++ b/common/src/app/common/svg/shapes_builder.cljc @@ -63,8 +63,7 @@ viewbox (or (:viewBox attrs) (dm/str "0 0 " width " " height)) - [x y width height] (->> (str/split viewbox #"[\s,]+") - (map d/parse-double)) + [x y width height] (csvg/parse-numbers viewbox) width (if (= width 0) 1 width) height (if (= height 0) 1 height)] From 9f80ddd1254ed47df7738711cbf3e3f03a34f66c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 25 Jan 2024 17:01:08 +0100 Subject: [PATCH 3/7] :bug: Fix path shapes that does not have :content attr --- common/src/app/common/files/migrations.cljc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 39d448597..686b49efb 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -697,9 +697,16 @@ (defmethod migrate 39 [data] (letfn [(update-shape [shape] - (if (and (cfh/bool-shape? shape) - (not (contains? shape :bool-content))) + (cond + (and (cfh/bool-shape? shape) + (not (contains? shape :bool-content))) (assoc shape :bool-content []) + + (and (cfh/path-shape? shape) + (not (contains? shape :content))) + (assoc shape :content []) + + :else shape)) (update-container [container] From adffd1f0007c3e609cf9b224a23335d697f65ee1 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 25 Jan 2024 17:21:05 +0100 Subject: [PATCH 4/7] :bug: Fix text shapes content internal data type incosistency --- common/src/app/common/files/migrations.cljc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 686b49efb..025f1d841 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -795,9 +795,16 @@ (defmethod migrate 43 [data] - (letfn [(update-text-node [node] + (letfn [(number->string [v] + (if (number? v) + (str v) + v)) + + (update-text-node [node] (-> node (d/update-when :fills #(filterv valid-fill? %)) + (d/update-when :font-size number->string) + (d/update-when :font-weight number->string) (d/without-nils))) (update-object [object] From 1a3c07abdb086b8e36caf4c66cb3cdf5a471323c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 25 Jan 2024 17:31:27 +0100 Subject: [PATCH 5/7] :bug: Remove completely broken shapes on comp-v2 migration --- backend/src/app/features/components_v2.clj | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/backend/src/app/features/components_v2.clj b/backend/src/app/features/components_v2.clj index 1aa2d9336..ff7ad5866 100644 --- a/backend/src/app/features/components_v2.clj +++ b/backend/src/app/features/components_v2.clj @@ -239,6 +239,26 @@ (update :pages-index update-vals fix-container) (d/update-when :components update-vals fix-container)))) + ;; Some files has totally broken shapes, we just remove them + fix-completly-broken-shapes + (fn [file-data] + (letfn [(update-object [objects id shape] + (if (nil? (:type shape)) + (let [ids (cfh/get-children-ids objects id)] + (-> objects + (dissoc id) + (as-> $ (reduce dissoc $ ids)) + (d/update-in-when [(:parent-id shape) :shapes] + (fn [shapes] (filterv #(not= id %) shapes))))) + objects)) + + (update-container [container] + (d/update-when container :objects #(reduce-kv update-object % %)))] + + (-> file-data + (update :pages-index update-vals update-container) + (update :components update-vals update-container)))) + fix-misc-shape-issues (fn [file-data] (letfn [(fix-container [container] @@ -658,6 +678,7 @@ (-> file-data (fix-file-data) (fix-page-invalid-options) + (fix-completly-broken-shapes) (fix-bad-children) (fix-misc-shape-issues) (fix-recent-colors) From b1d33d4c152e1e3e0c3aeb334d907c0728bdce61 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 25 Jan 2024 17:58:55 +0100 Subject: [PATCH 6/7] :bug: Add missing shape name on comp-v2 migration --- backend/src/app/features/components_v2.clj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/app/features/components_v2.clj b/backend/src/app/features/components_v2.clj index ff7ad5866..584259020 100644 --- a/backend/src/app/features/components_v2.clj +++ b/backend/src/app/features/components_v2.clj @@ -275,6 +275,9 @@ 0 gap))) + (nil? (:name shape)) + (assoc :name (d/name (:type shape))) + ;; Fix broken fills (seq (:fills shape)) (update :fills (fn [fills] (filterv valid-fill? fills))) From 623b4a985831b61a54a87f06cbd10fca8f798991 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 25 Jan 2024 18:05:57 +0100 Subject: [PATCH 7/7] :bug: Remove empty text shapes on comp-v2 migration --- backend/src/app/features/components_v2.clj | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/src/app/features/components_v2.clj b/backend/src/app/features/components_v2.clj index 584259020..03240a904 100644 --- a/backend/src/app/features/components_v2.clj +++ b/backend/src/app/features/components_v2.clj @@ -243,13 +243,20 @@ fix-completly-broken-shapes (fn [file-data] (letfn [(update-object [objects id shape] - (if (nil? (:type shape)) + (cond + (nil? (:type shape)) (let [ids (cfh/get-children-ids objects id)] (-> objects (dissoc id) (as-> $ (reduce dissoc $ ids)) (d/update-in-when [(:parent-id shape) :shapes] (fn [shapes] (filterv #(not= id %) shapes))))) + + (and (cfh/text-shape? shape) + (not (seq (:content shape)))) + (dissoc objects id) + + :else objects)) (update-container [container]