Skip to content

Commit

Permalink
enhance color management
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc committed Feb 8, 2024
1 parent b195632 commit c391fd5
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/renderer/color/core.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(ns renderer.color.core
(:require
[renderer.color.subs]))
7 changes: 7 additions & 0 deletions src/renderer/color/db.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(ns renderer.color.db)

(def default-palette
[["white" "maroon" "red" "purple" "magenta" "green" "lime"
"olive" "yellow" "navy" "blue" "teal" "cyan" "transparent"]
["black" "#111111" "#222222" "#333333" "#444444" "#555555" "#666666"
"#777777" "#888888" "#999999" "#aaaaaa" "#cccccc" "#dddddd" "#eeeeee"]])
34 changes: 34 additions & 0 deletions src/renderer/color/subs.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(ns renderer.color.subs
(:require
[clojure.set :as set]
[re-frame.core :as rf]
[renderer.color.db :as color.db]))

(rf/reg-sub
:color/fills
:<- [:element/visible]
(fn [visible-elements _]
(reduce (fn [colors element]
(let [color (-> element :attrs :fill)]
(conj colors color)))
#{}
visible-elements)))

(rf/reg-sub
:color/selected-fills
:<- [:element/selected]
(fn [selected-elements _]
(reduce (fn [colors element]
(let [color (-> element :attrs :fill)]
(conj colors color)))
#{}
selected-elements)))


(rf/reg-sub
:color/custom-fills
:<- [:color/fills]
(fn [fills _]
(let [palette-colors (set (flatten color.db/default-palette))
colors (set/difference fills palette-colors)]
(take 5 colors))))
9 changes: 2 additions & 7 deletions src/renderer/color/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
["@re-path/react-color" :refer [PhotoshopPicker]]
[i18n :refer [t]]
[re-frame.core :as rf]
[renderer.color.db :as color.db]
[renderer.components :as comp]))

(defn drip [color]
Expand All @@ -19,14 +20,8 @@
(defn swatch [colors]
[:div.flex (map drip colors)])

(def color-palette
[["white" "maroon" "red" "purple" "magenta" "green" "lime"
"olive" "yellow" "navy" "blue" "teal" "cyan" "transparent"]
["black" "#111111" "#222222" "#333333" "#444444" "#555555" "#666666"
"#777777" "#888888" "#999999" "#aaaaaa" "#cccccc" "#dddddd" "#eeeeee"]])

(defn palette []
(into [:div.flex.flex-col.palette] (map swatch color-palette)))
(into [:div.flex.flex-col.palette] (map swatch color.db/default-palette)))

(defn get-hex
[color-object]
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/document/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
{:hovered-keys #{}
:ignored-keys #{}
:active-page :default-page
:fill "#ffffff"
:stroke "#000000"
:fill "white"
:stroke "black"
:zoom 1
:rotate 0
:filter "No a11y filter"
Expand All @@ -39,5 +39,5 @@
:parent :canvas
:attrs {:width 800
:height 600
:fill "#ffffff"}
:fill "white"}
:children []}}})
10 changes: 0 additions & 10 deletions src/renderer/element/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,6 @@
(fn [[elements hovered-keys selected-keys] _]
(vals (select-keys elements (set/union hovered-keys selected-keys)))))

(rf/reg-sub
:element/colors
:<- [:element/visible]
(fn [visible-elements _]
(reduce (fn [colors element]
(let [color (get-in element [:attrs :fill])]
(conj colors color)))
#{}
visible-elements)))

(rf/reg-sub
:snapping-points
:<- [:document/elements]
Expand Down

0 comments on commit c391fd5

Please sign in to comment.