📎 Push a copy child's geometry in its new main's frame in the model

Pushing a swap into a main adds main shapes for the swap's children.
The model kept a child's authored geometry in the frame of its copy, so
a flip the child shows only through a flipped copy stayed in the
expected main shape, which production places unflipped. The model now
turns and flips that geometry from the copy parent's frame to the new
main parent's, as it does for main shapes the push keeps.

Harness only; the benchmark is not run.

Also in this commit:

- Drop the main's typography a pushed text style mixes in the model. A copy text
  that overrides some styles of a typography, but not the typography, has no
  typography. Pushing it into a main text that applies a typography drops that
  typography in production, as the main then takes those styles from both sides.
  The model kept the main's typography; it now records the pushed content for
  the typography group in that case.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-10 05:36:00 +01:00
parent a5ebdb9e8c
commit 16689df2e9
2 changed files with 80 additions and 12 deletions

View File

@ -106,6 +106,11 @@
:text-content-typography :typography :text-content-align :align :text-content-direction :direction
:text-content-valign :valign})
;; the text groups of the styles a typography sets
(def ^:private typography-groups
#{:text-content-family :text-content-weight :text-content-size
:text-content-line-height :text-content-spacing :text-content-case})
(defn values
[shape group]
(cond
@ -478,16 +483,18 @@
[group (if (= :geometry-group group) geometry (values shape group))]))
placement))
;; a main shape the push keeps turns with its main afterwards;
;; its pushed geometry leaves out the turn its copy parent shows
;; against its main parent (the root's, against its main)
(and (:geometry-group groups) (not pushed-swap?) (contains? before (:id ref)))
;; a main shape the push keeps or adds turns with its main
;; afterwards; its pushed geometry leaves out the turn its copy
;; parent shows against its main parent (the root's, against
;; its main), which an added main shape has only after the push
(and (:geometry-group groups) (not pushed-swap?))
(update :geometry-group
(fn [geometry]
(if (= (:id shape) root-id)
(in-orientation geometry root main-root)
(in-orientation geometry (get before (:parent-id shape))
(get before (:parent-id ref)))))))
(or (get before (:parent-id ref))
(get after (:parent-id ref))))))))
;; a variant main keeps its set's name, and the copy root its own
kept-name (when (and (= id root-id) (:variant-id ref)) (:name-group groups))
groups (cond-> groups kept-name (dissoc :name-group))
@ -498,13 +505,21 @@
kept-name
(assoc-in [id :name-group] kept-name)
(and (:shape-ref ref) (seq groups))
(update (:id ref) merge
(cond-> (grid/remap-groups groups (grid/get-child-map after shape ref))
;; a clone of the copy shape keeps the swap it authored against the same main
(and (= (:component-id ref)
(:component-id (get after (:shape-ref ref))))
(not= (:shape-ref ref) (:shape-ref shape)))
(dissoc :swap-group))))]
(update (:id ref)
(fn [main-groups]
(let [merged (merge main-groups
(cond-> (grid/remap-groups groups (grid/get-child-map after shape ref))
;; a clone of the copy shape keeps the swap it authored against the same main
(and (= (:component-id ref)
(:component-id (get after (:shape-ref ref))))
(not= (:shape-ref ref) (:shape-ref shape)))
(dissoc :swap-group)))]
(cond-> merged
;; a pushed style of a typography drops the typography of the main
(and (contains? merged :text-content-typography)
(not (contains? groups :text-content-typography))
(some #(contains? groups %) typography-groups))
(assoc :text-content-typography {:content (:content shape)}))))))]
(reduce #(push %1 %2 content?) result (:shapes shape))))]
(push model root-id false)))

View File

