Bilibili-Evolved/registry/lib/components/style/custom-font-family/set-font-family.scss
2023-10-13 05:19:04 +08:00

116 lines
3.1 KiB
SCSS

$name: 'custom-font-family';
$font-family-css: var(--#{$name}--options--font-family) !important;
// 收集 CSS 路径为单一字符串
@function collect-paths($path-list) {
$string-path: '';
@each $path in $path-list {
$i: index($path-list, $path);
@if $i!=1 {
$string-path: '#{$string-path}, ';
}
$string-path: '#{$string-path}#{$path}';
}
@return $string-path;
}
@function get-ornament-path() {
$new-video: '.reply-item .root-reply-container .content-warp .reply-decorate .user-sailing .user-sailing-text .sailing-text';
$dynamic: '.bili-dyn-ornament__type--3 span';
$dynamic-comment-area: '.bb-comment .sailing .sailing-info, .comment-bilibili-fold .sailing .sailing-info';
@return collect-paths(($new-video, $dynamic, $dynamic-comment-area));
}
@function get-fans-medal-path() {
$new-video: '.badge-level';
@return collect-paths(($new-video));
}
@function get-danmaku-path() {
$main: '.bili-dm';
@return collect-paths(($main));
}
@function get-icon-font-path() {
$main-a: '.iconfont';
$main-b: '.icon-font';
$note: '.read-icon';
$note-edit: '.bili-note-iconfont';
$footer: '.bili-footer-font';
$bangumi-info: '[class^="icon-"]';
$history: '.bilifont';
$message: '.bp-icon-font';
$creative-center-a: '.bcc-iconfont';
$creative-center-b: '.fontvt';
@return collect-paths(
(
$main-a,
$main-b,
$note,
$note-edit,
$footer,
$bangumi-info,
$history,
$message,
$creative-center-a,
$creative-center-b
)
);
}
@function get-column-path() {
$main-a: '.article-detail .article-container .article-container__content .article-content .read-article-holder';
$main-b: '.article-detail .article-container .article-container__content .article-content .read-article-holder *';
@return collect-paths(($main-a, $main-b));
}
@function get-score-path() {
$documentary: '.season-cover .score';
$big: '.season-cover .season-cover-score';
@return collect-paths(($documentary, $big));
}
// 装扮,在评论区、动态等界面显示
$ornament: get-ornament-path();
// 粉丝勋章,在评论区界面显示
$fans-medal: get-fans-medal-path();
// 弹幕,在播放器里显示
$danmaku: get-danmaku-path();
// 图标字体
$icon-font: get-icon-font-path();
// 专栏阅读页可能出现的部分自定义字体
$column: get-column-path();
// 分数,在部分剧集的右下角显示
$score: get-score-path();
// 收集所有路径
$discard-paths: collect-paths(($ornament, $fans-medal, $danmaku, $icon-font, $column, $score));
$on-option-names: (
'on-ornament',
'on-fans-medal',
'on-danmaku',
'on-icon-font',
'on-column',
'on-score'
);
$on-option-path-lists: ($ornament, $fans-medal, $danmaku, $icon-font, $column, $score);
$on-option-groups: zip($on-option-names, $on-option-path-lists);
html[#{$name}--detect--is-input-empty='false'] {
:not(#{$discard-paths}) {
font-family: $font-family-css;
}
@each $on-option-name, $on-option-path-list in $on-option-groups {
&[#{$name}--options--#{$on-option-name}='true'] :is(#{$on-option-path-list}) {
font-family: $font-family-css;
}
}
}