UNPKG

6.64 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2019 Ericsson and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.WidgetDecoration = void 0;
19/**
20 * Namespace for the decoration data and the styling refinements for the decorated widgets.
21 */
22var WidgetDecoration;
23(function (WidgetDecoration) {
24 /**
25 * CSS styles for the decorators.
26 */
27 let Styles;
28 (function (Styles) {
29 Styles.CAPTION_HIGHLIGHT_CLASS = 'theia-caption-highlight';
30 Styles.CAPTION_PREFIX_CLASS = 'theia-caption-prefix';
31 Styles.CAPTION_SUFFIX_CLASS = 'theia-caption-suffix';
32 Styles.ICON_WRAPPER_CLASS = 'theia-icon-wrapper';
33 Styles.DECORATOR_SIZE_CLASS = 'theia-decorator-size';
34 Styles.DECORATOR_SIDEBAR_SIZE_CLASS = 'theia-decorator-sidebar-size';
35 Styles.TOP_RIGHT_CLASS = 'theia-top-right';
36 Styles.BOTTOM_RIGHT_CLASS = 'theia-bottom-right';
37 Styles.BOTTOM_RIGHT_SIDEBAR_CLASS = 'theia-bottom-right-sidebar';
38 Styles.BOTTOM_LEFT_CLASS = 'theia-bottom-left';
39 Styles.TOP_LEFT_CLASS = 'theia-top-left';
40 })(Styles = WidgetDecoration.Styles || (WidgetDecoration.Styles = {}));
41 let TailDecoration;
42 (function (TailDecoration) {
43 function isDotDecoration(decoration) {
44 return decoration.icon === 'circle';
45 }
46 TailDecoration.isDotDecoration = isDotDecoration;
47 })(TailDecoration = WidgetDecoration.TailDecoration || (WidgetDecoration.TailDecoration = {}));
48 /**
49 * Enumeration for the quadrant to overlay the image on.
50 */
51 let IconOverlayPosition;
52 (function (IconOverlayPosition) {
53 /**
54 * Overlays the top right quarter of the original image.
55 */
56 IconOverlayPosition[IconOverlayPosition["TOP_RIGHT"] = 0] = "TOP_RIGHT";
57 /**
58 * Overlays the bottom right of the original image.
59 */
60 IconOverlayPosition[IconOverlayPosition["BOTTOM_RIGHT"] = 1] = "BOTTOM_RIGHT";
61 /**
62 * Overlays the bottom left segment of the original image.
63 */
64 IconOverlayPosition[IconOverlayPosition["BOTTOM_LEFT"] = 2] = "BOTTOM_LEFT";
65 /**
66 * Occupies the top left quarter of the original icon.
67 */
68 IconOverlayPosition[IconOverlayPosition["TOP_LEFT"] = 3] = "TOP_LEFT";
69 })(IconOverlayPosition = WidgetDecoration.IconOverlayPosition || (WidgetDecoration.IconOverlayPosition = {}));
70 (function (IconOverlayPosition) {
71 /**
72 * Returns with the CSS class style for the enum.
73 */
74 function getStyle(position, inSideBar) {
75 switch (position) {
76 case IconOverlayPosition.TOP_RIGHT:
77 return WidgetDecoration.Styles.TOP_RIGHT_CLASS;
78 case IconOverlayPosition.BOTTOM_RIGHT:
79 return inSideBar ? WidgetDecoration.Styles.BOTTOM_RIGHT_SIDEBAR_CLASS : WidgetDecoration.Styles.BOTTOM_RIGHT_CLASS;
80 case IconOverlayPosition.BOTTOM_LEFT:
81 return WidgetDecoration.Styles.BOTTOM_LEFT_CLASS;
82 case IconOverlayPosition.TOP_LEFT:
83 return WidgetDecoration.Styles.TOP_LEFT_CLASS;
84 }
85 }
86 IconOverlayPosition.getStyle = getStyle;
87 })(IconOverlayPosition = WidgetDecoration.IconOverlayPosition || (WidgetDecoration.IconOverlayPosition = {}));
88 let CaptionHighlight;
89 (function (CaptionHighlight) {
90 let Range;
91 (function (Range) {
92 /**
93 * `true` if the `arg` is contained in the range. The ranges are closed ranges, hence the check is inclusive.
94 */
95 function contains(arg, range) {
96 return arg >= range.offset && arg <= (range.offset + range.length);
97 }
98 Range.contains = contains;
99 })(Range = CaptionHighlight.Range || (CaptionHighlight.Range = {}));
100 /**
101 * Splits the `caption` argument based on the ranges from the `highlight` argument.
102 */
103 function split(caption, highlight) {
104 const result = [];
105 const ranges = highlight.ranges.slice();
106 const containerOf = (index) => ranges.findIndex(range => Range.contains(index, range));
107 let data = '';
108 for (let i = 0; i < caption.length; i++) {
109 const containerIndex = containerOf(i);
110 if (containerIndex === -1) {
111 data += caption[i];
112 }
113 else {
114 if (data.length > 0) {
115 result.push({ data });
116 }
117 const { length } = ranges.splice(containerIndex, 1).shift();
118 result.push({ data: caption.substring(i, i + length), highlight: true });
119 data = '';
120 i = i + length - 1;
121 }
122 }
123 if (data.length > 0) {
124 result.push({ data });
125 }
126 if (ranges.length !== 0) {
127 throw new Error('Error occurred when splitting the caption. There was a mismatch between the caption and the corresponding highlighting ranges.');
128 }
129 return result;
130 }
131 CaptionHighlight.split = split;
132 })(CaptionHighlight = WidgetDecoration.CaptionHighlight || (WidgetDecoration.CaptionHighlight = {}));
133 let Data;
134 (function (Data) {
135 /**
136 * Compares the decoration data based on the priority. Lowest priorities come first (i.e. left.priority - right.priority).
137 */
138 Data.comparePriority = (left, right) => (left.priority || 0) - (right.priority || 0);
139 })(Data = WidgetDecoration.Data || (WidgetDecoration.Data = {}));
140})(WidgetDecoration = exports.WidgetDecoration || (exports.WidgetDecoration = {}));
141//# sourceMappingURL=widget-decoration.js.map
\No newline at end of file