Skip to content
导航

stroke

描边。

关键属性

stroke: string | PaintPaint[]

填充颜色、图像,用于描边。

支持纯色线性渐变径向渐变角度渐变图片填充 等类型, 支持多个填充同时叠加。

描边样式属性

strokeAlign?: StrokeAlign

描边的对齐方式, 默认为 inside,Path / Line 默认为 center。

tsx
type StrokeAlign = 'inside' | 'outside' | 'center' // 居中 | 内部 | 外部

strokeWidth?: number

描边的宽度, 默认为 1。

strokeCap?: StrokeCap

描边的端点形状,默认为 none。

ts
type StrokeCap =
  | 'none' // 无
  | 'round' // 圆形
  | 'square' // 方形

strokeJoin?: StrokeJoin

描边的拐角处理,默认为 miter 。

ts
type StrokeJoin =  'miter''bevel' | 'round' //  直角 | 平角 | 圆角

dashPattern?: number[]

虚线描边的数值。

ts
rect.dashPattern = [20, 10] // [线段,间隙]

示例

纯色填充

ts
import { Leafer, Rect } from 'leafer-ui'

const leafer = new Leafer({ view: window })

const rect = new Rect({
    width: 100,
    height: 100,
    stroke: '#32cd79', 
})

leafer.add(rect)

渐变填充

支持 线性渐变径向渐变角度渐变 等类型。

ts
import { Leafer, Rect } from 'leafer-ui'

const leafer = new Leafer({ view: window })

const rect = new Rect({
    width: 100,
    height: 100,
    stroke: {  
        type: 'linear',
        stops: [{ offset: 0, color: '#FF4B4B' }, { offset: 1, color: '#FEB027' }]
    },
})

leafer.add(rect)

图片填充

图片填充 支持 覆盖、适应、裁剪、平铺等模式。

ts
import { Leafer, Rect } from 'leafer-ui'

const leafer = new Leafer({ view: window })

const rect = new Rect({
    width: 100,
    height: 100,
    stroke: {  
        type: 'image',
        url: '/image/leafer.jpg',
        mode: 'cover',
    }
})

leafer.add(rect)

多个填充叠加

填充的 opacity 暂时仅针对 颜色对象 和图片有效。

ts
import { Leafer, Rect } from 'leafer-ui'

const leafer = new Leafer({ view: window })

const rect = new Rect({
    width: 100,
    height: 100,
    stroke: [ 
        {
            type: 'linear',
            stops: [{ offset: 0, color: '#FF4B4B' }, { offset: 1, color: '#FEB027' }]
        },
        {
            type: 'image',
            url: '/image/leafer.jpg',
            mode: 'cover',
            opacity: 0.5
        }]
})

leafer.add(rect)

绘制虚线

ts
import { Leafer, Rect } from 'leafer-ui'

const leafer = new Leafer({ view: window })

const rect = new Rect({
    width: 100,
    height: 100,
    stroke: '#32cd79',
    strokeWidth: 2,
    dashPattern: [6, 6] 
})

leafer.add(rect)

Released under the MIT License.