Pixso 开放文档
插件 API
官方工具集
  • 中文
  • English
插件 API
官方工具集
  • 中文
  • English
  • 插件 API

    • 简介
    • 预备知识
    • manifest
    • 开发指南
    • 更新日志
    • Plugin API 文档

      • 概述
      • 全局对象

        • pixso
        • pixso.ui
        • pixso.host
        • pixso.mouse
        • pixso.editor
        • pixso.keyboard
        • pixso.fieldset
        • pixso.viewport
        • pixso.vectorEditor
        • pixso.stickyToolbar
        • pixso.clientStorage
        • pixso.serverStorage
      • 节点类型

        • BooleanOperationNode
        • ComponentNode
        • ComponentSetNode
        • DocumentNode
        • EllipseNode
        • FrameNode
        • GroupNode
        • InstanceNode
        • LineNode
        • PageNode
        • PolygonNode
        • RectangleNode
        • SectionNode
        • SliceNode
        • StarNode
        • TextNode
        • VectorNode
      • 样式类型

        • PaintStyle
        • TextStyle
        • EffectStyle
        • GridStyle
      • 数据类型

        • Action
        • ArcData
        • BlendMode
        • CommandItem
        • ComponentProperties-Related
        • Constraints
        • DialogType
        • DocumentationLink
        • Effect
        • EmbedData
        • ExportSettings
        • FontName
        • Guide
        • HandleMirroring
        • HyperlinkTarget
        • Image
        • LayoutGrid
        • LetterSpacing
        • Library
        • LineHeight
        • NodeChangeProperty
        • OverflowDirection
        • Overlay
        • Paint
        • PublishStatus
        • Reaction
        • Rect-related
        • RGB & RGBA
        • StickyToolbar
        • StrokeCap
        • StrokeJoin
        • StyleChangeProperty
        • TextCase
        • TextDecoration
        • TextListOptions
        • ThemeType
        • ToolType
        • Transition
        • Trigger
        • Vector
    • Host API 文档

      • 概述
      • Host API
  • 服务端 API

    • OpenAPI 文档
    • OpenAPI 文档
    • 事件订阅
    • 事件订阅
  • 客户端 API

    • 简介
    • 唤醒客户端
    • Web API
    • 更新日志

SectionNode

分区节点常应用于合并归类相关联的图层。

Section node properties

type

  • Readonly: true
  • Type: SECTION

此节点的类型,由字符串“SECTION”表示

clone

  • Type: clone(): SectionNode

复制分区节点。

resizeWithoutConstraints

  • Type: resizeWithoutConstraints(width: number, height: number): void

调整节点大小。如果父级没有自动布局,则节点的子节点永远不会调整大小,即使这些子节点有约束。如果父级具有自动布局,则节点父级子节点和都会调整大小(不能忽略此约束)。

Base node properties

id

  • Readonly: true
  • Type: string

当前节点的 ID。

parent

  • Readonly: true
  • Type: (BaseNode & ChildrenMixin) | null

获取当前节点的父节点。

index

  • Readonly: true
  • Type: number

获取当前节点在同一层级下的顺序索引。

name

  • Type: string

读取或设置组件的名字,即图层面板中所展示的图层名称。

removed

  • Readonly: true
  • Type: boolean

如果节点被移除了,则返回 true。如果插件保持打开一段时间并存储对节点的引用,您应该防御性地编写代码并检查节点是否未被用户删除。

remove

  • Type: remove():void

从文档中删除此节点及其所有子节点。

toString

  • Type: string

返回节点的字符串表示形式。

setRelaunchData

  • Type: data: {[command: string]: string}): void

在节点上设置状态以在选择节点时显示按钮和描述。

getRelaunchData

  • Type: getRelaunchData(): { [command: string]: string }

检索存储在此节点上的重新启动数据,使用 setRelaunchData。

getPluginData

  • Type: getPluginData(key: string): string

获取节点上存储自定义信息,对您的插件来说是私有的。如果要获取字符串以外的值类型,请先通过 JSON.parse 将其解码。

setPluginData

  • Type: setPluginData(key: string, value: string): void

