You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /* eslint-disable quote-props */
  2. /* eslint-disable n/no-unpublished-import */
  3. import path from 'path'
  4. import fs from 'fs'
  5. import sass from 'sass'
  6. const colors = {
  7. dark: '000',
  8. white: 'fff',
  9. // gold but for backwards compatibility called yellow
  10. yellow: 'a08b00',
  11. red: 'e9322d',
  12. orange: 'eca700',
  13. green: '46ba61',
  14. grey: '969696',
  15. }
  16. const variables = {}
  17. const icons = {
  18. 'add': path.join(__dirname, '../img', 'actions', 'add.svg'),
  19. 'address': path.join(__dirname, '../img', 'actions', 'address.svg'),
  20. 'alert-outline': path.join(__dirname, '../img', 'actions', 'alert-outline.svg'),
  21. 'audio-off': path.join(__dirname, '../img', 'actions', 'audio-off.svg'),
  22. 'audio': path.join(__dirname, '../img', 'actions', 'audio.svg'),
  23. 'calendar': path.join(__dirname, '../img', 'places', 'calendar.svg'),
  24. 'caret': path.join(__dirname, '../img', 'actions', 'caret.svg'),
  25. 'category-app-bundles': path.join(__dirname, '../img', 'categories', 'bundles.svg'),
  26. 'category-auth': path.join(__dirname, '../img', 'categories', 'auth.svg'),
  27. 'category-customization': path.join(__dirname, '../img', 'categories', 'customization.svg'),
  28. 'category-dashboard': path.join(__dirname, '../img', 'categories', 'dashboard.svg'),
  29. 'category-files': path.join(__dirname, '../img', 'categories', 'files.svg'),
  30. 'category-games': path.join(__dirname, '../img', 'categories', 'games.svg'),
  31. 'category-integration': path.join(__dirname, '../img', 'categories', 'integration.svg'),
  32. 'category-monitoring': path.join(__dirname, '../img', 'categories', 'monitoring.svg'),
  33. 'category-multimedia': path.join(__dirname, '../img', 'categories', 'multimedia.svg'),
  34. 'category-office': path.join(__dirname, '../img', 'categories', 'office.svg'),
  35. 'category-organization': path.join(__dirname, '../img', 'categories', 'organization.svg'),
  36. 'category-social': path.join(__dirname, '../img', 'categories', 'social.svg'),
  37. 'category-workflow': path.join(__dirname, '../img', 'categories', 'workflow.svg'),
  38. 'change': path.join(__dirname, '../img', 'actions', 'change.svg'),
  39. 'checkmark': path.join(__dirname, '../img', 'actions', 'checkmark.svg'),
  40. 'circles': path.join(__dirname, '../img', 'apps', 'circles.svg'),
  41. 'clippy': path.join(__dirname, '../img', 'actions', 'clippy.svg'),
  42. 'close': path.join(__dirname, '../img', 'actions', 'close.svg'),
  43. 'comment': path.join(__dirname, '../img', 'actions', 'comment.svg'),
  44. 'confirm-fade': path.join(__dirname, '../img', 'actions', 'confirm-fade.svg'),
  45. 'confirm': path.join(__dirname, '../img', 'actions', 'confirm.svg'),
  46. 'contacts': path.join(__dirname, '../img', 'places', 'contacts.svg'),
  47. 'delete': path.join(__dirname, '../img', 'actions', 'delete.svg'),
  48. 'desktop': path.join(__dirname, '../img', 'clients', 'desktop.svg'),
  49. 'details': path.join(__dirname, '../img', 'actions', 'details.svg'),
  50. 'disabled-user': path.join(__dirname, '../img', 'actions', 'disabled-user.svg'),
  51. 'disabled-users': path.join(__dirname, '../img', 'actions', 'disabled-users.svg'),
  52. 'download': path.join(__dirname, '../img', 'actions', 'download.svg'),
  53. 'edit': path.join(__dirname, '../img', 'actions', 'edit.svg'),
  54. 'encryption': path.join(__dirname, '../../', 'apps/files_external/img', 'app.svg'),
  55. 'error': path.join(__dirname, '../img', 'actions', 'error.svg'),
  56. 'external': path.join(__dirname, '../img', 'actions', 'external.svg'),
  57. 'favorite': path.join(__dirname, '../img', 'actions', 'star-dark.svg'),
  58. 'files': path.join(__dirname, '../img', 'places', 'files.svg'),
  59. 'filter': path.join(__dirname, '../img', 'actions', 'filter.svg'),
  60. 'folder': path.join(__dirname, '../img', 'filetypes', 'folder.svg'),
  61. 'fullscreen': path.join(__dirname, '../img', 'actions', 'fullscreen.svg'),
  62. 'group': path.join(__dirname, '../img', 'actions', 'group.svg'),
  63. 'history': path.join(__dirname, '../img', 'actions', 'history.svg'),
  64. 'home': path.join(__dirname, '../img', 'places', 'home.svg'),
  65. 'info': path.join(__dirname, '../img', 'actions', 'info.svg'),
  66. 'link': path.join(__dirname, '../img', 'places', 'link.svg'),
  67. 'logout': path.join(__dirname, '../img', 'actions', 'logout.svg'),
  68. 'mail': path.join(__dirname, '../img', 'actions', 'mail.svg'),
  69. 'menu-sidebar': path.join(__dirname, '../img', 'actions', 'menu-sidebar.svg'),
  70. 'menu': path.join(__dirname, '../img', 'actions', 'menu.svg'),
  71. 'more': path.join(__dirname, '../img', 'actions', 'more.svg'),
  72. 'music': path.join(__dirname, '../img', 'places', 'music.svg'),
  73. 'password': path.join(__dirname, '../img', 'actions', 'password.svg'),
  74. 'pause': path.join(__dirname, '../img', 'actions', 'pause.svg'),
  75. 'phone': path.join(__dirname, '../img', 'clients', 'phone.svg'),
  76. 'picture': path.join(__dirname, '../img', 'places', 'picture.svg'),
  77. 'play-add': path.join(__dirname, '../img', 'actions', 'play-add.svg'),
  78. 'play-next': path.join(__dirname, '../img', 'actions', 'play-next.svg'),
  79. 'play-previous': path.join(__dirname, '../img', 'actions', 'play-previous.svg'),
  80. 'play': path.join(__dirname, '../img', 'actions', 'play.svg'),
  81. 'projects': path.join(__dirname, '../img', 'actions', 'projects.svg'),
  82. 'public': path.join(__dirname, '../img', 'actions', 'public.svg'),
  83. 'quota': path.join(__dirname, '../img', 'actions', 'quota.svg'),
  84. 'recent': path.join(__dirname, '../img', 'actions', 'recent.svg'),
  85. 'rename': path.join(__dirname, '../img', 'actions', 'rename.svg'),
  86. 'screen-off': path.join(__dirname, '../img', 'actions', 'screen-off.svg'),
  87. 'screen': path.join(__dirname, '../img', 'actions', 'screen.svg'),
  88. 'search': path.join(__dirname, '../img', 'actions', 'search.svg'),
  89. 'settings': path.join(__dirname, '../img', 'actions', 'settings-dark.svg'),
  90. 'share': path.join(__dirname, '../img', 'actions', 'share.svg'),
  91. 'shared': path.join(__dirname, '../img', 'actions', 'share.svg'),
  92. 'sound-off': path.join(__dirname, '../img', 'actions', 'sound-off.svg'),
  93. 'sound': path.join(__dirname, '../img', 'actions', 'sound.svg'),
  94. 'star': path.join(__dirname, '../img', 'actions', 'star.svg'),
  95. 'starred': path.join(__dirname, '../img', 'actions', 'star-dark.svg'),
  96. 'star-rounded': path.join(__dirname, '../img', 'actions', 'star-rounded.svg'),
  97. 'tablet': path.join(__dirname, '../img', 'clients', 'tablet.svg'),
  98. 'tag': path.join(__dirname, '../img', 'actions', 'tag.svg'),
  99. 'talk': path.join(__dirname, '../img', 'apps', 'spreed.svg'),
  100. 'teams': path.join(__dirname, '../img', 'apps', 'circles.svg'),
  101. 'template-add': path.join(__dirname, '../img', 'actions', 'template-add.svg'),
  102. 'timezone': path.join(__dirname, '../img', 'actions', 'timezone.svg'),
  103. 'toggle-background': path.join(__dirname, '../img', 'actions', 'toggle-background.svg'),
  104. 'toggle-filelist': path.join(__dirname, '../img', 'actions', 'toggle-filelist.svg'),
  105. 'toggle-pictures': path.join(__dirname, '../img', 'actions', 'toggle-pictures.svg'),
  106. 'toggle': path.join(__dirname, '../img', 'actions', 'toggle.svg'),
  107. 'triangle-e': path.join(__dirname, '../img', 'actions', 'triangle-e.svg'),
  108. 'triangle-n': path.join(__dirname, '../img', 'actions', 'triangle-n.svg'),
  109. 'triangle-s': path.join(__dirname, '../img', 'actions', 'triangle-s.svg'),
  110. 'unshare': path.join(__dirname, '../img', 'actions', 'unshare.svg'),
  111. 'upload': path.join(__dirname, '../img', 'actions', 'upload.svg'),
  112. 'user-admin': path.join(__dirname, '../img', 'actions', 'user-admin.svg'),
  113. 'user': path.join(__dirname, '../img', 'actions', 'user.svg'),
  114. 'video-off': path.join(__dirname, '../img', 'actions', 'video-off.svg'),
  115. 'video-switch': path.join(__dirname, '../img', 'actions', 'video-switch.svg'),
  116. 'video': path.join(__dirname, '../img', 'actions', 'video.svg'),
  117. 'view-close': path.join(__dirname, '../img', 'actions', 'view-close.svg'),
  118. 'view-download': path.join(__dirname, '../img', 'actions', 'view-download.svg'),
  119. 'view-next': path.join(__dirname, '../img', 'actions', 'arrow-right.svg'),
  120. 'view-pause': path.join(__dirname, '../img', 'actions', 'view-pause.svg'),
  121. 'view-play': path.join(__dirname, '../img', 'actions', 'view-play.svg'),
  122. 'view-previous': path.join(__dirname, '../img', 'actions', 'arrow-left.svg'),
  123. }
  124. const iconsColor = {
  125. 'add-folder-description': {
  126. path: path.join(__dirname, '../img', 'actions', 'add-folder-description.svg'),
  127. color: 'grey',
  128. },
  129. 'settings': {
  130. path: path.join(__dirname, '../img', 'actions', 'settings.svg'),
  131. color: 'black',
  132. },
  133. 'error-color': {
  134. path: path.join(__dirname, '../img', 'actions', 'error.svg'),
  135. color: 'red',
  136. },
  137. 'checkmark-color': {
  138. path: path.join(__dirname, '../img', 'actions', 'checkmark.svg'),
  139. color: 'green',
  140. },
  141. 'starred': {
  142. path: path.join(__dirname, '../img', 'actions', 'star-dark.svg'),
  143. color: 'yellow',
  144. },
  145. 'star': {
  146. path: path.join(__dirname, '../img', 'actions', 'star-dark.svg'),
  147. color: 'grey',
  148. },
  149. 'delete-color': {
  150. path: path.join(__dirname, '../img', 'actions', 'delete.svg'),
  151. color: 'red',
  152. },
  153. 'file': {
  154. path: path.join(__dirname, '../img', 'filetypes', 'text.svg'),
  155. color: 'grey',
  156. },
  157. 'filetype-file': {
  158. path: path.join(__dirname, '../img', 'filetypes', 'file.svg'),
  159. color: 'grey',
  160. },
  161. 'filetype-folder': {
  162. path: path.join(__dirname, '../img', 'filetypes', 'folder.svg'),
  163. // TODO: replace primary ?
  164. color: 'primary',
  165. },
  166. 'filetype-folder-drag-accept': {
  167. path: path.join(__dirname, '../img', 'filetypes', 'folder-drag-accept.svg'),
  168. // TODO: replace primary ?
  169. color: 'primary',
  170. },
  171. 'filetype-text': {
  172. path: path.join(__dirname, '../img', 'filetypes', 'text.svg'),
  173. color: 'grey',
  174. },
  175. }
  176. // use this to define aliases to existing icons
  177. // key is the css selector, value is the variable
  178. const iconsAliases = {
  179. 'icon-caret': 'icon-caret-white',
  180. // starring action
  181. 'icon-star:hover': 'icon-starred',
  182. 'icon-star:focus': 'icon-starred',
  183. // Un-starring action
  184. 'icon-starred:hover': 'icon-star-grey',
  185. 'icon-starred:focus': 'icon-star-grey',
  186. // Delete normal
  187. 'icon-delete.no-permission:hover': 'icon-delete-dark',
  188. 'icon-delete.no-permission:focus': 'icon-delete-dark',
  189. 'icon-delete.no-hover:hover': 'icon-delete-dark',
  190. 'icon-delete.no-hover:focus': 'icon-delete-dark',
  191. 'icon-delete:hover': 'icon-delete-color-red',
  192. 'icon-delete:focus': 'icon-delete-color-red',
  193. // Delete white
  194. 'icon-delete-white.no-permission:hover': 'icon-delete-white',
  195. 'icon-delete-white.no-permission:focus': 'icon-delete-white',
  196. 'icon-delete-white.no-hover:hover': 'icon-delete-white',
  197. 'icon-delete-white.no-hover:focus': 'icon-delete-white',
  198. 'icon-delete-white:hover': 'icon-delete-color-red',
  199. 'icon-delete-white:focus': 'icon-delete-color-red',
  200. // Default to white
  201. 'icon-view-close': 'icon-view-close-white',
  202. 'icon-view-download': 'icon-view-download-white',
  203. 'icon-view-pause': 'icon-view-pause-white',
  204. 'icon-view-play': 'icon-view-play-white',
  205. // Default app place to white
  206. 'icon-calendar': 'icon-calendar-white',
  207. 'icon-contacts': 'icon-contacts-white',
  208. 'icon-files': 'icon-files-white',
  209. // Re-using existing icons
  210. 'icon-category-installed': 'icon-user-dark',
  211. 'icon-category-enabled': 'icon-checkmark-dark',
  212. 'icon-category-disabled': 'icon-close-dark',
  213. 'icon-category-updates': 'icon-download-dark',
  214. 'icon-category-security': 'icon-password-dark',
  215. 'icon-category-search': 'icon-search-dark',
  216. 'icon-category-tools': 'icon-settings-dark',
  217. 'nav-icon-systemtagsfilter': 'icon-tag-dark',
  218. }
  219. const colorSvg = function(svg = '', color = '000') {
  220. if (!color.match(/^[0-9a-f]{3,6}$/i)) {
  221. // Prevent not-sane colors from being written into the SVG
  222. console.warn(color, 'does not match the required format')
  223. color = '000'
  224. }
  225. // add fill (fill is not present on black elements)
  226. const fillRe = /<((circle|rect|path)((?!fill)[a-z0-9 =".\-#():;,])+)\/>/gmi
  227. svg = svg.replace(fillRe, '<$1 fill="#' + color + '"/>')
  228. // replace any fill or stroke colors
  229. svg = svg.replace(/stroke="#([a-z0-9]{3,6})"/gmi, 'stroke="#' + color + '"')
  230. svg = svg.replace(/fill="#([a-z0-9]{3,6})"/gmi, 'fill="#' + color + '"')
  231. return svg
  232. }
  233. const generateVariablesAliases = function(invert = false) {
  234. let css = ''
  235. Object.keys(variables).forEach(variable => {
  236. if (variable.indexOf('original-') !== -1) {
  237. let finalVariable = variable.replace('original-', '')
  238. if (invert) {
  239. finalVariable = finalVariable.replace('white', 'tempwhite')
  240. .replace('dark', 'white')
  241. .replace('tempwhite', 'dark')
  242. }
  243. css += `${finalVariable}: var(${variable});`
  244. }
  245. })
  246. return css
  247. }
  248. const formatIcon = function(icon, invert = false) {
  249. const color1 = invert ? 'white' : 'dark'
  250. const color2 = invert ? 'dark' : 'white'
  251. return `
  252. .icon-${icon},
  253. .icon-${icon}-dark {
  254. background-image: var(--icon-${icon}-${color1});
  255. }
  256. .icon-${icon}-white,
  257. .icon-${icon}.icon-white {
  258. background-image: var(--icon-${icon}-${color2});
  259. }`
  260. }
  261. const formatIconColor = function(icon) {
  262. const { color } = iconsColor[icon]
  263. return `
  264. .icon-${icon} {
  265. background-image: var(--icon-${icon}-${color});
  266. }`
  267. }
  268. const formatAlias = function(alias, invert = false) {
  269. let icon = iconsAliases[alias]
  270. if (invert) {
  271. icon = icon.replace('white', 'tempwhite')
  272. .replace('dark', 'white')
  273. .replace('tempwhite', 'dark')
  274. }
  275. return `
  276. .${alias} {
  277. background-image: var(--${icon})
  278. }`
  279. }
  280. let css = ''
  281. Object.keys(icons).forEach(icon => {
  282. const path = icons[icon]
  283. const svg = fs.readFileSync(path, 'utf8')
  284. const darkSvg = colorSvg(svg, '000000')
  285. const whiteSvg = colorSvg(svg, 'ffffff')
  286. variables[`--original-icon-${icon}-dark`] = Buffer.from(darkSvg, 'utf-8').toString('base64')
  287. variables[`--original-icon-${icon}-white`] = Buffer.from(whiteSvg, 'utf-8').toString('base64')
  288. })
  289. Object.keys(iconsColor).forEach(icon => {
  290. const { path, color } = iconsColor[icon]
  291. const svg = fs.readFileSync(path, 'utf8')
  292. const coloredSvg = colorSvg(svg, colors[color])
  293. variables[`--icon-${icon}-${color}`] = Buffer.from(coloredSvg, 'utf-8').toString('base64')
  294. })
  295. // ICONS VARIABLES LIST
  296. css += ':root {'
  297. Object.keys(variables).forEach(variable => {
  298. const data = variables[variable]
  299. css += `${variable}: url(data:image/svg+xml;base64,${data});`
  300. })
  301. css += '}'
  302. // DEFAULT THEME
  303. css += 'body {'
  304. css += generateVariablesAliases()
  305. Object.keys(icons).forEach(icon => {
  306. css += formatIcon(icon)
  307. })
  308. Object.keys(iconsColor).forEach(icon => {
  309. css += formatIconColor(icon)
  310. })
  311. Object.keys(iconsAliases).forEach(alias => {
  312. css += formatAlias(alias)
  313. })
  314. css += '}'
  315. // DARK THEME MEDIA QUERY
  316. css += '@media (prefers-color-scheme: dark) { body {'
  317. css += generateVariablesAliases(true)
  318. css += '}}'
  319. // DARK THEME
  320. css += '[data-themes*=light] {'
  321. css += generateVariablesAliases()
  322. css += '}'
  323. // DARK THEME
  324. css += '[data-themes*=dark] {'
  325. css += generateVariablesAliases(true)
  326. css += '}'
  327. // WRITE CSS
  328. fs.writeFileSync(path.join(__dirname, '../../dist', 'icons.css'), sass.compileString(css).css)