@vericus/slate-kit-highlight-text
Version:
plugin that provide a way to color/highlight a group of text on slate
64 lines • 2.24 kB
JavaScript
import * as tslib_1 from "tslib";
import { Record } from "immutable";
import isPlainObject from "is-plain-obj";
var defaultOptions = {
name: undefined,
marks: undefined,
type: undefined,
styles: undefined,
data: undefined,
defaultColor: undefined,
alpha: 1,
renderer: undefined,
label: undefined,
};
var Options = /** @class */ (function (_super) {
tslib_1.__extends(Options, _super);
function Options() {
return _super !== null && _super.apply(this, arguments) || this;
}
Options.create = function (attrs) {
if (attrs === void 0) { attrs = {}; }
if (Options.isOptions(attrs))
return attrs;
if (isPlainObject(attrs))
return Options.fromJSON(attrs);
throw new Error("`Options.create` only accepts objects, strings or options");
};
Options.fromJSON = function (object) {
var _a;
if (Options.isOptions(object))
return object;
var name = object.name, type = object.type, data = object.data, styles = object.styles, defaultColor = object.defaultColor, _b = object.alpha, alpha = _b === void 0 ? 1 : _b, renderer = object.renderer;
if (!type || !data || !styles || !defaultColor || !Array.isArray(styles)) {
throw new Error("Highlight text require type, data and style option");
}
if (alpha < 0 || alpha > 1) {
throw new Error("Alpha value can only go from 0 to 1");
}
return new Options({
marks: (_a = {},
_a[type] = type,
_a),
type: type,
data: data,
styles: styles,
alpha: alpha,
defaultColor: defaultColor,
name: name,
renderer: renderer,
});
};
Options.isOptions = function (args) {
if (args instanceof Record) {
var record_1 = args;
return ["marks", "type", "data", "styles", "defaultColor"].every(function (key) {
return record_1.has(key);
});
}
return false;
};
return Options;
}(Record(defaultOptions, "highlight text option")));
export default Options;
//# sourceMappingURL=index.js.map