-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
57 lines (46 loc) · 1.59 KB
/
Copy pathplugin.js
File metadata and controls
57 lines (46 loc) · 1.59 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// This is the main entry point for the Penpot plugin
// It registers the plugin with Penpot and sets up message handlers
// Declare the penpot variable
let penpot
function runPlugin() {
// Register the plugin with Penpot
penpot.api.register({
name: "Circular Text Plugin",
version: "1.0.0",
author: "Penpot Plugin Creator",
description: "Create text along a circular path",
iconSVG: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M12 8v8"/><path d="M8 12h8"/></svg>`,
main: "index.html",
})
// Listen for messages from Penpot
window.addEventListener("message", handlePenpotMessage)
// Initialize the plugin UI
console.log("Circular Text Plugin initialized")
}
// Handle messages from Penpot
function handlePenpotMessage(event) {
const message = event.data
// Only process messages from Penpot
if (message.source !== "penpot") return
console.log("Received message from Penpot:", message)
// Handle different message types
switch (message.type) {
case "selection-changed":
// Update the plugin UI based on the current selection
window.dispatchEvent(
new CustomEvent("penpot-selection-changed", {
detail: message.payload,
}),
)
break
case "plugin-loaded":
// Plugin has been loaded in Penpot
window.dispatchEvent(new CustomEvent("penpot-plugin-loaded"))
break
default:
// Handle other message types if needed
break
}
}
// Run the plugin when the window loads
window.addEventListener("load", runPlugin)