🐛 Fix problems with code generation

This commit is contained in:
alonso.torres 2023-09-22 14:22:40 +02:00
parent 6e8cfa7be4
commit 723c14bef2
9 changed files with 78 additions and 58 deletions

View file

@ -154,7 +154,7 @@
(empty? (:shapes shape)) (empty? (:shapes shape))
[(calculate-base-bounds shape)] [(calculate-base-bounds shape)]
(:masked-group shape) (or (:masked-group shape) (= :bool (:type shape)))
[(calculate-base-bounds shape)] [(calculate-base-bounds shape)]
(and (cph/frame-shape? shape) (not (:show-content shape))) (and (cph/frame-shape? shape) (not (:show-content shape)))

View file

@ -142,7 +142,9 @@
:center :center
[(gpt/add origin-h (hv (/ child-width 2))) [(gpt/add origin-h (hv (/ child-width 2)))
(gpo/project-point cell-bounds :h (gpo/center cell-bounds))] (-> (gpo/project-point cell-bounds :h (gpo/center cell-bounds))
(gpt/add (hv (/ left-m 2)))
(gpt/subtract (hv (/ right-m 2))))]
[origin-h [origin-h
(gpt/add (first cell-bounds) (hv left-m))]) (gpt/add (first cell-bounds) (hv left-m))])
@ -155,7 +157,9 @@
:center :center
[(gpt/add origin-v (vv (/ child-height 2))) [(gpt/add origin-v (vv (/ child-height 2)))
(gpo/project-point cell-bounds :v (gpo/center cell-bounds))] (-> (gpo/project-point cell-bounds :v (gpo/center cell-bounds))
(gpt/add (vv top-m))
(gpt/subtract (vv bottom-m)))]
[origin-v [origin-v
(gpt/add (first cell-bounds) (vv top-m))])] (gpt/add (first cell-bounds) (vv top-m))])]

View file

@ -168,8 +168,7 @@
is-component? (mf/use-ctx muc/is-component?) is-component? (mf/use-ctx muc/is-component?)
childs (cond-> childs childs (cond-> childs
(ctl/any-layout? shape) (ctl/any-layout? shape)
(cph/sort-layout-children-z-index)) (cph/sort-layout-children-z-index))]
]
[:> frame-container props [:> frame-container props
[:g.frame-children {:opacity (:opacity shape)} [:g.frame-children {:opacity (:opacity shape)}

View file

@ -519,8 +519,7 @@
:on-change-behaviour-v-refactor on-change-behaviour-v :on-change-behaviour-v-refactor on-change-behaviour-v
:on-change on-change-behaviour}] :on-change on-change-behaviour}]
(when is-absolute? (when is-absolute?
[:div {:class (stl/css-case :z-index-wrapper true [:div {:class (stl/css-case :z-index-wrapper true)
:disabled (not is-absolute?))
:title "z-index"} :title "z-index"}
[:span {:class (stl/css :icon-text)} [:span {:class (stl/css :icon-text)}
@ -653,7 +652,6 @@
:on-focus #(dom/select-target %) :on-focus #(dom/select-target %)
:on-change #(on-change-z-index %) :on-change #(on-change-z-index %)
:nillable true :nillable true
:disabled (not is-absolute?)
:value (:layout-item-z-index values)}]]]]) :value (:layout-item-z-index values)}]]]])
[:* [:*

View file

@ -11,6 +11,7 @@
(defn shape->selector (defn shape->selector
[shape] [shape]
(if shape
(let [name (-> (:name 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\:]+" "")) (str/replace #"[^a-zA-Z0-9\s\:]+" ""))
@ -20,4 +21,5 @@
(subs 24 36)) (subs 24 36))
selector (str/css-selector (dm/str name " " id)) selector (str/css-selector (dm/str name " " id))
selector (if (str/starts-with? selector "-") (subs selector 1) selector)] selector (if (str/starts-with? selector "-") (subs selector 1) selector)]
selector)) selector)
""))

View file

@ -42,7 +42,7 @@
;; When a shape has several strokes or the stroke is not a "border" ;; When a shape has several strokes or the stroke is not a "border"
(or (> (count (:strokes shape)) 1) (or (> (count (:strokes shape)) 1)
(and (= (count (:strokes shape)) 1) (and (= (count (:strokes shape)) 1)
(not= (-> shape :strokes first :stroke-alignment) :center))))) (not= (-> shape :strokes first :stroke-alignment) :inner)))))
(defn generate-html (defn generate-html
([objects shape] ([objects shape]
@ -58,7 +58,8 @@
(let [svg-markup (generate-svg objects shape)] (let [svg-markup (generate-svg objects shape)]
(dm/fmt "%<div class=\"%\">\n%\n%</div>" (dm/fmt "%<div class=\"%\">\n%\n%</div>"
indent indent
(cgc/shape->selector shape) (dm/str "shape " (d/name (:type shape)) " "
(cgc/shape->selector shape))
svg-markup svg-markup
indent)) indent))
@ -66,7 +67,8 @@
(let [text-shape-html (rds/renderToStaticMarkup (mf/element text/text-shape #js {:shape shape :code? true}))] (let [text-shape-html (rds/renderToStaticMarkup (mf/element text/text-shape #js {:shape shape :code? true}))]
(dm/fmt "%<div class=\"%\">\n%\n%</div>" (dm/fmt "%<div class=\"%\">\n%\n%</div>"
indent indent
(cgc/shape->selector shape) (dm/str "shape " (d/name (:type shape)) " "
(cgc/shape->selector shape))
text-shape-html text-shape-html
indent)) indent))
@ -76,19 +78,22 @@
(dm/fmt "%<img src=\"%\" class=\"%\">\n%</img>" (dm/fmt "%<img src=\"%\" class=\"%\">\n%</img>"
indent indent
image-url image-url
(cgc/shape->selector shape) (dm/str "shape " (d/name (:type shape)) " "
(cgc/shape->selector shape))
indent)) indent))
(empty? (:shapes shape)) (empty? (:shapes shape))
(dm/fmt "%<div class=\"%\">\n%</div>" (dm/fmt "%<div class=\"%\">\n%</div>"
indent indent
(cgc/shape->selector shape) (dm/str "shape " (d/name (:type shape)) " "
(cgc/shape->selector shape))
indent) indent)
:else :else
(dm/fmt "%<div class=\"%\">\n%\n%</div>" (dm/fmt "%<div class=\"%\">\n%\n%</div>"
indent indent
(cgc/shape->selector shape) (dm/str (d/name (:type shape)) " "
(cgc/shape->selector shape))
(->> (:shapes shape) (->> (:shapes shape)
(maybe-reverse) (maybe-reverse)
(map #(generate-html objects (get objects %) (inc level))) (map #(generate-html objects (get objects %) (inc level)))

View file

@ -78,6 +78,7 @@ svg {
:column-gap :column-gap
:row-gap :row-gap
:padding :padding
:z-index
;; Flex related properties ;; Flex related properties
:flex-direction :flex-direction

View file

@ -17,6 +17,8 @@
:top :position :top :position
:width :size :width :size
:height :size :height :size
:min-width :size
:min-height :size
:background :color :background :color
:background-color :color :background-color :color
:background-image :color-array :background-image :color-array
@ -28,6 +30,7 @@
:row-gap :size-array :row-gap :size-array
:column-gap :size-array :column-gap :size-array
:padding :size-array :padding :size-array
:margin :size-array
:grid-template-rows :tracks :grid-template-rows :tracks
:grid-template-columns :tracks :grid-template-columns :tracks
:transform :matrix :transform :matrix

View file

@ -28,8 +28,9 @@
(cond (cond
(or (and (ctl/any-layout-immediate-child? objects shape) (or (and (ctl/any-layout-immediate-child? objects shape)
(not (ctl/layout-absolute? shape)) (not (ctl/layout-absolute? shape))
(or (cph/group-shape? shape) (or (cph/group-like-shape? shape)
(cph/frame-shape? shape))) (cph/frame-shape? shape)
(svg-markup? shape)))
(cph/root-frame? shape)) (cph/root-frame? shape))
:relative :relative
@ -42,8 +43,11 @@
(defn get-shape-position (defn get-shape-position
[shape objects coord] [shape objects coord]
(let [
parent (get objects (:parent-id shape)) (when (and (not (cph/root-frame? shape))
(or (not (ctl/any-layout-immediate-child? objects shape))
(ctl/layout-absolute? shape)))
(let [parent (get objects (:parent-id shape))
parent-value (dm/get-in parent [:selrect coord]) parent-value (dm/get-in parent [:selrect coord])
[selrect _ _] [selrect _ _]
@ -51,24 +55,9 @@
(gsh/transform-points (gsh/shape->center parent) (:transform-inverse parent)) (gsh/transform-points (gsh/shape->center parent) (:transform-inverse parent))
(gsh/calculate-geometry)) (gsh/calculate-geometry))
;;shape (gsh/transform-shape) shape-value (get selrect coord)]
shape-value (get selrect coord)
]
(when (and (not (cph/root-frame? shape))
(or (not (ctl/any-layout-immediate-child? objects shape))
(ctl/layout-absolute? shape)))
(- shape-value parent-value)))) (- shape-value parent-value))))
#_(defn get-shape-position
[shape objects coord]
(when-not (or (cph/root-frame? shape)
(and (ctl/any-layout-immediate-child? objects shape)
(not (ctl/layout-absolute? shape))))
(let [parent (get objects (:parent-id shape))
bounds (gpo/parent-coords-bounds (:points shape) (:points parent))
vv (gpt/to-vec (first (:points parent)) (first bounds))]
(get vv coord))))
(defmethod get-value :left (defmethod get-value :left
[_ shape objects] [_ shape objects]
(get-shape-position shape objects :x)) (get-shape-position shape objects :x))
@ -250,7 +239,8 @@
(defn get-grid-coord (defn get-grid-coord
[shape objects prop span-prop] [shape objects prop span-prop]
(when (ctl/grid-layout-immediate-child? objects shape) (when (and (ctl/grid-layout-immediate-child? objects shape)
(not (ctl/layout-absolute? shape)))
(let [parent (get objects (:parent-id shape)) (let [parent (get objects (:parent-id shape))
cell (ctl/get-cell-by-shape-id parent (:id shape))] cell (ctl/get-cell-by-shape-id parent (:id shape))]
(if (> (get cell span-prop) 1) (if (> (get cell span-prop) 1)
@ -275,10 +265,22 @@
0)) 0))
(defmethod get-value :margin (defmethod get-value :margin
[_ shape objects] [_ {:keys [layout-item-margin] :as shape} objects]
(when (ctl/any-layout-immediate-child? objects shape)
(let [default-margin {:m1 0 :m2 0 :m3 0 :m4 0}
{:keys [m1 m2 m3 m4]} (merge default-margin layout-item-margin)]
(when (or (not= m1 0) (not= m2 0) (not= m3 0) (not= m4 0))
[m1 m2 m3 m4]))))
(defmethod get-value :z-index
[_ {:keys [layout-item-z-index] :as shape} objects]
(cond (cond
(ctl/flex-layout-immediate-child? objects shape) (cph/root-frame? shape)
(:layout-item-margin shape))) 0
(ctl/any-layout-immediate-child? objects shape)
layout-item-z-index))
(defmethod get-value :max-height (defmethod get-value :max-height
[_ shape objects] [_ shape objects]
@ -289,8 +291,11 @@
(defmethod get-value :min-height (defmethod get-value :min-height
[_ shape objects] [_ shape objects]
(cond (cond
(ctl/flex-layout-immediate-child? objects shape) (and (ctl/flex-layout-immediate-child? objects shape) (some? (:layout-item-min-h shape)))
(:layout-item-min-h shape))) (:layout-item-min-h shape)
(and (ctl/auto-height? shape) (cph/frame-shape? shape) (not (:show-content shape)))
(-> shape :selrect :height)))
(defmethod get-value :max-width (defmethod get-value :max-width
[_ shape objects] [_ shape objects]
@ -301,8 +306,11 @@
(defmethod get-value :min-width (defmethod get-value :min-width
[_ shape objects] [_ shape objects]
(cond (cond
(ctl/flex-layout-immediate-child? objects shape) (and (ctl/flex-layout-immediate-child? objects shape) (some? (:layout-item-min-w shape)))
(:layout-item-min-w shape))) (:layout-item-min-w shape)
(and (ctl/auto-width? shape) (cph/frame-shape? shape) (not (:show-content shape)))
(-> shape :selrect :width)))
(defmethod get-value :align-self (defmethod get-value :align-self
[_ shape objects] [_ shape objects]