hexo-theme-solitude 1.3.1 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. package/.github/FUNDING.yml +13 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.yml +107 -0
  3. package/.github/ISSUE_TEMPLATE/config.yml +13 -0
  4. package/.github/ISSUE_TEMPLATE/feature_request.yml +14 -0
  5. package/.github/workflows/npm-publish.yml +21 -0
  6. package/CONTRIBUTING.md +0 -0
  7. package/LICENSE +0 -0
  8. package/README.md +60 -43
  9. package/README_EN.md +60 -42
  10. package/_config.yml +602 -451
  11. package/languages/en-US.yml +4 -24
  12. package/languages/zh-CN.yml +4 -24
  13. package/layout/404.pug +1 -1
  14. package/layout/archive.pug +0 -0
  15. package/layout/category.pug +0 -0
  16. package/layout/includes/body/mode.pug +1 -6
  17. package/layout/includes/console.pug +3 -3
  18. package/layout/includes/footer.pug +16 -15
  19. package/layout/includes/head/config.pug +38 -30
  20. package/layout/includes/head/opengraph.pug +0 -0
  21. package/layout/includes/head/pwa.pug +5 -44
  22. package/layout/includes/head.pug +4 -2
  23. package/layout/includes/header.pug +0 -0
  24. package/layout/includes/inject/body.pug +114 -65
  25. package/layout/includes/inject/head.pug +11 -46
  26. package/layout/includes/layout.pug +1 -2
  27. package/layout/includes/loading.pug +0 -0
  28. package/layout/includes/mixins/articleSort.pug +0 -0
  29. package/layout/includes/mixins/pagination.pug +0 -0
  30. package/layout/includes/nav.pug +1 -1
  31. package/layout/includes/page/about.pug +1 -1
  32. package/layout/includes/page/categories.pug +0 -0
  33. package/layout/includes/page/default.pug +0 -0
  34. package/layout/includes/page/equipment.pug +0 -0
  35. package/layout/includes/page/links.pug +2 -2
  36. package/layout/includes/page/music.pug +0 -0
  37. package/layout/includes/page/not_configured.pug +0 -0
  38. package/layout/includes/page/rss.pug +3 -3
  39. package/layout/includes/page/says.pug +15 -15
  40. package/layout/includes/page/tags.pug +0 -0
  41. package/layout/includes/page/tlink.pug +1 -0
  42. package/layout/includes/recent-posts.pug +0 -0
  43. package/layout/includes/sidebar.pug +0 -0
  44. package/layout/includes/widgets/aside/aside.pug +6 -6
  45. package/layout/includes/widgets/aside/asideAllInfo.pug +0 -0
  46. package/layout/includes/widgets/aside/asideArchive.pug +0 -0
  47. package/layout/includes/widgets/aside/asideCustom.pug +1 -1
  48. package/layout/includes/widgets/aside/asideFlipCard.pug +0 -0
  49. package/layout/includes/widgets/aside/asideInfoCard.pug +3 -3
  50. package/layout/includes/widgets/aside/asideNewestPost.pug +0 -0
  51. package/layout/includes/widgets/aside/asideSwitch.pug +0 -4
  52. package/layout/includes/widgets/aside/asideTag.pug +1 -1
  53. package/layout/includes/widgets/aside/asideToc.pug +0 -0
  54. package/layout/includes/widgets/aside/asideWebInfo.pug +2 -2
  55. package/layout/includes/widgets/home/banner.pug +0 -0
  56. package/layout/includes/widgets/home/bb/json.pug +22 -0
  57. package/layout/includes/widgets/home/bb/local.pug +17 -0
  58. package/layout/includes/widgets/home/bb/memos.pug +25 -0
  59. package/layout/includes/widgets/home/bbTimeList.pug +11 -7
  60. package/layout/includes/widgets/home/categoryBar.pug +0 -0
  61. package/layout/includes/widgets/home/categoryGroup.pug +1 -1
  62. package/layout/includes/widgets/home/hometop.pug +0 -0
  63. package/layout/includes/widgets/home/postList.pug +0 -0
  64. package/layout/includes/widgets/home/topGroup.pug +0 -0
  65. package/layout/includes/widgets/nav/left.pug +0 -0
  66. package/layout/includes/widgets/nav/menu.pug +1 -1
  67. package/layout/includes/widgets/nav/right.pug +6 -5
  68. package/layout/includes/widgets/page/about/authorinfo.pug +10 -9
  69. package/layout/includes/widgets/page/about/award.pug +0 -0
  70. package/layout/includes/widgets/page/about/contentinfo.pug +35 -34
  71. package/layout/includes/widgets/page/about/hobbies.pug +21 -17
  72. package/layout/includes/widgets/page/about/motto.pug +17 -16
  73. package/layout/includes/widgets/page/about/other.pug +16 -16
  74. package/layout/includes/widgets/page/about/personalities.pug +15 -14
  75. package/layout/includes/widgets/page/about/skillsinfo.pug +37 -36
  76. package/layout/includes/widgets/page/about/tenyear.pug +0 -0
  77. package/layout/includes/widgets/page/banner.pug +9 -3
  78. package/layout/includes/widgets/page/equipment/content.pug +0 -0
  79. package/layout/includes/widgets/page/links/banner.pug +14 -12
  80. package/layout/includes/widgets/page/links/linksCard.pug +4 -6
  81. package/layout/includes/widgets/page/links/linksDiscn.pug +8 -0
  82. package/layout/includes/widgets/page/links/linksItem.pug +4 -6
  83. package/layout/includes/widgets/page/says/json.pug +78 -0
  84. package/layout/includes/widgets/page/says/local.pug +44 -0
  85. package/layout/includes/widgets/page/says/memos.pug +107 -0
  86. package/layout/includes/widgets/post/award.pug +0 -0
  87. package/layout/includes/widgets/post/copyright.pug +2 -2
  88. package/layout/includes/widgets/post/post-ai.pug +12 -0
  89. package/layout/includes/widgets/post/postMeta.pug +2 -2
  90. package/layout/includes/widgets/post/postNav.pug +0 -0
  91. package/layout/includes/widgets/post/wave.pug +0 -0
  92. package/layout/includes/widgets/randomlink.pug +1 -1
  93. package/layout/includes/widgets/rightside/index.pug +6 -5
  94. package/layout/includes/widgets/third-party/comments/comment.pug +1 -5
  95. package/layout/includes/widgets/third-party/comments/twikoo.pug +1 -1
  96. package/layout/includes/widgets/third-party/comments/waline.pug +9 -11
  97. package/layout/includes/widgets/third-party/music.pug +1 -1
  98. package/layout/includes/widgets/third-party/news-comment/newest-comment.pug +6 -0
  99. package/layout/includes/widgets/third-party/news-comment/twikoo.pug +70 -0
  100. package/layout/includes/widgets/third-party/news-comment/waline.pug +64 -0
  101. package/layout/includes/widgets/third-party/pjax.pug +0 -0
  102. package/layout/includes/widgets/third-party/search/algolia-search.pug +0 -0
  103. package/layout/includes/widgets/third-party/search/index.pug +8 -7
  104. package/layout/includes/widgets/third-party/search/local-search.pug +0 -0
  105. package/layout/index.pug +3 -3
  106. package/layout/page.pug +0 -4
  107. package/layout/post.pug +2 -2
  108. package/layout/tag.pug +0 -0
  109. package/package.json +18 -9
  110. package/plugins.yml +109 -0
  111. package/scripts/event/cdn.js +129 -0
  112. package/scripts/event/init.js +0 -0
  113. package/scripts/event/page.js +1 -21
  114. package/scripts/event/welcome.js +1 -1
  115. package/scripts/filter/checkThemeConfig.js +0 -0
  116. package/scripts/filter/default.js +0 -0
  117. package/scripts/filter/lazyload.js +1 -1
  118. package/scripts/filter/randomPosts.js +0 -0
  119. package/scripts/helper/cdn.js +0 -0
  120. package/scripts/helper/getArchiveLength.js +0 -0
  121. package/scripts/helper/page.js +0 -0
  122. package/scripts/helper/related_post.js +0 -0
  123. package/scripts/helper/stylus.js +0 -0
  124. package/scripts/tags/button.js +0 -0
  125. package/scripts/tags/bvideo.js +0 -0
  126. package/scripts/tags/card.js +0 -0
  127. package/scripts/tags/checkbox.js +0 -0
  128. package/scripts/tags/fold.js +0 -0
  129. package/scripts/tags/image.js +0 -0
  130. package/scripts/tags/inline-image.js +0 -0
  131. package/scripts/tags/label.js +0 -0
  132. package/scripts/tags/link.js +0 -0
  133. package/scripts/tags/media.js +0 -0
  134. package/scripts/tags/note.js +0 -0
  135. package/scripts/tags/span.js +0 -0
  136. package/scripts/tags/tabs.js +0 -0
  137. package/scripts/tags/timeline.js +0 -0
  138. package/scripts/tags/u.js +0 -0
  139. package/source/css/_global/animation.css +0 -0
  140. package/source/css/_global/function.styl +42 -42
  141. package/source/css/_global/index.styl +1 -1
  142. package/source/css/_global/var.styl +0 -0
  143. package/source/css/_layout/basic.styl +16 -13
  144. package/source/css/_layout/header.styl +7 -2
  145. package/source/css/_layout/index.styl +59 -5
  146. package/source/css/_mode/index.styl +1 -17
  147. package/source/css/_page/_home/category-bar.styl +0 -0
  148. package/source/css/_page/_home/home-top.styl +10 -31
  149. package/source/css/_page/_home/index.styl +0 -0
  150. package/source/css/_page/_home/pagination.styl +3 -0
  151. package/source/css/_page/_home/recent-post.styl +10 -3
  152. package/source/css/_page/about/author.styl +94 -0
  153. package/source/css/_page/about/buff.styl +34 -0
  154. package/source/css/_page/about/careers.styl +27 -0
  155. package/source/css/_page/about/contentinfo.styl +78 -0
  156. package/source/css/_page/about/game.styl +41 -0
  157. package/source/css/_page/about/index.styl +39 -1
  158. package/source/css/_page/about/like.styl +29 -0
  159. package/source/css/_page/about/maxim.styl +23 -0
  160. package/source/css/_page/about/myphoto.styl +34 -0
  161. package/source/css/_page/about/oneself.styl +91 -0
  162. package/source/css/_page/about/personalities.styl +25 -0
  163. package/source/css/_page/about/reward.styl +113 -0
  164. package/source/css/_page/about/skills.styl +75 -0
  165. package/source/css/_page/about/statistic.styl +55 -0
  166. package/source/css/_page/about/tenyear.styl +0 -0
  167. package/source/css/_page/category.styl +0 -0
  168. package/source/css/_page/douban.styl +0 -1
  169. package/source/css/_page/equipment.styl +0 -0
  170. package/source/css/_page/error.styl +0 -0
  171. package/source/css/_page/home.styl +0 -0
  172. package/source/css/_page/index.styl +20 -5
  173. package/source/css/_page/links.styl +84 -49
  174. package/source/css/_page/moment.styl +0 -0
  175. package/source/css/_page/music.styl +0 -0
  176. package/source/css/_page/rss.styl +0 -0
  177. package/source/css/_page/says.styl +10 -0
  178. package/source/css/_page/tag.styl +0 -0
  179. package/source/css/_widgets/_aside/allinfo.styl +34 -0
  180. package/source/css/_widgets/_aside/flip.styl +0 -0
  181. package/source/css/_widgets/_aside/index.styl +1 -7
  182. package/source/css/_widgets/_aside/info.styl +0 -0
  183. package/source/css/_widgets/_aside/newPost.styl +0 -0
  184. package/source/css/_widgets/_aside/toc.styl +0 -0
  185. package/source/css/_widgets/_aside/welcome.styl +0 -0
  186. package/source/css/_widgets/_comment/index.styl +0 -0
  187. package/source/css/_widgets/_comment/twikoo.styl +0 -2
  188. package/source/css/_widgets/_comment/waline.styl +0 -0
  189. package/source/css/_widgets/_extra/console.styl +0 -0
  190. package/source/css/_widgets/_extra/fullpage.styl +0 -0
  191. package/source/css/_widgets/_extra/music.styl +1 -1
  192. package/source/css/_widgets/_extra/pace.styl +0 -0
  193. package/source/css/_widgets/_extra/rightmenu.styl +0 -0
  194. package/source/css/_widgets/_mixins/article-sort.styl +0 -0
  195. package/source/css/_widgets/_mixins/footer.styl +1 -2
  196. package/source/css/_widgets/_mixins/other.styl +0 -4
  197. package/source/css/_widgets/_mixins/sidebar.styl +0 -0
  198. package/source/css/_widgets/_post/_highlight/diff.styl +0 -0
  199. package/source/css/_widgets/_post/_highlight/index.styl +0 -1
  200. package/source/css/_widgets/_post/_highlight/theme/default.styl +0 -0
  201. package/source/css/_widgets/_post/_highlight/theme/mac.styl +0 -0
  202. package/source/css/_widgets/_post/_highlight/theme.styl +0 -0
  203. package/source/css/_widgets/_post/commentBarrage.styl +0 -0
  204. package/source/css/_widgets/_post/content.styl +42 -11
  205. package/source/css/_widgets/_post/copyright.styl +0 -0
  206. package/source/css/_widgets/_post/index.styl +1 -1
  207. package/source/css/_widgets/_post/meta.styl +0 -3
  208. package/source/css/_widgets/_post/pagination.styl +1 -1
  209. package/source/css/_widgets/_post/postAI.styl +0 -0
  210. package/source/css/_widgets/_post/relatedPost.styl +0 -0
  211. package/source/css/_widgets/_post/tools.styl +0 -0
  212. package/source/css/_widgets/_search/algolia-search.styl +0 -0
  213. package/source/css/_widgets/_search/local-search.styl +0 -0
  214. package/source/css/_widgets/_tags/button.styl +0 -0
  215. package/source/css/_widgets/_tags/bvideo.styl +0 -0
  216. package/source/css/_widgets/_tags/card.styl +0 -0
  217. package/source/css/_widgets/_tags/checkbox.styl +0 -0
  218. package/source/css/_widgets/_tags/fold.styl +0 -0
  219. package/source/css/_widgets/_tags/image.styl +0 -0
  220. package/source/css/_widgets/_tags/index.styl +0 -0
  221. package/source/css/_widgets/_tags/inline-image.styl +0 -0
  222. package/source/css/_widgets/_tags/label.styl +0 -0
  223. package/source/css/_widgets/_tags/link.styl +4 -2
  224. package/source/css/_widgets/_tags/note.styl +0 -0
  225. package/source/css/_widgets/_tags/span.styl +0 -0
  226. package/source/css/_widgets/_tags/tabs.styl +0 -0
  227. package/source/css/_widgets/_tags/timeline.styl +0 -1
  228. package/source/css/_widgets/index.styl +4 -4
  229. package/source/css/index.styl +0 -0
  230. package/source/img/avatar.png +0 -0
  231. package/source/img/default.png +0 -0
  232. package/source/img/error_load.png +0 -0
  233. package/source/js/{extend/comment/twikoo/commentBarrage.js → comment/twikoo_commentBarrage.js} +0 -0
  234. package/source/js/{extend/comment/waline/commentBarrage.js → comment/waline_commentBarrage.js} +0 -0
  235. package/source/js/covercolor/api.js +92 -0
  236. package/source/js/covercolor/local.js +85 -0
  237. package/source/js/main.js +28 -235
  238. package/source/js/music.js +0 -0
  239. package/source/js/rightside.js +404 -0
  240. package/source/js/{extend/search/algolia-search.js → search/algolia.js} +10 -0
  241. package/source/js/{extend/search/local-search.js → search/local.js} +24 -2
  242. package/source/js/utils.js +75 -1
  243. package/layout/includes/head/fest.pug +0 -22
  244. package/layout/includes/page/echarts.pug +0 -7
  245. package/layout/includes/page/moments.pug +0 -4
  246. package/layout/includes/widgets/aside/asideHistory.pug +0 -8
  247. package/layout/includes/widgets/aside/asideWelcome.pug +0 -12
  248. package/layout/includes/widgets/page/moments/angle.pug +0 -19
  249. package/layout/includes/widgets/page/moments/index.pug +0 -23
  250. package/layout/includes/widgets/page/says/saysBottom.pug +0 -11
  251. package/layout/includes/widgets/page/says/saysContent.pug +0 -6
  252. package/layout/includes/widgets/page/says/saysFunction.pug +0 -10
  253. package/layout/includes/widgets/page/says/saysMeta.pug +0 -7
  254. package/layout/includes/widgets/third-party/ai/index.pug +0 -12
  255. package/layout/includes/widgets/third-party/comments/gitalk.pug +0 -0
  256. package/layout/includes/widgets/third-party/comments/valine.pug +0 -0
  257. package/scripts/helper/echarts.js +0 -407
  258. package/source/css/_page/about.styl +0 -764
  259. package/source/css/_widgets/_aside/history.styl +0 -42
  260. package/source/js/extend/comment/twikoo/twikoo.js +0 -67
  261. package/source/js/extend/comment/waline/waline.js +0 -60
  262. package/source/lib/bundle.min.js +0 -27
  263. package/source/lib/circle.min.js +0 -1
  264. package/source/lib/cover-color.min.js +0 -7
  265. package/source/lib/friends_post.js +0 -4
  266. package/source/lib/lazyload.min.js +0 -1
  267. package/source/lib/rightside.min.js +0 -1
  268. package/source/lib/snackbar.min.css +0 -1
  269. package/source/lib/snackbar.min.js +0 -9
  270. package/source/lib/txmap.min.js +0 -1
  271. package/source/lib/universe.min.js +0 -1
  272. package/source/lib/view-image.min.js +0 -6
  273. package/source/lib/waterfall.min.js +0 -1
  274. /package/source/{lib → js}/sco-ai.min.js +0 -0
