index.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import {
  4. CommandRegistry
  5. } from '@phosphor/commands';
  6. import {
  7. Token
  8. } from '@phosphor/coreutils';
  9. import {
  10. IInstanceTracker
  11. } from '@jupyterlab/apputils';
  12. import {
  13. ImageViewer
  14. } from './widget';
  15. export * from './widget';
  16. /**
  17. * A class that tracks editor widgets.
  18. */
  19. export
  20. interface IImageTracker extends IInstanceTracker<ImageViewer> {}
  21. /* tslint:disable */
  22. /**
  23. * The editor tracker token.
  24. */
  25. export
  26. const IImageTracker = new Token<IImageTracker>('jupyter.services.image-tracker');
  27. /* tslint:enable */
  28. /**
  29. * Add the default commands for the image widget.
  30. */
  31. export
  32. function addDefaultCommands(tracker: IImageTracker, commands: CommandRegistry) {
  33. commands.addCommand('imageviewer:zoom-in', {
  34. execute: zoomIn,
  35. label: 'Zoom In'
  36. });
  37. commands.addCommand('imageviewer:zoom-out', {
  38. execute: zoomOut,
  39. label: 'Zoom Out'
  40. });
  41. commands.addCommand('imageviewer:reset-zoom', {
  42. execute: resetZoom,
  43. label: 'Reset Zoom'
  44. });
  45. function zoomIn(): void {
  46. let widget = tracker.currentWidget;
  47. if (!widget) {
  48. return;
  49. }
  50. if (widget.scale > 1) {
  51. widget.scale += .5;
  52. } else {
  53. widget.scale *= 2;
  54. }
  55. }
  56. function zoomOut(): void {
  57. let widget = tracker.currentWidget;
  58. if (!widget) {
  59. return;
  60. }
  61. if (widget.scale > 1) {
  62. widget.scale -= .5;
  63. } else {
  64. widget.scale /= 2;
  65. }
  66. }
  67. function resetZoom(): void {
  68. let widget = tracker.currentWidget;
  69. if (!widget) {
  70. return;
  71. }
  72. widget.scale = 1;
  73. }
  74. }