UNPKG

graphics-ts

Version:

A porting of purescript-{canvas, free-canvas, drawing} featuring fp-ts

71 lines (70 loc) 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.showFont = exports.showFontOptions = exports.font = exports.fontOptions = void 0; /** * @since 1.0.0 */ var A = require("fp-ts/lib/Array"); var B = require("fp-ts/lib/boolean"); var O = require("fp-ts/lib/Option"); var RR = require("fp-ts/lib/ReadonlyRecord"); var Monoid_1 = require("fp-ts/lib/Monoid"); var Foldable_1 = require("fp-ts/lib/Foldable"); var pipeable_1 = require("fp-ts/lib/pipeable"); // ------------------------------------------------------------------------------------- // constructors // ------------------------------------------------------------------------------------- /** * Constructs a new `FontOptions` object. * * @category constructors * @since 1.0.0 */ exports.fontOptions = function (_a) { var style = _a.style, variant = _a.variant, weight = _a.weight; return ({ style: O.fromNullable(style), variant: O.fromNullable(variant), weight: O.fromNullable(weight) }); }; /** * Constructs a new `Font`. * * @category constructors * @since 1.0.0 */ exports.font = function (fontFamily, size, options) { return ({ fontFamily: fontFamily, size: size, fontOptions: typeof options === 'object' ? options : exports.fontOptions({}) }); }; // ------------------------------------------------------------------------------------- // instances // ------------------------------------------------------------------------------------- /** * The `Show` instance for `FontOptions`. * * @category instances * @since 1.0.0 */ exports.showFontOptions = { show: function (o) { return Foldable_1.intercalate(Monoid_1.monoidString, RR.readonlyRecord)(' ', RR.compact(RR.fromRecord(o))); } }; /** * The `Show` instance for `Font`. * * @category instances * @since 1.0.0 */ exports.showFont = { show: function (_a) { var fontFamily = _a.fontFamily, size = _a.size, fontOptions = _a.fontOptions; return Foldable_1.intercalate(Monoid_1.monoidString, A.array)(' ', A.compact([ // Determine if any font options were specified pipeable_1.pipe(fontOptions, RR.fromRecord, RR.compact, RR.isEmpty, B.fold(function () { return O.some(exports.showFontOptions.show(fontOptions)); }, function () { return O.none; })), O.some(size + "px"), O.some(fontFamily) ])); } };