0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 07:29:08 -05:00

Merge pull request #5054 from penpot/alotor-plugins-fixes

Update API types
This commit is contained in:
Andrey Antukh 2024-09-04 14:16:01 +02:00 committed by GitHub
commit cf0045681e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 2195 additions and 2076 deletions

File diff suppressed because it is too large Load diff

View file

@ -110,7 +110,7 @@
(def privacy-policy-uri (obj/get global "penpotPrivacyPolicyURI" "https://penpot.app/privacy")) (def privacy-policy-uri (obj/get global "penpotPrivacyPolicyURI" "https://penpot.app/privacy"))
(def flex-help-uri (obj/get global "penpotGridHelpURI" "https://help.penpot.app/user-guide/flexible-layouts/")) (def flex-help-uri (obj/get global "penpotGridHelpURI" "https://help.penpot.app/user-guide/flexible-layouts/"))
(def grid-help-uri (obj/get global "penpotGridHelpURI" "https://help.penpot.app/user-guide/flexible-layouts/")) (def grid-help-uri (obj/get global "penpotGridHelpURI" "https://help.penpot.app/user-guide/flexible-layouts/"))
(def plugins-list-uri (obj/get global "penpotPluginsListUri" "https://penpot-docs-plugins.pages.dev/technical-guide/plugins/getting-started/#examples")) (def plugins-list-uri (obj/get global "penpotPluginsListUri" "https://penpot-docs-plugins.pages.dev/plugins/getting-started/#examples"))
(defn- normalize-uri (defn- normalize-uri
[uri-str] [uri-str]

View file

@ -227,7 +227,7 @@
ids (into #{} (map #(obj/get % "$id")) shapes)] ids (into #{} (map #(obj/get % "$id")) shapes)]
(st/emit! (dwg/ungroup-shapes ids))))) (st/emit! (dwg/ungroup-shapes ids)))))
(createFrame (createBoard
[_] [_]
(create-shape $plugin :frame)) (create-shape $plugin :frame))

View file

