File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -426,3 +426,36 @@ export const getCSSVarName = value => {
426426 const match = value ?. match ( / v a r \( \s * ( [ ^ , ) \s ] + ) / )
427427 return match ? match [ 1 ] : null
428428}
429+
430+ /**
431+ * Convert a value from rem/em to px if the units array doesn't support it.
432+ *
433+ * @param {string[] } units - The list of supported units.
434+ * @param {string } currentUnit - The current unit of the value.
435+ * @param {string|number } currentValue - The current value to convert.
436+ *
437+ * @return {Object } An object containing the converted value and unit.
438+ */
439+ export function convertToPxIfUnsupported ( units , currentUnit , currentValue ) {
440+ const unitMultipliers = {
441+ rem : 16 ,
442+ em : 16 ,
443+ }
444+
445+ const normalizedUnit = currentUnit ?. toLowerCase ( )
446+
447+ if (
448+ ( ! units ?. length || ! units . includes ( normalizedUnit ) ) &&
449+ unitMultipliers [ normalizedUnit ]
450+ ) {
451+ return {
452+ value : `${ parseFloat ( currentValue ) * unitMultipliers [ normalizedUnit ] } ` ,
453+ unit : 'px' ,
454+ }
455+ }
456+
457+ return {
458+ value : currentValue ,
459+ unit : currentUnit ,
460+ }
461+ }
You can’t perform that action at this time.
0 commit comments