UNPKG

@mapcss/preset-typography

Version:

Typography preset for MapCSS

83 lines (82 loc) 2.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cssFn = exports.stringifyVarFunction = exports.stringifyCustomProperty = exports.completionRGBA = exports.rgbFn = exports.roundN = exports.roundTo = exports.multiple = exports.unit = exports.varFn = exports.customProperty = exports.quoter = exports.ratio = exports.shortDecimal = void 0; /** format numeric to `#.##` * ```ts * import { shortDecimal } from "https://deno.land/x/mapcss@$VERSION/core/utils/format.ts" * import { expect } from "https://deno.land/x/unitest/mod.ts" * expect(shortDecimal("0.5")).toBe(".5") * expect(shortDecimal("0.05")).toBe(".05") * expect(shortDecimal("1.5")).toBe("1.5") * ``` */ function shortDecimal(value) { return String(value).replace(/^0(.\d+)$/, "$1"); } exports.shortDecimal = shortDecimal; function ratio(value) { return value / 100; } exports.ratio = ratio; function quoter(value) { return value / 4; } exports.quoter = quoter; function customProperty(property, prefix = "") { return `--${prefix}${property}`; } exports.customProperty = customProperty; function varFn(customPropertyName) { return `var(${customPropertyName})`; } exports.varFn = varFn; function unit(unit) { return (value) => `${value}${unit}`; } exports.unit = unit; function multiple(a) { return (b) => a * b; } exports.multiple = multiple; /** High precision round */ function roundTo(number, digit) { return Number(number.toFixed(digit)); } exports.roundTo = roundTo; function roundN(digit) { return (number) => roundTo(number, digit); } exports.roundN = roundN; function rgbFn({ r, g, b, a }) { const _r = shortDecimal(r); const _g = shortDecimal(g); const _b = shortDecimal(b); const _a = shortDecimal(a); return `rgb(${_r} ${_g} ${_b}/${_a})`; } exports.rgbFn = rgbFn; function completionRGBA(alpha, asDefault = false) { return ({ r, g, b, a }) => { const _a = asDefault ? a ?? alpha : alpha; return { r, g, b, a: _a }; }; } exports.completionRGBA = completionRGBA; function stringifyCustomProperty(property, prefix = "") { return `--${prefix}${property}`; } exports.stringifyCustomProperty = stringifyCustomProperty; function stringifyVarFunction(...value) { return `var(${value.join(" ")})`; } exports.stringifyVarFunction = stringifyVarFunction; /** CSS functional-notation * ```ts * import { cssFn } from "https://deno.land/x/mapcss@$VERSION/core/utils/format.ts" * cssFn("var", "--map-css") // var(--map-css) * ``` */ function cssFn(funcName, argument) { return `${funcName}(${argument})`; } exports.cssFn = cssFn;