custom-electron-titlebar 3.2.6 → 3.2.10
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/.github/FUNDING.yml +1 -0
- package/README.md +15 -24
- package/_config.yml +1 -0
- package/{lib → build}/browser/browser.d.ts +0 -0
- package/{lib → build}/browser/browser.js +0 -0
- package/{lib → build}/browser/browser.js.map +0 -0
- package/{lib → build}/browser/event.d.ts +0 -0
- package/{lib → build}/browser/event.js +2 -1
- package/{lib → build}/browser/event.js.map +1 -1
- package/{lib → build}/browser/iframe.d.ts +0 -0
- package/{lib → build}/browser/iframe.js +0 -0
- package/{lib → build}/browser/iframe.js.map +0 -0
- package/{lib → build}/browser/keyboardEvent.d.ts +0 -0
- package/{lib → build}/browser/keyboardEvent.js +0 -0
- package/{lib → build}/browser/keyboardEvent.js.map +0 -0
- package/{lib → build}/browser/mouseEvent.d.ts +0 -0
- package/{lib → build}/browser/mouseEvent.js +0 -0
- package/{lib → build}/browser/mouseEvent.js.map +0 -0
- package/{lib → build}/common/arrays.d.ts +0 -0
- package/{lib → build}/common/arrays.js +0 -0
- package/{lib → build}/common/arrays.js.map +0 -0
- package/{lib → build}/common/async.d.ts +0 -0
- package/{lib → build}/common/async.js +0 -0
- package/{lib → build}/common/async.js.map +0 -0
- package/{lib → build}/common/charCode.d.ts +0 -0
- package/{lib → build}/common/charCode.js +0 -0
- package/{lib → build}/common/charCode.js.map +0 -0
- package/{lib → build}/common/color.d.ts +0 -0
- package/{lib → build}/common/color.js +0 -0
- package/{lib → build}/common/color.js.map +0 -0
- package/{lib → build}/common/dom.d.ts +0 -0
- package/{lib → build}/common/dom.js +16 -14
- package/build/common/dom.js.map +1 -0
- package/{lib → build}/common/event.d.ts +0 -0
- package/{lib → build}/common/event.js +1 -1
- package/build/common/event.js.map +1 -0
- package/{lib → build}/common/iterator.d.ts +0 -0
- package/{lib → build}/common/iterator.js +0 -0
- package/{lib → build}/common/iterator.js.map +0 -0
- package/{lib → build}/common/keyCodes.d.ts +0 -0
- package/{lib → build}/common/keyCodes.js +0 -0
- package/{lib → build}/common/keyCodes.js.map +0 -0
- package/{lib → build}/common/lifecycle.d.ts +0 -0
- package/{lib → build}/common/lifecycle.js +0 -0
- package/{lib → build}/common/lifecycle.js.map +0 -0
- package/{lib → build}/common/linkedList.d.ts +0 -0
- package/{lib → build}/common/linkedList.js +0 -0
- package/{lib → build}/common/linkedList.js.map +0 -0
- package/{lib → build}/common/platform.d.ts +0 -0
- package/{lib → build}/common/platform.js +0 -0
- package/{lib → build}/common/platform.js.map +0 -0
- package/{lib → build}/index.d.ts +0 -0
- package/{lib → build}/index.js +0 -0
- package/{lib → build}/index.js.map +0 -0
- package/{lib → build}/menu/menu.d.ts +0 -0
- package/{lib → build}/menu/menu.js +38 -38
- package/build/menu/menu.js.map +1 -0
- package/{lib → build}/menu/menuitem.d.ts +10 -2
- package/{lib → build}/menu/menuitem.js +70 -34
- package/build/menu/menuitem.js.map +1 -0
- package/{lib → build}/menubar.d.ts +0 -0
- package/{lib → build}/menubar.js +29 -30
- package/build/menubar.js.map +1 -0
- package/{lib → build}/themebar.d.ts +0 -0
- package/{lib → build}/themebar.js +2 -2
- package/build/themebar.js.map +1 -0
- package/{lib → build}/titlebar.d.ts +0 -0
- package/{lib → build}/titlebar.js +61 -58
- package/build/titlebar.js.map +1 -0
- package/package.json +13 -7
- package/lib/common/dom.js.map +0 -1
- package/lib/common/enableNativeMenuCommands.d.ts +0 -1
- package/lib/common/enableNativeMenuCommands.js +0 -32
- package/lib/common/enableNativeMenuCommands.js.map +0 -1
- package/lib/common/event.js.map +0 -1
- package/lib/main.d.ts +0 -1
- package/lib/main.js +0 -14
- package/lib/main.js.map +0 -1
- package/lib/menu/menu.js.map +0 -1
- package/lib/menu/menuitem.js.map +0 -1
- package/lib/menubar.js.map +0 -1
- package/lib/themebar.js.map +0 -1
- package/lib/titlebar.js.map +0 -1
- package/lib/vs/base/browser/browser.js +0 -150
- package/lib/vs/base/browser/canIUse.js +0 -58
- package/lib/vs/base/browser/codicons.js +0 -37
- package/lib/vs/base/browser/contextmenu.js +0 -9
- package/lib/vs/base/browser/dnd.js +0 -113
- package/lib/vs/base/browser/dom.js +0 -1417
- package/lib/vs/base/browser/event.js +0 -36
- package/lib/vs/base/browser/fastDomNode.js +0 -265
- package/lib/vs/base/browser/formattedTextRenderer.js +0 -248
- package/lib/vs/base/browser/globalMouseMoveMonitor.js +0 -137
- package/lib/vs/base/browser/history.js +0 -9
- package/lib/vs/base/browser/iframe.js +0 -126
- package/lib/vs/base/browser/keyboardEvent.js +0 -599
- package/lib/vs/base/browser/mouseEvent.js +0 -155
- package/lib/vs/base/browser/touch.js +0 -315
- package/lib/vs/base/browser/ui/actionbar/actionViewItems.js +0 -397
- package/lib/vs/base/browser/ui/actionbar/actionbar.js +0 -583
- package/lib/vs/base/browser/ui/checkbox/checkbox.js +0 -251
- package/lib/vs/base/browser/ui/codicons/codiconLabel.js +0 -31
- package/lib/vs/base/browser/ui/codicons/codiconStyles.js +0 -47
- package/lib/vs/base/browser/ui/contextview/contextview.js +0 -367
- package/lib/vs/base/browser/ui/dropdown/dropdown.js +0 -256
- package/lib/vs/base/browser/ui/dropdown/dropdownActionViewItem.js +0 -120
- package/lib/vs/base/browser/ui/keybindingLabel/keybindingLabel.js +0 -118
- package/lib/vs/base/browser/ui/list/list.js +0 -54
- package/lib/vs/base/browser/ui/list/listPaging.js +0 -322
- package/lib/vs/base/browser/ui/list/listView.js +0 -1388
- package/lib/vs/base/browser/ui/list/listWidget.js +0 -1709
- package/lib/vs/base/browser/ui/list/rangeMap.js +0 -223
- package/lib/vs/base/browser/ui/list/rowCache.js +0 -113
- package/lib/vs/base/browser/ui/list/splice.js +0 -23
- package/lib/vs/base/browser/ui/menu/menu.js +0 -1371
- package/lib/vs/base/browser/ui/menu/menubar.js +0 -1139
- package/lib/vs/base/browser/ui/scrollbar/abstractScrollbar.js +0 -278
- package/lib/vs/base/browser/ui/scrollbar/horizontalScrollbar.js +0 -115
- package/lib/vs/base/browser/ui/scrollbar/scrollableElement.js +0 -646
- package/lib/vs/base/browser/ui/scrollbar/scrollableElementOptions.js +0 -9
- package/lib/vs/base/browser/ui/scrollbar/scrollbarArrow.js +0 -106
- package/lib/vs/base/browser/ui/scrollbar/scrollbarState.js +0 -184
- package/lib/vs/base/browser/ui/scrollbar/scrollbarVisibilityController.js +0 -116
- package/lib/vs/base/browser/ui/scrollbar/verticalScrollbar.js +0 -114
- package/lib/vs/base/browser/ui/selectBox/selectBox.js +0 -85
- package/lib/vs/base/browser/ui/selectBox/selectBoxCustom.js +0 -985
- package/lib/vs/base/browser/ui/selectBox/selectBoxNative.js +0 -188
- package/lib/vs/base/browser/ui/toolbar/toolbar.js +0 -206
- package/lib/vs/base/browser/ui/widget.js +0 -69
- package/lib/vs/base/common/actions.js +0 -224
- package/lib/vs/base/common/amd.js +0 -31
- package/lib/vs/base/common/arrays.js +0 -641
- package/lib/vs/base/common/assert.js +0 -21
- package/lib/vs/base/common/async.js +0 -966
- package/lib/vs/base/common/buffer.js +0 -250
- package/lib/vs/base/common/cache.js +0 -40
- package/lib/vs/base/common/cancellation.js +0 -146
- package/lib/vs/base/common/charCode.js +0 -9
- package/lib/vs/base/common/codicon.js +0 -136
- package/lib/vs/base/common/codicons.js +0 -1378
- package/lib/vs/base/common/collections.js +0 -133
- package/lib/vs/base/common/color.js +0 -716
- package/lib/vs/base/common/comparers.js +0 -280
- package/lib/vs/base/common/console.js +0 -142
- package/lib/vs/base/common/date.js +0 -113
- package/lib/vs/base/common/decorators.js +0 -169
- package/lib/vs/base/common/errorMessage.js +0 -93
- package/lib/vs/base/common/errors.js +0 -213
- package/lib/vs/base/common/errorsWithActions.js +0 -28
- package/lib/vs/base/common/event.js +0 -873
- package/lib/vs/base/common/extpath.js +0 -401
- package/lib/vs/base/common/filters.js +0 -948
- package/lib/vs/base/common/functional.js +0 -28
- package/lib/vs/base/common/fuzzyScorer.js +0 -811
- package/lib/vs/base/common/glob.js +0 -696
- package/lib/vs/base/common/hash.js +0 -359
- package/lib/vs/base/common/history.js +0 -116
- package/lib/vs/base/common/htmlContent.js +0 -162
- package/lib/vs/base/common/idGenerator.js +0 -25
- package/lib/vs/base/common/iterator.js +0 -118
- package/lib/vs/base/common/json.js +0 -1624
- package/lib/vs/base/common/jsonEdit.js +0 -272
- package/lib/vs/base/common/jsonErrorMessages.js +0 -69
- package/lib/vs/base/common/jsonFormatter.js +0 -316
- package/lib/vs/base/common/jsonSchema.js +0 -9
- package/lib/vs/base/common/keyCodes.js +0 -591
- package/lib/vs/base/common/keybindingLabels.js +0 -231
- package/lib/vs/base/common/keybindingParser.js +0 -142
- package/lib/vs/base/common/labels.js +0 -430
- package/lib/vs/base/common/lazy.js +0 -71
- package/lib/vs/base/common/lifecycle.js +0 -308
- package/lib/vs/base/common/linkedList.js +0 -152
- package/lib/vs/base/common/linkedText.js +0 -73
- package/lib/vs/base/common/map.js +0 -1108
- package/lib/vs/base/common/marshalling.js +0 -80
- package/lib/vs/base/common/mime.js +0 -321
- package/lib/vs/base/common/navigator.js +0 -50
- package/lib/vs/base/common/network.js +0 -160
- package/lib/vs/base/common/normalization.js +0 -78
- package/lib/vs/base/common/numbers.js +0 -55
- package/lib/vs/base/common/objects.js +0 -268
- package/lib/vs/base/common/paging.js +0 -190
- package/lib/vs/base/common/parsers.js +0 -78
- package/lib/vs/base/common/path.js +0 -1550
- package/lib/vs/base/common/platform.js +0 -245
- package/lib/vs/base/common/process.js +0 -52
- package/lib/vs/base/common/processes.js +0 -32
- package/lib/vs/base/common/range.js +0 -79
- package/lib/vs/base/common/resourceTree.js +0 -185
- package/lib/vs/base/common/resources.js +0 -421
- package/lib/vs/base/common/scanCode.js +0 -1472
- package/lib/vs/base/common/scrollable.js +0 -397
- package/lib/vs/base/common/search.js +0 -55
- package/lib/vs/base/common/sequence.js +0 -64
- package/lib/vs/base/common/severity.js +0 -55
- package/lib/vs/base/common/skipList.js +0 -234
- package/lib/vs/base/common/stopwatch.js +0 -45
- package/lib/vs/base/common/stream.js +0 -418
- package/lib/vs/base/common/strings.js +0 -1283
- package/lib/vs/base/common/styler.js +0 -9
- package/lib/vs/base/common/types.js +0 -296
- package/lib/vs/base/common/uint.js +0 -46
- package/lib/vs/base/common/uri.js +0 -756
- package/lib/vs/base/common/uriIpc.js +0 -154
- package/lib/vs/base/common/uuid.js +0 -70
- package/lib/vs/nls.mock.js +0 -31
- package/lib/vs/platform/actions/browser/menuEntryActionViewItem.js +0 -342
- package/lib/vs/platform/actions/common/actions.js +0 -456
- package/lib/vs/platform/actions/common/menuService.js +0 -194
- package/lib/vs/platform/clipboard/browser/clipboardService.js +0 -99
- package/lib/vs/platform/clipboard/common/clipboardService.js +0 -14
- package/lib/vs/platform/contextkey/common/contextkey.js +0 -1210
- package/lib/vs/platform/contextkey/common/contextkeys.js +0 -23
- package/lib/vs/platform/contextview/browser/contextView.js +0 -15
- package/lib/vs/platform/contextview/browser/contextViewService.js +0 -96
- package/lib/vs/platform/environment/common/argv.js +0 -9
- package/lib/vs/platform/environment/common/environment.js +0 -15
- package/lib/vs/platform/instantiation/common/descriptors.js +0 -25
- package/lib/vs/platform/instantiation/common/extensions.js +0 -26
- package/lib/vs/platform/instantiation/common/graph.js +0 -93
- package/lib/vs/platform/instantiation/common/instantiation.js +0 -84
- package/lib/vs/platform/instantiation/common/instantiationService.js +0 -361
- package/lib/vs/platform/instantiation/common/serviceCollection.js +0 -39
- package/lib/vs/platform/keybinding/common/baseResolvedKeybinding.js +0 -73
- package/lib/vs/platform/keybinding/common/keybinding.js +0 -14
- package/lib/vs/platform/keybinding/common/keybindingResolver.js +0 -391
- package/lib/vs/platform/keybinding/common/keybindingsRegistry.js +0 -229
- package/lib/vs/platform/keybinding/common/resolvedKeybindingItem.js +0 -47
- package/lib/vs/platform/keybinding/common/usLayoutResolvedKeybinding.js +0 -160
- package/lib/vs/platform/layout/browser/layoutService.js +0 -14
- package/lib/vs/platform/menubar/common/menubar.js +0 -34
- package/lib/vs/platform/registry/common/platform.js +0 -38
- package/lib/vs/platform/theme/browser/checkbox.js +0 -32
- package/lib/vs/platform/theme/common/colorRegistry.js +0 -1154
- package/lib/vs/platform/theme/common/styler.js +0 -290
- package/lib/vs/platform/theme/common/theme.js +0 -21
- package/lib/vs/platform/theme/common/themeService.js +0 -176
- package/lib/vs/platform/theme/common/tokenClassificationRegistry.js +0 -540
- package/lib/vs/platform/theme/test/common/testThemeService.js +0 -98
|
@@ -1,1108 +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
|
-
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
exports.LRUCache = exports.LinkedMap = exports.ResourceMap = exports.TernarySearchTree = exports.UriIterator = exports.PathIterator = exports.StringIterator = exports.setToString = exports.mapToString = exports.getOrSet = void 0;
|
|
11
|
-
|
|
12
|
-
const uri_1 = require("./uri");
|
|
13
|
-
|
|
14
|
-
const strings_1 = require("./strings");
|
|
15
|
-
|
|
16
|
-
function getOrSet(map, key, value) {
|
|
17
|
-
let result = map.get(key);
|
|
18
|
-
|
|
19
|
-
if (result === undefined) {
|
|
20
|
-
result = value;
|
|
21
|
-
map.set(key, result);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
exports.getOrSet = getOrSet;
|
|
28
|
-
|
|
29
|
-
function mapToString(map) {
|
|
30
|
-
const entries = [];
|
|
31
|
-
map.forEach((value, key) => {
|
|
32
|
-
entries.push(`${key} => ${value}`);
|
|
33
|
-
});
|
|
34
|
-
return `Map(${map.size}) {${entries.join(', ')}}`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
exports.mapToString = mapToString;
|
|
38
|
-
|
|
39
|
-
function setToString(set) {
|
|
40
|
-
const entries = [];
|
|
41
|
-
set.forEach(value => {
|
|
42
|
-
entries.push(value);
|
|
43
|
-
});
|
|
44
|
-
return `Set(${set.size}) {${entries.join(', ')}}`;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
exports.setToString = setToString;
|
|
48
|
-
|
|
49
|
-
class StringIterator {
|
|
50
|
-
constructor() {
|
|
51
|
-
this._value = '';
|
|
52
|
-
this._pos = 0;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
reset(key) {
|
|
56
|
-
this._value = key;
|
|
57
|
-
this._pos = 0;
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
next() {
|
|
62
|
-
this._pos += 1;
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
hasNext() {
|
|
67
|
-
return this._pos < this._value.length - 1;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
cmp(a) {
|
|
71
|
-
const aCode = a.charCodeAt(0);
|
|
72
|
-
|
|
73
|
-
const thisCode = this._value.charCodeAt(this._pos);
|
|
74
|
-
|
|
75
|
-
return aCode - thisCode;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
value() {
|
|
79
|
-
return this._value[this._pos];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
exports.StringIterator = StringIterator;
|
|
85
|
-
|
|
86
|
-
class PathIterator {
|
|
87
|
-
constructor(_splitOnBackslash = true, _caseSensitive = true) {
|
|
88
|
-
this._splitOnBackslash = _splitOnBackslash;
|
|
89
|
-
this._caseSensitive = _caseSensitive;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
reset(key) {
|
|
93
|
-
this._value = key.replace(/\\$|\/$/, '');
|
|
94
|
-
this._from = 0;
|
|
95
|
-
this._to = 0;
|
|
96
|
-
return this.next();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
hasNext() {
|
|
100
|
-
return this._to < this._value.length;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
next() {
|
|
104
|
-
// this._data = key.split(/[\\/]/).filter(s => !!s);
|
|
105
|
-
this._from = this._to;
|
|
106
|
-
let justSeps = true;
|
|
107
|
-
|
|
108
|
-
for (; this._to < this._value.length; this._to++) {
|
|
109
|
-
const ch = this._value.charCodeAt(this._to);
|
|
110
|
-
|
|
111
|
-
if (ch === 47
|
|
112
|
-
/* Slash */
|
|
113
|
-
|| this._splitOnBackslash && ch === 92
|
|
114
|
-
/* Backslash */
|
|
115
|
-
) {
|
|
116
|
-
if (justSeps) {
|
|
117
|
-
this._from++;
|
|
118
|
-
} else {
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
justSeps = false;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return this;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
cmp(a) {
|
|
130
|
-
return this._caseSensitive ? strings_1.compareSubstring(a, this._value, 0, a.length, this._from, this._to) : strings_1.compareSubstringIgnoreCase(a, this._value, 0, a.length, this._from, this._to);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
value() {
|
|
134
|
-
return this._value.substring(this._from, this._to);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
exports.PathIterator = PathIterator;
|
|
140
|
-
|
|
141
|
-
class UriIterator {
|
|
142
|
-
constructor(_ignorePathCasing) {
|
|
143
|
-
this._ignorePathCasing = _ignorePathCasing;
|
|
144
|
-
this._states = [];
|
|
145
|
-
this._stateIdx = 0;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
reset(key) {
|
|
149
|
-
this._value = key;
|
|
150
|
-
this._states = [];
|
|
151
|
-
|
|
152
|
-
if (this._value.scheme) {
|
|
153
|
-
this._states.push(1
|
|
154
|
-
/* Scheme */
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (this._value.authority) {
|
|
159
|
-
this._states.push(2
|
|
160
|
-
/* Authority */
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (this._value.path) {
|
|
165
|
-
this._pathIterator = new PathIterator(false, !this._ignorePathCasing);
|
|
166
|
-
|
|
167
|
-
this._pathIterator.reset(key.path);
|
|
168
|
-
|
|
169
|
-
if (this._pathIterator.value()) {
|
|
170
|
-
this._states.push(3
|
|
171
|
-
/* Path */
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (this._value.query) {
|
|
177
|
-
this._states.push(4
|
|
178
|
-
/* Query */
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (this._value.fragment) {
|
|
183
|
-
this._states.push(5
|
|
184
|
-
/* Fragment */
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
this._stateIdx = 0;
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
next() {
|
|
193
|
-
if (this._states[this._stateIdx] === 3
|
|
194
|
-
/* Path */
|
|
195
|
-
&& this._pathIterator.hasNext()) {
|
|
196
|
-
this._pathIterator.next();
|
|
197
|
-
} else {
|
|
198
|
-
this._stateIdx += 1;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return this;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
hasNext() {
|
|
205
|
-
return this._states[this._stateIdx] === 3
|
|
206
|
-
/* Path */
|
|
207
|
-
&& this._pathIterator.hasNext() || this._stateIdx < this._states.length - 1;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
cmp(a) {
|
|
211
|
-
if (this._states[this._stateIdx] === 1
|
|
212
|
-
/* Scheme */
|
|
213
|
-
) {
|
|
214
|
-
return strings_1.compareIgnoreCase(a, this._value.scheme);
|
|
215
|
-
} else if (this._states[this._stateIdx] === 2
|
|
216
|
-
/* Authority */
|
|
217
|
-
) {
|
|
218
|
-
return strings_1.compareIgnoreCase(a, this._value.authority);
|
|
219
|
-
} else if (this._states[this._stateIdx] === 3
|
|
220
|
-
/* Path */
|
|
221
|
-
) {
|
|
222
|
-
return this._pathIterator.cmp(a);
|
|
223
|
-
} else if (this._states[this._stateIdx] === 4
|
|
224
|
-
/* Query */
|
|
225
|
-
) {
|
|
226
|
-
return strings_1.compare(a, this._value.query);
|
|
227
|
-
} else if (this._states[this._stateIdx] === 5
|
|
228
|
-
/* Fragment */
|
|
229
|
-
) {
|
|
230
|
-
return strings_1.compare(a, this._value.fragment);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
throw new Error();
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
value() {
|
|
237
|
-
if (this._states[this._stateIdx] === 1
|
|
238
|
-
/* Scheme */
|
|
239
|
-
) {
|
|
240
|
-
return this._value.scheme;
|
|
241
|
-
} else if (this._states[this._stateIdx] === 2
|
|
242
|
-
/* Authority */
|
|
243
|
-
) {
|
|
244
|
-
return this._value.authority;
|
|
245
|
-
} else if (this._states[this._stateIdx] === 3
|
|
246
|
-
/* Path */
|
|
247
|
-
) {
|
|
248
|
-
return this._pathIterator.value();
|
|
249
|
-
} else if (this._states[this._stateIdx] === 4
|
|
250
|
-
/* Query */
|
|
251
|
-
) {
|
|
252
|
-
return this._value.query;
|
|
253
|
-
} else if (this._states[this._stateIdx] === 5
|
|
254
|
-
/* Fragment */
|
|
255
|
-
) {
|
|
256
|
-
return this._value.fragment;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
throw new Error();
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
exports.UriIterator = UriIterator;
|
|
265
|
-
|
|
266
|
-
class TernarySearchTreeNode {
|
|
267
|
-
isEmpty() {
|
|
268
|
-
return !this.left && !this.mid && !this.right && !this.value;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
class TernarySearchTree {
|
|
274
|
-
constructor(segments) {
|
|
275
|
-
this._iter = segments;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
static forUris(ignorePathCasing = false) {
|
|
279
|
-
return new TernarySearchTree(new UriIterator(ignorePathCasing));
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
static forPaths() {
|
|
283
|
-
return new TernarySearchTree(new PathIterator());
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
static forStrings() {
|
|
287
|
-
return new TernarySearchTree(new StringIterator());
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
clear() {
|
|
291
|
-
this._root = undefined;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
set(key, element) {
|
|
295
|
-
const iter = this._iter.reset(key);
|
|
296
|
-
|
|
297
|
-
let node;
|
|
298
|
-
|
|
299
|
-
if (!this._root) {
|
|
300
|
-
this._root = new TernarySearchTreeNode();
|
|
301
|
-
this._root.segment = iter.value();
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
node = this._root;
|
|
305
|
-
|
|
306
|
-
while (true) {
|
|
307
|
-
const val = iter.cmp(node.segment);
|
|
308
|
-
|
|
309
|
-
if (val > 0) {
|
|
310
|
-
// left
|
|
311
|
-
if (!node.left) {
|
|
312
|
-
node.left = new TernarySearchTreeNode();
|
|
313
|
-
node.left.segment = iter.value();
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
node = node.left;
|
|
317
|
-
} else if (val < 0) {
|
|
318
|
-
// right
|
|
319
|
-
if (!node.right) {
|
|
320
|
-
node.right = new TernarySearchTreeNode();
|
|
321
|
-
node.right.segment = iter.value();
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
node = node.right;
|
|
325
|
-
} else if (iter.hasNext()) {
|
|
326
|
-
// mid
|
|
327
|
-
iter.next();
|
|
328
|
-
|
|
329
|
-
if (!node.mid) {
|
|
330
|
-
node.mid = new TernarySearchTreeNode();
|
|
331
|
-
node.mid.segment = iter.value();
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
node = node.mid;
|
|
335
|
-
} else {
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
const oldElement = node.value;
|
|
341
|
-
node.value = element;
|
|
342
|
-
node.key = key;
|
|
343
|
-
return oldElement;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
get(key) {
|
|
347
|
-
const iter = this._iter.reset(key);
|
|
348
|
-
|
|
349
|
-
let node = this._root;
|
|
350
|
-
|
|
351
|
-
while (node) {
|
|
352
|
-
const val = iter.cmp(node.segment);
|
|
353
|
-
|
|
354
|
-
if (val > 0) {
|
|
355
|
-
// left
|
|
356
|
-
node = node.left;
|
|
357
|
-
} else if (val < 0) {
|
|
358
|
-
// right
|
|
359
|
-
node = node.right;
|
|
360
|
-
} else if (iter.hasNext()) {
|
|
361
|
-
// mid
|
|
362
|
-
iter.next();
|
|
363
|
-
node = node.mid;
|
|
364
|
-
} else {
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
return node ? node.value : undefined;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
delete(key) {
|
|
373
|
-
const iter = this._iter.reset(key);
|
|
374
|
-
|
|
375
|
-
const stack = [];
|
|
376
|
-
let node = this._root; // find and unset node
|
|
377
|
-
|
|
378
|
-
while (node) {
|
|
379
|
-
const val = iter.cmp(node.segment);
|
|
380
|
-
|
|
381
|
-
if (val > 0) {
|
|
382
|
-
// left
|
|
383
|
-
stack.push([1, node]);
|
|
384
|
-
node = node.left;
|
|
385
|
-
} else if (val < 0) {
|
|
386
|
-
// right
|
|
387
|
-
stack.push([-1, node]);
|
|
388
|
-
node = node.right;
|
|
389
|
-
} else if (iter.hasNext()) {
|
|
390
|
-
// mid
|
|
391
|
-
iter.next();
|
|
392
|
-
stack.push([0, node]);
|
|
393
|
-
node = node.mid;
|
|
394
|
-
} else {
|
|
395
|
-
// remove element
|
|
396
|
-
node.value = undefined; // clean up empty nodes
|
|
397
|
-
|
|
398
|
-
while (stack.length > 0 && node.isEmpty()) {
|
|
399
|
-
let [dir, parent] = stack.pop();
|
|
400
|
-
|
|
401
|
-
switch (dir) {
|
|
402
|
-
case 1:
|
|
403
|
-
parent.left = undefined;
|
|
404
|
-
break;
|
|
405
|
-
|
|
406
|
-
case 0:
|
|
407
|
-
parent.mid = undefined;
|
|
408
|
-
break;
|
|
409
|
-
|
|
410
|
-
case -1:
|
|
411
|
-
parent.right = undefined;
|
|
412
|
-
break;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
node = parent;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
break;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
findSubstr(key) {
|
|
424
|
-
const iter = this._iter.reset(key);
|
|
425
|
-
|
|
426
|
-
let node = this._root;
|
|
427
|
-
let candidate = undefined;
|
|
428
|
-
|
|
429
|
-
while (node) {
|
|
430
|
-
const val = iter.cmp(node.segment);
|
|
431
|
-
|
|
432
|
-
if (val > 0) {
|
|
433
|
-
// left
|
|
434
|
-
node = node.left;
|
|
435
|
-
} else if (val < 0) {
|
|
436
|
-
// right
|
|
437
|
-
node = node.right;
|
|
438
|
-
} else if (iter.hasNext()) {
|
|
439
|
-
// mid
|
|
440
|
-
iter.next();
|
|
441
|
-
candidate = node.value || candidate;
|
|
442
|
-
node = node.mid;
|
|
443
|
-
} else {
|
|
444
|
-
break;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
return node && node.value || candidate;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
findSuperstr(key) {
|
|
452
|
-
const iter = this._iter.reset(key);
|
|
453
|
-
|
|
454
|
-
let node = this._root;
|
|
455
|
-
|
|
456
|
-
while (node) {
|
|
457
|
-
const val = iter.cmp(node.segment);
|
|
458
|
-
|
|
459
|
-
if (val > 0) {
|
|
460
|
-
// left
|
|
461
|
-
node = node.left;
|
|
462
|
-
} else if (val < 0) {
|
|
463
|
-
// right
|
|
464
|
-
node = node.right;
|
|
465
|
-
} else if (iter.hasNext()) {
|
|
466
|
-
// mid
|
|
467
|
-
iter.next();
|
|
468
|
-
node = node.mid;
|
|
469
|
-
} else {
|
|
470
|
-
// collect
|
|
471
|
-
if (!node.mid) {
|
|
472
|
-
return undefined;
|
|
473
|
-
} else {
|
|
474
|
-
return this._values(node.mid);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
return undefined;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
forEach(callback) {
|
|
483
|
-
for (const [key, value] of this) {
|
|
484
|
-
callback(value, key);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
*[Symbol.iterator]() {
|
|
489
|
-
yield* this._entries(this._root);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
*_values(node) {
|
|
493
|
-
for (const [, value] of this._entries(node)) {
|
|
494
|
-
yield value;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
*_entries(node) {
|
|
499
|
-
if (node) {
|
|
500
|
-
// left
|
|
501
|
-
yield* this._entries(node.left); // node
|
|
502
|
-
|
|
503
|
-
if (node.value) {
|
|
504
|
-
// callback(node.value, this._iter.join(parts));
|
|
505
|
-
yield [node.key, node.value];
|
|
506
|
-
} // mid
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
yield* this._entries(node.mid); // right
|
|
510
|
-
|
|
511
|
-
yield* this._entries(node.right);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
exports.TernarySearchTree = TernarySearchTree;
|
|
518
|
-
|
|
519
|
-
class ResourceMap {
|
|
520
|
-
constructor(mapOrKeyFn, toKey) {
|
|
521
|
-
this[Symbol.toStringTag] = 'ResourceMap';
|
|
522
|
-
|
|
523
|
-
if (mapOrKeyFn instanceof ResourceMap) {
|
|
524
|
-
this.map = new Map(mapOrKeyFn.map);
|
|
525
|
-
this.toKey = toKey !== null && toKey !== void 0 ? toKey : ResourceMap.defaultToKey;
|
|
526
|
-
} else {
|
|
527
|
-
this.map = new Map();
|
|
528
|
-
this.toKey = mapOrKeyFn !== null && mapOrKeyFn !== void 0 ? mapOrKeyFn : ResourceMap.defaultToKey;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
set(resource, value) {
|
|
533
|
-
this.map.set(this.toKey(resource), value);
|
|
534
|
-
return this;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
get(resource) {
|
|
538
|
-
return this.map.get(this.toKey(resource));
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
has(resource) {
|
|
542
|
-
return this.map.has(this.toKey(resource));
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
get size() {
|
|
546
|
-
return this.map.size;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
clear() {
|
|
550
|
-
this.map.clear();
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
delete(resource) {
|
|
554
|
-
return this.map.delete(this.toKey(resource));
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
forEach(clb, thisArg) {
|
|
558
|
-
if (typeof thisArg !== 'undefined') {
|
|
559
|
-
clb = clb.bind(thisArg);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
for (let [index, value] of this.map) {
|
|
563
|
-
clb(value, uri_1.URI.parse(index), this);
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
values() {
|
|
568
|
-
return this.map.values();
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
*keys() {
|
|
572
|
-
for (let key of this.map.keys()) {
|
|
573
|
-
yield uri_1.URI.parse(key);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
*entries() {
|
|
578
|
-
for (let tuple of this.map.entries()) {
|
|
579
|
-
yield [uri_1.URI.parse(tuple[0]), tuple[1]];
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
*[Symbol.iterator]() {
|
|
584
|
-
for (let item of this.map) {
|
|
585
|
-
yield [uri_1.URI.parse(item[0]), item[1]];
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
exports.ResourceMap = ResourceMap;
|
|
592
|
-
|
|
593
|
-
ResourceMap.defaultToKey = resource => resource.toString();
|
|
594
|
-
|
|
595
|
-
class LinkedMap {
|
|
596
|
-
constructor() {
|
|
597
|
-
this[Symbol.toStringTag] = 'LinkedMap';
|
|
598
|
-
this._map = new Map();
|
|
599
|
-
this._head = undefined;
|
|
600
|
-
this._tail = undefined;
|
|
601
|
-
this._size = 0;
|
|
602
|
-
this._state = 0;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
clear() {
|
|
606
|
-
this._map.clear();
|
|
607
|
-
|
|
608
|
-
this._head = undefined;
|
|
609
|
-
this._tail = undefined;
|
|
610
|
-
this._size = 0;
|
|
611
|
-
this._state++;
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
isEmpty() {
|
|
615
|
-
return !this._head && !this._tail;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
get size() {
|
|
619
|
-
return this._size;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
get first() {
|
|
623
|
-
var _a;
|
|
624
|
-
|
|
625
|
-
return (_a = this._head) === null || _a === void 0 ? void 0 : _a.value;
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
get last() {
|
|
629
|
-
var _a;
|
|
630
|
-
|
|
631
|
-
return (_a = this._tail) === null || _a === void 0 ? void 0 : _a.value;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
has(key) {
|
|
635
|
-
return this._map.has(key);
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
get(key, touch = 0
|
|
639
|
-
/* None */
|
|
640
|
-
) {
|
|
641
|
-
const item = this._map.get(key);
|
|
642
|
-
|
|
643
|
-
if (!item) {
|
|
644
|
-
return undefined;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
if (touch !== 0
|
|
648
|
-
/* None */
|
|
649
|
-
) {
|
|
650
|
-
this.touch(item, touch);
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
return item.value;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
set(key, value, touch = 0
|
|
657
|
-
/* None */
|
|
658
|
-
) {
|
|
659
|
-
let item = this._map.get(key);
|
|
660
|
-
|
|
661
|
-
if (item) {
|
|
662
|
-
item.value = value;
|
|
663
|
-
|
|
664
|
-
if (touch !== 0
|
|
665
|
-
/* None */
|
|
666
|
-
) {
|
|
667
|
-
this.touch(item, touch);
|
|
668
|
-
}
|
|
669
|
-
} else {
|
|
670
|
-
item = {
|
|
671
|
-
key,
|
|
672
|
-
value,
|
|
673
|
-
next: undefined,
|
|
674
|
-
previous: undefined
|
|
675
|
-
};
|
|
676
|
-
|
|
677
|
-
switch (touch) {
|
|
678
|
-
case 0
|
|
679
|
-
/* None */
|
|
680
|
-
:
|
|
681
|
-
this.addItemLast(item);
|
|
682
|
-
break;
|
|
683
|
-
|
|
684
|
-
case 1
|
|
685
|
-
/* AsOld */
|
|
686
|
-
:
|
|
687
|
-
this.addItemFirst(item);
|
|
688
|
-
break;
|
|
689
|
-
|
|
690
|
-
case 2
|
|
691
|
-
/* AsNew */
|
|
692
|
-
:
|
|
693
|
-
this.addItemLast(item);
|
|
694
|
-
break;
|
|
695
|
-
|
|
696
|
-
default:
|
|
697
|
-
this.addItemLast(item);
|
|
698
|
-
break;
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
this._map.set(key, item);
|
|
702
|
-
|
|
703
|
-
this._size++;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
return this;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
delete(key) {
|
|
710
|
-
return !!this.remove(key);
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
remove(key) {
|
|
714
|
-
const item = this._map.get(key);
|
|
715
|
-
|
|
716
|
-
if (!item) {
|
|
717
|
-
return undefined;
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
this._map.delete(key);
|
|
721
|
-
|
|
722
|
-
this.removeItem(item);
|
|
723
|
-
this._size--;
|
|
724
|
-
return item.value;
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
shift() {
|
|
728
|
-
if (!this._head && !this._tail) {
|
|
729
|
-
return undefined;
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
if (!this._head || !this._tail) {
|
|
733
|
-
throw new Error('Invalid list');
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
const item = this._head;
|
|
737
|
-
|
|
738
|
-
this._map.delete(item.key);
|
|
739
|
-
|
|
740
|
-
this.removeItem(item);
|
|
741
|
-
this._size--;
|
|
742
|
-
return item.value;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
forEach(callbackfn, thisArg) {
|
|
746
|
-
const state = this._state;
|
|
747
|
-
let current = this._head;
|
|
748
|
-
|
|
749
|
-
while (current) {
|
|
750
|
-
if (thisArg) {
|
|
751
|
-
callbackfn.bind(thisArg)(current.value, current.key, this);
|
|
752
|
-
} else {
|
|
753
|
-
callbackfn(current.value, current.key, this);
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
if (this._state !== state) {
|
|
757
|
-
throw new Error(`LinkedMap got modified during iteration.`);
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
current = current.next;
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
keys() {
|
|
765
|
-
const map = this;
|
|
766
|
-
const state = this._state;
|
|
767
|
-
let current = this._head;
|
|
768
|
-
const iterator = {
|
|
769
|
-
[Symbol.iterator]() {
|
|
770
|
-
return iterator;
|
|
771
|
-
},
|
|
772
|
-
|
|
773
|
-
next() {
|
|
774
|
-
if (map._state !== state) {
|
|
775
|
-
throw new Error(`LinkedMap got modified during iteration.`);
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
if (current) {
|
|
779
|
-
const result = {
|
|
780
|
-
value: current.key,
|
|
781
|
-
done: false
|
|
782
|
-
};
|
|
783
|
-
current = current.next;
|
|
784
|
-
return result;
|
|
785
|
-
} else {
|
|
786
|
-
return {
|
|
787
|
-
value: undefined,
|
|
788
|
-
done: true
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
};
|
|
794
|
-
return iterator;
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
values() {
|
|
798
|
-
const map = this;
|
|
799
|
-
const state = this._state;
|
|
800
|
-
let current = this._head;
|
|
801
|
-
const iterator = {
|
|
802
|
-
[Symbol.iterator]() {
|
|
803
|
-
return iterator;
|
|
804
|
-
},
|
|
805
|
-
|
|
806
|
-
next() {
|
|
807
|
-
if (map._state !== state) {
|
|
808
|
-
throw new Error(`LinkedMap got modified during iteration.`);
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
if (current) {
|
|
812
|
-
const result = {
|
|
813
|
-
value: current.value,
|
|
814
|
-
done: false
|
|
815
|
-
};
|
|
816
|
-
current = current.next;
|
|
817
|
-
return result;
|
|
818
|
-
} else {
|
|
819
|
-
return {
|
|
820
|
-
value: undefined,
|
|
821
|
-
done: true
|
|
822
|
-
};
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
};
|
|
827
|
-
return iterator;
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
entries() {
|
|
831
|
-
const map = this;
|
|
832
|
-
const state = this._state;
|
|
833
|
-
let current = this._head;
|
|
834
|
-
const iterator = {
|
|
835
|
-
[Symbol.iterator]() {
|
|
836
|
-
return iterator;
|
|
837
|
-
},
|
|
838
|
-
|
|
839
|
-
next() {
|
|
840
|
-
if (map._state !== state) {
|
|
841
|
-
throw new Error(`LinkedMap got modified during iteration.`);
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
if (current) {
|
|
845
|
-
const result = {
|
|
846
|
-
value: [current.key, current.value],
|
|
847
|
-
done: false
|
|
848
|
-
};
|
|
849
|
-
current = current.next;
|
|
850
|
-
return result;
|
|
851
|
-
} else {
|
|
852
|
-
return {
|
|
853
|
-
value: undefined,
|
|
854
|
-
done: true
|
|
855
|
-
};
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
};
|
|
860
|
-
return iterator;
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
[Symbol.iterator]() {
|
|
864
|
-
return this.entries();
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
trimOld(newSize) {
|
|
868
|
-
if (newSize >= this.size) {
|
|
869
|
-
return;
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
if (newSize === 0) {
|
|
873
|
-
this.clear();
|
|
874
|
-
return;
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
let current = this._head;
|
|
878
|
-
let currentSize = this.size;
|
|
879
|
-
|
|
880
|
-
while (current && currentSize > newSize) {
|
|
881
|
-
this._map.delete(current.key);
|
|
882
|
-
|
|
883
|
-
current = current.next;
|
|
884
|
-
currentSize--;
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
this._head = current;
|
|
888
|
-
this._size = currentSize;
|
|
889
|
-
|
|
890
|
-
if (current) {
|
|
891
|
-
current.previous = undefined;
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
this._state++;
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
addItemFirst(item) {
|
|
898
|
-
// First time Insert
|
|
899
|
-
if (!this._head && !this._tail) {
|
|
900
|
-
this._tail = item;
|
|
901
|
-
} else if (!this._head) {
|
|
902
|
-
throw new Error('Invalid list');
|
|
903
|
-
} else {
|
|
904
|
-
item.next = this._head;
|
|
905
|
-
this._head.previous = item;
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
this._head = item;
|
|
909
|
-
this._state++;
|
|
910
|
-
}
|
|
911
|
-
|
|
912
|
-
addItemLast(item) {
|
|
913
|
-
// First time Insert
|
|
914
|
-
if (!this._head && !this._tail) {
|
|
915
|
-
this._head = item;
|
|
916
|
-
} else if (!this._tail) {
|
|
917
|
-
throw new Error('Invalid list');
|
|
918
|
-
} else {
|
|
919
|
-
item.previous = this._tail;
|
|
920
|
-
this._tail.next = item;
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
this._tail = item;
|
|
924
|
-
this._state++;
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
removeItem(item) {
|
|
928
|
-
if (item === this._head && item === this._tail) {
|
|
929
|
-
this._head = undefined;
|
|
930
|
-
this._tail = undefined;
|
|
931
|
-
} else if (item === this._head) {
|
|
932
|
-
// This can only happend if size === 1 which is handle
|
|
933
|
-
// by the case above.
|
|
934
|
-
if (!item.next) {
|
|
935
|
-
throw new Error('Invalid list');
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
item.next.previous = undefined;
|
|
939
|
-
this._head = item.next;
|
|
940
|
-
} else if (item === this._tail) {
|
|
941
|
-
// This can only happend if size === 1 which is handle
|
|
942
|
-
// by the case above.
|
|
943
|
-
if (!item.previous) {
|
|
944
|
-
throw new Error('Invalid list');
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
item.previous.next = undefined;
|
|
948
|
-
this._tail = item.previous;
|
|
949
|
-
} else {
|
|
950
|
-
const next = item.next;
|
|
951
|
-
const previous = item.previous;
|
|
952
|
-
|
|
953
|
-
if (!next || !previous) {
|
|
954
|
-
throw new Error('Invalid list');
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
next.previous = previous;
|
|
958
|
-
previous.next = next;
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
item.next = undefined;
|
|
962
|
-
item.previous = undefined;
|
|
963
|
-
this._state++;
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
touch(item, touch) {
|
|
967
|
-
if (!this._head || !this._tail) {
|
|
968
|
-
throw new Error('Invalid list');
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
if (touch !== 1
|
|
972
|
-
/* AsOld */
|
|
973
|
-
&& touch !== 2
|
|
974
|
-
/* AsNew */
|
|
975
|
-
) {
|
|
976
|
-
return;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
if (touch === 1
|
|
980
|
-
/* AsOld */
|
|
981
|
-
) {
|
|
982
|
-
if (item === this._head) {
|
|
983
|
-
return;
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
const next = item.next;
|
|
987
|
-
const previous = item.previous; // Unlink the item
|
|
988
|
-
|
|
989
|
-
if (item === this._tail) {
|
|
990
|
-
// previous must be defined since item was not head but is tail
|
|
991
|
-
// So there are more than on item in the map
|
|
992
|
-
previous.next = undefined;
|
|
993
|
-
this._tail = previous;
|
|
994
|
-
} else {
|
|
995
|
-
// Both next and previous are not undefined since item was neither head nor tail.
|
|
996
|
-
next.previous = previous;
|
|
997
|
-
previous.next = next;
|
|
998
|
-
} // Insert the node at head
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
item.previous = undefined;
|
|
1002
|
-
item.next = this._head;
|
|
1003
|
-
this._head.previous = item;
|
|
1004
|
-
this._head = item;
|
|
1005
|
-
this._state++;
|
|
1006
|
-
} else if (touch === 2
|
|
1007
|
-
/* AsNew */
|
|
1008
|
-
) {
|
|
1009
|
-
if (item === this._tail) {
|
|
1010
|
-
return;
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
const next = item.next;
|
|
1014
|
-
const previous = item.previous; // Unlink the item.
|
|
1015
|
-
|
|
1016
|
-
if (item === this._head) {
|
|
1017
|
-
// next must be defined since item was not tail but is head
|
|
1018
|
-
// So there are more than on item in the map
|
|
1019
|
-
next.previous = undefined;
|
|
1020
|
-
this._head = next;
|
|
1021
|
-
} else {
|
|
1022
|
-
// Both next and previous are not undefined since item was neither head nor tail.
|
|
1023
|
-
next.previous = previous;
|
|
1024
|
-
previous.next = next;
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
item.next = undefined;
|
|
1028
|
-
item.previous = this._tail;
|
|
1029
|
-
this._tail.next = item;
|
|
1030
|
-
this._tail = item;
|
|
1031
|
-
this._state++;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
toJSON() {
|
|
1036
|
-
const data = [];
|
|
1037
|
-
this.forEach((value, key) => {
|
|
1038
|
-
data.push([key, value]);
|
|
1039
|
-
});
|
|
1040
|
-
return data;
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
fromJSON(data) {
|
|
1044
|
-
this.clear();
|
|
1045
|
-
|
|
1046
|
-
for (const [key, value] of data) {
|
|
1047
|
-
this.set(key, value);
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
exports.LinkedMap = LinkedMap;
|
|
1054
|
-
|
|
1055
|
-
class LRUCache extends LinkedMap {
|
|
1056
|
-
constructor(limit, ratio = 1) {
|
|
1057
|
-
super();
|
|
1058
|
-
this._limit = limit;
|
|
1059
|
-
this._ratio = Math.min(Math.max(0, ratio), 1);
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
get limit() {
|
|
1063
|
-
return this._limit;
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
set limit(limit) {
|
|
1067
|
-
this._limit = limit;
|
|
1068
|
-
this.checkTrim();
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
get ratio() {
|
|
1072
|
-
return this._ratio;
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
set ratio(ratio) {
|
|
1076
|
-
this._ratio = Math.min(Math.max(0, ratio), 1);
|
|
1077
|
-
this.checkTrim();
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
get(key, touch = 2
|
|
1081
|
-
/* AsNew */
|
|
1082
|
-
) {
|
|
1083
|
-
return super.get(key, touch);
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
peek(key) {
|
|
1087
|
-
return super.get(key, 0
|
|
1088
|
-
/* None */
|
|
1089
|
-
);
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
set(key, value) {
|
|
1093
|
-
super.set(key, value, 2
|
|
1094
|
-
/* AsNew */
|
|
1095
|
-
);
|
|
1096
|
-
this.checkTrim();
|
|
1097
|
-
return this;
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
checkTrim() {
|
|
1101
|
-
if (this.size > this._limit) {
|
|
1102
|
-
this.trimOld(Math.round(this._limit * this._ratio));
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
exports.LRUCache = LRUCache;
|