pico/docs/js/pico.docs.min.js

1 line
12 KiB
JavaScript
Raw Normal View History

2021-11-08 00:12:34 +07:00
"use strict";!function(){var e={minWidth:"992px",targets:{nav:"aside nav",details:"aside details"},init:function(){var e,t;window.matchMedia("(min-width: "+this.minWidth+")").matches&&(e=document.querySelector(this.targets.nav),t=document.querySelectorAll(this.targets.details),e.clientHeight<e.scrollHeight&&t.forEach(function(e){e.removeAttribute("open")}))}},t={_scheme:"auto",change:{light:"<i>Turn on dark mode</i>",dark:"<i>Turn off dark mode</i>"},buttonsTarget:".theme-switcher",init:function(){this.scheme=this._scheme,this.initSwitchers()},get preferedColorScheme(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"},initSwitchers:function(){document.querySelectorAll(this.buttonsTarget).forEach(function(e){e.addEventListener("click",function(e){"dark"==this.scheme?this.scheme="light":this.scheme="dark"}.bind(this),!1)}.bind(this))},addButton:function(e){var t=document.createElement(e.tag);t.className=e.class,document.querySelector(e.target).appendChild(t)},set scheme(e){"auto"==e?"dark"==this.preferedColorScheme?this._scheme="dark":this._scheme="light":"dark"!=e&&"light"!=e||(this._scheme=e),this.applyScheme()},get scheme(){return this._scheme},applyScheme:function(){var t;document.querySelector("html").setAttribute("data-theme",this.scheme),document.querySelectorAll(this.buttonsTarget).forEach(function(e){t="dark"==this.scheme?this.change.dark:this.change.light,e.innerHTML=t,e.setAttribute("aria-label",t.replace(/<[^>]*>?/gm,""))}.bind(this))}},a={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,t="",a="";for(e in this.colors)t+='<button data-color="'+e+'" aria-label="Activate '+e+' theme"></button>',a+='\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 n=document.createElement("FIGURE");n.innerHTML=t,document.querySelector(this.buttonsTarget).before(n),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));n=document.createElement("STYLE");n.setAttribute("title","color-picker"),this.generatedStyles=this.minifyCSS(a),n.innerHTML=this.generatedStyles,document.querySelector("head").appendChild(n)},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 t=e,e=this.colors[e],a={".name":t.charAt(0).toUpperCase()+t.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(a).forEach(function(t){document.querySelectorAll(this.selectorSection+" "+t).forEach(function(e){e.innerHTML=a[t]}.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 @medi