-
Notifications
You must be signed in to change notification settings - Fork 346
Expand file tree
/
Copy pathcode.ts
More file actions
31 lines (25 loc) · 862 Bytes
/
code.ts
File metadata and controls
31 lines (25 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
figma.showUI(__html__, { height: 600, width: 600 });
void initialize();
async function initialize() {
if ("loadAllPagesAsync" in figma) {
await figma.loadAllPagesAsync();
}
figma.on("documentchange", (event) => {
const messages = event.documentChanges.map(documentChangeAsString);
figma.ui.postMessage(messages);
});
}
function documentChangeAsString(change: DocumentChange): string {
const { origin, type } = change;
const list: string[] = [origin, type];
if (type === "PROPERTY_CHANGE") {
list.push(change.node.type, change.properties.join(", "));
} else if (type === "STYLE_PROPERTY_CHANGE") {
if (change.style) {
list.push(change.style.name, change.properties.join(", "));
}
} else if (type !== "STYLE_CREATE" && type !== "STYLE_DELETE") {
list.push(change.node.type);
}
return list.join(" ");
}