custom-electron-titlebar 3.2.9 → 4.0.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.
- package/README.md +10 -203
- package/{build → dist}/browser/browser.d.ts +0 -0
- package/{build → dist}/browser/event.d.ts +0 -0
- package/{build → dist}/browser/iframe.d.ts +0 -0
- package/{build → dist}/browser/keyboardEvent.d.ts +0 -0
- package/{build → dist}/browser/mouseEvent.d.ts +0 -0
- package/{build → dist}/common/arrays.d.ts +0 -0
- package/{build → dist}/common/async.d.ts +0 -0
- package/{build → dist}/common/charCode.d.ts +0 -0
- package/{build → dist}/common/color.d.ts +0 -0
- package/{build → dist}/common/dom.d.ts +0 -0
- package/{build → dist}/common/event.d.ts +0 -0
- package/{build → dist}/common/iterator.d.ts +0 -0
- package/{build → dist}/common/keyCodes.d.ts +0 -0
- package/{build → dist}/common/lifecycle.d.ts +0 -0
- package/{build → dist}/common/linkedList.d.ts +0 -0
- package/{build → dist}/common/platform.d.ts +0 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1 -0
- package/dist/interfaces.d.ts +95 -0
- package/{build → dist}/menu/menu.d.ts +3 -1
- package/{build → dist}/menu/menuitem.d.ts +3 -4
- package/{build → dist}/menubar.d.ts +1 -24
- package/dist/titlebar.d.ts +77 -0
- package/package.json +23 -16
- package/webpack.config.js +37 -0
- package/.github/ISSUE_TEMPLATE/issue-report.md +0 -29
- package/.vscode/launch.json +0 -49
- package/.vscode/tasks.json +0 -34
- package/build/browser/browser.js +0 -157
- package/build/browser/browser.js.map +0 -1
- package/build/browser/event.js +0 -30
- package/build/browser/event.js.map +0 -1
- package/build/browser/iframe.js +0 -110
- package/build/browser/iframe.js.map +0 -1
- package/build/browser/keyboardEvent.js +0 -226
- package/build/browser/keyboardEvent.js.map +0 -1
- package/build/browser/mouseEvent.js +0 -110
- package/build/browser/mouseEvent.js.map +0 -1
- package/build/common/arrays.js +0 -18
- package/build/common/arrays.js.map +0 -1
- package/build/common/async.js +0 -95
- package/build/common/async.js.map +0 -1
- package/build/common/charCode.js +0 -7
- package/build/common/charCode.js.map +0 -1
- package/build/common/color.js +0 -494
- package/build/common/color.js.map +0 -1
- package/build/common/dom.js +0 -984
- package/build/common/dom.js.map +0 -1
- package/build/common/event.js +0 -611
- package/build/common/event.js.map +0 -1
- package/build/common/iterator.js +0 -164
- package/build/common/iterator.js.map +0 -1
- package/build/common/keyCodes.js +0 -268
- package/build/common/keyCodes.js.map +0 -1
- package/build/common/lifecycle.js +0 -63
- package/build/common/lifecycle.js.map +0 -1
- package/build/common/linkedList.js +0 -139
- package/build/common/linkedList.js.map +0 -1
- package/build/common/platform.js +0 -115
- package/build/common/platform.js.map +0 -1
- package/build/index.d.ts +0 -3
- package/build/index.js +0 -20
- package/build/index.js.map +0 -1
- package/build/menu/menu.js +0 -538
- package/build/menu/menu.js.map +0 -1
- package/build/menu/menuitem.js +0 -339
- package/build/menu/menuitem.js.map +0 -1
- package/build/menubar.js +0 -608
- package/build/menubar.js.map +0 -1
- package/build/themebar.d.ts +0 -20
- package/build/themebar.js +0 -568
- package/build/themebar.js.map +0 -1
- package/build/titlebar.d.ts +0 -135
- package/build/titlebar.js +0 -453
- package/build/titlebar.js.map +0 -1
package/build/common/dom.js
DELETED
|
@@ -1,984 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.getElementsByTagName = exports.removeTabIndexAndUpdateFocus = exports.hide = exports.show = exports.join = exports.$ = exports.prepend = exports.append = exports.trackFocus = exports.restoreParentsScrollTop = exports.saveParentsScrollTop = exports.EventHelper = exports.EventType = exports.isHTMLElement = exports.removeCSSRulesContainingSelector = exports.createCSSRule = exports.createStyleSheet = exports.findParentWithClass = exports.isAncestor = exports.getLargestChildWidth = exports.getTotalHeight = exports.getContentHeight = exports.getTotalScrollWidth = exports.getContentWidth = exports.getTotalWidth = exports.StandardWindow = exports.getDomNodePagePosition = exports.position = exports.size = exports.getTopLeftOffset = exports.Dimension = exports.getClientArea = exports.getComputedStyle = exports.addDisposableThrottledListener = exports.modify = exports.measure = exports.scheduleAtNextAnimationFrame = exports.runAtThisOrScheduleAtNextAnimationFrame = exports.addDisposableNonBubblingMouseOutListener = exports.addStandardDisposableListener = exports.addDisposableListener = exports.toggleClass = exports.removeClasses = exports.removeClass = exports.addClasses = exports.addClass = exports.hasClass = exports.isInDOM = exports.removeNode = exports.clearNode = void 0;
|
|
8
|
-
exports.animate = exports.windowOpenNoOpener = exports.computeScreenAwareSize = exports.domContentLoaded = exports.finalHandler = void 0;
|
|
9
|
-
const browser = require("../browser/browser");
|
|
10
|
-
const event_1 = require("../browser/event");
|
|
11
|
-
const keyboardEvent_1 = require("../browser/keyboardEvent");
|
|
12
|
-
const mouseEvent_1 = require("../browser/mouseEvent");
|
|
13
|
-
const async_1 = require("./async");
|
|
14
|
-
const event_2 = require("./event");
|
|
15
|
-
const lifecycle_1 = require("./lifecycle");
|
|
16
|
-
const platform = require("./platform");
|
|
17
|
-
const arrays_1 = require("./arrays");
|
|
18
|
-
function clearNode(node) {
|
|
19
|
-
while (node.firstChild) {
|
|
20
|
-
node.removeChild(node.firstChild);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.clearNode = clearNode;
|
|
24
|
-
function removeNode(node) {
|
|
25
|
-
if (node.parentNode) {
|
|
26
|
-
node.parentNode.removeChild(node);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.removeNode = removeNode;
|
|
30
|
-
function isInDOM(node) {
|
|
31
|
-
while (node) {
|
|
32
|
-
if (node === document.body) {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
node = node.parentNode;
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
exports.isInDOM = isInDOM;
|
|
40
|
-
const _manualClassList = new class {
|
|
41
|
-
_findClassName(node, className) {
|
|
42
|
-
let classes = node.className;
|
|
43
|
-
if (!classes) {
|
|
44
|
-
this._lastStart = -1;
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
className = className.trim();
|
|
48
|
-
let classesLen = classes.length, classLen = className.length;
|
|
49
|
-
if (classLen === 0) {
|
|
50
|
-
this._lastStart = -1;
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (classesLen < classLen) {
|
|
54
|
-
this._lastStart = -1;
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (classes === className) {
|
|
58
|
-
this._lastStart = 0;
|
|
59
|
-
this._lastEnd = classesLen;
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
let idx = -1, idxEnd;
|
|
63
|
-
while ((idx = classes.indexOf(className, idx + 1)) >= 0) {
|
|
64
|
-
idxEnd = idx + classLen;
|
|
65
|
-
// a class that is followed by another class
|
|
66
|
-
if ((idx === 0 || classes.charCodeAt(idx - 1) === 32 /* Space */) && classes.charCodeAt(idxEnd) === 32 /* Space */) {
|
|
67
|
-
this._lastStart = idx;
|
|
68
|
-
this._lastEnd = idxEnd + 1;
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
// last class
|
|
72
|
-
if (idx > 0 && classes.charCodeAt(idx - 1) === 32 /* Space */ && idxEnd === classesLen) {
|
|
73
|
-
this._lastStart = idx - 1;
|
|
74
|
-
this._lastEnd = idxEnd;
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
// equal - duplicate of cmp above
|
|
78
|
-
if (idx === 0 && idxEnd === classesLen) {
|
|
79
|
-
this._lastStart = 0;
|
|
80
|
-
this._lastEnd = idxEnd;
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
this._lastStart = -1;
|
|
85
|
-
}
|
|
86
|
-
hasClass(node, className) {
|
|
87
|
-
this._findClassName(node, className);
|
|
88
|
-
return this._lastStart !== -1;
|
|
89
|
-
}
|
|
90
|
-
addClasses(node, ...classNames) {
|
|
91
|
-
classNames.forEach(nameValue => nameValue.split(' ').forEach(name => this.addClass(node, name)));
|
|
92
|
-
}
|
|
93
|
-
addClass(node, className) {
|
|
94
|
-
if (!node.className) { // doesn't have it for sure
|
|
95
|
-
node.className = className;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
this._findClassName(node, className); // see if it's already there
|
|
99
|
-
if (this._lastStart === -1) {
|
|
100
|
-
node.className = node.className + ' ' + className;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
removeClass(node, className) {
|
|
105
|
-
this._findClassName(node, className);
|
|
106
|
-
if (this._lastStart === -1) {
|
|
107
|
-
return; // Prevent styles invalidation if not necessary
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
node.className = node.className.substring(0, this._lastStart) + node.className.substring(this._lastEnd);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
removeClasses(node, ...classNames) {
|
|
114
|
-
classNames.forEach(nameValue => nameValue.split(' ').forEach(name => this.removeClass(node, name)));
|
|
115
|
-
}
|
|
116
|
-
toggleClass(node, className, shouldHaveIt) {
|
|
117
|
-
this._findClassName(node, className);
|
|
118
|
-
if (this._lastStart !== -1 && (shouldHaveIt === undefined || !shouldHaveIt)) {
|
|
119
|
-
this.removeClass(node, className);
|
|
120
|
-
}
|
|
121
|
-
if (this._lastStart === -1 && (shouldHaveIt === undefined || shouldHaveIt)) {
|
|
122
|
-
this.addClass(node, className);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
const _nativeClassList = new class {
|
|
127
|
-
hasClass(node, className) {
|
|
128
|
-
return Boolean(className) && node.classList && node.classList.contains(className);
|
|
129
|
-
}
|
|
130
|
-
addClasses(node, ...classNames) {
|
|
131
|
-
classNames.forEach(nameValue => nameValue.split(' ').forEach(name => this.addClass(node, name)));
|
|
132
|
-
}
|
|
133
|
-
addClass(node, className) {
|
|
134
|
-
if (className && node.classList) {
|
|
135
|
-
node.classList.add(className);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
removeClass(node, className) {
|
|
139
|
-
if (className && node.classList) {
|
|
140
|
-
node.classList.remove(className);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
removeClasses(node, ...classNames) {
|
|
144
|
-
classNames.forEach(nameValue => nameValue.split(' ').forEach(name => this.removeClass(node, name)));
|
|
145
|
-
}
|
|
146
|
-
toggleClass(node, className, shouldHaveIt) {
|
|
147
|
-
if (node.classList) {
|
|
148
|
-
node.classList.toggle(className, shouldHaveIt);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
// In IE11 there is only partial support for `classList` which makes us keep our
|
|
153
|
-
// custom implementation. Otherwise use the native implementation, see: http://caniuse.com/#search=classlist
|
|
154
|
-
const _classList = browser.isIE ? _manualClassList : _nativeClassList;
|
|
155
|
-
exports.hasClass = _classList.hasClass.bind(_classList);
|
|
156
|
-
exports.addClass = _classList.addClass.bind(_classList);
|
|
157
|
-
exports.addClasses = _classList.addClasses.bind(_classList);
|
|
158
|
-
exports.removeClass = _classList.removeClass.bind(_classList);
|
|
159
|
-
exports.removeClasses = _classList.removeClasses.bind(_classList);
|
|
160
|
-
exports.toggleClass = _classList.toggleClass.bind(_classList);
|
|
161
|
-
class DomListener {
|
|
162
|
-
constructor(node, type, handler, useCapture) {
|
|
163
|
-
this._node = node;
|
|
164
|
-
this._type = type;
|
|
165
|
-
this._handler = handler;
|
|
166
|
-
this._useCapture = (useCapture || false);
|
|
167
|
-
this._node.addEventListener(this._type, this._handler, this._useCapture);
|
|
168
|
-
}
|
|
169
|
-
dispose() {
|
|
170
|
-
if (!this._handler) {
|
|
171
|
-
// Already disposed
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
this._node.removeEventListener(this._type, this._handler, this._useCapture);
|
|
175
|
-
// Prevent leakers from holding on to the dom or handler func
|
|
176
|
-
this._node = null;
|
|
177
|
-
this._handler = null;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
function addDisposableListener(node, type, handler, useCapture) {
|
|
181
|
-
return new DomListener(node, type, handler, useCapture);
|
|
182
|
-
}
|
|
183
|
-
exports.addDisposableListener = addDisposableListener;
|
|
184
|
-
function _wrapAsStandardMouseEvent(handler) {
|
|
185
|
-
return function (e) {
|
|
186
|
-
return handler(new mouseEvent_1.StandardMouseEvent(e));
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
function _wrapAsStandardKeyboardEvent(handler) {
|
|
190
|
-
return function (e) {
|
|
191
|
-
return handler(new keyboardEvent_1.StandardKeyboardEvent(e));
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
let addStandardDisposableListener = function addStandardDisposableListener(node, type, handler, useCapture) {
|
|
195
|
-
let wrapHandler = handler;
|
|
196
|
-
if (type === 'click' || type === 'mousedown') {
|
|
197
|
-
wrapHandler = _wrapAsStandardMouseEvent(handler);
|
|
198
|
-
}
|
|
199
|
-
else if (type === 'keydown' || type === 'keypress' || type === 'keyup') {
|
|
200
|
-
wrapHandler = _wrapAsStandardKeyboardEvent(handler);
|
|
201
|
-
}
|
|
202
|
-
return addDisposableListener(node, type, wrapHandler, useCapture);
|
|
203
|
-
};
|
|
204
|
-
exports.addStandardDisposableListener = addStandardDisposableListener;
|
|
205
|
-
function addDisposableNonBubblingMouseOutListener(node, handler) {
|
|
206
|
-
return addDisposableListener(node, 'mouseout', (e) => {
|
|
207
|
-
// Mouse out bubbles, so this is an attempt to ignore faux mouse outs coming from children elements
|
|
208
|
-
let toElement = (e.relatedTarget || e.target);
|
|
209
|
-
while (toElement && toElement !== node) {
|
|
210
|
-
toElement = toElement.parentNode;
|
|
211
|
-
}
|
|
212
|
-
if (toElement === node) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
handler(e);
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
exports.addDisposableNonBubblingMouseOutListener = addDisposableNonBubblingMouseOutListener;
|
|
219
|
-
let _animationFrame = null;
|
|
220
|
-
function doRequestAnimationFrame(callback) {
|
|
221
|
-
if (!_animationFrame) {
|
|
222
|
-
const emulatedRequestAnimationFrame = (callback) => {
|
|
223
|
-
return setTimeout(() => callback(new Date().getTime()), 0);
|
|
224
|
-
};
|
|
225
|
-
_animationFrame = (self.requestAnimationFrame
|
|
226
|
-
|| self.msRequestAnimationFrame
|
|
227
|
-
|| self.webkitRequestAnimationFrame
|
|
228
|
-
|| self.mozRequestAnimationFrame
|
|
229
|
-
|| self.oRequestAnimationFrame
|
|
230
|
-
|| emulatedRequestAnimationFrame);
|
|
231
|
-
}
|
|
232
|
-
return _animationFrame.call(self, callback);
|
|
233
|
-
}
|
|
234
|
-
class AnimationFrameQueueItem {
|
|
235
|
-
constructor(runner, priority = 0) {
|
|
236
|
-
this._runner = runner;
|
|
237
|
-
this.priority = priority;
|
|
238
|
-
this._canceled = false;
|
|
239
|
-
}
|
|
240
|
-
dispose() {
|
|
241
|
-
this._canceled = true;
|
|
242
|
-
}
|
|
243
|
-
execute() {
|
|
244
|
-
if (this._canceled) {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
try {
|
|
248
|
-
this._runner();
|
|
249
|
-
}
|
|
250
|
-
catch (e) {
|
|
251
|
-
console.error(e);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
// Sort by priority (largest to lowest)
|
|
255
|
-
static sort(a, b) {
|
|
256
|
-
return b.priority - a.priority;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
(function () {
|
|
260
|
-
/**
|
|
261
|
-
* The runners scheduled at the next animation frame
|
|
262
|
-
*/
|
|
263
|
-
let NEXT_QUEUE = [];
|
|
264
|
-
/**
|
|
265
|
-
* The runners scheduled at the current animation frame
|
|
266
|
-
*/
|
|
267
|
-
let CURRENT_QUEUE = null;
|
|
268
|
-
/**
|
|
269
|
-
* A flag to keep track if the native requestAnimationFrame was already called
|
|
270
|
-
*/
|
|
271
|
-
let animFrameRequested = false;
|
|
272
|
-
/**
|
|
273
|
-
* A flag to indicate if currently handling a native requestAnimationFrame callback
|
|
274
|
-
*/
|
|
275
|
-
let inAnimationFrameRunner = false;
|
|
276
|
-
let animationFrameRunner = () => {
|
|
277
|
-
animFrameRequested = false;
|
|
278
|
-
CURRENT_QUEUE = NEXT_QUEUE;
|
|
279
|
-
NEXT_QUEUE = [];
|
|
280
|
-
inAnimationFrameRunner = true;
|
|
281
|
-
while (CURRENT_QUEUE.length > 0) {
|
|
282
|
-
CURRENT_QUEUE.sort(AnimationFrameQueueItem.sort);
|
|
283
|
-
let top = CURRENT_QUEUE.shift();
|
|
284
|
-
top.execute();
|
|
285
|
-
}
|
|
286
|
-
inAnimationFrameRunner = false;
|
|
287
|
-
};
|
|
288
|
-
exports.scheduleAtNextAnimationFrame = (runner, priority = 0) => {
|
|
289
|
-
let item = new AnimationFrameQueueItem(runner, priority);
|
|
290
|
-
NEXT_QUEUE.push(item);
|
|
291
|
-
if (!animFrameRequested) {
|
|
292
|
-
animFrameRequested = true;
|
|
293
|
-
doRequestAnimationFrame(animationFrameRunner);
|
|
294
|
-
}
|
|
295
|
-
return item;
|
|
296
|
-
};
|
|
297
|
-
exports.runAtThisOrScheduleAtNextAnimationFrame = (runner, priority) => {
|
|
298
|
-
if (inAnimationFrameRunner) {
|
|
299
|
-
let item = new AnimationFrameQueueItem(runner, priority);
|
|
300
|
-
CURRENT_QUEUE.push(item);
|
|
301
|
-
return item;
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
return (0, exports.scheduleAtNextAnimationFrame)(runner, priority);
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
})();
|
|
308
|
-
function measure(callback) {
|
|
309
|
-
return (0, exports.scheduleAtNextAnimationFrame)(callback, 10000 /* must be early */);
|
|
310
|
-
}
|
|
311
|
-
exports.measure = measure;
|
|
312
|
-
function modify(callback) {
|
|
313
|
-
return (0, exports.scheduleAtNextAnimationFrame)(callback, -10000 /* must be late */);
|
|
314
|
-
}
|
|
315
|
-
exports.modify = modify;
|
|
316
|
-
const MINIMUM_TIME_MS = 16;
|
|
317
|
-
const DEFAULT_EVENT_MERGER = function (lastEvent, currentEvent) {
|
|
318
|
-
return currentEvent;
|
|
319
|
-
};
|
|
320
|
-
class TimeoutThrottledDomListener extends lifecycle_1.Disposable {
|
|
321
|
-
constructor(node, type, handler, eventMerger = DEFAULT_EVENT_MERGER, minimumTimeMs = MINIMUM_TIME_MS) {
|
|
322
|
-
super();
|
|
323
|
-
let lastEvent = null;
|
|
324
|
-
let lastHandlerTime = 0;
|
|
325
|
-
let timeout = this._register(new async_1.TimeoutTimer());
|
|
326
|
-
let invokeHandler = () => {
|
|
327
|
-
lastHandlerTime = (new Date()).getTime();
|
|
328
|
-
handler(lastEvent);
|
|
329
|
-
lastEvent = null;
|
|
330
|
-
};
|
|
331
|
-
this._register(addDisposableListener(node, type, (e) => {
|
|
332
|
-
lastEvent = eventMerger(lastEvent, e);
|
|
333
|
-
let elapsedTime = (new Date()).getTime() - lastHandlerTime;
|
|
334
|
-
if (elapsedTime >= minimumTimeMs) {
|
|
335
|
-
timeout.cancel();
|
|
336
|
-
invokeHandler();
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
timeout.setIfNotSet(invokeHandler, minimumTimeMs - elapsedTime);
|
|
340
|
-
}
|
|
341
|
-
}));
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
function addDisposableThrottledListener(node, type, handler, eventMerger, minimumTimeMs) {
|
|
345
|
-
return new TimeoutThrottledDomListener(node, type, handler, eventMerger, minimumTimeMs);
|
|
346
|
-
}
|
|
347
|
-
exports.addDisposableThrottledListener = addDisposableThrottledListener;
|
|
348
|
-
function getComputedStyle(el) {
|
|
349
|
-
return document.defaultView.getComputedStyle(el, null);
|
|
350
|
-
}
|
|
351
|
-
exports.getComputedStyle = getComputedStyle;
|
|
352
|
-
// Adapted from WinJS
|
|
353
|
-
// Converts a CSS positioning string for the specified element to pixels.
|
|
354
|
-
const convertToPixels = (function () {
|
|
355
|
-
return function (element, value) {
|
|
356
|
-
return parseFloat(value) || 0;
|
|
357
|
-
};
|
|
358
|
-
})();
|
|
359
|
-
function getDimension(element, cssPropertyName, jsPropertyName) {
|
|
360
|
-
let computedStyle = getComputedStyle(element);
|
|
361
|
-
let value = '0';
|
|
362
|
-
if (computedStyle) {
|
|
363
|
-
if (computedStyle.getPropertyValue) {
|
|
364
|
-
value = computedStyle.getPropertyValue(cssPropertyName);
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
// IE8
|
|
368
|
-
value = computedStyle.getAttribute(jsPropertyName);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
return convertToPixels(element, value);
|
|
372
|
-
}
|
|
373
|
-
function getClientArea(element) {
|
|
374
|
-
// Try with DOM clientWidth / clientHeight
|
|
375
|
-
if (element !== document.body) {
|
|
376
|
-
return new Dimension(element.clientWidth, element.clientHeight);
|
|
377
|
-
}
|
|
378
|
-
// Try innerWidth / innerHeight
|
|
379
|
-
if (window.innerWidth && window.innerHeight) {
|
|
380
|
-
return new Dimension(window.innerWidth, window.innerHeight);
|
|
381
|
-
}
|
|
382
|
-
// Try with document.body.clientWidth / document.body.clientHeight
|
|
383
|
-
if (document.body && document.body.clientWidth && document.body.clientHeight) {
|
|
384
|
-
return new Dimension(document.body.clientWidth, document.body.clientHeight);
|
|
385
|
-
}
|
|
386
|
-
// Try with document.documentElement.clientWidth / document.documentElement.clientHeight
|
|
387
|
-
if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) {
|
|
388
|
-
return new Dimension(document.documentElement.clientWidth, document.documentElement.clientHeight);
|
|
389
|
-
}
|
|
390
|
-
throw new Error('Unable to figure out browser width and height');
|
|
391
|
-
}
|
|
392
|
-
exports.getClientArea = getClientArea;
|
|
393
|
-
const sizeUtils = {
|
|
394
|
-
getBorderLeftWidth: function (element) {
|
|
395
|
-
return getDimension(element, 'border-left-width', 'borderLeftWidth');
|
|
396
|
-
},
|
|
397
|
-
getBorderRightWidth: function (element) {
|
|
398
|
-
return getDimension(element, 'border-right-width', 'borderRightWidth');
|
|
399
|
-
},
|
|
400
|
-
getBorderTopWidth: function (element) {
|
|
401
|
-
return getDimension(element, 'border-top-width', 'borderTopWidth');
|
|
402
|
-
},
|
|
403
|
-
getBorderBottomWidth: function (element) {
|
|
404
|
-
return getDimension(element, 'border-bottom-width', 'borderBottomWidth');
|
|
405
|
-
},
|
|
406
|
-
getPaddingLeft: function (element) {
|
|
407
|
-
return getDimension(element, 'padding-left', 'paddingLeft');
|
|
408
|
-
},
|
|
409
|
-
getPaddingRight: function (element) {
|
|
410
|
-
return getDimension(element, 'padding-right', 'paddingRight');
|
|
411
|
-
},
|
|
412
|
-
getPaddingTop: function (element) {
|
|
413
|
-
return getDimension(element, 'padding-top', 'paddingTop');
|
|
414
|
-
},
|
|
415
|
-
getPaddingBottom: function (element) {
|
|
416
|
-
return getDimension(element, 'padding-bottom', 'paddingBottom');
|
|
417
|
-
},
|
|
418
|
-
getMarginLeft: function (element) {
|
|
419
|
-
return getDimension(element, 'margin-left', 'marginLeft');
|
|
420
|
-
},
|
|
421
|
-
getMarginTop: function (element) {
|
|
422
|
-
return getDimension(element, 'margin-top', 'marginTop');
|
|
423
|
-
},
|
|
424
|
-
getMarginRight: function (element) {
|
|
425
|
-
return getDimension(element, 'margin-right', 'marginRight');
|
|
426
|
-
},
|
|
427
|
-
getMarginBottom: function (element) {
|
|
428
|
-
return getDimension(element, 'margin-bottom', 'marginBottom');
|
|
429
|
-
},
|
|
430
|
-
__commaSentinel: false
|
|
431
|
-
};
|
|
432
|
-
// ----------------------------------------------------------------------------------------
|
|
433
|
-
// Position & Dimension
|
|
434
|
-
class Dimension {
|
|
435
|
-
constructor(width, height) {
|
|
436
|
-
this.width = width;
|
|
437
|
-
this.height = height;
|
|
438
|
-
}
|
|
439
|
-
static equals(a, b) {
|
|
440
|
-
if (a === b) {
|
|
441
|
-
return true;
|
|
442
|
-
}
|
|
443
|
-
if (!a || !b) {
|
|
444
|
-
return false;
|
|
445
|
-
}
|
|
446
|
-
return a.width === b.width && a.height === b.height;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
exports.Dimension = Dimension;
|
|
450
|
-
function getTopLeftOffset(element) {
|
|
451
|
-
// Adapted from WinJS.Utilities.getPosition
|
|
452
|
-
// and added borders to the mix
|
|
453
|
-
let offsetParent = element.offsetParent, top = element.offsetTop, left = element.offsetLeft;
|
|
454
|
-
while ((element = element.parentNode) !== null && element !== document.body && element !== document.documentElement) {
|
|
455
|
-
top -= element.scrollTop;
|
|
456
|
-
let c = getComputedStyle(element);
|
|
457
|
-
if (c) {
|
|
458
|
-
left -= c.direction !== 'rtl' ? element.scrollLeft : -element.scrollLeft;
|
|
459
|
-
}
|
|
460
|
-
if (element === offsetParent) {
|
|
461
|
-
left += sizeUtils.getBorderLeftWidth(element);
|
|
462
|
-
top += sizeUtils.getBorderTopWidth(element);
|
|
463
|
-
top += element.offsetTop;
|
|
464
|
-
left += element.offsetLeft;
|
|
465
|
-
offsetParent = element.offsetParent;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
return {
|
|
469
|
-
left: left,
|
|
470
|
-
top: top
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
exports.getTopLeftOffset = getTopLeftOffset;
|
|
474
|
-
function size(element, width, height) {
|
|
475
|
-
if (typeof width === 'number') {
|
|
476
|
-
element.style.width = `${width}px`;
|
|
477
|
-
}
|
|
478
|
-
if (typeof height === 'number') {
|
|
479
|
-
element.style.height = `${height}px`;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
exports.size = size;
|
|
483
|
-
function position(element, top, right, bottom, left, position = 'absolute') {
|
|
484
|
-
if (typeof top === 'number') {
|
|
485
|
-
element.style.top = `${top}px`;
|
|
486
|
-
}
|
|
487
|
-
if (typeof right === 'number') {
|
|
488
|
-
element.style.right = `${right}px`;
|
|
489
|
-
}
|
|
490
|
-
if (typeof bottom === 'number') {
|
|
491
|
-
element.style.bottom = `${bottom}px`;
|
|
492
|
-
}
|
|
493
|
-
if (typeof left === 'number') {
|
|
494
|
-
element.style.left = `${left}px`;
|
|
495
|
-
}
|
|
496
|
-
element.style.position = position;
|
|
497
|
-
}
|
|
498
|
-
exports.position = position;
|
|
499
|
-
/**
|
|
500
|
-
* Returns the position of a dom node relative to the entire page.
|
|
501
|
-
*/
|
|
502
|
-
function getDomNodePagePosition(domNode) {
|
|
503
|
-
let bb = domNode.getBoundingClientRect();
|
|
504
|
-
return {
|
|
505
|
-
left: bb.left + exports.StandardWindow.scrollX,
|
|
506
|
-
top: bb.top + exports.StandardWindow.scrollY,
|
|
507
|
-
width: bb.width,
|
|
508
|
-
height: bb.height
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
exports.getDomNodePagePosition = getDomNodePagePosition;
|
|
512
|
-
exports.StandardWindow = new class {
|
|
513
|
-
get scrollX() {
|
|
514
|
-
if (typeof window.scrollX === 'number') {
|
|
515
|
-
// modern browsers
|
|
516
|
-
return window.scrollX;
|
|
517
|
-
}
|
|
518
|
-
else {
|
|
519
|
-
return document.body.scrollLeft + document.documentElement.scrollLeft;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
get scrollY() {
|
|
523
|
-
if (typeof window.scrollY === 'number') {
|
|
524
|
-
// modern browsers
|
|
525
|
-
return window.scrollY;
|
|
526
|
-
}
|
|
527
|
-
else {
|
|
528
|
-
return document.body.scrollTop + document.documentElement.scrollTop;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
// Adapted from WinJS
|
|
533
|
-
// Gets the width of the element, including margins.
|
|
534
|
-
function getTotalWidth(element) {
|
|
535
|
-
let margin = sizeUtils.getMarginLeft(element) + sizeUtils.getMarginRight(element);
|
|
536
|
-
return element.offsetWidth + margin;
|
|
537
|
-
}
|
|
538
|
-
exports.getTotalWidth = getTotalWidth;
|
|
539
|
-
function getContentWidth(element) {
|
|
540
|
-
let border = sizeUtils.getBorderLeftWidth(element) + sizeUtils.getBorderRightWidth(element);
|
|
541
|
-
let padding = sizeUtils.getPaddingLeft(element) + sizeUtils.getPaddingRight(element);
|
|
542
|
-
return element.offsetWidth - border - padding;
|
|
543
|
-
}
|
|
544
|
-
exports.getContentWidth = getContentWidth;
|
|
545
|
-
function getTotalScrollWidth(element) {
|
|
546
|
-
let margin = sizeUtils.getMarginLeft(element) + sizeUtils.getMarginRight(element);
|
|
547
|
-
return element.scrollWidth + margin;
|
|
548
|
-
}
|
|
549
|
-
exports.getTotalScrollWidth = getTotalScrollWidth;
|
|
550
|
-
// Adapted from WinJS
|
|
551
|
-
// Gets the height of the content of the specified element. The content height does not include borders or padding.
|
|
552
|
-
function getContentHeight(element) {
|
|
553
|
-
let border = sizeUtils.getBorderTopWidth(element) + sizeUtils.getBorderBottomWidth(element);
|
|
554
|
-
let padding = sizeUtils.getPaddingTop(element) + sizeUtils.getPaddingBottom(element);
|
|
555
|
-
return element.offsetHeight - border - padding;
|
|
556
|
-
}
|
|
557
|
-
exports.getContentHeight = getContentHeight;
|
|
558
|
-
// Adapted from WinJS
|
|
559
|
-
// Gets the height of the element, including its margins.
|
|
560
|
-
function getTotalHeight(element) {
|
|
561
|
-
let margin = sizeUtils.getMarginTop(element) + sizeUtils.getMarginBottom(element);
|
|
562
|
-
return element.offsetHeight + margin;
|
|
563
|
-
}
|
|
564
|
-
exports.getTotalHeight = getTotalHeight;
|
|
565
|
-
// Gets the left coordinate of the specified element relative to the specified parent.
|
|
566
|
-
function getRelativeLeft(element, parent) {
|
|
567
|
-
if (element === null) {
|
|
568
|
-
return 0;
|
|
569
|
-
}
|
|
570
|
-
let elementPosition = getTopLeftOffset(element);
|
|
571
|
-
let parentPosition = getTopLeftOffset(parent);
|
|
572
|
-
return elementPosition.left - parentPosition.left;
|
|
573
|
-
}
|
|
574
|
-
function getLargestChildWidth(parent, children) {
|
|
575
|
-
let childWidths = children.map((child) => {
|
|
576
|
-
return Math.max(getTotalScrollWidth(child), getTotalWidth(child)) + getRelativeLeft(child, parent) || 0;
|
|
577
|
-
});
|
|
578
|
-
let maxWidth = Math.max(...childWidths);
|
|
579
|
-
return maxWidth;
|
|
580
|
-
}
|
|
581
|
-
exports.getLargestChildWidth = getLargestChildWidth;
|
|
582
|
-
// ----------------------------------------------------------------------------------------
|
|
583
|
-
function isAncestor(testChild, testAncestor) {
|
|
584
|
-
while (testChild) {
|
|
585
|
-
if (testChild === testAncestor) {
|
|
586
|
-
return true;
|
|
587
|
-
}
|
|
588
|
-
testChild = testChild.parentNode;
|
|
589
|
-
}
|
|
590
|
-
return false;
|
|
591
|
-
}
|
|
592
|
-
exports.isAncestor = isAncestor;
|
|
593
|
-
function findParentWithClass(node, clazz, stopAtClazzOrNode) {
|
|
594
|
-
while (node) {
|
|
595
|
-
if ((0, exports.hasClass)(node, clazz)) {
|
|
596
|
-
return node;
|
|
597
|
-
}
|
|
598
|
-
if (stopAtClazzOrNode) {
|
|
599
|
-
if (typeof stopAtClazzOrNode === 'string') {
|
|
600
|
-
if ((0, exports.hasClass)(node, stopAtClazzOrNode)) {
|
|
601
|
-
return null;
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
else {
|
|
605
|
-
if (node === stopAtClazzOrNode) {
|
|
606
|
-
return null;
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
node = node.parentNode;
|
|
611
|
-
}
|
|
612
|
-
return null;
|
|
613
|
-
}
|
|
614
|
-
exports.findParentWithClass = findParentWithClass;
|
|
615
|
-
function createStyleSheet(container = document.getElementsByTagName('head')[0]) {
|
|
616
|
-
let style = document.createElement('style');
|
|
617
|
-
style.type = 'text/css';
|
|
618
|
-
style.media = 'screen';
|
|
619
|
-
container.appendChild(style);
|
|
620
|
-
return style;
|
|
621
|
-
}
|
|
622
|
-
exports.createStyleSheet = createStyleSheet;
|
|
623
|
-
let _sharedStyleSheet = null;
|
|
624
|
-
function getSharedStyleSheet() {
|
|
625
|
-
if (!_sharedStyleSheet) {
|
|
626
|
-
_sharedStyleSheet = createStyleSheet();
|
|
627
|
-
}
|
|
628
|
-
return _sharedStyleSheet;
|
|
629
|
-
}
|
|
630
|
-
function getDynamicStyleSheetRules(style) {
|
|
631
|
-
if (style && style.sheet && style.sheet.rules) {
|
|
632
|
-
// Chrome, IE
|
|
633
|
-
return style.sheet.rules;
|
|
634
|
-
}
|
|
635
|
-
if (style && style.sheet && style.sheet.cssRules) {
|
|
636
|
-
// FF
|
|
637
|
-
return style.sheet.cssRules;
|
|
638
|
-
}
|
|
639
|
-
return [];
|
|
640
|
-
}
|
|
641
|
-
function createCSSRule(selector, cssText, style = getSharedStyleSheet()) {
|
|
642
|
-
if (!style || !cssText) {
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
style.sheet.insertRule(selector + '{' + cssText + '}', 0);
|
|
646
|
-
}
|
|
647
|
-
exports.createCSSRule = createCSSRule;
|
|
648
|
-
function removeCSSRulesContainingSelector(ruleName, style = getSharedStyleSheet()) {
|
|
649
|
-
if (!style) {
|
|
650
|
-
return;
|
|
651
|
-
}
|
|
652
|
-
let rules = getDynamicStyleSheetRules(style);
|
|
653
|
-
let toDelete = [];
|
|
654
|
-
for (let i = 0; i < rules.length; i++) {
|
|
655
|
-
let rule = rules[i];
|
|
656
|
-
if (rule.selectorText.indexOf(ruleName) !== -1) {
|
|
657
|
-
toDelete.push(i);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
for (let i = toDelete.length - 1; i >= 0; i--) {
|
|
661
|
-
style.sheet.deleteRule(toDelete[i]);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
exports.removeCSSRulesContainingSelector = removeCSSRulesContainingSelector;
|
|
665
|
-
function isHTMLElement(o) {
|
|
666
|
-
if (typeof HTMLElement === 'object') {
|
|
667
|
-
return o instanceof HTMLElement;
|
|
668
|
-
}
|
|
669
|
-
return o && typeof o === 'object' && o.nodeType === 1 && typeof o.nodeName === 'string';
|
|
670
|
-
}
|
|
671
|
-
exports.isHTMLElement = isHTMLElement;
|
|
672
|
-
exports.EventType = {
|
|
673
|
-
// Window
|
|
674
|
-
MINIMIZE: 'minimize',
|
|
675
|
-
MAXIMIZE: 'maximize',
|
|
676
|
-
UNMAXIMIZE: 'unmaximize',
|
|
677
|
-
ENTER_FULLSCREEN: 'enter-full-screen',
|
|
678
|
-
LEAVE_FULLSCREEN: 'leave-full-screen',
|
|
679
|
-
// Mouse
|
|
680
|
-
CLICK: 'click',
|
|
681
|
-
DBLCLICK: 'dblclick',
|
|
682
|
-
MOUSE_UP: 'mouseup',
|
|
683
|
-
MOUSE_DOWN: 'mousedown',
|
|
684
|
-
MOUSE_OVER: 'mouseover',
|
|
685
|
-
MOUSE_MOVE: 'mousemove',
|
|
686
|
-
MOUSE_OUT: 'mouseout',
|
|
687
|
-
MOUSE_ENTER: 'mouseenter',
|
|
688
|
-
MOUSE_LEAVE: 'mouseleave',
|
|
689
|
-
CONTEXT_MENU: 'contextmenu',
|
|
690
|
-
WHEEL: 'wheel',
|
|
691
|
-
// Keyboard
|
|
692
|
-
KEY_DOWN: 'keydown',
|
|
693
|
-
KEY_PRESS: 'keypress',
|
|
694
|
-
KEY_UP: 'keyup',
|
|
695
|
-
// HTML Document
|
|
696
|
-
LOAD: 'load',
|
|
697
|
-
UNLOAD: 'unload',
|
|
698
|
-
ABORT: 'abort',
|
|
699
|
-
ERROR: 'error',
|
|
700
|
-
RESIZE: 'resize',
|
|
701
|
-
SCROLL: 'scroll',
|
|
702
|
-
// Form
|
|
703
|
-
SELECT: 'select',
|
|
704
|
-
CHANGE: 'change',
|
|
705
|
-
SUBMIT: 'submit',
|
|
706
|
-
RESET: 'reset',
|
|
707
|
-
FOCUS: 'focus',
|
|
708
|
-
FOCUS_IN: 'focusin',
|
|
709
|
-
FOCUS_OUT: 'focusout',
|
|
710
|
-
BLUR: 'blur',
|
|
711
|
-
INPUT: 'input',
|
|
712
|
-
// Local Storage
|
|
713
|
-
STORAGE: 'storage',
|
|
714
|
-
// Drag
|
|
715
|
-
DRAG_START: 'dragstart',
|
|
716
|
-
DRAG: 'drag',
|
|
717
|
-
DRAG_ENTER: 'dragenter',
|
|
718
|
-
DRAG_LEAVE: 'dragleave',
|
|
719
|
-
DRAG_OVER: 'dragover',
|
|
720
|
-
DROP: 'drop',
|
|
721
|
-
DRAG_END: 'dragend',
|
|
722
|
-
// Animation
|
|
723
|
-
ANIMATION_START: browser.isWebKit ? 'webkitAnimationStart' : 'animationstart',
|
|
724
|
-
ANIMATION_END: browser.isWebKit ? 'webkitAnimationEnd' : 'animationend',
|
|
725
|
-
ANIMATION_ITERATION: browser.isWebKit ? 'webkitAnimationIteration' : 'animationiteration'
|
|
726
|
-
};
|
|
727
|
-
exports.EventHelper = {
|
|
728
|
-
stop: function (e, cancelBubble) {
|
|
729
|
-
if (e.preventDefault) {
|
|
730
|
-
e.preventDefault();
|
|
731
|
-
}
|
|
732
|
-
else {
|
|
733
|
-
// IE8
|
|
734
|
-
e.returnValue = false;
|
|
735
|
-
}
|
|
736
|
-
if (cancelBubble) {
|
|
737
|
-
if (e.stopPropagation) {
|
|
738
|
-
e.stopPropagation();
|
|
739
|
-
}
|
|
740
|
-
else {
|
|
741
|
-
// IE8
|
|
742
|
-
e.cancelBubble = true;
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
};
|
|
747
|
-
function saveParentsScrollTop(node) {
|
|
748
|
-
let r = [];
|
|
749
|
-
for (let i = 0; node && node.nodeType === node.ELEMENT_NODE; i++) {
|
|
750
|
-
r[i] = node.scrollTop;
|
|
751
|
-
node = node.parentNode;
|
|
752
|
-
}
|
|
753
|
-
return r;
|
|
754
|
-
}
|
|
755
|
-
exports.saveParentsScrollTop = saveParentsScrollTop;
|
|
756
|
-
function restoreParentsScrollTop(node, state) {
|
|
757
|
-
for (let i = 0; node && node.nodeType === node.ELEMENT_NODE; i++) {
|
|
758
|
-
if (node.scrollTop !== state[i]) {
|
|
759
|
-
node.scrollTop = state[i];
|
|
760
|
-
}
|
|
761
|
-
node = node.parentNode;
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
exports.restoreParentsScrollTop = restoreParentsScrollTop;
|
|
765
|
-
class FocusTracker {
|
|
766
|
-
constructor(element) {
|
|
767
|
-
this._onDidFocus = new event_2.Emitter();
|
|
768
|
-
this.onDidFocus = this._onDidFocus.event;
|
|
769
|
-
this._onDidBlur = new event_2.Emitter();
|
|
770
|
-
this.onDidBlur = this._onDidBlur.event;
|
|
771
|
-
this.disposables = [];
|
|
772
|
-
let hasFocus = isAncestor(document.activeElement, element);
|
|
773
|
-
let loosingFocus = false;
|
|
774
|
-
let onFocus = () => {
|
|
775
|
-
loosingFocus = false;
|
|
776
|
-
if (!hasFocus) {
|
|
777
|
-
hasFocus = true;
|
|
778
|
-
this._onDidFocus.fire();
|
|
779
|
-
}
|
|
780
|
-
};
|
|
781
|
-
let onBlur = () => {
|
|
782
|
-
if (hasFocus) {
|
|
783
|
-
loosingFocus = true;
|
|
784
|
-
window.setTimeout(() => {
|
|
785
|
-
if (loosingFocus) {
|
|
786
|
-
loosingFocus = false;
|
|
787
|
-
hasFocus = false;
|
|
788
|
-
this._onDidBlur.fire();
|
|
789
|
-
}
|
|
790
|
-
}, 0);
|
|
791
|
-
}
|
|
792
|
-
};
|
|
793
|
-
(0, event_1.domEvent)(element, exports.EventType.FOCUS, true)(onFocus, null, this.disposables);
|
|
794
|
-
(0, event_1.domEvent)(element, exports.EventType.BLUR, true)(onBlur, null, this.disposables);
|
|
795
|
-
}
|
|
796
|
-
dispose() {
|
|
797
|
-
this.disposables = (0, lifecycle_1.dispose)(this.disposables);
|
|
798
|
-
this._onDidFocus.dispose();
|
|
799
|
-
this._onDidBlur.dispose();
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
function trackFocus(element) {
|
|
803
|
-
return new FocusTracker(element);
|
|
804
|
-
}
|
|
805
|
-
exports.trackFocus = trackFocus;
|
|
806
|
-
function append(parent, ...children) {
|
|
807
|
-
children.forEach(child => parent.appendChild(child));
|
|
808
|
-
return children[children.length - 1];
|
|
809
|
-
}
|
|
810
|
-
exports.append = append;
|
|
811
|
-
function prepend(parent, child) {
|
|
812
|
-
parent.insertBefore(child, parent.firstChild);
|
|
813
|
-
return child;
|
|
814
|
-
}
|
|
815
|
-
exports.prepend = prepend;
|
|
816
|
-
const SELECTOR_REGEX = /([\w\-]+)?(#([\w\-]+))?((.([\w\-]+))*)/;
|
|
817
|
-
function $(description, attrs, ...children) {
|
|
818
|
-
let match = SELECTOR_REGEX.exec(description);
|
|
819
|
-
if (!match) {
|
|
820
|
-
throw new Error('Bad use of emmet');
|
|
821
|
-
}
|
|
822
|
-
let result = document.createElement(match[1] || 'div');
|
|
823
|
-
if (match[3]) {
|
|
824
|
-
result.id = match[3];
|
|
825
|
-
}
|
|
826
|
-
if (match[4]) {
|
|
827
|
-
result.className = match[4].replace(/\./g, ' ').trim();
|
|
828
|
-
}
|
|
829
|
-
attrs = attrs || {};
|
|
830
|
-
Object.keys(attrs).forEach(name => {
|
|
831
|
-
const value = attrs[name];
|
|
832
|
-
if (/^on\w+$/.test(name)) {
|
|
833
|
-
result[name] = value;
|
|
834
|
-
}
|
|
835
|
-
else if (name === 'selected') {
|
|
836
|
-
if (value) {
|
|
837
|
-
result.setAttribute(name, 'true');
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
else {
|
|
841
|
-
result.setAttribute(name, value);
|
|
842
|
-
}
|
|
843
|
-
});
|
|
844
|
-
(0, arrays_1.coalesce)(children)
|
|
845
|
-
.forEach(child => {
|
|
846
|
-
if (child instanceof Node) {
|
|
847
|
-
result.appendChild(child);
|
|
848
|
-
}
|
|
849
|
-
else {
|
|
850
|
-
result.appendChild(document.createTextNode(child));
|
|
851
|
-
}
|
|
852
|
-
});
|
|
853
|
-
return result;
|
|
854
|
-
}
|
|
855
|
-
exports.$ = $;
|
|
856
|
-
function join(nodes, separator) {
|
|
857
|
-
const result = [];
|
|
858
|
-
nodes.forEach((node, index) => {
|
|
859
|
-
if (index > 0) {
|
|
860
|
-
if (separator instanceof Node) {
|
|
861
|
-
result.push(separator.cloneNode());
|
|
862
|
-
}
|
|
863
|
-
else {
|
|
864
|
-
result.push(document.createTextNode(separator));
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
result.push(node);
|
|
868
|
-
});
|
|
869
|
-
return result;
|
|
870
|
-
}
|
|
871
|
-
exports.join = join;
|
|
872
|
-
function show(...elements) {
|
|
873
|
-
for (let element of elements) {
|
|
874
|
-
if (element) {
|
|
875
|
-
element.style.display = '';
|
|
876
|
-
element.removeAttribute('aria-hidden');
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
exports.show = show;
|
|
881
|
-
function hide(...elements) {
|
|
882
|
-
for (let element of elements) {
|
|
883
|
-
if (element) {
|
|
884
|
-
element.style.display = 'none';
|
|
885
|
-
element.setAttribute('aria-hidden', 'true');
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
exports.hide = hide;
|
|
890
|
-
function findParentWithAttribute(node, attribute) {
|
|
891
|
-
while (node) {
|
|
892
|
-
if (node instanceof HTMLElement && node.hasAttribute(attribute)) {
|
|
893
|
-
return node;
|
|
894
|
-
}
|
|
895
|
-
node = node.parentNode;
|
|
896
|
-
}
|
|
897
|
-
return null;
|
|
898
|
-
}
|
|
899
|
-
function removeTabIndexAndUpdateFocus(node) {
|
|
900
|
-
if (!node || !node.hasAttribute('tabIndex')) {
|
|
901
|
-
return;
|
|
902
|
-
}
|
|
903
|
-
// If we are the currently focused element and tabIndex is removed,
|
|
904
|
-
// standard DOM behavior is to move focus to the <body> element. We
|
|
905
|
-
// typically never want that, rather put focus to the closest element
|
|
906
|
-
// in the hierarchy of the parent DOM nodes.
|
|
907
|
-
if (document.activeElement === node) {
|
|
908
|
-
let parentFocusable = findParentWithAttribute(node.parentElement, 'tabIndex');
|
|
909
|
-
if (parentFocusable) {
|
|
910
|
-
parentFocusable.focus();
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
node.removeAttribute('tabindex');
|
|
914
|
-
}
|
|
915
|
-
exports.removeTabIndexAndUpdateFocus = removeTabIndexAndUpdateFocus;
|
|
916
|
-
function getElementsByTagName(tag) {
|
|
917
|
-
return Array.prototype.slice.call(document.getElementsByTagName(tag), 0);
|
|
918
|
-
}
|
|
919
|
-
exports.getElementsByTagName = getElementsByTagName;
|
|
920
|
-
function finalHandler(fn) {
|
|
921
|
-
return e => {
|
|
922
|
-
e.preventDefault();
|
|
923
|
-
e.stopPropagation();
|
|
924
|
-
fn(e);
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
exports.finalHandler = finalHandler;
|
|
928
|
-
function domContentLoaded() {
|
|
929
|
-
return new Promise(resolve => {
|
|
930
|
-
const readyState = document.readyState;
|
|
931
|
-
if (readyState === 'complete' || (document && document.body !== null)) {
|
|
932
|
-
platform.setImmediate(resolve);
|
|
933
|
-
}
|
|
934
|
-
else {
|
|
935
|
-
window.addEventListener('DOMContentLoaded', resolve, false);
|
|
936
|
-
}
|
|
937
|
-
});
|
|
938
|
-
}
|
|
939
|
-
exports.domContentLoaded = domContentLoaded;
|
|
940
|
-
/**
|
|
941
|
-
* Find a value usable for a dom node size such that the likelihood that it would be
|
|
942
|
-
* displayed with constant screen pixels size is as high as possible.
|
|
943
|
-
*
|
|
944
|
-
* e.g. We would desire for the cursors to be 2px (CSS px) wide. Under a devicePixelRatio
|
|
945
|
-
* of 1.25, the cursor will be 2.5 screen pixels wide. Depending on how the dom node aligns/"snaps"
|
|
946
|
-
* with the screen pixels, it will sometimes be rendered with 2 screen pixels, and sometimes with 3 screen pixels.
|
|
947
|
-
*/
|
|
948
|
-
function computeScreenAwareSize(cssPx) {
|
|
949
|
-
const screenPx = window.devicePixelRatio * cssPx;
|
|
950
|
-
return Math.max(1, Math.floor(screenPx)) / window.devicePixelRatio;
|
|
951
|
-
}
|
|
952
|
-
exports.computeScreenAwareSize = computeScreenAwareSize;
|
|
953
|
-
/**
|
|
954
|
-
* See https://github.com/Microsoft/monaco-editor/issues/601
|
|
955
|
-
* To protect against malicious code in the linked site, particularly phishing attempts,
|
|
956
|
-
* the window.opener should be set to null to prevent the linked site from having access
|
|
957
|
-
* to change the location of the current page.
|
|
958
|
-
* See https://mathiasbynens.github.io/rel-noopener/
|
|
959
|
-
*/
|
|
960
|
-
function windowOpenNoOpener(url) {
|
|
961
|
-
if (platform.isNative || browser.isEdgeWebView) {
|
|
962
|
-
// In VSCode, window.open() always returns null...
|
|
963
|
-
// The same is true for a WebView (see https://github.com/Microsoft/monaco-editor/issues/628)
|
|
964
|
-
window.open(url);
|
|
965
|
-
}
|
|
966
|
-
else {
|
|
967
|
-
let newTab = window.open();
|
|
968
|
-
if (newTab) {
|
|
969
|
-
newTab.opener = null;
|
|
970
|
-
newTab.location.href = url;
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
exports.windowOpenNoOpener = windowOpenNoOpener;
|
|
975
|
-
function animate(fn) {
|
|
976
|
-
const step = () => {
|
|
977
|
-
fn();
|
|
978
|
-
stepDisposable = (0, exports.scheduleAtNextAnimationFrame)(step);
|
|
979
|
-
};
|
|
980
|
-
let stepDisposable = (0, exports.scheduleAtNextAnimationFrame)(step);
|
|
981
|
-
return (0, lifecycle_1.toDisposable)(() => stepDisposable.dispose());
|
|
982
|
-
}
|
|
983
|
-
exports.animate = animate;
|
|
984
|
-
//# sourceMappingURL=dom.js.map
|