@ -31,14 +31,22 @@
"mixed" "mixed"
value)) value))
;; export type PenpotPoint = { x: number; y: number }; ;; export type Point = { x: number; y: number };
(defn format-point (defn format-point
[{:keys [x y] :as point}] [{:keys [x y] :as point}]
(when (some? point) (when (some? point)
(obj/without-empty (obj/without-empty
#js {:x x :y y}))) #js {:x x :y y})))
;;export type PenpotBounds = { (defn shape-type
[type]
(case type
:frame "board"
:rect "rectangle"
:circle "ellipse"
(d/name type)))
;;export type Bounds = {
;; x: number; ;; x: number;
;; y: number; ;; y: number;
;; width: number; ;; width: number;
@ -50,7 +58,7 @@
(obj/without-empty (obj/without-empty
#js {:x x :y y :width width :height height}))) #js {:x x :y y :width width :height height})))
;; export interface PenpotColorShapeInfoEntry { ;; export interface ColorShapeInfoEntry {
;; readonly property: string; ;; readonly property: string;
;; readonly index?: number; ;; readonly index?: number;
;; readonly shapeId: string; ;; readonly shapeId: string;
@ -63,7 +71,7 @@
:index index :index index
:shapeId (dm/str shape-id)}))) :shapeId (dm/str shape-id)})))
;; export type PenpotGradient = { ;; export type Gradient = {
;; type: 'linear' | 'radial'; ;; type: 'linear' | 'radial';
;; startX: number; ;; startX: number;
;; startY: number; ;; startY: number;
@ -89,7 +97,7 @@
:width width :width width
:stops (format-array format-stop stops)}))) :stops (format-array format-stop stops)})))
;; export type PenpotImageData = { ;; export type ImageData = {
;; name?: string; ;; name?: string;
;; width: number; ;; width: number;
;; height: number; ;; height: number;
@ -108,7 +116,7 @@
:id (format-id id) :id (format-id id)
:keepAspectRatio keep-aspect-ratio}))) :keepAspectRatio keep-aspect-ratio})))
;; export interface PenpotColor { ;; export interface Color {
;; id?: string; ;; id?: string;
;; name?: string; ;; name?: string;
;; path?: string; ;; path?: string;
@ -116,8 +124,8 @@
;; opacity?: number; ;; opacity?: number;
;; refId?: string; ;; refId?: string;
;; refFile?: string; ;; refFile?: string;
;; gradient?: PenpotGradient; ;; gradient?: Gradient;
;; image?: PenpotImageData; ;; image?: ImageData;
;; } ;; }
(defn format-color (defn format-color
[{:keys [id name path color opacity ref-id ref-file gradient image] :as color-data}] [{:keys [id name path color opacity ref-id ref-file gradient image] :as color-data}]
@ -133,7 +141,7 @@
:gradient (format-gradient gradient) :gradient (format-gradient gradient)
:image (format-image image)}))) :image (format-image image)})))
;; PenpotColor & PenpotColorShapeInfo ;; Color & ColorShapeInfo
(defn format-color-result (defn format-color-result
[[color attrs]] [[color attrs]]
(let [shapes-info (apply array (map format-shape-info attrs)) (let [shapes-info (apply array (map format-shape-info attrs))
@ -142,7 +150,7 @@
color)) color))
;; export interface PenpotShadow { ;; export interface Shadow {
;; id?: string; ;; id?: string;
;; style?: 'drop-shadow' | 'inner-shadow'; ;; style?: 'drop-shadow' | 'inner-shadow';
;; offsetX?: number; ;; offsetX?: number;
@ -150,7 +158,7 @@
;; blur?: number; ;; blur?: number;
;; spread?: number; ;; spread?: number;
;; hidden?: boolean; ;; hidden?: boolean;
;; color?: PenpotColor; ;; color?: Color;
;; } ;; }
(defn format-shadow (defn format-shadow
[{:keys [id style offset-x offset-y blur spread hidden color] :as shadow}] [{:keys [id style offset-x offset-y blur spread hidden color] :as shadow}]
@ -170,13 +178,13 @@
(when (some? shadows) (when (some? shadows)
(format-array format-shadow shadows))) (format-array format-shadow shadows)))
;;export interface PenpotFill { ;;export interface Fill {
;; fillColor?: string; ;; fillColor?: string;
;; fillOpacity?: number; ;; fillOpacity?: number;
;; fillColorGradient?: PenpotGradient; ;; fillColorGradient?: Gradient;
;; fillColorRefFile?: string; ;; fillColorRefFile?: string;
;; fillColorRefId?: string; ;; fillColorRefId?: string;
;; fillImage?: PenpotImageData; ;; fillImage?: ImageData;
;;} ;;}
(defn format-fill (defn format-fill
[{:keys [fill-color fill-opacity fill-color-gradient fill-color-ref-file fill-color-ref-id fill-image] :as fill}] [{:keys [fill-color fill-opacity fill-color-gradient fill-color-ref-file fill-color-ref-id fill-image] :as fill}]
@ -201,7 +209,7 @@
(some? fills) (some? fills)
(format-array format-fill fills))) (format-array format-fill fills)))
;; export interface PenpotStroke { ;; export interface Stroke {
;; strokeColor?: string; ;; strokeColor?: string;
;; strokeColorRefFile?: string; ;; strokeColorRefFile?: string;
;; strokeColorRefId?: string; ;; strokeColorRefId?: string;
@ -209,9 +217,9 @@
;; strokeStyle?: 'solid' | 'dotted' | 'dashed' | 'mixed' | 'none' | 'svg'; ;; strokeStyle?: 'solid' | 'dotted' | 'dashed' | 'mixed' | 'none' | 'svg';
;; strokeWidth?: number; ;; strokeWidth?: number;
;; strokeAlignment?: 'center' | 'inner' | 'outer'; ;; strokeAlignment?: 'center' | 'inner' | 'outer';
;; strokeCapStart?: PenpotStrokeCap; ;; strokeCapStart?: StrokeCap;
;; strokeCapEnd?: PenpotStrokeCap; ;; strokeCapEnd?: StrokeCap;
;; strokeColorGradient?: PenpotGradient; ;; strokeColorGradient?: Gradient;
;; } ;; }
(defn format-stroke (defn format-stroke
[{:keys [stroke-color stroke-color-ref-file stroke-color-ref-id [{:keys [stroke-color stroke-color-ref-file stroke-color-ref-id
@ -236,7 +244,7 @@
(when (some? strokes) (when (some? strokes)
(format-array format-stroke strokes))) (format-array format-stroke strokes)))
;; export interface PenpotBlur { ;; export interface Blur {
;; id?: string; ;; id?: string;
;; type?: 'layer-blur'; ;; type?: 'layer-blur';
;; value?: number; ;; value?: number;
@ -251,7 +259,7 @@
:value value :value value
:hidden hidden}))) :hidden hidden})))
;; export interface PenpotExport { ;; export interface Export {
;; type: 'png' | 'jpeg' | 'svg' | 'pdf'; ;; type: 'png' | 'jpeg' | 'svg' | 'pdf';
;; scale: number; ;; scale: number;
;; suffix: string; ;; suffix: string;
@ -269,7 +277,7 @@
(when (some? exports) (when (some? exports)
(format-array format-export exports))) (format-array format-export exports)))
;; export interface PenpotFrameGuideColumnParams { ;; export interface GuideColumnParams {
;; color: { color: string; opacity: number }; ;; color: { color: string; opacity: number };
;; type?: 'stretch' | 'left' | 'center' | 'right'; ;; type?: 'stretch' | 'left' | 'center' | 'right';
;; size?: number; ;; size?: number;
@ -288,10 +296,10 @@
:itemLength item-length :itemLength item-length
:gutter gutter}))) :gutter gutter})))
;; export interface PenpotFrameGuideColumn { ;; export interface GuideColumn {
;; type: 'column'; ;; type: 'column';
;; display: boolean; ;; display: boolean;
;; params: PenpotFrameGuideColumnParams; ;; params: GuideColumnParams;
;; } ;; }
(defn format-frame-guide-column (defn format-frame-guide-column
[{:keys [type display params] :as guide}] [{:keys [type display params] :as guide}]
@ -301,10 +309,10 @@
:display display :display display
:params (format-frame-guide-column-params params)}))) :params (format-frame-guide-column-params params)})))
;; export interface PenpotFrameGuideRow { ;; export interface GuideRow {
;; type: 'row'; ;; type: 'row';
;; display: boolean; ;; display: boolean;
;; params: PenpotFrameGuideColumnParams; ;; params: GuideColumnParams;
;; } ;; }
(defn format-frame-guide-row (defn format-frame-guide-row
[{:keys [type display params] :as guide}] [{:keys [type display params] :as guide}]
@ -314,7 +322,7 @@
:display display :display display
:params (format-frame-guide-column-params params)}))) :params (format-frame-guide-column-params params)})))
;;export interface PenpotFrameGuideSquareParams { ;;export interface GuideSquareParams {
;; color: { color: string; opacity: number }; ;; color: { color: string; opacity: number };
;; size?: number; ;; size?: number;
;;} ;;}
@ -325,10 +333,10 @@
#js {:color (format-color color) #js {:color (format-color color)
:size size}))) :size size})))
;; export interface PenpotFrameGuideSquare { ;; export interface GuideSquare {
;; type: 'square'; ;; type: 'square';
;; display: boolean; ;; display: boolean;
;; params: PenpotFrameGuideSquareParams; ;; params: GuideSquareParams;
;; } ;; }
(defn format-frame-guide-square (defn format-frame-guide-square
@ -352,7 +360,7 @@
(when (some? guides) (when (some? guides)
(format-array format-frame-guide guides))) (format-array format-frame-guide guides)))
;;interface PenpotPathCommand { ;;interface PathCommand {
;; command: ;; command:
;; | 'M' | 'move-to' ;; | 'M' | 'move-to'
;; | 'Z' | 'close-path' ;; | 'Z' | 'close-path'
@ -407,10 +415,10 @@
(when (some? content) (when (some? content)
(format-array format-command content))) (format-array format-command content)))
;; export type PenpotTrackType = 'flex' | 'fixed' | 'percent' | 'auto'; ;; export type TrackType = 'flex' | 'fixed' | 'percent' | 'auto';
;; ;;
;; export interface PenpotTrack { ;; export interface Track {
;; type: PenpotTrackType; ;; type: TrackType;
;; value: number | null; ;; value: number | null;
;; } ;; }
(defn format-track (defn format-track
@ -426,13 +434,13 @@
(format-array format-track tracks))) (format-array format-track tracks)))
;; export interface PenpotDissolve { ;; export interface Dissolve {
;; type: 'dissolve'; ;; type: 'dissolve';
;; duration: number; ;; duration: number;
;; easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out'; ;; easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out';
;; } ;; }
;; ;;
;; export interface PenpotSlide { ;; export interface Slide {
;; type: 'slide'; ;; type: 'slide';
;; way: 'in' | 'out'; ;; way: 'in' | 'out';
;; direction?: ;; direction?:
@ -445,7 +453,7 @@
;; easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out'; ;; easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out';
;; } ;; }
;; ;;
;; export interface PenpotPush { ;; export interface Push {
;; type: 'push'; ;; type: 'push';
;; direction?: ;; direction?:
;; | 'right' ;; | 'right'
@ -457,7 +465,7 @@
;; easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out'; ;; easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out';
;; } ;; }
;; ;;
;; export type PenpotAnimation = PenpotDissolve | PenpotSlide | PenpotPush; ;; export type Animation = Dissolve | Slide | Push;
(defn format-animation (defn format-animation
[animation] [animation]
@ -485,24 +493,24 @@
:easing (format-key (:easing animation))} :easing (format-key (:easing animation))}
nil)))) nil))))
;;export type PenpotAction = ;;export type Action =
;; | PenpotNavigateTo ;; | NavigateTo
;; | PenpotOpenOverlay ;; | OpenOverlay
;; | PenpotToggleOverlay ;; | ToggleOverlay
;; | PenpotCloseOverlay ;; | CloseOverlay
;; | PenpotPreviousScreen ;; | PreviousScreen
;; | PenpotOpenUrl; ;; | OpenUrl;
;; ;;
;;export interface PenpotNavigateTo { ;;export interface NavigateTo {
;; type: 'navigate-to'; ;; type: 'navigate-to';
;; destination: PenpotFrame; ;; destination: Board;
;; preserveScrollPosition?: boolean; ;; preserveScrollPosition?: boolean;
;; animation: PenpotAnimation; ;; animation: Animation;
;;} ;;}
;; ;;
;;export interface PenpotOverlayAction { ;;export interface OverlayAction {
;; destination: PenpotFrame; ;; destination: Board;
;; relativeTo?: PenpotShape; ;; relativeTo?: Shape;
;; position?: ;; position?:
;; | 'manual' ;; | 'manual'
;; | 'center' ;; | 'center'
@ -512,31 +520,31 @@
;; | 'bottom-left' ;; | 'bottom-left'
;; | 'bottom-right' ;; | 'bottom-right'
;; | 'bottom-center'; ;; | 'bottom-center';
;; manualPositionLocation?: PenpotPoint; ;; manualPositionLocation?: Point;
;; closeWhenClickOutside?: boolean; ;; closeWhenClickOutside?: boolean;
;; addBackgroundOverlay?: boolean; ;; addBackgroundOverlay?: boolean;
;; animation: PenpotAnimation; ;; animation: Animation;
;;} ;;}
;; ;;
;;export interface PenpotOpenOverlay extends PenpotOverlayAction { ;;export interface OpenOverlay extends OverlayAction {
;; type: 'open-overlay'; ;; type: 'open-overlay';
;;} ;;}
;; ;;
;;export interface PenpotToggleOverlay extends PenpotOverlayAction { ;;export interface ToggleOverlay extends OverlayAction {
;; type: 'toggle-overlay'; ;; type: 'toggle-overlay';
;;} ;;}
;; ;;
;;export interface PenpotCloseOverlay { ;;export interface CloseOverlay {
;; type: 'close-overlay'; ;; type: 'close-overlay';
;; destination?: PenpotFrame; ;; destination?: Board;
;; animation: PenpotAnimation; ;; animation: Animation;
;;} ;;}
;; ;;
;;export interface PenpotPreviousScreen { ;;export interface PreviousScreen {
;; type: 'previous-screen'; ;; type: 'previous-screen';
;;} ;;}
;; ;;
;;export interface PenpotOpenUrl { ;;export interface OpenUrl {
;; type: 'open-url'; ;; type: 'open-url';
;; url: string; ;; url: string;
;;} ;;}

