MCPcopy Create free account
hub / github.com/CanadaHonk/shadow / lengthAbs

Method lengthAbs

engine/layout.js:524–627  ·  view source on GitHub ↗
(i, property, parent = this.parent)

Source from the content-addressed store, hash-verified

522
523 // technically <length-percentage> but uhm yeah
524 lengthAbs(i, property, parent = this.parent) {
525 const x = this.resolveValue(i ?? '', property, parent);
526 if (typeof x === 'number') return x;
527
528 if (property === 'font-size') {
529 if (this.tagName === 'document') return this.defaultFontSize();
530
531 // :/
532 switch (x) {
533 case 'xx-small': return this.defaultFontSize() * (3/5);
534 case 'x-small': return this.defaultFontSize() * (3/4);
535 case 'small': return this.defaultFontSize() * (8/9);
536 case 'medium': return this.defaultFontSize() * (1);
537 case 'large': return this.defaultFontSize() * (6/5);
538 case 'x-large': return this.defaultFontSize() * (3/2);
539 case 'xx-large': return this.defaultFontSize() * (2/1);
540 case 'xxx-large': return defaultFontSize * (3/1);
541
542 // not specified exactly :(
543 case 'smaller': return this.parent.fontSize() * (5/6);
544 case 'larger': return this.parent.fontSize() * (6/5);
545 }
546 }
547
548 let val = '', unit = '';
549
550 for (const c of x) {
551 if (c >= 'a' || c === '%') {
552 unit += c;
553 } else val += c;
554 }
555
556 if (!unit) {
557 switch (property) {
558 case 'line-height':
559 unit = 'em';
560 break;
561
562 default:
563 unit = 'px';
564 break;
565 }
566 }
567
568 val = parseFloat(val);
569 if (Number.isNaN(val)) val = 0;
570
571 switch (unit) {
572 case 'px': return val;
573
574 case 'cm': return val * CM;
575 case 'mm': return val * (CM / 10);
576 case 'Q': return val * (CM / 40);
577 case 'in': return val * IN;
578 case 'pc': return val * (IN / 6);
579 case 'pt': return val * (IN / 72);
580
581 case '%':

Callers 15

cssWidthMethod · 0.95
cssHeightMethod · 0.95
imageWidthMethod · 0.95
imageHeightMethod · 0.95
lineHeightMethod · 0.95
maxWidthMethod · 0.95
xMethod · 0.95
yMethod · 0.95
marginTopMethod · 0.95
marginBottomMethod · 0.95
marginLeftMethod · 0.95
marginRightMethod · 0.95

Calls 6

resolveValueMethod · 0.95
defaultFontSizeMethod · 0.95
fontSizeMethod · 0.95
propToFuncFunction · 0.85
cssHeightMethod · 0.80
heightMethod · 0.80

Tested by

no test coverage detected