custom-electron-titlebar 4.2.7 → 4.4.0

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 (77) hide show
  1. package/README.md +43 -19
  2. package/index.d.mts +684 -0
  3. package/index.d.ts +684 -3
  4. package/index.js +5225 -175
  5. package/index.js.map +1 -0
  6. package/index.mjs +5227 -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 +56 -33
  15. package/theme/base.css +425 -0
  16. package/theme/mac.css +0 -0
  17. package/theme/win.css +0 -0
  18. package/base/browser/browser.d.ts +0 -26
  19. package/base/browser/browser.js +0 -317
  20. package/base/browser/event.d.ts +0 -12
  21. package/base/browser/event.js +0 -215
  22. package/base/browser/keyboardEvent.d.ts +0 -38
  23. package/base/browser/keyboardEvent.js +0 -464
  24. package/base/browser/mouseEvent.d.ts +0 -61
  25. package/base/browser/mouseEvent.js +0 -327
  26. package/base/browser/touch.d.ts +0 -39
  27. package/base/browser/touch.js +0 -454
  28. package/base/common/arrays.d.ts +0 -10
  29. package/base/common/arrays.js +0 -210
  30. package/base/common/async.d.ts +0 -35
  31. package/base/common/async.js +0 -280
  32. package/base/common/charCode.d.ts +0 -405
  33. package/base/common/charCode.js +0 -9
  34. package/base/common/color.d.ts +0 -159
  35. package/base/common/color.js +0 -708
  36. package/base/common/decorators.d.ts +0 -6
  37. package/base/common/decorators.js +0 -300
  38. package/base/common/dom.d.ts +0 -221
  39. package/base/common/dom.js +0 -1478
  40. package/base/common/event.d.ts +0 -213
  41. package/base/common/event.js +0 -804
  42. package/base/common/iterator.d.ts +0 -69
  43. package/base/common/iterator.js +0 -381
  44. package/base/common/keyCodes.d.ts +0 -478
  45. package/base/common/keyCodes.js +0 -479
  46. package/base/common/lifecycle.d.ts +0 -17
  47. package/base/common/lifecycle.js +0 -258
  48. package/base/common/linkedList.d.ts +0 -17
  49. package/base/common/linkedList.js +0 -319
  50. package/base/common/platform.d.ts +0 -36
  51. package/base/common/platform.js +0 -314
  52. package/base/common/strings.d.ts +0 -23
  53. package/base/common/strings.js +0 -273
  54. package/consts.d.ts +0 -58
  55. package/consts.js +0 -317
  56. package/main/attach-titlebar-to-window.d.ts +0 -3
  57. package/main/attach-titlebar-to-window.js +0 -210
  58. package/main/setup-titlebar.d.ts +0 -2
  59. package/main/setup-titlebar.js +0 -255
  60. package/menubar/index.d.ts +0 -86
  61. package/menubar/index.js +0 -1121
  62. package/menubar/menu/index.d.ts +0 -46
  63. package/menubar/menu/index.js +0 -566
  64. package/menubar/menu/item.d.ts +0 -67
  65. package/menubar/menu/item.js +0 -575
  66. package/menubar/menu/separator.d.ts +0 -11
  67. package/menubar/menu/separator.js +0 -213
  68. package/menubar/menu/submenu.d.ts +0 -32
  69. package/menubar/menu/submenu.js +0 -372
  70. package/menubar/menubar-options.d.ts +0 -47
  71. package/menubar/menubar-options.js +0 -9
  72. package/titlebar/index.d.ts +0 -104
  73. package/titlebar/index.js +0 -696
  74. package/titlebar/options.d.ts +0 -84
  75. package/titlebar/options.js +0 -9
  76. package/titlebar/themebar.d.ts +0 -20
  77. package/titlebar/themebar.js +0 -267
package/titlebar/index.js DELETED
@@ -1,696 +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
- };
46
- // TODO: Refactor, verify if is possible use into menubar
47
- this.closeMenu = () => {
48
- if (this.menuBar) {
49
- this.menuBar.blur();
50
- }
51
- };
52
- this.currentOptions = {
53
- ...this.currentOptions,
54
- ...options
55
- };
56
- const jWindowIcons = _get__("consts_1").menuIcons[(0, _get__("platform_1").PlatformToString)(_get__("platform_1").platform)?.toLocaleLowerCase()];
57
- this.platformIcons = jWindowIcons;
58
- this.titlebar = (0, _get__("dom_1").$)('.cet-titlebar');
59
- this.dragRegion = (0, _get__("dom_1").$)('.cet-drag-region');
60
- this.icon = (0, _get__("dom_1").$)('.cet-icon');
61
- this.menuBarContainer = (0, _get__("dom_1").$)('.cet-menubar');
62
- this.title = (0, _get__("dom_1").$)('.cet-title');
63
- this.controlsContainer = (0, _get__("dom_1").$)('.cet-window-controls');
64
- this.container = (0, _get__("dom_1").$)('.cet-container');
65
- this.controls = {
66
- minimize: (0, _get__("dom_1").$)('.cet-control-minimize'),
67
- maximize: (0, _get__("dom_1").$)('.cet-control-maximize'),
68
- close: (0, _get__("dom_1").$)('.cet-control-close')
69
- };
70
- this.resizer = {
71
- top: (0, _get__("dom_1").$)('.cet-resizer.top'),
72
- left: (0, _get__("dom_1").$)('.cet-resizer.left')
73
- };
74
- (0, _get__("dom_1").append)(this.titlebar, this.dragRegion);
75
- (0, _get__("dom_1").append)(this.titlebar, this.resizer.left);
76
- (0, _get__("dom_1").append)(this.titlebar, this.resizer.top);
77
- this.loadIcons();
78
- this.setupBackgroundColor();
79
- this.createIcon();
80
- this.setupMenubar();
81
- this.setupTitle();
82
- this.setupWindowControls();
83
- this.setupContainer();
84
- this.setupTitleBar();
85
- this.loadEvents();
86
- // this.registerTheme(ThemeBar.win)
87
- }
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.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 ? _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 ? _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
- /// Public methods
330
- /**
331
- * Update title bar styles based on focus state.
332
- * @param hasFocus focus state of the window
333
- */
334
- onWindowFocus(focus) {
335
- if (this.titlebar) {
336
- if (focus) {
337
- (0, _get__("dom_1").removeClass)(this.titlebar, 'inactive');
338
- this.onFocus();
339
- } else {
340
- (0, _get__("dom_1").addClass)(this.titlebar, 'inactive');
341
- this.menuBar?.blur();
342
- this.onBlur();
343
- }
344
- }
345
- }
346
- /**
347
- * Update the full screen state and hide or show the title bar.
348
- * @param fullscreen Fullscreen state of the window
349
- */
350
- onWindowFullScreen(fullscreen) {
351
- const height = _get__("platform_1").isMacintosh ? _get__("consts_1").TOP_TITLEBAR_HEIGHT_MAC : _get__("consts_1").TOP_TITLEBAR_HEIGHT_WIN;
352
- const hasShadow = this.currentOptions.shadow;
353
- if (!_get__("platform_1").isMacintosh) {
354
- if (fullscreen) {
355
- (0, _get__("dom_1").hide)(this.titlebar);
356
- this.container.style.top = '0px';
357
- } else {
358
- (0, _get__("dom_1").show)(this.titlebar);
359
- if (this.currentOptions.menuPosition === 'bottom') {
360
- this.container.style.top = (0, _get__("consts_1").getPx)(_get__("consts_1").BOTTOM_TITLEBAR_HEIGHT);
361
- this.controlsContainer.style.height = (0, _get__("consts_1").getPx)(_get__("consts_1").TOP_TITLEBAR_HEIGHT_WIN);
362
- } else {
363
- this.container.style.top = (0, _get__("consts_1").getPx)(height + (hasShadow ? 1 : 0));
364
- }
365
- }
366
- }
367
- }
368
- /**
369
- * Update the title of the title bar.
370
- * You can use this method if change the content of `<title>` tag on your html.
371
- * @param title The title of the title bar and document.
372
- */
373
- updateTitle(title) {
374
- this.title.innerText = title;
375
- document.title = title;
376
- return this;
377
- }
378
- /**
379
- * It method set new icon to title-bar-icon of title-bar.
380
- * @param path path to icon
381
- */
382
- updateIcon(path) {
383
- if (this.icon) {
384
- this.icon.firstElementChild.setAttribute('src', path);
385
- }
386
- return this;
387
- }
388
- /**
389
- * Horizontal alignment of the title.
390
- * @param side `left`, `center` or `right`.
391
- */
392
- updateTitleAlignment(side) {
393
- const order = this.currentOptions.order;
394
- const menuPosition = this.currentOptions.menuPosition;
395
- if (side === 'left' || side === 'right' && order === 'inverted') {
396
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-left');
397
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-right');
398
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-center');
399
- (0, _get__("dom_1").addClass)(this.title, 'cet-title-left');
400
- }
401
- if (side === 'right' || side === 'left' && order === 'inverted') {
402
- if (side !== 'left' && order !== 'inverted') {
403
- this.controlsContainer.style.marginLeft = '10px';
404
- }
405
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-left');
406
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-right');
407
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-center');
408
- (0, _get__("dom_1").addClass)(this.title, 'cet-title-right');
409
- }
410
- if (side === 'center') {
411
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-left');
412
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-right');
413
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-center');
414
- if (menuPosition !== 'bottom') {
415
- (0, _get__("dom_1").addDisposableListener)(window, 'resize', () => {
416
- if (window.innerWidth >= 1188) {
417
- (0, _get__("dom_1").addClass)(this.title, 'cet-title-center');
418
- } else {
419
- (0, _get__("dom_1").removeClass)(this.title, 'cet-title-center');
420
- }
421
- });
422
- (0, _get__("dom_1").addClass)(this.title, 'cet-title-center');
423
- }
424
- if (!_get__("platform_1").isMacintosh && order === 'first-buttons') {
425
- this.controlsContainer.style.marginLeft = 'auto';
426
- }
427
- this.title.style.maxWidth = 'calc(100% - 296px)';
428
- }
429
- return this;
430
- }
431
- /**
432
- * Update the background color of the title bar
433
- * @param backgroundColor The color for the background
434
- */
435
- updateBackground(backgroundColor) {
436
- if (typeof backgroundColor === 'string') backgroundColor = _get__("color_1").Color.fromHex(backgroundColor);
437
- this.currentOptions.backgroundColor = backgroundColor;
438
- this.updateStyles();
439
- return this;
440
- }
441
- /**
442
- * Update the item background color of the menubar
443
- * @param itemBGColor The color for the item background
444
- */
445
- updateItemBGColor(itemBGColor) {
446
- if (typeof itemBGColor === 'string') itemBGColor = _get__("color_1").Color.fromHex(itemBGColor);
447
- this.currentOptions.itemBackgroundColor = itemBGColor;
448
- this.updateStyles();
449
- return this;
450
- }
451
- /**
452
- * Update the menu from Menu.getApplicationMenu()
453
- */
454
- async refreshMenu() {
455
- if (!_get__("platform_1").isMacintosh) {
456
- _get__("electron_1").ipcRenderer.invoke('request-application-menu').then(menu => this.updateMenu(menu));
457
- }
458
- return this;
459
- }
460
- /**
461
- * Update the position of menubar.
462
- * @param menuPosition The position of the menu `left` or `bottom`.
463
- */
464
- updateMenuPosition(menuPosition) {
465
- const height = _get__("platform_1").isMacintosh ? _get__("consts_1").TOP_TITLEBAR_HEIGHT_MAC : _get__("consts_1").TOP_TITLEBAR_HEIGHT_WIN;
466
- const onlyRendererMenuBar = this.currentOptions.onlyShowMenuBar;
467
- const hasShadow = this.currentOptions.shadow;
468
- this.currentOptions.menuPosition = menuPosition;
469
- if (menuPosition === 'left' || onlyRendererMenuBar) {
470
- this.titlebar.style.height = (0, _get__("consts_1").getPx)(height + (hasShadow ? 1 : 0));
471
- this.container.style.top = (0, _get__("consts_1").getPx)(height + (hasShadow ? 1 : 0));
472
- (0, _get__("dom_1").removeClass)(this.menuBarContainer, 'bottom');
473
- } else {
474
- this.titlebar.style.height = (0, _get__("consts_1").getPx)(_get__("consts_1").BOTTOM_TITLEBAR_HEIGHT);
475
- this.container.style.top = (0, _get__("consts_1").getPx)(_get__("consts_1").BOTTOM_TITLEBAR_HEIGHT);
476
- this.controlsContainer.style.height = (0, _get__("consts_1").getPx)(height);
477
- (0, _get__("dom_1").addClass)(this.menuBarContainer, 'bottom');
478
- }
479
- return this;
480
- }
481
- /**
482
- * Remove the titlebar, menubar and all methods.
483
- */
484
- dispose() {
485
- // if (this.menuBar) this.menuBar.dispose()
486
- this.titlebar.remove();
487
- while (this.container.firstChild) (0, _get__("dom_1").append)(document.body, this.container.firstChild);
488
- this.container.remove();
489
- }
490
- get titlebarElement() {
491
- return this.titlebar;
492
- }
493
- get menubarElement() {
494
- return this.menuBar;
495
- }
496
- get containerElement() {
497
- return this.container;
498
- }
499
- get titleElement() {
500
- return this.title;
501
- }
502
- }
503
- exports.CustomTitlebar = _get__("CustomTitlebar");
504
- function _getGlobalObject() {
505
- try {
506
- if (!!global) {
507
- return global;
508
- }
509
- } catch (e) {
510
- try {
511
- if (!!window) {
512
- return window;
513
- }
514
- } catch (e) {
515
- return this;
516
- }
517
- }
518
- }
519
- ;
520
- var _RewireModuleId__ = null;
521
- function _getRewireModuleId__() {
522
- if (_RewireModuleId__ === null) {
523
- let globalVariable = _getGlobalObject();
524
- if (!globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__) {
525
- globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__ = 0;
526
- }
527
- _RewireModuleId__ = __$$GLOBAL_REWIRE_NEXT_MODULE_ID__++;
528
- }
529
- return _RewireModuleId__;
530
- }
531
- function _getRewireRegistry__() {
532
- let theGlobalVariable = _getGlobalObject();
533
- if (!theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__) {
534
- theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
535
- }
536
- return theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__;
537
- }
538
- function _getRewiredData__() {
539
- let moduleId = _getRewireModuleId__();
540
- let registry = _getRewireRegistry__();
541
- let rewireData = registry[moduleId];
542
- if (!rewireData) {
543
- registry[moduleId] = Object.create(null);
544
- rewireData = registry[moduleId];
545
- }
546
- return rewireData;
547
- }
548
- (function registerResetAll() {
549
- let theGlobalVariable = _getGlobalObject();
550
- if (!theGlobalVariable['__rewire_reset_all__']) {
551
- theGlobalVariable['__rewire_reset_all__'] = function () {
552
- theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);
553
- };
554
- }
555
- })();
556
- var INTENTIONAL_UNDEFINED = '__INTENTIONAL_UNDEFINED__';
557
- let _RewireAPI__ = {};
558
- (function () {
559
- function addPropertyToAPIObject(name, value) {
560
- Object.defineProperty(_RewireAPI__, name, {
561
- value: value,
562
- enumerable: false,
563
- configurable: true
564
- });
565
- }
566
- addPropertyToAPIObject('__get__', _get__);
567
- addPropertyToAPIObject('__GetDependency__', _get__);
568
- addPropertyToAPIObject('__Rewire__', _set__);
569
- addPropertyToAPIObject('__set__', _set__);
570
- addPropertyToAPIObject('__reset__', _reset__);
571
- addPropertyToAPIObject('__ResetDependency__', _reset__);
572
- addPropertyToAPIObject('__with__', _with__);
573
- })();
574
- function _get__(variableName) {
575
- let rewireData = _getRewiredData__();
576
- if (rewireData[variableName] === undefined) {
577
- return _get_original__(variableName);
578
- } else {
579
- var value = rewireData[variableName];
580
- if (value === INTENTIONAL_UNDEFINED) {
581
- return undefined;
582
- } else {
583
- return value;
584
- }
585
- }
586
- }
587
- function _get_original__(variableName) {
588
- switch (variableName) {
589
- case "consts_1":
590
- return consts_1;
591
- case "platform_1":
592
- return platform_1;
593
- case "dom_1":
594
- return dom_1;
595
- case "color_1":
596
- return color_1;
597
- case "electron_1":
598
- return electron_1;
599
- case "menubar_1":
600
- return menubar_1;
601
- case "themebar_1":
602
- return themebar_1;
603
- case "CustomTitlebar":
604
- return CustomTitlebar;
605
- }
606
- return undefined;
607
- }
608
- function _assign__(variableName, value) {
609
- let rewireData = _getRewiredData__();
610
- if (rewireData[variableName] === undefined) {
611
- return _set_original__(variableName, value);
612
- } else {
613
- return rewireData[variableName] = value;
614
- }
615
- }
616
- function _set_original__(variableName, _value) {
617
- switch (variableName) {}
618
- return undefined;
619
- }
620
- function _update_operation__(operation, variableName, prefix) {
621
- var oldValue = _get__(variableName);
622
- var newValue = operation === '++' ? oldValue + 1 : oldValue - 1;
623
- _assign__(variableName, newValue);
624
- return prefix ? newValue : oldValue;
625
- }
626
- function _set__(variableName, value) {
627
- let rewireData = _getRewiredData__();
628
- if (typeof variableName === 'object') {
629
- Object.keys(variableName).forEach(function (name) {
630
- rewireData[name] = variableName[name];
631
- });
632
- return function () {
633
- Object.keys(variableName).forEach(function (name) {
634
- _reset__(variableName);
635
- });
636
- };
637
- } else {
638
- if (value === undefined) {
639
- rewireData[variableName] = INTENTIONAL_UNDEFINED;
640
- } else {
641
- rewireData[variableName] = value;
642
- }
643
- return function () {
644
- _reset__(variableName);
645
- };
646
- }
647
- }
648
- function _reset__(variableName) {
649
- let rewireData = _getRewiredData__();
650
- delete rewireData[variableName];
651
- if (Object.keys(rewireData).length == 0) {
652
- delete _getRewireRegistry__()[_getRewireModuleId__];
653
- }
654
- ;
655
- }
656
- function _with__(object) {
657
- let rewireData = _getRewiredData__();
658
- var rewiredVariableNames = Object.keys(object);
659
- var previousValues = {};
660
- function reset() {
661
- rewiredVariableNames.forEach(function (variableName) {
662
- rewireData[variableName] = previousValues[variableName];
663
- });
664
- }
665
- return function (callback) {
666
- rewiredVariableNames.forEach(function (variableName) {
667
- previousValues[variableName] = rewireData[variableName];
668
- rewireData[variableName] = object[variableName];
669
- });
670
- let result = callback();
671
- if (!!result && typeof result.then == 'function') {
672
- result.then(reset).catch(reset);
673
- } else {
674
- reset();
675
- }
676
- return result;
677
- };
678
- }
679
- let _typeOfOriginalExport = typeof module.exports;
680
- function addNonEnumerableProperty(name, value) {
681
- Object.defineProperty(module.exports, name, {
682
- value: value,
683
- enumerable: false,
684
- configurable: true
685
- });
686
- }
687
- if ((_typeOfOriginalExport === 'object' || _typeOfOriginalExport === 'function') && Object.isExtensible(module.exports)) {
688
- addNonEnumerableProperty('__get__', _get__);
689
- addNonEnumerableProperty('__GetDependency__', _get__);
690
- addNonEnumerableProperty('__Rewire__', _set__);
691
- addNonEnumerableProperty('__set__', _set__);
692
- addNonEnumerableProperty('__reset__', _reset__);
693
- addNonEnumerableProperty('__ResetDependency__', _reset__);
694
- addNonEnumerableProperty('__with__', _with__);
695
- addNonEnumerableProperty('__RewireAPI__', _RewireAPI__);
696
- }