Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/mail/avatar/dist/ |
Upload File : |
{"version":3,"file":"avatar.bundle.js","sources":["../src/avatar.js"],"sourcesContent":["import { Tag } from 'main.core';\nimport './css/style.css';\n\nexport class Avatar\n{\n\tstatic stringToHashCode(string)\n\t{\n\t\tlet hashCode = 0;\n\n\t\tfor (let i = 0; i < string.length; i++)\n\t\t{\n\t\t\thashCode = string.charCodeAt(i) + ((hashCode << 5) - hashCode);\n\t\t}\n\n\t\treturn hashCode;\n\t}\n\n\tstatic alignChannelRangeColor(chanelCode)\n\t{\n\t\tif(chanelCode > 255)\n\t\t{\n\t\t\treturn 255;\n\t\t}\n\t\telse if(chanelCode < 0)\n\t\t{\n\t\t\treturn 0;\n\t\t}\n\t\telse\n\t\t{\n\t\t\treturn Math.ceil(chanelCode);\n\t\t}\n\t}\n\n\tstatic hashToColor(hash)\n\t{\n\t\tconst maxIntensityAllChannels = 255*3;\n\t\tconst minIntensityAllChannels = 0;\n\t\tconst differenceCoefficientForGrayDetection = 0.20;\n\n\t\tlet r = (hash & 0xFF0000) >> 16;\n\t\tlet g = (hash & 0x00FF00) >> 8;\n\t\tlet b = (hash & 0x0000FF);\n\n\t\tconst contrastRatioForPastelColors = 1.5;\n\t\tconst contrastRatioForDarkColors = 2.5;\n\t\tconst channelReductionCoefficientIfGray = 2;\n\n\t\tif(maxIntensityAllChannels - (r+g+b) < 100)\n\t\t{\t//Pastel colors or white\n\t\t\tr/=contrastRatioForPastelColors;\n\t\t\tg/=contrastRatioForPastelColors;\n\t\t\tb/=contrastRatioForPastelColors;\n\t\t}\n\t\telse if((r+g+b) < (200 - minIntensityAllChannels))\n\t\t{\n\t\t\t//Very dark colors\n\t\t\tr*=contrastRatioForDarkColors;\n\t\t\tg*=contrastRatioForDarkColors;\n\t\t\tb*=contrastRatioForDarkColors;\n\t\t}\n\n\t\tlet channels = [r,g,b];\n\t\tchannels.sort(function(a,b){\n\t\t\treturn a - b;\n\t\t})\n\n\t\tif(((channels[channels.length - 1]-channels[0])/channels[0]) < differenceCoefficientForGrayDetection)\n\t\t{\n\t\t\t//Shade of gray\n\t\t\tg/=channelReductionCoefficientIfGray;\n\t\t}\n\n\t\tr=this.alignChannelRangeColor(r);\n\t\tg=this.alignChannelRangeColor(g);\n\t\tb=this.alignChannelRangeColor(b);\n\n\t\tconst color = \"#\" + (\"0\" + r.toString(16)).substr(-2) + (\"0\" + g.toString(16)).substr(-2) + (\"0\" + b.toString(16)).substr(-2);\n\t\treturn color.toUpperCase();\n\t}\n\n\tstatic stringToColor(name)\n\t{\n\t\treturn this.hashToColor(this.stringToHashCode(name));\n\t}\n\n\tstatic getInitials(string, email)\n\t{\n\t\tstring=string.replace(/[0-9]|[-\\u0026\\u002f\\u005c\\u0023\\u002c\\u002b\\u0028\\u0029\\u0024\\u007e\\u0025\\u002e\\u0027\\u0022\\u003a\\u002a\\u003f\\u003c\\u003e\\u007b\\u007d\\u00ab\\u00bb]/g,\"\");\n\t\tstring=string.replace(/^\\s+|\\s+$/g, '');\n\n\t\tconst names = string.split(' ');\n\n\t\tlet initials = names[0].substring(0, 1).toUpperCase();\n\n\t\tif (names.length > 1)\n\t\t{\n\t\t\tinitials += names[names.length - 1].substring(0, 1).toUpperCase();\n\t\t}\n\n\t\tif(initials === '')\n\t\t{\n\t\t\tinitials = email[0].toUpperCase();\n\t\t}\n\n\t\treturn initials;\n\t}\n\n\tstatic getAvatarData(config = {\n\t\tfullName: 'User Quest',\n\t\temail: 'info@example.com',\n\t})\n\t{\n\t\treturn {\n\t\t\t'abbreviation': this.getInitials(config['fullName'], config['email']),\n\t\t\t'color': this.stringToColor(config['email']),\n\t\t};\n\t}\n\n\tstatic build(config = {\n\t\tsize: 'small',\n\t\tfullName: 'User Quest',\n\t\temail: 'info@example.com',\n\t})\n\t{\n\t\tconst whiteList = new Set(['small', 'big']);\n\n\t\tif (config['size'] === undefined || !whiteList.has(config['size']))\n\t\t{\n\t\t\tconfig['size'] = 'small';\n\t\t}\n\n\t\tconst data = this.getAvatarData(config);\n\n\t\tlet avatar = Tag.render`<span class=\"mail-ui-avatar mail-ui-avatar-${config['size']}\">${data['abbreviation']}</span>`;\n\t\tavatar.style.backgroundColor = data['color'];\n\n\t\treturn avatar;\n\t}\n\n\tstatic replaceElementWithAvatar(object, avatar)\n\t{\n\t\tconst parent = object.parentNode;\n\t\tparent.insertBefore(avatar, object);\n\t\tparent.removeChild(object);\n\t}\n\n\tstatic replaceTagsWithAvatars(config = { className: 'mail-ui-avatar' })\n\t{\n\t\tconst elements = document.getElementsByClassName(config['className']);\n\t\tfor (let element of elements)\n\t\t{\n\t\t\tthis.replaceElementWithAvatar(element, this.build({\n\t\t\t\tfullName: element.getAttribute('user-name'),\n\t\t\t\temail: element.getAttribute('email'),\n\t\t\t}));\n\t\t}\n\t}\n}"],"names":["Avatar","string","hashCode","i","length","charCodeAt","chanelCode","Math","ceil","hash","maxIntensityAllChannels","minIntensityAllChannels","differenceCoefficientForGrayDetection","r","g","b","contrastRatioForPastelColors","contrastRatioForDarkColors","channelReductionCoefficientIfGray","channels","sort","a","alignChannelRangeColor","color","toString","substr","toUpperCase","name","hashToColor","stringToHashCode","email","replace","names","split","initials","substring","config","fullName","getInitials","stringToColor","size","whiteList","Set","undefined","has","data","getAvatarData","avatar","Tag","render","style","backgroundColor","object","parent","parentNode","insertBefore","removeChild","className","elements","document","getElementsByClassName","element","replaceElementWithAvatar","build","getAttribute"],"mappings":";;;;;;;;;;;KAGaA,MAAb;GAAA;KAAA;;;GAAA;KAAA;KAAA,iCAEyBC,MAFzB,EAGC;OACC,I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