mirror of
https://github.com/penpot/penpot.git
synced 2025-06-07 06:11:38 +02:00
🐛 Fix object exportation.
This commit is contained in:
parent
605143ef7e
commit
038e820815
1 changed files with 37 additions and 11 deletions
|
@ -36,6 +36,26 @@
|
||||||
[data]
|
[data]
|
||||||
(xml/js2xml (clj->js data)))
|
(xml/js2xml (clj->js data)))
|
||||||
|
|
||||||
|
(defn ^boolean element?
|
||||||
|
[item]
|
||||||
|
(and (map? item)
|
||||||
|
(= "element" (get item "type"))))
|
||||||
|
|
||||||
|
(defn ^boolean group-element?
|
||||||
|
[item]
|
||||||
|
(and (element? item)
|
||||||
|
(= "g" (get item "name"))))
|
||||||
|
|
||||||
|
(defn ^boolean shape-element?
|
||||||
|
[item]
|
||||||
|
(and (element? item)
|
||||||
|
(str/starts-with? (get-in item ["attributes" "id"]) "shape-")))
|
||||||
|
|
||||||
|
(defn ^boolean foreign-object-element?
|
||||||
|
[item]
|
||||||
|
(and (element? item)
|
||||||
|
(= "foreignObject" (get item "name"))))
|
||||||
|
|
||||||
(defn ^boolean empty-defs-element?
|
(defn ^boolean empty-defs-element?
|
||||||
[item]
|
[item]
|
||||||
(and (= (get item "name") "defs")
|
(and (= (get item "name") "defs")
|
||||||
|
@ -50,10 +70,6 @@
|
||||||
(nil? d)
|
(nil? d)
|
||||||
(str/empty? d)))))
|
(str/empty? d)))))
|
||||||
|
|
||||||
(defn ^boolean foreign-object-element?
|
|
||||||
[item]
|
|
||||||
(and (map? item)
|
|
||||||
(= "foreignObject" (get item "name"))))
|
|
||||||
|
|
||||||
(defn flatten-toplevel-svg-elements
|
(defn flatten-toplevel-svg-elements
|
||||||
"Flattens XML data structure if two nested top-side SVG elements found."
|
"Flattens XML data structure if two nested top-side SVG elements found."
|
||||||
|
@ -78,8 +94,14 @@
|
||||||
|
|
||||||
(process-element [item xform]
|
(process-element [item xform]
|
||||||
(let [item (d/update-when item "elements" #(into [] xform %))]
|
(let [item (d/update-when item "elements" #(into [] xform %))]
|
||||||
(if (str/starts-with? (get-in item ["attributes" "id"]) "shape-")
|
(if (shape-element? item)
|
||||||
(assoc item "elements" (get-in item ["elements" 0 "elements"]))
|
(update item "elements"
|
||||||
|
(fn [elements]
|
||||||
|
;; flatten content of a shape element
|
||||||
|
(into [] (mapcat (fn [item]
|
||||||
|
(if (group-element? item)
|
||||||
|
(get item "elements")
|
||||||
|
[item]))) elements)))
|
||||||
item)))]
|
item)))]
|
||||||
|
|
||||||
(let [xform (comp (remove empty-defs-element?)
|
(let [xform (comp (remove empty-defs-element?)
|
||||||
|
@ -90,9 +112,7 @@
|
||||||
(flatten-toplevel-svg-elements)
|
(flatten-toplevel-svg-elements)
|
||||||
(walk/prewalk (fn [item]
|
(walk/prewalk (fn [item]
|
||||||
(cond-> item
|
(cond-> item
|
||||||
(and (map? item)
|
(element? item)
|
||||||
(string? (get item "name"))
|
|
||||||
(= "element" (get item "type")))
|
|
||||||
(process-element xform))))
|
(process-element xform))))
|
||||||
(clj->xml)))))
|
(clj->xml)))))
|
||||||
|
|
||||||
|
@ -234,8 +254,14 @@
|
||||||
(p/let [dom (bwr/select page "#screenshot")
|
(p/let [dom (bwr/select page "#screenshot")
|
||||||
xmldata (bwr/eval! dom (fn [elem] (.-outerHTML ^js elem)))
|
xmldata (bwr/eval! dom (fn [elem] (.-outerHTML ^js elem)))
|
||||||
nodes (process-text-nodes page)
|
nodes (process-text-nodes page)
|
||||||
nodes (d/index-by :id nodes)]
|
nodes (d/index-by :id nodes)
|
||||||
(replace-text-nodes xmldata nodes)))
|
result (replace-text-nodes xmldata nodes)]
|
||||||
|
;; (println "------- ORIGIN:")
|
||||||
|
;; (cljs.pprint/pprint (xml->clj xmldata))
|
||||||
|
;; (println "------- RESULT:")
|
||||||
|
;; (cljs.pprint/pprint (xml->clj result))
|
||||||
|
;; (println "-------")
|
||||||
|
result))
|
||||||
|
|
||||||
(render-in-page [page {:keys [uri cookie] :as rctx}]
|
(render-in-page [page {:keys [uri cookie] :as rctx}]
|
||||||
(p/do!
|
(p/do!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue