gitea

Development moved to Codeberg

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
  101. 101
  102. 102
  103. 103
  104. 104
  105. 105
  106. 106
  107. 107
  108. 108
  109. 109
  110. 110
  111. 111
  112. 112
  113. 113
  114. 114
  115. 115
  116. 116
  117. 117
  118. 118
  119. 119
  120. 120
  121. 121
  122. 122
  123. 123
  124. 124
  125. 125
  126. 126
  127. 127
  128. 128
  129. 129
  130. 130
/* font i18n */
:root {
  /* customizable localized variables */
  :lang(ja) {
    --fonts-override: var(--fonts-default-override-ja);
  }
  :lang(zh-CN) {
    --fonts-override: var(--fonts-default-override-zh-cn);
  }
  :lang(zh-TW) {
    --fonts-override: var(--fonts-default-override-zh-tw);
  }
  :lang(zh-HK) {
    --fonts-override: var(--fonts-default-override-zh-hk);
  }
  :lang(ko) {
    --fonts-override: var(--fonts-default-override-ko);
  }
}

[lang] {
  font-family: var(--fonts-regular);
}

each(@fonts, {
  @weights: .gen-weights-all(@value);
  @locale: replace(@key, "@", "-");
  .font-face-cjk(~"system-ui@{locale}", @weights[@light], 300);
  .font-face-cjk(~"system-ui@{locale}", @weights[@regular], 400);
  .font-face-cjk(~"system-ui@{locale}", @weights[@medium], 500);
  .font-face-cjk(~"system-ui@{locale}", @weights[@bold], 700);
  /* Safari on macOS/iOS */
  @font-face {
    font-family: ~"system-ui@{locale}";
    src: local("HelveticaNeue");
    unicode-range: U+A0;
  }
  /* Other browsers on macOS/iOS */
  @supports not (-webkit-hyphens:none) {
    @font-face {
      font-family: ~"system-ui@{locale}";
      src: local("HelveticaNeue");
      unicode-range: U+20;
    }
  }
  :root {
    /* Special handling for Firefox on Windows/Linux */
    @supports (-moz-appearance:none) {
      --fonts-default-override@{locale}: ~"var(--fonts-proportional), system-ui@{locale}";
    }
    --fonts-default-override@{locale}: ~"system-ui@{locale}, var(--fonts-proportional)";
  }
});

@fonts: {
  @ja:
    "HiraKakuProN-:{W3,W6}", "Hiragino Kaku Gothic ProN :{W3,W6}", "HiraginoSans-:{W2,W4,W5,W6}",
    .shs("JP")[], .shs("J")[], .noto("JP")[], .shs("")[],
    /* https://acetaminophen.hatenablog.com/entry/2016/02/15/225009 */
    "Yu Gothic :{Regular,Medium,Bold}", "YuGothic :{Regular,Medium,Bold}",
    "Droid Sans Japanese:{}", "Meiryo:{, Bold}", "MS PGothic:{}";
  @zh-cn:
    .pingfang("SC")[],
    .shs("CN")[], .shs("SC")[], .noto("SC")[],
    "HiraginoSansGB-:{W3,W6}", "Hiragino Sans GB :{W3,W6}",
    "Microsoft YaHei:{ Light,, Bold}", "Heiti SC :{Light,Medium}", "SimHei:{}";
  @zh-tw:
    .pingfang("TC")[],
    .shs("TW")[], .shs("TC")[], .noto("TC")[],
    "HiraginoSansTC-:{W3,W6}", "Hiragino Sans TC :{W3,W6}",
    "Microsoft JhengHei:{ Light,, Bold}", "Heiti TC :{Light,Medium}", "PMingLiU:{}";
  @zh-hk:
    .pingfang("HK")[],
    .shs("HK")[], .shs("HC")[], .noto("HK")[], .shs("TC")[], .noto("TC")[],
    "HiraginoSansTC-:{W3,W6}", "Hiragino Sans TC :{W3,W6}",
    "Microsoft JhengHei:{ Light,, Bold}", "Heiti TC :{Light,Medium}", "PMingLiU_HKSCS:{}", "PMingLiU:{}";
  @ko:
    "AppleSDGothicNeo-:{Light,Regular,Medium,SemiBold}",
    .shs("KR")[], .shs("K")[], .noto("KR")[],
    "NanumBarunGothic:{ Light,, Bold}",
    "Malgun Gothic:{ Semilight,, Bold}", "Nanum Gothic:{, Bold}", "Dotum:{}";
}

.noto(@suffix) { @value: "Noto Sans CJK @{suffix} ", "NotoSansCJK@{suffix}-"; }
.shs(@suffix) { @value: replace("Source Han Sans @{suffix} ", "  ", " "), "SourceHanSans@{suffix}-"; }
.pingfang(@suffix) { @value: "PingFang@{suffix}-:{Light,Regular,Medium,Semibold}"; }
.font-face-cjk(@family, @src, @weight) {
  @font-face {
    font-family: @family;
    src: @src;
    font-weight: @weight;
    unicode-range: ~"U+11??, U+2E80-4DBF, U+4E00-9FFF, U+A960-A97F, U+AC00-D7FF, U+F900-FAFF, U+FE00-FE6F, U+FF00-FFEF, U+1F2??, U+2????";
  }
}

.gen-weights(@family) when (isstring(@family)) {
  @family-str: replace(@family, ":\{.*\}$", "");
  // apply standard style names if none is given
  // should the font have no styles, use :{}, as in "SimHei:{}"
  @weights-str: if(@family = @family-str, "Light,Regular,Medium,Bold", replace(@family, ".*:\{(.*)\}$", "$1"));
  @lightest: replace(@weights-str, ",.*", "");
  @boldest: replace(@weights-str, ".*,", "");
  @2ndboldest: replace(@weights-str, "(?:.*,|)([^,]*),.*$", "$1");
  @2ndlightest: if(@2ndboldest = @lightest, @lightest, replace(@weights-str, "^.*?,([^,]*).*", "$1"));

  @light: local("@{family-str}@{lightest}");
  @regular: local("@{family-str}@{2ndlightest}");
  @medium: local("@{family-str}@{2ndboldest}");
  @bold: local("@{family-str}@{boldest}");
}
.gen-weights(@family) when not (isstring(@family)) {
  .gen-weights-all(@family);
}
.gen-weights(@family, @last) {
  @this: .gen-weights(@family);

  @light: @last[@light], @this[@light];
  @regular: @last[@regular], @this[@regular];
  @medium: @last[@medium], @this[@medium];
  @bold: @last[@bold], @this[@bold];
}
.gen-weights-all(@family) when not (isstring(@family)) {
  .gen-weights-all(@family, length(@family));
}
.gen-weights-all(@family, 1) when not (isstring(@family)) {
  .gen-weights(extract(@family, 1));
}
.gen-weights-all(@family, @ctr) when not (isstring(@family)) and (@ctr > 1) and (@ctr <= length(@family)) {
  .gen-weights(extract(@family, @ctr), .gen-weights-all(@family, @ctr - 1));
}