Luis de Dios fad083314d
🎉 Expose per-side stroke width in the plugin API (#11994)
* ✨ Add stroke side-width helpers to common types

Add set-width-to-all-sides, set-width-to-single-side and side-width to
app.common.types.stroke, mirroring the border-radius helpers in
app.common.types.shape.radius. They back the per-side stroke width API
and are covered by unit tests.

AI-assisted-by: deepseek-v4.1-flash

* ✨ Round-trip per-side stroke widths through the plugin API

Add strokeWidthTop/Right/Bottom/Left to format-stroke and parse-stroke so
reading shape.strokes exposes the per-side widths and writing a stroke
back preserves them instead of collapsing to the uniform width.

parse-stroke prefers a live stroke proxy's hidden raw state when present,
so a commit only rewrites the attributes the plugin touched.

AI-assisted-by: deepseek-v4.1-flash

* ✨ Add per-side stroke widths to the plugin API types

Add the four per-side members to the Stroke interface and to the
borderWidth and dimension token property lists, and refresh the generated
API surface used by the plugin test suite.

AI-assisted-by: deepseek-v4.1-flash

* ✨ Expose per-side stroke width on the stroke proxy

Add strokeWidthTop/Right/Bottom/Left to StrokeProxy. Reads fall back to
the uniform strokeWidth; strokeWidth now writes all four sides, like
borderRadius writes all four corners; each side setter writes only its
own key and the top side also updates strokeWidth.

Reject per-side writes on shapes other than boards and rectangles with a
validation error naming the property, and expose the raw stroke map
through a hidden proxy member so a commit preserves untouched attributes.

AI-assisted-by: deepseek-v4.1-flash

* ✨ Support stroke width tokens per side in the plugin API

Token attribute expansion now accepts the uniform strokeWidth property and
expands it to the four per-side attributes, mirroring the design tab.
shape.tokens exposes the per-side keys and reports strokeWidth when all
four sides share one token, and applyToken routes through the shared
expander.

AI-assisted-by: deepseek-v4.1-flash

* 📚 Document per-side stroke width in the plugins changelog

Note the new Stroke members, the restored strokeWidth token property and
the shape-type validation in plugins/CHANGELOG.md.

AI-assisted-by: deepseek-v4.1-flash

* 🐛 Fix some minor issues

---------

Co-authored-by: alonso.torres <alonso.torres@kaleidos.net>
2026-10-08 18:09:06 +02:00

71 lines
2.9 KiB
Clojure

;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS SUBSIDIARY SL
(ns frontend-tests.plugins.format-test
(:require
[app.plugins.exports :as exports]
[app.plugins.format :as format]
[app.plugins.shadows :as shadows]
[app.plugins.tracks :as tracks]
[cljs.test :as t :include-macros true]))
(t/deftest test-format-array-always-returns-array
(t/testing "nil collection returns an empty array"
(let [result (format/format-array identity nil)]
(t/is (array? result))
(t/is (= 0 (.-length result)))))
(t/testing "empty collection returns an empty array"
(let [result (format/format-array identity [])]
(t/is (array? result))
(t/is (= 0 (.-length result)))))
(t/testing "non-empty collection maps each item"
(let [result (format/format-array inc [1 2 3])]
(t/is (array? result))
(t/is (= [2 3 4] (vec result)))))
(t/testing "items dropped by format-fn (nil) are removed"
(let [result (format/format-array #(when (odd? %) %) [1 2 3 4])]
(t/is (= [1 3] (vec result))))))
(t/deftest test-array-wrappers-return-empty-array-on-nil
;; Each wrapper backs a non-nullable array-typed Plugin API property and
;; must return an empty array (never nil) when the source collection is nil.
(t/are [result] (and (array? result) (= 0 (.-length result)))
(shadows/format-shadows nil)
(exports/format-exports nil)
(format/format-frame-guides nil)
(tracks/format-tracks nil nil nil nil nil nil)
(format/format-path-content nil)))
(t/deftest test-format-color-result-uses-shapes-info-key
(let [shape-id (random-uuid)
result (format/format-color-result
[{:color "#fabada"}
[{:prop :fill :shape-id shape-id :index 0}]])
info (aget result "shapesInfo")]
(t/is (array? info))
(t/is (nil? (aget result "shapesColors")))
(t/is (= "fill" (aget (aget info 0) "property")))
(t/is (= (str shape-id) (aget (aget info 0) "shapeId")))))
(t/deftest test-shape-type-reports-boolean
(t/is (= "boolean" (format/shape-type :bool))))
(t/deftest test-format-stroke-exposes-per-side-widths
(let [stroke (format/format-stroke {:stroke-color "#000000"
:stroke-width 1
:stroke-width-top 2
:stroke-width-right 3
:stroke-width-bottom 4
:stroke-width-left 5})]
(t/is (= 1 (aget stroke "strokeWidth")))
(t/is (= 2 (aget stroke "strokeWidthTop")))
(t/is (= 3 (aget stroke "strokeWidthRight")))
(t/is (= 4 (aget stroke "strokeWidthBottom")))
(t/is (= 5 (aget stroke "strokeWidthLeft")))))