2022-10-14 04:19:11 -05:00
|
|
|
# Developer guide
|
|
|
|
|
2024-04-08 04:43:30 -05:00
|
|
|
The plugin relies in
|
|
|
|
[penpot.js](https://github.com/penpot/penpot-exporter-figma-plugin/blob/main/src/penpot.js) library.
|
|
|
|
It contains a subset of Penpot frontend app, transpiled into javascript to be used from js code
|
|
|
|
(this was easy since the frontend is written in ClojureScript, that has direct translation to
|
|
|
|
javascript).
|
2022-10-14 04:19:11 -05:00
|
|
|
|
2024-04-08 04:43:30 -05:00
|
|
|
Basically, it exports the `createFile` function and the `File` data type, that represents a Penpot
|
|
|
|
file as it resides in memory inside the frontend app. It has function to create pages and their
|
|
|
|
content, and also an `export` function that generates and downloads a .zip archive with the Penpot
|
|
|
|
file as svg documents in Penpot annotated format, that you can import directly into Penpot.
|
2022-10-14 04:19:11 -05:00
|
|
|
|
2024-04-08 04:43:30 -05:00
|
|
|
You can see the
|
|
|
|
[source of the library at Penpot repo](https://github.com/penpot/penpot/tree/develop/frontend/src/app/libs).
|
2022-10-14 04:19:11 -05:00
|
|
|
|
2024-04-08 04:43:30 -05:00
|
|
|
To see a general description of the data types used in the functions you can see
|
|
|
|
[the data model](https://help.penpot.app/technical-guide/data-model/). Their full specifications are
|
|
|
|
in the
|
|
|
|
[common types module](https://github.com/penpot/penpot/tree/develop/common/src/app/common/types).
|
2022-10-14 04:19:11 -05:00
|
|
|
|
2024-04-08 04:43:30 -05:00
|
|
|
Those types are defined in [Clojure spec](https://clojure.org/guides/spec) format. For those
|
|
|
|
unfamiliar with the syntax, here is a small basic guide:
|
2022-10-14 04:19:11 -05:00
|
|
|
|
|
|
|
```clojure
|
|
|
|
(s/def ::name string?)
|
|
|
|
(s/def ::id uuid?)
|
|
|
|
```
|
|
|
|
|
2024-04-08 04:43:30 -05:00
|
|
|
A parameter or attribute called `name` is of type string, and `id` is an _uuid_ string (e.g.
|
|
|
|
"000498f3-27fc-8000-8988-ca7d52f46843").
|
2022-10-14 04:19:11 -05:00
|
|
|
|
|
|
|
```clojure
|
|
|
|
(s/def ::stroke-alignment #{:center :inner :outer})
|
|
|
|
```
|
|
|
|
|
2024-04-08 04:43:30 -05:00
|
|
|
`stroke-alignment` is of an enumerated type, and the valid values are "center", "inner" and "outer".
|
2022-10-14 04:19:11 -05:00
|
|
|
|
|
|
|
```clojure
|
|
|
|
(ns app.common.types.shape
|
|
|
|
(:require
|
|
|
|
[app.common.spec :as us]
|
|
|
|
...))
|
|
|
|
|
|
|
|
(s/def ::line-height ::us/safe-number)
|
|
|
|
```
|
|
|
|
|
2024-04-08 04:43:30 -05:00
|
|
|
`line-height` is of the type `safe-number`, defined in `app.common.spec` namespace, that here is
|
|
|
|
imported with the name `us` (a _safe number_ is a integer or floating point number, with a value not
|
|
|
|
too big or small).
|
2022-10-14 04:19:11 -05:00
|
|
|
|
|
|
|
```clojure
|
|
|
|
(s/def ::page
|
|
|
|
(s/keys :req-un [::id ::name ::objects ::options]))
|
|
|
|
```
|
|
|
|
|
2024-04-08 04:43:30 -05:00
|
|
|
`page` is an object with four required arguments: `id`, `name`, `objects` and `options`, whose types
|
|
|
|
have to be defined above.
|
2022-10-14 04:19:11 -05:00
|
|
|
|
|
|
|
```clojure
|
|
|
|
(s/def ::column
|
|
|
|
(s/keys :req-un [::color]
|
|
|
|
:opt-un [::size
|
|
|
|
::type
|
|
|
|
::item-length
|
|
|
|
::margin
|
|
|
|
::gutter]))
|
|
|
|
```
|
|
|
|
|
2024-04-08 04:43:30 -05:00
|
|
|
`column` has one required attribute `color` and five optional ones `size`, `type`, `item-length`,
|
|
|
|
`margin` and `gutter`.
|
2022-10-14 04:19:11 -05:00
|
|
|
|
|
|
|
```clojure
|
|
|
|
(s/def ::children
|
|
|
|
(s/coll-of ::content
|
|
|
|
:kind vector?
|
|
|
|
:min-count 1))
|
|
|
|
```
|
|
|
|
|
2024-04-08 04:43:30 -05:00
|
|
|
`children` is a collection (implemented as a vector) of objects of type `content`, and must have a
|
|
|
|
minimun lenght of 1.
|
2022-10-14 04:19:11 -05:00
|
|
|
|
|
|
|
```clojure
|
|
|
|
(defmulti animation-spec :animation-type)
|
|
|
|
|
|
|
|
(defmethod animation-spec :dissolve [_]
|
|
|
|
(s/keys :req-un [::duration
|
|
|
|
::easing]))
|
|
|
|
|
|
|
|
(defmethod animation-spec :slide [_]
|
|
|
|
(s/keys :req-un [::duration
|
|
|
|
::easing
|
|
|
|
::way
|
|
|
|
::direction
|
|
|
|
::offset-effect]))
|
|
|
|
|
|
|
|
(defmethod animation-spec :push [_]
|
|
|
|
(s/keys :req-un [::duration
|
|
|
|
::easing
|
|
|
|
::direction]))
|
|
|
|
|
|
|
|
(s/def ::animation
|
|
|
|
(s/multi-spec animation-spec ::animation-type))
|
|
|
|
```
|
|
|
|
|
2024-04-08 04:43:30 -05:00
|
|
|
This is probably the most complex construct. `animation` is a multi schema object. It has an
|
|
|
|
attribute called `animation-type` and the rest of the fields depend on its value. For example, if
|
|
|
|
`animation-type` is "dissolve", the object must also have a `duration` and an `easing` attribute.
|
2022-10-14 04:19:11 -05:00
|
|
|
|
2024-04-08 04:43:30 -05:00
|
|
|
Other constructs should be more or less auto explicative with this guide and the clojure.spec manual
|
|
|
|
linked above.
|