@ -2027,6 +2027,23 @@
:ops [[:make-variant 4 0 0 0] [:combine 0 0 0 0] [:transform 6 7 0 0] [:nest 1 0 0 0]
[:combine 3] [:switch 6] [:style 16 35 1] [:edit 8 1 1 :copy-head] [:reset 8]]}))))
(t/deftest pushing-a-swap-into-a-main-leaves-out-the-flip-its-children-show-from-their-copy
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false
:layout-item-margins false :grid-square false :rich-variants true
:layout-children false :grid-empty false :layout-copies true :text true}]
:ops [[:switch 7 0 0 0] [:update-main 0 0 0 0] [:delete 0 0 0 0] [:duplicate 14 0 0 0]
[:transform 4 4 0 4] [:combine 1] [:switch 9] [:transform 5 0 0 7]
[:update-main 3 0 0 0] [:edit 1 0 1 1] [:update-main 1]]}))))
(t/deftest pushing-a-style-of-a-typography-into-a-main-drops-the-mains-typography
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false
:layout-item-margins false :grid-square false :rich-variants true
:layout-children false :grid-empty false :layout-copies true :text true}]
:ops [[:combine 0] [:switch 2] [:make-variant 0 0 0 0] [:swap 4 0 0 0] [:add-variant 20 0 0 0]
[:text-style 6 8 1] [:make-variant 0] [:switch 5] [:make-variant 0] [:switch 6]
[:edit 6 0 1 1] [:update-main 6] [:add-variant 0] [:switch 3] [:edit 0 0 1 1]
[:update-main 0]]}))))
(t/deftest turning-a-flipped-copy-turns-a-child-stored-as-the-other-mirror-turn
(t/is (map? (cg/run {:world [2 2 {:variants true :text-styles true :layout nil :variant-diff false
:layout-item-margins false :grid-square false :rich-variants true
@ -2450,6 +2467,42 @@
(t/is (= 0 (:rotation expected)))
(t/is (= 120 (:height expected)))))
(t/deftest pushed-swap-shadow-leaves-out-the-flip-a-child-shows-from-its-flipped-copy
(let [geometry {:width 50 :height 50 :rotation 0 :flip-x true :flip-y nil :content-scale nil}
before {:copy {:id :copy :shape-ref :main :component-root true :flip-x true :shapes [:child]}
:main {:id :main :component-root true}
:child {:id :child :parent-id :copy :component-id :target :shape-ref :position
:flip-x true :shapes [:leaf]}
:leaf (merge {:id :leaf :parent-id :child :shape-ref :position-leaf} geometry)
:position {:id :position :component-id :target :shapes [:position-leaf]}
:position-leaf {:id :position-leaf :parent-id :position}}
after (-> before
(assoc-in [:child :shape-ref] :pushed)
(assoc-in [:leaf :shape-ref] :pushed-leaf)
(assoc :pushed {:id :pushed :component-id :target :shape-ref :position
:parent-id :main :shapes [:pushed-leaf]}
:pushed-leaf {:id :pushed-leaf :shape-ref :position-leaf :parent-id :pushed}))
model (shadow/update-main {:child {:swap-group {}} :leaf {:geometry-group geometry}}
before after :copy)]
(t/is (false? (get-in model [:pushed-leaf :geometry-group :flip-x])))
(t/is (= 50 (get-in model [:pushed-leaf :geometry-group :width])))))
(t/deftest update-main-shadow-drops-the-main-typography-a-pushed-style-mixes
(let [before {:copy {:id :copy :shape-ref :main :component-root true :shapes [:text]}
:main {:id :main :component-root true :shapes [:main-text]}
:text {:id :text :type :text :parent-id :copy :shape-ref :main-text :content :copy-content}
:main-text {:id :main-text :type :text :parent-id :main :shape-ref :position
:content :main-content}
:position {:id :position :type :text}}
model (shadow/update-main {:text {:text-content-family {:content :copy-content} :content-group {}}
:main-text {:text-content-typography {:content :main-content}
:text-content-size {:content :main-content}
:content-group {}}}
before before :copy)]
(t/is (= {:content :copy-content} (get-in model [:main-text :text-content-typography])))
(t/is (= {:content :copy-content} (get-in model [:main-text :text-content-family])))
(t/is (= {:content :main-content} (get-in model [:main-text :text-content-size])))))
(t/deftest pushed-swap-shadow-predicts-content-without-reading-the-new-child
(let [before {:copy {:id :copy :shape-ref :main :shapes [:child]}
:main {:id :main}