-
Notifications
You must be signed in to change notification settings - Fork 289
Plugins
Adam Argyle edited this page May 20, 2019
·
3 revisions
Writing a plugin for VisBug requires 2 things:
-
An array:
a list of strings that when/typed
invoke your plugin -
A function:
VisBug will invoke your function with selected DOM
export const commands = []
export default async function({selected, query}) {
// selected is a nodeList containing the elements currently selected with VisBug
}
Have an idea and write a function that does it. Here's the Barrel Roll plugin as an example:
// VisBug won't allow registering a command that's already taken
export const commands = [
'barrel roll',
'do a barrel roll',
]
export default async function() {
// full access to the page dom: document.body, window, etc
document.body.style.transformOrigin = 'center 50vh'
await document.body.animate([
{ transform: 'rotateZ(0)' },
{ transform: 'rotateZ(1turn)' },
], { duration: 1500 }).finished
document.body.style.transformOrigin = ''
}
// plugins/_registry.js
import { commands as barrel_roll_commands, default as BarrelRollPlugin } from './barrel-roll'
...commandsToHash(barrel_roll_commands, BarrelRollPlugin),
test, debug, create a PR 💀🤘