"use strict";const g=require("../../../../../../../_virtual/reducer.js");require("./convert.js");const y=require("../../../../../../../_virtual/convert.js");Object.defineProperty(g.__exports,"__esModule",{value:!0});g.__exports.flip=s;var c=y.convert.exports,p=V(c);function V(t){return t&&t.__esModule?t:{default:t}}function l(t,a){return t.type==="MathExpression"?b(t,a):t.type==="Calc"?l(t.value,a):t}function v(t,a){return t.type===a.type&&t.value===a.value}function u(t){switch(t){case"LengthValue":case"AngleValue":case"TimeValue":case"FrequencyValue":case"ResolutionValue":case"EmValue":case"ExValue":case"ChValue":case"RemValue":case"VhValue":case"VwValue":case"VminValue":case"VmaxValue":case"PercentageValue":case"Value":return!0}return!1}function x(t,a){var i=(0,p.default)(t.left,t.right,a),r=l(i.left,a),e=l(i.right,a);return r.type==="MathExpression"&&e.type==="MathExpression"&&(r.operator==="/"&&e.operator==="*"||r.operator==="-"&&e.operator==="+"||r.operator==="*"&&e.operator==="/"||r.operator==="+"&&e.operator==="-")&&(v(r.right,e.right)?i=(0,p.default)(r.left,e.left,a):v(r.right,e.left)&&(i=(0,p.default)(r.left,e.right,a)),r=l(i.left,a),e=l(i.right,a)),t.left=r,t.right=e,t}function s(t){return t==="+"?"-":"+"}function h(t){return u(t.type)?t.value=-t.value:t.type=="MathExpression"&&(t.left=h(t.left),t.right=h(t.right)),t}function E(t,a){var i=t,r=i.left,e=i.right,f=i.operator;if(r.type==="CssVariable"||e.type==="CssVariable")return t;if(e.value===0)return r;if(r.value===0&&f==="+")return e;if(r.value===0&&f==="-")return h(e);if(r.type===e.type&&u(r.type)&&(t=Object.assign({},r),f==="+"?t.value=r.value+e.value:t.value=r.value-e.value),u(r.type)&&(e.operator==="+"||e.operator==="-")&&e.type==="MathExpression"){if(r.type===e.left.type)return t=Object.assign({},t),t.left=l({type:"MathExpression",operator:f,left:r,right:e.left},a),t.right=e.right,t.operator=f==="-"?s(e.operator):e.operator,l(t,a);if(r.type===e.right.type)return t=Object.assign({},t),t.left=l({type:"MathExpression",operator:f==="-"?s(e.operator):e.operator,left:r,right:e.right},a),t.right=e.left,l(t,a)}if(r.type==="MathExpression"&&(r.operator==="+"||r.operator==="-")&&u(e.type)){if(e.type===r.left.type)return t=Object.assign({},r),t.left=l({type:"MathExpression",operator:f,left:r.left,right:e},a),l(t,a);if(e.type===r.right.type)return t=Object.assign({},r),r.operator==="-"?(t.right=l({type:"MathExpression",operator:f==="-"?"+":"-",left:e,right:r.right},a),t.operator=f==="-"?"-":"+"):t.right=l({type:"MathExpression",operator:f,left:r.right,right:e},a),t.right.value<0&&(t.right.value*=-1,t.operator=t.operator==="-"?"+":"-"),l(t,a)}return t}function M(t,a){if(!u(t.right.type))return t;if(t.right.type!=="Value")throw new Error('Cannot divide by "'+t.right.unit+'", number expected');if(t.right.value===0)throw new Error("Cannot divide by zero");return t.left.type==="MathExpression"?u(t.left.left.type)&&u(t.left.right.type)?(t.left.left.value/=t.right.value,t.left.right.value/=t.right.value,l(t.left,a)):t:u(t.left.type)?(t.left.value/=t.right.value,t.left):t}function _(t){if(t.left.type==="MathExpression"&&t.right.type==="Value"){if(u(t.left.left.type)&&u(t.left.right.type))return t.left.left.value*=t.right.value,t.left.right.value*=t.right.value,t.left}else{if(u(t.left.type)&&t.right.type==="Value")return t.left.value*=t.right.value,t.left;if(t.left.type==="Value"&&t.right.type==="MathExpression"){if(u(t.right.left.type)&&u(t.right.right.type))return t.right.left.value*=t.left.value,t.right.right.value*=t.left.value,t.right}else if(t.left.type==="Value"&&u(t.right.type))return t.right.value*=t.left.value,t.right}return t}function b(t,a){switch(t=x(t,a),t.operator){case"+":case"-":return E(t,a);case"/":return M(t,a);case"*":return _(t)}return t}g.__exports.default=l;
//# sourceMappingURL=reducer.js.map
