ghostyles-manager
Source: ghostyles-manager.js:2
Instance Methods
deactivateEffect(): any
Deactivates the currently active ghostyle effect. If the loaded ghostyle module defines an onClear hook, it is invoked with the overlay canvas context to allow the effect to clean up any custom drawing state. Returns the style object for the previously active effect.
Returns
any— The style object of the previously active ghostyle, if any.
- See:
- toggleEffect – called when switching effects to ensure the previous effect is properly cleared.
- main.js – UI interactions trigger effect toggling which eventually calls this function.
messageEffectChange(
effect: string | null,
previousEffect: string | null,
)
Dispatches a custom effectChanged event to inform the rest of the application about a change in the active ghostyle effect. The event payload includes the new activeEffect identifier and the previous effect identifier.
Parameters
effect(string | null) — The identifier of the newly active effect, or null if none.previousEffect(string | null) — The identifier of the effect that was previously active.
- See:
- toggleEffect – triggers this notification when an effect is switched.
- main.js – listens for this event to update UI state.
Static Methods
fetchGhostyleMetadata(url: string): Object
Retrieves ghostyle metadata from a remote script URL. Parses the script text to extract the @name comment and derives an identifier from the filename. Returns an object containing id, name and the original url.
window.gstmxx is the local API used by the ghostyle(s) In regards of the loading, you can see from the network manager that each JS is loaded twice. The first time is to extract the metadata, the second time is to import the module.
Parameters
url(string) — The URL of the ghostyle script to fetch.
Returns
Object— Metadata for the ghostyle.
Throws
Error— Throws an error if the HTTP request fails or the response is not OK.
- See:
- scripts/main.js – loads ghostyle list and calls this function for each URL.
- tests/unit/ghostyles-manager.test.js – unit tests for metadata extraction.
importGhostyleModule(param: Object): Object
Dynamically imports a ghostyle module after its metadata has been retrieved. Returns an object containing the original metadata plus the loaded module.
Parameters
param(Object) — The ghostyle metadata.
Returns
Object— The ghostyle with its imported module.
- See:
- main.js – after metadata extraction, this function loads the actual ghostyle code.
- tests/unit/ghostyles-manager.test.js – tests import behavior.
loadGhostyle(
url: string,
expectedName: string,
options: Object,
): Promise.<(object|null)>
Unified plugin loader for both engines.
Every ghostyle is loaded from the same manifest. Runtime capabilities are detected from module exports:
- if module exports
onDraw, it can render on face-api ticks - if module exports
paintUV, it can render on MediaPipe UV ticks
Parameters
url(string)expectedName(string)options(Object)
Returns
Promise.<(object|null)>
toggleEffect(effect: string, button: HTMLElement)
Toggles a ghostyle effect on or off. Handles activation, deactivation, state updates, logging, and UI selection.
Parameters
effect(string) — Identifier of the ghostyle effect.button(HTMLElement) — The UI button tied to the effect.
- See:
- deactivateEffect – clears previous effect.
- messageEffectChange – notifies of effect changes.
- main.js – UI triggers this toggle.
reloadPlugins(options?: Object): Promise.<number>
Reload all plugins from the unified manifest with cache busting. The currently active plugin is deactivated and must be reselected.
Parameters
options(Object, optional)
Returns
Promise.<number>— Number of plugins loaded.