@vericus/slate-kit-highlight-text
Version:
plugin that provide a way to color/highlight a group of text on slate
25 lines • 1.21 kB
JavaScript
import * as tslib_1 from "tslib";
import tinycolor from "tinycolor2";
var defaultStyle = {
textDecoration: "inherit",
textDecorationColor: "inherit",
};
export default function createProps(opts) {
var type = opts.type, dataField = opts.data, styleFields = opts.styles, alpha = opts.alpha;
return function (props) {
var _a;
if (!props.mark || props.mark.type !== type)
return props;
var attributes = props.attributes, data = props.mark.data;
var style = (attributes || { style: {} }).style;
var color = tinycolor(data.get(dataField));
style = tslib_1.__assign({}, defaultStyle, style, { textDecoration: "inherit", decorationStyle: "initial" }, styleFields.reduce(function (acc, styleField) {
var _a;
return (tslib_1.__assign({}, acc, (_a = {}, _a[styleField] = color.setAlpha(alpha).toRgbString(), _a)));
}, {}));
return tslib_1.__assign({}, props, { attributes: tslib_1.__assign({}, props.attributes, (_a = { style: style }, _a["data-slate-kit-" + type.toLowerCase()] = color
.setAlpha(alpha)
.toRgbString(), _a)) });
};
}
//# sourceMappingURL=index.js.map