1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | Object.defineProperty(exports, "__esModule", { value: true });
|
22 | exports.measureTextHeight = exports.measureTextWidth = exports.preventNavigation = exports.parseCssTime = exports.parseCssMagnitude = exports.animationFrame = exports.isBasicWasmSupported = exports.isNative = exports.isIPad = exports.isSafari = exports.isChrome = exports.isWebKit = exports.isFirefox = exports.isOpera = exports.isEdgeOrIE = exports.isEdge = exports.isIE = void 0;
|
23 | const userAgent = typeof navigator !== 'undefined' ? navigator.userAgent : '';
|
24 | exports.isIE = (userAgent.indexOf('Trident') >= 0);
|
25 | exports.isEdge = (userAgent.indexOf('Edge/') >= 0);
|
26 | exports.isEdgeOrIE = exports.isIE || exports.isEdge;
|
27 | exports.isOpera = (userAgent.indexOf('Opera') >= 0);
|
28 | exports.isFirefox = (userAgent.indexOf('Firefox') >= 0);
|
29 | exports.isWebKit = (userAgent.indexOf('AppleWebKit') >= 0);
|
30 | exports.isChrome = (userAgent.indexOf('Chrome') >= 0);
|
31 | exports.isSafari = (userAgent.indexOf('Chrome') === -1) && (userAgent.indexOf('Safari') >= 0);
|
32 | exports.isIPad = (userAgent.indexOf('iPad') >= 0);
|
33 |
|
34 | exports.isNative = typeof window.process !== 'undefined';
|
35 |
|
36 | exports.isBasicWasmSupported = typeof window.WebAssembly !== 'undefined';
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | function animationFrame(n = 1) {
|
42 | return new Promise(resolve => {
|
43 | function frameFunc() {
|
44 | if (n <= 0) {
|
45 | resolve();
|
46 | }
|
47 | else {
|
48 | n--;
|
49 | requestAnimationFrame(frameFunc);
|
50 | }
|
51 | }
|
52 | frameFunc();
|
53 | });
|
54 | }
|
55 | exports.animationFrame = animationFrame;
|
56 | function parseCssMagnitude(value, defaultValue) {
|
57 | if (value) {
|
58 | let parsed;
|
59 | if (value.endsWith('px')) {
|
60 | parsed = parseFloat(value.substring(0, value.length - 2));
|
61 | }
|
62 | else {
|
63 | parsed = parseFloat(value);
|
64 | }
|
65 | if (!isNaN(parsed)) {
|
66 | return parsed;
|
67 | }
|
68 | }
|
69 | return defaultValue;
|
70 | }
|
71 | exports.parseCssMagnitude = parseCssMagnitude;
|
72 | function parseCssTime(time, defaultValue) {
|
73 | if (time) {
|
74 | let parsed;
|
75 | if (time.endsWith('ms')) {
|
76 | parsed = parseFloat(time.substring(0, time.length - 2));
|
77 | }
|
78 | else if (time.endsWith('s')) {
|
79 | parsed = parseFloat(time.substring(0, time.length - 1)) * 1000;
|
80 | }
|
81 | else {
|
82 | parsed = parseFloat(time);
|
83 | }
|
84 | if (!isNaN(parsed)) {
|
85 | return parsed;
|
86 | }
|
87 | }
|
88 | return defaultValue;
|
89 | }
|
90 | exports.parseCssTime = parseCssTime;
|
91 | function getMonacoEditorScroll(elem) {
|
92 | const linesContent = elem.querySelector('.lines-content');
|
93 | const viewLines = elem.querySelector('.view-lines');
|
94 |
|
95 | if (linesContent === null || viewLines === null) {
|
96 | return undefined;
|
97 | }
|
98 | const linesContentStyle = linesContent.style;
|
99 | const elemStyle = elem.style;
|
100 | const viewLinesStyle = viewLines.style;
|
101 | return {
|
102 | left: -parseCssMagnitude(linesContentStyle.left, 0),
|
103 | top: -parseCssMagnitude(linesContentStyle.top, 0),
|
104 | maxLeft: parseCssMagnitude(viewLinesStyle.width, 0) - parseCssMagnitude(elemStyle.width, 0),
|
105 | maxTop: parseCssMagnitude(viewLinesStyle.height, 0) - parseCssMagnitude(elemStyle.height, 0)
|
106 | };
|
107 | }
|
108 |
|
109 |
|
110 |
|
111 | function preventNavigation(event) {
|
112 | const { currentTarget, deltaX, deltaY } = event;
|
113 | const absDeltaX = Math.abs(deltaX);
|
114 | const absDeltaY = Math.abs(deltaY);
|
115 | let elem = event.target;
|
116 | while (elem && elem !== currentTarget) {
|
117 | let scroll;
|
118 | if (elem.classList.contains('monaco-scrollable-element')) {
|
119 | scroll = getMonacoEditorScroll(elem);
|
120 | }
|
121 | else {
|
122 | scroll = {
|
123 | left: elem.scrollLeft,
|
124 | top: elem.scrollTop,
|
125 | maxLeft: elem.scrollWidth - elem.clientWidth,
|
126 | maxTop: elem.scrollHeight - elem.clientHeight
|
127 | };
|
128 | }
|
129 | if (scroll) {
|
130 | const scrollH = scroll.maxLeft > 0 && (deltaX < 0 && scroll.left > 0 || deltaX > 0 && scroll.left < scroll.maxLeft);
|
131 | const scrollV = scroll.maxTop > 0 && (deltaY < 0 && scroll.top > 0 || deltaY > 0 && scroll.top < scroll.maxTop);
|
132 | if (scrollH && scrollV || scrollH && absDeltaX > absDeltaY || scrollV && absDeltaY > absDeltaX) {
|
133 |
|
134 | return;
|
135 | }
|
136 | }
|
137 | elem = elem.parentElement;
|
138 | }
|
139 | event.preventDefault();
|
140 | event.stopPropagation();
|
141 | }
|
142 | exports.preventNavigation = preventNavigation;
|
143 | function measureTextWidth(text, style) {
|
144 | const measureElement = getMeasurementElement(style);
|
145 | text = Array.isArray(text) ? text : [text];
|
146 | let width = 0;
|
147 | for (const item of text) {
|
148 | measureElement.textContent = item;
|
149 | width = Math.max(measureElement.getBoundingClientRect().width, width);
|
150 | }
|
151 | return width;
|
152 | }
|
153 | exports.measureTextWidth = measureTextWidth;
|
154 | function measureTextHeight(text, style) {
|
155 | const measureElement = getMeasurementElement(style);
|
156 | text = Array.isArray(text) ? text : [text];
|
157 | let height = 0;
|
158 | for (const item of text) {
|
159 | measureElement.textContent = item;
|
160 | height = Math.max(measureElement.getBoundingClientRect().height, height);
|
161 | }
|
162 | return height;
|
163 | }
|
164 | exports.measureTextHeight = measureTextHeight;
|
165 | const defaultStyle = document.createElement('div').style;
|
166 | defaultStyle.fontFamily = 'var(--theia-ui-font-family)';
|
167 | defaultStyle.fontSize = 'var(--theia-ui-font-size1)';
|
168 | defaultStyle.visibility = 'hidden';
|
169 | function getMeasurementElement(style) {
|
170 | let measureElement = document.getElementById('measure');
|
171 | if (!measureElement) {
|
172 | measureElement = document.createElement('span');
|
173 | measureElement.id = 'measure';
|
174 | measureElement.style.fontFamily = defaultStyle.fontFamily;
|
175 | measureElement.style.fontSize = defaultStyle.fontSize;
|
176 | measureElement.style.visibility = defaultStyle.visibility;
|
177 | document.body.appendChild(measureElement);
|
178 | }
|
179 | const measureStyle = measureElement.style;
|
180 |
|
181 | for (let i = 0; i < measureStyle.length; i++) {
|
182 | const property = measureStyle[i];
|
183 | measureStyle.setProperty(property, defaultStyle.getPropertyValue(property));
|
184 | }
|
185 |
|
186 | if (style) {
|
187 | for (const [key, value] of Object.entries(style)) {
|
188 | measureStyle.setProperty(key, value);
|
189 | }
|
190 | }
|
191 | return measureElement;
|
192 | }
|
193 |
|
\ | No newline at end of file |