pixso.codegen
pixso.codegen
provides APIs related to code generation. These APIs are only effective in the Dev mode, Historical Dev mode, and single artboard mode. For how the plugin runs in these modes, please refer to the manifest.editorType configuration.
unit
- type:
unit: "px" | "pt" | "dp" | "rem" | "sp"
Gets or modifies the dimension unit of the generated code. The default value is px
.
language
- type:
language: "CSS" | "swiftUI" | "UIKit" | "XML" | "Compose"
Gets or modifies the language type of the generated code. The default value is CSS
.
conversionRate
- type:
number
Gets or modifies the dimension ratio of the generated code. The default value is 1
.
on
on(type: "generatewithcfg", callback: (event: CodegenResultWithConfig) => void): void;
The on
method allows you to register a handler function for the code generation event. The callback function will be executed when the event occurs. The event types are as follows:
generatewithcfg
: This event will be triggered when the selected nodes in the canvas change, or when the configurations of codegen (such asunit
,language
,conversionRate
) change.
once
once(type: "generatewithcfg", callback: (event: CodegenResultWithConfig) => void): void;
The once
method allows you to register a handler function for the code generation event. The callback function will be executed when the event occurs. The difference between the once
method and the on
method is that the event handler function registered through the once
method will only be executed once.
off
off(type: "generatewithcfg", callback: (event: CodegenResultWithConfig) => void): void;
Removes the event handler function bound through pixso.codegen.on
or pixso.codegen.once
.