@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
133 lines • 4.75 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const widget_utilities_1 = __importDefault(require("../widget.utilities"));
const termKitUtil = {
buildFrame(frame, parent) {
const calculated = widget_utilities_1.default.buildFrame(frame, parent);
return {
x: calculated.left,
y: calculated.top,
width: calculated.width,
height: calculated.height,
};
},
mapWidgetOptionsToTermKitOptions(options) {
const mapped = {};
const keys = Object.keys(options);
const ignores = [
'shouldLockHeightWithParent',
'shouldLockWidthWithParent',
'shouldLockBottomWithParent',
'term',
];
if (options.backgroundColor) {
mapped.attr = {
...mapped.attr,
bgColor: options.backgroundColor,
};
}
if (options.foregroundColor) {
mapped.attr = {
...mapped.attr,
color: options.foregroundColor,
};
}
for (const key of keys) {
const item = options[key];
if (Array.isArray(item)) {
mapped[key] = [];
for (const i of item) {
mapped[key].push(this.mapWidgetOptionsToTermKitOptions(i));
}
}
else {
switch (key) {
case 'left':
mapped.x = item;
break;
case 'top':
mapped.y = item;
break;
case 'width':
if (typeof item === 'string') {
mapped.widthPercent = parseInt(item);
}
else {
mapped.width = item;
}
break;
case 'height':
if (typeof item === 'string') {
mapped.heightPercent = parseInt(item);
}
else {
mapped.height = item;
}
break;
case 'parent':
mapped.parent = item.getTermKitElement();
break;
default:
if (ignores.indexOf(key) > -1) {
break;
}
if (typeof item !== 'function' && (0, lodash_1.isObject)(item)) {
mapped[key] =
this.mapWidgetOptionsToTermKitOptions(item);
}
else {
mapped[key] = item;
}
}
}
}
return mapped;
},
mapTermKitOptionsToWidgetOptions(options) {
const mapped = {};
const keys = Object.keys(options);
for (const key of keys) {
const item = options[key];
if (Array.isArray(item)) {
mapped[key] = [];
for (const i of item) {
mapped[key].push(this.mapTermKitOptionsToWidgetOptions(i));
}
}
else {
switch (key) {
case 'left':
mapped.x = item;
break;
case 'top':
mapped.y = item;
break;
case 'widthPercent':
mapped.width = `${item}%`;
break;
case 'heightPercent':
mapped.height = `${item}%`;
break;
case 'parent':
mapped.parent = item.getTermKitElement();
break;
default:
if (typeof item !== 'function' && (0, lodash_1.isObject)(item)) {
mapped[key] =
this.mapTermKitOptionsToWidgetOptions(item);
}
else {
mapped[key] = item;
}
}
}
}
return mapped;
},
};
exports.default = termKitUtil;
//# sourceMappingURL=termKit.utility.js.map