custom-electron-titlebar 4.2.8 → 4.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +32 -12
  2. package/index.d.mts +684 -0
  3. package/index.d.ts +684 -3
  4. package/index.js +5207 -175
  5. package/index.js.map +1 -0
  6. package/index.mjs +5219 -0
  7. package/index.mjs.map +1 -0
  8. package/main/index.d.mts +21 -0
  9. package/main/index.d.ts +21 -3
  10. package/main/index.js +793 -175
  11. package/main/index.js.map +1 -0
  12. package/main/index.mjs +785 -0
  13. package/main/index.mjs.map +1 -0
  14. package/package.json +40 -32
  15. package/base/browser/browser.d.ts +0 -26
  16. package/base/browser/browser.js +0 -317
  17. package/base/browser/event.d.ts +0 -12
  18. package/base/browser/event.js +0 -215
  19. package/base/browser/keyboardEvent.d.ts +0 -38
  20. package/base/browser/keyboardEvent.js +0 -462
  21. package/base/browser/mouseEvent.d.ts +0 -61
  22. package/base/browser/mouseEvent.js +0 -327
  23. package/base/browser/touch.d.ts +0 -39
  24. package/base/browser/touch.js +0 -454
  25. package/base/common/arrays.d.ts +0 -10
  26. package/base/common/arrays.js +0 -210
  27. package/base/common/async.d.ts +0 -35
  28. package/base/common/async.js +0 -280
  29. package/base/common/charCode.d.ts +0 -405
  30. package/base/common/charCode.js +0 -9
  31. package/base/common/color.d.ts +0 -159
  32. package/base/common/color.js +0 -708
  33. package/base/common/decorators.d.ts +0 -6
  34. package/base/common/decorators.js +0 -300
  35. package/base/common/dom.d.ts +0 -221
  36. package/base/common/dom.js +0 -1476
  37. package/base/common/event.d.ts +0 -213
  38. package/base/common/event.js +0 -804
  39. package/base/common/iterator.d.ts +0 -69
  40. package/base/common/iterator.js +0 -380
  41. package/base/common/keyCodes.d.ts +0 -478
  42. package/base/common/keyCodes.js +0 -477
  43. package/base/common/lifecycle.d.ts +0 -17
  44. package/base/common/lifecycle.js +0 -258
  45. package/base/common/linkedList.d.ts +0 -17
  46. package/base/common/linkedList.js +0 -319
  47. package/base/common/platform.d.ts +0 -36
  48. package/base/common/platform.js +0 -314
  49. package/base/common/strings.d.ts +0 -23
  50. package/base/common/strings.js +0 -273
  51. package/consts.d.ts +0 -58
  52. package/consts.js +0 -317
  53. package/main/attach-titlebar-to-window.d.ts +0 -3
  54. package/main/attach-titlebar-to-window.js +0 -210
  55. package/main/setup-titlebar.d.ts +0 -2
  56. package/main/setup-titlebar.js +0 -255
  57. package/menubar/index.d.ts +0 -86
  58. package/menubar/index.js +0 -1119
  59. package/menubar/menu/index.d.ts +0 -46
  60. package/menubar/menu/index.js +0 -565
  61. package/menubar/menu/item.d.ts +0 -67
  62. package/menubar/menu/item.js +0 -575
  63. package/menubar/menu/separator.d.ts +0 -11
  64. package/menubar/menu/separator.js +0 -213
  65. package/menubar/menu/submenu.d.ts +0 -32
  66. package/menubar/menu/submenu.js +0 -372
  67. package/menubar/menubar-options.d.ts +0 -47
  68. package/menubar/menubar-options.js +0 -9
  69. package/titlebar/index.d.ts +0 -105
  70. package/titlebar/index.js +0 -703
  71. package/titlebar/options.d.ts +0 -89
  72. package/titlebar/options.js +0 -9
  73. package/titlebar/themebar.d.ts +0 -20
  74. package/titlebar/themebar.js +0 -267
