|
2 | 2 | @use "@/presentation/assets/styles/mixins" as *; |
3 | 3 | @use "@/presentation/assets/styles/vite-path" as *; |
4 | 4 | @use "@/presentation/assets/styles/typography" as *; |
5 | | -@use 'sass:math'; |
6 | 5 |
|
7 | 6 | @mixin code-block() { |
8 | 7 | pre { |
|
26 | 25 | $color-background, |
27 | 26 | $code-block-padding, |
28 | 27 | ) { |
29 | | - $font-size-code: $font-size-relative-smaller; // Keep relative size to scale right with different text sizes around. |
| 28 | + $font-size-code-in-percentage: $font-size-relative-smaller; // Keep relative size to scale right with different text sizes around. |
30 | 29 | $border-radius: 2px; // Subtle rounding still maintaining sharp design. |
31 | 30 |
|
32 | 31 | @include base-code { |
33 | 32 | font-family: $font-family-monospace; |
34 | | - border-radius: $border-radius; |
35 | | - font-size: $font-size-code; |
| 33 | + font-size: $font-size-code-in-percentage; |
36 | 34 | color: $color-on-primary; |
37 | 35 | } |
38 | 36 |
|
39 | 37 | @include inline-code { |
40 | 38 | background: $color-background; |
41 | 39 | word-break: break-all; // Enables inline code to wrap with the text, even for long single words (like registry paths), thus preventing overflow. |
42 | 40 |
|
43 | | - $font-size-code-in-decimal: math.div($font-size-code, 100%); // Converts percentage (e.g., 85%) to decimal (e.g., 0.85) for calculations. |
44 | | - $font-size-code-in-em: calc(1em * #{$font-size-code-in-decimal}); |
45 | | - $vertical-padding: calc((1em - #{$font-size-code-in-em}) / 2); |
46 | | - $horizontal-padding: calc(#{$font-size-code-in-em} * 0.4); |
47 | | - padding: $vertical-padding $horizontal-padding; |
| 41 | + $padding-x-max : 8px; |
| 42 | + $padding-x-desired : 0.4em; |
| 43 | + $padding-y-max : 4px; |
| 44 | + $padding-y-desired : calculate-min-vertical-empty-space($font-size-code-in-percentage); |
| 45 | + $padding-y-desired : calc(calculate-min-vertical-empty-space($font-size-code-in-percentage) / 2); |
| 46 | + |
| 47 | + $padding-y: min($padding-y-desired, $padding-y-max); |
| 48 | + $padding-x: min($padding-x-desired, $padding-x-max); |
| 49 | + padding: #{$padding-y} #{$padding-x}; |
| 50 | + display: inline-block; // Required for centering, otherwise contents align towards bottom with Y padding, causing overflows |
48 | 51 | } |
49 | 52 |
|
| 53 | + |
50 | 54 | @include code-block { |
51 | 55 | background: $color-background; |
52 | 56 | border-radius: $border-radius; |
53 | 57 | overflow: auto; // Prevents horizontal expansion of inner content (e.g., when a code block is shown) |
54 | 58 | padding: $code-block-padding; |
55 | 59 | } |
56 | 60 | } |
| 61 | + |
| 62 | +@function convert-percentage-to-decimal-ratio($current-relative-font-size) { |
| 63 | + @return calc($current-relative-font-size / 100%); |
| 64 | +} |
| 65 | + |
| 66 | + |
| 67 | +@function calculate-inline-parent-min-line-height( |
| 68 | + $inline-child-relative-font-size-in-decimal, |
| 69 | +) { |
| 70 | + $parent-line-height: calc( |
| 71 | + 1lh /* self height, height = 1 lh for inline element*/ |
| 72 | + / |
| 73 | + #{$inline-child-relative-font-size-in-decimal} /* minimum possible font size of parent */ |
| 74 | + ); |
| 75 | + $parent-min-height: round(down, #{$parent-line-height}, 1px); |
| 76 | + @return $parent-min-height; |
| 77 | +} |
| 78 | + |
| 79 | +@function calculate-vertical-empty-space($parent-min-line-height) { |
| 80 | + $available-space: calc( |
| 81 | + #{$parent-min-line-height} /* Parent should be able to show single line of text text */ |
| 82 | + - |
| 83 | + 1lh, /* self height, height = 1 lh for inline element*/ |
| 84 | + ); |
| 85 | + @return max(#{$available-space}, 0px); // Return 0px if there's no available space |
| 86 | +} |
| 87 | + |
| 88 | +@function calculate-min-vertical-empty-space( |
| 89 | + $inline-element-relative-font-size-in-percentage, |
| 90 | +) { |
| 91 | + $self-font-size-relative-in-decimal: convert-percentage-to-decimal-ratio($inline-element-relative-font-size-in-percentage); |
| 92 | + $parent-minimum-height: calculate-inline-parent-min-line-height($self-font-size-relative-in-decimal); |
| 93 | + $total-empty-space-y: calculate-vertical-empty-space($parent-minimum-height); |
| 94 | + @return $total-empty-space-y; |
| 95 | +} |
0 commit comments