允许您在任何节点上存储自定义信息,对您的插件来说是私有的。如果要存储字符串以外的值类型,请先通过 JSON.stringify 将其编码。

getPluginDataKeys

  • Type: getPluginDataKeys(): string[]

获取当前插件存储信息的所有键名。

getSharedPluginData

  • Type: getSharedPluginData(namespace: string, key: string): string

获取存储在特定命名空间上的共享数据。

setSharedPluginData

  • Type: setSharedPluginData(namespace: string, key: string, value: string): void

这使您可以在任何节点上存储自定义信息。您可以稍后通过使用相同的命名空间和键调用 getSharedPluginData 来检索它。要查找存储在特定命名空间中的节点上的所有数据,请使用 getSharpedPluginDataKeys。

您使用此 API 编写的任何数据都可以被任何插件读取。目的是允许插件相互操作。如果您不希望其他插件能够读取您的数据,请改用 setPluginData。

您还必须提供命名空间参数以避免与其他插件的键冲突。此参数是强制性的,以防止多个插件使用通用键名(如数据)并相互覆盖。我们建议传递一个标识您的插件的值。可以将此命名空间提供给其他插件的作者,以便他们可以从您的插件中读取数据。

namespace 用于标识您的插件并避免与其他插件发生键冲突的唯一字符串。命名空间必须至少包含 3 个字母数字字符。

getSharedPluginDataKeys

  • Type: getSharedPluginDataKeys(namespace: string): string[]

查找存储在特定命名空间中的节点上的所有数据的键名。

Scene node properties

visible

  • Type: boolean

节点是否可见。该属性不影响插件访问节点的能力。

locked

  • Type: boolean

节点是否被锁定,防止在画布上进行某些用户交互,例如选择和拖动。该属性不影响插件写入这些属性的能力。

componentPropertyReferences

  • Type: { [nodeProperty in 'visible' | 'characters' | 'mainComponent']?: string} | null

获取应用在当前节点上的所有组件属性。键值对当中的值会对应组件或组件集节点上通过 componentPropertyDefinitions 获取到的组件属性名称。

只有组件或实例节点的子节点才具有 componentPropertyReferences 属性。

Children-related

children

  • Readonly: true
  • Type: ReadonlyArray<SceneNode>
  • Type Declaration: SceneNode

当前节点的直接子节点。

childrenCount

  • Readonly: true
  • Type: number

获取当前节点的直接子节点的数量。

appendChild

  • Type: appendChild(child: SceneNode, preserveAbsolutePostion?: boolean): void

将给定的节点 child 添加为当前节点的直接子节点。

appendChild 之后,默认保持 child 节点的 relativeTransform,由于 child 的父图层的改变,可能导致 child 节点在画布上的位置发生变更;若想保持 child 节点的位置,可以将 preserveAbsolutePostion 设为 true。

insertChild

  • Type: insertChild(index: number, child: SceneNode, preserveAbsolutePostion?: boolean): void

在指定的位置 index 处插入子节点 child。假设一个组有三个子节点 A、B、C,现在调用 insertChild 方法将插入图层节点 D:

  • insertChild(0, D),子节点顺序为:D、A、B、C。
  • insertChild(1, D),子节点顺序为:A、D、B、C。
  • insertChild(2, D),子节点顺序为:A、B、D、C。
  • insertChild(3, D),子节点顺序为:A、B、C、D。

findChildren

  • Type: findChildren(callback?: (node: SceneNode) => boolean): SceneNode[]

与 findAll 类似,不同之处在于,findChildren 仅会在当前节点的直接子节点(不包括子节点的子节点)中进行查找。

findChild

  • Type: findChild(callback: (node: SceneNode) => boolean): SceneNode | null

与 findOne 类似,不同之处在于,findChild 仅会在当前 ComponentNode 节点的直接子节点(不包括子节点的子节点)中进行查找。

findAll

  • Type: findAll(callback?: (node: SceneNode) => boolean): SceneNode[]

搜索整个子树(此节点的子节点、其子节点的子节点等)。 返回回调为其返回 true 的所有节点。

findOne

  • Type: findOne(callback: (node: SceneNode) => boolean): SceneNode | null

