Merge branch 'jkrielaars-border-radius'

This commit is contained in:
Niklas von Hertzen 2018-01-07 19:20:24 +08:00
commit e198eae398
2 changed files with 53 additions and 41 deletions

View File

@ -202,40 +202,32 @@ export const parseBoundCurves = (
borders: Array<Border>, borders: Array<Border>,
borderRadius: Array<BorderRadius> borderRadius: Array<BorderRadius>
): BoundCurves => { ): BoundCurves => {
const HALF_WIDTH = bounds.width / 2; let tlh = borderRadius[CORNER.TOP_LEFT][H].getAbsoluteValue(bounds.width);
const HALF_HEIGHT = bounds.height / 2; let tlv = borderRadius[CORNER.TOP_LEFT][V].getAbsoluteValue(bounds.height);
const tlh = let trh = borderRadius[CORNER.TOP_RIGHT][H].getAbsoluteValue(bounds.width);
borderRadius[CORNER.TOP_LEFT][H].getAbsoluteValue(bounds.width) < HALF_WIDTH let trv = borderRadius[CORNER.TOP_RIGHT][V].getAbsoluteValue(bounds.height);
? borderRadius[CORNER.TOP_LEFT][H].getAbsoluteValue(bounds.width) let brh = borderRadius[CORNER.BOTTOM_RIGHT][H].getAbsoluteValue(bounds.width);
: HALF_WIDTH; let brv = borderRadius[CORNER.BOTTOM_RIGHT][V].getAbsoluteValue(bounds.height);
const tlv = let blh = borderRadius[CORNER.BOTTOM_LEFT][H].getAbsoluteValue(bounds.width);
borderRadius[CORNER.TOP_LEFT][V].getAbsoluteValue(bounds.height) < HALF_HEIGHT let blv = borderRadius[CORNER.BOTTOM_LEFT][V].getAbsoluteValue(bounds.height);
? borderRadius[CORNER.TOP_LEFT][V].getAbsoluteValue(bounds.height)
: HALF_HEIGHT; const factors = [];
const trh = factors.push((tlh + trh) / bounds.width);
borderRadius[CORNER.TOP_RIGHT][H].getAbsoluteValue(bounds.width) < HALF_WIDTH factors.push((blh + brh) / bounds.width);
? borderRadius[CORNER.TOP_RIGHT][H].getAbsoluteValue(bounds.width) factors.push((tlv + blv) / bounds.height);
: HALF_WIDTH; factors.push((trv + brv) / bounds.height);
const trv = const maxFactor = Math.max(...factors);
borderRadius[CORNER.TOP_RIGHT][V].getAbsoluteValue(bounds.height) < HALF_HEIGHT
? borderRadius[CORNER.TOP_RIGHT][V].getAbsoluteValue(bounds.height) if (maxFactor > 1) {
: HALF_HEIGHT; tlh /= maxFactor;
const brh = tlv /= maxFactor;
borderRadius[CORNER.BOTTOM_RIGHT][H].getAbsoluteValue(bounds.width) < HALF_WIDTH trh /= maxFactor;
? borderRadius[CORNER.BOTTOM_RIGHT][H].getAbsoluteValue(bounds.width) trv /= maxFactor;
: HALF_WIDTH; brh /= maxFactor;
const brv = brv /= maxFactor;
borderRadius[CORNER.BOTTOM_RIGHT][V].getAbsoluteValue(bounds.height) < HALF_HEIGHT blh /= maxFactor;
? borderRadius[CORNER.BOTTOM_RIGHT][V].getAbsoluteValue(bounds.height) blv /= maxFactor;
: HALF_HEIGHT; }
const blh =
borderRadius[CORNER.BOTTOM_LEFT][H].getAbsoluteValue(bounds.width) < HALF_WIDTH
? borderRadius[CORNER.BOTTOM_LEFT][H].getAbsoluteValue(bounds.width)
: HALF_WIDTH;
const blv =
borderRadius[CORNER.BOTTOM_LEFT][V].getAbsoluteValue(bounds.height) < HALF_HEIGHT
? borderRadius[CORNER.BOTTOM_LEFT][V].getAbsoluteValue(bounds.height)
: HALF_HEIGHT;
const topWidth = bounds.width - trh; const topWidth = bounds.width - trh;
const rightHeight = bounds.height - brv; const rightHeight = bounds.height - brv;

View File

@ -5,7 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="../../test.js"></script> <script type="text/javascript" src="../../test.js"></script>
<style type="text/css"> <style type="text/css">
div { .box {
width: 200px; width: 200px;
height: 200px; height: 200px;
display: inline-block; display: inline-block;
@ -63,6 +63,21 @@
border-radius: 200px; border-radius: 200px;
} }
.gauge{
display: inline-block;
width: 100px;
height: 50px;
background: green;
margin-bottom: 20px;
}
.gauge1{ border-radius: 25px 25px 0 0 / 25px 25px 0 0; }
.gauge2{ border-radius: 100px 100px 0 0 / 50px 50px 0 0; }
.gauge3{ border-radius: 100px 100px 0 0 / 100px 100px 0 0; }
.gauge4{ border-radius: 300px 100px 0 0 / 100px 100px 0 0; }
.gauge5{ border-radius: 400px 400px 50px 50px / 50px 50px 50px 50px; }
html { html {
background: #3a84c3; background: #3a84c3;
} }
@ -70,11 +85,16 @@
</head> </head>
<body> <body>
<div class="box1">&nbsp;</div> <div class="box box1">&nbsp;</div>
<div class="box2">&nbsp;</div> <div class="box box2">&nbsp;</div>
<div class="box3">&nbsp;</div> <div class="box box3">&nbsp;</div>
<div class="box4">&nbsp;</div> <div class="box box4">&nbsp;</div>
<div class="box5">&nbsp;</div> <div class="box box5">&nbsp;</div>
<div class="box6">&nbsp;</div> <div class="box box6">&nbsp;</div>
<div class="gauge gauge1"></div>
<div class="gauge gauge2"></div>
<div class="gauge gauge3"></div>
<div class="gauge gauge4"></div>
<div class="gauge gauge5"></div>
</body> </body>
</html> </html>