Improved code generation

This commit is contained in:
alonso.torres 2023-06-26 12:51:02 +02:00
parent cb502fc70d
commit 30d78554c2
10 changed files with 117 additions and 40 deletions

View file

@ -12,11 +12,12 @@
(defn shape->selector
[shape]
(let [name (-> (:name shape)
(subs 0 (min 10 (count (:name shape)))))
(subs 0 (min 10 (count (:name shape))))
(str/replace #"[^a-zA-Z0-9\s\:]+" ""))
;; selectors cannot start with numbers
name (if (re-matches #"^\d.*" name) (dm/str "c-" name) name)
id (-> (dm/str (:id shape))
#_(subs 24 36))
(subs 24 36))
selector (str/css-selector (dm/str name " " id))
selector (if (str/starts-with? selector "-") (subs selector 1) selector)]
selector))

View file

@ -30,6 +30,7 @@
:padding :size-array
:grid-template-rows :tracks
:grid-template-columns :tracks
:transform :matrix
})
(defmulti format-value
@ -132,6 +133,10 @@
[_ value _options]
(dm/fmt "blur(%)" (fmt/format-pixels value)))
(defmethod format-value :matrix
[_ value _options]
(fmt/format-matrix value))
(defmethod format-value :default
[_ value _options]
(if (keyword? value)

View file

@ -77,12 +77,13 @@
(get-shape-position shape objects :y))
(defn get-shape-size
[shape type]
[shape objects type]
(let [sizing (if (= type :width)
(:layout-item-h-sizing shape)
(:layout-item-v-sizing shape))]
(cond
(or (= sizing :fill) (= sizing :auto))
(or (and (ctl/any-layout? shape) (= sizing :auto))
(and (ctl/any-layout-immediate-child? shape objects) (= sizing :fill)))
sizing
(some? (:selrect shape))
@ -92,18 +93,22 @@
(get shape type))))
(defmethod get-value :width
[_ shape _]
(get-shape-size shape :width))
[_ shape objects]
(get-shape-size shape objects :width))
(defmethod get-value :height
[_ shape _]
(get-shape-size shape :height))
[_ shape objects]
(get-shape-size shape objects :height))
(defmethod get-value :transform
[_ shape objects]
(let [parent (get objects (:parent-id shape))]
(dm/str (gmt/multiply (:transform shape (gmt/matrix))
(:transform-inverse parent (gmt/matrix))))))
(let [parent (get objects (:parent-id shape))
transform
(gmt/multiply (:transform shape (gmt/matrix))
(:transform-inverse parent (gmt/matrix)))]
(when-not (gmt/unit? transform)
transform)))
(defmethod get-value :background
[_ {:keys [fills] :as shape} _]