From f3f708ee9dc513a48e31cc0a2f0b46a7ff5e46b7 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 11 May 2023 06:29:48 +0200 Subject: [PATCH 1/4] :bug: Fix svg import with null fill-opacity --- frontend/src/app/main/data/workspace/svg_upload.cljs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/main/data/workspace/svg_upload.cljs b/frontend/src/app/main/data/workspace/svg_upload.cljs index 0a9b3c5d08..c78fa1a94f 100644 --- a/frontend/src/app/main/data/workspace/svg_upload.cljs +++ b/frontend/src/app/main/data/workspace/svg_upload.cljs @@ -100,13 +100,13 @@ (-> (update :svg-attrs dissoc :fill-opacity) (update-in [:svg-attrs :style] dissoc :fill-opacity) (assoc-in [:fills 0 :fill-opacity] (-> (get-in shape [:svg-attrs :fill-opacity]) - (d/parse-double)))) + (d/parse-double 1)))) (get-in shape [:svg-attrs :style :fill-opacity]) (-> (update-in [:svg-attrs :style] dissoc :fill-opacity) (update :svg-attrs dissoc :fill-opacity) (assoc-in [:fills 0 :fill-opacity] (-> (get-in shape [:svg-attrs :style :fill-opacity]) - (d/parse-double))))))) + (d/parse-double 1))))))) (defn setup-stroke [shape] (let [stroke-linecap (-> (or (get-in shape [:svg-attrs :stroke-linecap]) From 00d625ee3392c450fcb5c161e6c532a003be76d1 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 11 May 2023 10:02:46 +0200 Subject: [PATCH 2/4] :bug: Avoid nil values for position-data --- frontend/src/app/util/text_svg_position.cljs | 47 ++++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/frontend/src/app/util/text_svg_position.cljs b/frontend/src/app/util/text_svg_position.cljs index 45cdfe5296..69f3fe02e4 100644 --- a/frontend/src/app/util/text_svg_position.cljs +++ b/frontend/src/app/util/text_svg_position.cljs @@ -90,27 +90,26 @@ [shape-id] (when (some? shape-id) (p/let [text-data (calc-text-node-positions shape-id)] - (when (d/not-empty? text-data) - (->> text-data - (mapv (fn [{:keys [node position text direction]}] - (let [{:keys [x y width height]} position - styles (js/getComputedStyle ^js node) - get (fn [prop] - (let [value (.getPropertyValue styles prop)] - (when (and value (not= value "")) - value)))] - (d/without-nils - {:x x - :y (+ y height) - :width width - :height height - :direction direction - :font-family (str (get "font-family")) - :font-size (str (get "font-size")) - :font-weight (str (get "font-weight")) - :text-transform (str (get "text-transform")) - :text-decoration (str (get "text-decoration")) - :letter-spacing (str (get "letter-spacing")) - :font-style (str (get "font-style")) - :fills (transit/decode-str (get "--fills")) - :text text}))))))))) + (->> text-data + (mapv (fn [{:keys [node position text direction]}] + (let [{:keys [x y width height]} position + styles (js/getComputedStyle ^js node) + get (fn [prop] + (let [value (.getPropertyValue styles prop)] + (when (and value (not= value "")) + value)))] + (d/without-nils + {:x x + :y (+ y height) + :width width + :height height + :direction direction + :font-family (str (get "font-family")) + :font-size (str (get "font-size")) + :font-weight (str (get "font-weight")) + :text-transform (str (get "text-transform")) + :text-decoration (str (get "text-decoration")) + :letter-spacing (str (get "letter-spacing")) + :font-style (str (get "font-style")) + :fills (transit/decode-str (get "--fills")) + :text text})))))))) From cb5ae99e1d16a00c675f4e0b8cd6825fa55b5b75 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Fri, 12 May 2023 10:01:45 +0200 Subject: [PATCH 3/4] :bug: Fix svg import making it more resilient --- .../app/main/data/workspace/svg_upload.cljs | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/frontend/src/app/main/data/workspace/svg_upload.cljs b/frontend/src/app/main/data/workspace/svg_upload.cljs index c78fa1a94f..2478eda461 100644 --- a/frontend/src/app/main/data/workspace/svg_upload.cljs +++ b/frontend/src/app/main/data/workspace/svg_upload.cljs @@ -8,6 +8,7 @@ (:require [app.common.colors :as clr] [app.common.data :as d] + [app.common.exceptions :as ex] [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] [app.common.geom.shapes :as gsh] @@ -30,6 +31,7 @@ [app.util.svg :as usvg] [app.util.webapi :as wapi] [beicon.core :as rx] + [clojure.spec.alpha :as s] [cuerdas.core :as str] [potok.core :as ptk])) @@ -38,11 +40,12 @@ (defonce default-image {:x 0 :y 0 :width 1 :height 1 :rx 0 :ry 0}) (defn- assert-valid-num [attr num] - (us/verify! - :expr (and (d/num? num) + (when-not (and (d/num? num) (<= num max-safe-int) (>= num min-safe-int)) - :hint (str/ffmt "%1 attribute has invalid value: %2" (d/name attr) num)) + (ex/raise :type :assertion + :code :expr-validation + :hint (str/ffmt "%1 attribute has invalid value: %2" (d/name attr) num))) ;; If the number is between 0-1 we round to 1 (same in negative form (cond @@ -52,11 +55,24 @@ (defn- assert-valid-pos-num [attr num] - (us/verify! - :expr (pos? num) - :hint (str/ffmt "%1 attribute should be positive" (d/name attr))) + (when-not (pos? num) + (ex/raise :type :assertion + :code :expr-validation + :hint (str/ffmt "%1 attribute should be positive" (d/name attr)))) num) +(defn- assert-valid-blend-mode + [mode] + (let [clean-value (-> mode + str/trim + str/lower + keyword)] + (when-not (s/valid? ::cts/blend-mode clean-value) + (ex/raise :type :assertion + :code :expr-validation + :hint (str/ffmt "%1 is not a valid blend mode" clean-value))) + clean-value)) + (defn- svg-dimensions [data] (let [width (get-in data [:attrs :width] 100) height (get-in data [:attrs :height] 100) @@ -133,12 +149,12 @@ (get-in shape [:svg-attrs :stroke-opacity]) (-> (update :svg-attrs dissoc :stroke-opacity) (assoc-in [:strokes 0 :stroke-opacity] (-> (get-in shape [:svg-attrs :stroke-opacity]) - (d/parse-double)))) + (d/parse-double 1)))) (get-in shape [:svg-attrs :style :stroke-opacity]) (-> (update-in [:svg-attrs :style] dissoc :stroke-opacity) (assoc-in [:strokes 0 :stroke-opacity] (-> (get-in shape [:svg-attrs :style :stroke-opacity]) - (d/parse-double)))) + (d/parse-double 1)))) (get-in shape [:svg-attrs :stroke-width]) (-> (update :svg-attrs dissoc :stroke-width) @@ -165,21 +181,21 @@ (get-in shape [:svg-attrs :opacity]) (-> (update :svg-attrs dissoc :opacity) (assoc :opacity (-> (get-in shape [:svg-attrs :opacity]) - (d/parse-double)))) + (d/parse-double 1)))) (get-in shape [:svg-attrs :style :opacity]) (-> (update-in [:svg-attrs :style] dissoc :opacity) (assoc :opacity (-> (get-in shape [:svg-attrs :style :opacity]) - (d/parse-double)))) + (d/parse-double 1)))) (get-in shape [:svg-attrs :mix-blend-mode]) (-> (update :svg-attrs dissoc :mix-blend-mode) - (assoc :blend-mode (-> (get-in shape [:svg-attrs :mix-blend-mode]) keyword))) + (assoc :blend-mode (-> (get-in shape [:svg-attrs :mix-blend-mode]) assert-valid-blend-mode))) (get-in shape [:svg-attrs :style :mix-blend-mode]) (-> (update-in [:svg-attrs :style] dissoc :mix-blend-mode) - (assoc :blend-mode (-> (get-in shape [:svg-attrs :style :mix-blend-mode]) keyword))))) + (assoc :blend-mode (-> (get-in shape [:svg-attrs :style :mix-blend-mode]) assert-valid-blend-mode))))) (defn create-raw-svg [name frame-id svg-data {:keys [tag attrs] :as data}] (let [{:keys [x y width height offset-x offset-y]} svg-data] From 6f59c80d86f7dd15097bbd63eb528adf2bd8222a Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 31 May 2023 09:48:35 +0200 Subject: [PATCH 4/4] :bug: Fix create color assets opacity specs --- common/src/app/common/types/color.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/app/common/types/color.cljc b/common/src/app/common/types/color.cljc index 2032cd0477..59b3122418 100644 --- a/common/src/app/common/types/color.cljc +++ b/common/src/app/common/types/color.cljc @@ -28,7 +28,7 @@ (s/def ::color-gradient/width ::us/safe-number) (s/def ::color-gradient-stop/color ::us/rgb-color-str) -(s/def ::color-gradient-stop/opacity ::us/safe-number) +(s/def ::color-gradient-stop/opacity (s/nilable ::us/safe-number)) (s/def ::color-gradient-stop/offset ::us/safe-number) (s/def ::color-gradient/stop