mirror of
https://github.com/penpot/penpot.git
synced 2025-05-30 02:16:10 +02:00
Merge remote-tracking branch 'origin/staging' into develop
This commit is contained in:
commit
5a733c84be
2 changed files with 55 additions and 41 deletions
|
@ -8,7 +8,7 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.colors :as clr]
|
[app.common.colors :as clr]
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.geom.matrix :as gmt]
|
[app.common.geom.matrix :as gmt]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
|
@ -31,6 +31,7 @@
|
||||||
[app.util.svg :as usvg]
|
[app.util.svg :as usvg]
|
||||||
[app.util.webapi :as wapi]
|
[app.util.webapi :as wapi]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[potok.core :as ptk]))
|
[potok.core :as ptk]))
|
||||||
|
|
||||||
|
@ -39,11 +40,12 @@
|
||||||
(defonce default-image {:x 0 :y 0 :width 1 :height 1 :rx 0 :ry 0})
|
(defonce default-image {:x 0 :y 0 :width 1 :height 1 :rx 0 :ry 0})
|
||||||
|
|
||||||
(defn- assert-valid-num [attr num]
|
(defn- assert-valid-num [attr num]
|
||||||
(dm/assert!
|
(when-not (and (d/num? num)
|
||||||
["%1 attribute has invalid value: %2" (d/name attr) num]
|
(<= num max-safe-int)
|
||||||
(and (d/num? num)
|
(>= num min-safe-int))
|
||||||
(<= num max-safe-int)
|
(ex/raise :type :assertion
|
||||||
(>= num min-safe-int)))
|
: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
|
;; If the number is between 0-1 we round to 1 (same in negative form
|
||||||
(cond
|
(cond
|
||||||
|
@ -53,11 +55,24 @@
|
||||||
|
|
||||||
(defn- assert-valid-pos-num
|
(defn- assert-valid-pos-num
|
||||||
[attr num]
|
[attr num]
|
||||||
(dm/assert!
|
(when-not (pos? num)
|
||||||
["%1 attribute should be positive" (d/name attr)]
|
(ex/raise :type :assertion
|
||||||
(pos? num))
|
:code :expr-validation
|
||||||
|
:hint (str/ffmt "%1 attribute should be positive" (d/name attr))))
|
||||||
num)
|
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]
|
(defn- svg-dimensions [data]
|
||||||
(let [width (get-in data [:attrs :width] 100)
|
(let [width (get-in data [:attrs :width] 100)
|
||||||
height (get-in data [:attrs :height] 100)
|
height (get-in data [:attrs :height] 100)
|
||||||
|
@ -101,13 +116,13 @@
|
||||||
(-> (update :svg-attrs dissoc :fill-opacity)
|
(-> (update :svg-attrs dissoc :fill-opacity)
|
||||||
(update-in [:svg-attrs :style] dissoc :fill-opacity)
|
(update-in [:svg-attrs :style] dissoc :fill-opacity)
|
||||||
(assoc-in [:fills 0 :fill-opacity] (-> (get-in shape [:svg-attrs :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])
|
(get-in shape [:svg-attrs :style :fill-opacity])
|
||||||
(-> (update-in [:svg-attrs :style] dissoc :fill-opacity)
|
(-> (update-in [:svg-attrs :style] dissoc :fill-opacity)
|
||||||
(update :svg-attrs dissoc :fill-opacity)
|
(update :svg-attrs dissoc :fill-opacity)
|
||||||
(assoc-in [:fills 0 :fill-opacity] (-> (get-in shape [:svg-attrs :style :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]
|
(defn setup-stroke [shape]
|
||||||
(let [stroke-linecap (-> (or (get-in shape [:svg-attrs :stroke-linecap])
|
(let [stroke-linecap (-> (or (get-in shape [:svg-attrs :stroke-linecap])
|
||||||
|
@ -134,12 +149,12 @@
|
||||||
(get-in shape [:svg-attrs :stroke-opacity])
|
(get-in shape [:svg-attrs :stroke-opacity])
|
||||||
(-> (update :svg-attrs dissoc :stroke-opacity)
|
(-> (update :svg-attrs dissoc :stroke-opacity)
|
||||||
(assoc-in [:strokes 0 :stroke-opacity] (-> (get-in shape [:svg-attrs :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])
|
(get-in shape [:svg-attrs :style :stroke-opacity])
|
||||||
(-> (update-in [:svg-attrs :style] dissoc :stroke-opacity)
|
(-> (update-in [:svg-attrs :style] dissoc :stroke-opacity)
|
||||||
(assoc-in [:strokes 0 :stroke-opacity] (-> (get-in shape [:svg-attrs :style :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])
|
(get-in shape [:svg-attrs :stroke-width])
|
||||||
(-> (update :svg-attrs dissoc :stroke-width)
|
(-> (update :svg-attrs dissoc :stroke-width)
|
||||||
|
@ -166,21 +181,21 @@
|
||||||
(get-in shape [:svg-attrs :opacity])
|
(get-in shape [:svg-attrs :opacity])
|
||||||
(-> (update :svg-attrs dissoc :opacity)
|
(-> (update :svg-attrs dissoc :opacity)
|
||||||
(assoc :opacity (-> (get-in shape [:svg-attrs :opacity])
|
(assoc :opacity (-> (get-in shape [:svg-attrs :opacity])
|
||||||
(d/parse-double))))
|
(d/parse-double 1))))
|
||||||
|
|
||||||
(get-in shape [:svg-attrs :style :opacity])
|
(get-in shape [:svg-attrs :style :opacity])
|
||||||
(-> (update-in [:svg-attrs :style] dissoc :opacity)
|
(-> (update-in [:svg-attrs :style] dissoc :opacity)
|
||||||
(assoc :opacity (-> (get-in shape [:svg-attrs :style :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])
|
(get-in shape [:svg-attrs :mix-blend-mode])
|
||||||
(-> (update :svg-attrs dissoc :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])
|
(get-in shape [:svg-attrs :style :mix-blend-mode])
|
||||||
(-> (update-in [:svg-attrs :style] dissoc :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}]
|
(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]
|
(let [{:keys [x y width height offset-x offset-y]} svg-data]
|
||||||
|
|
|
@ -90,27 +90,26 @@
|
||||||
[shape-id]
|
[shape-id]
|
||||||
(when (some? shape-id)
|
(when (some? shape-id)
|
||||||
(p/let [text-data (calc-text-node-positions shape-id)]
|
(p/let [text-data (calc-text-node-positions shape-id)]
|
||||||
(when (d/not-empty? text-data)
|
(->> text-data
|
||||||
(->> text-data
|
(mapv (fn [{:keys [node position text direction]}]
|
||||||
(mapv (fn [{:keys [node position text direction]}]
|
(let [{:keys [x y width height]} position
|
||||||
(let [{:keys [x y width height]} position
|
styles (js/getComputedStyle ^js node)
|
||||||
styles (js/getComputedStyle ^js node)
|
get (fn [prop]
|
||||||
get (fn [prop]
|
(let [value (.getPropertyValue styles prop)]
|
||||||
(let [value (.getPropertyValue styles prop)]
|
(when (and value (not= value ""))
|
||||||
(when (and value (not= value ""))
|
value)))]
|
||||||
value)))]
|
(d/without-nils
|
||||||
(d/without-nils
|
{:x x
|
||||||
{:x x
|
:y (+ y height)
|
||||||
:y (+ y height)
|
:width width
|
||||||
:width width
|
:height height
|
||||||
:height height
|
:direction direction
|
||||||
:direction direction
|
:font-family (str (get "font-family"))
|
||||||
:font-family (str (get "font-family"))
|
:font-size (str (get "font-size"))
|
||||||
:font-size (str (get "font-size"))
|
:font-weight (str (get "font-weight"))
|
||||||
:font-weight (str (get "font-weight"))
|
:text-transform (str (get "text-transform"))
|
||||||
:text-transform (str (get "text-transform"))
|
:text-decoration (str (get "text-decoration"))
|
||||||
:text-decoration (str (get "text-decoration"))
|
:letter-spacing (str (get "letter-spacing"))
|
||||||
:letter-spacing (str (get "letter-spacing"))
|
:font-style (str (get "font-style"))
|
||||||
:font-style (str (get "font-style"))
|
:fills (transit/decode-str (get "--fills"))
|
||||||
:fills (transit/decode-str (get "--fills"))
|
:text text}))))))))
|
||||||
:text text})))))))))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue