All files / src tokens.ts

100% Statements 89/89
100% Branches 10/10
100% Functions 5/5
100% Lines 89/89

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273                            40x   40x 40x 40x 40x   40x   40x 40x                                                                       40x                   40x                                                           40x 40x 40x 40x 40x     40x   40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x   40x 40x   40x 40x 40x 40x   40x 40x 40x 40x   40x 40x 40x 40x 40x   40x 40x 40x 40x 40x 40x   40x 40x 40x 40x 40x 40x 40x 40x   40x     40x 40x 40x     40x           40x             40x             40x             40x         40x         40x   40x 40x 40x   40x   40x 40x 40x 40x   40x 40x     40x   40x 40x   40x 40x 40x   40x 40x             40x         40x         40x                                                    
import {
  PACKAGE_NAME as FONTS_PACKAGE_NAME,
  IFontManager,
  IStyles,
} from '@deathbeds/jupyterlab-fonts';
import type { GlobalStyles } from '@deathbeds/jupyterlab-fonts/lib/_schema';
import { Token } from '@lumino/coreutils';
import { ISignal } from '@lumino/signaling';
import { Widget } from '@lumino/widgets';
 
import * as _PACKAGE from '../package.json';
 
import type { Layover } from './tools/layover';
 
export const PACKAGE = _PACKAGE;
 
export const NS = PACKAGE.name;
export const VERSION = PACKAGE.version;
export const PLUGIN_ID = `${NS}:plugin`;
export const CATEGORY = 'Decks';
 
export const NOTEBOOK_FACTORY = 'Notebook';
 
export const MARKDOWN_MIMETYPES = ['text/markdown', 'text/x-ipythongfm'];
export const MARKDOWN_PREVIEW_FACTORY = 'Markdown Preview';
 
/** The cell/notebook metadata. */
 
export interface IDeckManager {
  start(force: boolean): Promise<void>;
  stop(): Promise<void>;
  __: (msgid: string, ...args: string[]) => string;
  go(direction: TDirection, alternate?: TDirection): void;
  canGo(): Promise<Partial<TCanGoDirection>>;
  cacheStyle(...nodes: HTMLElement[]): void;
  uncacheStyle(...nodes: HTMLElement[]): void;
  addPresenter(presenter: IPresenter<any>): void;
  addStylePreset(preset: IStylePreset): void;
  stylePresets: IStylePreset[];
  activeWidget: Widget | null;
  activeWidgetStack: Widget[];
  activateWidget(widget: Widget): void;
  layover: Layover | null;
  // signals
  activeChanged: ISignal<IDeckManager, void>;
  stylePresetsChanged: ISignal<IDeckManager, void>;
  // re-hosted
  fonts: IFontManager;
  showLayover(): void;
  hideLayover(): void;
  layoverChanged: ISignal<IDeckManager, void>;
  activePresenter: IPresenter<any> | null;
  setSlideType(slideType: TSlideType): void;
  getSlideType(): TSlideType;
  getLayerScope(): TLayerScope | null;
  setLayerScope(layerScope: TLayerScope | null): void;
  getPartStyles(): GlobalStyles | null;
  setPartStyles(styles: GlobalStyles | null): void;
}
 
export const IDeckManager = new Token<IDeckManager>(PLUGIN_ID);
 
export interface IPresenterCapbilities {
  layout?: boolean;
  slideType?: boolean;
  layerScope?: boolean;
  stylePart?: boolean;
  subslides?: boolean;
}
 
export const INCAPABLE: IPresenterCapbilities = Object.freeze({
  layout: false,
  slideType: false,
  layerScope: false,
  stylePart: false,
  subslides: false,
});
 
export interface IPresenterOptional<T> {
  setSlideType(widget: T, slideType: TSlideType): void;
  getSlideType(widget: T): TSlideType;
  setLayerScope(widget: T, layerType: TLayerScope | null): void;
  getLayerScope(widget: T): TLayerScope | null;
  getPartStyles(widget: T): GlobalStyles | null;
  setPartStyles(widget: T, styles: GlobalStyles | null): void;
}
 
export interface IPresenter<T extends Widget> extends Partial<IPresenterOptional<T>> {
  id: string;
  rank: number;
  capabilities: IPresenterCapbilities;
  accepts(widget: Widget): T | null;
  stop(widget: Widget): Promise<void>;
  start(widget: T): Promise<void>;
  go(widget: T, direction: TDirection, alternate?: TDirection): Promise<void>;
  canGo(widget: T): Promise<Partial<TCanGoDirection>>;
  style(widget: T): Promise<void>;
  activeChanged: ISignal<IPresenter<T>, void>;
}
 
export namespace DATA {
  export const deckMode = 'jpDeckMode';
  export const presenting = 'presenting';
  export const layoutMode = 'jpDeckLayoutMode';
  export const designing = 'designing';
}
 
export namespace CSS {
  // lab
  export const disabled = 'jp-mod-disabled';
  export const icon = 'jp-icon3';
  export const iconBrand = 'jp-icon-brand0';
  export const iconContrast = 'jp-icon-contrast0';
  export const iconWarn = 'jp-icon-warn0';
  export const selectWrapper = 'jp-select-wrapper';
  export const styled = 'jp-mod-styled';
  export const accept = 'jp-mod-accept';
  export const active = 'jp-mod-active';
  export const mainContent = 'jp-main-content-panel';
  export const renderedMarkdown = 'jp-RenderedMarkdown';
  export const markdownViewer = 'jp-MarkdownViewer';
  // deck
  export const deck = 'jp-Deck';
  export const presenting = `[data-jp-deck-mode='${DATA.presenting}']`;
  // remote
  export const remote = 'jp-Deck-Remote';
  export const directions = 'jp-Deck-Remote-directions';
  export const stop = 'jp-deck-mod-stop';
  export const widgetStack = 'jp-Deck-Remote-WidgetStack';
  // notebook
  export const direction = 'jp-deck-mod-direction';
  export const onScreen = 'jp-deck-mod-onscreen';
  export const visible = 'jp-deck-mod-visible';
  export const layer = 'jp-deck-mod-layer';
  // metadata
  export const metaTool = 'jp-Deck-Metadata';
  export const selectSplit = 'jp-Deck-SelectSplit';
  export const toolLayer = 'jp-Deck-Tool-layer';
  export const toolPreset = 'jp-Deck-Tool-preset';
  export const apply = 'jp-deck-mod-apply';
  // layover
  export const layover = 'jp-Deck-Layover';
  export const layoverPart = 'jp-Deck-LayoverPart';
  export const layoverPartLabel = 'jp-Deck-LayoverLabel';
  export const layoverHandle = 'jp-Deck-LayoverHandle';
  export const dragging = 'jp-deck-mod-dragging';
  export const layoverUnstyle = 'jp-Deck-LayoverUnstyle';
  // design tools
  export const designTools = 'jp-Deck-DesignTools';
  export const selector = 'jp-Deck-DesignTools-Selector';
  export const slider = 'jp-Deck-DesignTools-Slider';
  export const slideType = 'jp-deck-mod-slidetype';
  export const layerScope = 'jp-deck-mod-layerscope';
  export const zoom = 'jp-deck-mod-zoom';
  export const opacity = 'jp-deck-mod-opacity';
  export const zIndex = 'jp-deck-mod-z-index';
  // sheets
  export const sheet = 'jp-Deck-Stylesheet';
}
 
export namespace ID {
  export const layerSelect = 'id-jp-decktools-select-layer';
  export const presetSelect = 'id-jp-decktools-select-preset';
}
 
export const EMOJI = '🃏';
 
export type TDirection = 'forward' | 'up' | 'back' | 'down';
 
export type TCanGoDirection = Record<TDirection, boolean>;
 
export const DIRECTION: Record<string, TDirection> = {
  up: 'up',
  down: 'down',
  back: 'back',
  forward: 'forward',
};
 
export const DIRECTION_LABEL: Record<TDirection, string> = {
  forward: 'Go to next slide/fragment in Deck',
  back: 'Go to previous slide/fragment in Deck',
  up: 'Go to slide, subslide, or fragment above in Deck',
  down: 'Go to next fragment or subslide in Deck',
};
 
export const DIRECTION_KEYS: Record<TDirection, string[]> = {
  forward: ['ArrowRight'],
  back: ['ArrowLeft'],
  up: ['ArrowUp'],
  down: ['ArrowDown'],
};
 
export const COMPOUND_LABEL = new Map<[TDirection, TDirection], string>([
  [[DIRECTION.down, DIRECTION.forward], 'Go to next fragment, subslide, or slide'],
  [[DIRECTION.up, DIRECTION.back], 'Go to previous fragment, subslide, or slide'],
]);
 
export const COMPOUND_KEYS = new Map<[TDirection, TDirection], string[]>([
  [[DIRECTION.down, DIRECTION.forward], ['Space']],
  [[DIRECTION.up, DIRECTION.back], ['Shift Space']],
]);
 
export namespace CommandIds {
  /* global */
  export const toggle = 'deck:toggle';
  export const start = 'deck:start';
  export const stop = 'deck:stop';
  /* nagivate */
  export const go = 'deck:go';
  /* directions */
  export const forward = 'deck:forward';
  export const back = 'deck:back';
  export const down = 'deck:down';
  export const up = 'deck:up';
  /* layover */
  export const showLayover = 'deck:show-layover';
  export const hideLayover = 'deck:hide-layover';
}
 
export namespace META {
  // nbconvert
  export const slideshow = 'slideshow';
  export const slideType = 'slide_type';
  // fonts
  export const fonts = FONTS_PACKAGE_NAME;
  export const nullSelector = '';
  export const presentingCell = `body[data-jp-deck-mode='presenting'] &`;
  // deck
  export const deck = NS.split('/')[1];
  export const layer = 'layer';
}
 
/**
 * mutually-exclusive `cells/{i}/metadata/slideshow` values supported by
 * nbconvert, notebook, and lab UI
 **/
export const SLIDE_TYPES = ['slide', 'subslide', null, 'fragment', 'notes', 'skip'];
export type TSlideType = (typeof SLIDE_TYPES)[number];
 
/** The scope of extents that will have this layer */
 
export const LAYER_SCOPES = ['deck', 'stack', 'slide', 'fragment'];
export type TLayerScope = (typeof LAYER_SCOPES)[number];
 
export type TSelectLabels<T extends string> = Record<T, string>;
 
export const LAYER_TITLES: TSelectLabels<TLayerScope | '-'> = {
  '-': 'Do not show this cell as a layer.',
  deck: 'Show this layer on all future slides.',
  stack: 'Show this layer until the next slide.',
  slide: 'Show this layer until the next slider or subslide.',
  fragment: 'Show this until the next fragment.',
};
 
/** Expected cell metadata in the `jupyterlab-deck` namespace */
export interface ICellDeckMetadata {
  layer?: TLayerScope;
}
 
export interface IStylePreset {
  key: string;
  scope: 'layer' | 'slide' | 'deck' | 'any';
  label: string;
  styles: IStyles;
}
 
export interface IDeckSettings {
  active?: boolean;
  stylePresets?: {
    [key: string]: Partial<IStylePreset>;
  };
}