mirror of
https://github.com/penpot/penpot.git
synced 2025-06-07 06:31:37 +02:00
💄 Format common code
This commit is contained in:
parent
0b29aaecc4
commit
b6ecc8b1be
63 changed files with 825 additions and 880 deletions
|
@ -14,10 +14,10 @@
|
||||||
(:require-macros [app.common.data]))
|
(:require-macros [app.common.data]))
|
||||||
|
|
||||||
(:require
|
(:require
|
||||||
#?(:cljs [cljs.reader :as r]
|
|
||||||
:clj [clojure.edn :as r])
|
|
||||||
#?(:cljs [cljs.core :as c]
|
#?(:cljs [cljs.core :as c]
|
||||||
:clj [clojure.core :as c])
|
:clj [clojure.core :as c])
|
||||||
|
#?(:cljs [cljs.reader :as r]
|
||||||
|
:clj [clojure.edn :as r])
|
||||||
#?(:cljs [goog.array :as garray])
|
#?(:cljs [goog.array :as garray])
|
||||||
[app.common.math :as mth]
|
[app.common.math :as mth]
|
||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
|
@ -846,7 +846,7 @@
|
||||||
(def ^:const trail-zeros-regex-2 #"(\.\d*[^0])0+$")
|
(def ^:const trail-zeros-regex-2 #"(\.\d*[^0])0+$")
|
||||||
|
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(defn format-precision
|
(defn format-precision
|
||||||
"Creates a number with predetermined precision and then removes the trailing 0.
|
"Creates a number with predetermined precision and then removes the trailing 0.
|
||||||
Examples:
|
Examples:
|
||||||
12.0123, 0 => 12
|
12.0123, 0 => 12
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
keys in contrast to clojure.core/select-keys"
|
keys in contrast to clojure.core/select-keys"
|
||||||
[target keys]
|
[target keys]
|
||||||
(assert (vector? keys) "keys expected to be a vector")
|
(assert (vector? keys) "keys expected to be a vector")
|
||||||
`{ ~@(mapcat (fn [key] [key (list `c/get target key)]) keys) ~@[] })
|
`{~@(mapcat (fn [key] [key (list `c/get target key)]) keys) ~@[]})
|
||||||
|
|
||||||
(defmacro get-in
|
(defmacro get-in
|
||||||
"A macro version of `get-in`. Useful when the keys vector is known at
|
"A macro version of `get-in`. Useful when the keys vector is known at
|
||||||
|
|
|
@ -83,7 +83,7 @@
|
||||||
(sm/humanize-explain (::sm/explain data) opts)))
|
(sm/humanize-explain (::sm/explain data) opts)))
|
||||||
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(defn format-throwable
|
(defn format-throwable
|
||||||
[^Throwable cause & {:keys [summary? detail? header? data? explain? chain? data-level data-length trace-length]
|
[^Throwable cause & {:keys [summary? detail? header? data? explain? chain? data-level data-length trace-length]
|
||||||
:or {summary? true
|
:or {summary? true
|
||||||
detail? true
|
detail? true
|
||||||
|
@ -183,13 +183,12 @@
|
||||||
(when-let [cause (ex-cause cause)]
|
(when-let [cause (ex-cause cause)]
|
||||||
(newline)
|
(newline)
|
||||||
(print-detail cause)
|
(print-detail cause)
|
||||||
(recur cause))))))
|
(recur cause))))))]
|
||||||
]
|
|
||||||
|
|
||||||
(with-out-str
|
(with-out-str
|
||||||
(print-all cause)))))
|
(print-all cause)))))
|
||||||
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(defn print-throwable
|
(defn print-throwable
|
||||||
[cause & {:as opts}]
|
[cause & {:as opts}]
|
||||||
(println (format-throwable cause opts))))
|
(println (format-throwable cause opts))))
|
||||||
|
|
|
@ -688,7 +688,7 @@
|
||||||
:val (:shape-ref shape)}
|
:val (:shape-ref shape)}
|
||||||
{:type :set
|
{:type :set
|
||||||
:attr :touched
|
:attr :touched
|
||||||
:val (:touched shape)}]}) ]
|
:val (:touched shape)}]})]
|
||||||
(-> changes
|
(-> changes
|
||||||
(update :redo-changes
|
(update :redo-changes
|
||||||
(fn [redo-changes]
|
(fn [redo-changes]
|
||||||
|
|
|
@ -621,7 +621,7 @@
|
||||||
(defmethod migrate 33
|
(defmethod migrate 33
|
||||||
[data]
|
[data]
|
||||||
(letfn [(update-object [object]
|
(letfn [(update-object [object]
|
||||||
; Ensure all root objects are well formed shapes.
|
;; Ensure all root objects are well formed shapes.
|
||||||
(if (= (:id object) uuid/zero)
|
(if (= (:id object) uuid/zero)
|
||||||
(-> object
|
(-> object
|
||||||
(assoc :parent-id uuid/zero
|
(assoc :parent-id uuid/zero
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
(ns app.common.geom.matrix
|
(ns app.common.geom.matrix
|
||||||
(:require
|
(:require
|
||||||
|
#?(:clj [app.common.fressian :as fres])
|
||||||
#?(:cljs [cljs.pprint :as pp]
|
#?(:cljs [cljs.pprint :as pp]
|
||||||
:clj [clojure.pprint :as pp])
|
:clj [clojure.pprint :as pp])
|
||||||
#?(:clj [app.common.fressian :as fres])
|
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
|
@ -100,7 +100,7 @@
|
||||||
(sg/small-double)
|
(sg/small-double)
|
||||||
(sg/small-double)
|
(sg/small-double)
|
||||||
(sg/small-double)
|
(sg/small-double)
|
||||||
(sg/small-double) )
|
(sg/small-double))
|
||||||
(sg/fmap #(apply pos->Matrix %)))
|
(sg/fmap #(apply pos->Matrix %)))
|
||||||
::oapi/type "string"
|
::oapi/type "string"
|
||||||
::oapi/format "matrix"
|
::oapi/format "matrix"
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
(ns app.common.geom.point
|
(ns app.common.geom.point
|
||||||
(:refer-clojure :exclude [divide min max abs])
|
(:refer-clojure :exclude [divide min max abs])
|
||||||
(:require
|
(:require
|
||||||
#?(:cljs [cljs.pprint :as pp]
|
#?(:clj [app.common.fressian :as fres])
|
||||||
:clj [clojure.pprint :as pp])
|
|
||||||
#?(:cljs [cljs.core :as c]
|
#?(:cljs [cljs.core :as c]
|
||||||
:clj [clojure.core :as c])
|
:clj [clojure.core :as c])
|
||||||
#?(:clj [app.common.fressian :as fres])
|
#?(:cljs [cljs.pprint :as pp]
|
||||||
|
:clj [clojure.pprint :as pp])
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
|
|
|
@ -363,9 +363,9 @@
|
||||||
(cond-> bounds
|
(cond-> bounds
|
||||||
(> target-height height)
|
(> target-height height)
|
||||||
(-> (assoc :height target-height)
|
(-> (assoc :height target-height)
|
||||||
(update :y - (/ (- target-height height ) 2)))
|
(update :y - (/ (- target-height height) 2)))
|
||||||
|
|
||||||
(< target-height height)
|
(< target-height height)
|
||||||
(-> (assoc :width target-width)
|
(-> (assoc :width target-width)
|
||||||
(update :x - (/ (- target-width width ) 2)))))
|
(update :x - (/ (- target-width width) 2)))))
|
||||||
bounds))
|
bounds))
|
||||||
|
|
|
@ -171,7 +171,7 @@
|
||||||
layout-gap-row
|
layout-gap-row
|
||||||
0)
|
0)
|
||||||
|
|
||||||
col-pad (if (or(and row? space-evenly?)
|
col-pad (if (or (and row? space-evenly?)
|
||||||
(and row? space-around?)
|
(and row? space-around?)
|
||||||
(and col? content-evenly?))
|
(and col? content-evenly?))
|
||||||
layout-gap-col
|
layout-gap-col
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
(<= (+ b-y b-height) (+ a-y a-height))))
|
(<= (+ b-y b-height) (+ a-y a-height))))
|
||||||
|
|
||||||
(defn intersects?
|
(defn intersects?
|
||||||
[[a-x a-y a-width a-height ]
|
[[a-x a-y a-width a-height]
|
||||||
[b-x b-y b-width b-height]]
|
[b-x b-y b-width b-height]]
|
||||||
(not (or (<= (+ b-x b-width) a-x)
|
(not (or (<= (+ b-x b-width) a-x)
|
||||||
(<= (+ b-y b-height) a-y)
|
(<= (+ b-y b-height) a-y)
|
||||||
|
@ -76,11 +76,9 @@
|
||||||
y2 (min ra-y rb-y)
|
y2 (min ra-y rb-y)
|
||||||
height (- y2 y1)
|
height (- y2 y1)
|
||||||
rb-x (+ b-x b-width)
|
rb-x (+ b-x b-width)
|
||||||
width (- a-width (- rb-x a-x))
|
width (- a-width (- rb-x a-x))]
|
||||||
]
|
|
||||||
(when (and (> width 0) (> height 0))
|
(when (and (> width 0) (> height 0))
|
||||||
(make-area rb-x y1 width height)))
|
(make-area rb-x y1 width height))))
|
||||||
)
|
|
||||||
|
|
||||||
(defn difference
|
(defn difference
|
||||||
[area-a area-b]
|
[area-a area-b]
|
||||||
|
|
|
@ -82,7 +82,7 @@
|
||||||
(let [[size max-size]
|
(let [[size max-size]
|
||||||
(case type
|
(case type
|
||||||
:percent
|
:percent
|
||||||
(let [value (/ (* total-value value) 100) ]
|
(let [value (/ (* total-value value) 100)]
|
||||||
[value value])
|
[value value])
|
||||||
|
|
||||||
:fixed
|
:fixed
|
||||||
|
@ -190,7 +190,7 @@
|
||||||
;; Apply assign-fr to the track-list
|
;; Apply assign-fr to the track-list
|
||||||
track-list
|
track-list
|
||||||
(reduce
|
(reduce
|
||||||
(fn [track-list [idx assignment] ]
|
(fn [track-list [idx assignment]]
|
||||||
(-> track-list
|
(-> track-list
|
||||||
(update-in [idx :size] max assignment)))
|
(update-in [idx :size] max assignment)))
|
||||||
track-list
|
track-list
|
||||||
|
|
|
@ -176,7 +176,7 @@
|
||||||
[shape rect include-content?]
|
[shape rect include-content?]
|
||||||
|
|
||||||
(when (d/not-empty? (:content shape))
|
(when (d/not-empty? (:content shape))
|
||||||
(let [ ;; If paths are too complex the intersection is too expensive
|
(let [;; If paths are too complex the intersection is too expensive
|
||||||
;; we fallback to check its bounding box otherwise the performance penalty
|
;; we fallback to check its bounding box otherwise the performance penalty
|
||||||
;; is too big
|
;; is too big
|
||||||
;; TODO: Look for ways to optimize this operation
|
;; TODO: Look for ways to optimize this operation
|
||||||
|
|
|
@ -477,8 +477,7 @@
|
||||||
result)
|
result)
|
||||||
last-start (if (= :move-to command)
|
last-start (if (= :move-to command)
|
||||||
point
|
point
|
||||||
last-start)
|
last-start)]
|
||||||
]
|
|
||||||
(recur (first pending)
|
(recur (first pending)
|
||||||
(rest pending)
|
(rest pending)
|
||||||
result
|
result
|
||||||
|
@ -523,7 +522,7 @@
|
||||||
"Point on line"
|
"Point on line"
|
||||||
[position from-p to-p]
|
[position from-p to-p]
|
||||||
|
|
||||||
(let [e1 (gpt/to-vec from-p to-p )
|
(let [e1 (gpt/to-vec from-p to-p)
|
||||||
e2 (gpt/to-vec from-p position)
|
e2 (gpt/to-vec from-p position)
|
||||||
|
|
||||||
len2 (+ (mth/sq (:x e1)) (mth/sq (:y e1)))
|
len2 (+ (mth/sq (:x e1)) (mth/sq (:y e1)))
|
||||||
|
@ -730,7 +729,7 @@
|
||||||
ray-t (get-line-tval ray-line curve-v)]
|
ray-t (get-line-tval ray-line curve-v)]
|
||||||
(and (> ray-t 0)
|
(and (> ray-t 0)
|
||||||
(> (mth/abs (- curve-tg-angle 180)) 0.01)
|
(> (mth/abs (- curve-tg-angle 180)) 0.01)
|
||||||
(> (mth/abs (- curve-tg-angle 0)) 0.01)) )))]
|
(> (mth/abs (- curve-tg-angle 0)) 0.01)))))]
|
||||||
(->> curve-ts
|
(->> curve-ts
|
||||||
(mapv #(vector (curve-values curve %)
|
(mapv #(vector (curve-values curve %)
|
||||||
(curve-windup curve %))))))
|
(curve-windup curve %))))))
|
||||||
|
|
|
@ -74,7 +74,7 @@
|
||||||
points
|
points
|
||||||
(if has-resize?
|
(if has-resize?
|
||||||
(-> (:points shape)
|
(-> (:points shape)
|
||||||
(gco/transform-points (ctm/modifiers->transform modifiers)) )
|
(gco/transform-points (ctm/modifiers->transform modifiers)))
|
||||||
points)]
|
points)]
|
||||||
[modifiers points])]
|
[modifiers points])]
|
||||||
(position-pixel-precision modifiers shape points precision ignore-axis)))
|
(position-pixel-precision modifiers shape points precision ignore-axis)))
|
||||||
|
|
|
@ -239,7 +239,7 @@
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(defn slf4j-log-handler
|
(defn slf4j-log-handler
|
||||||
{:no-doc true}
|
{:no-doc true}
|
||||||
[_ _ _ {:keys [::logger ::level ::trace ::message] }]
|
[_ _ _ {:keys [::logger ::level ::trace ::message]}]
|
||||||
(when-let [logger (enabled? logger level)]
|
(when-let [logger (enabled? logger level)]
|
||||||
(let [message (cond-> @message
|
(let [message (cond-> @message
|
||||||
(some? trace)
|
(some? trace)
|
||||||
|
|
|
@ -344,8 +344,7 @@
|
||||||
|
|
||||||
`(~'withMeta [~this-sym ~val-sym]
|
`(~'withMeta [~this-sym ~val-sym]
|
||||||
(new ~tagname ~@(->> (replace {'$meta val-sym} fields)
|
(new ~tagname ~@(->> (replace {'$meta val-sym} fields)
|
||||||
(generate-field-access this-sym val-sym))))
|
(generate-field-access this-sym val-sym))))])))
|
||||||
])))
|
|
||||||
|
|
||||||
(defmacro defrecord
|
(defmacro defrecord
|
||||||
[rsym fields & impls]
|
[rsym fields & impls]
|
||||||
|
|
|
@ -122,9 +122,7 @@
|
||||||
:encoders (mt/-string-encoders)}
|
:encoders (mt/-string-encoders)}
|
||||||
{:name :collections
|
{:name :collections
|
||||||
:decoders coders
|
:decoders coders
|
||||||
:encoders coders}
|
:encoders coders})))
|
||||||
|
|
||||||
)))
|
|
||||||
|
|
||||||
(defn validator
|
(defn validator
|
||||||
[s]
|
[s]
|
||||||
|
|
|
@ -169,15 +169,14 @@
|
||||||
(map (fn [[k _ s]]
|
(map (fn [[k _ s]]
|
||||||
(str (pad " " level) (str/camel k)
|
(str (pad " " level) (str/camel k)
|
||||||
(when (contains? optional k) "?")
|
(when (contains? optional k) "?")
|
||||||
": " s )))
|
": " s)))
|
||||||
(str/join ",\n"))
|
(str/join ",\n"))
|
||||||
|
|
||||||
header (cond-> (if (zero? level)
|
header (cond-> (if (zero? level)
|
||||||
(str "type " title)
|
(str "type " title)
|
||||||
(str title))
|
(str title))
|
||||||
closed? (str "!")
|
closed? (str "!")
|
||||||
(some? title) (str " ")
|
(some? title) (str " "))]
|
||||||
)]
|
|
||||||
|
|
||||||
(str header "{\n" entries "\n" (pad "}" level))))))
|
(str header "{\n" entries "\n" (pad "}" level))))))
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
(ns app.common.svg
|
(ns app.common.svg
|
||||||
(:require
|
(:require
|
||||||
#?(:cljs ["./svg/optimizer.js" :as svgo])
|
|
||||||
#?(:clj [clojure.xml :as xml]
|
#?(:clj [clojure.xml :as xml]
|
||||||
:cljs [tubax.core :as tubax])
|
:cljs [tubax.core :as tubax])
|
||||||
|
#?(:cljs ["./svg/optimizer.js" :as svgo])
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.geom.matrix :as gmt]
|
[app.common.geom.matrix :as gmt]
|
||||||
|
@ -115,8 +115,7 @@
|
||||||
:tspan
|
:tspan
|
||||||
:use
|
:use
|
||||||
:view
|
:view
|
||||||
:vkern
|
:vkern})
|
||||||
})
|
|
||||||
|
|
||||||
;; https://www.w3.org/TR/SVG11/attindex.html
|
;; https://www.w3.org/TR/SVG11/attindex.html
|
||||||
(def svg-attr-list
|
(def svg-attr-list
|
||||||
|
@ -680,7 +679,7 @@
|
||||||
;; Removed this warning because slows a lot rendering with big svgs
|
;; Removed this warning because slows a lot rendering with big svgs
|
||||||
#_(let [filtered-props (->> attrs (remove known-property?) (map first))]
|
#_(let [filtered-props (->> attrs (remove known-property?) (map first))]
|
||||||
(when (seq filtered-props)
|
(when (seq filtered-props)
|
||||||
(.warn js/console "Unknown properties: " (str/join ", " filtered-props ))))
|
(.warn js/console "Unknown properties: " (str/join ", " filtered-props))))
|
||||||
|
|
||||||
(into {}
|
(into {}
|
||||||
(comp (filter known-property?)
|
(comp (filter known-property?)
|
||||||
|
@ -740,7 +739,7 @@
|
||||||
|
|
||||||
node-defs (->> rec-result (map first) (reduce merge current-node-defs))]
|
node-defs (->> rec-result (map first) (reduce merge current-node-defs))]
|
||||||
|
|
||||||
[ node-defs node ])))
|
[node-defs node])))
|
||||||
|
|
||||||
(defn find-attr-references [attrs]
|
(defn find-attr-references [attrs]
|
||||||
(->> attrs
|
(->> attrs
|
||||||
|
@ -1048,7 +1047,7 @@
|
||||||
(conj {:href (or (:href attrs) (:xlink:href attrs))
|
(conj {:href (or (:href attrs) (:xlink:href attrs))
|
||||||
:width (d/parse-integer (:width attrs) 0)
|
:width (d/parse-integer (:width attrs) 0)
|
||||||
:height (d/parse-integer (:height attrs) 0)})))]
|
:height (d/parse-integer (:height attrs) 0)})))]
|
||||||
(reduce-nodes redfn [] svg-data )))
|
(reduce-nodes redfn [] svg-data)))
|
||||||
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(defn- secure-parser-factory
|
(defn- secure-parser-factory
|
||||||
|
|
|
@ -159,8 +159,8 @@
|
||||||
point->handlers (content->handlers content)
|
point->handlers (content->handlers content)
|
||||||
|
|
||||||
handlers (->> point
|
handlers (->> point
|
||||||
(point->handlers )
|
(point->handlers)
|
||||||
(filter (fn [[ci cp]] (and (not= index ci) (not= prefix cp)) )))]
|
(filter (fn [[ci cp]] (and (not= index ci) (not= prefix cp)))))]
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
(= (count handlers) 1)
|
(= (count handlers) 1)
|
||||||
|
|
|
@ -107,8 +107,7 @@
|
||||||
[:c2x :number]
|
[:c2x :number]
|
||||||
[:c2y :number]
|
[:c2y :number]
|
||||||
[:x :number]
|
[:x :number]
|
||||||
[:y :number]])
|
[:y :number]])]
|
||||||
]
|
|
||||||
(for [params param-list]
|
(for [params param-list]
|
||||||
{:command :curve-to
|
{:command :curve-to
|
||||||
:relative relative
|
:relative relative
|
||||||
|
|
|
@ -132,8 +132,7 @@
|
||||||
[:c2x :number]
|
[:c2x :number]
|
||||||
[:c2y :number]
|
[:c2y :number]
|
||||||
[:x :number]
|
[:x :number]
|
||||||
[:y :number]])
|
[:y :number]])]
|
||||||
]
|
|
||||||
(for [params param-list]
|
(for [params param-list]
|
||||||
{:command :curve-to
|
{:command :curve-to
|
||||||
:relative relative
|
:relative relative
|
||||||
|
@ -254,8 +253,7 @@
|
||||||
|
|
||||||
dtheta (unit-vector-angle v1x v1y v2x v2y)
|
dtheta (unit-vector-angle v1x v1y v2x v2y)
|
||||||
dtheta (if (and (= fs 0) (> dtheta 0)) (- dtheta (* mth/PI 2)) dtheta)
|
dtheta (if (and (= fs 0) (> dtheta 0)) (- dtheta (* mth/PI 2)) dtheta)
|
||||||
dtheta (if (and (= fs 1) (< dtheta 0)) (+ dtheta (* mth/PI 2)) dtheta)
|
dtheta (if (and (= fs 1) (< dtheta 0)) (+ dtheta (* mth/PI 2)) dtheta)]
|
||||||
]
|
|
||||||
|
|
||||||
[cx cy theta1 dtheta]))
|
[cx cy theta1 dtheta]))
|
||||||
|
|
||||||
|
@ -302,8 +300,7 @@
|
||||||
(and (zero? rx)
|
(and (zero? rx)
|
||||||
(zero? ry)))
|
(zero? ry)))
|
||||||
[]
|
[]
|
||||||
(let [
|
(let [rx (mth/abs rx)
|
||||||
rx (mth/abs rx)
|
|
||||||
ry (mth/abs ry)
|
ry (mth/abs ry)
|
||||||
lambda (+ (/ (* x1p x1p) (* rx rx))
|
lambda (+ (/ (* x1p x1p) (* rx rx))
|
||||||
(/ (* y1p y1p) (* ry ry)))
|
(/ (* y1p y1p) (* ry ry)))
|
||||||
|
|
|
@ -6,14 +6,14 @@
|
||||||
|
|
||||||
(ns app.common.transit
|
(ns app.common.transit
|
||||||
(:require
|
(:require
|
||||||
|
#?(:clj [datoteka.fs :as fs])
|
||||||
|
#?(:cljs ["luxon" :as lxn])
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.uri :as uri]
|
[app.common.uri :as uri]
|
||||||
[cognitect.transit :as t]
|
[cognitect.transit :as t]
|
||||||
[lambdaisland.uri :as luri]
|
[lambdaisland.uri :as luri]
|
||||||
[linked.core :as lk]
|
[linked.core :as lk]
|
||||||
[linked.set :as lks]
|
[linked.set :as lks])
|
||||||
#?(:clj [datoteka.fs :as fs])
|
|
||||||
#?(:cljs ["luxon" :as lxn]))
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(:import
|
(:import
|
||||||
java.io.ByteArrayInputStream
|
java.io.ByteArrayInputStream
|
||||||
|
|
|
@ -656,8 +656,7 @@
|
||||||
[modifiers]
|
[modifiers]
|
||||||
(let [modifiers (concat (dm/get-prop modifiers :geometry-parent)
|
(let [modifiers (concat (dm/get-prop modifiers :geometry-parent)
|
||||||
(dm/get-prop modifiers :geometry-child))
|
(dm/get-prop modifiers :geometry-child))
|
||||||
modifiers (sort-by #(dm/get-prop % :order) modifiers)
|
modifiers (sort-by #(dm/get-prop % :order) modifiers)]
|
||||||
]
|
|
||||||
(modifiers->transform1 modifiers)))
|
(modifiers->transform1 modifiers)))
|
||||||
|
|
||||||
(defn modifiers->transform-old
|
(defn modifiers->transform-old
|
||||||
|
|
|
@ -194,8 +194,7 @@
|
||||||
[:vector {:gen/max 1} ::ctss/shadow]]
|
[:vector {:gen/max 1} ::ctss/shadow]]
|
||||||
[:blur {:optional true} ::ctsb/blur]
|
[:blur {:optional true} ::ctsb/blur]
|
||||||
[:grow-type {:optional true}
|
[:grow-type {:optional true}
|
||||||
[::sm/one-of #{:auto-width :auto-height :fixed}]]
|
[::sm/one-of #{:auto-width :auto-height :fixed}]]])
|
||||||
])
|
|
||||||
|
|
||||||
(sm/define! ::group-attrs
|
(sm/define! ::group-attrs
|
||||||
[:map {:title "GroupAttrs"}
|
[:map {:title "GroupAttrs"}
|
||||||
|
|
|
@ -1129,9 +1129,7 @@
|
||||||
(defn assign-cells
|
(defn assign-cells
|
||||||
[parent objects]
|
[parent objects]
|
||||||
(prn ">assign-cells")
|
(prn ">assign-cells")
|
||||||
(let [
|
(let [parent (assign-cell-positions parent objects)
|
||||||
|
|
||||||
parent (assign-cell-positions parent objects)
|
|
||||||
|
|
||||||
shape-has-cell?
|
shape-has-cell?
|
||||||
(into #{} (mapcat (comp :shapes second)) (:layout-grid-cells parent))
|
(into #{} (mapcat (comp :shapes second)) (:layout-grid-cells parent))
|
||||||
|
|
|
@ -8,10 +8,10 @@
|
||||||
(ns app.common.uuid
|
(ns app.common.uuid
|
||||||
(:refer-clojure :exclude [next uuid zero? short])
|
(:refer-clojure :exclude [next uuid zero? short])
|
||||||
(:require
|
(:require
|
||||||
[app.common.data.macros :as dm]
|
|
||||||
#?(:clj [clojure.core :as c])
|
#?(:clj [clojure.core :as c])
|
||||||
#?(:cljs [app.common.uuid-impl :as impl])
|
#?(:cljs [app.common.uuid-impl :as impl])
|
||||||
#?(:cljs [cljs.core :as c]))
|
#?(:cljs [cljs.core :as c])
|
||||||
|
[app.common.data.macros :as dm])
|
||||||
#?(:clj (:import
|
#?(:clj (:import
|
||||||
app.common.UUIDv8
|
app.common.UUIDv8
|
||||||
java.util.UUID
|
java.util.UUID
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
(ns common-tests.colors-test
|
(ns common-tests.colors-test
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
#?(:cljs [goog.color :as gcolors])
|
||||||
[app.common.colors :as colors]
|
[app.common.colors :as colors]
|
||||||
[clojure.test :as t]
|
[app.common.data :as d]
|
||||||
#?(:cljs [goog.color :as gcolors])))
|
[clojure.test :as t]))
|
||||||
|
|
||||||
(t/deftest valid-hex-color
|
(t/deftest valid-hex-color
|
||||||
(t/is (false? (colors/valid-hex-color? nil)))
|
(t/is (false? (colors/valid-hex-color? nil)))
|
||||||
|
@ -18,16 +18,14 @@
|
||||||
(t/is (false? (colors/valid-hex-color? "#qqqqqq")))
|
(t/is (false? (colors/valid-hex-color? "#qqqqqq")))
|
||||||
(t/is (true? (colors/valid-hex-color? "#aaa")))
|
(t/is (true? (colors/valid-hex-color? "#aaa")))
|
||||||
(t/is (false? (colors/valid-hex-color? "#aaaa")))
|
(t/is (false? (colors/valid-hex-color? "#aaaa")))
|
||||||
(t/is (true? (colors/valid-hex-color? "#fabada")))
|
(t/is (true? (colors/valid-hex-color? "#fabada"))))
|
||||||
)
|
|
||||||
|
|
||||||
(t/deftest valid-rgb-color
|
(t/deftest valid-rgb-color
|
||||||
(t/is (false? (colors/valid-rgb-color? nil)))
|
(t/is (false? (colors/valid-rgb-color? nil)))
|
||||||
(t/is (false? (colors/valid-rgb-color? "")))
|
(t/is (false? (colors/valid-rgb-color? "")))
|
||||||
(t/is (false? (colors/valid-rgb-color? "()")))
|
(t/is (false? (colors/valid-rgb-color? "()")))
|
||||||
(t/is (true? (colors/valid-rgb-color? "(255, 30, 30)")))
|
(t/is (true? (colors/valid-rgb-color? "(255, 30, 30)")))
|
||||||
(t/is (true? (colors/valid-rgb-color? "rgb(255, 30, 30)")))
|
(t/is (true? (colors/valid-rgb-color? "rgb(255, 30, 30)"))))
|
||||||
)
|
|
||||||
|
|
||||||
(t/deftest rgb-to-str
|
(t/deftest rgb-to-str
|
||||||
(t/is (= "rgb(1,2,3)" (colors/rgb->str [1 2 3])))
|
(t/is (= "rgb(1,2,3)" (colors/rgb->str [1 2 3])))
|
||||||
|
@ -37,16 +35,14 @@
|
||||||
;; (prn (colors/rgb->hsv [1 2 3]))
|
;; (prn (colors/rgb->hsv [1 2 3]))
|
||||||
;; (prn (gcolors/rgbToHsv 1 2 3))
|
;; (prn (gcolors/rgbToHsv 1 2 3))
|
||||||
(t/is (= [210.0 0.6666666666666666 3.0] (colors/rgb->hsv [1.0 2.0 3.0])))
|
(t/is (= [210.0 0.6666666666666666 3.0] (colors/rgb->hsv [1.0 2.0 3.0])))
|
||||||
#?(:cljs (t/is (= (colors/rgb->hsv [1 2 3]) (vec (gcolors/rgbToHsv 1 2 3)))))
|
#?(:cljs (t/is (= (colors/rgb->hsv [1 2 3]) (vec (gcolors/rgbToHsv 1 2 3))))))
|
||||||
)
|
|
||||||
|
|
||||||
(t/deftest hsv-to-rgb
|
(t/deftest hsv-to-rgb
|
||||||
(t/is (= [1 2 3]
|
(t/is (= [1 2 3]
|
||||||
(colors/hsv->rgb [210 0.6666666666666666 3])))
|
(colors/hsv->rgb [210 0.6666666666666666 3])))
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(t/is (= (colors/hsv->rgb [210 0.6666666666666666 3])
|
(t/is (= (colors/hsv->rgb [210 0.6666666666666666 3])
|
||||||
(vec (gcolors/hsvToRgb 210 0.6666666666666666 3)))))
|
(vec (gcolors/hsvToRgb 210 0.6666666666666666 3))))))
|
||||||
)
|
|
||||||
|
|
||||||
(t/deftest rgb-to-hex
|
(t/deftest rgb-to-hex
|
||||||
(t/is (= "#010203" (colors/rgb->hex [1 2 3]))))
|
(t/is (= "#010203" (colors/rgb->hex [1 2 3]))))
|
||||||
|
@ -68,9 +64,7 @@
|
||||||
(t/is (= [1 2 3] (colors/hsl->rgb [210.0 0.5 0.00784313725490196])))
|
(t/is (= [1 2 3] (colors/hsl->rgb [210.0 0.5 0.00784313725490196])))
|
||||||
(t/is (= [210.0 0.5 0.00784313725490196] (colors/rgb->hsl [1 2 3])))
|
(t/is (= [210.0 0.5 0.00784313725490196] (colors/rgb->hsl [1 2 3])))
|
||||||
#?(:cljs (t/is (= (colors/hsl->rgb [210 0.5 0.00784313725490196])
|
#?(:cljs (t/is (= (colors/hsl->rgb [210 0.5 0.00784313725490196])
|
||||||
(vec (gcolors/hslToRgb 210 0.5 0.00784313725490196)))))
|
(vec (gcolors/hslToRgb 210 0.5 0.00784313725490196))))))
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
(t/deftest expand-hex
|
(t/deftest expand-hex
|
||||||
(t/is (= "aaaaaa" (colors/expand-hex "a")))
|
(t/is (= "aaaaaa" (colors/expand-hex "a")))
|
||||||
|
@ -93,8 +87,5 @@
|
||||||
(t/is (true? (colors/color-string? "magenta")))
|
(t/is (true? (colors/color-string? "magenta")))
|
||||||
(t/is (false? (colors/color-string? nil)))
|
(t/is (false? (colors/color-string? nil)))
|
||||||
(t/is (false? (colors/color-string? "")))
|
(t/is (false? (colors/color-string? "")))
|
||||||
(t/is (false? (colors/color-string? "kkkkkk")))
|
(t/is (false? (colors/color-string? "kkkkkk"))))
|
||||||
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,7 @@
|
||||||
(d/remove-at-index [5 1 2 3 4] 0)))
|
(d/remove-at-index [5 1 2 3 4] 0)))
|
||||||
|
|
||||||
(t/is (= [1 2 3 4]
|
(t/is (= [1 2 3 4]
|
||||||
(d/remove-at-index [1 5 2 3 4] 1)))
|
(d/remove-at-index [1 5 2 3 4] 1))))
|
||||||
)
|
|
||||||
|
|
||||||
(t/deftest with-next
|
(t/deftest with-next
|
||||||
(t/is (= [[0 1] [1 2] [2 3] [3 4] [4 nil]]
|
(t/is (= [[0 1] [1 2] [2 3] [3 4] [4 nil]]
|
||||||
|
|
|
@ -86,5 +86,4 @@
|
||||||
;; (pprint expect)
|
;; (pprint expect)
|
||||||
|
|
||||||
(t/is (= (dissoc expect :version)
|
(t/is (= (dissoc expect :version)
|
||||||
(dissoc res :version)))
|
(dissoc res :version)))))
|
||||||
))
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
(ns common-tests.geom-point-test
|
(ns common-tests.geom-point-test
|
||||||
(:require
|
(:require
|
||||||
[app.common.math :as mth]
|
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
|
[app.common.math :as mth]
|
||||||
[clojure.test :as t]))
|
[clojure.test :as t]))
|
||||||
|
|
||||||
(t/deftest add-points
|
(t/deftest add-points
|
||||||
|
@ -62,8 +62,7 @@
|
||||||
(t/is (gpt/close? rs p1)))
|
(t/is (gpt/close? rs p1)))
|
||||||
|
|
||||||
(let [rs (gpt/min p2 p1)]
|
(let [rs (gpt/min p2 p1)]
|
||||||
(t/is (gpt/close? rs p1)))
|
(t/is (gpt/close? rs p1)))))
|
||||||
))
|
|
||||||
|
|
||||||
(t/deftest max-point
|
(t/deftest max-point
|
||||||
(let [p1 (gpt/point 1 2)
|
(let [p1 (gpt/point 1 2)
|
||||||
|
@ -85,8 +84,7 @@
|
||||||
(t/is (gpt/close? rs p2)))
|
(t/is (gpt/close? rs p2)))
|
||||||
|
|
||||||
(let [rs (gpt/max p2 p1)]
|
(let [rs (gpt/max p2 p1)]
|
||||||
(t/is (gpt/close? rs p2)))
|
(t/is (gpt/close? rs p2)))))
|
||||||
))
|
|
||||||
|
|
||||||
(t/deftest inverse-point
|
(t/deftest inverse-point
|
||||||
(let [p1 (gpt/point 1 2)
|
(let [p1 (gpt/point 1 2)
|
||||||
|
@ -154,8 +152,7 @@
|
||||||
p2 (gpt/point 1 5)
|
p2 (gpt/point 1 5)
|
||||||
rs (gpt/angle-sign p1 p2)]
|
rs (gpt/angle-sign p1 p2)]
|
||||||
(t/is (number? rs))
|
(t/is (number? rs))
|
||||||
(t/is (mth/close? -1 rs)))
|
(t/is (mth/close? -1 rs))))
|
||||||
)
|
|
||||||
|
|
||||||
(t/deftest update-angle
|
(t/deftest update-angle
|
||||||
(let [p1 (gpt/point 1 3)
|
(let [p1 (gpt/point 1 3)
|
||||||
|
@ -184,8 +181,7 @@
|
||||||
(let [p1 (gpt/point -1 -3)
|
(let [p1 (gpt/point -1 -3)
|
||||||
rs (gpt/quadrant p1)]
|
rs (gpt/quadrant p1)]
|
||||||
(t/is (number? rs))
|
(t/is (number? rs))
|
||||||
(t/is (mth/close? 3 rs)))
|
(t/is (mth/close? 3 rs))))
|
||||||
)
|
|
||||||
|
|
||||||
(t/deftest round-point
|
(t/deftest round-point
|
||||||
(let [p1 (gpt/point 1.34567 3.34567)
|
(let [p1 (gpt/point 1.34567 3.34567)
|
||||||
|
@ -198,8 +194,7 @@
|
||||||
rs (gpt/round p1 2)]
|
rs (gpt/round p1 2)]
|
||||||
(t/is (gpt/point? rs))
|
(t/is (gpt/point? rs))
|
||||||
(t/is (mth/close? 1.35 (:x rs)))
|
(t/is (mth/close? 1.35 (:x rs)))
|
||||||
(t/is (mth/close? 3.35 (:y rs))))
|
(t/is (mth/close? 3.35 (:y rs)))))
|
||||||
)
|
|
||||||
|
|
||||||
(t/deftest halft-round-point
|
(t/deftest halft-round-point
|
||||||
(let [p1 (gpt/point 1.34567 3.34567)
|
(let [p1 (gpt/point 1.34567 3.34567)
|
||||||
|
|
|
@ -65,8 +65,7 @@
|
||||||
(get-in shape-after [:selrect :width])))
|
(get-in shape-after [:selrect :width])))
|
||||||
|
|
||||||
(t/is (close? (get-in shape-before [:selrect :height])
|
(t/is (close? (get-in shape-before [:selrect :height])
|
||||||
(get-in shape-after [:selrect :height])))
|
(get-in shape-after [:selrect :height]))))))
|
||||||
)))
|
|
||||||
|
|
||||||
(t/testing "Transform with empty translation"
|
(t/testing "Transform with empty translation"
|
||||||
(t/are [type]
|
(t/are [type]
|
||||||
|
@ -163,9 +162,7 @@
|
||||||
(:selrect shape-after))))
|
(:selrect shape-after))))
|
||||||
|
|
||||||
:rect (grc/make-rect 0 0 ##Inf ##Inf)
|
:rect (grc/make-rect 0 0 ##Inf ##Inf)
|
||||||
:path (grc/make-rect 0 0 ##Inf ##Inf)
|
:path (grc/make-rect 0 0 ##Inf ##Inf))))
|
||||||
))
|
|
||||||
)
|
|
||||||
|
|
||||||
(t/deftest points-to-selrect
|
(t/deftest points-to-selrect
|
||||||
(let [points [(gpt/point 0.5 0.5)
|
(let [points [(gpt/point 0.5 0.5)
|
||||||
|
@ -197,7 +194,7 @@
|
||||||
;; Displacement
|
;; Displacement
|
||||||
(grc/make-rect 0 0 10 10)
|
(grc/make-rect 0 0 10 10)
|
||||||
(-> (grc/make-rect 20 20 10 10)
|
(-> (grc/make-rect 20 20 10 10)
|
||||||
(grc/rect->points ))
|
(grc/rect->points))
|
||||||
(gmt/matrix 1 0 0 1 20 20)
|
(gmt/matrix 1 0 0 1 20 20)
|
||||||
|
|
||||||
;; Resize
|
;; Resize
|
||||||
|
@ -234,5 +231,4 @@
|
||||||
(t/is (true? (gsin/fast-has-point? shape point1)))
|
(t/is (true? (gsin/fast-has-point? shape point1)))
|
||||||
(t/is (true? (gsin/slow-has-point? shape point1)))
|
(t/is (true? (gsin/slow-has-point? shape point1)))
|
||||||
(t/is (false? (gsin/fast-has-point? shape point2)))
|
(t/is (false? (gsin/fast-has-point? shape point2)))
|
||||||
(t/is (false? (gsin/fast-has-point? shape point2)))
|
(t/is (false? (gsin/fast-has-point? shape point2)))))
|
||||||
))
|
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
(ns common-tests.geom-test
|
(ns common-tests.geom-test
|
||||||
(:require
|
(:require
|
||||||
[clojure.test :as t]
|
[app.common.geom.matrix :as gmt]
|
||||||
[app.common.math :as mth]
|
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.matrix :as gmt]))
|
[app.common.math :as mth]
|
||||||
|
[clojure.test :as t]))
|
||||||
|
|
||||||
(t/deftest point-constructors-test
|
(t/deftest point-constructors-test
|
||||||
(t/testing "Create point with both coordinates"
|
(t/testing "Create point with both coordinates"
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
|
|
||||||
(ns common-tests.helpers.components
|
(ns common-tests.helpers.components
|
||||||
(:require
|
(:require
|
||||||
[clojure.test :as t]
|
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
[app.common.types.component :as ctk]
|
[app.common.types.component :as ctk]
|
||||||
[app.common.types.container :as ctn]
|
[app.common.types.container :as ctn]
|
||||||
[app.common.types.file :as ctf]))
|
[app.common.types.file :as ctf]
|
||||||
|
[clojure.test :as t]))
|
||||||
|
|
||||||
;; ---- Helpers to manage libraries and synchronization
|
;; ---- Helpers to manage libraries and synchronization
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
(ns common-tests.pages-helpers-test
|
(ns common-tests.pages-helpers-test
|
||||||
(:require
|
(:require
|
||||||
[clojure.test :as t]
|
[app.common.files.helpers :as cfh]
|
||||||
[clojure.pprint :refer [pprint]]
|
[clojure.pprint :refer [pprint]]
|
||||||
[app.common.files.helpers :as cfh]))
|
[clojure.test :as t]))
|
||||||
|
|
||||||
(t/deftest parse-path-name
|
(t/deftest parse-path-name
|
||||||
(t/is (= ["foo" "bar"] (cfh/parse-path-name "foo/bar")))
|
(t/is (= ["foo" "bar"] (cfh/parse-path-name "foo/bar")))
|
||||||
|
|
|
@ -82,8 +82,7 @@
|
||||||
:option [:values :test2]
|
:option [:values :test2]
|
||||||
:value nil}]
|
:value nil}]
|
||||||
res (ch/process-changes data chgs)]
|
res (ch/process-changes data chgs)]
|
||||||
(t/is (= [:test1] (keys (get-in res [:pages-index page-id :options :values]))))))
|
(t/is (= [:test1] (keys (get-in res [:pages-index page-id :options :values]))))))))
|
||||||
))
|
|
||||||
|
|
||||||
(t/deftest process-change-add-obj
|
(t/deftest process-change-add-obj
|
||||||
(let [file-id (uuid/custom 2 2)
|
(let [file-id (uuid/custom 2 2)
|
||||||
|
@ -137,8 +136,7 @@
|
||||||
(t/is (not (nil? (get objects id-a))))
|
(t/is (not (nil? (get objects id-a))))
|
||||||
(t/is (not (nil? (get objects id-b))))
|
(t/is (not (nil? (get objects id-b))))
|
||||||
(t/is (not (nil? (get objects id-c))))
|
(t/is (not (nil? (get objects id-c))))
|
||||||
(t/is (= [id-b id-c id-a] (get-in objects [uuid/zero :shapes]))))))
|
(t/is (= [id-b id-c id-a] (get-in objects [uuid/zero :shapes]))))))))
|
||||||
))
|
|
||||||
|
|
||||||
(t/deftest process-change-mod-obj
|
(t/deftest process-change-mod-obj
|
||||||
(let [file-id (uuid/custom 2 2)
|
(let [file-id (uuid/custom 2 2)
|
||||||
|
@ -164,9 +162,7 @@
|
||||||
:attr :name
|
:attr :name
|
||||||
:val "foobar"}]}
|
:val "foobar"}]}
|
||||||
res (ch/process-changes data [chg])]
|
res (ch/process-changes data [chg])]
|
||||||
(t/is (= res data))))
|
(t/is (= res data))))))
|
||||||
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
;; (t/deftest process-change-del-obj
|
;; (t/deftest process-change-del-obj
|
||||||
|
|
|
@ -50,6 +50,5 @@
|
||||||
(t/is (= 10 (dm/get-prop u :a)))
|
(t/is (= 10 (dm/get-prop u :a)))
|
||||||
(t/is (= 20 (dm/get-prop u :b)))
|
(t/is (= 20 (dm/get-prop u :b)))
|
||||||
(t/is (= 124 (:c u)))
|
(t/is (= 124 (:c u)))
|
||||||
(t/is (not= u o)))))
|
(t/is (not= u o)))))))
|
||||||
))
|
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
|
|
||||||
(ns common-tests.svg-path-test
|
(ns common-tests.svg-path-test
|
||||||
(:require
|
(:require
|
||||||
|
#?(:cljs [app.common.svg.path.legacy-parser2 :as svg.path.legacy1])
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.pprint :as pp]
|
|
||||||
[app.common.math :as mth]
|
[app.common.math :as mth]
|
||||||
|
[app.common.pprint :as pp]
|
||||||
[app.common.svg.path :as svg.path]
|
[app.common.svg.path :as svg.path]
|
||||||
[app.common.svg.path.legacy-parser2 :as svg.path.legacy2]
|
[app.common.svg.path.legacy-parser2 :as svg.path.legacy2]
|
||||||
[clojure.test :as t]
|
[clojure.test :as t]))
|
||||||
#?(:cljs [app.common.svg.path.legacy-parser2 :as svg.path.legacy1])))
|
|
||||||
|
|
||||||
(t/deftest parse-test-1
|
(t/deftest parse-test-1
|
||||||
(let [data (str "m -994.563 4564.1423 149.3086 -52.8821 30.1828 "
|
(let [data (str "m -994.563 4564.1423 149.3086 -52.8821 30.1828 "
|
||||||
|
@ -242,8 +242,7 @@
|
||||||
|
|
||||||
(doseq [[k v] (:params item1)]
|
(doseq [[k v] (:params item1)]
|
||||||
(t/is (mth/close? v (get-in item2 [:params k]) 0.000000001))
|
(t/is (mth/close? v (get-in item2 [:params k]) 0.000000001))
|
||||||
(t/is (mth/close? v (get-in item3 [:params k]) 0.000000001))
|
(t/is (mth/close? v (get-in item3 [:params k]) 0.000000001)))))))
|
||||||
)))))
|
|
||||||
|
|
||||||
(t/deftest parse-test-5
|
(t/deftest parse-test-5
|
||||||
(let [data (str "M363 826"
|
(let [data (str "M363 826"
|
||||||
|
@ -268,8 +267,7 @@
|
||||||
"8.5 8.676 8.5 21.5 0 12.825-8.675 21.325-8.676 8.5-21.5 8.5Zm120 0Q747 886 "
|
"8.5 8.676 8.5 21.5 0 12.825-8.675 21.325-8.676 8.5-21.5 8.5Zm120 0Q747 886 "
|
||||||
"738.5 877.325q-8.5-8.676-8.5-21.5 0-12.825 8.675-21.325 8.676-8.5 21.5-8.5 "
|
"738.5 877.325q-8.5-8.676-8.5-21.5 0-12.825 8.675-21.325 8.676-8.5 21.5-8.5 "
|
||||||
"12.825 0 21.325 8.675 8.5 8.676 8.5 21.5 0 12.825-8.675 21.325-8.676 8.5-21.5 "
|
"12.825 0 21.325 8.675 8.5 8.676 8.5 21.5 0 12.825-8.675 21.325-8.676 8.5-21.5 "
|
||||||
"8.5Z"
|
"8.5Z")
|
||||||
)
|
|
||||||
|
|
||||||
result1 (->> (svg.path/parse data)
|
result1 (->> (svg.path/parse data)
|
||||||
(mapv (fn [entry]
|
(mapv (fn [entry]
|
||||||
|
@ -287,15 +285,13 @@
|
||||||
|
|
||||||
(dotimes [i (count result1)]
|
(dotimes [i (count result1)]
|
||||||
(let [item1 (nth result1 i)
|
(let [item1 (nth result1 i)
|
||||||
item2 (nth result2 i)
|
item2 (nth result2 i)]
|
||||||
]
|
|
||||||
|
|
||||||
(t/is (= (:command item1)
|
(t/is (= (:command item1)
|
||||||
(:command item2)))
|
(:command item2)))
|
||||||
|
|
||||||
(doseq [[k v] (:params item1)]
|
(doseq [[k v] (:params item1)]
|
||||||
(t/is (mth/close? v (get-in item2 [:params k]) 0.000000001))
|
(t/is (mth/close? v (get-in item2 [:params k]) 0.000000001)))))))
|
||||||
)))))
|
|
||||||
|
|
||||||
(t/deftest parse-test-6
|
(t/deftest parse-test-6
|
||||||
(let [data (str "M3.078 3.548v16.9a.5.5 0 0 0 1 0v-16.9a.5.5 0 0 0-1 0ZM18.422 11.5"
|
(let [data (str "M3.078 3.548v16.9a.5.5 0 0 0 1 0v-16.9a.5.5 0 0 0-1 0ZM18.422 11.5"
|
||||||
|
@ -325,15 +321,13 @@
|
||||||
|
|
||||||
(dotimes [i (count result1)]
|
(dotimes [i (count result1)]
|
||||||
(let [item1 (nth result1 i)
|
(let [item1 (nth result1 i)
|
||||||
item2 (nth result2 i)
|
item2 (nth result2 i)]
|
||||||
]
|
|
||||||
|
|
||||||
(t/is (= (:command item1)
|
(t/is (= (:command item1)
|
||||||
(:command item2)))
|
(:command item2)))
|
||||||
|
|
||||||
(doseq [[k v] (:params item1)]
|
(doseq [[k v] (:params item1)]
|
||||||
(t/is (mth/close? v (get-in item2 [:params k]) 0.000000001))
|
(t/is (mth/close? v (get-in item2 [:params k]) 0.000000001)))))
|
||||||
)))
|
|
||||||
|
|
||||||
#?(:cljs
|
#?(:cljs
|
||||||
(let [result3 (svg.path.legacy1/parse data)]
|
(let [result3 (svg.path.legacy1/parse data)]
|
||||||
|
@ -414,9 +408,7 @@
|
||||||
(dotimes [i (count result2)]
|
(dotimes [i (count result2)]
|
||||||
(t/is (mth/close? (nth result2 i)
|
(t/is (mth/close? (nth result2 i)
|
||||||
(nth expected2 i)
|
(nth expected2 i)
|
||||||
0.000000000001)))))
|
0.000000000001)))))))
|
||||||
|
|
||||||
))
|
|
||||||
|
|
||||||
(t/deftest arc-to-bezier-2
|
(t/deftest arc-to-bezier-2
|
||||||
(let [expected1 [3.0779999999999994,
|
(let [expected1 [3.0779999999999994,
|
||||||
|
@ -486,9 +478,7 @@
|
||||||
(dotimes [i (count result2)]
|
(dotimes [i (count result2)]
|
||||||
(t/is (mth/close? (nth result2 i)
|
(t/is (mth/close? (nth result2 i)
|
||||||
(nth expected2 i)
|
(nth expected2 i)
|
||||||
0.000000000001)))))
|
0.000000000001)))))))
|
||||||
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -553,8 +543,7 @@
|
||||||
(t/is (= (nth result 2)
|
(t/is (= (nth result 2)
|
||||||
(nth expected 2)))
|
(nth expected 2)))
|
||||||
(t/is (= (nth result 3)
|
(t/is (= (nth result 3)
|
||||||
(nth expected 3)))
|
(nth expected 3)))))
|
||||||
))
|
|
||||||
|
|
||||||
;; FOR POSSIBLE FUTURE TEST CASES
|
;; FOR POSSIBLE FUTURE TEST CASES
|
||||||
;; (str "M259.958 89.134c-6.88-.354-10.484-1.241-12.44-3.064-1.871-1.743-6.937-3.098-15.793-4.226-7.171-.913-17.179-2.279-22.24-3.034-5.06-.755-15.252-2.016-22.648-2.8-18.685-1.985-35.63-4.223-38.572-5.096-3.655-1.084-3.016-3.548.708-2.726 1.751.387 13.376 1.701 25.833 2.922 12.456 1.22 29.018 3.114 36.803 4.208 29.94 4.206 29.433 4.204 34.267.136 3.787-3.186 5.669-3.669 14.303-3.669 14.338 0 17.18 1.681 12.182 7.205-2.053 2.268-1.994 2.719.707 5.42 3.828 3.827 3.74 5.846-.238 5.5-1.752-.153-7.544-.502-12.872-.776zm7.563-3.194c0-.778-1.751-1.352-3.892-1.274l-3.893.141 3.539 1.133c1.946.624 3.698 1.197 3.893 1.275.194.077.354-.496.354-1.275zm-15.899-8.493c1.43-2.29 1.414-2.83-.084-2.83-2.05 0-5.25 2.76-5.25 4.529 0 2.226 3.599 1.08 5.334-1.699zm8.114 0c2.486-2.746 2.473-2.83-.438-2.83-1.65 0-3.683 1.273-4.516 2.83-1.175 2.196-1.077 2.831.438 2.831 1.075 0 3.107-1.274 4.516-2.83zm7.814.674c2.858-3.444.476-4.085-3.033-.816-2.451 2.284-2.677 2.973-.975 2.973 1.22 0 3.023-.97 4.008-2.157zm-49.571-4.509c-1.168-.43-3.294-1.802-4.725-3.051-2.112-1.843-9.304-2.595-38.219-3.994-46.474-2.25-63-4.077-60.27-6.665.324-.308 9.507.261 20.406 1.264 10.9 1.003 31.16 2.258 45.024 2.789l25.207.964 4.625-3.527c4.313-3.29 5.41-3.474 16.24-2.732 6.389.438 11.981 1.388 12.428 2.111.447.723-.517 2.73-2.141 4.46l-2.954 3.144c1.607 1.697 3.308 3.289 5.049 4.845 3.248 2.189-5.438 1.289-8.678 1.284-5.428-.061-10.825-.463-11.992-.892zm12.74-3.242c-1.123-.694-2.36-.943-2.75-.554-.389.39.21 1.275 1.334 1.97 1.122.693 2.36.942 2.749.553.389-.39-.21-1.275-1.334-1.97zm-5.663 0a1.42 1.42 0 00-1.415-1.416 1.42 1.42 0 00-1.416 1.416 1.42 1.42 0 001.416 1.415 1.42 1.42 0 001.415-1.415zm-8.464-6.404c.984-1.187 1.35-2.598.813-3.135-1.181-1.18-5.408 1.297-6.184 3.624-.806 2.42 3.265 2.048 5.37-.49zm6.863.258c.867-1.045 1.163-2.313.658-2.819-1.063-1.062-4.719 1.631-4.719 3.476 0 1.864 2.274 1.496 4.061-.657zm8.792-.36c1.637-1.972 1.448-2.197-1.486-1.77-1.848.27-3.622 1.287-3.943 2.26-.838 2.547 3.212 2.181 5.429-.49zm32.443-4.11c-6.156-2.228-67.1-6.138-119.124-7.642-39.208-1.134-72.072-.928-94.618.593-6.617.446-19.681 1.16-29.03 1.587-15.798.72-17.183.573-19.588-2.085-4.498-4.97-2.544-7.857 6.39-9.44 4.394-.778 9.164-2.436 10.6-3.685 5.44-4.729 20.332-14.06 31.14-19.509C65.717 11.88 78.955 7.79 103.837 3.08 121.686-.3 125.552-.642 129.318.82c2.44.948 12.4 1.948 22.132 2.221 15.37.432 20.004 1.18 35.294 5.698 22.36 6.606 39.732 15.1 56.55 27.653 7.307 5.452 14.086 9.913 15.066 9.913.98 0 2.148.956 2.596 2.124.55 1.432 2.798 2.123 6.914 2.123 6.213 0 12.4 3.046 12.38 6.096-.012 1.75-6.502 5.353-9.118 5.063-.818-.09-3.717-.972-6.442-1.958zm-16.986-7.436c0-1.575-33.326-18.118-43.173-21.43-23.008-7.739-54.084-12.922-77.136-12.866-16.863.041-37.877 3.628-52.465 8.956-18.062 6.596-26.563 10.384-29.181 13.002-1.205 1.205-5.306 3.769-9.112 5.698-7.754 3.929-8.841 5.482-3.029 4.325 13.494-2.685 66.794-3.773 110.913-2.264 38.005 1.3 96.812 4.435 102.122 5.443.584.111 1.061-.277 1.061-.864zm-236.39-3.18c0-.78-1.592-1.416-3.539-1.416-1.946 0-3.538.637-3.538 1.415 0 .779 1.592 1.416 3.538 1.416 1.947 0 3.54-.637 3.54-1.416zm7.078-1.416c0-.779-.956-1.416-2.124-1.416-1.167 0-2.123.637-2.123 1.416 0 .778.956 1.415 2.123 1.415 1.168 0 2.124-.637 2.124-1.415zm11.734-4.437c3.278-1.661 6.278-3.483 6.667-4.048 1.366-1.98 20.645-11.231 32.557-15.622 11.862-4.372 36.546-9.865 44.327-9.865 3.485 0 3.867-.404 3.012-3.185-.538-1.752-1.177-3.41-1.42-3.685-.907-1.026-36.72 7.16-45.065 10.302-17.226 6.484-47.566 24.27-47.566 27.886 0 1.786.845 1.585 7.488-1.783zm206.254-5.577c-12.298-10.518-53.842-27.166-70.896-28.41-5.526-.404-6.3-.097-6.695 2.655-.33 2.307.402 3.275 2.831 3.742 32.436 6.237 52.205 12.315 66.975 20.594 11.904 6.673 14.477 7.141 7.785 1.419zM150.1 11.04c-1.949-3.64-7.568-4.078-6.886-.538.256 1.329 2.054 2.817 3.997 3.309 4.498 1.137 4.816.832 2.888-2.771zm6.756.94c-.248-1.752-1.026-3.185-1.727-3.185-.7 0-1.493 1.433-1.76 3.185-.328 2.152.232 3.185 1.727 3.185 1.485 0 2.064-1.047 1.76-3.185zm-30.178-2.458c0-2.303-.908-3.694-2.627-4.025-3.6-.694-5.23 1.301-4.22 5.166 1.216 4.647 6.847 3.709 6.847-1.14zm12.544 2.104c-.448-1.168-1.224-2.132-1.725-2.142-.5-.013-2.343-.404-4.095-.873-2.569-.689-3.185-.274-3.185 2.142 0 2.476.854 2.996 4.91 2.996 3.783 0 4.723-.487 4.095-2.123z")
|
;; (str "M259.958 89.134c-6.88-.354-10.484-1.241-12.44-3.064-1.871-1.743-6.937-3.098-15.793-4.226-7.171-.913-17.179-2.279-22.24-3.034-5.06-.755-15.252-2.016-22.648-2.8-18.685-1.985-35.63-4.223-38.572-5.096-3.655-1.084-3.016-3.548.708-2.726 1.751.387 13.376 1.701 25.833 2.922 12.456 1.22 29.018 3.114 36.803 4.208 29.94 4.206 29.433 4.204 34.267.136 3.787-3.186 5.669-3.669 14.303-3.669 14.338 0 17.18 1.681 12.182 7.205-2.053 2.268-1.994 2.719.707 5.42 3.828 3.827 3.74 5.846-.238 5.5-1.752-.153-7.544-.502-12.872-.776zm7.563-3.194c0-.778-1.751-1.352-3.892-1.274l-3.893.141 3.539 1.133c1.946.624 3.698 1.197 3.893 1.275.194.077.354-.496.354-1.275zm-15.899-8.493c1.43-2.29 1.414-2.83-.084-2.83-2.05 0-5.25 2.76-5.25 4.529 0 2.226 3.599 1.08 5.334-1.699zm8.114 0c2.486-2.746 2.473-2.83-.438-2.83-1.65 0-3.683 1.273-4.516 2.83-1.175 2.196-1.077 2.831.438 2.831 1.075 0 3.107-1.274 4.516-2.83zm7.814.674c2.858-3.444.476-4.085-3.033-.816-2.451 2.284-2.677 2.973-.975 2.973 1.22 0 3.023-.97 4.008-2.157zm-49.571-4.509c-1.168-.43-3.294-1.802-4.725-3.051-2.112-1.843-9.304-2.595-38.219-3.994-46.474-2.25-63-4.077-60.27-6.665.324-.308 9.507.261 20.406 1.264 10.9 1.003 31.16 2.258 45.024 2.789l25.207.964 4.625-3.527c4.313-3.29 5.41-3.474 16.24-2.732 6.389.438 11.981 1.388 12.428 2.111.447.723-.517 2.73-2.141 4.46l-2.954 3.144c1.607 1.697 3.308 3.289 5.049 4.845 3.248 2.189-5.438 1.289-8.678 1.284-5.428-.061-10.825-.463-11.992-.892zm12.74-3.242c-1.123-.694-2.36-.943-2.75-.554-.389.39.21 1.275 1.334 1.97 1.122.693 2.36.942 2.749.553.389-.39-.21-1.275-1.334-1.97zm-5.663 0a1.42 1.42 0 00-1.415-1.416 1.42 1.42 0 00-1.416 1.416 1.42 1.42 0 001.416 1.415 1.42 1.42 0 001.415-1.415zm-8.464-6.404c.984-1.187 1.35-2.598.813-3.135-1.181-1.18-5.408 1.297-6.184 3.624-.806 2.42 3.265 2.048 5.37-.49zm6.863.258c.867-1.045 1.163-2.313.658-2.819-1.063-1.062-4.719 1.631-4.719 3.476 0 1.864 2.274 1.496 4.061-.657zm8.792-.36c1.637-1.972 1.448-2.197-1.486-1.77-1.848.27-3.622 1.287-3.943 2.26-.838 2.547 3.212 2.181 5.429-.49zm32.443-4.11c-6.156-2.228-67.1-6.138-119.124-7.642-39.208-1.134-72.072-.928-94.618.593-6.617.446-19.681 1.16-29.03 1.587-15.798.72-17.183.573-19.588-2.085-4.498-4.97-2.544-7.857 6.39-9.44 4.394-.778 9.164-2.436 10.6-3.685 5.44-4.729 20.332-14.06 31.14-19.509C65.717 11.88 78.955 7.79 103.837 3.08 121.686-.3 125.552-.642 129.318.82c2.44.948 12.4 1.948 22.132 2.221 15.37.432 20.004 1.18 35.294 5.698 22.36 6.606 39.732 15.1 56.55 27.653 7.307 5.452 14.086 9.913 15.066 9.913.98 0 2.148.956 2.596 2.124.55 1.432 2.798 2.123 6.914 2.123 6.213 0 12.4 3.046 12.38 6.096-.012 1.75-6.502 5.353-9.118 5.063-.818-.09-3.717-.972-6.442-1.958zm-16.986-7.436c0-1.575-33.326-18.118-43.173-21.43-23.008-7.739-54.084-12.922-77.136-12.866-16.863.041-37.877 3.628-52.465 8.956-18.062 6.596-26.563 10.384-29.181 13.002-1.205 1.205-5.306 3.769-9.112 5.698-7.754 3.929-8.841 5.482-3.029 4.325 13.494-2.685 66.794-3.773 110.913-2.264 38.005 1.3 96.812 4.435 102.122 5.443.584.111 1.061-.277 1.061-.864zm-236.39-3.18c0-.78-1.592-1.416-3.539-1.416-1.946 0-3.538.637-3.538 1.415 0 .779 1.592 1.416 3.538 1.416 1.947 0 3.54-.637 3.54-1.416zm7.078-1.416c0-.779-.956-1.416-2.124-1.416-1.167 0-2.123.637-2.123 1.416 0 .778.956 1.415 2.123 1.415 1.168 0 2.124-.637 2.124-1.415zm11.734-4.437c3.278-1.661 6.278-3.483 6.667-4.048 1.366-1.98 20.645-11.231 32.557-15.622 11.862-4.372 36.546-9.865 44.327-9.865 3.485 0 3.867-.404 3.012-3.185-.538-1.752-1.177-3.41-1.42-3.685-.907-1.026-36.72 7.16-45.065 10.302-17.226 6.484-47.566 24.27-47.566 27.886 0 1.786.845 1.585 7.488-1.783zm206.254-5.577c-12.298-10.518-53.842-27.166-70.896-28.41-5.526-.404-6.3-.097-6.695 2.655-.33 2.307.402 3.275 2.831 3.742 32.436 6.237 52.205 12.315 66.975 20.594 11.904 6.673 14.477 7.141 7.785 1.419zM150.1 11.04c-1.949-3.64-7.568-4.078-6.886-.538.256 1.329 2.054 2.817 3.997 3.309 4.498 1.137 4.816.832 2.888-2.771zm6.756.94c-.248-1.752-1.026-3.185-1.727-3.185-.7 0-1.493 1.433-1.76 3.185-.328 2.152.232 3.185 1.727 3.185 1.485 0 2.064-1.047 1.76-3.185zm-30.178-2.458c0-2.303-.908-3.694-2.627-4.025-3.6-.694-5.23 1.301-4.22 5.166 1.216 4.647 6.847 3.709 6.847-1.14zm12.544 2.104c-.448-1.168-1.224-2.132-1.725-2.142-.5-.013-2.343-.404-4.095-.873-2.569-.689-3.185-.274-3.185 2.142 0 2.476.854 2.996 4.91 2.996 3.783 0 4.723-.487 4.095-2.123z")
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.text :as txt]
|
[app.common.text :as txt]
|
||||||
[clojure.test :as t :include-macros true]
|
[clojure.pprint :refer [pprint]]
|
||||||
[clojure.pprint :refer [pprint]]))
|
[clojure.test :as t :include-macros true]))
|
||||||
|
|
||||||
(t/deftest test-basic-conversion-roundtrip
|
(t/deftest test-basic-conversion-roundtrip
|
||||||
(let [text "qwqw 🠒"
|
(let [text "qwqw 🠒"
|
||||||
|
|
|
@ -187,8 +187,7 @@
|
||||||
:text-decoration "none"
|
:text-decoration "none"
|
||||||
:letter-spacing "0"
|
:letter-spacing "0"
|
||||||
:fills [{:fill-color "#000000"
|
:fills [{:fill-color "#000000"
|
||||||
:fill-opacity 1}]}]
|
:fill-opacity 1}]}]}]}]}}))
|
||||||
}]}]}}))
|
|
||||||
absorbed-file (ctf/update-file-data
|
absorbed-file (ctf/update-file-data
|
||||||
file
|
file
|
||||||
#(ctf/absorb-assets % (:data library)))
|
#(ctf/absorb-assets % (:data library)))
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
(ns common-tests.types-modifiers-test
|
(ns common-tests.types-modifiers-test
|
||||||
(:require
|
(:require
|
||||||
[clojure.test :as t]
|
|
||||||
[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.types.modifiers :as ctm]))
|
[app.common.types.modifiers :as ctm]
|
||||||
|
[clojure.test :as t]))
|
||||||
|
|
||||||
(t/deftest test-modifiers->transform
|
(t/deftest test-modifiers->transform
|
||||||
(let [modifiers
|
(let [modifiers
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
|
|
||||||
(ns common-tests.types-shape-interactions-test
|
(ns common-tests.types-shape-interactions-test
|
||||||
(:require
|
(:require
|
||||||
[app.common.math :as mth]
|
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.rect :as grc]
|
[app.common.geom.rect :as grc]
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
|
[app.common.math :as mth]
|
||||||
[app.common.types.shape :as cts]
|
[app.common.types.shape :as cts]
|
||||||
[app.common.types.shape.interactions :as ctsi]
|
[app.common.types.shape.interactions :as ctsi]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
|
@ -48,8 +48,7 @@
|
||||||
new-interaction
|
new-interaction
|
||||||
(ctsi/set-event-type interaction :after-delay frame)]
|
(ctsi/set-event-type interaction :after-delay frame)]
|
||||||
(t/is (= :after-delay (:event-type new-interaction)))
|
(t/is (= :after-delay (:event-type new-interaction)))
|
||||||
(t/is (= 300 (:delay new-interaction)))))
|
(t/is (= 300 (:delay new-interaction)))))))
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
(t/deftest set-action-type
|
(t/deftest set-action-type
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
|
|
||||||
(ns common-tests.types-test
|
(ns common-tests.types-test
|
||||||
(:require
|
(:require
|
||||||
[clojure.test :as t]
|
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.schema.generators :as sg]
|
[app.common.schema.generators :as sg]
|
||||||
[app.common.transit :as transit]
|
[app.common.transit :as transit]
|
||||||
[app.common.types.shape :as cts]
|
[app.common.types.file :as ctf]
|
||||||
[app.common.types.page :as ctp]
|
[app.common.types.page :as ctp]
|
||||||
[app.common.types.file :as ctf]))
|
[app.common.types.shape :as cts]
|
||||||
|
[clojure.test :as t]))
|
||||||
|
|
||||||
(t/deftest transit-encode-decode-with-shape
|
(t/deftest transit-encode-decode-with-shape
|
||||||
(sg/check!
|
(sg/check!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue