|
| 1 | +--- |
| 2 | +whiskers: |
| 3 | + version: "2.0.0" |
| 4 | +--- |
| 5 | +import { |
| 6 | + JupyterFrontEnd, |
| 7 | + JupyterFrontEndPlugin |
| 8 | +} from '@jupyterlab/application'; |
| 9 | + |
| 10 | +import { IThemeManager } from '@jupyterlab/apputils'; |
| 11 | + |
| 12 | +import { ISettingRegistry } from '@jupyterlab/settingregistry'; |
| 13 | + |
| 14 | +import { CatppuccinPalettes } from './palettes'; |
| 15 | + |
| 16 | +/** |
| 17 | + * Initialization data for the catppuccin_jupyterlab extension. |
| 18 | + */ |
| 19 | +const plugin: JupyterFrontEndPlugin<void> = { |
| 20 | + id: 'catppuccin_jupyterlab:plugin', |
| 21 | + description: '📊 Soothing pastel theme for JupyterLab.', |
| 22 | + autoStart: true, |
| 23 | + requires: [IThemeManager], |
| 24 | + optional: [ISettingRegistry], |
| 25 | + activate: ( |
| 26 | + app: JupyterFrontEnd, |
| 27 | + manager: IThemeManager, |
| 28 | + settingRegistry: ISettingRegistry | null |
| 29 | + ) => { |
| 30 | + const style = 'catppuccin_jupyterlab/index.css'; |
| 31 | + const palettes = new CatppuccinPalettes(); |
| 32 | + |
| 33 | + let brandColor = 'mauve'; |
| 34 | + let accentColor = 'green'; |
| 35 | + |
| 36 | + function loadSettings(settingRegistry: ISettingRegistry | null) { |
| 37 | + if (settingRegistry) { |
| 38 | + settingRegistry |
| 39 | + .load(plugin.id) |
| 40 | + .then(settings => { |
| 41 | + brandColor = settings.get('brandColor').composite as string; |
| 42 | + accentColor = settings.get('accentColor').composite as string; |
| 43 | + console.debug( |
| 44 | + `catppuccin_jupyterlab settings loaded. Brand color is '${brandColor}', Accent color is '${accentColor}'` |
| 45 | + ); |
| 46 | + }) |
| 47 | + .catch(reason => { |
| 48 | + console.error( |
| 49 | + 'Failed to load settings for catppuccin_jupyterlab.', |
| 50 | + reason |
| 51 | + ); |
| 52 | + }); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + loadSettings(settingRegistry); |
| 57 | + |
| 58 | + {%- for id, flavor in flavors %} |
| 59 | + |
| 60 | + manager.register({ |
| 61 | + name: 'Catppuccin {{flavor.name}}', |
| 62 | + isLight: {{not flavor.dark}}, |
| 63 | + load: () => { |
| 64 | + palettes.setColors{{flavor.name | slugify | capitalize}}(); |
| 65 | + palettes.setConfigColors(brandColor, accentColor); |
| 66 | + return manager.loadCSS(style); |
| 67 | + }, |
| 68 | + unload: () => Promise.resolve(undefined) |
| 69 | + }); |
| 70 | + |
| 71 | + {%- endfor %} |
| 72 | + } |
| 73 | +}; |
| 74 | + |
| 75 | +export default plugin; |
0 commit comments