DarkTheme.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com>
  5. *
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author John Molakvoæ <skjnldsv@protonmail.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\Theming\Themes;
  26. use OCA\Theming\ITheme;
  27. class DarkTheme extends DefaultTheme implements ITheme {
  28. public function getId(): string {
  29. return 'dark';
  30. }
  31. public function getTitle(): string {
  32. return $this->l->t('Dark theme');
  33. }
  34. public function getEnableLabel(): string {
  35. return $this->l->t('Enable dark theme');
  36. }
  37. public function getDescription(): string {
  38. return $this->l->t('A dark theme to ease your eyes by reducing the overall luminosity and brightness.');
  39. }
  40. public function getMediaQuery(): string {
  41. return '(prefers-color-scheme: dark)';
  42. }
  43. public function getMeta(): array {
  44. // https://html.spec.whatwg.org/multipage/semantics.html#meta-color-scheme
  45. return [[
  46. 'name' => 'color-scheme',
  47. 'content' => 'dark',
  48. ]];
  49. }
  50. public function getCSSVariables(): array {
  51. $defaultVariables = parent::getCSSVariables();
  52. $colorMainText = '#EBEBEB';
  53. $colorMainBackground = '#171717';
  54. $colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground));
  55. $colorTextMaxcontrast = $this->util->darken($colorMainText, 32);
  56. $colorBoxShadow = $this->util->darken($colorMainBackground, 70);
  57. $colorBoxShadowRGB = join(',', $this->util->hexToRGB($colorBoxShadow));
  58. $colorError = '#FF3333';
  59. $colorWarning = '#FFCC00';
  60. $colorSuccess = '#3B973B';
  61. $colorInfo = '#00AEFF';
  62. return array_merge(
  63. $defaultVariables,
  64. $this->generatePrimaryVariables($colorMainBackground, $colorMainText),
  65. [
  66. '--color-main-text' => $colorMainText,
  67. '--color-main-background' => $colorMainBackground,
  68. '--color-main-background-rgb' => $colorMainBackgroundRGB,
  69. '--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .85)',
  70. '--color-scrollbar' => $this->util->lighten($colorMainBackground, 15),
  71. '--color-background-hover' => $this->util->lighten($colorMainBackground, 4),
  72. '--color-background-dark' => $this->util->lighten($colorMainBackground, 7),
  73. '--color-background-darker' => $this->util->lighten($colorMainBackground, 14),
  74. '--color-placeholder-light' => $this->util->lighten($colorMainBackground, 10),
  75. '--color-placeholder-dark' => $this->util->lighten($colorMainBackground, 20),
  76. '--color-text-maxcontrast' => $colorTextMaxcontrast,
  77. '--color-text-maxcontrast-default' => $colorTextMaxcontrast,
  78. '--color-text-maxcontrast-background-blur' => $this->util->lighten($colorTextMaxcontrast, 6),
  79. '--color-text-light' => 'var(--color-main-text)', // deprecated
  80. '--color-text-lighter' => 'var(--color-text-maxcontrast)', // deprecated
  81. '--color-error' => $colorError,
  82. '--color-error-rgb' => join(',', $this->util->hexToRGB($colorError)),
  83. '--color-error-hover' => $this->util->lighten($colorError, 10),
  84. '--color-error-text' => $this->util->lighten($colorError, 15),
  85. '--color-warning' => $colorWarning,
  86. '--color-warning-rgb' => join(',', $this->util->hexToRGB($colorWarning)),
  87. '--color-warning-hover' => $this->util->lighten($colorWarning, 10),
  88. '--color-warning-text' => $colorWarning,
  89. '--color-success' => $colorSuccess,
  90. '--color-success-rgb' => join(',', $this->util->hexToRGB($colorSuccess)),
  91. '--color-success-hover' => $this->util->lighten($colorSuccess, 10),
  92. '--color-success-text' => $this->util->lighten($colorSuccess, 15),
  93. '--color-info' => $colorInfo,
  94. '--color-info-rgb' => join(',', $this->util->hexToRGB($colorInfo)),
  95. '--color-info-hover' => $this->util->lighten($colorInfo, 10),
  96. '--color-info-text' => $colorInfo,
  97. '--color-favorite' => '#ffde00',
  98. // used for the icon loading animation
  99. '--color-loading-light' => '#777',
  100. '--color-loading-dark' => '#CCC',
  101. '--color-box-shadow' => $colorBoxShadow,
  102. '--color-box-shadow-rgb' => $colorBoxShadowRGB,
  103. '--color-border' => $this->util->lighten($colorMainBackground, 7),
  104. '--color-border-dark' => $this->util->lighten($colorMainBackground, 14),
  105. '--color-border-maxcontrast' => $this->util->lighten($colorMainBackground, 40),
  106. '--background-invert-if-dark' => 'invert(100%)',
  107. '--background-invert-if-bright' => 'no',
  108. ]
  109. );
  110. }
  111. }