From cfa5241f3d7163deec6e446c71844aeb3fc13d99 Mon Sep 17 00:00:00 2001 From: Daniel Leong Date: Fri, 1 Nov 2024 15:20:28 -0400 Subject: [PATCH 1/2] Migrate to the lambdaisland-maintained version of garden --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index c1c121b..a296197 100644 --- a/project.clj +++ b/project.clj @@ -8,7 +8,7 @@ :dependencies [[org.clojure/clojure "1.10.0"] [org.clojure/clojurescript "1.10.520"] - [garden "1.3.10"] + [com.lambdaisland/garden "1.5.569"] [net.cgrand/macrovich "0.2.1"]] :plugins [[lein-figwheel "0.5.19"] From f82b77270117b9b7c1054ad822b04a82f20c9bd3 Mon Sep 17 00:00:00 2001 From: Daniel Leong Date: Fri, 1 Nov 2024 15:21:06 -0400 Subject: [PATCH 2/2] Fix support for complex defkeyframes in the latest garden version --- src/spade/core.cljc | 17 ++++++++++++----- src/spade/util.cljc | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/spade/core.cljc b/src/spade/core.cljc index 119421d..59fbeb0 100644 --- a/src/spade/core.cljc +++ b/src/spade/core.cljc @@ -5,7 +5,8 @@ #?@(:clj [[garden.stylesheet] [net.cgrand.macrovich :as macros] [spade.runtime]]) - [spade.util :refer [factory->name build-style-name]])) + [spade.util :refer [factory->name build-style-name + unpack-keyframes-nesting]])) (defn- extract-key [style] (:key (meta (first style)))) @@ -169,10 +170,16 @@ style params style-name-var) info-map (cond-> `{:css (when ~name-var - (spade.runtime/compile-css - (garden.stylesheet/at-keyframes - ~name-var - ~(or base-style-var (vec style))))) + ~(if base-style-var + `(spade.runtime/compile-css + (apply garden.stylesheet/at-keyframes + ~name-var + (#'unpack-keyframes-nesting ~base-style-var))) + `(spade.runtime/compile-css + (garden.stylesheet/at-keyframes + ~name-var + ~@style)))) + :style ~(str (vec style)) :name ~name-var} key-var (assoc ::key key-var))] diff --git a/src/spade/util.cljc b/src/spade/util.cljc index b1582ec..8d45ac8 100644 --- a/src/spade/util.cljc +++ b/src/spade/util.cljc @@ -49,3 +49,18 @@ ; easiest case: no key is necessary :else base)) + +(defn unpack-keyframes-nesting + "In the latest versions of garden, using [:&] to return multiple + style rules from within a conditional or other structure like + `(let)` in an `(at-keyframes)` structure keeps that `&` in the + output CSS. This function 'unpacks' such structures so the compiled CSS is clean." + [style-rules] + (mapcat + (fn maybe-unpack-keyframes-nesting [style-rule] + (if (and (vector? style-rule) + (= :& (first style-rule))) + (next style-rule) + [style-rule])) + style-rules)) +