From ca59e79b631a07dc98c9cb4ed02e17c3b029ffe3 Mon Sep 17 00:00:00 2001 From: Phillip Davis Date: Sun, 17 Aug 2025 20:50:42 -0400 Subject: [PATCH] supoport multiply and divide in calc exprs --- src/Css.elm | 17 ++++++++++++++++- tests/Properties.elm | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Css.elm b/src/Css.elm index c3812b72..ecd95e52 100644 --- a/src/Css.elm +++ b/src/Css.elm @@ -4,7 +4,7 @@ module Css exposing , Color, all, important, solid, transparent, rgb, rgba, hsl, hsla, hex , featureTag, featureTag2, featureOn, featureOff , borderCollapse, borderColor, borderColor2, borderColor3, borderColor4, borderBottomLeftRadius, borderBottomLeftRadius2, borderBottomRightRadius, borderBottomRightRadius2, borderTopLeftRadius, borderTopLeftRadius2, borderTopRightRadius, borderTopRightRadius2, borderRadius, borderRadius2, borderRadius3, borderRadius4, borderWidth, borderWidth2, borderWidth3, borderWidth4, borderBottomWidth, borderLeftWidth, borderRightWidth, borderTopWidth, borderBottomStyle, borderLeftStyle, borderRightStyle, borderTopStyle, borderStyle, borderBottomColor, borderLeftColor, borderRightColor, borderTopColor, borderBox, contentBox, border, border2, border3, borderTop, borderTop2, borderTop3, borderBottom, borderBottom2, borderBottom3, borderLeft, borderLeft2, borderLeft3, borderRight, borderRight2, borderRight3, borderImageOutset, borderImageOutset2, borderImageOutset3, borderImageOutset4, borderImageWidth, borderImageWidth2, borderImageWidth3, borderImageWidth4, scroll, visible, block, inlineBlock, inlineFlex, inline, none, auto, inherit, unset, initial, noWrap, top, static, fixed, sticky, relative, absolute, position, float, bottom, middle, baseline, sub, super, textTop, textBottom, hidden, wavy, dotted, dashed, double, groove, ridge, inset, outset, matrix, matrix3d, perspective, rotate3d, rotateX, rotateY, rotateZ, scale, scale2, scale3d, scaleX, scaleY, skew, skew2, skewX, skewY, translate, translate2, translate3d, translateX, translateY, translateZ, rotate, fillBox, viewBox, flat, preserve3d, content, wrapReverse, wrap, flexStart, flexEnd, stretch, row, rowReverse, column, columnReverse, serif, sansSerif, monospace, cursive, fantasy, xxSmall, xSmall, small, large, xLarge, xxLarge, smaller, larger, normal, italic, oblique, bold, lighter, bolder, smallCaps, allSmallCaps, petiteCaps, allPetiteCaps, unicase, titlingCaps, commonLigatures, noCommonLigatures, discretionaryLigatures, noDiscretionaryLigatures, historicalLigatures, noHistoricalLigatures, contextual, noContextual, liningNums, oldstyleNums, proportionalNums, tabularNums, diagonalFractions, stackedFractions, ordinal, slashedZero, default, pointer, crosshair, contextMenu, help, progress, wait, cell, text_, verticalText, cursorAlias, copy, move, noDrop, notAllowed, eResize, nResize, neResize, nwResize, sResize, seResize, swResize, wResize, ewResize, nsResize, neswResize, nwseResize, colResize, rowResize, allScroll, zoomIn, zoomOut, grab, grabbing, visiblePainted, visibleFill, visibleStroke, painted, stroke - , Length, pct, px, em, pt, ex, ch, rem, vh, vw, vmin, vmax, mm, cm, inches, pc, int, num, zero, calc, plus, minus + , Length, pct, px, em, pt, ex, ch, rem, vh, vw, vmin, vmax, mm, cm, inches, pc, int, num, zero, calc, plus, minus, mult, dividedBy , Px, Em, Rem, Pct, Ex, Ch, Vh, Vw, Vmin, Vmax, Mm, Cm, In, Pt, Pc , deg, rad, grad, turn , Duration, sec, ms @@ -867,6 +867,8 @@ type alias CalculatedLength = type CalcExpression = Addition | Subtraction + | Multiplication + | Division calcExpressionToString : CalcExpression -> String @@ -878,6 +880,12 @@ calcExpressionToString expression = Subtraction -> "-" + Multiplication -> + "*" + + Division -> + "/" + {-| -} @@ -967,6 +975,13 @@ minus : CalcExpression minus = Subtraction +mult : CalcExpression +mult = + Multiplication + +dividedBy : CalcExpression +dividedBy = + Division combineLengths : (Float -> Float -> Float) diff --git a/tests/Properties.elm b/tests/Properties.elm index e4f379ef..420ff34e 100644 --- a/tests/Properties.elm +++ b/tests/Properties.elm @@ -199,6 +199,10 @@ all = , ( lineHeight (num 0), "0" ) , ( lineHeight (calc (px 5) plus (pct 1)), "calc(5px + 1%)" ) , ( lineHeight (calc (em 5.5) minus (pt 1)), "calc(5.5em - 1pt)" ) + , ( lineHeight (calc (em 1.5) mult (pct 1)), "calc(1.5em * 1%)") + , ( lineHeight (calc (px 3.25) mult (rem 2)), "calc(3.25px * 2rem)") + , ( lineHeight (calc (em 1.5) dividedBy (pct 1)), "calc(1.5em / 1%)") + , ( lineHeight (calc (px 3.25) dividedBy (rem 2)), "calc(3.25px / 2rem)") , ( lineHeight (calc (px 5) plus (calc (pct 5) plus (vh 3))), "calc(5px + (5% + 3vh))" ) , ( lineHeight (calc (px 5) plus (calc (pct 5) minus (vh 3))), "calc(5px + (5% - 3vh))" ) , ( lineHeight (calc (px 5) minus (calc (pct 5) plus (vh 3))), "calc(5px - (5% + 3vh))" )