UNPKG

@maggioli-design-system/design-tokens

Version:

This is the Design Token library of Maggioli Design System, here you'll find all the visual data used around the libraries.

126 lines (125 loc) 4.71 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.tailwindFontSize = exports.stripText = exports.safeString = exports.rgbCommaSeparatedChannel = exports.rgbChannel = exports.pixelToScale = exports.pixelToRem = exports.pixelToEm = exports.pascalCase = exports.leadZero = exports.kebabCase = exports.ifTailwindFontSizeProp = exports.ifEquals = exports.ifDartTextStyleProp = exports.humanCase = exports.firstArrayElement = void 0; const handlebars_1 = __importDefault(require("handlebars")); const hex_rgb_1 = __importDefault(require("hex-rgb")); const humanCase = (separator = '-', options) => { if (typeof options.fn(this) !== 'string') { return options.fn(this); } const value = options.fn(this); const arr = value.split(separator); for (let i = 0; i < arr.length; i++) { arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].slice(1); } return arr.join(' '); }; exports.humanCase = humanCase; const firstArrayElement = (value) => { if (Array.isArray(value)) return value[0]; return new handlebars_1.default.SafeString(value.replace(/"|'/g, '').split(',')[0]); }; exports.firstArrayElement = firstArrayElement; const pascalCase = (options) => { if (typeof options.fn(this) !== 'string') { return options.fn(this); } const value = options.fn(this); const arr = value.split('-'); for (let i = 0; i < arr.length; i++) { if (i === 0) { arr[i] = arr[i].charAt(0).toLowerCase() + arr[i].slice(1); } else { arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].slice(1); } } return arr.join(''); }; exports.pascalCase = pascalCase; const kebabCase = (options) => { if (typeof options.fn(this) !== 'string') { return options.fn(this); } const value = options.fn(this); return value.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); }; exports.kebabCase = kebabCase; const rgbCommaSeparatedChannel = (value) => { const color = (0, hex_rgb_1.default)(value); return `${color.red}, ${color.green}, ${color.blue}`; }; exports.rgbCommaSeparatedChannel = rgbCommaSeparatedChannel; const rgbChannel = (value) => { const color = (0, hex_rgb_1.default)(value); return `${color.red} ${color.green} ${color.blue}`; }; exports.rgbChannel = rgbChannel; const leadZero = (value) => { return Number(value) < 10 ? `0${value}` : value; }; exports.leadZero = leadZero; const ifEquals = (valueA, valueB, options) => { return valueA === valueB ? options.fn(this) : options.inverse(this); }; exports.ifEquals = ifEquals; const safeString = (value) => { return new handlebars_1.default.SafeString(value); }; exports.safeString = safeString; const stripText = (value, stripReplacer) => { return value.replace(stripReplacer, ''); }; exports.stripText = stripText; const pixelToRem = (value, defaultPixelSize = 16) => { const pixels = Number(value.replace('px', '')); return Number((pixels / defaultPixelSize).toFixed(4)).toString() + 'rem'; }; exports.pixelToRem = pixelToRem; const pixelToEm = (value, defaultPixelSize = 16) => { const pixels = Number(value.replace('px', '')); return Number((pixels / defaultPixelSize).toFixed(4)).toString() + 'em'; }; exports.pixelToEm = pixelToEm; const pixelToScale = (valueA, valueB) => { const valueNumberA = Number(valueA.replace('px', '')); const valueNumberB = Number(valueB.replace('px', '')); return Number((valueNumberA / valueNumberB).toFixed(4)).toString(); }; exports.pixelToScale = pixelToScale; const ifTailwindFontSizeProp = (property, options) => { const attributes = ['letterSpacing', 'lineHeight', 'fontWeight']; return attributes.includes(property) ? options.fn(this) : options.inverse(this); }; exports.ifTailwindFontSizeProp = ifTailwindFontSizeProp; const tailwindFontSize = (property, value) => { switch (property) { case 'fontSize': case 'lineHeight': { return pixelToRem(value); } case 'letterSpacing': { return pixelToEm(value); } default: { return value; } } }; exports.tailwindFontSize = tailwindFontSize; const ifDartTextStyleProp = (property, options) => { const attributes = [ 'fontFamily', 'fontFamilyFallback', 'fontSize', 'letterSpacing', 'lineHeight', 'fontWeight', ]; return attributes.includes(property) ? options.fn(this) : options.inverse(this); }; exports.ifDartTextStyleProp = ifDartTextStyleProp;