1((Drupal, drupalSettings, once) => { 2 Drupal.behaviors.ginAccent = { 3 attach: function(context) { 4 once("ginAccent", "body", context).forEach((() => { 5 Drupal.ginAccent.checkDarkmode(), Drupal.ginAccent.setAccentColor(), Drupal.ginAccent.setFocusColor(); 6 })); 7 } 8 }, Drupal.ginAccent = { 9 setAccentColor: function() { 10 let preset = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : null, color = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : null; 11 const accentColorPreset = null != preset ? preset : drupalSettings.gin.preset_accent_color; 12 document.body.setAttribute("data-gin-accent", accentColorPreset), "custom" === accentColorPreset && this.setCustomAccentColor(color); 13 }, 14 setCustomAccentColor: function() { 15 let color = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : null, element = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : document.body; 16 const accentColor = null != color ? color : drupalSettings.gin.accent_color; 17 if (accentColor) { 18 this.clearAccentColor(element); 19 const strippedAccentColor = accentColor.replace("#", ""), darkAccentColor = this.mixColor("ffffff", strippedAccentColor, 65).replace("#", ""), style = document.createElement("style"); 20 style.className = "gin-custom-colors", style.innerHTML = `\n [data-gin-accent="custom"] {\n --gin-color-primary-rgb: ${this.hexToRgb(accentColor)};\n --gin-color-primary-hover: ${this.shadeColor(accentColor, -10)};\n --gin-color-primary-active: ${this.shadeColor(accentColor, -15)};\n --gin-bg-app-rgb: ${this.hexToRgb(this.mixColor("ffffff", strippedAccentColor, 97))};\n --gin-bg-header: ${this.mixColor("ffffff", strippedAccentColor, 85)};\n --gin-color-sticky-rgb: ${this.hexToRgb(this.mixColor("ffffff", strippedAccentColor, 92))};\n }\n .gin--dark-mode[data-gin-accent="custom"],\n .gin--dark-mode [data-gin-accent="custom"] {\n --gin-color-primary-rgb: ${this.hexToRgb(darkAccentColor)};\n --gin-color-primary-hover: ${this.mixColor("ffffff", strippedAccentColor, 55)};\n --gin-color-primary-active: ${this.mixColor("ffffff", strippedAccentColor, 50)};\n --gin-bg-header: ${this.mixColor("2A2A2D", darkAccentColor, 88)};\n }\n `, 21 element.append(style); 22 } 23 }, 24 clearAccentColor: function() { 25 let element = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : document.body; 26 if (element.querySelectorAll(".gin-custom-colors").length > 0) { 27 const removeElement = element.querySelector(".gin-custom-colors"); 28 removeElement.parentNode.removeChild(removeElement); 29 } 30 }, 31 setFocusColor: function() { 32 let preset = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : null, color = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : null; 33 const focusColorPreset = null != preset ? preset : drupalSettings.gin.preset_focus_color; 34 document.body.setAttribute("data-gin-focus", focusColorPreset), "custom" === focusColorPreset && this.setCustomFocusColor(color); 35 }, 36 setCustomFocusColor: function() { 37 let color = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : null, element = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : document.body; 38 const accentColor = null != color ? color : drupalSettings.gin.focus_color; 39 if (accentColor) { 40 this.clearFocusColor(element); 41 const strippedAccentColor = accentColor.replace("#", ""), darkAccentColor = this.mixColor("ffffff", strippedAccentColor, 65), style = document.createElement("style"); 42 style.className = "gin-custom-focus", style.innerHTML = `\n [data-gin-focus="custom"] {\n --gin-color-focus: ${accentColor};\n }\n .gin--dark-mode[data-gin-focus="custom"],\n .gin--dark-mode [data-gin-focus="custom"] {\n --gin-color-focus: ${darkAccentColor};\n }`, 43 element.append(style); 44 } 45 }, 46 clearFocusColor: function() { 47 let element = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : document.body;
48 if (element.querySelectorAll(".gin-custom-focus").length > 0) { 49 const removeElement = element.querySelector(".gin-custom-focus"); 50 removeElement.parentNode.removeChild(removeElement); 51 } 52 }, 53 checkDarkmode: () => { 54 const darkmodeClass = drupalSettings.gin.darkmode_class; 55 window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (e => { 56 e.matches && "auto" === window.ginDarkmode && document.querySelector("html").classList.add(darkmodeClass); 57 })), window.matchMedia("(prefers-color-scheme: light)").addEventListener("change", (e => { 58 e.matches && "auto" === window.ginDarkmode && document.querySelector("html").classList.remove(darkmodeClass); 59 })); 60 }, 61 hexToRgb: hex => { 62 hex = hex.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (function(m, r, g, b) { 63 return r + r + g + g + b + b; 64 })); 65 var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); 66 return result ? `${parseInt(result[1], 16)}, ${parseInt(result[2], 16)}, ${parseInt(result[3], 16)}` : null; 67 }, 68 mixColor: (color_1, color_2, weight) => { 69 function h2d(h) { 70 return parseInt(h, 16); 71 } 72 weight = void 0 !== weight ? weight : 50; 73 for (var color = "#", i = 0; i <= 5; i += 2) { 74 for (var v1 = h2d(color_1.substr(i, 2)), v2 = h2d(color_2.substr(i, 2)), val = Math.floor(v2 + weight / 100 * (v1 - v2)).toString(16); val.length < 2; ) val = "0" + val; 75 color += val; 76 } 77 return color; 78 }, 79 shadeColor: (color, percent) => { 80 const num = parseInt(color.replace("#", ""), 16), amt = Math.round(2.55 * percent), R = (num >> 16) + amt, B = (num >> 8 & 255) + amt, G = (255 & num) + amt; 81 return `#${(16777216 + 65536 * (R < 255 ? R < 1 ? 0 : R : 255) + 256 * (B < 255 ? B < 1 ? 0 : B : 255) + (G < 255 ? G < 1 ? 0 : G : 255)).toString(16).slice(1)}`; 82 } 83 }; 84})(Drupal, drupalSettings, once);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.