pico/docs/js/customization.min.js

1 line
7.7 KiB
JavaScript
Raw Normal View History

2021-10-31 21:33:19 +07:00
"use strict";!function(){var e={colors:null,buttonsTarget:'#customization article[data-theme="generated"]',selectorButton:"#customization button[data-color]",selectorSection:"#customization",buttons:null,generatedStyles:null,init:function(){this.generateButtons(),this.setActiveButton("pink"),this.generateTheme("pink")},generateButtons:function(){var e,a="",f="";for(e in this.colors)a+='<button data-color="'+e+'" aria-label="Activate '+e+' theme"></button>',f+='\n button[data-color="'.concat(e,'"] {\n background-color: ').concat(this.colors[e][600],';\n }\n [data-theme="light"] button[data-color="').concat(e,'"]:hover,\n [data-theme="light"] button[data-color="').concat(e,'"]:active,\n [data-theme="light"] button[data-color="').concat(e,'"]:focus {\n background-color: ').concat(this.colors[e][700],'; \'\n }\n [data-theme="dark"] button[data-color="').concat(e,'"]:hover,\n [data-theme="dark"] button[data-color="').concat(e,'"]:active,\n [data-theme="dark"] button[data-color="').concat(e,'"]:focus {\n background-color: ').concat(this.colors[e][500],";\n }");var t=document.createElement("FIGURE");t.innerHTML=a,document.querySelector(this.buttonsTarget).before(t),this.buttons=document.querySelectorAll(this.selectorButton),this.buttons.forEach(function(e){e.addEventListener("click",function(e){e=e.target.getAttribute("data-color");this.setActiveButton(e),this.generateTheme(e)}.bind(this),!1)}.bind(this));t=document.createElement("STYLE");t.setAttribute("title","color-picker"),this.generatedStyles=this.minifyCSS(f),t.innerHTML=this.generatedStyles,document.querySelector("head").appendChild(t)},setActiveButton:function(e){this.buttons.forEach(function(e){e.removeAttribute("class")}.bind(this)),document.querySelector(this.selectorButton+'[data-color="'+e+'"]').setAttribute("class","picked")},generateTheme:function(e){var a=e,e=this.colors[e],f={".name":a.charAt(0).toUpperCase()+a.substring(1)+" ",".c500":e[500],".c600":e[600],".c700":e[700],".c600-outline-light":this.hexToRgbA(e[600],.125),".c600-outline-dark":this.hexToRgbA(e[600],.25),".inverse":e.inverse};Object.keys(f).forEach(function(a){document.querySelectorAll(this.selectorSection+" "+a).forEach(function(e){e.innerHTML=f[a]}.bind(this))}.bind(this));e='\n [data-theme="generated"] {\n --h4-color: '.concat(e[700],";\n --primary: ").concat(e[600],";\n --primary-hover: ").concat(e[700],";\n --primary-focus: ").concat(this.hexToRgbA(e[600],.125),";\n --primary-inverse: ").concat(e.inverse,';\n }\n @media only screen and (prefers-color-scheme: dark) {\n :root:not([data-theme="light"]) [data-theme="generated"] {\n --h4-color: ').concat(e[400],";\n --primary: ").concat(e[600],";\n --primary-hover: ").concat(e[500],";\n --primary-focus: ").concat(this.hexToRgbA(e[600],.25),";\n --primary-inverse: ").concat(e.inverse,';\n }\n }\n [data-theme="dark"] [data-theme="generated"] {\n --h4-color: ').concat(e[500],";\n --primary: ").concat(e[600],";\n --primary-hover: ").concat(e[500],";\n --primary-focus: ").concat(this.hexToRgbA(e[600],.25),";\n --primary-inverse: ").concat(e.inverse,';\n }\n [data-theme="generated"] {\n --form-element-active-border-color: var(--primary);\n --form-element-focus-color: var(--primary-focus);\n --switch-color: var(--primary-inverse);\n --switch-checked-background-color: var(--primary);\n }');document.querySelector('style[title="color-picker"]').innerHTML=this.generatedStyles+this.minifyCSS(e)},minifyCSS:function(e){return e.replace(/^ +/gm,"")},hexToRgbA:function(e,a){if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(e))return"rgba("+[(e="0x"+(e=3==(e=e.substring(1).split("")).length?[e[0],e[0],e[1],e[1],e[2],e[2]]:e).join(""))>>16&255,e>>8&255,255&e].join(", ")+", "+a+")";throw new Error("Bad Hex")}};e.colors={red:{50:"#ffebee",100:"#ffcdd2",200:"#ef9a9a",300:"#e57373",400:"#ef5350",500:"#f44336",600:"#e53935",700:"#d32f2f",800:"#c62828",