diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index becc05752..7f0a4e788 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -1,7 +1,12 @@ {:lint-as {potok.core/reify clojure.core/reify promesa.core/let clojure.core/let rumext.alpha/defc clojure.core/defn + app.common.data/export clojure.core/def app.db/with-atomic clojure.core/with-open} + + :hooks + {:analyze-call {app.common.data/export hooks.export/export}} + :output {:exclude-files ["data_readers.clj"]} diff --git a/.clj-kondo/hooks/export.clj b/.clj-kondo/hooks/export.clj new file mode 100644 index 000000000..bac6996ca --- /dev/null +++ b/.clj-kondo/hooks/export.clj @@ -0,0 +1,11 @@ +(ns hooks.export + (:require [clj-kondo.hooks-api :as api])) + +(defn export + [{:keys [:node]}] + (let [[_ sname] (:children node) + result (api/list-node + [(api/token-node (symbol "def")) + (api/token-node (symbol (name (:value sname)))) + sname])] + {:node result})) diff --git a/common/src/app/common/data.cljc b/common/src/app/common/data.cljc index 649e29097..580184cdf 100644 --- a/common/src/app/common/data.cljc +++ b/common/src/app/common/data.cljc @@ -10,14 +10,15 @@ #?(:cljs (:require-macros [app.common.data])) (:require - [linked.set :as lks] [app.common.math :as mth] [clojure.set :as set] #?(:clj [cljs.analyzer.api :as aapi]) #?(:cljs [cljs.reader :as r] :clj [clojure.edn :as r]) #?(:cljs [cljs.core :as core] - :clj [clojure.core :as core])) + :clj [clojure.core :as core]) + [linked.set :as lks]) + #?(:clj (:import linked.set.LinkedSet))) @@ -482,8 +483,8 @@ " [m1 m2] - (let [m1ks (keys m1) - m2ks (keys m2) + (let [m1ks (set (keys m1)) + m2ks (set (keys m2)) keys (set/union m1ks m2ks) diff-attr diff --git a/common/src/app/common/data/undo_stack.cljc b/common/src/app/common/data/undo_stack.cljc index 57f71d128..09694aa01 100644 --- a/common/src/app/common/data/undo_stack.cljc +++ b/common/src/app/common/data/undo_stack.cljc @@ -46,7 +46,7 @@ (assoc-in stack [:items index] value)) (defn undo - [{index :index items :items :as stack}] + [stack] (update stack :index dec)) (defn redo @@ -56,5 +56,5 @@ (update :index inc))) (defn size - [{index :index items :items :as stack}] + [{index :index :as stack}] (inc index)) diff --git a/common/src/app/common/geom/align.cljc b/common/src/app/common/geom/align.cljc index 4a14e4b1e..45d8b4321 100644 --- a/common/src/app/common/geom/align.cljc +++ b/common/src/app/common/geom/align.cljc @@ -6,9 +6,9 @@ (ns app.common.geom.align (:require - [clojure.spec.alpha :as s] + [app.common.data :as d] [app.common.geom.shapes :as gsh] - [app.common.data :as d])) + [clojure.spec.alpha :as s])) ;; --- Alignment diff --git a/common/src/app/common/geom/matrix.cljc b/common/src/app/common/geom/matrix.cljc index 04aa8651d..1c0a83482 100644 --- a/common/src/app/common/geom/matrix.cljc +++ b/common/src/app/common/geom/matrix.cljc @@ -8,10 +8,8 @@ (:require #?(:cljs [cljs.pprint :as pp] :clj [clojure.pprint :as pp]) - [cuerdas.core :as str] - [app.common.data :as d] - [app.common.math :as mth] - [app.common.geom.point :as gpt])) + [app.common.geom.point :as gpt] + [app.common.math :as mth])) ;; --- Matrix Impl diff --git a/common/src/app/common/geom/shapes.cljc b/common/src/app/common/geom/shapes.cljc index db0d51e29..96e489157 100644 --- a/common/src/app/common/geom/shapes.cljc +++ b/common/src/app/common/geom/shapes.cljc @@ -7,14 +7,13 @@ (ns app.common.geom.shapes (:require [app.common.data :as d] - [app.common.math :as mth] [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] [app.common.geom.shapes.common :as gco] + [app.common.geom.shapes.intersect :as gin] [app.common.geom.shapes.path :as gsp] [app.common.geom.shapes.rect :as gpr] [app.common.geom.shapes.transforms :as gtr] - [app.common.geom.shapes.intersect :as gin] [app.common.spec :as us])) diff --git a/common/src/app/common/geom/shapes/intersect.cljc b/common/src/app/common/geom/shapes/intersect.cljc index 2b55cb339..e4dc2cc56 100644 --- a/common/src/app/common/geom/shapes/intersect.cljc +++ b/common/src/app/common/geom/shapes/intersect.cljc @@ -6,9 +6,8 @@ (ns app.common.geom.shapes.intersect (:require - [app.common.data :as d] - [app.common.geom.point :as gpt] [app.common.geom.matrix :as gmt] + [app.common.geom.point :as gpt] [app.common.geom.shapes.path :as gpp] [app.common.geom.shapes.rect :as gpr] [app.common.math :as mth])) @@ -113,11 +112,10 @@ ;; Even-odd algorithm ;; Cast a ray from the point in any direction and count the intersections ;; if it's odd the point is inside the polygon - (let [] - (->> lines - (filter #(intersect-ray? p %)) - (count) - (odd?)))) + (->> lines + (filter #(intersect-ray? p %)) + (count) + (odd?))) (defn- next-windup "Calculates the next windup number for the nonzero algorithm" @@ -173,7 +171,7 @@ (defn overlaps-path? "Checks if the given rect overlaps with the path in any point" [shape rect] - + (let [;; If paths are too complex the intersection is too expensive ;; we fallback to check its bounding box otherwise the performance penalty ;; is too big @@ -186,7 +184,7 @@ (points->lines (:points shape)) (gpp/path->lines shape)) start-point (-> shape :content (first) :params (gpt/point))] - + (or (is-point-inside-nonzero? (first rect-points) path-lines) (is-point-inside-nonzero? start-point rect-lines) (intersects-lines? rect-lines path-lines)))) @@ -197,14 +195,14 @@ (let [center (gpt/point cx cy) transform (gmt/transform-in center transform) - {px :x py :y} (gpt/transform point transform)] - ;; Ellipse inequality formula - ;; https://en.wikipedia.org/wiki/Ellipse#Shifted_ellipse - (let [v (+ (/ (mth/sq (- px cx)) - (mth/sq rx)) - (/ (mth/sq (- py cy)) - (mth/sq ry)))] - (<= v 1)))) + {px :x py :y} (gpt/transform point transform) + ;; Ellipse inequality formula + ;; https://en.wikipedia.org/wiki/Ellipse#Shifted_ellipse + v (+ (/ (mth/sq (- px cx)) + (mth/sq rx)) + (/ (mth/sq (- py cy)) + (mth/sq ry)))] + (<= v 1))) (defn intersects-line-ellipse? "Checks wether a single line intersects with the given ellipse" @@ -272,13 +270,13 @@ center (gpt/point (+ x (/ width 2)) (+ y (/ height 2))) - + ellipse-data {:cx (:x center) :cy (:y center) :rx (/ width 2) :ry (/ height 2) :transform (:transform-inverse shape)}] - + (or (is-point-inside-evenodd? center rect-lines) (is-point-inside-ellipse? (first rect-points) ellipse-data) (intersects-lines-ellipse? rect-lines ellipse-data)))) diff --git a/common/src/app/common/geom/shapes/path.cljc b/common/src/app/common/geom/shapes/path.cljc index 0339cd652..ae2d1d6f3 100644 --- a/common/src/app/common/geom/shapes/path.cljc +++ b/common/src/app/common/geom/shapes/path.cljc @@ -6,10 +6,10 @@ (ns app.common.geom.shapes.path (:require + [app.common.data :as d] [app.common.geom.point :as gpt] [app.common.geom.shapes.rect :as gpr] - [app.common.math :as mth] - [app.common.data :as d])) + [app.common.math :as mth])) (defn content->points [content] (->> content @@ -79,7 +79,7 @@ ;; When the term a is close to zero we have a linear equation [(/ (- c) b)] - ;; If a is not close to zero return the two roots for a cuadratic + ;; If a is not close to zero return the two roots for a cuadratic (not (mth/almost-zero? a)) [(/ (+ (- b) sqrt-b2-4ac) (* 2 a)) @@ -267,7 +267,7 @@ (and (< (d ht) (d t1)) (< (d ht) (d t2))) [ht1 ht2] - + (< (d t1) (d t2)) [t1 ht] @@ -324,7 +324,7 @@ (if (and (some? acc) (or (not cur) (<= min-dist cur-dist))) [min-p min-dist] [cur-p cur-dist]))] - + (->> (:content shape) (d/with-prev) (map point+distance) diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index 0c7b8183d..3af771a22 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -7,13 +7,13 @@ (ns app.common.geom.shapes.transforms (:require [app.common.attrs :as attrs] + [app.common.data :as d] [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] [app.common.geom.shapes.common :as gco] [app.common.geom.shapes.path :as gpa] [app.common.geom.shapes.rect :as gpr] [app.common.math :as mth] - [app.common.data :as d] [app.common.text :as txt])) ;; --- Relative Movement @@ -58,12 +58,6 @@ dy (- (d/check-num y) (-> shape :selrect :y))] (move shape (gpt/point dx dy)))) - -(defn- modif-rotation [shape] - (let [cur-rotation (d/check-num (:rotation shape)) - delta-angle (d/check-num (get-in shape [:modifiers :rotation]))] - (mod (+ cur-rotation delta-angle) 360))) - (defn transform-matrix "Returns a transformation matrix without changing the shape properties. The result should be used in a `transform` attribute in svg" @@ -86,14 +80,13 @@ (gpt/point 0 0))] (inverse-transform-matrix shape shape-center))) ([{:keys [flip-x flip-y] :as shape} center] - (let [] - (-> (gmt/matrix) - (gmt/translate center) - (cond-> - flip-x (gmt/scale (gpt/point -1 1)) - flip-y (gmt/scale (gpt/point 1 -1))) - (gmt/multiply (:transform-inverse shape (gmt/matrix))) - (gmt/translate (gpt/negate center)))))) + (-> (gmt/matrix) + (gmt/translate center) + (cond-> + flip-x (gmt/scale (gpt/point -1 1)) + flip-y (gmt/scale (gpt/point 1 -1))) + (gmt/multiply (:transform-inverse shape (gmt/matrix))) + (gmt/translate (gpt/negate center))))) (defn transform-point-center "Transform a point around the shape center" @@ -333,8 +326,9 @@ (dissoc :modifiers)))) shape))) +;; TODO: looks like orig-shape is useless argument (defn apply-text-resize - [shape orig-shape modifiers] + [shape _orig-shape modifiers] (if (and (= (:type shape) :text) (:resize-scale-text modifiers)) (let [merge-attrs (fn [attrs] @@ -376,7 +370,7 @@ :y (- (:y new-selrect 0) (:y selrect 0)) :width (- (:width new-selrect 1) (:width selrect 1)) :height (- (:height new-selrect 1) (:height selrect 1))}] - + (cond-> group (and (some? svg-viewbox) (some? selrect) (some? new-selrect)) (update :svg-viewbox @@ -388,9 +382,6 @@ (defn update-group-selrect [group children] (let [shape-center (gco/center-shape group) - transform (:transform group (gmt/matrix)) - transform-inverse (:transform-inverse group (gmt/matrix)) - ;; Points for every shape inside the group points (->> children (mapcat :points)) diff --git a/common/src/app/common/pages/changes.cljc b/common/src/app/common/pages/changes.cljc index 5d2624574..cc346aac9 100644 --- a/common/src/app/common/pages/changes.cljc +++ b/common/src/app/common/pages/changes.cljc @@ -9,12 +9,11 @@ [app.common.data :as d] [app.common.exceptions :as ex] [app.common.geom.shapes :as gsh] - [app.common.pages.helpers :as cph] - [app.common.pages.spec :as ps] - [app.common.spec :as us] [app.common.pages.common :refer [component-sync-attrs]] + [app.common.pages.helpers :as cph] [app.common.pages.init :as init] - [app.common.pages.spec :as spec])) + [app.common.pages.spec :as spec] + [app.common.spec :as us])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Page Transformation Changes @@ -33,7 +32,7 @@ (when verify? (us/assert ::spec/changes items)) - (let [pages (into #{} (map :page-id) items) + (let [pages (into #{} (map :page-id) items) result (->> items (reduce #(or (process-change %1 %2) %1) data))] @@ -42,7 +41,7 @@ (doseq [page-id pages] (let [page (get-in result [:pages-index page-id])] (doseq [[id shape] (:objects page)] - (if-not (= shape (get-in data [:pages-index page-id :objects id])) + (when-not (= shape (get-in data [:pages-index page-id :objects id])) ;; If object has change verify is correct (us/verify ::spec/shape shape)))))) diff --git a/common/src/app/common/pages/helpers.cljc b/common/src/app/common/pages/helpers.cljc index 9eb194c27..ae9b83da4 100644 --- a/common/src/app/common/pages/helpers.cljc +++ b/common/src/app/common/pages/helpers.cljc @@ -10,7 +10,6 @@ [app.common.geom.shapes :as gsh] [app.common.spec :as us] [app.common.uuid :as uuid] - [clojure.set :as set] [cuerdas.core :as str])) (defn walk-pages @@ -119,14 +118,14 @@ (conj! pending current) (first children) (rest children)) - [result pending]))] + [result pending])) - ;; If we have still pending, advance the iterator - (let [length (count pending)] - (if (pos? length) - (let [next (get pending (dec length))] - (recur result (pop! pending) next)) - (persistent! result)))))) + ;; If we have still pending, advance the iterator + length (count pending)] + (if (pos? length) + (let [next (get pending (dec length))] + (recur result (pop! pending) next)) + (persistent! result))))) (defn get-children-objects "Retrieve all children objects recursively for a given object" @@ -403,14 +402,14 @@ [objects shape-id] (let [shape (get objects shape-id) parent (get objects (:parent-id shape)) - [parent-idx _] (d/seek (fn [[idx child-id]] (= child-id shape-id)) + [parent-idx _] (d/seek (fn [[_idx child-id]] (= child-id shape-id)) (d/enumerate (:shapes parent)))] parent-idx)) (defn split-path - [path] "Decompose a string in the form 'one / two / three' into an array of strings, normalizing spaces." + [path] (->> (str/split path "/") (map str/trim) (remove str/empty?))) diff --git a/common/src/app/common/pages/indices.cljc b/common/src/app/common/pages/indices.cljc index fa3993799..c1681fef1 100644 --- a/common/src/app/common/pages/indices.cljc +++ b/common/src/app/common/pages/indices.cljc @@ -7,7 +7,6 @@ (ns app.common.pages.indices (:require [app.common.data :as d] - [app.common.geom.shapes :as gsh] [app.common.pages.helpers :as helpers] [app.common.uuid :as uuid] [clojure.set :as set])) @@ -100,7 +99,8 @@ "Retrieves the mask information for an object" [objects parents-index] (let [retrieve-masks - (fn [id parents] + (fn [_ parents] + ;; TODO: use transducers? (->> parents (map #(get objects %)) (filter #(:masked-group? %)) diff --git a/common/src/app/common/pages/init.cljc b/common/src/app/common/pages/init.cljc index 5ca2b85f1..08d222f34 100644 --- a/common/src/app/common/pages/init.cljc +++ b/common/src/app/common/pages/init.cljc @@ -7,9 +7,9 @@ (ns app.common.pages.init (:require [app.common.data :as d] - [app.common.uuid :as uuid] [app.common.exceptions :as ex] - [app.common.pages.common :refer [file-version default-color]])) + [app.common.pages.common :refer [file-version default-color]] + [app.common.uuid :as uuid])) (def root uuid/zero) diff --git a/common/src/app/common/pages/migrations.cljc b/common/src/app/common/pages/migrations.cljc index 8e93da804..7a1216780 100644 --- a/common/src/app/common/pages/migrations.cljc +++ b/common/src/app/common/pages/migrations.cljc @@ -6,13 +6,13 @@ (ns app.common.pages.migrations (:require - [app.common.pages :as cp] + [app.common.data :as d] + [app.common.geom.matrix :as gmt] [app.common.geom.shapes :as gsh] [app.common.geom.shapes.path :as gsp] - [app.common.geom.matrix :as gmt] [app.common.math :as mth] - [app.common.uuid :as uuid] - [app.common.data :as d])) + [app.common.pages :as cp] + [app.common.uuid :as uuid])) ;; TODO: revisit this and rename to file-migrations @@ -94,7 +94,7 @@ (= :curve (:type object)) (assoc :type :path) - (or (#{:curve :path} (:type object))) + (#{:curve :path} (:type object)) (migrate-path) (= :frame (:type object)) diff --git a/common/src/app/common/spec.cljc b/common/src/app/common/spec.cljc index 61c651136..ea08717e5 100644 --- a/common/src/app/common/spec.cljc +++ b/common/src/app/common/spec.cljc @@ -11,11 +11,9 @@ (:require #?(:clj [clojure.spec.alpha :as s] :cljs [cljs.spec.alpha :as s]) - - [expound.alpha :as expound] - [app.common.uuid :as uuid] [app.common.exceptions :as ex] [app.common.geom.point :as gpt] + [app.common.uuid :as uuid] [cuerdas.core :as str])) (s/check-asserts true) diff --git a/common/src/app/common/text.cljc b/common/src/app/common/text.cljc index 6c92810a7..9f184e7e9 100644 --- a/common/src/app/common/text.cljc +++ b/common/src/app/common/text.cljc @@ -6,8 +6,6 @@ (ns app.common.text (:require - [app.common.attrs :as attrs] - [app.common.uuid :as uuid] [app.common.data :as d] [app.common.transit :as t] [clojure.walk :as walk] diff --git a/common/src/app/common/transit.cljc b/common/src/app/common/transit.cljc index 365d1913e..7f1eddda5 100644 --- a/common/src/app/common/transit.cljc +++ b/common/src/app/common/transit.cljc @@ -212,5 +212,5 @@ [v] (try (-> v decode-str nil? not) - (catch #?(:cljs js/SyntaxError :clj Exception) e + (catch #?(:cljs js/SyntaxError :clj Exception) _e false)))