UNPKG

@coin-voyage/paykit

Version:

Seamless crypto payments. Onboard users from any chain, any coin into your app with one click.

27 lines (26 loc) 708 B
import { css } from "styled-components"; export const hexToP3 = (hex) => { const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); if (result == null) { return hex; } const values = { r: Number.parseInt(result[1], 16), g: Number.parseInt(result[2], 16), b: Number.parseInt(result[3], 16), }; return `color(display-p3 ${values.r / 255} ${values.g / 255} ${values.b / 255})`; }; export const p3Hex = (hex, property) => { const isSafari = true; const p3 = hexToP3(hex); if (!p3 || !isSafari) { return css ` ${property}: ${hex}; `; } return css ` ${property}: ${hex}; ${property}: ${p3}; `; };