UNPKG

@parischap/pretty-print

Version:
148 lines (146 loc) 5.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.styles = exports.none = exports.moduleTag = exports.make = exports.id = exports.has = exports.get = exports.equivalence = exports.darkMode = void 0; var _ansiStyles = /*#__PURE__*/require("@parischap/ansi-styles"); var _effectLib = /*#__PURE__*/require("@parischap/effect-lib"); var _effect = /*#__PURE__*/require("effect"); var PPValueBasedStyler = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("./ValueBasedStyler.js")); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /** * This module implements a map of ContextStyler's (see * * @parischap/ansi-styles/ContextStyler.ts). These ContextStyler's are used to style the different parts of a * stringified value. * * With the make function, you can define your own instances if the provided ones don't suit your * needs. */ /** * Module tag * * @category Models */ const moduleTag = exports.moduleTag = '@parischap/pretty-print/StyleMap/'; const _TypeId = /*#__PURE__*/Symbol.for(moduleTag); /** * Type guard * * @category Guards */ const has = u => _effect.Predicate.hasProperty(u, _TypeId); /** * Equivalence * * @category Equivalences */ exports.has = has; const equivalence = (self, that) => that.id === self.id; /** Prototype */ exports.equivalence = equivalence; const _TypeIdHash = /*#__PURE__*/_effect.Hash.hash(_TypeId); const proto = { [_TypeId]: _TypeId, [_effect.Equal.symbol](that) { return has(that) && equivalence(this, that); }, [_effect.Hash.symbol]() { return (0, _effect.pipe)(this.id, _effect.Hash.hash, _effect.Hash.combine(_TypeIdHash), _effect.Hash.cached(this)); }, [_effectLib.MInspectable.IdSymbol]() { return this.id; }, ... /*#__PURE__*/_effectLib.MInspectable.BaseProto(moduleTag), ..._effectLib.MPipeable.BaseProto }; /** * Constructor * * @category Constructors */ const make = params => _effectLib.MTypes.objectFromDataAndProto(proto, params); /** * Returns the `id` property of `self` * * @category Destructors */ exports.make = make; const id = exports.id = /*#__PURE__*/_effect.Struct.get('id'); /** * Returns the `styles` property of `self` * * @category Destructors */ const styles = exports.styles = /*#__PURE__*/_effect.Struct.get('styles'); /** * Returns the ValueBasedStyler associated with `partName` which identifies a part of a stringified * value. Returns `ASContextStyler.none` if `partName` is not present in `self`. * * @category Destructors */ const get = partName => (0, _effect.flow)(styles, _effect.HashMap.get(partName), _effect.Option.getOrElse(_effect.Function.constant(_ansiStyles.ASContextStyler.none()))); /** * StyleMap instance for ansi dark mode * * @category Instances */ exports.get = get; const darkMode = exports.darkMode = /*#__PURE__*/make({ id: 'DarkMode', styles: /*#__PURE__*/_effect.HashMap.make(['Message', /*#__PURE__*/_ansiStyles.ASContextStyler.green()], ['ToStringedObject', /*#__PURE__*/_ansiStyles.ASContextStyler.yellow()], ['PrimitiveValue', /*#__PURE__*/PPValueBasedStyler.makeTypeIndexed(/*#__PURE__*/_ansiStyles.ASPalette.make( // string _ansiStyles.ASStyle.green, // number _ansiStyles.ASStyle.yellow, // bigint _ansiStyles.ASStyle.yellow, // boolean _ansiStyles.ASStyle.yellow, // symbol _ansiStyles.ASStyle.cyan, /*#__PURE__*/ // null (0, _effect.pipe)(_ansiStyles.ASStyle.green, /*#__PURE__*/_ansiStyles.ASStyle.mergeOver(_ansiStyles.ASStyle.bold)), // undefined _ansiStyles.ASStyle.green))], ['PropertyKey', /*#__PURE__*/PPValueBasedStyler.makeKeyTypeIndexed(/*#__PURE__*/_ansiStyles.ASPalette.make( // string key _ansiStyles.ASStyle.red, // symbolic key _ansiStyles.ASStyle.cyan))], ['PrototypeDelimiters', /*#__PURE__*/_ansiStyles.ASContextStyler.green()], ['KeyValueSeparator', /*#__PURE__*/_ansiStyles.ASContextStyler.white()], ['InBetweenPropertySeparator', /*#__PURE__*/_ansiStyles.ASContextStyler.white()], ['NonPrimitiveValueDelimiters', /*#__PURE__*/PPValueBasedStyler.makeDepthIndexed(/*#__PURE__*/_ansiStyles.ASPalette.make(_ansiStyles.ASStyle.red, _ansiStyles.ASStyle.green, _ansiStyles.ASStyle.yellow, _ansiStyles.ASStyle.blue, _ansiStyles.ASStyle.magenta, _ansiStyles.ASStyle.cyan, _ansiStyles.ASStyle.white))], ['Indentation', /*#__PURE__*/_ansiStyles.ASContextStyler.green()], ['NonPrimitiveValueId', /*#__PURE__*/_ansiStyles.ASContextStyler.green()], ['NonPrimitiveValueIdSeparator', /*#__PURE__*/_ansiStyles.ASContextStyler.green()], ['PropertyNumbers', /*#__PURE__*/_ansiStyles.ASContextStyler.green()], ['PropertyNumberSeparator', /*#__PURE__*/_ansiStyles.ASContextStyler.green()], ['PropertyNumberDelimiters', /*#__PURE__*/_ansiStyles.ASContextStyler.green()]) }); /** * StyleMap instance that doesn't apply any formatting (uses the none ContextStyler of the * ansi-styles library for all parts to be formatted) * * @category Instances */ const none = exports.none = /*#__PURE__*/make({ id: 'None', styles: /*#__PURE__*/_effect.HashMap.empty() }); //# sourceMappingURL=StyleMap.js.map