编程语言/sketch:修订间差异
来自康健生活
小 文字替换 -“{{leftrightflex|”替换为“{{Double-columns|” |
|||
| (未显示同一用户的14个中间版本) | |||
| 第1行: | 第1行: | ||
== 引言 == | == 引言 == | ||
一个偶然的机会,开始接触设计软件的插件开发,在此记录 sketch 软件的插件开发过程。{{Timepoint|timepoint=2021-6-23 4:47 pm}} | 一个偶然的机会,开始接触设计软件的插件开发,在此记录 sketch 软件的插件开发过程。{{Timepoint|timepoint=2021-6-23 4:47 pm}} | ||
== API == | |||
<blockquote><pre> | |||
Library: Library | |||
Style: Style | |||
Fill: Fill | |||
ImageData: ImageData | |||
Image: Image | |||
Shadow: Shadow | |||
Document: Document | |||
SharedStyle: SharedStyle | |||
Override: Override | |||
Group: Group | |||
Artboard: Artboard | |||
Border: Border | |||
BorderOptions: BorderOptions | |||
Shape: Shape | |||
Blur: Blur | |||
Gradient: Gradient | |||
SymbolMaster: SymbolMaster | |||
DataOverride: DataOverride | |||
Text: Text | |||
HotSpot: HotSpot | |||
Page: Page | |||
ImportableObject: ImportableObject | |||
Flow: Flow | |||
SymbolInstance: SymbolInstance | |||
ShapePath: ShapePath | |||
GradientStop: GradientStop | |||
</pre></blockquote> | |||
== 插件 == | == 插件 == | ||
| 第99行: | 第128行: | ||
==== iframe ==== | ==== iframe ==== | ||
在 sketch 的 iframe 中,由于使用 iframe 并不能获取其 contentWindow,这与 photoshop 有着极大的区别。 | 在 sketch 的 iframe 中,由于使用 iframe 并不能获取其 contentWindow,这与 photoshop 有着极大的区别。 | ||
{{ | {{Double-columns|<syntaxhighlight lang="javascript"> | ||
console.log(iframe.contentDocument) | console.log(iframe.contentDocument) | ||
console.log(iframe.contentWindow.document) | console.log(iframe.contentWindow.document) | ||
| 第140行: | 第169行: | ||
== 项目结构 == | == 项目结构 == | ||
要扩展插件,所以我重构了一下项目的结构,现如下(重构中,并不是最终结果)。 | 要扩展插件,所以我重构了一下项目的结构,现如下(重构中,并不是最终结果)。 | ||
{{ | {{Double-columns|<pre> | ||
. | . | ||
├── assets | ├── assets | ||
| 第276行: | 第305行: | ||
</blockquote> | </blockquote> | ||
}} | }} | ||
== sketchObject == | |||
[[/sketchObject|sketchObject]] | |||
== other == | == other == | ||
| 第284行: | 第316行: | ||
| sketch-dev-tools || 示例 || 示例 | | sketch-dev-tools || 示例 || 示例 | ||
|} | |} | ||
=== sharedStyleId === | |||
<syntaxhighlight lang="javascript"> | |||
const outOfSync = !!layer.sharedStyleId && layer.style.isOutOfSyncWithSharedStyle(layer.sharedStyle)</syntaxhighlight> | |||
=== symbolId === | |||
获取 MSSymbolMaster。[[/MSSymbolMaster|MSSymbolMaster]] 的示例。 | |||
{{Double-columns|<syntaxhighlight lang="javascript"> | |||
const document = context.document; | |||
log(document.documentData().symbolWithID(layer?.symbolId));</syntaxhighlight>|{{consoleout|<pre> | |||
<MSSymbolMaster: 0x7fe41b62d400> icon_using document (3C94663C-B213-4FCD-A7CB-43A6AA877859) | |||
</pre>}}}} | |||
获取 symbol 样式。 | |||
{{Double-columns|<syntaxhighlight lang="javascript"> | |||
if (layer?.symbolId) { | |||
const document = context.document; | |||
const immutableMaster = document.documentData().symbolWithID(layer?.symbolId); | |||
const layerItem = sketch.fromNative(immutableMaster); | |||
log(layerItem); | |||
}</syntaxhighlight>|{{consoleout|<pre> | |||
if (layer?.symbolId) { | |||
const document = context.document; | |||
const immutableMaster = document.documentData().symbolWithID(layer?.symbolId); | |||
const layerItem = sketch.fromNative(immutableMaster); | |||
log(layerItem); | |||
} | |||
... | |||
type = Style; | |||
verticalAlignment = "<MOUndefined: 0x6000025b8da0>"; | |||
}; | |||
symbolId = "9AD4358B-C5B7-4D59-BBA3-D451D757685E"; | |||
transform = { | |||
}; | |||
type = SymbolMaster; | |||
} | |||
</pre>}}}} | |||
=== MSImmutableSymbolMaster === | |||
{{Double-columns|<syntaxhighlight lang="javascript"> | |||
const document = context.document; | |||
const immutableMaster = document.documentData().symbolWithID(layer?.symbolId).immutableModelObject(); | |||
log(immutableMaster)</syntaxhighlight>|{{consoleout|<pre> | |||
MSImmutableSymbolMaster: 0x7fe942b0d7d0> icon_using document (3C94663C-B213-4FCD-A7CB-43A6AA877859) | |||
</pre>}}}} | |||
== 示例 == | == 示例 == | ||
| 第295行: | 第371行: | ||
* https://developer.sketch.com/plugins/debugging/ | * https://developer.sketch.com/plugins/debugging/ | ||
* https://www.sketch.com/extensions/plugins/ | * https://www.sketch.com/extensions/plugins/ | ||
* https://sketchplugins.com/ | |||
* https://github.com/sketch-hq/sketch-document/ | |||
* https://github.com/sketch-hq/SketchAPI | |||