View file

@ -29,17 +29,26 @@
{:x (obj/get point "x") {:x (obj/get point "x")
:y (obj/get point "y")})) :y (obj/get point "y")}))
(defn parse-shape-type
[type]
(case type
"board" :frame
"boolean" :bool
"rectangle" :rect
"ellipse" :circle
(parse-keyword type)))
;; { ;; {
;; name?: string; ;; name?: string;
;; nameLike?: string; ;; nameLike?: string;
;; type?: ;; type?:
;; | 'frame' ;; | 'board'
;; | 'group' ;; | 'group'
;; | 'bool' ;; | 'boolean'
;; | 'rect' ;; | 'rectangle'
;; | 'path' ;; | 'path'
;; | 'text' ;; | 'text'
;; | 'circle' ;; | 'ellipse'
;; | 'svg-raw' ;; | 'svg-raw'
;; | 'image'; ;; | 'image';
;; } ;; }
@ -49,9 +58,9 @@
(d/without-nils (d/without-nils
{:name (obj/get criteria "name") {:name (obj/get criteria "name")
:name-like (obj/get criteria "nameLike") :name-like (obj/get criteria "nameLike")
:type (-> (obj/get criteria "type") parse-keyword)}))) :type (-> (obj/get criteria "type") parse-shape-type)})))
;;export type PenpotImageData = { ;;export type ImageData = {
;; name?: string; ;; name?: string;
;; width: number; ;; width: number;
;; height: number; ;; height: number;
@ -70,7 +79,7 @@
:mtype (obj/get image-data "mtype") :mtype (obj/get image-data "mtype")
:keep-aspect-ratio (obj/get image-data "keepApectRatio")}))) :keep-aspect-ratio (obj/get image-data "keepApectRatio")})))
;; export type PenpotGradient = { ;; export type Gradient = {
;; type: 'linear' | 'radial'; ;; type: 'linear' | 'radial';
;; startX: number; ;; startX: number;
;; startY: number; ;; startY: number;
@ -100,7 +109,7 @@
:stops (->> (obj/get gradient "stops") :stops (->> (obj/get gradient "stops")
(mapv parse-gradient-stop))}))) (mapv parse-gradient-stop))})))
;; export interface PenpotColor { ;; export interface Color {
;; id?: string; ;; id?: string;
;; name?: string; ;; name?: string;
;; path?: string; ;; path?: string;
@ -108,8 +117,8 @@
;; opacity?: number; ;; opacity?: number;
;; refId?: string; ;; refId?: string;
;; refFile?: string; ;; refFile?: string;
;; gradient?: PenpotGradient; ;; gradient?: Gradient;
;; image?: PenpotImageData; ;; image?: ImageData;
;; } ;; }
(defn parse-color (defn parse-color
[^js color] [^js color]
@ -125,7 +134,7 @@
:gradient (-> (obj/get color "gradient") parse-gradient) :gradient (-> (obj/get color "gradient") parse-gradient)
:image (-> (obj/get color "image") parse-image-data)}))) :image (-> (obj/get color "image") parse-image-data)})))
;; export interface PenpotShadow { ;; export interface Shadow {
;; id?: string; ;; id?: string;
;; style?: 'drop-shadow' | 'inner-shadow'; ;; style?: 'drop-shadow' | 'inner-shadow';
;; offsetX?: number; ;; offsetX?: number;
@ -133,7 +142,7 @@
;; blur?: number; ;; blur?: number;
;; spread?: number; ;; spread?: number;
;; hidden?: boolean; ;; hidden?: boolean;
;; color?: PenpotColor; ;; color?: Color;
;; } ;; }
(defn parse-shadow (defn parse-shadow
[^js shadow] [^js shadow]
@ -153,13 +162,13 @@
(when (some? shadows) (when (some? shadows)
(into [] (map parse-shadow) shadows))) (into [] (map parse-shadow) shadows)))
;;export interface PenpotFill { ;;export interface Fill {
;; fillColor?: string; ;; fillColor?: string;
;; fillOpacity?: number; ;; fillOpacity?: number;
;; fillColorGradient?: PenpotGradient; ;; fillColorGradient?: Gradient;
;; fillColorRefFile?: string; ;; fillColorRefFile?: string;
;; fillColorRefId?: string; ;; fillColorRefId?: string;
;; fillImage?: PenpotImageData; ;; fillImage?: ImageData;
;;} ;;}
(defn parse-fill (defn parse-fill
[^js fill] [^js fill]
@ -177,7 +186,7 @@
(when (some? fills) (when (some? fills)
(into [] (map parse-fill) fills))) (into [] (map parse-fill) fills)))
;; export interface PenpotStroke { ;; export interface Stroke {
;; strokeColor?: string; ;; strokeColor?: string;
;; strokeColorRefFile?: string; ;; strokeColorRefFile?: string;
;; strokeColorRefId?: string; ;; strokeColorRefId?: string;
@ -185,9 +194,9 @@
;; strokeStyle?: 'solid' | 'dotted' | 'dashed' | 'mixed' | 'none' | 'svg'; ;; strokeStyle?: 'solid' | 'dotted' | 'dashed' | 'mixed' | 'none' | 'svg';
;; strokeWidth?: number; ;; strokeWidth?: number;
;; strokeAlignment?: 'center' | 'inner' | 'outer'; ;; strokeAlignment?: 'center' | 'inner' | 'outer';
;; strokeCapStart?: PenpotStrokeCap; ;; strokeCapStart?: StrokeCap;
;; strokeCapEnd?: PenpotStrokeCap; ;; strokeCapEnd?: StrokeCap;
;; strokeColorGradient?: PenpotGradient; ;; strokeColorGradient?: Gradient;
;; } ;; }
(defn parse-stroke (defn parse-stroke
[^js stroke] [^js stroke]
@ -209,7 +218,7 @@
(when (some? strokes) (when (some? strokes)
(into [] (map parse-stroke) strokes))) (into [] (map parse-stroke) strokes)))
;; export interface PenpotBlur { ;; export interface Blur {
;; id?: string; ;; id?: string;
;; type?: 'layer-blur'; ;; type?: 'layer-blur';
;; value?: number; ;; value?: number;
@ -225,7 +234,7 @@
:hidden (obj/get blur "hidden")}))) :hidden (obj/get blur "hidden")})))
;; export interface PenpotExport { ;; export interface Export {
;; type: 'png' | 'jpeg' | 'svg' | 'pdf'; ;; type: 'png' | 'jpeg' | 'svg' | 'pdf';
;; scale: number; ;; scale: number;
;; suffix: string; ;; suffix: string;
@ -243,7 +252,7 @@
(when (some? exports) (when (some? exports)
(into [] (map parse-export) exports))) (into [] (map parse-export) exports)))
;; export interface PenpotFrameGuideColumnParams { ;; export interface GuideColumnParams {
;; color: { color: string; opacity: number }; ;; color: { color: string; opacity: number };
;; type?: 'stretch' | 'left' | 'center' | 'right'; ;; type?: 'stretch' | 'left' | 'center' | 'right';
;; size?: number; ;; size?: number;
@ -262,10 +271,10 @@
:item-length (obj/get params "itemLength") :item-length (obj/get params "itemLength")
:gutter (obj/get params "gutter")}))) :gutter (obj/get params "gutter")})))
;; export interface PenpotFrameGuideColumn { ;; export interface GuideColumn {
;; type: 'column'; ;; type: 'column';
;; display: boolean; ;; display: boolean;
;; params: PenpotFrameGuideColumnParams; ;; params: GuideColumnParams;
;; } ;; }
(defn parse-frame-guide-column (defn parse-frame-guide-column
[^js guide] [^js guide]
@ -275,10 +284,10 @@
:display (obj/get guide "display") :display (obj/get guide "display")
:params (-> (obj/get guide "params") parse-frame-guide-column-params)}))) :params (-> (obj/get guide "params") parse-frame-guide-column-params)})))
;; export interface PenpotFrameGuideRow { ;; export interface GuideRow {
;; type: 'row'; ;; type: 'row';
;; display: boolean; ;; display: boolean;
;; params: PenpotFrameGuideColumnParams; ;; params: GuideColumnParams;
;; } ;; }
(defn parse-frame-guide-row (defn parse-frame-guide-row
@ -289,7 +298,7 @@
:display (obj/get guide "display") :display (obj/get guide "display")
:params (-> (obj/get guide "params") parse-frame-guide-column-params)}))) :params (-> (obj/get guide "params") parse-frame-guide-column-params)})))
;;export interface PenpotFrameGuideSquareParams { ;;export interface GuideSquareParams {
;; color: { color: string; opacity: number }; ;; color: { color: string; opacity: number };
;; size?: number; ;; size?: number;
;;} ;;}
@ -300,10 +309,10 @@
{:color (-> (obj/get params "color") parse-color) {:color (-> (obj/get params "color") parse-color)
:size (obj/get params "size")}))) :size (obj/get params "size")})))
;; export interface PenpotFrameGuideSquare { ;; export interface GuideSquare {
;; type: 'square'; ;; type: 'square';
;; display: boolean; ;; display: boolean;
;; params: PenpotFrameGuideSquareParams; ;; params: GuideSquareParams;
;; } ;; }
(defn parse-frame-guide-square (defn parse-frame-guide-square
[^js guide] [^js guide]
@ -331,7 +340,7 @@
(when (some? guides) (when (some? guides)
(into [] (map parse-frame-guide) guides))) (into [] (map parse-frame-guide) guides)))
;;interface PenpotPathCommand { ;;interface PathCommand {
;; command: ;; command:
;; | 'M' | 'move-to' ;; | 'M' | 'move-to'
;; | 'Z' | 'close-path' ;; | 'Z' | 'close-path'
@ -401,13 +410,13 @@
(when (some? content) (when (some? content)
(into [] (map parse-command) content))) (into [] (map parse-command) content)))
;; export interface PenpotDissolve { ;; export interface Dissolve {
;; type: 'dissolve'; ;; type: 'dissolve';
;; duration: number; ;; duration: number;
;; easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out'; ;; easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out';
;; } ;; }
;; ;;
;; export interface PenpotSlide { ;; export interface Slide {
;; type: 'slide'; ;; type: 'slide';
;; way: 'in' | 'out'; ;; way: 'in' | 'out';
;; direction?: ;; direction?:
@ -420,7 +429,7 @@
;; easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out'; ;; easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out';
;; } ;; }
;; ;;
;; export interface PenpotPush { ;; export interface Push {
;; type: 'push'; ;; type: 'push';
;; direction?: ;; direction?:
;; | 'right' ;; | 'right'
@ -432,7 +441,7 @@
;; easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out'; ;; easing?: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out';
;; } ;; }
;; ;;
;; export type PenpotAnimation = PenpotDissolve | PenpotSlide | PenpotPush; ;; export type Animation = Dissolve | Slide | Push;
(defn parse-animation (defn parse-animation
[^js animation] [^js animation]
@ -461,24 +470,24 @@
nil))))) nil)))))
;;export type PenpotAction = ;;export type Action =
;; | PenpotNavigateTo ;; | NavigateTo
;; | PenpotOpenOverlay ;; | OpenOverlay
;; | PenpotToggleOverlay ;; | ToggleOverlay
;; | PenpotCloseOverlay ;; | CloseOverlay
;; | PenpotPreviousScreen ;; | PreviousScreen
;; | PenpotOpenUrl; ;; | OpenUrl;
;; ;;
;;export interface PenpotNavigateTo { ;;export interface NavigateTo {
;; type: 'navigate-to'; ;; type: 'navigate-to';
;; destination: PenpotFrame; ;; destination: Board;
;; preserveScrollPosition?: boolean; ;; preserveScrollPosition?: boolean;
;; animation: PenpotAnimation; ;; animation: Animation;
;;} ;;}
;; ;;
;;export interface PenpotOverlayAction { ;;export interface OverlayAction {
;; destination: PenpotFrame; ;; destination: Board;
;; relativeTo?: PenpotShape; ;; relativeTo?: Shape;
;; position?: ;; position?:
;; | 'manual' ;; | 'manual'
;; | 'center' ;; | 'center'
@ -488,31 +497,31 @@
;; | 'bottom-left' ;; | 'bottom-left'
;; | 'bottom-right' ;; | 'bottom-right'
;; | 'bottom-center'; ;; | 'bottom-center';
;; manualPositionLocation?: PenpotPoint; ;; manualPositionLocation?: Point;
;; closeWhenClickOutside?: boolean; ;; closeWhenClickOutside?: boolean;
;; addBackgroundOverlay?: boolean; ;; addBackgroundOverlay?: boolean;
;; animation: PenpotAnimation; ;; animation: Animation;
;;} ;;}
;; ;;
;;export interface PenpotOpenOverlay extends PenpotOverlayAction { ;;export interface OpenOverlay extends OverlayAction {
;; type: 'open-overlay'; ;; type: 'open-overlay';
;;} ;;}
;; ;;
;;export interface PenpotToggleOverlay extends PenpotOverlayAction { ;;export interface ToggleOverlay extends OverlayAction {
;; type: 'toggle-overlay'; ;; type: 'toggle-overlay';
;;} ;;}
;; ;;
;;export interface PenpotCloseOverlay { ;;export interface CloseOverlay {
;; type: 'close-overlay'; ;; type: 'close-overlay';
;; destination?: PenpotFrame; ;; destination?: Board;
;; animation: PenpotAnimation; ;; animation: Animation;
;;} ;;}
;; ;;
;;export interface PenpotPreviousScreen { ;;export interface PreviousScreen {
;; type: 'previous-screen'; ;; type: 'previous-screen';
;;} ;;}
;; ;;
;;export interface PenpotOpenUrl { ;;export interface OpenUrl {
;; type: 'open-url'; ;; type: 'open-url';
;; url: string; ;; url: string;
;;} ;;}

