@difizen/mana-app
Version:
133 lines (132 loc) • 4.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TreeViewDecorationStyles = exports.TreeViewDecorationData = exports.TreeViewDecoration = exports.IconOverlayPosition = exports.CaptionHighlight = void 0;
var TreeViewDecorationStyles = exports.TreeViewDecorationStyles = {
CAPTION_HIGHLIGHT_CLASS: 'mana-caption-highlight',
CAPTION_PREFIX_CLASS: 'mana-caption-prefix',
CAPTION_SUFFIX_CLASS: 'mana-caption-suffix',
ICON_WRAPPER_CLASS: 'mana-icon-wrapper',
DECORATOR_SIZE_CLASS: 'mana-decorator-size',
DECORATOR_SIDEBAR_SIZE_CLASS: 'mana-decorator-sidebar-size',
TOP_RIGHT_CLASS: 'mana-top-right',
BOTTOM_RIGHT_CLASS: 'mana-bottom-right',
BOTTOM_RIGHT_SIDEBAR_CLASS: 'mana-bottom-right-sidebar',
BOTTOM_LEFT_CLASS: 'mana-bottom-left',
TOP_LEFT_CLASS: 'mana-top-left'
};
/**
* Enumeration for the quadrant to overlay the image on.
*/
var IconOverlayPosition = exports.IconOverlayPosition = /*#__PURE__*/function (IconOverlayPosition) {
/**
* Overlays the top right quarter of the original image.
*/
IconOverlayPosition[IconOverlayPosition["TOP_RIGHT"] = 0] = "TOP_RIGHT";
/**
* Overlays the bottom right of the original image.
*/
IconOverlayPosition[IconOverlayPosition["BOTTOM_RIGHT"] = 1] = "BOTTOM_RIGHT";
/**
* Overlays the bottom left segment of the original image.
*/
IconOverlayPosition[IconOverlayPosition["BOTTOM_LEFT"] = 2] = "BOTTOM_LEFT";
/**
* Occupies the top left quarter of the original icon.
*/
IconOverlayPosition[IconOverlayPosition["TOP_LEFT"] = 3] = "TOP_LEFT";
return IconOverlayPosition;
}({});
(function (_IconOverlayPosition) {
function getStyle(position, inSideBar) {
switch (position) {
case IconOverlayPosition.TOP_RIGHT:
return TreeViewDecorationStyles.TOP_RIGHT_CLASS;
case IconOverlayPosition.BOTTOM_RIGHT:
return inSideBar ? TreeViewDecorationStyles.BOTTOM_RIGHT_SIDEBAR_CLASS : TreeViewDecorationStyles.BOTTOM_RIGHT_CLASS;
case IconOverlayPosition.BOTTOM_LEFT:
return TreeViewDecorationStyles.BOTTOM_LEFT_CLASS;
case IconOverlayPosition.TOP_LEFT:
return TreeViewDecorationStyles.TOP_LEFT_CLASS;
default:
return '';
}
}
_IconOverlayPosition.getStyle = getStyle;
})(IconOverlayPosition || (exports.IconOverlayPosition = IconOverlayPosition = {}));
var CaptionHighlight;
(function (_CaptionHighlight) {
/**
* A pair of offset and length that has to be highlighted as a range.
*/
var Range;
(function (_Range) {
function contains(arg, range) {
return arg >= range.offset && arg <= range.offset + range.length;
}
_Range.contains = contains;
})(Range || (Range = _CaptionHighlight.Range || (_CaptionHighlight.Range = {})));
/**
* The result of a caption splitting based on the highlighting information.
*/
/**
* Splits the `caption` argument based on the ranges from the `highlight` argument.
*/
function split(caption, highlight) {
var result = [];
var ranges = highlight.ranges.slice();
var containerOf = function containerOf(index) {
return ranges.findIndex(function (range) {
return Range.contains(index, range);
});
};
var data = '';
for (var i = 0; i < caption.length; i += 1) {
var containerIndex = containerOf(i);
if (containerIndex === -1) {
data += caption[i];
} else {
if (data.length > 0) {
result.push({
data: data
});
}
var _ref = ranges.splice(containerIndex, 1).shift(),
length = _ref.length;
result.push({
data: caption.substr(i, length),
highlight: true
});
data = '';
i = i + length - 1;
}
}
if (data.length > 0) {
result.push({
data: data
});
}
if (ranges.length !== 0) {
throw new Error('Error occurred when splitting the caption. There was a mismatch between the caption and the corresponding highlighting ranges.');
}
return result;
}
_CaptionHighlight.split = split;
})(CaptionHighlight || (exports.CaptionHighlight = CaptionHighlight = {}));
/**
* The caption highlighting with the highlighted ranges and an optional background color.
*/
/**
* Namespace for the decoration data and the styling refinements for the decorated widgets.
*/
var TreeViewDecoration;
/**
* Encapsulates styling information that has to be applied on the widget which we decorate.
*/
var TreeViewDecorationData;
(function (_TreeViewDecorationData) {
var comparePriority = _TreeViewDecorationData.comparePriority = function (left, right) {
return (left.priority || 0) - (right.priority || 0);
};
})(TreeViewDecorationData || (exports.TreeViewDecorationData = TreeViewDecorationData = {}));