package/titlebar/index.js DELETED
@@ -1,703 +0,0 @@
1
- "use strict";
2
-
3
- /* ---------------------------------------------------------------------------------------------
4
- * Copyright (c) AlexTorresDev. All rights reserved.
5
- * Licensed under the MIT License. See License.txt in the project root for license information.
6
- *-------------------------------------------------------------------------------------------- */
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports.CustomTitlebar = void 0;
11
- const electron_1 = require("electron");
12
- const color_1 = require("../base/common/color");
13
- const dom_1 = require("../base/common/dom");
14
- const platform_1 = require("../base/common/platform");
15
- const menubar_1 = require("../menubar");
16
- const themebar_1 = require("./themebar");
17
- const consts_1 = require("../consts");
18
- class CustomTitlebar extends _get__("themebar_1").ThemeBar {
19
- /**
20
- * Create a new TitleBar instance
21
- * @param options The options for the title bar
22
- */
23
- constructor(options) {
24
- super();
25
- this.isInactive = false;
26
- this.currentOptions = {
27
- closeable: true,
28
- enableMnemonics: true,
29
- // hideWhenClickingClose: false,
30
- iconSize: 16,
31
- itemBackgroundColor: undefined,
32
- maximizable: true,
33
- menuPosition: 'left',
34
- menuTransparency: 0,
35
- minimizable: true,
36
- onlyShowMenuBar: false,
37
- shadow: false,
38
- titleHorizontalAlignment: 'center',
39
- tooltips: {
40
- close: 'Close',
41
- maximize: 'Maximize',
42
- minimize: 'Minimize',
43
- restoreDown: 'Restore Down'
44
- },
45
- unfocusEffect: true
46
- };
47
- // TODO: Refactor, verify if is possible use into menubar
48
- this.closeMenu = () => {
49
- if (this.menuBar) {
50
- this.menuBar.blur();
51
- }
52
- };
53
- this.currentOptions = {
54
- ...this.currentOptions,
55
- ...options
56
- };
57
- const jWindowIcons = _get__("consts_1").menuIcons[(0, _get__("platform_1").PlatformToString)(_get__("platform_1").platform)?.toLocaleLowerCase()];
58
- this.platformIcons = jWindowIcons;
59
- this.titlebar = (0, _get__("dom_1").$)('.cet-titlebar');
60
- this.dragRegion = (0, _get__("dom_1").$)('.cet-drag-region');
61
- this.icon = (0, _get__("dom_1").$)('.cet-icon');
62
- this.menuBarContainer = (0, _get__("dom_1").$)('.cet-menubar');
63
- this.title = (0, _get__("dom_1").$)('.cet-title');
64
- this.controlsContainer = (0, _get__("dom_1").$)('.cet-window-controls');
65
- this.container = (0, _get__("dom_1").$)('.cet-container');
66
- this.controls = {
67
- minimize: (0, _get__("dom_1").$)('.cet-control-minimize'),
68
- maximize: (0, _get__("dom_1").$)('.cet-control-maximize'),
69
- close: (0, _get__("dom_1").$)('.cet-control-close')
70
- };
71
- this.resizer = {
72
- top: (0, _get__("dom_1").$)('.cet-resizer.top'),
73
- left: (0, _get__("dom_1").$)('.cet-resizer.left')
74
- };
75
- (0, _get__("dom_1").append)(this.titlebar, this.dragRegion);
76
- (0, _get__("dom_1").append)(this.titlebar, this.resizer.left);
77
- (0, _get__("dom_1").append)(this.titlebar, this.resizer.top);
78
- this.loadIcons();
79
- this.setupBackgroundColor();
80
- this.createIcon();
81
- this.setupMenubar();
82
- this.setupTitle();
83
- this.setupWindowControls();
84
- this.setupContainer();
85
- this.setupTitleBar();
86
- this.loadEvents();
87
- // this.registerTheme(ThemeBar.win)
88
- }
89
- loadIcons() {
90
- const icons = this.currentOptions.icons;
91
- if (icons) {
92
- const {
93
- platformIcons
94
- } = (0, _get__("consts_1").loadWindowIcons)(icons);
95
- this.platformIcons = platformIcons;
96
- }
97
- }
98
- /**
99
- * Setup the background color of the title bar
100
- * By default, it will use the meta theme-color or msapplication-TileColor and if it doesn't exist, it will use white
101
- */
102
- setupBackgroundColor() {
103
- let color = this.currentOptions.backgroundColor;
104
- if (!color) {
105
- const metaColor = document.querySelectorAll('meta[name="theme-color"]') || document.querySelectorAll('meta[name="msapplication-TileColor"]');
106
- metaColor.forEach(meta => {
107
- color = _get__("color_1").Color.fromHex(meta.getAttribute('content'));
108
- });
109
- if (!color) color = _get__("color_1").Color.WHITE;
110
- this.currentOptions.backgroundColor = color;
111
- }
112
- this.titlebar.style.backgroundColor = color.toString();
113
- }
114
- /**
115
- * Render the icon of the title bar, if is mac, it will not render
116
- * By default, it will use the first icon found in the head of the document
117
- */
118
- createIcon() {
119
- // const onlyRendererMenuBar = this.currentOptions.onlyShowMenuBar
120
- if (_get__("platform_1").isMacintosh) return;
121
- let icon = this.currentOptions.icon;
122
- if (!icon) {
123
- const tagLink = document.querySelectorAll('link');
124
- tagLink.forEach(link => {
125
- if (link.getAttribute('rel') === 'icon' || link.getAttribute('rel') === 'shortcut icon') {
126
- icon = link.getAttribute('href');
127
- }
128
- this.currentOptions.icon = icon;
129
- });
130
- }
131
- if (icon) {
132
- const windowIcon = (0, _get__("dom_1").append)(this.icon, (0, _get__("dom_1").$)('img'));
133
- if (typeof icon === 'string') {
134
- windowIcon.setAttribute('src', icon);
135
- } else {
136
- windowIcon.setAttribute('src', icon.toDataURL());
137
- }
138
- this.setIconSize(this.currentOptions.iconSize);
139
- (0, _get__("dom_1").append)(this.titlebar, this.icon);
140
- }
141
- }
142
- setIconSize(size) {
143
- if (size < 16) size = 16;
144
- if (size > 24) size = 24;
145
- this.icon.firstElementChild.setAttribute('style', `height: ${size}px`);
146
- }
147
- setupMenubar() {
148
- _get__("electron_1").ipcRenderer.invoke('request-application-menu')?.then(menu => this.updateMenu(menu));
149
- const menuPosition = this.currentOptions.menuPosition;
150
- if (menuPosition) {
151
- this.updateMenuPosition(menuPosition);
152
- }
153
- (0, _get__("dom_1").append)(this.titlebar, this.menuBarContainer);
154
- }
155
- setupTitle() {
156
- const onlyRendererMenuBar = this.currentOptions.onlyShowMenuBar;
157
- if (onlyRendererMenuBar) return;
158
- this.updateTitle(document.title);
159
- this.updateTitleAlignment(this.currentOptions.titleHorizontalAlignment);
160
- (0, _get__("dom_1").append)(this.titlebar, this.title);
161
- }
162
- createControlButton(element, icon, title, active = true) {
163
- (0, _get__("dom_1").addClass)(element, 'cet-control-icon');
164
- element.innerHTML = icon;
165
- element.title = title;
166
- if (!active) {
167
- (0, _get__("dom_1").addClass)(element, 'inactive');
168
- }
169
- (0, _get__("dom_1").append)(this.controlsContainer, element);
170
- }
171
- setupWindowControls() {
172
- const onlyRendererMenuBar = this.currentOptions.onlyShowMenuBar;
173
- const tooltips = this.currentOptions.tooltips;
174
- if (_get__("platform_1").isMacintosh || onlyRendererMenuBar) return;
175
- this.createControlButton(this.controls.minimize, this.platformIcons?.minimize, tooltips.minimize, this.currentOptions.minimizable);
176
- this.createControlButton(this.controls.maximize, this.platformIcons?.maximize, tooltips.maximize, this.currentOptions.maximizable);
177
- this.createControlButton(this.controls.close, this.platformIcons?.close, tooltips.close, this.currentOptions.closeable);
178
- (0, _get__("dom_1").append)(this.titlebar, this.controlsContainer);
179
- }
180
- setupContainer() {
181
- const containerOverflow = this.currentOptions.containerOverflow;
182
- if (containerOverflow) {
183
- this.container.style.overflow = containerOverflow;
184
- }
185
- while (document.body.firstChild) {
186
- (0, _get__("dom_1").append)(this.container, document.body.firstChild);
187
- }
188
- (0, _get__("dom_1").append)(document.body, this.container);
189
- }
190
- setupTitleBar() {
191
- const order = this.currentOptions.order;
192
- const hasShadow = this.currentOptions.shadow;
193
- (0, _get__("dom_1").addClass)(this.titlebar, `cet-${(0, _get__("platform_1").PlatformToString)(_get__("platform_1").platform)?.toLocaleLowerCase()}`);
194
- if (order) {
195
- (0, _get__("dom_1").addClass)(this.titlebar, `cet-${order}`);
196
- }
197
- if (hasShadow) {
198
- (0, _get__("dom_1").addClass)(this.titlebar, 'cet-shadow');
199
- }
200
- if (!_get__("platform_1").isMacintosh) {
201
- this.title.style.cursor = 'default';
202
- }
203
- (0, _get__("dom_1").prepend)(document.body, this.titlebar);
204
- }
205
- loadEvents() {
206
- const onlyRendererMenuBar = this.currentOptions.onlyShowMenuBar;
207
- if (onlyRendererMenuBar) return;
208
- const minimizable = this.currentOptions.minimizable;
209
- const maximizable = this.currentOptions.maximizable;
210
- const closeable = this.currentOptions.closeable;
211
- this.onDidChangeMaximized(_get__("electron_1").ipcRenderer.sendSync('window-event', 'window-is-maximized'));
212
- _get__("electron_1").ipcRenderer.on('window-maximize', (_, isMaximized) => this.onDidChangeMaximized(isMaximized));
213
- _get__("electron_1").ipcRenderer.on('window-fullscreen', (_, isFullScreen) => this.onWindowFullScreen(isFullScreen));
214
- _get__("electron_1").ipcRenderer.on('window-focus', (_, isFocused) => this.onWindowFocus(isFocused));
215
- if (minimizable) {
216
- (0, _get__("dom_1").addDisposableListener)(this.controls.minimize, _get__("dom_1").EventType.CLICK, () => {
217
- _get__("electron_1").ipcRenderer.send('window-event', 'window-minimize');
218
- });
219
- }
220
- if (_get__("platform_1").isMacintosh) {
221
- (0, _get__("dom_1").addDisposableListener)(this.titlebar, _get__("dom_1").EventType.DBLCLICK, () => {
222
- _get__("electron_1").ipcRenderer.send('window-event', 'window-maximize');
223
- });
224
- }
225
- if (maximizable) {
226
- (0, _get__("dom_1").addDisposableListener)(this.controls.maximize, _get__("dom_1").EventType.CLICK, () => {
227
- _get__("electron_1").ipcRenderer.send('window-event', 'window-maximize');
228
- });
229
- }
230
- if (closeable) {
231
- (0, _get__("dom_1").addDisposableListener)(this.controls.close, _get__("dom_1").EventType.CLICK, () => {
232
- _get__("electron_1").ipcRenderer.send('window-event', 'window-close');
233
- });
234
- }
235
- }
236
- onBlur() {
237
- this.isInactive = true;
238
- this.updateStyles();
239
- }
240
- onFocus() {
241
- this.isInactive = false;
242
- this.updateStyles();
243
- }
244
- onMenuBarVisibilityChanged(visible) {
245
- if (_get__("platform_1").isWindows || _get__("platform_1").isLinux || _get__("platform_1").isFreeBSD) {
246
- if (visible) {
247
- // Hack to fix issue #52522 with layered webkit-app-region elements appearing under cursor
248
- (0, _get__("dom_1").hide)(this.dragRegion);
249
- setTimeout(() => (0, _get__("dom_1").show)(this.dragRegion), 50);
250
- }
251
- }
252
- }
253
- onMenuBarFocusChanged(focused) {
254
- if (_get__("platform_1").isWindows || _get__("platform_1").isLinux || _get__("platform_1").isFreeBSD) {
255
- if (focused) (0, _get__("dom_1").hide)(this.dragRegion);else (0, _get__("dom_1").show)(this.dragRegion);
256
- }
257
- }
258
- onDidChangeMaximized(isMaximized) {
259
- const maximize = this.controls.maximize;
260
- if (maximize) {
261
- maximize.title = isMaximized ? this.currentOptions.tooltips?.restoreDown : this.currentOptions.tooltips?.maximize;
262
- maximize.innerHTML = isMaximized ? this.platformIcons?.restore : this.platformIcons?.maximize;
263
- }
264
- if (this.resizer) {
265
- if (isMaximized) (0, _get__("dom_1").hide)(this.resizer.top, this.resizer.left);else (0, _get__("dom_1").show)(this.resizer.top, this.resizer.left);
266
- }
267
- }
268
- updateMenu(menu) {
269
- if (_get__("platform_1").isMacintosh || !menu) return;
270
- if (this.menuBar) this.menuBar.dispose();
271
- this.menuBar = new (_get__("menubar_1").MenuBar)(this.menuBarContainer, _get__("consts_1").menuIcons, this.currentOptions, {
272
- enableMnemonics: true
273
- }, this.closeMenu); // TODO: Verify menubar options
274
- this.menuBar.push(menu);
275
- this.menuBar.update();
276
- this.menuBar.onVisibilityChange(e => this.onMenuBarVisibilityChanged(e));
277
- this.menuBar.onFocusStateChange(e => this.onMenuBarFocusChanged(e));
278
- this.updateStyles();
279
- }
280
- updateStyles() {
281
- if (this.isInactive) {
282
- (0, _get__("dom_1").addClass)(this.titlebar, 'inactive');
283
- } else {
284
- (0, _get__("dom_1").removeClass)(this.titlebar, 'inactive');
285
- }
286
- const backgroundColor = this.isInactive && this.currentOptions.unfocusEffect ? this.currentOptions.backgroundColor?.lighten(0.12) : this.currentOptions.backgroundColor;
287
- if (backgroundColor) {
288
- this.titlebar.style.backgroundColor = backgroundColor?.toString();
289
- }
290
- let foregroundColor;
291
- if (backgroundColor?.isLighter()) {
292
- (0, _get__("dom_1").addClass)(this.titlebar, 'light');
293
- foregroundColor = this.isInactive && this.currentOptions.unfocusEffect ? _get__("consts_1").INACTIVE_FOREGROUND_DARK : _get__("consts_1").ACTIVE_FOREGROUND_DARK;
294
- } else {
295
- (0, _get__("dom_1").removeClass)(this.titlebar, 'light');
296
- foregroundColor = this.isInactive && this.currentOptions.unfocusEffect ? _get__("consts_1").INACTIVE_FOREGROUND : _get__("consts_1").ACTIVE_FOREGROUND;
297
- }
298
- this.titlebar.style.color = foregroundColor?.toString();
299
- const updatedWindowControls = _get__("electron_1").ipcRenderer.sendSync('update-window-controls', {
300
- color: backgroundColor?.toString(),
301
- symbolColor: foregroundColor?.toString(),
302
- height: _get__("consts_1").TOP_TITLEBAR_HEIGHT_WIN
303
- });
304
- if (updatedWindowControls) {
305
- (0, _get__("dom_1").hide)(this.controlsContainer);
306
- } else {
307
- (0, _get__("dom_1").show)(this.controlsContainer);
308
- }
309
- if (this.menuBar) {
310
- let fgColor;
311
- const backgroundColor = this.currentOptions.menuBarBackgroundColor || this.currentOptions.backgroundColor.darken(0.12);
312
- const foregroundColor = backgroundColor?.isLighter() ? _get__("consts_1").INACTIVE_FOREGROUND_DARK : _get__("consts_1").INACTIVE_FOREGROUND;
313
- const bgColor = this.currentOptions.itemBackgroundColor && !this.currentOptions.itemBackgroundColor.equals(backgroundColor) ? this.currentOptions.itemBackgroundColor : _get__("consts_1").DEFAULT_ITEM_SELECTOR;
314
- if (bgColor?.equals(_get__("consts_1").DEFAULT_ITEM_SELECTOR)) {
315
- fgColor = backgroundColor?.isLighter() ? _get__("consts_1").ACTIVE_FOREGROUND_DARK : _get__("consts_1").ACTIVE_FOREGROUND;
316
- } else {
317
- fgColor = bgColor?.isLighter() ? _get__("consts_1").ACTIVE_FOREGROUND_DARK : _get__("consts_1").ACTIVE_FOREGROUND;
318
- }
319
- this.menuBar.setStyles({
320
- backgroundColor,
321
- foregroundColor,
322
- selectionBackgroundColor: bgColor,
323
- selectionForegroundColor: fgColor,
324
- separatorColor: this.currentOptions.menuSeparatorColor ?? foregroundColor,
325
- svgColor: this.currentOptions.svgColor
326
- });
327
- }
328
- }
329
- canCenterTitle() {
330
- const menuBarContainerMargin = 20;
331
- const menuSpaceLimit = window.innerWidth / 2 - this.menuBarContainer.getBoundingClientRect().right - menuBarContainerMargin;
332
- return this.title.getBoundingClientRect().width / 2 <= menuSpaceLimit;
333
- }
334
- /// Public methods
335
- /**
336
- * Update title bar styles based on focus state.
337
- * @param hasFocus focus state of the window
338
- */
339
- onWindowFocus(focus) {
340
- if (this.titlebar) {
341
- if (focus) {
342
- (0, _get__("dom_1").removeClass)(this.titlebar, 'inactive');
343
- this.onFocus();
344
- } else {
345
- (0, _get__("dom_1").addClass)(this.titlebar, 'inactive');
346
- this.menuBar?.blur();
347
- this.onBlur();
348
- }
349
- }
350
- }
351
- /**
352
- * Update the full screen state and hide or show the title bar.
353
- * @param fullscreen Fullscreen state of the window
354
- */
355
- onWindowFullScreen(fullscreen) {
356
- const height = _get__("platform_1").isMacintosh ? _get__("consts_1").TOP_TITLEBAR_HEIGHT_MAC : _get__("consts_1").TOP_TITLEBAR_HEIGHT_WIN;
357
- const hasShadow = this.currentOptions.shadow;
358
- if (!_get__("platform_1").isMacintosh) {
359
- if (fullscreen) {
360
- (0, _get__("dom_1").hide)(this.titlebar);
361
- this.container.style.top = '0px';
362
- } else {
363
- (0, _get__("dom_1").show)(this.titlebar);
364
- if (this.currentOptions.menuPosition === 'bottom') {
365
- this.container.style.top = (0, _get__("consts_1").getPx)(_get__("consts_1").BOTTOM_TITLEBAR_HEIGHT);
366
- this.controlsContainer.style.height = (0, _get__("consts_1").getPx)(_get__("consts_1").TOP_TITLEBAR_HEIGHT_WIN);
367
- } else {
368
- this.container.style.top = (0, _get__("consts_1").getPx)(height + (hasShadow ? 1 : 0));
369
- }
370
- }
371
- }
372
- }
373
- /**
374
- * Update the title of the title bar.
375
- * You can use this method if change the content of `<title>` tag on your html.
376
- * @param title The title of the title bar and document.
377
- */
378
- updateTitle(title) {
379
- this.title.innerText = title;
380
- document.title = title;
381
- return this;
382
- }
383
- /**
384
- * It method set new icon to title-bar-icon of title-bar.
385
- * @param path path to icon
386
- */
387
- updateIcon(path) {
388
- if (this.icon) {
389
- this.icon.firstElementChild.setAttribute('src', path);
390
- }
391
- return this;
392
- }
393
- /**
394
- * Horizontal alignment of the title.
395
- * @param side `left`, `center` or `right`.
396
- */
397
- updateTitleAlignment(side) {
398
- const order = this.currentOptions.order;
399
- const menuPosition = this.currentOptions.menuPosition;
400
- if (side === 'left' || side === 'right' && order === 'inverted') {
401
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-left');
402
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-right');
403
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-center');
404
- (0, _get__("dom_1").addClass)(this.title, 'cet-title-left');
405
- }
406
- if (side === 'right' || side === 'left' && order === 'inverted') {
407
- if (side !== 'left' && order !== 'inverted') {
408
- this.controlsContainer.style.marginLeft = '10px';
409
- }
410
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-left');
411
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-right');
412
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-center');
413
- (0, _get__("dom_1").addClass)(this.title, 'cet-title-right');
414
- }
415
- if (side === 'center') {
416
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-left');
417
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-right');
418
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-center');
419
- if (menuPosition !== 'bottom') {
420
- (0, _get__("dom_1").addDisposableListener)(window, 'resize', () => {
421
- if (this.canCenterTitle()) {
422
- (0, _get__("dom_1").addClass)(this.title, 'cet-title-center');
423
- } else {
424
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-center');
425
- }
426
- });
427
- if (this.canCenterTitle()) {
428
- (0, _get__("dom_1").addClass)(this.title, 'cet-title-center');
429
- }
430
- }
431
- if (!_get__("platform_1").isMacintosh && order === 'first-buttons') {
432
- this.controlsContainer.style.marginLeft = 'auto';
433
- }
434
- this.title.style.maxWidth = 'calc(100% - 296px)';
435
- }
436
- return this;
437
- }
438
- /**
439
- * Update the background color of the title bar
440
- * @param backgroundColor The color for the background
441
- */
442
- updateBackground(backgroundColor) {
443
- if (typeof backgroundColor === 'string') backgroundColor = _get__("color_1").Color.fromHex(backgroundColor);
444
- this.currentOptions.backgroundColor = backgroundColor;
445
- this.updateStyles();
446
- return this;
447
- }
448
- /**
449
- * Update the item background color of the menubar
450
- * @param itemBGColor The color for the item background
451
- */
452
- updateItemBGColor(itemBGColor) {
453
- if (typeof itemBGColor === 'string') itemBGColor = _get__("color_1").Color.fromHex(itemBGColor);
454
- this.currentOptions.itemBackgroundColor = itemBGColor;
455
- this.updateStyles();
456
- return this;
457
- }
458
- /**
459
- * Update the menu from Menu.getApplicationMenu()
460
- */
461
- async refreshMenu() {
462
- if (!_get__("platform_1").isMacintosh) {
463
- _get__("electron_1").ipcRenderer.invoke('request-application-menu').then(menu => this.updateMenu(menu));
464
- }
465
- return this;
466
- }
467
- /**
468
- * Update the position of menubar.
469
- * @param menuPosition The position of the menu `left` or `bottom`.
470
- */
471
- updateMenuPosition(menuPosition) {
472
- const height = _get__("platform_1").isMacintosh ? _get__("consts_1").TOP_TITLEBAR_HEIGHT_MAC : _get__("consts_1").TOP_TITLEBAR_HEIGHT_WIN;
473
- const onlyRendererMenuBar = this.currentOptions.onlyShowMenuBar;
474
- const hasShadow = this.currentOptions.shadow;
475
- this.currentOptions.menuPosition = menuPosition;
476
- if (menuPosition === 'left' || onlyRendererMenuBar) {
477
- this.titlebar.style.height = (0, _get__("consts_1").getPx)(height + (hasShadow ? 1 : 0));
478
- this.container.style.top = (0, _get__("consts_1").getPx)(height + (hasShadow ? 1 : 0));
479
- (0, _get__("dom_1").removeClass)(this.menuBarContainer, 'bottom');
480
- } else {
481
- this.titlebar.style.height = (0, _get__("consts_1").getPx)(_get__("consts_1").BOTTOM_TITLEBAR_HEIGHT);
482
- this.container.style.top = (0, _get__("consts_1").getPx)(_get__("consts_1").BOTTOM_TITLEBAR_HEIGHT);
483
- this.controlsContainer.style.height = (0, _get__("consts_1").getPx)(height);
484
- (0, _get__("dom_1").addClass)(this.menuBarContainer, 'bottom');
485
- }
486
- return this;
487
- }
488
- /**
489
- * Remove the titlebar, menubar and all methods.
490
- */
491
- dispose() {
492
- // if (this.menuBar) this.menuBar.dispose()
493
- this.titlebar.remove();
494
- while (this.container.firstChild) (0, _get__("dom_1").append)(document.body, this.container.firstChild);
495
- this.container.remove();
496
- }
497
- get titlebarElement() {
498
- return this.titlebar;
499
- }
500
- get menubarElement() {
501
- return this.menuBar;
502
- }
503
- get containerElement() {
504
- return this.container;
505
- }
506
- get titleElement() {
507
- return this.title;
508
- }
509
- }
510
- exports.CustomTitlebar = _get__("CustomTitlebar");
511
- function _getGlobalObject() {
512
- try {
513
- if (!!global) {
514
- return global;
515
- }
516
- } catch (e) {
517
- try {
518
- if (!!window) {
519
- return window;
520
- }
521
- } catch (e) {
522
- return this;
523
- }
524
- }
525
- }
526
- ;
527
- var _RewireModuleId__ = null;
528
- function _getRewireModuleId__() {
529
- if (_RewireModuleId__ === null) {
530
- let globalVariable = _getGlobalObject();
531
- if (!globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__) {
532
- globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__ = 0;
533
- }
534
- _RewireModuleId__ = __$$GLOBAL_REWIRE_NEXT_MODULE_ID__++;
535
- }
536
- return _RewireModuleId__;
537
- }
538
- function _getRewireRegistry__() {
539
- let theGlobalVariable = _getGlobalObject();
540
- if (!theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__) {
541
- theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
542
- }
543
- return theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__;
544
- }
545
- function _getRewiredData__() {
546
- let moduleId = _getRewireModuleId__();
547
- let registry = _getRewireRegistry__();
548
- let rewireData = registry[moduleId];
549
- if (!rewireData) {
550
- registry[moduleId] = Object.create(null);
551
- rewireData = registry[moduleId];
552
- }
553
- return rewireData;
554
- }
555
- (function registerResetAll() {
556
- let theGlobalVariable = _getGlobalObject();
557
- if (!theGlobalVariable['__rewire_reset_all__']) {
558
- theGlobalVariable['__rewire_reset_all__'] = function () {
559
- theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
560
- };
561
- }
562
- })();
563
- var INTENTIONAL_UNDEFINED = '__INTENTIONAL_UNDEFINED__';
564
- let _RewireAPI__ = {};
565
- (function () {
566
- function addPropertyToAPIObject(name, value) {
567
- Object.defineProperty(_RewireAPI__, name, {
568
- value: value,
569
- enumerable: false,
570
- configurable: true
571
- });
572
- }
573
- addPropertyToAPIObject('__get__', _get__);
574
- addPropertyToAPIObject('__GetDependency__', _get__);
575
- addPropertyToAPIObject('__Rewire__', _set__);
576
- addPropertyToAPIObject('__set__', _set__);
577
- addPropertyToAPIObject('__reset__', _reset__);
578
- addPropertyToAPIObject('__ResetDependency__', _reset__);
579
- addPropertyToAPIObject('__with__', _with__);
580
- })();
581
- function _get__(variableName) {
582
- let rewireData = _getRewiredData__();
583
- if (rewireData[variableName] === undefined) {
584
- return _get_original__(variableName);
585
- } else {
586
- var value = rewireData[variableName];
587
- if (value === INTENTIONAL_UNDEFINED) {
588
- return undefined;
589
- } else {
590
- return value;
591
- }
592
- }
593
- }
594
- function _get_original__(variableName) {
595
- switch (variableName) {
596
- case "consts_1":
597
- return consts_1;
598
- case "platform_1":
599
- return platform_1;
600
- case "dom_1":
601
- return dom_1;
602
- case "color_1":
603
- return color_1;
604
- case "electron_1":
605
- return electron_1;
606
- case "menubar_1":
607
- return menubar_1;
608
- case "themebar_1":
609
- return themebar_1;
610
- case "CustomTitlebar":
611
- return CustomTitlebar;
612
- }
613
- return undefined;
614
- }
615
- function _assign__(variableName, value) {
616
- let rewireData = _getRewiredData__();
617
- if (rewireData[variableName] === undefined) {
618
- return _set_original__(variableName, value);
619
- } else {
620
- return rewireData[variableName] = value;
621
- }
622
- }
623
- function _set_original__(variableName, _value) {
624
- switch (variableName) {}
625
- return undefined;
626
- }
627
- function _update_operation__(operation, variableName, prefix) {
628
- var oldValue = _get__(variableName);
629
- var newValue = operation === '++' ? oldValue + 1 : oldValue - 1;
630
- _assign__(variableName, newValue);
631
- return prefix ? newValue : oldValue;
632
- }
633
- function _set__(variableName, value) {
634
- let rewireData = _getRewiredData__();
635
- if (typeof variableName === 'object') {
636
- Object.keys(variableName).forEach(function (name) {
637
- rewireData[name] = variableName[name];
638
- });
639
- return function () {
640
- Object.keys(variableName).forEach(function (name) {
641
- _reset__(variableName);
642
- });
643
- };
644
- } else {
645
- if (value === undefined) {
646
- rewireData[variableName] = INTENTIONAL_UNDEFINED;
647
- } else {
648
- rewireData[variableName] = value;
649
- }
650
- return function () {
651
- _reset__(variableName);
652
- };
653
- }
654
- }
655
- function _reset__(variableName) {
656
- let rewireData = _getRewiredData__();
657
- delete rewireData[variableName];
658
- if (Object.keys(rewireData).length == 0) {
659
- delete _getRewireRegistry__()[_getRewireModuleId__];
660
- }
661
- ;
662
- }
663
- function _with__(object) {
664
- let rewireData = _getRewiredData__();
665
- var rewiredVariableNames = Object.keys(object);
666
- var previousValues = {};
667
- function reset() {
668
- rewiredVariableNames.forEach(function (variableName) {
669
- rewireData[variableName] = previousValues[variableName];
670
- });
671
- }
672
- return function (callback) {
673
- rewiredVariableNames.forEach(function (variableName) {
674
- previousValues[variableName] = rewireData[variableName];
675
- rewireData[variableName] = object[variableName];
676
- });
677
- let result = callback();
678
- if (!!result && typeof result.then == 'function') {
679
- result.then(reset).catch(reset);
680
- } else {
681
- reset();
682
- }
683
- return result;
684
- };
685
- }
686
- let _typeOfOriginalExport = typeof module.exports;
687
- function addNonEnumerableProperty(name, value) {
688
- Object.defineProperty(module.exports, name, {
689
- value: value,
690
- enumerable: false,
691
- configurable: true
692
- });
693
- }
694
- if ((_typeOfOriginalExport === 'object' || _typeOfOriginalExport === 'function') && Object.isExtensible(module.exports)) {
695
- addNonEnumerableProperty('__get__', _get__);
696
- addNonEnumerableProperty('__GetDependency__', _get__);
697
- addNonEnumerableProperty('__Rewire__', _set__);
698
- addNonEnumerableProperty('__set__', _set__);
699
- addNonEnumerableProperty('__reset__', _reset__);
700
- addNonEnumerableProperty('__ResetDependency__', _reset__);
701
- addNonEnumerableProperty('__with__', _with__);
702
- addNonEnumerableProperty('__RewireAPI__', _RewireAPI__);
703
- }