View file

@ -605,7 +605,7 @@
:get #(-> % u/proxy->shape :id str)} :get #(-> % u/proxy->shape :id str)}
{:name "type" {:name "type"
:get #(-> % u/proxy->shape :type d/name)} :get #(-> % u/proxy->shape :type format/shape-type)}
{:name "name" {:name "name"
:get #(-> % u/proxy->shape :name) :get #(-> % u/proxy->shape :name)
@ -656,6 +656,21 @@
(let [id (obj/get self "$id")] (let [id (obj/get self "$id")]
(st/emit! (dwsh/update-shapes [id] #(assoc % :hidden value))))))} (st/emit! (dwsh/update-shapes [id] #(assoc % :hidden value))))))}
{:name "visible"
:get #(-> % u/proxy->shape :hidden boolean not)
:set
(fn [self value]
(cond
(not (boolean? value))
(u/display-not-valid :visible value)
(not (r/check-permission plugin-id "content:write"))
(u/display-not-valid :visible "Plugin doesn't have 'content:write' permission")
:else
(let [id (obj/get self "$id")]
(st/emit! (dwsh/update-shapes [id] #(assoc % :hidden (not value)))))))}
{:name "proportionLock" {:name "proportionLock"
:get #(-> % u/proxy->shape :proportion-lock boolean) :get #(-> % u/proxy->shape :proportion-lock boolean)
:set :set
@ -972,7 +987,7 @@
parent-y (:y parent)] parent-y (:y parent)]
(st/emit! (dw/update-position id {:y (+ parent-y value)})))))} (st/emit! (dw/update-position id {:y (+ parent-y value)})))))}
{:name "frameX" {:name "boardX"
:get (fn [self] :get (fn [self]
(let [shape (u/proxy->shape self) (let [shape (u/proxy->shape self)
frame-id (:parent-id shape) frame-id (:parent-id shape)
@ -995,7 +1010,7 @@
frame-x (:x frame)] frame-x (:x frame)]
(st/emit! (dw/update-position id {:x (+ frame-x value)})))))} (st/emit! (dw/update-position id {:x (+ frame-x value)})))))}
{:name "frameY" {:name "boardY"
:get (fn [self] :get (fn [self]
(let [shape (u/proxy->shape self) (let [shape (u/proxy->shape self)
frame-id (:parent-id shape) frame-id (:parent-id shape)

View file

@ -175,7 +175,12 @@
:set :set
(fn [self value] (fn [self value]
(let [font (fonts/get-font-data (obj/get self "fontId")) (let [font (fonts/get-font-data (obj/get self "fontId"))
variant (fonts/find-variant font {:weight (dm/str value)})] weight (dm/str value)
style (obj/get self "fontStyle")
variant
(or
(fonts/find-variant font {:style style :weight weight})
(fonts/find-variant font {:weight weight}))]
(cond (cond
(nil? variant) (nil? variant)
(u/display-not-valid :fontWeight (dm/str "Font weight '" value "' not supported for the current font")) (u/display-not-valid :fontWeight (dm/str "Font weight '" value "' not supported for the current font"))
@ -193,7 +198,12 @@
:set :set
(fn [self value] (fn [self value]
(let [font (fonts/get-font-data (obj/get self "fontId")) (let [font (fonts/get-font-data (obj/get self "fontId"))
variant (fonts/find-variant font {:style (dm/str value)})] style (dm/str value)
weight (obj/get self "fontWeight")
variant
(or
(fonts/find-variant font {:weight weight :style style})
(fonts/find-variant font {:style style}))]
(cond (cond
(nil? variant) (nil? variant)
(u/display-not-valid :fontStyle (dm/str "Font style '" value "' not supported for the current font")) (u/display-not-valid :fontStyle (dm/str "Font style '" value "' not supported for the current font"))
@ -439,7 +449,12 @@
(fn [self value] (fn [self value]
(let [id (obj/get self "$id") (let [id (obj/get self "$id")
font (fonts/get-font-data (obj/get self "fontId")) font (fonts/get-font-data (obj/get self "fontId"))
variant (fonts/find-variant font {:weight (dm/str value)})] weight (dm/str value)
style (obj/get self "fontStyle")
variant
(or
(fonts/find-variant font {:style style :weight weight})
(fonts/find-variant font {:weight weight}))]
(cond (cond
(nil? variant) (nil? variant)
(u/display-not-valid :fontWeight (dm/str "Font weight '" value "' not supported for the current font")) (u/display-not-valid :fontWeight (dm/str "Font weight '" value "' not supported for the current font"))
@ -456,7 +471,12 @@
(fn [self value] (fn [self value]
(let [id (obj/get self "$id") (let [id (obj/get self "$id")
font (fonts/get-font-data (obj/get self "fontId")) font (fonts/get-font-data (obj/get self "fontId"))
variant (fonts/find-variant font {:style (dm/str value)})] style (dm/str value)
weight (obj/get self "fontWeight")
variant
(or
(fonts/find-variant font {:weight weight :style style})
(fonts/find-variant font {:style style}))]
(cond (cond
(nil? variant) (nil? variant)
(u/display-not-valid :fontStyle (dm/str "Font style '" value "' not supported for the current font")) (u/display-not-valid :fontStyle (dm/str "Font style '" value "' not supported for the current font"))

View file

@ -223,22 +223,22 @@
(t/is (= (-> (. shape -strokes) (aget 0) (aget "strokeWidth")) 5)))) (t/is (= (-> (. shape -strokes) (aget 0) (aget "strokeWidth")) 5))))
(t/testing "Relative properties" (t/testing "Relative properties"
(let [frame (.createFrame context)] (let [board (.createBoard context)]
(set! (.-x frame) 100) (set! (.-x board) 100)
(set! (.-y frame) 200) (set! (.-y board) 200)
(t/is (= (.-x frame) 100)) (t/is (= (.-x board) 100))
(t/is (= (.-y frame) 200)) (t/is (= (.-y board) 200))
(.appendChild frame shape) (.appendChild board shape)
(t/testing " - frameX" (t/testing " - boardX"
(set! (.-frameX shape) 10) (set! (.-boardX shape) 10)
(t/is (m/close? (.-frameX shape) 10)) (t/is (m/close? (.-boardX shape) 10))
(t/is (m/close? (.-x shape) 110)) (t/is (m/close? (.-x shape) 110))
(t/is (m/close? (get-in @store (get-shape-path :x)) 110))) (t/is (m/close? (get-in @store (get-shape-path :x)) 110)))
(t/testing " - frameY" (t/testing " - boardY"
(set! (.-frameY shape) 20) (set! (.-boardY shape) 20)
(t/is (m/close? (.-frameY shape) 20)) (t/is (m/close? (.-boardY shape) 20))
(t/is (m/close? (.-y shape) 220)) (t/is (m/close? (.-y shape) 220))
(t/is (m/close? (get-in @store (get-shape-path :y)) 220))) (t/is (m/close? (get-in @store (get-shape-path :y)) 220)))