UNPKG

2.2 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var widgets_1 = require("@phosphor/widgets");
4var FontManager = /** @class */ (function () {
5 function FontManager(commands) {
6 this._commands = commands;
7 this._codeFontMenu = new widgets_1.Menu({ commands: commands });
8 this._codeFontMenu.title.label = 'Code Font';
9 this._codeStyle = document.createElement('style');
10 }
11 Object.defineProperty(FontManager.prototype, "menus", {
12 get: function () {
13 return [this._codeFontMenu];
14 },
15 enumerable: true,
16 configurable: true
17 });
18 Object.defineProperty(FontManager.prototype, "styles", {
19 get: function () {
20 return [this._codeStyle];
21 },
22 enumerable: true,
23 configurable: true
24 });
25 Object.defineProperty(FontManager.prototype, "codeFontFamily", {
26 get: function () {
27 return this._codeFontFamily;
28 },
29 set: function (fontFamily) {
30 this._codeFontFamily = fontFamily;
31 this._codeStyle.textContent = ":root {--jp-code-font-family: \"" + fontFamily + "\";}";
32 },
33 enumerable: true,
34 configurable: true
35 });
36 FontManager.prototype.registerCodeFont = function (fontFamily, variants) {
37 var _this = this;
38 if (variants === void 0) { variants = []; }
39 if (!variants.length) {
40 variants = [fontFamily];
41 }
42 else {
43 variants = variants.map(function (v) { return fontFamily + " " + v; });
44 }
45 variants.forEach(function (fontFamily) {
46 var id = 'code-font:' + fontFamily.replace(/[^a-z\d]/gi, '-').toLowerCase();
47 _this._commands.addCommand(id, {
48 label: "Use Code Font " + fontFamily,
49 isToggled: function () { return _this._codeFontFamily === fontFamily; },
50 execute: function () {
51 _this.codeFontFamily = fontFamily;
52 },
53 });
54 _this._codeFontMenu.addItem({ command: id });
55 return id;
56 });
57 };
58 return FontManager;
59}());
60exports.FontManager = FontManager;