从当前节点开始查找整个节点树,对每个节点调用 callback 函数,并返回第一个对于 callback 函数的返回值为 true 的节点。

findAllWithCriteria

  • Type: findAllWithCriteria<T extends NodeType[]>(criteria: {types: T;}): Array<{ type: T[number] } & SceneNode>
  • Type Declaration: NodeType

搜索整个子树(此节点的子节点、其子节点的子节点等)。返回满足条件中定义的任何类型的所有节点。

Layout-related

x

  • Type: number

图层节点的位置,等价于 relativeTransform[0][2]。

y

  • Type: number

图层节点的位置,等价于 relativeTransform[1][2]。

width

  • Readonly: true
  • Type: number

图层节点的宽度。

height

  • Readonly: true
  • Type: number

图层节点的高度。

relativeTransform

  • Type: Transform
  • Type Declaration: Transform

图层节点相对于其父节点的位置,以变换矩阵的方式呈现。注意:relativeTransform 对自动布局普通子图层不生效,带有绝对定位的子图层依然生效。

absoluteTransform

  • Readonly: true
  • Type: Transform
  • Type Declaration: Transform

图层节点相对于包含它的页面的位置,以变换矩阵的方式呈现。

absoluteBoundingBox

  • Readonly: true
  • Type: Rect | null
  • Type Declaration: Rect

不包括阴影或笔触等渲染属性的节点边界。

getNestedBoundaryBox

  • Type:getNestedBoundaryBox(): NestedBoundaryBox
  • Type Declaration: NestedBoundaryBox

获取当前图层及其所有子图层的 boundaryBox 信息

Geometry-related

fills

  • Type: ReadonlyArray<Paint> | pixso.mixed
  • Type Declaration: Paint

图层的填充。

// 设置 fills
node.fills = newFills;

fillStyleId

  • Type: string | pixso.mixed

当前节点所链接的填充样式的 id。即当前节点的 fills 属性所链接的 PaintStyle 对象的 id。赋值为空即解绑样式。

strokes

  • Type: ReadonlyArray<Paint>
  • Type Declaration: Paint

图层的描边。

strokeStyleId

  • Type: string

当前节点所链接的描边样式的 id。即当前节点的 strokes 属性所链接的 PaintStyle 对象的 id。赋值为空即解绑样式。

strokeWeight

  • Type: number

四个方向描边的粗细,以像素为单位。必须是非负数,可以是小数。需要注意,若设置了单边描边如strokeTopWeight,则以单边描边为准;若设置了 strokeWeight,会同时设置了四个方向的单边描边。

strokeJoin

  • Type: StrokeJoin | pixso.mixed
  • Type Declaration: StrokeJoin

边角的装饰。

  • 'MITER': 直角。
  • 'BEVEL': 斜切。
  • 'ROUND': 圆角。

strokeAlign

  • Type: "CENTER" | "INSIDE" | "OUTSIDE"

描边相对于图层边界的对齐方式。

  • 'CENTER': 居中。
  • 'INSIDE': 内部。
  • 'OUTSIDE': 外部。

dashPattern

  • Type: ReadonlyArray<number>

指定交替短划线和间隙长度的数字列表,以像素为单位。

strokeCap

  • Type: StrokeCap | pixso.mixed
  • Type Declaration: StrokeCap

端点的装饰。

strokeMiterLimit

  • Type: number

行程的斜接限制。这与 SVG 斜接限制相同。

Export-related

exportSettings

  • Type: exportSettings: ReadonlyArray<ExportSettings>
  • Type Declaration: ExportSettings

节点的导出设置。

exportAsync

  • Type: exportAsync(settings?: ExportSettings): Promise<Uint8Array>
  • Type Declaration: ExportSettings

将节点导出为编码图像。

HWDC

exportJsonAsync

  • Type: exportJsonAsync(): Promise<string>

导出节点的 JSON 数据,该数据中包括节点的所有信息。

exportHexAsync

  • Type: exportHexAsync(hex: string): Promise<string>

导出节点的 Hex 数据,该数据中包括节点的所有信息。


Prev
RectangleNode
Next
SliceNode