UNPKG

@varlet/ui

Version:

A Vue3 component library based on Material Design 2 and 3, supporting mobile and desktop.

14 lines (13 loc) 442 B
function toViewport(theme, options = {}) { const { viewportWidth = 375, viewportUnit = "vmin", unitPrecision = 6 } = options; return Object.entries(theme).reduce((target, [key, value]) => { target[key] = value.includes("px") ? value.replace( /(\d+(\.\d+)?)px/g, (_, p1) => `${Number((p1 / viewportWidth * 100).toFixed(unitPrecision))}${viewportUnit}` ) : value; return target; }, {}); } export { toViewport };