@@ -0,0 +1,92 @@
1
+ const coverColor = () => {
2
+ const path = document.getElementById("post-cover")?.src;
3
+ if (path) {
4
+ handleApiColor(path);
5
+ }
6
+ }
7
+
8
+ function handleApiColor(path) {
9
+ const cacheGroup = JSON.parse(localStorage.getItem('Solitude')) || {};
10
+ console.log(cacheGroup)
11
+ if (cacheGroup.postcolor && cacheGroup.postcolor[path]) {
12
+ const color = cacheGroup.postcolor[path].value;
13
+ const [r, g, b] = color.match(/\w\w/g).map(x => parseInt(x, 16));
14
+ setThemeColors(color, r, g, b);
15
+ } else {
16
+ img2color(path);
17
+ }
18
+ }
19
+
20
+ function img2color(src) {
21
+ const apiUrl = coverColorConfig.api + encodeURIComponent(src);
22
+ fetch(apiUrl)
23
+ .then(response => response.json())
24
+ .then(data => {
25
+ const color = data.RGB;
26
+ const [r, g, b] = color.match(/\w\w/g).map(x => parseInt(x, 16));
27
+ setThemeColors(color, r, g, b);
28
+ const expirationTime = Date.now() + coverColorConfig.time;
29
+ const cacheGroup = saveToLocal.get('Solitude') || {};
30
+ cacheGroup.postcolor = cacheGroup.postcolor || {};
31
+ cacheGroup.postcolor[src] = {value: color, expiration: expirationTime};
32
+ localStorage.setItem('Solitude', JSON.stringify(cacheGroup));
33
+ })
34
+ .catch(error => {
35
+ console.error('请检查API是否正常!\n' + error);
36
+ setThemeColors();
37
+ });
38
+ }
39
+
40
+ function setThemeColors(value, r = null, g = null, b = null) {
41
+ if (value) {
42
+ document.documentElement.style.setProperty('--sco-main', value);
43
+ document.documentElement.style.setProperty('--sco-main-op', value + '23');
44
+ document.documentElement.style.setProperty('--sco-main-op-deep', value + 'dd');
45
+ document.documentElement.style.setProperty('--sco-main-none', value + '00');
46
+
47
+ if (r && g && b) {
48
+ var brightness = Math.round(((parseInt(r) * 299) + (parseInt(g) * 587) + (parseInt(b) * 114)) / 1000);
49
+ if (brightness < 125) {
50
+ var cardContents = document.getElementsByClassName('card-content');
51
+ for (let i = 0; i < cardContents.length; i++) {
52
+ cardContents[i].style.setProperty('--sco-card-bg', 'var(--sco-white)');
53
+ }
54
+
55
+ var authorInfo = document.getElementsByClassName('author-info__sayhi');
56
+ for (let i = 0; i < authorInfo.length; i++) {
57
+ authorInfo[i].style.setProperty('background', 'var(--sco-white-op)');
58
+ authorInfo[i].style.setProperty('color', 'var(--sco-white)');
59
+ }
60
+ }
61
+ }
62
+
63
+ document.getElementById("coverdiv").classList.add("loaded");
64
+ initThemeColor();
65
+ } else {
66
+ document.documentElement.style.setProperty('--sco-main', 'var(--sco-theme)');
67
+ document.documentElement.style.setProperty('--sco-main-op', 'var(--sco-theme-op)');
68
+ document.documentElement.style.setProperty('--sco-main-op-deep', 'var(--sco-theme-op-deep)');
69
+ document.documentElement.style.setProperty('--sco-main-none', 'var(--sco-theme-none)');
70
+ initThemeColor();
71
+ }
72
+ }
73
+
74
+ function initThemeColor() {
75
+ const currentTop = window.scrollY || document.documentElement.scrollTop;
76
+ let themeColor;
77
+ if (currentTop > 0) {
78
+ themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-card-bg');
79
+ } else if (PAGE_CONFIG.is_post) {
80
+ themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-main');
81
+ } else {
82
+ themeColor = getComputedStyle(document.documentElement).getPropertyValue('--sco-background');
83
+ }
84
+ changeThemeColor(themeColor);
85
+ }
86
+
87
+ function changeThemeColor(color) {
88
+ const meta = document.querySelector('meta[name="theme-color"]');
89
+ if (meta) {
90
+ meta.setAttribute('content', color);
91
+ }
92
+ }
@@ -0,0 +1,85 @@
1
+ function coverColor() {
2
+ const path = document.getElementById("post-cover")?.src;
3
+
4
+ if (path) {
5
+ localColor(path);
6
+ }
7
+ }
8
+
9
+ function localColor(path) {
10
+ const img = new Image();
11
+ img.crossOrigin = "Anonymous";
12
+ img.onload = function () {
13
+ const canvas = document.createElement("canvas");
14
+ canvas.width = this.width;
15
+ canvas.height = this.height;
16
+ const ctx = canvas.getContext("2d");
17
+ ctx.drawImage(this, 0, 0);
18
+ const data = ctx.getImageData(0, 0, this.width, this.height).data;
19
+ const {r, g, b} = calculateRGB(data);
20
+ let value = rgbToHex(r, g, b);
21
+ if (getContrastYIQ(value) === "light") {
22
+ value = LightenDarkenColor(value, -50);
23
+ }
24
+ setThemeColors(value, r, g, b);
25
+ };
26
+ img.src = path;
27
+ }
28
+
29
+ function rgbToHex(r, g, b) {
30
+ return "#" + [r, g, b].map(x => x.toString(16).padStart(2, '0')).join('');
31
+ }
32
+
33
+ function LightenDarkenColor(col, amt) {
34
+ let usePound = false;
35
+
36
+ if (col[0] === "#") {
37
+ col = col.slice(1);
38
+ usePound = true;
39
+ }
40
+
41
+ const num = parseInt(col, 16);
42
+ const r = Math.min(255, Math.max(0, (num >> 16) + amt));
43
+ const b = Math.min(255, Math.max(0, ((num >> 8) & 0xff) + amt));
44
+ const g = Math.min(255, Math.max(0, (num & 0xff) + amt));
45
+
46
+ return `${usePound ? "#" : ""}${(g | (b << 8) | (r << 16)).toString(16).padStart(6, "0")}`;
47
+ }
48
+
49
+ function getContrastYIQ(hexcolor) {
50
+ var colorrgb = colorRgb(hexcolor);
51
+ var colors = colorrgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
52
+ var red = colors[1];
53
+ var green = colors[2];
54
+ var blue = colors[3];
55
+ var brightness = (red * 299) + (green * 587) + (blue * 114);
56
+ brightness = brightness / 255000;
57
+ return brightness >= 0.5 ? "light" : "dark";
58
+ }
59
+
60
+ function colorRgb(str) {
61
+ const HEX_SHORT_REGEX = /^#([0-9a-fA-f]{3})$/;
62
+ const HEX_LONG_REGEX = /^#([0-9a-fA-f]{6})$/;
63
+ const HEX_SHORT_LENGTH = 4;
64
+
65
+ if (!str || typeof str !== 'string') {
66
+ return str;
67
+ }
68
+
69
+ const sColor = str.toLowerCase();
70
+ let hexValue = "";
71
+
72
+ if (sColor && (HEX_SHORT_REGEX.test(sColor) || HEX_LONG_REGEX.test(sColor))) {
73
+ hexValue = sColor.length === HEX_SHORT_LENGTH ?
74
+ sColor.replace(/^#(.)/g, "#$1$1") :
75
+ sColor;
76
+
77
+ const rgbValue = hexValue.slice(1)
78
+ .match(/.{2}/g)
79
+ .map(val => parseInt(val, 16));
80
+
81
+ return `rgb(${rgbValue[0]}, ${rgbValue[1]}, ${rgbValue[2]})`;
82
+ } else {
83
+ return sColor;
84
+ }
85
+ }