mirror of
https://github.com/penpot/penpot.git
synced 2025-08-01 03:28:22 +02:00
🎉 Add .penpot (binfile-v3) support for library
This commit is contained in:
parent
1fea1e8f5b
commit
29d23577d2
20 changed files with 926 additions and 751 deletions
|
@ -27,7 +27,8 @@
|
|||
(t/is (some? data))))
|
||||
|
||||
(t/testing "Add empty page (only root-frame)"
|
||||
(let [page (-> (fb/create-file {:name "Test"})
|
||||
(let [page (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/get-current-page))
|
||||
|
||||
|
@ -36,18 +37,19 @@
|
|||
(t/is (some? data))))
|
||||
|
||||
(t/testing "Create simple shape on root"
|
||||
(let [file (-> (fb/create-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-shape
|
||||
{:type :rect
|
||||
:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100}))
|
||||
page (fb/get-current-page file)
|
||||
(let [state (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-shape
|
||||
{:type :rect
|
||||
:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100}))
|
||||
page (fb/get-current-page state)
|
||||
|
||||
data (-> (sd/make-snap-data)
|
||||
(sd/add-page page))
|
||||
data (-> (sd/make-snap-data)
|
||||
(sd/add-page page))
|
||||
|
||||
result-x (sd/query data (:id page) uuid/zero :x [0 100])]
|
||||
|
||||
|
@ -66,17 +68,18 @@
|
|||
(t/is (= (first (nth result-x 2)) 100))))
|
||||
|
||||
(t/testing "Add page with single empty frame"
|
||||
(let [file (-> (fb/create-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-artboard
|
||||
{:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100})
|
||||
(fb/close-artboard))
|
||||
(let [state (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-board
|
||||
{:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100})
|
||||
(fb/close-board))
|
||||
|
||||
frame-id (::fb/last-id file)
|
||||
page (fb/get-current-page file)
|
||||
frame-id (::fb/last-id state)
|
||||
page (fb/get-current-page state)
|
||||
|
||||
;; frame-id (::fb/last-id file)
|
||||
data (-> (sd/make-snap-data)
|
||||
|
@ -91,26 +94,27 @@
|
|||
|
||||
(t/testing "Add page with some shapes inside frames"
|
||||
(with-redefs [uuid/next (get-mocked-uuid)]
|
||||
(let [file (-> (fb/create-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-artboard
|
||||
{:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100}))
|
||||
(let [state (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-board
|
||||
{:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100}))
|
||||
|
||||
frame-id (::fb/last-id file)
|
||||
frame-id (::fb/last-id state)
|
||||
|
||||
file (-> file
|
||||
(fb/add-shape
|
||||
{:type :rect
|
||||
:x 25
|
||||
:y 25
|
||||
:width 50
|
||||
:height 50})
|
||||
(fb/close-artboard))
|
||||
state (-> state
|
||||
(fb/add-shape
|
||||
{:type :rect
|
||||
:x 25
|
||||
:y 25
|
||||
:width 50
|
||||
:height 50})
|
||||
(fb/close-board))
|
||||
|
||||
page (fb/get-current-page file)
|
||||
page (fb/get-current-page state)
|
||||
|
||||
data (-> (sd/make-snap-data)
|
||||
(sd/add-page page))
|
||||
|
@ -123,21 +127,21 @@
|
|||
(t/is (= (count result-frame-x) 5)))))
|
||||
|
||||
(t/testing "Add a global guide"
|
||||
(let [file (-> (fb/create-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-guide {:position 50 :axis :x})
|
||||
(fb/add-artboard {:x 200 :y 200 :width 100 :height 100})
|
||||
(fb/close-artboard))
|
||||
(let [state (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-guide {:position 50 :axis :x})
|
||||
(fb/add-board {:x 200 :y 200 :width 100 :height 100})
|
||||
(fb/close-board))
|
||||
|
||||
frame-id (::fb/last-id file)
|
||||
page (fb/get-current-page file)
|
||||
frame-id (::fb/last-id state)
|
||||
page (fb/get-current-page state)
|
||||
|
||||
;; frame-id (::fb/last-id file)
|
||||
data (-> (sd/make-snap-data)
|
||||
(sd/add-page page))
|
||||
data (-> (sd/make-snap-data)
|
||||
(sd/add-page page))
|
||||
|
||||
result-zero-x (sd/query data (:id page) uuid/zero :x [0 100])
|
||||
result-zero-y (sd/query data (:id page) uuid/zero :y [0 100])
|
||||
result-zero-x (sd/query data (:id page) uuid/zero :x [0 100])
|
||||
result-zero-y (sd/query data (:id page) uuid/zero :y [0 100])
|
||||
result-frame-x (sd/query data (:id page) frame-id :x [0 100])
|
||||
result-frame-y (sd/query data (:id page) frame-id :y [0 100])]
|
||||
|
||||
|
@ -151,17 +155,18 @@
|
|||
(t/is (= (count result-frame-y) 0))))
|
||||
|
||||
(t/testing "Add a frame guide"
|
||||
(let [file (-> (fb/create-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-artboard {:x 200 :y 200 :width 100 :height 100})
|
||||
(fb/close-artboard))
|
||||
(let [state (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-board {:x 200 :y 200 :width 100 :height 100})
|
||||
(fb/close-board))
|
||||
|
||||
frame-id (::fb/last-id file)
|
||||
frame-id (::fb/last-id state)
|
||||
|
||||
file (-> file
|
||||
(fb/add-guide {:position 50 :axis :x :frame-id frame-id}))
|
||||
state (-> state
|
||||
(fb/add-guide {:position 50 :axis :x :frame-id frame-id}))
|
||||
|
||||
page (fb/get-current-page file)
|
||||
page (fb/get-current-page state)
|
||||
|
||||
data (-> (sd/make-snap-data)
|
||||
(sd/add-page page))
|
||||
|
@ -182,26 +187,26 @@
|
|||
|
||||
(t/deftest test-update-index
|
||||
(t/testing "Create frame on root and then remove it."
|
||||
(let [file (-> (fb/create-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-artboard
|
||||
{:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100})
|
||||
(fb/close-artboard))
|
||||
(let [state (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-board
|
||||
{:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100})
|
||||
(fb/close-board))
|
||||
|
||||
shape-id (::fb/last-id file)
|
||||
page (fb/get-current-page file)
|
||||
shape-id (::fb/last-id state)
|
||||
page (fb/get-current-page state)
|
||||
|
||||
;; frame-id (::fb/last-id file)
|
||||
data (-> (sd/make-snap-data)
|
||||
(sd/add-page page))
|
||||
|
||||
file (-> file
|
||||
(fb/delete-shape shape-id))
|
||||
state (-> state
|
||||
(fb/delete-shape shape-id))
|
||||
|
||||
new-page (fb/get-current-page file)
|
||||
new-page (fb/get-current-page state)
|
||||
data (sd/update-page data page new-page)
|
||||
|
||||
result-x (sd/query data (:id page) uuid/zero :x [0 100])
|
||||
|
@ -212,25 +217,26 @@
|
|||
(t/is (= (count result-y) 0))))
|
||||
|
||||
(t/testing "Create simple shape on root. Then remove it"
|
||||
(let [file (-> (fb/create-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-shape
|
||||
{:type :rect
|
||||
:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100}))
|
||||
(let [state (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-shape
|
||||
{:type :rect
|
||||
:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100}))
|
||||
|
||||
shape-id (::fb/last-id file)
|
||||
page (fb/get-current-page file)
|
||||
shape-id (::fb/last-id state)
|
||||
page (fb/get-current-page state)
|
||||
|
||||
;; frame-id (::fb/last-id file)
|
||||
;; frame-id (::fb/last-id state)
|
||||
data (-> (sd/make-snap-data)
|
||||
(sd/add-page page))
|
||||
|
||||
file (fb/delete-shape file shape-id)
|
||||
state (fb/delete-shape state shape-id)
|
||||
|
||||
new-page (fb/get-current-page file)
|
||||
new-page (fb/get-current-page state)
|
||||
data (sd/update-page data page new-page)
|
||||
|
||||
result-x (sd/query data (:id page) uuid/zero :x [0 100])
|
||||
|
@ -241,30 +247,31 @@
|
|||
(t/is (= (count result-y) 0))))
|
||||
|
||||
(t/testing "Create shape inside frame, then remove it"
|
||||
(let [file (-> (fb/create-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-artboard
|
||||
{:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100}))
|
||||
frame-id (::fb/last-id file)
|
||||
(let [state (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-board
|
||||
{:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100}))
|
||||
frame-id (::fb/last-id state)
|
||||
|
||||
file (fb/add-shape file {:type :rect :x 25 :y 25 :width 50 :height 50})
|
||||
shape-id (::fb/last-id file)
|
||||
state (fb/add-shape state {:type :rect :x 25 :y 25 :width 50 :height 50})
|
||||
shape-id (::fb/last-id state)
|
||||
|
||||
file (fb/close-artboard file)
|
||||
state (fb/close-board state)
|
||||
|
||||
page (fb/get-current-page file)
|
||||
data (-> (sd/make-snap-data)
|
||||
(sd/add-page page))
|
||||
page (fb/get-current-page state)
|
||||
data (-> (sd/make-snap-data)
|
||||
(sd/add-page page))
|
||||
|
||||
file (fb/delete-shape file shape-id)
|
||||
new-page (fb/get-current-page file)
|
||||
state (fb/delete-shape state shape-id)
|
||||
new-page (fb/get-current-page state)
|
||||
|
||||
data (sd/update-page data page new-page)
|
||||
data (sd/update-page data page new-page)
|
||||
|
||||
result-zero-x (sd/query data (:id page) uuid/zero :x [0 100])
|
||||
result-zero-x (sd/query data (:id page) uuid/zero :x [0 100])
|
||||
result-frame-x (sd/query data (:id page) frame-id :x [0 100])]
|
||||
|
||||
(t/is (some? data))
|
||||
|
@ -272,26 +279,28 @@
|
|||
(t/is (= (count result-frame-x) 3))))
|
||||
|
||||
(t/testing "Create global guide then remove it"
|
||||
(let [file (-> (fb/create-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-guide {:position 50 :axis :x}))
|
||||
(let [state (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-guide {:position 50 :axis :x}))
|
||||
|
||||
guide-id (::fb/last-id file)
|
||||
guide-id (::fb/last-id state)
|
||||
|
||||
file (-> (fb/add-artboard file {:x 200 :y 200 :width 100 :height 100})
|
||||
(fb/close-artboard))
|
||||
state (-> (fb/add-board state {:x 200 :y 200 :width 100 :height 100})
|
||||
(fb/close-board))
|
||||
|
||||
frame-id (::fb/last-id file)
|
||||
page (fb/get-current-page file)
|
||||
data (-> (sd/make-snap-data) (sd/add-page page))
|
||||
frame-id (::fb/last-id state)
|
||||
page (fb/get-current-page state)
|
||||
data (-> (sd/make-snap-data)
|
||||
(sd/add-page page))
|
||||
|
||||
new-page (-> (fb/delete-guide file guide-id)
|
||||
new-page (-> (fb/delete-guide state guide-id)
|
||||
(fb/get-current-page))
|
||||
|
||||
data (sd/update-page data page new-page)
|
||||
data (sd/update-page data page new-page)
|
||||
|
||||
result-zero-x (sd/query data (:id page) uuid/zero :x [0 100])
|
||||
result-zero-y (sd/query data (:id page) uuid/zero :y [0 100])
|
||||
result-zero-x (sd/query data (:id page) uuid/zero :x [0 100])
|
||||
result-zero-y (sd/query data (:id page) uuid/zero :y [0 100])
|
||||
result-frame-x (sd/query data (:id page) frame-id :x [0 100])
|
||||
result-frame-y (sd/query data (:id page) frame-id :y [0 100])]
|
||||
|
||||
|
@ -305,10 +314,11 @@
|
|||
(t/is (= (count result-frame-y) 0))))
|
||||
|
||||
(t/testing "Create frame guide then remove it"
|
||||
(let [file (-> (fb/create-file {:name "Test"})
|
||||
(let [file (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-artboard {:x 200 :y 200 :width 100 :height 100})
|
||||
(fb/close-artboard))
|
||||
(fb/add-board {:x 200 :y 200 :width 100 :height 100})
|
||||
(fb/close-board))
|
||||
|
||||
frame-id (::fb/last-id file)
|
||||
file (fb/add-guide file {:position 50 :axis :x :frame-id frame-id})
|
||||
|
@ -336,30 +346,31 @@
|
|||
(t/is (= (count result-frame-y) 0))))
|
||||
|
||||
(t/testing "Update frame coordinates"
|
||||
(let [file (-> (fb/create-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-artboard
|
||||
{:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100})
|
||||
(fb/close-artboard))
|
||||
(let [state (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-board
|
||||
{:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100})
|
||||
(fb/close-board))
|
||||
|
||||
frame-id (::fb/last-id file)
|
||||
page (fb/get-current-page file)
|
||||
data (-> (sd/make-snap-data) (sd/add-page page))
|
||||
frame-id (::fb/last-id state)
|
||||
page (fb/get-current-page state)
|
||||
data (-> (sd/make-snap-data)
|
||||
(sd/add-page page))
|
||||
|
||||
file (fb/update-shape file frame-id
|
||||
(fn [shape]
|
||||
(-> shape
|
||||
(dissoc :selrect :points)
|
||||
(assoc :x 200 :y 200)
|
||||
(cts/setup-shape))))
|
||||
state (fb/update-shape state frame-id
|
||||
(fn [shape]
|
||||
(-> shape
|
||||
(dissoc :selrect :points)
|
||||
(assoc :x 200 :y 200)
|
||||
(cts/setup-shape))))
|
||||
|
||||
|
||||
new-page (fb/get-current-page file)
|
||||
|
||||
data (sd/update-page data page new-page)
|
||||
new-page (fb/get-current-page state)
|
||||
data (sd/update-page data page new-page)
|
||||
|
||||
result-zero-x-1 (sd/query data (:id page) uuid/zero :x [0 100])
|
||||
result-frame-x-1 (sd/query data (:id page) frame-id :x [0 100])
|
||||
|
@ -373,28 +384,29 @@
|
|||
(t/is (= (count result-frame-x-2) 3))))
|
||||
|
||||
(t/testing "Update shape coordinates"
|
||||
(let [file (-> (fb/create-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-shape
|
||||
{:type :rect
|
||||
:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100}))
|
||||
(let [state (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-shape
|
||||
{:type :rect
|
||||
:x 0
|
||||
:y 0
|
||||
:width 100
|
||||
:height 100}))
|
||||
|
||||
shape-id (::fb/last-id file)
|
||||
page (fb/get-current-page file)
|
||||
shape-id (::fb/last-id state)
|
||||
page (fb/get-current-page state)
|
||||
data (-> (sd/make-snap-data)
|
||||
(sd/add-page page))
|
||||
|
||||
file (fb/update-shape file shape-id
|
||||
(fn [shape]
|
||||
(-> shape
|
||||
(dissoc :selrect :points)
|
||||
(assoc :x 200 :y 200)
|
||||
(cts/setup-shape))))
|
||||
state (fb/update-shape state shape-id
|
||||
(fn [shape]
|
||||
(-> shape
|
||||
(dissoc :selrect :points)
|
||||
(assoc :x 200 :y 200)
|
||||
(cts/setup-shape))))
|
||||
|
||||
new-page (fb/get-current-page file)
|
||||
new-page (fb/get-current-page state)
|
||||
;; FIXME: update
|
||||
data (sd/update-page data page new-page)
|
||||
|
||||
|
@ -406,25 +418,26 @@
|
|||
(t/is (= (count result-zero-x-2) 3))))
|
||||
|
||||
(t/testing "Update global guide"
|
||||
(let [guide {:position 50 :axis :x}
|
||||
file (-> (fb/create-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-guide guide))
|
||||
(let [guide {:position 50 :axis :x}
|
||||
state (-> (fb/create-state)
|
||||
(fb/add-file {:name "Test"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-guide guide))
|
||||
|
||||
guide-id (::fb/last-id file)
|
||||
guide (assoc guide :id guide-id)
|
||||
guide-id (::fb/last-id state)
|
||||
guide (assoc guide :id guide-id)
|
||||
|
||||
file (-> (fb/add-artboard file {:x 500 :y 500 :width 100 :height 100})
|
||||
(fb/close-artboard))
|
||||
state (-> (fb/add-board state {:x 500 :y 500 :width 100 :height 100})
|
||||
(fb/close-board))
|
||||
|
||||
frame-id (::fb/last-id file)
|
||||
page (fb/get-current-page file)
|
||||
frame-id (::fb/last-id state)
|
||||
page (fb/get-current-page state)
|
||||
data (-> (sd/make-snap-data) (sd/add-page page))
|
||||
|
||||
new-page (-> (fb/update-guide file (assoc guide :position 150))
|
||||
new-page (-> (fb/update-guide state (assoc guide :position 150))
|
||||
(fb/get-current-page))
|
||||
|
||||
data (sd/update-page data page new-page)
|
||||
data (sd/update-page data page new-page)
|
||||
|
||||
result-zero-x-1 (sd/query data (:id page) uuid/zero :x [0 100])
|
||||
result-zero-y-1 (sd/query data (:id page) uuid/zero :y [0 100])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue