Skip to content

Commit b76c566

Browse files
committed
[css-backgrounds-3] Make radius-expansion.html show red outline for invalid values
1 parent 15fcd3d commit b76c566

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

css-backgrounds-3/radius-expansion.html

+26-19
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
{width: 500, height: 50, spread: 30, borderRadius: "1px 1px 49px 49px"},
8686
{width: 500, height: 50, spread: 30, borderRadius: "50%"},
8787
{width: 500, height: 50, spread: 30, borderRadius: "50% 50% 1px 50%"},
88+
{width: 0, height: 0, spread: 30, borderRadius: "50px 0px 0px 0px"},
8889
];
8990

9091
function show({incremental = false} = {}) {
@@ -134,6 +135,9 @@
134135
outer.style.width = "max-content";
135136
container.appendChild(outer);
136137
outer.style.borderRadius = resolve(testCase, inner);
138+
if (!outer.style.borderRadius) {
139+
outer.style.outline = "solid red";
140+
}
137141
}
138142
}
139143
}
@@ -169,23 +173,26 @@
169173
};
170174

171175
// Normalize radii that add up to > 100%
172-
const f = Math.min(
176+
let f = Math.min(
173177
testCase.width / (radii.topLeft[0] + radii.topRight[0]),
174178
testCase.width / (radii.bottomLeft[0] + radii.bottomRight[0]),
175179
testCase.height / (radii.topLeft[1] + radii.bottomLeft[1]),
176180
testCase.height / (radii.topRight[1] + radii.bottomRight[1])
177181
);
182+
if (Number.isNaN(f)) {
183+
f = 0;
184+
}
178185
if (f < 1) {
179186
for (let corner in radii) {
180187
radii[corner] = radii[corner].map(v => v * f);
181188
}
182189
}
183190

184191
let r = {
185-
topLeft: radii.topLeft,
186-
topRight: radii.topRight,
187-
bottomLeft: radii.bottomLeft,
188-
bottomRight: radii.bottomRight,
192+
topLeft: [],
193+
topRight: [],
194+
bottomLeft: [],
195+
bottomRight: [],
189196
};
190197
const algorithm = document.forms[0].elements.algorithm.value;
191198

@@ -195,8 +202,8 @@
195202

196203
let percentageSameAxis = {};
197204

198-
for (let corner in r) {
199-
let c = r[corner];
205+
for (let corner in radii) {
206+
let c = radii[corner];
200207
let [rx, ry] = c;
201208

202209
let px = rx / width;
@@ -207,8 +214,8 @@
207214

208215
let currentSpec = {};
209216

210-
for (let corner in r) {
211-
currentSpec[corner] = r[corner].map(value => {
217+
for (let corner in radii) {
218+
currentSpec[corner] = radii[corner].map(value => {
212219
if (value >= testCase.spread) {
213220
return value + testCase.spread;
214221
}
@@ -218,13 +225,13 @@
218225
}
219226

220227
if (algorithm === "increase-by-spread") {
221-
for (let corner in r) {
222-
r[corner] = r[corner].map(v => v + testCase.spread);
228+
for (let corner in radii) {
229+
r[corner] = radii[corner].map(v => v + testCase.spread);
223230
}
224231
}
225232
else if (algorithm === "old-spec") {
226-
for (let corner in r) {
227-
let c = r[corner];
233+
for (let corner in radii) {
234+
let c = radii[corner];
228235
r[corner] = c[0] + c[1] === 0 ? [0, 0] : [c[0] + testCase.spread, c[1] + testCase.spread];
229236
}
230237
}
@@ -240,10 +247,10 @@
240247
let spreadHeight = height + testCase.spread * 2;
241248

242249
let straights = {
243-
top: width - r.topLeft[0] - r.topRight[0],
244-
bottom: width - r.bottomLeft[0] - r.bottomRight[0],
245-
left: height - r.topLeft[1] - r.bottomLeft[1],
246-
right: height - r.topRight[1] - r.bottomRight[1],
250+
top: width - radii.topLeft[0] - radii.topRight[0],
251+
bottom: width - radii.bottomLeft[0] - radii.bottomRight[0],
252+
left: height - radii.topLeft[1] - radii.bottomLeft[1],
253+
right: height - radii.topRight[1] - radii.bottomRight[1],
247254
}
248255

249256
function getStraightSegment(corner, axis) {
@@ -259,8 +266,8 @@
259266
return straights[parts[axis]];
260267
}
261268

262-
for (let corner in r) {
263-
r[corner] = r[corner].map((value, axis) => {
269+
for (let corner in radii) {
270+
r[corner] = radii[corner].map((value, axis) => {
264271
let straight = getStraightSegment(corner, axis);
265272
let ratio = straight / value;
266273
ratio = Math.min(ratio, 1);

0 commit comments

Comments
 (0)