mirror of
https://github.com/penpot/penpot.git
synced 2025-03-11 07:11:32 -05:00
Allow passing of tokens
This commit is contained in:
parent
b1b6b5292c
commit
0921f8043b
1 changed files with 19 additions and 16 deletions
|
@ -41,7 +41,7 @@
|
||||||
(js/console.log "Input Data" js-data))
|
(js/console.log "Input Data" js-data))
|
||||||
(StyleDictionary. js-data)))
|
(StyleDictionary. js-data)))
|
||||||
|
|
||||||
(defn resolve-tokens+
|
(defn resolve-sd-tokens+
|
||||||
"Resolves references and math expressions using StyleDictionary.
|
"Resolves references and math expressions using StyleDictionary.
|
||||||
Returns a promise with the resolved dictionary."
|
Returns a promise with the resolved dictionary."
|
||||||
[tokens & {:keys [debug?] :as config}]
|
[tokens & {:keys [debug?] :as config}]
|
||||||
|
@ -61,22 +61,25 @@
|
||||||
(js/console.log "Resolved tokens" resolved-tokens))
|
(js/console.log "Resolved tokens" resolved-tokens))
|
||||||
resolved-tokens))))))
|
resolved-tokens))))))
|
||||||
|
|
||||||
|
(defn resolve-tokens+
|
||||||
|
[tokens & {:keys [debug?] :as config}]
|
||||||
|
(p/let [sd-tokens (-> (tokens->tree tokens)
|
||||||
|
(clj->js)
|
||||||
|
(resolve-sd-tokens+ config))]
|
||||||
|
(let [resolved-tokens (reduce
|
||||||
|
(fn [acc cur]
|
||||||
|
(let [resolved-value (.-value cur)
|
||||||
|
id (uuid (.-id cur))]
|
||||||
|
(assoc-in acc [id :value] resolved-value)))
|
||||||
|
tokens sd-tokens)]
|
||||||
|
(when debug?
|
||||||
|
(js/console.log "Resolved tokens" resolved-tokens))
|
||||||
|
resolved-tokens)))
|
||||||
|
|
||||||
(defn resolve-workspace-tokens+
|
(defn resolve-workspace-tokens+
|
||||||
[& {:keys [debug?] :as config}]
|
[& {:keys [debug?] :as config}]
|
||||||
(when-let [workspace-tokens @refs/workspace-tokens]
|
(when-let [workspace-tokens @refs/workspace-tokens]
|
||||||
(p/let [sd-tokens (-> workspace-tokens
|
(resolve-tokens+ workspace-tokens)))
|
||||||
(tokens->tree)
|
|
||||||
(clj->js)
|
|
||||||
(resolve-tokens+ config))]
|
|
||||||
(let [resolved-tokens (reduce
|
|
||||||
(fn [acc cur]
|
|
||||||
(let [resolved-value (.-value cur)
|
|
||||||
id (uuid (.-id cur))]
|
|
||||||
(assoc-in acc [id :value] resolved-value)))
|
|
||||||
workspace-tokens sd-tokens)]
|
|
||||||
(when debug?
|
|
||||||
(js/console.log "Resolved tokens" resolved-tokens))
|
|
||||||
resolved-tokens))))
|
|
||||||
|
|
||||||
;; Testing ---------------------------------------------------------------------
|
;; Testing ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -98,9 +101,9 @@
|
||||||
(tokens->tree)
|
(tokens->tree)
|
||||||
(clj->js)
|
(clj->js)
|
||||||
(#(doto % js/console.log))
|
(#(doto % js/console.log))
|
||||||
(resolve-tokens+ {:debug? true}))
|
(resolve-sd-tokens+ {:debug? true}))
|
||||||
|
|
||||||
(-> (tokens-studio-example)
|
(-> (tokens-studio-example)
|
||||||
(resolve-tokens+ {:debug? true}))
|
(resolve-sd-tokens+ {:debug? true}))
|
||||||
|
|
||||||
nil)
|
nil)
|
||||||
|
|
Loading…
Add table
Reference in a new issue