diff --git a/dist/CookieMonsterDev.js b/dist/CookieMonsterDev.js index 4b6a7c8..2130b60 100644 --- a/dist/CookieMonsterDev.js +++ b/dist/CookieMonsterDev.js @@ -1,3 +1,14014 @@ -/*! For license information please see CookieMonsterDev.js.LICENSE.txt */ -(()=>{var e={877:function(e){!function(t,o){"use strict";"object"!=typeof e.exports?o(t):e.exports=t.document?o(t):function(e){if(!e.document)throw new Error("jscolor needs a window with document");return o(e)}}("undefined"!=typeof window?window:this,(function(e){"use strict";var t,o,n,a,i=((a={initialized:!1,instances:[],readyQueue:[],register:function(){void 0!==e&&e.document&&e.document.addEventListener("DOMContentLoaded",a.pub.init,!1)},installBySelector:function(t,o){if(!(o=o?a.node(o):e.document))throw new Error("Missing root node");for(var n=o.querySelectorAll(t),i=new RegExp("(^|\\s)("+a.pub.lookupClass+")(\\s*(\\{[^}]*\\})|\\s|$)","i"),r=0;r-1},isButtonEmpty:function(e){switch(a.nodeName(e)){case"input":return!e.value||""===e.value.trim();case"button":return""===e.textContent.trim()}return null},isPassiveEventSupported:function(){var t=!1;try{var o=Object.defineProperty({},"passive",{get:function(){t=!0}});e.addEventListener("testPassive",null,o),e.removeEventListener("testPassive",null,o)}catch(e){}return t}(),isColorAttrSupported:(n=e.document.createElement("input"),!(!n.setAttribute||(n.setAttribute("type","color"),"color"!=n.type.toLowerCase()))),dataProp:"_data_jscolor",setData:function(){var e=arguments[0];if(3===arguments.length){var t=e.hasOwnProperty(a.dataProp)?e[a.dataProp]:e[a.dataProp]={},o=arguments[2];return t[i=arguments[1]]=o,!0}if(2===arguments.length&&"object"==typeof arguments[1]){t=e.hasOwnProperty(a.dataProp)?e[a.dataProp]:e[a.dataProp]={};var n=arguments[1];for(var i in n)n.hasOwnProperty(i)&&(t[i]=n[i]);return!0}throw new Error("Invalid arguments")},removeData:function(){var e=arguments[0];if(!e.hasOwnProperty(a.dataProp))return!0;for(var t=1;t=3&&(n=s[0].match(l))&&(a=s[1].match(l))&&(i=s[2].match(l)))return o.format="rgb",o.rgba=[parseFloat(n[1])||0,parseFloat(a[1])||0,parseFloat(i[1])||0,null],s.length>=4&&(r=s[3].match(l))&&(o.format="rgba",o.rgba[3]=parseFloat(r[1])||0),o}return!1},parsePaletteValue:function(e){var t=[];"string"==typeof e?e.replace(/#[0-9A-F]{3}([0-9A-F]{3})?|rgba?\(([^)]*)\)/gi,(function(e){t.push(e)})):Array.isArray(e)&&(t=e);for(var o=[],n=0;nl[n]&&-t[n]+e[n]+s[n]/2>l[n]/2&&e[n]+s[n]-d[n]>=0?e[n]+s[n]-d[n]:e[n],-t[i]+e[i]+s[i]+d[i]-m+m*r>l[i]?-t[i]+e[i]+s[i]/2>l[i]/2&&e[i]+s[i]-m-m*r>=0?e[i]+s[i]-m-m*r:e[i]+s[i]-m+m*r:e[i]+s[i]-m+m*r>=0?e[i]+s[i]-m+m*r:e[i]+s[i]-m-m*r];else var p=[e[n],e[i]+s[i]-m+m*r];var u=p[n],h=p[i],g=o.fixed?"fixed":"absolute",f=(p[0]+d[0]>e[0]||p[0]0?Math.ceil(s/o):0,a=Math.max(1,Math.floor((t-(o-1)*e.paletteSpacing)/o)),i=e.paletteHeight?Math.min(e.paletteHeight,a):a),n&&(r=n*i+(n-1)*e.paletteSpacing),{cols:o,rows:n,cellW:a,cellH:i,width:t,height:r}},getControlPadding:function(e){return Math.max(e.padding/2,2*e.pointerBorderWidth+e.pointerThickness-e.controlBorderWidth)},getPadYChannel:function(e){switch(e.mode.charAt(1).toLowerCase()){case"v":return"v"}return"s"},getSliderChannel:function(e){if(e.mode.length>2)switch(e.mode.charAt(2).toLowerCase()){case"s":return"s";case"v":return"v"}return null},triggerCallback:function(e,t){if(e[t]){var o=null;if("string"==typeof e[t])try{o=new Function(e[t])}catch(e){console.error(e)}else o=e[t];o&&o.call(e)}},triggerGlobal:function(e){for(var t=a.getInstances(),o=0;o0)for(var c=0;c=2&&"string"==typeof arguments[0]){try{if(!i(arguments[0],arguments[1]))return!1}catch(e){return console.warn(e),!1}return this.redraw(),this.exposeColor(),!0}if(1===arguments.length&&"object"==typeof arguments[0]){var e=arguments[0],t=!0;for(var o in e)if(e.hasOwnProperty(o))try{i(o,e[o])||(t=!1)}catch(e){console.warn(e),t=!1}return this.redraw(),this.exposeColor(),t}throw new Error("Invalid arguments")},this.channel=function(e,t){if("string"!=typeof e)throw new Error("Invalid value for channel name: "+e);if(void 0===t)return this.channels.hasOwnProperty(e.toLowerCase())?this.channels[e.toLowerCase()]:(console.warn("Getting unknown channel: "+e),!1);var o=!1;switch(e.toLowerCase()){case"r":o=this.fromRGBA(t,null,null,null);break;case"g":o=this.fromRGBA(null,t,null,null);break;case"b":o=this.fromRGBA(null,null,t,null);break;case"h":o=this.fromHSVA(t,null,null,null);break;case"s":o=this.fromHSVA(null,t,null,null);break;case"v":o=this.fromHSVA(null,null,t,null);break;case"a":o=this.fromHSVA(null,null,null,t);break;default:return console.warn("Setting unknown channel: "+e),!1}return!!o&&(this.redraw(),!0)},this.trigger=function(e){for(var t=a.strList(e),o=0;o127.5},this.hide=function(){m()&&(a.removeClass(n.targetElement,a.pub.activeClassName),a.picker.wrap.parentNode.removeChild(a.picker.wrap),delete a.picker.owner)},this.show=function(){s()},this.redraw=function(){m()&&s()},this.getFormat=function(){return this._currentFormat},this._setFormat=function(e){this._currentFormat=e.toLowerCase()},this.hasAlphaChannel=function(){return"auto"===this.alphaChannel?"any"===this.format.toLowerCase()||a.isAlphaFormat(this.getFormat())||void 0!==this.alpha||void 0!==this.alphaElement:this.alphaChannel},this.processValueInput=function(e){this.fromString(e)||this.exposeColor()},this.processAlphaInput=function(e){this.fromHSVA(null,null,null,parseFloat(e))||this.exposeColor()},this.exposeColor=function(e){var t=this.toString(),o=this.getFormat();if(a.setDataAttr(this.targetElement,"current-color",t),e&a.flags.leaveValue||!this.valueElement||("hex"!==o&&"hexa"!==o||(this.uppercase||(t=t.toLowerCase()),this.hash||(t=t.replace(/^#/,""))),this.setValueElementValue(t)),!(e&a.flags.leaveAlpha)&&this.alphaElement){var n=Math.round(100*this.channels.a)/100;this.setAlphaElementValue(n)}e&a.flags.leavePreview||!this.previewElement||((a.isTextInput(this.previewElement)||a.isButton(this.previewElement)&&!a.isButtonEmpty(this.previewElement))&&this.previewPosition,this.setPreviewElementBg(this.toRGBAString())),m()&&(l(),c(),d())},this.setPreviewElementBg=function(e){if(this.previewElement){var t=null,o=null;(a.isTextInput(this.previewElement)||a.isButton(this.previewElement)&&!a.isButtonEmpty(this.previewElement))&&(t=this.previewPosition,o=this.previewSize);var n=[];if(e){n.push({image:a.genColorPreviewGradient(e,t,o?o-a.pub.previewSeparator.length:null),position:"left top",size:"auto",repeat:t?"repeat-y":"repeat",origin:"padding-box"});var i=a.genColorPreviewCanvas("rgba(0,0,0,0)",t?{left:"right",right:"left"}[t]:null,o,!0);n.push({image:"url('"+i.canvas.toDataURL()+"')",position:(t||"left")+" top",size:i.width+"px "+i.height+"px",repeat:t?"repeat-y":"repeat",origin:"padding-box"})}else n.push({image:"none",position:"left top",size:"auto",repeat:"no-repeat",origin:"padding-box"});for(var r={image:[],position:[],size:[],repeat:[],origin:[]},s=0;s=0;h-=1){var g=u[h];if(g)if(a.pub.presets.hasOwnProperty(g)){for(var p in a.pub.presets[g])if(a.pub.presets[g].hasOwnProperty(p))try{i(p,a.pub.presets[g][p])}catch(e){console.warn(e)}}else console.warn("Unknown preset: %s",g)}var f=["preset"];for(var p in o)if(o.hasOwnProperty(p)&&-1===f.indexOf(p))try{i(p,o[p])}catch(e){console.warn(e)}if(void 0===this.container?this.container=e.document.body:this.container=a.node(this.container),!this.container)throw new Error("Cannot instantiate color picker without a container element");if(this.targetElement=a.node(t),!this.targetElement){if("string"==typeof t&&/^[a-zA-Z][\w:.-]*$/.test(t))throw new Error("If '"+t+"' is supposed to be an ID, please use '#"+t+"' or any valid CSS selector.");throw new Error("Cannot instantiate color picker without a target element")}if(this.targetElement.jscolor&&this.targetElement.jscolor instanceof a.pub)throw new Error("Color picker already installed on this element");if(this.targetElement.jscolor=this,a.addClass(this.targetElement,a.pub.className),a.instances.push(this),a.isButton(this.targetElement)&&("button"!==this.targetElement.type.toLowerCase()&&(this.targetElement.type="button"),a.isButtonEmpty(this.targetElement))){a.removeChildren(this.targetElement),this.targetElement.appendChild(e.document.createTextNode(" "));var k=a.getCompStyle(this.targetElement);(parseFloat(k["min-width"])||0)-1){var b=a.parseColorString(M);this._currentFormat=b?b.format:"hex"}else this._currentFormat=this.format.toLowerCase();this.processValueInput(M),void 0!==y&&this.processAlphaInput(y)}}).pub.className="jscolor",a.pub.activeClassName="jscolor-active",a.pub.looseJSON=!0,a.pub.presets={},a.pub.presets.default={},a.pub.presets.light={backgroundColor:"rgba(255,255,255,1)",controlBorderColor:"rgba(187,187,187,1)",buttonColor:"rgba(0,0,0,1)"},a.pub.presets.dark={backgroundColor:"rgba(51,51,51,1)",controlBorderColor:"rgba(153,153,153,1)",buttonColor:"rgba(240,240,240,1)"},a.pub.presets.small={width:101,height:101,padding:10,sliderSize:14,paletteCols:8},a.pub.presets.medium={width:181,height:101,padding:12,sliderSize:16,paletteCols:10},a.pub.presets.large={width:271,height:151,padding:12,sliderSize:24,paletteCols:15},a.pub.presets.thin={borderWidth:1,controlBorderWidth:1,pointerBorderWidth:1},a.pub.presets.thick={borderWidth:2,controlBorderWidth:2,pointerBorderWidth:2},a.pub.sliderInnerSpace=3,a.pub.chessboardSize=8,a.pub.chessboardColor1="#666666",a.pub.chessboardColor2="#999999",a.pub.previewSeparator=["rgba(255,255,255,.65)","rgba(128,128,128,.65)"],a.pub.init=function(){if(!a.initialized)for(e.document.addEventListener("mousedown",a.onDocumentMouseDown,!1),e.document.addEventListener("keyup",a.onDocumentKeyUp,!1),e.addEventListener("resize",a.onWindowResize,!1),e.addEventListener("scroll",a.onWindowScroll,!1),a.pub.install(),a.initialized=!0;a.readyQueue.length;)a.readyQueue.shift()()},a.pub.install=function(e){var t=!0;try{a.installBySelector("[data-jscolor]",e)}catch(e){t=!1,console.warn(e)}if(a.pub.lookupClass)try{a.installBySelector("input."+a.pub.lookupClass+", button."+a.pub.lookupClass,e)}catch(e){}return t},a.pub.ready=function(e){return"function"!=typeof e?(console.warn("Passed value is not a function"),!1):(a.initialized?e():a.readyQueue.push(e),!0)},a.pub.trigger=function(e){var t=function(){a.triggerGlobal(e)};a.initialized?t():a.pub.ready(t)},a.pub.hide=function(){a.picker&&a.picker.owner&&a.picker.owner.hide()},a.pub.chessboard=function(e){return e||(e="rgba(0,0,0,0)"),a.genColorPreviewCanvas(e).canvas.toDataURL()},a.pub.background=function(e){var t=[];t.push(a.genColorPreviewGradient(e));var o=a.genColorPreviewCanvas();return t.push(["url('"+o.canvas.toDataURL()+"')","left top","repeat"].join(" ")),t.join(", ")},a.pub.options={},a.pub.lookupClass="jscolor",a.pub.installByClassName=function(){return console.error('jscolor.installByClassName() is DEPRECATED. Use data-jscolor="" attribute instead of a class name.'+a.docsRef),!1},a.register(),a.pub);return void 0===e.jscolor&&(e.jscolor=e.JSColor=i),i}))}},t={};function o(n){var a=t[n];if(void 0!==a)return a.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,o),i.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";function e(){}function t(){Object.keys(Game.mods.cookieMonsterFramework.saveData).forEach((e=>{const t=JSON.stringify(Game.mods.cookieMonsterFramework.saveData[e]),o=b64_to_utf8(unescape(localStorage.getItem("CookieClickerGame")).split("!END!")[0]),n=new RegExp(`${e}.*(;|$)`),a=o.match(n);if(null!==a){const n=o.replace(a[0],`${e}:${t}`);localStorage.setItem("CookieClickerGame",escape(`${utf8_to_b64(n)}!END!`))}}))}function n(e,o){switch(void 0===Game.mods.cookieMonsterFramework.saveData[e].headers[o]&&(Game.mods.cookieMonsterFramework.saveData[e].headers[o]=1),Game.mods.cookieMonsterFramework.saveData[e].headers[o]){case 0:Game.mods.cookieMonsterFramework.saveData[e].headers[o]=1;break;default:Game.mods.cookieMonsterFramework.saveData[e].headers[o]=0}t()}function a(e,t){t.disconnect(),"log"===Game.onMenu?function(){const e=l("menu").children[1];if(e.insertBefore(function(){const e=document.createElement("div");e.className="subsection",e.id="cookieMonsterFrameworkMenuSection";const t=document.createElement("div");t.className="title",t.innerHTML="Cookie Monster Mod Family";const o=document.createElement("span");if(o.style.cursor="pointer",o.style.display="inline-block",o.style.height="14px",o.style.width="14px",o.style.borderRadius="7px",o.style.textAlign="center",o.style.backgroundColor="#C0C0C0",o.style.color="black",o.style.fontSize="13px",o.style.verticalAlign="middle",o.textContent=Game.mods.cookieMonsterFramework.saveData.cookieMonsterFramework.headers.infoMenu?"-":"+",o.onclick=function(){n("cookieMonsterFramework","infoMenu"),Game.UpdateMenu()},t.appendChild(o),e.appendChild(t),Game.mods.cookieMonsterFramework.saveData.cookieMonsterFramework.headers.infoMenu){const t=document.createElement("div");t.className="listing",t.innerHTML='Cookie Monster Team\noffers a suite of tools to enhance your game experience.
\nOriginally known from our work on the Cookie Monster add-on we are now expanding and working on new tools within the Cookie Monster Mod Family.
\nKeep an eye on our GitHub to see future work or use it to report bugs or feature requests!
\n',e.appendChild(t)}return e}(),e.children[1]),Game.mods.cookieMonsterFramework.saveData.cookieMonsterFramework.headers.infoMenu){const e=Game.mods.cookieMonsterFramework.listeners.infoMenu;for(let t=0;t{void 0===e.settings||void 0===e.settings[o]?a[o]=t[o].defaultValue:a[o]=e.settings[o]})),n.settings=a;const i={};return Object.keys(o).forEach((t=>{void 0===e.headers||void 0===e.headers[t]?i[t]=o[t]:i[t]=e.headers[t]})),n.headers=i,Object.keys(e).forEach((t=>{"settings"!==t&&"headers"!==t&&(n[t]=e[t])})),n}(r,n,a),t(),i(),Object.keys(Game.mods.cookieMonsterFramework.saveData[e].settings).forEach((e=>{void 0!==n[e].func&&n[e].func()})),Game.UpdateMenu()}const r={infoMenu:1,optionsMenu:1},s={};function c(){}const d={init:function(){window.cookieMonsterFrameworkData={},new MutationObserver(a).observe(document.getElementById("menu"),{attributes:!0,childList:!0,subtree:!0}),Game.registerHook("draw",e)},load:function(e){i("cookieMonsterFramework",e,s,r,c)},save:function(){return JSON.stringify(Game.mods.cookieMonsterFramework.saveData.cookieMonsterFramework)},listeners:{infoMenu:[]},saveData:{cookieMonsterFramework:{headers:{},settings:{}}}},m=function(){"undefined"==typeof cookieMonsterFrameworkData&&Game.registerMod("cookieMonsterFramework",d)},p=function(e){Game.mods.cookieMonsterFramework.saveData[e]={settings:{},headers:{}}},u=function(e){const t=document.createElement("div");return t.className="listing",t.innerHTML=e,t},h=function(e,t,o){const a=document.createElement("div");a.className="subsection",a.id=`${e}MenuSection`;const i=document.createElement("div");i.className="title",i.style.fontSize="18px",i.innerHTML=t;const r=document.createElement("span");return r.style.cursor="pointer",r.style.display="inline-block",r.style.height="14px",r.style.width="14px",r.style.borderRadius="7px",r.style.textAlign="center",r.style.backgroundColor="#C0C0C0",r.style.color="black",r.style.fontSize="13px",r.style.verticalAlign="middle",r.textContent=Game.mods.cookieMonsterFramework.saveData[e].headers[o]?"-":"+",r.onclick=function(){n(e,o),Game.UpdateMenu()},i.appendChild(r),a.appendChild(i),a};function g(){Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.WrinklerButtons&&Game.elderWrath?(l("PopAllNormalWrinklerButton").style.display="",l("PopFattestWrinklerButton").style.display=""):(l("PopAllNormalWrinklerButton").style.display="none",l("PopFattestWrinklerButton").style.display="none")}const f=["","","M","G","T","P","E","Z","Y"],k=["","","M","B","Tr","Quadr","Quint","Sext","Sept","Oct","Non","Dec","Undec","Duodec","Tredec","Quattuordec","Quindec","Sexdec","Septendec","Octodec","Novemdec","Vigint","Unvigint","Duovigint","Trevigint","Quattuorvigint"],C=["","K","M","B","T","Qa","Qi","Sx","Sp","Oc","No","De","UDe","DDe","TDe","QaDe","QiDe","SxDe","SpDe","ODe","NDe","Vi","UVi","DVi","TVi","QaVi","QiVi","SxVi","SpVi","OVi","NVi","Tr","UTr","DTr","TTr","QaTr","QiTr","SxTr","SpTr","OTr","NTr","Qaa","UQa","DQa","TQa","QaQa","QiQa","SxQa","SpQa","OQa","NQa","Qia","UQi","DQi","TQi","QaQi","QiQi","SxQi","SpQi","OQi","NQi","Sxa","USx","DSx","TSx","QaSx","QiSx","SxSx","SpSx","OSx","NSx","Spa","USp","DSp","TSp","QaSp","QiSp","SxSp","SpSp","OSp","NSp","Oco","UOc","DOc","TOc","QaOc","QiOc","SxOc","SpOc","OOc","NOc","Noa","UNo","DNo","TNo","QaNo","QiNo","SxNo","SpNo","ONo","NNo","Ct","UCt"];let M,y,b,G,w,v,x,T,S,B,E,F,P,N,O,D,A=[],L=[],W=[],j={},H=Date.now(),U=Date.now();function $(e,t,o){const n=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.ScaleDecimals+1;if(e===1/0)return"Infinity";if(void 0===e)return"0";if(0===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.Scale)return j.Beautify(e,t);if(Number.isFinite(e)){if(e<0)return`-${$(Math.abs(e))}`;let a="";if(0===e)return e.toString();if(e>.001&&e=.01&&e=.01&&e=.01&&e0&&(c+=o,l-=1)}return c}const Ut="CMText",$t="CMBack",Rt="Blue",It="Green",zt="Yellow",Vt="Orange",_t="Red",Qt="Purple",Xt="Gray",qt="Pink",Yt="Brown",Kt=[Rt,It,zt,Vt,_t,Qt,qt,Yt,Xt],Jt=[["GoldCookTooltipPlaceholder","Calculated with Golden Switch off","200px"],["GoldCookDragonsFortuneTooltipPlaceholder","Calculated with Golden Switch off and at least one golden cookie on-screen","240px"],["PrestMaxTooltipPlaceholder","The MAX prestige is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg","320px"],["NextPrestTooltipPlaceholder","Calculated with cookies gained from wrinklers and Chocolate egg","200px"],["HeavenChipMaxTooltipPlaceholder","The MAX heavenly chips is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg","330px"],["ResetTooltipPlaceholder","The bonus income you would get from new prestige levels unlocked at 100% of its potential and from ascension achievements if you have the same buildings/upgrades after reset","370px"],["ChoEggTooltipPlaceholder","The amount of cookies you would get from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and then buying Chocolate egg","300px"],["ChainNextLevelPlaceholder","Cheated cookies might break this formula","250px"],["FavouriteSettingPlaceholder","Click to set this setting as favourite and show it in 'favourite' settings at the top of the Cookie Monster Settings","250px"]],Zt={};let eo,to=0,oo=-1,no=[],ao=function(){},io=1,ro=1,so=1;const lo=[10,15,30,60,300,600,900,1800],co=[1,5,10,15,30],mo={Frenzy:zt,"Dragon Harvest":Yt,"Elder frenzy":It,Clot:_t,"Click frenzy":Rt,Dragonflight:qt};let po,uo,ho,go,fo,ko,Co,Mo={},yo="",bo=[];function Go(){let e,t=Game.buyBulk;1===Game.buyMode?ro=t:t=ro,1===t?t=Qe:10===t?t=Xe:100===t&&(t=qe),l("storeBulk1").style.removeProperty("color"),l("storeBulk10").style.removeProperty("color"),l("storeBulk100").style.removeProperty("color"),1===Game.buyMode?1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.BuildColour?(Object.keys(t).forEach((e=>{l(`productPrice${Game.Objects[e].id}`).style.color=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[`Colour${t[e].color}`]})),l(`storeBulk${xt}`).style.color=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.ColourGreen):Object.keys(Game.Objects).forEach((e=>{l(`productPrice${Game.Objects[e].id}`).style.removeProperty("color")})):-1===Game.buyMode&&Object.keys(Qe).forEach((e=>{const t=Game.Objects[e];l(`productPrice${t.id}`).style.color="",l(`productPrice${t.id}`).innerHTML=$(Ht(t,t.basePrice,t.amount,t.free,Game.buyBulk,1))})),1===Game.buyMode&&Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.SortBuildings?1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.SortBuildings?(e=Object.keys(Qe).map((e=>{const t={};return t.name=e,t.pp=Qe[e].pp,t.color=Qe[e].color,t})),e.sort(((e,t)=>Kt.indexOf(e.color)===Kt.indexOf(t.color)?e.pp-t.pp:Kt.indexOf(e.color)-Kt.indexOf(t.color)))):2===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.SortBuildings?(e=Object.keys(t).map((e=>{const o={};return o.name=e,o.pp=t[e].pp,o.color=t[e].color,o})),e.sort(((e,t)=>Kt.indexOf(e.color)===Kt.indexOf(t.color)?e.pp-t.pp:Kt.indexOf(e.color)-Kt.indexOf(t.color)))):3===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.SortBuildings&&(e=Object.keys(Ye).map((e=>{const t={};return t.name=e,t.id=Game.Objects[e].id,t.amountUntilNext=Ye[e].AmountNeeded,t.priceUntilNext=Ye[e].price,t})),e.sort(((e,t)=>e.id-t.id)),e.sort(((e,t)=>(101!==e.amountUntilNext?e.priceUntilNext:1/0)-(101!==t.amountUntilNext?t.priceUntilNext:1/0)))):(e=Object.keys(Qe).map((e=>{const t={};return t.name=e,t.id=Game.Objects[e].id,t})),e.sort(((e,t)=>e.id-t.id)));for(let t=0;t{Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.UpgradesNeverCollapse||"products"===e.id?e.style.height="auto":"vaultUpgrades"===e.id?(e.style.height="",e.style.minHeight="0px"):"upgrades"===e.id?(e.style.height="",e.className.includes("hasMenu")?e.style.minHeight="82px":e.style.minHeight="60px"):(e.style.height="",e.style.minHeight="60px")}))}function vo(){if(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.UpBarColour>0){let e=0,t=0,o=0,n=0,a=0,i=0,r=0;Object.keys(Game.UpgradesInStore).forEach((s=>{const c=Game.UpgradesInStore[s];let d=!1;for(let e=0;eKt.indexOf(e.color)===Kt.indexOf(t.color)?e.pp-t.pp:Kt.indexOf(e.color)-Kt.indexOf(t.color))):e.sort(((e,t)=>e.price-t.price));const t=function(e,t){return e.findIndex((e=>e.name===t.name))};for(let o=0;o315576e4)return"XX:XX:XX:XX:XX";l+=(n<10?"0":"")+n+":",l+=(a<10?"0":"")+a+":",l+=(i<10?"0":"")+i+":",l+=(r<10?"0":"")+r+":",l+=(s<10?"0":"")+s}else{if(o>7776e5)return t?"Over 9000 days!":">9000d";l+=n>0?n+(t?1===n?" year":" years":"y")+", ":"",(l.length>0||a>0)&&(l+=a+(t?1===a?" day":" days":"d")+", "),(l.length>0||i>0)&&(l+=i+(t?1===i?" hour":" hours":"h")+", "),(l.length>0||r>0)&&(l+=r+(t?1===r?" minute":" minutes":"m")+", "),l+=s+(t?1===s?" second":" seconds":"s")}return l}function To(e){let t,o;return e<=0?(o=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TimeFormat?"00:00:00:00:00":"Done!",t=It):(o=xo(e),t=e>300?_t:e>60?Vt:zt),{text:o,color:t}}function So(){return Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.CPSMode?ae:0===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.CalcWrink?Game.cookiesPs*(1-Game.cpsSucked):1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.CalcWrink?Game.cookiesPs*(et+(1-.05*tt)):null!==Ze[1]&&2===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.CalcWrink&&1===Game.wrinklers[Ze[1]].type?Game.cookiesPs*(3*et/tt+(1-.05*tt)):Game.cookiesPs*(et/tt+(1-.05*tt))}function Bo(){return 1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.CalcWrink?Ke:2===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.CalcWrink?Ze[0]:0}function Eo(e,t,o){const n=document.createElement("div");n.id=e,n.style.height="12px",n.style.margin="0px 10px",n.style.position="relative";const a=document.createElement("div");a.style.width="100%",a.style.height="10px",a.style.margin="auto",a.style.position="absolute",a.style.left="0px",a.style.top="0px",a.style.right="0px",a.style.bottom="0px";const i=document.createElement("span");i.style.display="inline-block",i.style.textAlign="right",i.style.fontSize="10px",i.style.width="108px",i.style.marginRight="5px",i.style.verticalAlign="text-top",i.textContent=t,a.appendChild(i);for(let e=0;e{let o,n=Game.buyBulk;1===Game.buyMode?io=n:n=io,1===n&&(n=Qe),10===n&&(n=Xe),100===n&&(n=qe),e+=1,l("CMBotBar").firstChild.firstChild.childNodes[0].childNodes[e].childNodes[1].textContent=Game.Objects[t].amount,l("CMBotBar").firstChild.firstChild.childNodes[1].childNodes[e].textContent=$(n[t].bonus,2),l("CMBotBar").firstChild.firstChild.childNodes[2].childNodes[e].className=Ut+n[t].color,o=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.PPDisplayTime?xo(Math.round(n[t].pp)):$(Math.round(n[t].pp),2),l("CMBotBar").firstChild.firstChild.childNodes[2].childNodes[e].textContent=o;const a=To((Game.Objects[t].bulkPrice-(Game.cookies+Bo()))/So());l("CMBotBar").firstChild.firstChild.childNodes[3].childNodes[e].className=Ut+a.color,"Done!"===a.text&&Game.cookies{!Game.Tiers[e.tieredUpgrades[o].tier].special&&Lt(e.tieredUpgrades[o].name)&&(t*=2)})),Object.keys(e.synergies).forEach((o=>{if(Lt(e.synergies[o].name)){const n=e.synergies[o];n.buildingTie1.name===e.name?t*=1+.05*n.buildingTie2.amount:n.buildingTie2.name===e.name&&(t*=1+.001*n.buildingTie1.amount)}})),e.fortune&&Lt(e.fortune.name)&&(t*=1.07),e.grandma&&Lt(e.grandma.name)&&(t*=1+.01*Ft.Grandma.amount*(1/(e.id-1))),"object"==typeof e.tieredUpgrades.misfortune&&1===e.vanilla&&Lt(e.tieredUpgrades.misfortune.name))switch(Game.elderWrath){default:t*=1;break;case 1:t*=1.02;break;case 2:t*=1.04;break;case 3:t*=1.06}return t}function jo(e){const t=Game.Objects[e],o={};return"Cursor"===t.name?o.cps=function(e){let t=0;Lt("Thousand fingers")&&(t+=.1),Lt("Million fingers")&&(t*=5),Lt("Billion fingers")&&(t*=10),Lt("Trillion fingers")&&(t*=20),Lt("Quadrillion fingers")&&(t*=20),Lt("Quintillion fingers")&&(t*=20),Lt("Sextillion fingers")&&(t*=20),Lt("Septillion fingers")&&(t*=20),Lt("Octillion fingers")&&(t*=20),Lt("Nonillion fingers")&&(t*=20);let o=1,n=0;return Object.keys(Ft).forEach((e=>{"Cursor"!==Ft[e].name&&(n+=Ft[e].amount)})),t*=n,o*=Wo(e),o*=Game.magicCpS("Cursor"),o*=At("cursorCps"),Game.ComputeCps(.1,Lt("Reinforced index finger")+Lt("Carpal tunnel prevention cream")+Lt("Ambidextrous"),t)*o}:"Grandma"===t.name?o.cps=function(e){let o=1;if(Object.keys(Game.GrandmaSynergies).forEach((e=>{Lt(Game.GrandmaSynergies[e])&&(o*=2)})),Lt("Bingo center/Research facility")&&(o*=4),Lt("Ritual rolling pins")&&(o*=2),Lt("Naughty list")&&(o*=2),Lt("Elderwort biscuits")&&(o*=1.02),o*=At("grandmaCps"),Lt("Cat ladies"))for(let e=0;e{"Grandma"!==Ft[e].name&&(a+=Ft[e].amount)})),o*=1+.01*Ot("Elder Battalion")*a,o*=Game.magicCpS(t.name),(t.baseCps+n)*o}:o.cps=function(e){let t=1;return t*=Wo(e),t*=Game.magicCpS(e.name),e.baseCPS*t},o.baseCps=t.baseCps,o.name=t.name,o.tieredUpgrades=t.tieredUpgrades,o.synergies=t.synergies,o.fortune=t.fortune,o.grandma=t.grandma,o.baseCPS=t.baseCps,o.id=t.id,o.vanilla=t.vanilla,o}function Ho(e){const t=Game.Upgrades[e],o={};return o.power=t.power,"function"==typeof o.power&&("Sugar crystal cookies"===t.name?o.power=function(){let e=5;return Object.keys(Ft).forEach((t=>{Ft[t].level>=10&&(e+=1)})),e}:o.power=function(){let e=2;if(Lt("Starlove")&&(e=3),Game.hasGod){const t=Wt("seasons");1===t?e*=1.3:2===t?e*=1.2:3===t&&(e*=1.1)}return e}),o.pool=t.pool,o.name=t.name,o}function Uo(){de=Game.UpgradesOwned,me=Game.pledges,pe=Game.AchievementsOwned,ue=Game.heavenlyPower,he=Game.prestige,Object.keys(Game.Objects).forEach((e=>{const t=Game.Objects[e];let o=Ft[e];void 0===o&&(Ft[e]=jo(e),o=Ft[e],Fo(e)),o.amount=t.amount,o.level=t.level,o.totalCookies=t.totalCookies,o.basePrice=t.basePrice,o.free=t.free,t.minigameLoaded&&("Temple"===t.name&&(ke=t.minigame.slot[0],Ce=t.minigame.slot[1],Me=t.minigame.slot[2]),o.minigameLoaded=t.minigameLoaded,o.minigame=t.minigame),Ft[e]=o})),Object.keys(Game.Upgrades).forEach((e=>{const t=Game.Upgrades[e];let o=Pt[e];void 0===o&&(Pt[e]=Ho(e),o=Pt[e]),o.bought=t.bought,Pt[e]=o})),Object.keys(Game.Achievements).forEach((e=>{const t=Game.Achievements[e];let o=Nt[e];void 0===o&&(Nt[e]=Lo(e),o=Nt[e]),o.won=t.won,Nt[e]=o})),Ao(),ge=xe,fe=Te}function $o(e){const t=document.createElement("div");return t.style.fontWeight="bold",t.id=`${e}Title`,t.className="CMTextBlue",t.textContent=e,t}function Ro(e){e.appendChild($o("Bonus Income"));const t=document.createElement("div");t.style.marginBottom="4px",t.style.color="white",t.id="CMTooltipIncome",e.appendChild(t),e.appendChild($o("Bonus Cookies per Click")),e.lastChild.style.display="none";const o=document.createElement("div");o.style.marginBottom="4px",o.style.color="white",o.style.display="none",o.id="CMTooltipCookiePerClick",e.appendChild(o),e.appendChild($o("Payback Period"));const n=document.createElement("div");n.style.marginBottom="4px",n.id="CMTooltipPP",e.appendChild(n),e.appendChild($o("Time Left"));const a=document.createElement("div");if(a.id="CMTooltipTime",e.appendChild(a),"b"===ho){e.appendChild($o("Production left till next achievement")),e.lastChild.id="CMTooltipProductionLeftHeader";const t=document.createElement("div");t.id="CMTooltipProductionLeft",e.appendChild(t)}if("b"===ho){e.appendChild($o("Buildings (price / PP) left till next achievement")),e.lastChild.id="CMTooltipNextAchievementHeader";const t=document.createElement("div");t.id="CMTooltipNextAchievement",e.appendChild(t)}}function Io(e,t){let o="";return o=e.pp<=0||e.pp===1/0?Xt:e.pp0&&(o=_t),o}function zo(){let e=1;return Object.keys(Game.buffs).forEach((t=>{void 0!==Game.buffs[t].multCpS&&(e*=Game.buffs[t].multCpS)})),e}function Vo(e){Nt[e]&&0===Nt[e].won&&(Nt[e].won=1,"shadow"!==Game.Achievements[e].pool&&(pe+=1))}function _o(){Ge=0;let e=1;const t={};Object.keys(Game.Objects).forEach((e=>{if(Game.Objects[e].minigameLoaded&&Game.Objects[e].minigame.effs){const o=Game.Objects[e].minigame.effs;Object.keys(o).forEach((e=>{t[e]?t[e]*=o[e]:t[e]=o[e]}))}})),be=t,1!==Game.ascensionMode&&(e+=.01*parseFloat(he)*ue*function(){let e=0;if(Lt("Heavenly chip secret")&&(e+=.05),Lt("Heavenly cookie stand")&&(e+=.2),Lt("Heavenly bakery")&&(e+=.25),Lt("Heavenly confectionery")&&(e+=.25),Lt("Heavenly key")&&(e+=.25),e*=1+.05*Ot("Dragon God"),Lt("Lucky digit")&&(e*=1.01),Lt("Lucky number")&&(e*=1.01),Lt("Lucky payout")&&(e*=1.01),Game.hasGod){const t=Wt("creation");1===t?e*=.7:2===t?e*=.8:3===t&&(e*=.9)}return e}()),e*=At("cps"),Lt("Heralds")&&1!==Game.ascensionMode&&(e*=1+.01*Game.heralds),Object.keys(Game.cookieUpgrades).forEach((t=>{const o=Game.cookieUpgrades[t];Lt(o.name)&&("function"==typeof o.power?e*=1+.01*Pt[o.name].power(Pt[o.name]):e*=1+.01*o.power)})),Lt("Specialized chocolate chips")&&(e*=1.01),Lt("Designer cocoa beans")&&(e*=1.02),Lt("Underworld ovens")&&(e*=1.03),Lt("Exotic nuts")&&(e*=1.04),Lt("Arcane sugar")&&(e*=1.05),Lt("Increased merriness")&&(e*=1.15),Lt("Improved jolliness")&&(e*=1.15),Lt("A lump of coal")&&(e*=1.01),Lt("An itchy sweater")&&(e*=1.01),Lt("Santa's dominion")&&(e*=1.2),Lt("Fortune #100")&&(e*=1.01),Lt("Fortune #101")&&(e*=1.07),Lt("Dragon scale")&&(e*=1.03);let o=1;if(Wt){let t=Wt("asceticism");1===t?e*=1.15:2===t?e*=1.1:3===t&&(e*=1.05),t=Wt("ages"),1===t?e*=1+.15*Math.sin(H/1e3/10800*Math.PI*2):2===t?e*=1+.15*Math.sin(H/1e3/43200*Math.PI*2):3===t&&(e*=1+.15*Math.sin(H/1e3/86400*Math.PI*2)),t=Wt("decadence"),1===t?o*=.93:2===t?o*=.95:3===t&&(o*=.98),t=Wt("industry"),1===t?o*=1.1:2===t?o*=1.06:3===t&&(o*=1.03),t=Wt("labor"),1===t?o*=.97:2===t?o*=.98:3===t&&(o*=.99)}Lt("Santa's legacy")&&(e*=1+.03*(Game.santaLevel+1));const n=pe/25;let a=1;if(Lt("Santa's milk and cookies")&&(a*=1.05),a*=1+.05*Ot("Breath of Milk"),Wt){const e=Wt("mother");1===e?a*=1.1:2===e?a*=1.05:3===e&&(a*=1.03)}a*=At("milk");let i=1;Lt("Kitten helpers")&&(i*=1+.1*n*a),Lt("Kitten workers")&&(i*=1+.125*n*a),Lt("Kitten engineers")&&(i*=1+.15*n*a),Lt("Kitten overseers")&&(i*=1+.175*n*a),Lt("Kitten managers")&&(i*=1+.2*n*a),Lt("Kitten accountants")&&(i*=1+.2*n*a),Lt("Kitten specialists")&&(i*=1+.2*n*a),Lt("Kitten experts")&&(i*=1+.2*n*a),Lt("Kitten consultants")&&(i*=1+.2*n*a),Lt("Kitten assistants to the regional manager")&&(i*=1+.175*n*a),Lt("Kitten marketeers")&&(i*=1+.15*n*a),Lt("Kitten analysts")&&(i*=1+.125*n*a),Lt("Kitten executives")&&(i*=1+.115*n*a),Lt("Kitten angels")&&(i*=1+.1*n*a),Lt("Fortune #103")&&(i*=1+.05*n*a),Object.keys(Ft).forEach((e=>{const t=Ft[e];let i=t.cps(t);1!==Game.ascensionMode&&(i*=(1+.01*t.level)*o),"Grandma"===t.name&&Lt("Milkhelp® lactose intolerance relief tablets")&&(i*=1+.05*n*a),Ge+=t.amount*i})),Lt('"egg"')&&(Ge+=9),e*=i;let r=1;if(Lt("Chicken egg")&&(r*=1.01),Lt("Duck egg")&&(r*=1.01),Lt("Turkey egg")&&(r*=1.01),Lt("Quail egg")&&(r*=1.01),Lt("Robin egg")&&(r*=1.01),Lt("Ostrich egg")&&(r*=1.01),Lt("Cassowary egg")&&(r*=1.01),Lt("Salmon roe")&&(r*=1.01),Lt("Frogspawn")&&(r*=1.01),Lt("Shark egg")&&(r*=1.01),Lt("Turtle egg")&&(r*=1.01),Lt("Ant larva")&&(r*=1.01),Lt("Century egg")){let e=10*Math.floor((U-Game.startDate)/1e3/10)/60/60/24;e=Math.min(e,100),ze=1+.1*(1-(1-e/100)**3),r*=ze}e*=r,Lt("Sugar baking")&&(e*=1+.01*Math.min(100,Game.lumps)),e*=1+Ot("Radiant Appetite");const s=Ge*e;Object.keys(Game.CpsAchievements).forEach((e=>{s>=Game.CpsAchievements[e].threshold&&Vo(Game.CpsAchievements[e].name)})),we=s;const{n:l}=Game.shimmerTypes.golden,c=Ot("Dragon's Fortune");for(let t=0;t{Lt(e[o])&&(t+=.1)}))}e*=t}if(Lt("Shimmering veil [off]")){let t=.5;Lt("Reinforced membrane")&&(t+=.1),e*=1+t}Lt("Magic shenanigans")&&(e*=1e3),Lt("Occult obstruction")&&(e*=0),Ge=Game.runModHookOnValue("cps",Ge),e*=zo(),Ge*=e}const Qo=["Fortune #001","Fortune #002","Fortune #003","Fortune #004","Fortune #005","Fortune #006","Fortune #007","Fortune #008","Fortune #009","Fortune #010","Fortune #011","Fortune #012","Fortune #013","Fortune #014","Fortune #015","Fortune #016","Fortune #017","Fortune #018","Fortune #100","Fortune #101","Fortune #102","Fortune #103","Fortune #104"],Xo=["Skull cookies","Ghost cookies","Bat cookies","Slime cookies","Pumpkin cookies","Eyeball cookies","Spider cookies"],qo=["Christmas tree biscuits","Snowflake biscuits","Snowman biscuits","Holly biscuits","Candy cane biscuits","Bell biscuits","Present biscuits"],Yo=["Pure heart biscuits","Ardent heart biscuits","Sour heart biscuits","Weeping heart biscuits","Golden heart biscuits","Eternal heart biscuits","Prism heart biscuits"],Ko=["Elderwort biscuits","Bakeberry cookies","Duketater cookies","Green yeast digestives","Wheat slims","Fern tea","Ichor syrup"];function Jo(e){return Nt[e]?Nt[e].won:0}function Zo(){let e=0;Object.keys(Game.GrandmaSynergies).forEach((t=>{Lt(Game.GrandmaSynergies[t])&&(e+=1)})),!Jo("Elder")&&e>=7&&Vo("Elder"),!Jo("Veteran")&&e>=14&&Vo("Veteran");let t=0,o=1,n=1,a=1e5;Object.keys(Ft).forEach((e=>{t+=Ft[e].amount,a=Math.min(Ft[e].amount,a),Jo("Mathematician")||Ft[e].amount=1&&Vo("One with everything"),1===o&&Vo("Mathematician"),1===n&&Vo("Base 10"),a>=100&&Vo("Centennial"),a>=150&&Vo("Centennial and a half"),a>=200&&Vo("Bicentennial"),a>=250&&Vo("Bicentennial and a half"),a>=300&&Vo("Tricentennial"),a>=350&&Vo("Tricentennial and a half"),a>=400&&Vo("Quadricentennial"),a>=450&&Vo("Quadricentennial and a half"),a>=500&&Vo("Quincentennial"),a>=550&&Vo("Quincentennial and a half"),a>=600&&Vo("Sexcentennial"),t>=100&&Vo("Builder"),t>=500&&Vo("Architect"),t>=1e3&&Vo("Engineer"),t>=2e3&&Vo("Lord of Constructs"),t>=4e3&&Vo("Grand design"),t>=8e3&&Vo("Ecumenopolis"),de>=20&&Vo("Enhancer"),de>=50&&Vo("Augmenter"),de>=100&&Vo("Upgrader"),de>=200&&Vo("Lord of Progress"),de>=300&&Vo("The full picture"),de>=400&&Vo("When there's nothing left to add"),t>=4e3&&de>=300&&Vo("Polymath"),t>=8e3&&de>=400&&Vo("Renaissance baker"),Ft.Cursor.amount+Ft.Grandma.amount>=777&&Vo("The elder scrolls");let i=!0;Object.keys(Xo).forEach((e=>{Lt(Xo[e])||(i=!1)})),i&&Vo("Spooky cookies");let r=!0;if(Object.keys(qo).forEach((e=>{Lt(qo[e])||(r=!1)})),r&&Vo("Let it snow"),Lt("Fortune cookies")){const e=Game.Tiers.fortune.upgrades;let t=0;Object.keys(e).forEach((o=>{Lt(e[o].name)&&(t+=1)})),t>=e.length&&Vo("O Fortuna")}}function en(e,t){Uo(),Ft[e].amount+=t;const o=Ft[e];"Cursor"===e?(o.amount>=1&&Vo("Click"),o.amount>=2&&Vo("Double-click"),o.amount>=50&&Vo("Mouse wheel"),o.amount>=100&&Vo("Of Mice and Men"),o.amount>=200&&Vo("The Digital"),o.amount>=300&&Vo("Extreme polydactyly"),o.amount>=400&&Vo("Dr. T"),o.amount>=500&&Vo("Thumbs, phalanges, metacarpals"),o.amount>=600&&Vo("With her finger and her thumb"),o.amount>=700&&Vo("Gotta hand it to you"),o.amount>=800&&Vo("The devil's workshop")):Object.keys(Game.Objects[o.name].tieredAchievs).forEach((e=>{o.amount>=Game.Tiers[Game.Objects[o.name].tieredAchievs[e].tier].achievUnlock&&Vo(Game.Objects[o.name].tieredAchievs[e].name)}));const n=pe;return _o(),Zo(),n!==pe&&_o(),Ge-Game.cookiesPs}function tn(e,t,o){let n=e,a=0;for(;ne.plantsById[e.plot[go[1]][go[0]][0]-1].mature,o=e.plantsById[e.plot[go[1]][go[0]][0]-1].name;l("CMTooltipBorder").appendChild($o("Reward (Current / Maximum)"));const n=document.createElement("div");n.id="CMTooltipPlantReward",l("CMTooltipBorder").appendChild(n),"Bakeberry"===o?l("CMTooltipPlantReward").textContent=`${t?$(Math.min(.03*Game.cookies,60*Game.cookiesPs*30)):"0"} / ${$(60*Game.cookiesPs*30)}`:"Chocoroot"===o||"White chocoroot"===o?l("CMTooltipPlantReward").textContent=`${t?$(Math.min(.03*Game.cookies,60*Game.cookiesPs*3)):"0"} / ${$(60*Game.cookiesPs*3)}`:"Queenbeet"===o?l("CMTooltipPlantReward").textContent=`${t?$(Math.min(.04*Game.cookies,60*Game.cookiesPs*60)):"0"} / ${$(60*Game.cookiesPs*60)}`:"Duketater"===o?l("CMTooltipPlantReward").textContent=`${t?$(Math.min(.08*Game.cookies,60*Game.cookiesPs*120)):"0"} / ${$(60*Game.cookiesPs*120)}`:l("CMTooltipArea").style.display="none"}else l("CMTooltipArea").style.display="none"}():"ha"===ho?function(){const{minigame:e}=Game.Objects.Farm;if(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TooltipLump){l("CMTooltipBorder").appendChild($o("Cookies gained from harvesting:"));let t=0,o=0;Game.keys[16]&&Game.keys[17]&&(o=1);for(let n=0;n<6;n++)for(let a=0;a<6;a++)if(e.plot[n][a][0]>=1){const i=e.plot[n][a],r=e.plantsById[i[0]-1],s=r.name;let l=!0;o&&r.immortal&&(l=!1),i[1]0&&e=1?l("CMTimerBarAutosaveBar").textContent=Math.ceil(e):l("CMTimerBarAutosaveBar").textContent="",l("CMTimerBarAutosaveTime").textContent=Math.ceil(e),o+=1}else l("CMTimerBarAutosave").style.display="none";0!==Game.shimmerTypes.golden.spawned||Game.Has("Golden switch [off]")?l("CMTimerBarGC").style.display="none":(l("CMTimerBarGC").style.display="",l("CMTimerBarGCMinBar").style.width=`${Math.round(Math.max(0,Game.shimmerTypes.golden.minTime-Game.shimmerTypes.golden.time)*e/Game.shimmerTypes.golden.maxTime)}px`,Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TimerBarOverlay>=1?l("CMTimerBarGCMinBar").textContent=Math.ceil((Game.shimmerTypes.golden.minTime-Game.shimmerTypes.golden.time)/Game.fps):l("CMTimerBarGCMinBar").textContent="",Game.shimmerTypes.golden.minTime===Game.shimmerTypes.golden.maxTime?(l("CMTimerBarGCMinBar").style.borderTopRightRadius="10px",l("CMTimerBarGCMinBar").style.borderBottomRightRadius="10px"):(l("CMTimerBarGCMinBar").style.borderTopRightRadius="",l("CMTimerBarGCMinBar").style.borderBottomRightRadius=""),l("CMTimerBarGCBar").style.width=`${Math.round(Math.min(Game.shimmerTypes.golden.maxTime-Game.shimmerTypes.golden.minTime,Game.shimmerTypes.golden.maxTime-Game.shimmerTypes.golden.time)*e/Game.shimmerTypes.golden.maxTime)}px`,Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TimerBarOverlay>=1?l("CMTimerBarGCBar").textContent=Math.ceil(Math.min(Game.shimmerTypes.golden.maxTime-Game.shimmerTypes.golden.minTime,Game.shimmerTypes.golden.maxTime-Game.shimmerTypes.golden.time)/Game.fps):l("CMTimerBarGCBar").textContent="",l("CMTimerBarGCTime").textContent=Math.ceil((Game.shimmerTypes.golden.maxTime-Game.shimmerTypes.golden.time)/Game.fps),o+=1),"christmas"===Game.season&&0===Game.shimmerTypes.reindeer.spawned?(l("CMTimerBarRen").style.display="",l("CMTimerBarRenMinBar").style.width=`${Math.round(Math.max(0,Game.shimmerTypes.reindeer.minTime-Game.shimmerTypes.reindeer.time)*e/Game.shimmerTypes.reindeer.maxTime)}px`,Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TimerBarOverlay>=1?l("CMTimerBarRenMinBar").textContent=Math.ceil((Game.shimmerTypes.reindeer.minTime-Game.shimmerTypes.reindeer.time)/Game.fps):l("CMTimerBarRenMinBar").textContent="",l("CMTimerBarRenBar").style.width=`${Math.round(Math.min(Game.shimmerTypes.reindeer.maxTime-Game.shimmerTypes.reindeer.minTime,Game.shimmerTypes.reindeer.maxTime-Game.shimmerTypes.reindeer.time)*e/Game.shimmerTypes.reindeer.maxTime)}px`,Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TimerBarOverlay>=1?l("CMTimerBarRenBar").textContent=Math.ceil(Math.min(Game.shimmerTypes.reindeer.maxTime-Game.shimmerTypes.reindeer.minTime,Game.shimmerTypes.reindeer.maxTime-Game.shimmerTypes.reindeer.time)/Game.fps):l("CMTimerBarRenBar").textContent="",l("CMTimerBarRenTime").textContent=Math.ceil((Game.shimmerTypes.reindeer.maxTime-Game.shimmerTypes.reindeer.time)/Game.fps),o+=1):l("CMTimerBarRen").style.display="none";const n={};l("CMTimerBarBuffTimers").innerHTML="",Object.keys(Game.buffs).forEach((e=>{if(Game.buffs[e]){const a=Eo(Game.buffs[e].name,Game.buffs[e].name,[{id:`${Game.buffs[e].name}Bar`}]);a.style.display="";let i="";i=void 0!==mo[Game.buffs[e].name]?mo[Game.buffs[e].name]:Qt,a.lastChild.children[1].className=$t+i,a.lastChild.children[1].style.color="black",2===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TimerBarOverlay?a.lastChild.children[1].textContent=`${Math.round(Game.buffs[e].time/Game.buffs[e].maxTime*100)}%`:a.lastChild.children[1].textContent="",a.lastChild.children[1].style.width=`${Math.round(Game.buffs[e].time*(t-8*Math.ceil(Game.buffs[e].time/Game.fps).toString().length)/Game.buffs[e].maxTime)}px`,a.lastChild.children[2].textContent=Math.ceil(Game.buffs[e].time/Game.fps),o+=1,n[Game.buffs[e].name]=a}})),Object.keys(n).forEach((e=>{l("CMTimerBarBuffTimers").appendChild(n[e])})),0!==o&&(l("CMTimerBar").style.height=12*o+2+"px"),Co!==o&&(Co=o,Oo())}}(),Po(),nn(),function(){if(1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TooltipWrink&&1===to){let e=!1;Object.keys(Game.wrinklers).forEach((t=>{const o=Game.wrinklers[t];if(o.phase>0&&o.selected){if(e=!0,0===no[t]||void 0===no[t]){const e=document.createElement("div"),o=document.createElement("div");o.style.minWidth="120px",o.style.marginBottom="4px";const n=document.createElement("div");n.style.textAlign="center",n.id="CMTooltipWrinkler",o.appendChild(n),e.appendChild(o),Game.tooltip.draw(this,escape(e.innerHTML)),oo=t,no[t]=1}}else no[t]=0})),e||Game.tooltip.hide()}}(),function(){if(1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TooltipWrink&&null!==l("CMTooltipWrinkler")){let{sucked:e}=Game.wrinklers[oo],t=1.1;if(Game.Has("Sacrilegious corruption")&&(t*=1.05),1===Game.wrinklers[oo].type&&(t*=3),e*=t,Game.Has("Wrinklerspawn")&&(e*=1.05),Ft.Temple.minigameLoaded){const t=Game.hasGod("scorn");1===t?e*=1.15:2===t?e*=1.1:3===t&&(e*=1.05)}l("CMTooltipWrinkler").textContent=$(e)}}(),Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.UpStats&&"stats"===Game.onMenu&&(Game.drawT-1)%(5*Game.fps)!=0&&(Game.drawT-1)%Game.fps==0&&Game.UpdateMenu(),g(),Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.Scale){let e=l("cookies").innerHTML.replace(/.*(?=
)/i,$(Game.cookies));Game.prefs.monospace&&(e=`${e}`),l("cookies").innerHTML=e}}function rn(){R.addLatest(Game.computedMouseCps)}class sn{constructor(e){this.maxLength=e,this.queue=[]}addLatest(e){this.queue.push(e)>this.maxLength&&this.queue.shift()}calcAverage(e){let t=e;t>this.maxLength&&(t=this.maxLength),t>this.queue.length&&(t=this.queue.length);let o=0;for(let e=this.queue.length-1;e>=0&&e>this.queue.length-1-t;e--)o+=this.queue[e];return 0===o?0:o/t}calcSum(e){let t=e;return t>this.maxLength&&(t=this.maxLength),t>this.queue.length&&(t=this.queue.length),0===t?0:this.queue.slice(-t).reduce(((e,t)=>e+t),0)}}function ln(){const e=Math.floor(Date.now()/1e3);if(Game.T/Game.fps%1==0){let t=Game.cookies+Bt;Game.cpsSucked>0&&(t+=Ke),Mt=Math.max(Game.cookiesEarned,t),t*=.05;const o=e-q,n=Math.max(0,Game.cookies-Y)/o,a=Math.max(0,Ke-K)/o,i=Math.max(0,Ze[0]-J)/o,r=Math.max(0,t-_e)/o,s=(Game.cookieClicks-Z)/o;for(let e=0;e{if(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.PPRigidelMode&&1===t)e[o].color=Xt;else{e[o].color=Io(e[o],Game.Objects[o].getSumPrice(t));for(let t=0;t{const n=Game.Objects[o].getSumPrice(t);Game.cookiesPs?e[o].pp=Math.max(n-(Game.cookies+Bo()),0)/Game.cookiesPs+n/e[o].bonus:e[o].pp=n/e[o].bonus,Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.PPRigidelMode&&1===t||Tt.push([e[o].pp,t,n])}))}function mn(){!function(){vt=1/0,Tt=[],void 0===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.PPExcludeTop&&(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.PPExcludeTop=0),dn(Qe,1),dn(Xe,10),dn(qe,100),Tt.sort(((e,t)=>e[0]-t[0]));let e=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.PPExcludeTop;if(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.PPOnlyConsiderBuyable)for(;Tt[e][2]>Game.cookies&&(e+=1,Tt.length!==e+1););vt=Tt[e][0],xt=Tt[e][1],cn(Qe,1),cn(Xe,10),cn(qe,100)}(),Object.keys(ot).forEach((e=>{Game.cookiesPs?ot[e].pp=Math.max(Game.Upgrades[e].getPrice()-(Game.cookies+Bo()),0)/Game.cookiesPs+Game.Upgrades[e].getPrice()/ot[e].bonus:ot[e].pp=Game.Upgrades[e].getPrice()/ot[e].bonus,Number.isNaN(ot[e].pp)&&(ot[e].pp=1/0),ot[e].color=Io(ot[e],Game.Upgrades[e].getPrice())})),window.CookieMonsterData.Objects1=JSON.parse(JSON.stringify(Qe)),window.CookieMonsterData.Objects10=JSON.parse(JSON.stringify(Xe)),window.CookieMonsterData.Objects100=JSON.parse(JSON.stringify(qe)),window.CookieMonsterData.Upgrades=[],Object.entries(ot).forEach((e=>{window.CookieMonsterData.Upgrades[e[0]]=JSON.parse(JSON.stringify(e[1]))}))}function pn(e,t,o,n,a){let i=o,r=0;for(let o=0;o{t[o]={},t[o].bonus=en(o,e),1!==e&&(se=1)})),t}function hn(){Object.keys(Game.Objects).forEach((e=>{Qe[e].price=pn(Game.Objects[e],Game.Objects[e].basePrice,Game.Objects[e].amount,Game.Objects[e].free,1),Xe[e].price=pn(Game.Objects[e],Game.Objects[e].basePrice,Game.Objects[e].amount,Game.Objects[e].free,10),qe[e].price=pn(Game.Objects[e],Game.Objects[e].basePrice,Game.Objects[e].amount,Game.Objects[e].free,100),Ye[e].price=pn(Game.Objects[e],Game.Objects[e].basePrice,Game.Objects[e].amount,Game.Objects[e].free,Ye[e].AmountNeeded)}))}function gn(){Qe=un(1),Xe=un(10),qe=un(100),ot=[],Object.keys(Game.Upgrades).forEach((e=>{const t=function(e){if("toggle"===Game.Upgrades[e].pool||0===Game.Upgrades[e].bought&&Game.Upgrades[e].unlocked&&"prestige"!==Game.Upgrades[e].pool){Uo(),"Shimmering veil [on]"===Pt[e].name?Pt["Shimmering veil [off]"].bought=0:"Golden switch [on]"===Pt[e].name?Pt["Golden switch [off]"].bought=0:Pt[e].bought=(Pt[e].bought+1)%2,Game.CountsAsUpgradeOwned(Game.Upgrades[e].pool)&&(de+=1),"Elder Pledge"===e?(me+=1,me>0&&Vo("Elder nap"),me>=5&&Vo("Elder slumber")):"Elder Covenant"===e?Vo("Elder calm"):"Prism heart biscuits"===e?Vo("Lovely cookies"):"Heavenly key"===e&&Vo("Wholesome");const t=pe;_o(),Zo(),t!==pe&&_o();const o=function(){let e=0;Lt("Thousand fingers")&&(e+=.1),Lt("Million fingers")&&(e*=5),Lt("Billion fingers")&&(e*=10),Lt("Trillion fingers")&&(e*=20),Lt("Quadrillion fingers")&&(e*=20),Lt("Quintillion fingers")&&(e*=20),Lt("Sextillion fingers")&&(e*=20),Lt("Septillion fingers")&&(e*=20),Lt("Octillion fingers")&&(e*=20),Lt("Nonillion fingers")&&(e*=20);let t=0;Object.keys(Ft).forEach((e=>{t+=Ft[e].amount})),t-=Ft.Cursor.amount,e*=t,Lt("Plastic mouse")&&(e+=.01*Ge),Lt("Iron mouse")&&(e+=.01*Ge),Lt("Titanium mouse")&&(e+=.01*Ge),Lt("Adamantium mouse")&&(e+=.01*Ge),Lt("Unobtainium mouse")&&(e+=.01*Ge),Lt("Eludium mouse")&&(e+=.01*Ge),Lt("Wishalloy mouse")&&(e+=.01*Ge),Lt("Fantasteel mouse")&&(e+=.01*Ge),Lt("Nevercrack mouse")&&(e+=.01*Ge),Lt("Armythril mouse")&&(e+=.01*Ge),Lt("Technobsidian mouse")&&(e+=.01*Ge),Lt("Plasmarble mouse")&&(e+=.01*Ge),Lt("Miraculite mouse")&&(e+=.01*Ge),Lt("Fortune #104")&&(e+=.01*Ge);let o=1;if(Lt("Santa's helpers")&&(o*=1.1),Lt("Cookie egg")&&(o*=1.1),Lt("Halo gloves")&&(o*=1.1),Lt("Dragon claw")&&(o*=1.03),Lt("Aura gloves")&&(o*=1+.05*Math.min(Game.Objects.Cursor.level,Lt("Luminous gloves")?20:10)),o*=At("click"),Ft.Temple.minigameLoaded&&Wt){const e=Wt("labor");1===e?o*=1.15:2===e?o*=1.1:3===e&&(o*=1.05)}Object.keys(Game.buffs).forEach((e=>{void 0!==Game.buffs[e].multClick&&(o*=Game.buffs[e].multClick)})),o*=1+.05*Ot("Dragon Cursor");let n=o*Game.ComputeCps(1,Lt("Reinforced index finger")+Lt("Carpal tunnel prevention cream")+Lt("Ambidextrous"),e);return n=Game.runModHookOnValue("cookiesPerClick",n),Game.hasBuff("Cursed finger")&&(n=Game.buffs["Cursed finger"].power),n}()-Game.computedMouseCps;return o?[Ge-Game.cookiesPs,o]:[Ge-Game.cookiesPs]}return[]}(e);"Elder Pledge"===e?(ot[e]={bonus:Game.cookiesPs-ee},1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.CalcWrink?ot[e].bonus-=te:2===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.CalcWrink&&(ot[e].bonus-=oe),Number.isFinite(ot[e].bonus)||(ot[e].bonus=0)):(ot[e]={},t[0]&&(ot[e].bonus=t[0]),t[1]&&(ot[e].bonusMouse=t[1]))}))}function fn(e,t,o){let n=0,a=0,i=0,r=0,s=1+Math.max(0,Math.ceil(Math.log(Game.cookies)/Math.LN10)-10);for(;i0?e/=t:e=0,ct=fn(7,e,$e),st=2*ct[1]/$e,lt=ct[2]/60/60/6/Ue,pt=fn(6,e,Re),dt=2*pt[1]/Re,mt=pt[2]/60/60/6/Ue,gt=fn(7,7*e,$e),ut=2*gt[1]/$e,ht=gt[2]/60/60/6/Ue,Ct=fn(6,7*e,Re),ft=2*Ct[1]/Re,kt=Ct[2]/60/60/6/Ue}function Cn(){const e=Math.floor(Date.now()/1e3);if(Game.T/Game.fps%1==0){const t=Game.HowMuchPrestige(Game.cookiesReset),o=Math.floor(Game.HowMuchPrestige(Game.cookiesReset+Game.cookiesEarned))-Math.floor(t),n=e-ie,a=Math.max(0,o-re)/n;for(let e=0;e{e.push(Game.Upgrades[t])})),e.sort((function(e,t){return e.order>t.order?1:e.order{const o=e[t];if(0===o.bought){let e="";e+=function(e){let t="crate upgrade missing";"prestige"===e.pool&&(t+=" heavenly");let o=0;Game.prefs.crates||(o=1),o&&(t+=" noFrame");let{icon:n}=e;e.iconFunction&&(n=e.iconFunction());const a=`function() {return Game.crateTooltip(Game.UpgradesById[${e.id}], 'stats');}`;return`
\n\t
`}(o),"prestige"===o.pool?it+=e:"cookie"===o.pool?rt+=e:"toggle"!==o.pool&&"unused"!==o.pool&&"debug"!==o.pool&&(at+=e)}}))}function yn(){if("christmas"===Game.season){let e=60*Game.cookiesPs;Game.hasBuff("Elder frenzy")&&(e*=.5),Game.hasBuff("Frenzy")&&(e*=.75),Ve=Math.max(25,e),Game.Has("Ho ho ho-flavored frosting")&&(Ve*=2)}}function bn(){Ee=900*He/.15,Ee*=Ue;const e=zo();e>0?Ee/=e:Ee=0,Fe=$e*(.15*Ee)+13,Pe=Re*(.15*Ee)+13,Ne=7*Ee,Oe=$e*(.15*Ne)+13,De=Re*(.15*Ne)+13,Ae=2*Ee,Le=.15*Ae,We=0;let t=0,o=0;Object.keys(Game.Objects).forEach((e=>{Game.Objects[e].amount>t&&(t=Game.Objects[e].amount),Game.Objects[e].amount>0&&(o+=1)})),Object.keys(Game.Objects).forEach((e=>{(Game.Objects[e].amountWe&&(We=2*Game.Objects[e].price,je=e)}))}function Gn(){let e=1,t=1,o=1;Lt("Green yeast digestives")&&(o*=1.01),Lt("Dragon fang")&&(o*=1.03),e*=1+.1*Game.auraMult("Ancestral Metamorphosis"),e*=Game.eff("goldenCookieGain"),t*=1+.1*Game.auraMult("Unholy Dominion"),t*=Game.eff("wrathCookieGain"),$e=o*e,Re=o*t,Ue=1,0===Game.shimmerTypes.golden.n&&(Ue*=1+1.23*Game.auraMult("Dragon's Fortune"))}function wn(e){const t={};Object.keys(Game.Objects).forEach((o=>{if(0!==Object.keys(Ye).length&&Ye[o].TotalNeeded>Game.Objects[o].amount&&!e)t[o]={AmountNeeded:Ye[o].TotalNeeded-Game.Objects[o].amount,TotalNeeded:Ye[o].TotalNeeded,price:Game.Objects[o].getSumPrice(Ye[o].TotalNeeded-Game.Objects[o].amount)};else{const e=function(e){const t=Game.AchievementsOwned;let o=100,n=100;for(;o>-1;)if(en(e,o),pe>t)n=o,o-=10;else{if(100===o)return 101;for(o+=1;o<=n;){if(en(e,o),pe>t)return o;o+=1}}return 101}(o);t[o]={AmountNeeded:e,TotalNeeded:Game.Objects[o].amount+e,price:Game.Objects[o].getSumPrice(e)}}})),Ye=t}function vn(){Ke=0,Je=0,Ze=[0,null];for(let e=0;eZe[0]&&(Ze=[t,e]))}}function xn(){Ao(),vn(),bn(),Gn(),kn(),Mn(),yn(),I=new sn(lo[lo.length-1]),z=new sn(lo[lo.length-1]),V=new sn(lo[lo.length-1]),_=new sn(lo[lo.length-1]),Q=new sn(co[co.length-1]),X=new sn(5),R=new sn(20*co[co.length-1]),Cn(),wn(),ln(),gn(),hn(),mn()}function Tn(){Object.keys(Game.wrinklers).forEach((e=>{Game.wrinklers[e].sucked>0&&0===Game.wrinklers[e].type&&(Game.wrinklers[e].hp=0)}))}function Sn(e,t){if("b"===e){if(l("tooltip").innerHTML=Game.Objects[t].tooltip(),1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TooltipAmor){const e=pn(Game.Objects[t],Game.Objects[t].basePrice,0,Game.Objects[t].free,Game.Objects[t].amount),o=e-Game.Objects[t].totalCookies;o>0&&(l("tooltip").innerHTML=l("tooltip").innerHTML.split("so far").join(`so far
${$(o)} ${1===Math.floor(o)?"cookie":"cookies"} left to amortize (${To((e-Game.Objects[t].totalCookies)/(Game.Objects[t].storedTotalCps*Game.globalCpsMult)).text})`))}-1===Game.buyMode&&(l("tooltip").innerHTML=l("tooltip").innerHTML.split($(Game.Objects[t].bulkPrice)).join($((Game.Objects[t],Game.Objects[t].basePrice,Game.Objects[t].amount,Game.Objects[t].free,Game.buyBulk,1))))}else if("u"===e){if(!Game.UpgradesInStore[t])return"";l("tooltip").innerHTML=Game.crateTooltip(Game.UpgradesInStore[t],"store")}else"s"===e?l("tooltip").innerHTML=Game.lumpTooltip():"g"===e?l("tooltip").innerHTML=Game.Objects["Wizard tower"].minigame.spellTooltip(t)():"p"===e?l("tooltip").innerHTML=Game.ObjectsById[2].minigame.tileTooltip(t[0],t[1])():"ha"===e?l("tooltip").innerHTML=Game.ObjectsById[2].minigame.toolTooltip(1)():"wb"===e?l("tooltip").innerHTML="":"pag"===e?l("tooltip").innerHTML=Game.Objects.Temple.minigame.godTooltip(t)():"pas"===e&&(l("tooltip").innerHTML=Game.Objects.Temple.minigame.slotTooltip(t[0])());if("b"===e&&1===Game.buyMode||"u"===e||"s"===e||"g"===e||"p"===e&&!Game.keys[16]||"ha"===e||"wb"===e||"pag"===e||"pas"===e&&-1!==t[1]){const e=document.createElement("div");e.id="CMTooltipArea",l("tooltip").appendChild(e)}return ho=e,go=t,nn(),l("tooltip").innerHTML}function Bn(){1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.Favicon&&F>0?bt.wrath?l("CMFavicon").href="https://CookieMonsterTeam.github.io/CookieMonster/favicon/wrathCookie.ico":l("CMFavicon").href="https://CookieMonsterTeam.github.io/CookieMonster/favicon/goldenCookie.ico":l("CMFavicon").href="https://orteil.dashnet.org/cookieclicker/favicon.ico"}function En(){Ft=[],Object.keys(Game.Objects).forEach((e=>{Ft[e]=jo(e)})),Pt=[],Object.keys(Game.Upgrades).forEach((e=>{Pt[e]=Ho(e)})),Nt=[],Object.keys(Game.Achievements).forEach((e=>{Nt[e]=Lo(e)})),Uo()}function Fn(){Game.Objects["Wizard tower"].minigameLoaded&&Object.keys(Game.Objects["Wizard tower"].minigame.spellsById).forEach((e=>{null!==l(`grimoireSpell${e}`).onmouseover&&(L[e]=l(`grimoireSpell${e}`).onmouseover,l(`grimoireSpell${e}`).onmouseover=function(){Game.tooltip.dynamic=1,Game.tooltip.draw(this,(()=>Sn("g",`${e}`)),"this"),Game.tooltip.wobble()})}))}function Pn(){if(!x&&Game.Objects["Wizard tower"].minigameLoaded){const{minigame:e}=Game.Objects["Wizard tower"];w=e.draw,Game.Objects["Wizard tower"].minigame.draw=function(){w(),1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.GrimoireBar&&e.magic{if(e=n,Game.Objects[e].amount{ye=!0})),Scale:new Rn(2,"bool","Notation",["Game's setting scale","Metric","Short scale","Short scale (Abbreviated)","Scientific notation","Engineering notation"],"Change how long numbers are formatted",!1,(()=>{jn()})),ScaleDecimals:new Rn(2,"bool","Notation",["1 decimals","2 decimals","3 decimals"],'Set the number of decimals used when applicable. This only works with Cookie Monster scales and not with "Game\'s Setting Scale"',!1,(()=>{jn()})),ScaleSeparator:new Rn(0,"bool","Notation",[". for decimals (standard)",". for thousands"],"Set the separator used for decimals and thousands",!1,(()=>{jn()})),ScaleCutoff:new $n(999999,"numscale","Notation","Notation cut-off point: ","The number from which Cookie Monster will start formatting numbers based on chosen scale. Standard is 999,999. Setting this above 999,999,999 might break certain notations",1,999999999),TimeFormat:new Rn(0,"bool","Notation",["Time XXd, XXh, XXm, XXs","Time XX:XX:XX:XX:XX"],"Change the time format",!1),DetailedTime:new Rn(1,"bool","Notation",["Detailed time OFF","Detailed time ON"],"Change how time is displayed in certain statistics and tooltips",!0,(()=>{1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.DetailedTime?Game.sayTime=ao:Game.sayTime=j.sayTime})),PPDisplayTime:new Rn(0,"bool","Notation",["PP as value (standard)","PP as time unit"],"Display PP as calculated value or as approximate time unit. Note that PP does not translate directly into a time unit and this is therefore only an approximation.",!1),BuildColour:new Rn(1,"bool","Colours",["Building colours OFF","Building colours ON"],"Colour code buildings",!0,(()=>{Go()})),PPOnlyConsiderBuyable:new Rn(0,"bool","Colours",["Don't ignore non-buyable","Ignore non-buyable"],"Makes Cookie Monster label buildings and upgrades you can't buy right now red, useful in those situations where you just want to spend your full bank 'most optimally'",!0),PPExcludeTop:new Rn(0,"bool","Colours",["Don't ignore any","Ignore 1st best","Ignore 1st and 2nd best","Ignore 1st, 2nd and 3rd best"],"Makes Cookie Monster ignore the 1st, 2nd or 3rd best buildings in labeling and colouring PP values",!0),PPRigidelMode:new Rn(0,"bool","Colours",["Rigidel mode OFF","Rigidel mode ON"],'Makes Cookie Monster ignore all "buy 1" options when colouring PP in order to stay at a total building count ending in 10 for pantheon god Rigidel',!0),PPSecondsLowerLimit:new $n(0,"numscale","Colours","Lower limit for PP (in seconds): ",'If a building or upgrade costs less than the specified seconds of CPS it will also be considered optimal and label it as such ("PP is less than xx seconds of CPS"); setting to 0 ignores this option',0,1/0),ColourBlue:new Un("#4bb8f0","colour","Colours","Standard colour is blue. Used to show upgrades better than best PP building, for Click Frenzy bar, and for various labels"),ColourGreen:new Un("#00ff00","colour","Colours","Standard colour is green. Used to show best PP building, for Blood Frenzy bar, and for various labels"),ColourYellow:new Un("#ffff00","colour","Colours","Standard colour is yellow. Used to show buildings within the top 10 of PP, for Frenzy bar, and for various labels"),ColourOrange:new Un("#ff7f00","colour","Colours","Standard colour is orange. Used to show buildings within the top 20 of PP, for Next Reindeer bar, and for various labels"),ColourRed:new Un("#ff0000","colour","Colours","Standard colour is Red. Used to show buildings within the top 30 of PP, for Clot bar, and for various labels"),ColourPurple:new Un("#ff00ff","colour","Colours","Standard colour is purple. Used to show buildings outside of the top 30 of PP, for Next Cookie bar, and for various labels"),ColourGray:new Un("#b3b3b3","colour","Colours","Standard colour is gray. Used to show negative or infinity PP, and for Next Cookie/Next Reindeer bar"),ColourPink:new Un("#ff1493","colour","Colours","Standard colour is pink. Used for Dragonflight bar"),ColourBrown:new Un("#8b4513","colour","Colours","Standard colour is brown. Used for Dragon Harvest bar"),BotBar:new Rn(1,"bool","BarsDisplay",["Bottom bar OFF","Bottom bar ON"],"Building information",!0,(()=>{Wn()})),TimerBar:new Rn(1,"bool","BarsDisplay",["Timer bar OFF","Timer bar ON"],"Bar with timers for golden cookie, season popup, Frenzy (Normal, Clot, Elder), Click Frenzy",!0,(()=>{Do()})),TimerBarPos:new Rn(0,"bool","BarsDisplay",["Timer bar position (top left)","Timer bar position (bottom)"],"Placement of the timer bar",!1,(()=>{0===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TimerBarPos?(l("CMTimerBar").style.width="30%",l("CMTimerBar").style.bottom="",l("game").insertBefore(l("CMTimerBar"),l("sectionLeft"))):(l("CMTimerBar").style.width="100%",l("CMTimerBar").style.bottom="0px",l("wrapper").appendChild(l("CMTimerBar"))),Oo()})),TimerBarOverlay:new Rn(2,"bool","BarsDisplay",["Timer bar overlay OFF","Timer bar overlay only seconds","Timer bar overlay full"],"Overlay on timers displaying seconds and/or percentage left",!0),AutosaveTimerBar:new Rn(0,"bool","BarsDisplay",["Autosave timer bar OFF","Autosave timer bar ON"],"Show a timer counting down till next autosave in the timer bar",!0),UpBarColour:new Rn(1,"bool","BarsDisplay",["Upgrade colours/bar OFF","Upgrade colours with bar ON","Upgrade colours without bar ON"],"Colour code upgrades and optionally add a counter bar",!1,(()=>{1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.UpBarColor?(l("CMUpgradeBar").style.display="",vo()):2===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.UpBarColor?(l("CMUpgradeBar").style.display="none",vo()):(l("CMUpgradeBar").style.display="none",Game.RebuildUpgrades())})),UpgradeBarFixedPos:new Rn(1,"bool","BarsDisplay",["Upgrade bar fixed position OFF","Upgrade bar fixed position ON"],"Lock the upgrade bar at top of the screen to prevent it from moving ofscreen when scrolling",!0,(()=>{1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.UpgradeBarFixedPos?(l("CMUpgradeBar").style.position="sticky",l("CMUpgradeBar").style.top="0px"):l("CMUpgradeBar").style.position=""})),SortBuildings:new Rn(0,"bool","BarsDisplay",["Sort buildings: default","Sort buildings: PP of x1 purchase","Sort buildings: PP of selected bulk mode","Sort buildings: price until next achievement"],"Sort the display of buildings in default order, by PP, or until next achievement",!1,(()=>{Go()})),SortUpgrades:new Rn(0,"bool","BarsDisplay",["Sort upgrades: default","Sort upgrades: PP"],"Sort the display of upgrades in either default order or by PP",!1,(()=>{vo()})),UpgradesNeverCollapse:new Rn(0,"bool","BarsDisplay",["Upgrades always expanded OFF","Upgrades always expanded ON"],"Toggle to make the upgrades sections always expanded to the size needed to display all upgrades",!0,(()=>{wo()})),DragonAuraInfo:new Rn(1,"bool","BarsDisplay",["Extra dragon aura info OFF","Extra dragon aura info ON"],"Shows information about changes in CPS and costs in the dragon aura interface.",!0),GrimoireBar:new Rn(1,"bool","BarsDisplay",["Grimoire magic meter timer OFF","Grimoire magic meter timer ON"],"A timer overlay showing how long till the Grimoire magic meter is full",!0),GCTimer:new Rn(1,"bool","BarsDisplay",["Golden cookie timer OFF","Golden cookie timer ON"],"A timer on the golden cookie when it has been spawned",!0,(()=>{1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.GCTimer?Object.keys(Mo).forEach((e=>{Mo[e].style.display="block",Mo[e].style.left=St[e].l.style.left,Mo[e].style.top=St[e].l.style.top})):Object.keys(Mo).forEach((e=>Mo[e].style.display="none"))})),Favicon:new Rn(1,"bool","BarsDisplay",["Favicon OFF","Favicon ON"],"Update favicon with golden/wrath cookie",!0,(()=>{Bn()})),WrinklerButtons:new Rn(1,"bool","BarsDisplay",["Extra wrinkler buttons OFF","Extra wrinkler buttons ON"],"Show buttons for popping wrinklers at bottom of cookie section",!0,(()=>{g()})),HideSectionsButtons:new Rn(0,"bool","BarsDisplay",["Hide buildings/upgrades button OFF","Hide buildings/upgrades button ON"],"Show buttons for hiding and showing the buildings and upgrades sections in the right column",!0,(()=>{Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.HideSectionsButtons?l("CMSectionHidButtons").style.display="":l("CMSectionHidButtons").style.display="none"})),TooltipBuildUpgrade:new Rn(1,"bool","Tooltip",["Building/upgrade tooltip information OFF","Building/upgrade tooltip information ON"],"Extra information in building/upgrade tooltips",!0),TooltipAmor:new Rn(0,"bool","Tooltip",["Buildings tooltip amortization information OFF","Buildings tooltip amortization information ON"],"Add amortization information to buildings tooltip",!0),ToolWarnLucky:new Rn(1,"bool","Tooltip",["Tooltip lucky warning OFF","Tooltip lucky warning ON"],'A warning when buying if it will put the bank under the amount needed for max "Lucky!" rewards',!0),ToolWarnLuckyFrenzy:new Rn(1,"bool","Tooltip",["Tooltip lucky frenzy warning OFF","Tooltip lucky frenzy warning ON"],'A warning when buying if it will put the bank under the amount needed for max "Lucky!" (Frenzy) rewards',!0),ToolWarnConjure:new Rn(1,"bool","Tooltip",["Tooltip conjure warning OFF","Tooltip conjure warning ON"],'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards',!0),ToolWarnConjureFrenzy:new Rn(1,"bool","Tooltip",["Tooltip conjure frenzy warning OFF","Tooltip conjure frenzy warning ON"],'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards with Frenzy active',!0),ToolWarnEdifice:new Rn(1,"bool","Tooltip",["Tooltip edifice warning OFF","Tooltip edifice warning ON"],'A warning when buying if it will put the bank under the amount needed for "Spontaneous Edifice" to possibly give you your most expensive building',!0),ToolWarnUser:new $n(0,"numscale","Tooltip","Tooltip warning at x times CPS: ","Use this to show a customized warning if buying it will put the bank under the amount equal to value times cps; setting to 0 disables the function altogether",0,1/0),ToolWarnBon:new Rn(1,"bool","Tooltip",["Calculate tooltip warning with bonus CPS OFF","Calculate tooltip warning with bonus CPS ON"],"Calculate the warning with or without the bonus CPS you get from buying",!0),ToolWarnPos:new Rn(1,"bool","Tooltip",["Tooltip warning position (left)","Tooltip warning position (bottom)"],"Placement of the warning boxes",!1,(()=>{on()})),TooltipGrim:new Rn(1,"bool","Tooltip",["Grimoire tooltip information OFF","Grimoire tooltip information ON"],"Extra information in tooltip for grimoire",!0),TooltipWrink:new Rn(1,"bool","Tooltip",["Wrinkler tooltip OFF","Wrinkler tooltip ON"],"Shows the amount of cookies a wrinkler will give when popping it",!0),TooltipLump:new Rn(1,"bool","Tooltip",["Sugar lump tooltip OFF","Sugar lump tooltip ON"],"Shows the current Sugar Lump type in Sugar lump tooltip.",!0),TooltipPlots:new Rn(1,"bool","Tooltip",["Garden plots tooltip OFF","Garden plots tooltip ON"],"Shows a tooltip for plants that have a cookie reward.",!0),TooltipPantheon:new Rn(1,"bool","Tooltip",["Pantheon tooltip OFF","Pantheon tooltip ON"],"Shows additional info in the pantheon tooltip",!0),TooltipAscendButton:new Rn(1,"bool","Tooltip",["Show Extra Info Ascend Tooltip OFF","Show Extra Info Ascend Tooltip ON"],"Shows additional info in the ascend tooltip",!0),Stats:new Rn(1,"bool","Statistics",["Statistics OFF","Statistics ON"],"Extra Cookie Monster statistics!",!0),MissingUpgrades:new Rn(1,"bool","Statistics",["Missing upgrades OFF","Missing upgrades ON"],"Shows missing upgrades in statistics menu",!0),MissingAchievements:new Rn(0,"bool","Statistics",["Missing Achievements OFF","Missing Normal Achievements ON"],"Shows missing normal achievements in statistics menu.",!0),UpStats:new Rn(1,"bool","Statistics",["Statistics update rate (default)","Statistics update rate (1s)"],"Default rate is once every 5 seconds",!1),HeavenlyChipsTarget:new $n(1,"numscale","Statistics","Heavenly chips target: ",'Use this to set a heavenly chips target that will be counted towards in the "prestige" statsistics sections',1,1/0),ShowMissedGC:new Rn(1,"bool","Statistics",["Missed GC OFF","Missed GC ON"],"Show a stat in the statistics screen that counts how many golden cookies you have missed",!0),Title:new Rn(1,"bool","NotificationGeneral",["Title OFF","Title ON","Title pinned tab highlight"],'Update title with colden cookie/season popup timers; pinned tab highlight only changes the title when a golden cookie/season popup spawns; "!" means that golden cookie/reindeer can spawn',!0),GeneralSound:new Rn(1,"bool","NotificationGeneral",["Consider game volume setting OFF","Consider game volume setting ON"],'Turning this toggle to "off" makes Cookie Monster no longer consider the volume setting of the base game, allowing mod notifications to play with base game volume turned down',!0),GCNotification:new Rn(0,"bool","NotificationGC",["Notification OFF","Notification ON"],"Create a notification when golden cookie spawns",!0,(()=>{Ln(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.GCNotification)})),GCFlash:new Rn(1,"bool","NotificationGC",["Flash OFF","Flash ON"],"Flash screen on golden cookie",!0),ColourGCFlash:new Un("#ffffff","colour","NotificationGC","The colour of the GC flash, standard colour is white"),GCSound:new Rn(1,"bool","NotificationGC",["Sound OFF","Sound ON"],"Play a sound on golden cookie",!0),GCVolume:new In(100,"vol","NotificationGC",[],"Volume"),GCSoundURL:new Rn("https://freesound.org/data/previews/66/66717_931655-lq.mp3","url","NotificationGC","Sound URL:","URL of the sound to be played when a golden cookie spawns"),FortuneNotification:new Rn(0,"bool","NotificationFC",["Notification OFF","Notification ON"],"Create a notification when fortune cookie is on the ticker",!0,(()=>{Ln(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.FortuneNotification)})),FortuneFlash:new Rn(1,"bool","NotificationFC",["Flash OFF","Flash ON"],"Flash screen on fortune cookie spawn",!0),ColourFortuneFlash:new Un("#ffffff","colour","NotificationFC","The colour of the fortune flash, standard colour is white"),FortuneSound:new Rn(1,"bool","NotificationFC",["Sound OFF","Sound ON"],"Play a sound on fortune cookie spawn",!0),FortuneVolume:new In(100,"vol","NotificationFC",[],"Volume"),FortuneSoundURL:new Rn("https://freesound.org/data/previews/174/174027_3242494-lq.mp3","url","NotificationFC","Sound URL:","URL of the sound to be played when the ticker has a fortune cookie"),SeaNotification:new Rn(0,"bool","NotificationSea",["Notification OFF","Notification ON"],"Create a notification on season popup",!0,(()=>{Ln(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.SeaNotification)})),SeaFlash:new Rn(1,"bool","NotificationSea",["Flash OFF","Flash ON"],"Flash screen on season popup",!0),ColourSeaFlash:new Un("#ffffff","colour","NotificationSea","The colour of the season popup flash, standard colour is white"),SeaSound:new Rn(1,"bool","NotificationSea",["Sound OFF","Sound ON"],"Play a sound on season popup",!0),SeaVolume:new In(100,"vol","NotificationSea",[],"Volume"),SeaSoundURL:new Rn("https://www.freesound.org/data/previews/121/121099_2193266-lq.mp3","url","NotificationSea","Sound URL:","URL of the sound to be played when on season popup spawns"),GardFlash:new Rn(1,"bool","NotificationGard",["Garden Tick Flash OFF","Flash ON"],"Flash screen on garden tick",!0),ColourGardFlash:new Un("#ffffff","colour","NotificationGard","The colour of the garden flash, standard colour is white"),GardSound:new Rn(1,"bool","NotificationGard",["Sound OFF","Sound ON"],"Play a sound on garden tick",!0),GardVolume:new In(100,"vol","NotificationGard",[],"Volume"),GardSoundURL:new Rn("https://freesound.org/data/previews/103/103046_861714-lq.mp3","url","NotificationGard","Garden Tick Sound URL:","URL of the sound to be played when the garden ticks"),MagicNotification:new Rn(0,"bool","NotificationMagi",["Notification OFF","Notification ON"],"Create a notification when magic reaches maximum",!0,(()=>{Ln(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.MagicNotification)})),MagicFlash:new Rn(1,"bool","NotificationMagi",["Flash OFF","Flash ON"],"Flash screen when magic reaches maximum",!0),ColourMagicFlash:new Un("#ffffff","colour","NotificationMagi","The colour of the magic flash, standard colour is white"),MagicSound:new Rn(1,"bool","NotificationMagi",["Sound OFF","Sound ON"],"Play a sound when magic reaches maximum",!0),MagicVolume:new In(100,"vol","NotificationMagi",[],"Volume"),MagicSoundURL:new Rn("https://freesound.org/data/previews/221/221683_1015240-lq.mp3","url","NotificationMagi","Sound URL:","URL of the sound to be played when magic reaches maxium"),WrinklerNotification:new Rn(0,"bool","NotificationWrink",["Notification OFF","Notification ON"],"Create a notification when a wrinkler appears",!0,(()=>{Ln(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.WrinklerNotification)})),WrinklerFlash:new Rn(1,"bool","NotificationWrink",["Flash OFF","Flash ON"],"Flash screen when a wrinkler appears",!0),ColourWrinklerFlash:new Un("#ffffff","colour","NotificationWrink","The colour of the wrinkler flash, standard colour is white"),WrinklerSound:new Rn(1,"bool","NotificationWrink",["Sound OFF","Sound ON"],"Play a sound when a wrinkler appears",!0),WrinklerVolume:new In(100,"vol","NotificationWrink",[],"Volume"),WrinklerSoundURL:new Rn("https://freesound.org/data/previews/124/124186_8043-lq.mp3","url","NotificationWrink","Sound URL:","URL of the sound to be played when a wrinkler appears"),WrinklerMaxNotification:new Rn(0,"bool","NotificationWrinkMax",["Notification OFF","Notification ON"],"Create a notification when the maximum amount of wrinklers has appeared",!0,(()=>{Ln(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.WrinklerMaxNotification)})),WrinklerMaxFlash:new Rn(1,"bool","NotificationWrinkMax",["Flash OFF","Flash ON"],"Flash screen when the maximum amount of Wrinklers has appeared",!0),ColourWrinklerMaxFlash:new Un("#ffffff","colour","NotificationWrinkMax","The colour of the maximum wrinkler flash, standard colour is white"),WrinklerMaxSound:new Rn(1,"bool","NotificationWrinkMax",["Sound OFF","Sound ON"],"Play a sound when the maximum amount of wrinklers has appeared",!0),WrinklerMaxVolume:new In(100,"vol","NotificationWrinkMax",[],"Volume"),WrinklerMaxSoundURL:new Rn("https://freesound.org/data/previews/152/152743_15663-lq.mp3","url","NotificationWrinkMax","Sound URL:","URL of the sound to be played when the maximum amount of wrinklers has appeared"),BulkBuyBlock:new Rn(1,"bool","Miscellaneous",["Block bulk buying OFF","Block bulk buying ON"],"Block clicking bulk buying when you can't buy all. This prevents buying 7 of a building when you are in buy-10 or buy-100 mode.",!0),FavouriteSettings:new Rn(1,"bool","Miscellaneous",["Favourite settings section OFF","Favourite settings section ON","Favourite settings section ON (Locked)"],"Show stars before each setting which allows selecting it for a 'favourites' section at the top of the Cookie Monster settings. Setting this to Locked removes the stars but shows the 'favourites' section",!0,(()=>{Game.UpdateMenu()}))},Vn="CMConfig";function _n(e){null!==l(`slider${e}`)&&(l(`slider${e}right`).innerHTML=`${l(`slider${e}`).value}%`,Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e]=Math.round(l(`slider${e}`).value)),t()}function Qn(e){Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[e]+=1,Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[e]>1&&(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[e]=0),t()}function Xn(e,t){const o=document.createElement("div");o.className="title",o.style.padding="0px 16px",o.style.opacity="0.7",o.style.fontSize="17px",o.style.fontFamily='"Kavoon", Georgia, serif',o.appendChild(document.createTextNode(`${e} `));const n=document.createElement("span");return n.style.cursor="pointer",n.style.display="inline-block",n.style.height="14px",n.style.width="14px",n.style.borderRadius="7px",n.style.textAlign="center",n.style.backgroundColor="#C0C0C0",n.style.color="black",n.style.fontSize="13px",n.style.verticalAlign="middle",n.textContent=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[t]?"-":"+",n.onclick=function(){Qn(t),Game.UpdateMenu()},o.appendChild(n),o}function qn(e,t,o,n){const a=document.createElement("div");a.className="listing";const i=document.createElement("b");if(i.textContent=t,a.appendChild(i),"withTooltip"===e){a.className="listing",a.appendChild(document.createTextNode(" "));const e=document.createElement("span");e.onmouseout=function(){Game.tooltip.hide()},e.onmouseover=function(){Game.tooltip.draw(this,escape(Zt[n].innerHTML))},e.style.cursor="default",e.style.display="inline-block",e.style.height="10px",e.style.width="10px",e.style.borderRadius="5px",e.style.textAlign="center",e.style.backgroundColor="#C0C0C0",e.style.color="black",e.style.fontSize="9px",e.style.verticalAlign="bottom",e.textContent="?",a.appendChild(e)}return a.appendChild(document.createTextNode(": ")),a.appendChild(o),a}function Yn(e,t,o,n){const a=document.createElement("div");a.className="listing";const i=document.createElement("b");return i.textContent=t,!0===n&&(i.style.color=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.ColourGreen),a.appendChild(i),a.appendChild(document.createTextNode(": ")),a.appendChild(o),a}function Kn(e){const t=document.createDocumentFragment();t.appendChild(document.createTextNode(`${e.length} `));const o=document.createElement("span");o.onmouseout=function(){Game.tooltip.hide()};const n=document.createElement("div"),a=document.createElement("div");a.style.minWidth="140px",a.style.marginBottom="4px";const i=document.createElement("div");return i.className="name",i.style.marginBottom="4px",i.style.textAlign="center",i.textContent="Missing",a.appendChild(i),Object.keys(e).forEach((t=>{const o=document.createElement("div");o.style.textAlign="center",o.appendChild(document.createTextNode(e[t])),a.appendChild(o)})),n.appendChild(a),o.onmouseover=function(){Game.tooltip.draw(this,escape(n.innerHTML))},o.style.cursor="default",o.style.display="inline-block",o.style.height="10px",o.style.width="10px",o.style.borderRadius="5px",o.style.textAlign="center",o.style.backgroundColor="#C0C0C0",o.style.color="black",o.style.fontSize="9px",o.style.verticalAlign="bottom",o.textContent="?",t.appendChild(o),t}function Jn(e){const t=document.createElement("div");if(t.className="subsection",t.appendChild(e),t.appendChild(Xn("Lucky Cookies","Lucky")),Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers.Lucky&&t.appendChild(function(){const e=Game.auraMult("Dragon's Fortune")?"GoldCookDragonsFortuneTooltipPlaceholder":"GoldCookTooltipPlaceholder",t=document.createElement("div");t.className="CMStatsLuckySection";const o=Game.cookies+Bo(){Game.HasUnlocked(Ko[e])||c.push(Ko[e])})),0!==c.length&&e.appendChild(qn("basic","Rare plant drops left to unlock",Kn(c))),e}())),t.appendChild(Xn("Prestige","Prestige")),Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers.Prestige&&t.appendChild(function(){const e=document.createElement("div");e.className="CMStatsPrestigeSection";const t=Math.floor(Game.HowMuchPrestige(Mt+Game.cookiesReset+Ke+(Game.HasUnlocked("Chocolate egg")&&!Game.Has("Chocolate egg")?_e:0)));e.appendChild(qn("withTooltip","Prestige level (cur / max)",document.createTextNode(`${$(Game.prestige)} / ${$(t)}`),"PrestMaxTooltipPlaceholder"));const o=Math.max(0,Game.HowManyCookiesReset(t+1)-(Mt+Game.cookiesReset+Ke+(Game.HasUnlocked("Chocolate egg")&&!Game.Has("Chocolate egg")&&_e?_e:0))),n=document.createDocumentFragment();n.appendChild(document.createTextNode($(o)));const a=document.createElement("small");a.textContent=` (${xo(o/yt,1)})`,n.appendChild(a),e.appendChild(qn("withTooltip","Cookies to next level",n,"NextPrestTooltipPlaceholder")),e.appendChild(qn("withTooltip","Heavenly chips (cur / max)",document.createTextNode(`${$(Game.heavenlyChips)} / ${$(t-Game.prestige+Game.heavenlyChips)}`),"HeavenChipMaxTooltipPlaceholder")),e.appendChild(qn("basic","Heavenly chips per second (last 5 seconds)",document.createTextNode($(Ie,2))));const i=Number(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.HeavenlyChipsTarget);if(!Number.isNaN(i)){const t=i-Math.floor(Game.HowMuchPrestige(Game.cookiesReset+Game.cookiesEarned));t>0&&(e.appendChild(qn("basic","Heavenly chips to target set in settings (cur)",document.createTextNode($(t)))),e.appendChild(qn("basic","Time till target (cur, current 5 second average)",document.createTextNode(xo(t/Ie)))))}const r=function(e){let t=Game.cookiesPs;Uo(),0===Pt["Heavenly key"].bought&&(Pt["Heavenly chip secret"].bought=1,Pt["Heavenly cookie stand"].bought=1,Pt["Heavenly bakery"].bought=1,Pt["Heavenly confectionery"].bought=1,Pt["Heavenly key"].bought=1,_o(),t=Ge,Uo()),Mt>=1e6&&Vo("Sacrifice"),Mt>=1e9&&Vo("Oblivion"),Mt>=1e12&&Vo("From scratch"),Mt>=1e15&&Vo("Nihilism"),Mt>=1e18&&Vo("Dematerialize"),Mt>=1e21&&Vo("Nil zero zilch"),Mt>=1e24&&Vo("Transcendence"),Mt>=1e27&&Vo("Obliterate"),Mt>=1e30&&Vo("Negative void"),Mt>=1e33&&Vo("To crumbs, you say?"),Mt>=1e36&&Vo("You get nothing"),Mt>=1e39&&Vo("Humble rebeginnings"),Mt>=1e42&&Vo("The end of the world"),Mt>=1e45&&Vo("Oh, you're back"),Mt>=1e48&&Vo("Lazarus"),Mt>=1e51&&Vo("Smurf account"),Mt>=1e54&&Vo("If at first you don't succeed"),Pt["Heavenly chip secret"].bought=1,Pt["Heavenly cookie stand"].bought=1,Pt["Heavenly bakery"].bought=1,Pt["Heavenly confectionery"].bought=1,Pt["Heavenly key"].bought=1,he=e;const o=pe;_o(),Zo(),o!==pe&&_o();const n=Ge-t;return he=Game.prestige,n}(t),s=document.createDocumentFragment();s.appendChild(document.createTextNode($(r)));const l=Math.round(r/Game.cookiesPs*1e4);if(Number.isFinite(l)&&0!==l){const e=document.createElement("small");e.textContent=` (${l/100}% of income)`,s.appendChild(e)}e.appendChild(qn("withTooltip","Reset bonus income",s,"ResetTooltipPlaceholder"));const c=Math.floor(Game.HowMuchPrestige(Game.cookiesReset)),d=Math.floor(Game.HowMuchPrestige(Game.cookiesReset+Game.cookiesEarned)),m=d-c;if(!Game.Has("Lucky digit")){let t=7-d%10;t<0&&(t+=10);const o=m+t,n=d+t,a=document.createDocumentFragment();a.appendChild(document.createTextNode(`${n.toLocaleString()} / ${o.toLocaleString()} (+${t})`)),e.appendChild(qn("basic",'Next "Lucky Digit" (total / reset)',a))}if(!Game.Has("Lucky number")){let t=777-d%1e3;t<0&&(t+=1e3);const o=m+t,n=d+t,a=document.createDocumentFragment();a.appendChild(document.createTextNode(`${n.toLocaleString()} / ${o.toLocaleString()} (+${t})`)),e.appendChild(qn("basic",'Next "Lucky Number" (total / reset)',a))}if(!Game.Has("Lucky payout")){let t=777777-d%1e6;t<0&&(t+=1e6);const o=m+t,n=d+t,a=document.createDocumentFragment();a.appendChild(document.createTextNode(`${n.toLocaleString()} / ${o.toLocaleString()} (+${t})`)),e.appendChild(qn("basic",'Next "Lucky Payout" (total / reset)',a))}return e}()),Game.cpsSucked>0&&(t.appendChild(Xn("Wrinklers","Wrink")),Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers.Wrink)){const e=document.createDocumentFragment();e.appendChild(document.createTextNode(`${$(Ke)} / ${$(Je)} `));const o=document.createElement("a");o.textContent="Pop All Normal",o.className="option",o.onclick=function(){Tn()},e.appendChild(o),t.appendChild(qn("basic","Rewards of Popping (All/Normal)",e));const n=document.createDocumentFragment();n.appendChild(document.createTextNode(`${$(Ze[0])} `));const a=document.createElement("a");a.textContent="Pop Single Fattest",a.className="option",a.onclick=function(){null!==Ze[1]&&(Game.wrinklers[Ze[1]].hp=0)},n.appendChild(a),t.appendChild(qn("basic",`Rewards of Popping Single Fattest Non-Shiny Wrinkler (id: ${null!==Ze[1]?Ze[1]:"None"})`,n))}if(t.appendChild(function(){const e=document.createElement("div");e.className="CMStatsSeasonSection";let t=!1;const o=[];Object.keys(Xo).forEach((e=>{Game.Has(Xo[e])||(o.push(Xo[e]),t=!0)}));const n=[];Object.keys(qo).forEach((e=>{Game.Has(qo[e])||(n.push(qo[e]),t=!0)}));const a=[];Object.keys(Yo).forEach((e=>{Game.Has(Yo[e])||(a.push(Yo[e]),t=!0)}));const i=[];Object.keys(Game.eggDrops).forEach((e=>{Game.HasUnlocked(Game.eggDrops[e])||(i.push(Game.eggDrops[e]),t=!0)}));const r=[];Object.keys(Game.rareEggDrops).forEach((e=>{Game.HasUnlocked(Game.rareEggDrops[e])||(r.push(Game.rareEggDrops[e]),t=!0)}));const s=Game.HasUnlocked("Chocolate egg")&&!Game.Has("Chocolate egg"),l=Game.Has("Century egg");if(("christmas"===Game.season||t||s||l)&&(e.appendChild(Xn("Season Specials","Sea")),Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers.Sea)){if(0!==o.length){e.appendChild(Yn(0,"Halloween cookies left to buy",Kn(o),"halloween"===Game.season));let t=.95;if(Game.HasAchiev("Spooky cookies")&&(t=.8),Game.Has("Starterror")&&(t*=.9),t*=1/Game.dropRateMult(),Game.hasGod){const e=Game.hasGod("seasons");1===e?t*=.9:2===e?t*=.95:3===e&&(t*=.97)}const n=o.length/7;e.appendChild(Yn(0,"Chance of receiving a cookie from wrinkler/shiny wrinkler",document.createTextNode(`${$((1-t)*n*100)}% / ${$((1-.9*t)*n*100)}%`),"halloween"===Game.season))}if(0!==n.length){e.appendChild(Yn(0,"Christmas cookies left to buy",Kn(n),"christmas"===Game.season));let t=.8;if(Game.HasAchiev("Let it snow")&&(t=.6),t*=1/Game.dropRateMult(),Game.Has("Starsnow")&&(t*=.95),Game.hasGod){const e=Game.hasGod("seasons");1===e?t*=.9:2===e?t*=.95:3===e&&(t*=.97)}const o=n.length/7;e.appendChild(Yn(0,"Chance of receiving a cookie from reindeer",document.createTextNode(`${$((1-t)*o*100)}%`),"christmas"===Game.season))}0!==a.length&&e.appendChild(Yn(0,"Valentine cookies left to buy",Kn(a),"valentines"===Game.season));const t=function(e){let t=e*(1/Game.dropRateMult());if(Game.HasAchiev("Hide & seek champion")&&(t*=.7),Game.Has("Omelette")&&(t*=.9),Game.Has("Starspawn")&&(t*=.9),Game.hasGod){const e=Game.hasGod("seasons");1===e?t*=.9:2===e?t*=.95:3===e&&(t*=.97)}const o=1-t,n=Game.eggDrops.length-i.length,a=Game.rareEggDrops.length-r.length,s=.9*o*(1-n/Game.eggDrops.length),l=.1*o*(1-a/Game.rareEggDrops.length),c=.9*o*(n/Game.eggDrops.length)+.1*o*(a/Game.rareEggDrops.length);return[s+.9*c*(1-n/Game.eggDrops.length),l+.1*c*(1-a/Game.rareEggDrops.length)]};0!==i.length&&(e.appendChild(Yn(0,"Normal easter eggs left to unlock",Kn(i),"easter"===Game.season)),e.appendChild(Yn(0,"Chance of receiving an egg from wrinkler/golden cookie",document.createTextNode(`${$(100*t(.98)[0])}% / ${$(100*t(.9)[0])}%`),"easter"===Game.season))),0!==r.length&&(e.appendChild(Yn(0,"Rare easter eggs left to unlock",Kn(r),"easter"===Game.season)),e.appendChild(Yn(0,"Chance of receiving a rare egg from wrinkler/golden cookie",document.createTextNode(`${$(100*t(.98)[1])}% / ${$(100*t(.9)[1])}%`),"easter"===Game.season))),"christmas"===Game.season&&e.appendChild(Yn(0,"Reindeer reward",document.createTextNode($(Ve)),!0)),s&&e.appendChild(qn("withTooltip","Chocolate egg cookies",document.createTextNode($(_e)),"ChoEggTooltipPlaceholder")),l&&e.appendChild(qn("basic","Century egg multiplier",document.createTextNode(Math.round(1e4*(ze-1))/100+"%")))}return e}()),t.appendChild(Xn("Achievements","Achievs")),Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers.Achievs&&Object.keys(Game.Objects).forEach((e=>{const o=Ye[e];t.appendChild(qn("basic",e,o.AmountNeeded<101?document.createTextNode(`Next achievement in ${o.AmountNeeded}, price: ${$(o.price)}`):document.createTextNode("No new achievement for next 100 buildings")))})),t.appendChild(Xn("Miscellaneous","Misc")),Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers.Misc){if(t.appendChild(qn("basic",`Average cookies per second (past ${lo[Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.AvgCPSHist]<60?`${lo[Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.AvgCPSHist]} seconds`:lo[Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.AvgCPSHist]/60+(3===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.AvgCPSHist?" minute":" minutes")})`,document.createTextNode($(So(),3)))),t.appendChild(qn("basic",`Average cookie clicks per second (past ${co[Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.AvgClicksHist]}${0===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.AvgClicksHist?" second":" seconds"})`,document.createTextNode($(nt,1)))),t.appendChild(qn("basic",`Cookies from clicking (past ${co[Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.AvgClicksHist]}${0===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.AvgClicksHist?" second":" seconds"})`,document.createTextNode($(R.calcSum(nt*co[Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.AvgClicksHist]))))),Game.Has("Fortune cookies")){const e=[];Object.keys(Qo).forEach((t=>{Game.Has(Qo[t])||e.push(Qo[t])})),0!==e.length&&t.appendChild(qn("basic","Fortune Upgrades Left to Buy",Kn(e)))}if(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.ShowMissedGC&&t.appendChild(qn("basic","Missed golden cookies",document.createTextNode($(Game.missedGoldenClicks)))),Game.prefs.autosave){const e=document.createElement("span");e.id="CMStatsAutosaveTimer",e.innerText=Game.sayTime(60*Game.fps-(Game.OnAscend?0:Game.T%(60*Game.fps)),4),t.appendChild(qn("basic","Time till autosave",e))}}l("menu").insertBefore(t,l("menu").childNodes[2]),Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.MissingUpgrades&&l("menu").childNodes.forEach((e=>{if(e.children[0])if("Prestige"===e.children[0].innerHTML&&it){const t=it.match(new RegExp("div","g")||0).length/2,o=document.createElement("div");o.id="CMMissingUpgradesPrestigeTitle",o.className="listing";const n=document.createElement("div");n.innerHTML=`Missing Prestige upgrades: ${t}/${Game.PrestigeUpgrades.length} (${Math.floor(t/Game.PrestigeUpgrades.length*100)}%)`,o.appendChild(n),e.appendChild(o);const a=document.createElement("div");a.className="listing crateBox",a.innerHTML=it,e.appendChild(a)}else if("Upgrades"===e.children[0].innerHTML){if(at){const t=at.match(new RegExp("div","g")||0).length/2,o=document.createElement("div");o.id="CMMissingUpgradesTitle",o.className="listing";const n=document.createElement("div");n.innerHTML=`Missing normal upgrades: ${t}/${Game.UpgradesByPool[""].length+Game.UpgradesByPool.tech.length} (${Math.floor(t/(Game.UpgradesByPool[""].length+Game.UpgradesByPool.tech.length)*100)}%)`,o.appendChild(n),e.insertBefore(o,e.childNodes[3]);const a=document.createElement("div");a.className="listing crateBox",a.innerHTML=at,e.insertBefore(a,document.getElementById("CMMissingUpgradesTitle").nextSibling)}if(rt){const t=rt.match(new RegExp("div","g")||0).length/2,o=document.createElement("div");o.id="CMMissingUpgradesCookiesTitle",o.className="listing";const n=document.createElement("div");n.innerHTML=`Missing Cookie upgrades: ${t}/${Game.UpgradesByPool.cookie.length} (${Math.floor(t/Game.UpgradesByPool.cookie.length*100)}%)`,o.appendChild(n),e.appendChild(o);const a=document.createElement("div");a.className="listing crateBox",a.innerHTML=rt,e.appendChild(a)}}})),Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.MissingAchievements&&function(){let e;Object.values(document.querySelectorAll("div.title")).forEach((t=>{t.textContent.includes("Achievements")&&(e=t.parentElement.querySelectorAll("div.listing.crateBox")[0])})),Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.MissingAchievements&&Object.values(e.children).forEach((e=>{if(!e.className.includes("enabled")){const t=e.onclick.toString().split(/\[(.*)\]/gi)[1],{icon:o}=Game.AchievementsById[t];e.style.backgroundPosition=`${48*-o[0]}px ${48*-o[1]}px`,e.onmouseover=function(){Game.mouseDown||(Game.setOnCrate(this),Game.tooltip.dynamic=1,Game.tooltip.draw(this,(()=>function(e){const t=[];"shadow"===e.pool?t.push("Shadow Achievement","#9700cf"):t.push("Achievement",0),t.push("Locked",0);let o=0;(Game.Has("Neuromancy")||Game.sesame&&"debug"===e.pool)&&(o=1),o&&0===e.won?t.push("Click to win!","#00c462"):o&&e.won>0&&t.push("Click to lose!","#00c462");let{icon:n}=e;e.iconFunction&&(n=e.iconFunction());let{desc:a}=e;e.descFunc&&(a=e.descFunc("stats"));let i="";for(let e=0;e[${t[e]}]`);return i=i.substring(1),`
\n
\n
${e.name}
\n ${i}
${a}
\n ${Game.sesame?`
Id : ${e.id} | Order : ${Math.floor(e.order)}${e.tier?` | Tier : ${e.tier}`:""}
`:""}`}(Game.AchievementsById[t])),"top"),Game.tooltip.wobble())}}}))}()}const Zn={Favourite:"Favourite Settings",Calculation:"Calculation",Notation:"Notation",Colours:"Colours and colour coding",BarsDisplay:"Infobars and visual settings",Tooltip:"Tooltips",Statistics:"Statistics",Notification:"Notifications",Miscellaneous:"Miscellaneous"},ea={NotificationGeneral:"General Notifications",NotificationGC:"Golden Cookie",NotificationFC:"Fortune Cookie",NotificationSea:"Season Special",NotificationGard:"Garden Tick",NotificationMagi:"Full Magic Bar",NotificationWrink:"Wrinkler",NotificationWrinkMax:"Maximum Wrinklers"};function ta(e,t){const o=document.createElement("div");o.className="title",o.style.opacity="0.7",o.style.fontSize="17px",o.appendChild(document.createTextNode(`${t} `));const n=document.createElement("span");return n.style.cursor="pointer",n.style.display="inline-block",n.style.height="14px",n.style.width="14px",n.style.borderRadius="7px",n.style.textAlign="center",n.style.backgroundColor="#C0C0C0",n.style.color="black",n.style.fontSize="13px",n.style.verticalAlign="middle",n.textContent=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[e]?"-":"+",n.onclick=function(){Qn(e),Game.UpdateMenu()},o.appendChild(n),o}function oa(){let e="";for(let t=0;t{aa(2,t,!0)}),1e3/Game.fps)):setTimeout((()=>{aa(0,t,!0)}),1e3/Game.fps)):2===e?(l("CMFlashScreen").style.opacity="1",setTimeout((()=>{aa(1,t,!0)}),1e3/Game.fps)):0===e&&(l("CMFlashScreen").style.display="none")}function ia(e,t,o,n){if((1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[t]||n)&&!1===na){const t=new Audio(e);Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.GeneralSound?t.volume=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[o]/100*(Game.volume/100):t.volume=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[o]/100,t.play()}}function ra(e){const o=document.createElement("div");if(o.className="listing",1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.FavouriteSettings&&o.appendChild(function(e){const o=document.createElement("a");return bo.includes(e)?(o.innerText="★",o.style.color="yellow"):o.innerText="☆",o.className="option",o.onclick=function(){!function(e){bo.includes(e)?bo=bo.filter((t=>t!==e)):bo.push(e)}(e),t(),Game.UpdateMenu()},o.onmouseover=function(){Game.tooltip.draw(this,escape(Zt.FavouriteSettingPlaceholder.innerHTML))},o.onmouseout=function(){Game.tooltip.hide()},o.appendChild(document.createTextNode(" ")),o}(e)),"bool"===zn[e].type){const n=document.createElement("a");zn[e].toggle&&0===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e]?n.className="option off":n.className="option",n.id=Vn+e,n.onclick=function(){!function(e){Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e]+=1,Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e]===zn[e].label.length?(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e]=0,zn[e].toggle&&(l(Vn+e).className="option off")):l(Vn+e).className="option",void 0!==zn[e].func&&zn[e].func(),t()}(e),Game.UpdateMenu()},n.textContent=zn[e].label[Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e]],o.appendChild(n);const a=document.createElement("label");return a.textContent=zn[e].desc,a.style.lineHeight="1.6",o.appendChild(a),o}if("vol"===zn[e].type){const t=document.createElement("div");t.className="sliderBox";const n=document.createElement("div");n.style.float="left",n.innerHTML=zn[e].desc,t.appendChild(n);const a=document.createElement("div");a.id=`slider${e}right`,a.style.float="right",a.innerHTML=`${Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e]}%`,t.appendChild(a);const i=document.createElement("input");i.className="slider",i.id=`slider${e}`,i.style.clear="both",i.type="range",i.min="0",i.max="100",i.step="1",i.value=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e],i.oninput=function(){_n(e),Game.UpdateMenu()},i.onchange=function(){_n(e),Game.UpdateMenu()},t.appendChild(i),o.appendChild(t);const r=document.createElement("a");return r.className="option",r.onclick=function(){ia(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e.replace("Volume","SoundURL")],e.replace("Volume","Sound"),e,!0)},r.textContent="Test sound",o.appendChild(r),o}if("url"===zn[e].type){const n=document.createElement("span");n.className="option",n.textContent=`${zn[e].label} `,n.style.lineHeight="1.6",o.appendChild(n);const a=document.createElement("input");a.id=Vn+e,a.className="option",a.type="text",a.readOnly=!0,a.setAttribute("value",Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e]),a.style.width="300px",o.appendChild(a),o.appendChild(document.createTextNode(" "));const i=document.createElement("input");i.id=`${Vn+e}Prompt`,i.className="option",i.type="text",i.setAttribute("value",Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e]);const r=document.createElement("a");r.className="option",r.onclick=function(){!function(e,t){Game.promptWrapL.className="framed";const o=e;Game.promptL.innerHTML=`${o}
`,Object.keys(t).forEach((e=>{const o=document.createElement("a");o.id=`promptOption${e}`,o.className="option",o.onclick=function(){PlaySound("snd/tick.mp3"),t[e][1]()},o.textContent=t[e][0],Game.promptL.children[1].appendChild(o)})),Game.promptAnchorL.style.display="block",Game.darkenL.style.display="block",Game.promptL.focus(),Game.promptOn=1,Game.UpdatePrompt()}(i.outerHTML,[["Save",function(){Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e]=l(`CMConfig${e}Prompt`).value,t(),Game.ClosePrompt(),Game.UpdateMenu()}],["Cancel",function(){Game.ClosePrompt()}]])},r.textContent="Edit",o.appendChild(r);const s=document.createElement("label");return s.textContent=zn[e].desc,s.style.lineHeight="1.6",o.appendChild(s),o}if("colour"===zn[e].type){const n=document.createElement("span");n.className="option";const a=document.createElement("input");a.id=e,a.style.width="65px",a.setAttribute("value",Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e]),n.appendChild(a),new On(a,{hash:!0,position:"right",onInput:function(){Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[this.targetElement.id]=this.toHEXString(),oa(),t(),Game.UpdateMenu()}});const i=document.createElement("label");if(i.textContent=zn[e].desc,i.style.lineHeight="1.6",n.appendChild(i),e.includes("Flash")){const t=document.createElement("a");t.className="option",t.onclick=function(){aa(3,e.replace("Colour",""),!0)},t.textContent="Test flash",n.appendChild(t)}return o.appendChild(n),Dn().init(),o}if("numscale"===zn[e].type){const n=document.createElement("span");n.className="option",n.textContent=`${zn[e].label} `,n.style.lineHeight="1.6",o.appendChild(n);const a=document.createElement("input");a.id=Vn+e,a.className="option",a.type="number",a.value=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e],a.min=zn[e].min,a.max=zn[e].max,a.oninput=function(){Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e]=this.value,t(),jn(),Game.UpdateMenu()},o.appendChild(a),o.appendChild(document.createTextNode(" "));const i=document.createElement("label");return i.textContent=zn[e].desc,i.style.lineHeight="1.6",o.appendChild(i),o}return o}function sa(e){if(1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TimerBar&&0===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TimerBarPos){const t=parseInt(l("CMTimerBar").style.height,10);Game.mouseY-=t,e(),Game.mouseY+=t}else e()}function la(){j.Beautify=Beautify,Beautify=$,j.CalculateGains=Game.CalculateGains,Game.CalculateGains=function(){j.CalculateGains(),ye=1,H=Date.now(),U=Date.now()},j.tooltip={},j.tooltip.draw=Game.tooltip.draw,j.tooltip.drawMod=new Function(`return ${Game.tooltip.draw.toString().split("this").join("Game.tooltip")}`)(),Game.tooltip.draw=function(e,t,o){j.tooltip.drawMod(e,t,o)},j.tooltip.update=Game.tooltip.update,j.tooltip.updateMod=new Function(`return ${Game.tooltip.update.toString().split("this.").join("Game.tooltip.")}`)(),Game.tooltip.update=function(){j.tooltip.updateMod(),function(){if("store"===Game.tooltip.origin){let e=0;1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.ToolWarnLucky&&1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.ToolWarnPos&&null!==l("CMDispTooltipWarningParent")&&(e=l("CMDispTooltipWarningParent").clientHeight-4),Game.tooltip.tta.style.top=`${Math.min(parseInt(Game.tooltip.tta.style.top,10),l("game").clientHeight+l("topBar").clientHeight-Game.tooltip.tt.clientHeight-e-46)}px`}}()},j.UpdateWrinklers=Game.UpdateWrinklers,Game.UpdateWrinklers=function(){sa(j.UpdateWrinklers)},j.UpdateSpecial=Game.UpdateSpecial,Game.UpdateSpecial=function(){sa(j.UpdateSpecial)},l("bigCookie").removeEventListener("click",Game.ClickCookie,!1),l("bigCookie").addEventListener("click",(()=>{sa(Game.ClickCookie)}),!1),j.RebuildUpgrades=Game.RebuildUpgrades,Game.RebuildUpgrades=function(){j.RebuildUpgrades(),W=[],Object.keys(Game.UpgradesInStore).forEach((e=>{null!==l(`upgrade${e}`).onmouseover&&(W[e]=l(`upgrade${e}`).onmouseover,l(`upgrade${e}`).onmouseover=function(){Game.mouseDown||(Game.setOnCrate(this),Game.tooltip.dynamic=1,Game.tooltip.draw(this,(()=>Sn("u",`${e}`)),"store"),Game.tooltip.wobble())})})),Game.CalculateGains()},j.ClickProduct=Game.ClickProduct,Game.ClickProduct=function(e){(!Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.BulkBuyBlock||Game.ObjectsById[e].bulkPrice-1;--e)if(Game.ObjectsById[e].amount>0){const o=Ft[Game.ObjectsById[e].name].name;Ft[o].amount-=1,ce-=1,t=Ft[o].basePrice*Game.priceIncrease**Math.max(0,Ft[o].amount-1-Ft[o].free),t=Game.modifyBuildingPrice(Ft[o],t),t=Math.ceil(t);break}const o=pe;return _o(),Zo(),o!==pe&&_o(),[Ge-Game.cookiesPs,t]}(e),n=xo(o/(t+Game.cookiesPs));let a;a=0===Game.cookiesPs?$(1/0):$(t/Game.cookiesPs*100),l("dragonAuraInfo").style.minHeight="60px",l("dragonAuraInfo").style.margin="8px",l("dragonAuraInfo").appendChild(document.createElement("div")).className="line";const i=document.createElement("div");i.style.minWidth="200px",i.style.textAlign="center",i.textContent=`Picking this aura will change CPS by ${$(t)} (${a}% of current CPS).`,l("dragonAuraInfo").appendChild(i);const r=document.createElement("div");r.style.minWidth="200px",r.style.textAlign="center",r.textContent=`It will take ${n} to recover the cost.`,l("dragonAuraInfo").appendChild(r)}}(e)},j.ToggleSpecialMenu=Game.ToggleSpecialMenu,Game.ToggleSpecialMenu=function(e){j.ToggleSpecialMenu(e),function(){if(null!==(l("specialPopup").className.match(/onScreen/)&&l("specialPopup").children[0].style.background.match(/dragon/)))for(let e=0;e${Be}`,"this"),Game.tooltip.wobble()},l("specialPopup").children[e].onmouseout=function(){Game.tooltip.shouldHide=1})}()},j.UpdateMenu=Game.UpdateMenu,Game.UpdateMenu=function(){void 0!==Dn().picker&&void 0!==Dn().picker.owner||(j.UpdateMenu(),function(){const e=document.createElement("div");e.className="title","prefs"===Game.onMenu?(e.textContent="Cookie Monster Settings",function(e){const t=document.createDocumentFragment();t.appendChild(e),Object.keys(Zn).forEach((e=>{if("Favourite"===e){if(0!==bo.length&&Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.FavouriteSettings>0&&(t.appendChild(ta(e,Zn[e])),Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[e]))for(let e=0;e{const o=ta(e,ea[e]);o.style.fontSize="15px",o.style.opacity="0.5",t.appendChild(o),Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[e]&&Object.keys(zn).forEach((o=>{zn[o].group===e&&t.appendChild(ra(o))}))})):Object.keys(zn).forEach((o=>{zn[o].group===e&&t.appendChild(ra(o))})))})),l("menu").childNodes[2].insertBefore(t,l("menu").childNodes[2].childNodes[l("menu").childNodes[2].childNodes.length-1])}(e)):"stats"===Game.onMenu&&Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.Stats&&(e.textContent="Cookie Monster Statistics",Jn(e))}())},j.sayTime=Game.sayTime,ao=function(e,t){return Number.isNaN(e)||e<=0?j.sayTime(e,t):xo(e/Game.fps,1)},j.Logic=Game.Logic,Game.Logic=function(){j.Logic();let e="Cookie Clicker";"fools"===Game.season&&(e="Cookie Baker"),yo=`${Game.OnAscend?"Ascending! ":""}${$(Game.cookies)} ${1===Game.cookies?"cookie":"cookies"} - ${e}`,function(){if(Game.OnAscend||0===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.Title)document.title=yo;else if(1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.Title){let e,t,o,n=!1,a=!1;e=bt?bt.wrath?`[W${Math.ceil(bt.life/Game.fps)}]`:`[G${Math.ceil(bt.life/Game.fps)}]`:Game.Has("Golden switch [off]")?"[GS]":`[${Number(l("CMTimerBarGCMinBar").textContent)<0?"!":""}${Math.ceil((Game.shimmerTypes.golden.maxTime-Game.shimmerTypes.golden.time)/Game.fps)}]`,B&&(n=!0,t="[F]"),"christmas"===Game.season&&(a=!0,o=S?`[R${Math.ceil(Gt.life/Game.fps)}]`:`[${Number(l("CMTimerBarRenMinBar").textContent)<0?"!":""}${Math.ceil((Game.shimmerTypes.reindeer.maxTime-Game.shimmerTypes.reindeer.time)/Game.fps)}]`);let i=yo;"["===i.charAt(0)&&(i=i.substring(i.lastIndexOf("]")+1)),document.title=`${e+(n?t:"")+(a?o:"")} ${i}`}else if(2===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.Title){let e="",t=!1;bt&&(t=!0,bt.wrath?e+=`[W${Math.ceil(bt.life/Game.fps)}]`:e+=`[G${Math.ceil(bt.life/Game.fps)}]`),B&&(t=!0,e+="[F]"),"christmas"===Game.season&&S&&(e+=`[R${Math.ceil(Gt.life/Game.fps)}]`,t=!0),t&&(e+=" - ");let o="Cookie Clicker";"fools"===Game.season&&(o="Cookie Baker"),e+=o,document.title=e}}(),function(){const e=Math.max(0,Game.HowManyCookiesReset(Math.floor(Game.HowMuchPrestige(Game.cookiesReset+Game.cookiesEarned))+1)-(Game.cookiesEarned+Game.cookiesReset)),t=Game.sayTime((Date.now()-Game.startDate)/1e3*Game.fps,-1);let o="";o+=`You've been on this run for ${""===t?"not very long":t}.
`,o+='
',Game.prestige>0&&(o+=`Your prestige level is currently ${$(Game.prestige)}.
(CpS +${$(Game.prestige)}%)`,o+='
'),o+=re<1?"Ascending now would grant you no prestige.":re<2?"Ascending now would grant you
1 prestige level (+1% CpS)
and 1 heavenly chip to spend.":`Ascending now would grant you
${$(re)} prestige levels (+${$(re)}% CpS)
and ${$(re)} heavenly chips to spend.`,o+='
',o+=`You need ${$(e)} more cookies for the next level.
`,o+=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TooltipAscendButton?`
It takes ${wt} to reach the next level and you were making ${$(Ie,2)} chips on average in the last 5 seconds.
`:"",l("ascendTooltip").innerHTML=o}()}}function ca(){const e=h("cookieMonsterMod","Cookie Monster","infoMenu");return Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers.infoMenu&&(e.appendChild(u('Cookie Monster\n offers a wide range of tools and statistics to enhance your game experience.\n It is not a cheat interface – although it does offer helpers for golden cookies and such, everything can be toggled off at will to only leave how much information you want.
\n Progess on new updates and all previous release notes can be found on the GitHub page linked above!
\n Please also report any bugs you may find over there!
\n ')),e.appendChild(u('This update implements the following functions:
\n- HOTFIX: Fixed the possibility of clicking Golden Cookies multiple times with autoclickers
\n- For developers: we now expose some data calculated by Cookie Monster to the global scope. You can access it through the CookieMonsterData object
\n- The column with the most optimal building now has a green coloured indicator whenever colour coding is turned on
\n- The current season in the seasons statistics section is now displayed with green text for easier identification
\n- New option to show a timer bar that counts down till next autosave
\n- New option to sort buildings based on the "cost till next achievement"
\n- Added extra information about achievements in statistics page
\n
\nThis update fixes the following bugs:
\n- Fixed a bug where ignoring certain buildings in rare cases did not create a "most optimal building"
\n- Fixed some issues related to "left till achievement"
\n- Fixed some cases where upgrades and buildings were not correctly sorted
\n- Fixed the tooltip of "Pop all normal wrinklers" displaying an incorrect reward when Shiny\'s are present
\n'))),e}function da(){window.CookieMonsterData={},Game.mods.cookieMonsterFramework.listeners.infoMenu.push(ca),En(),bn(),xn(),M=Object.keys(Game.mods).length,ve=document.createElement("style"),ve.type="text/css",ve.id="CMCSS",document.head.appendChild(ve),function(){const e=document.createElement("div");e.id="CMBotBar",e.style.height="69px",e.style.width="100%",e.style.position="absolute",e.style.display="none",e.style.backgroundColor="#262224",e.style.backgroundImage="linear-gradient(to bottom, #4d4548, #000000)",e.style.borderTop="1px solid black",e.style.overflow="auto",e.style.textShadow="-1px 0 black, 0 1px black, 1px 0 black, 0 -1px black";const t=e.appendChild(document.createElement("table"));t.style.width="100%",t.style.textAlign="center",t.style.whiteSpace="nowrap";const o=t.appendChild(document.createElement("tbody")),n=function(e,t){const o=document.createElement("td");return o.style.textAlign="right",o.className=Ut+t,o.textContent=e,o},a=o.appendChild(document.createElement("tr"));a.style.fontWeight="bold",a.appendChild(n("CM 2.031.9",zt)),o.appendChild(document.createElement("tr")).appendChild(n("Bonus Income",Rt)),o.appendChild(document.createElement("tr")).appendChild(n("Payback Period",Rt)),o.appendChild(document.createElement("tr")).appendChild(n("Time Left",Rt)),l("wrapper").appendChild(e),Object.keys(Game.Objects).forEach((e=>{Fo(e)}))}(),function(){const e=document.createElement("div");e.id="CMTimerBar",e.style.position="absolute",e.style.display="none",e.style.height="0px",e.style.fontSize="10px",e.style.fontWeight="bold",e.style.backgroundColor="black";const t=Eo("CMTimerBarAutosave","Autosave",[{id:"CMTimerBarAutosaveBar",color:Qt}]);e.appendChild(t);const o=Eo("CMTimerBarGC","Next Cookie",[{id:"CMTimerBarGCMinBar",color:Xt},{id:"CMTimerBarGCBar",color:Qt}]);e.appendChild(o);const n=Eo("CMTimerBarRen","Next Reindeer",[{id:"CMTimerBarRenMinBar",color:Xt},{id:"CMTimerBarRenBar",color:Vt}]);e.appendChild(n);const a=document.createElement("div");a.id="CMTimerBarBuffTimers",e.appendChild(a),l("wrapper").appendChild(e)}(),function(){const e=document.createElement("div");e.id="CMUpgradeBar",e.style.width="100%",e.style.backgroundColor="black",e.style.textAlign="center",e.style.fontWeight="bold",e.style.display="none",e.style.zIndex="21",e.onmouseout=function(){Game.tooltip.hide()};const t=document.createElement("div");t.appendChild(function(){const e=document.createElement("div");e.style.minWidth="330px",e.style.marginBottom="4px";const t=document.createElement("div");t.className="name",t.style.marginBottom="4px",t.textContent="Legend",e.appendChild(t);const o=function(e,t){const o=document.createElement("div");o.style.verticalAlign="middle";const n=document.createElement("span");return n.className=$t+e,n.style.display="inline-block",n.style.height="10px",n.style.width="10px",n.style.marginRight="4px",o.appendChild(n),o.appendChild(document.createTextNode(t)),o};return e.appendChild(o(Rt,"Better than the best PP of a building option")),e.appendChild(o(It,"Same as the best PP building option")),e.appendChild(o(zt,"Within the top 10 of PP for buildings")),e.appendChild(o(Vt,"Within the top 20 of PP for buildings")),e.appendChild(o(_t,"Within the top 30 of PP for buildings")),e.appendChild(o(Qt,"Outside of the top 30 of PP for buildings")),e.appendChild(o(Xt,"Negative or infinity PP")),e}()),e.onmouseover=function(){Game.tooltip.draw(this,escape(t.innerHTML),"store")};const o=function(e,t){const o=document.createElement("span");return o.id=e,o.className=Ut+t,o.style.width="14.28571428571429%",o.style.display="inline-block",o.textContent="0",o};e.appendChild(o("CMUpgradeBarBlue",Rt)),e.appendChild(o("CMUpgradeBarGreen",It)),e.appendChild(o("CMUpgradeBarYellow",zt)),e.appendChild(o("CMUpgradeBarOrange",Vt)),e.appendChild(o("CMUpgradeBarRed",_t)),e.appendChild(o("CMUpgradeBarPurple",Qt)),e.appendChild(o("CMUpgradeBarGray",Xt)),l("upgrades").parentNode.insertBefore(e,l("upgrades").parentNode.childNodes[3])}(),function(){const e=document.createElement("div");e.id="CMFlashScreen",e.style.width="100%",e.style.height="100%",e.style.backgroundColor="white",e.style.display="none",e.style.zIndex="9999999999",e.style.position="absolute",l("wrapper").appendChild(e)}(),function(){const e=document.createElement("div");e.id="CMSectionHidButtons",e.style.textAlign="center";const t=document.createElement("a");t.className="option",t.onclick=function(){"flex"===l("upgrades").style.display?(l("upgrades").style.display="none",l("toggleUpgrades").style.display="none",l("techUpgrades").style.display="none",l("vaultUpgrades").style.display="none"):(l("upgrades").style.display="flex",0!==l("toggleUpgrades").children.length&&(l("toggleUpgrades").style.display="block"),0!==l("techUpgrades").children.length&&(l("techUpgrades").style.display="block"),0!==l("vaultUpgrades").children.length&&(l("vaultUpgrades").style.display="block"))},t.textContent="Hide/Show Upgrades",e.appendChild(t);const o=document.createElement("a");o.className="option",o.onclick=function(){"grid"===l("products").style.display?l("products").style.display="none":l("products").style.display="grid"},o.textContent="Hide/Show Buildings",e.appendChild(o),l("store").insertBefore(e,l("store").childNodes[2])}(),function(){const e=document.createElement("link");e.id="CMFavicon",e.rel="shortcut icon",e.href="https://orteil.dashnet.org/cookieclicker/favicon.ico",document.getElementsByTagName("head")[0].appendChild(e)}(),Object.keys(Jt).forEach((e=>{!function(e,t,o){const n=document.createElement("div");n.id=e;const a=document.createElement("div");a.style.minWidth=o,a.style.marginBottom="4px";const i=document.createElement("div");i.style.textAlign="left",i.textContent=t,a.appendChild(i),n.appendChild(a),Zt[e]=n}(Jt[e][0],Jt[e][1],Jt[e][2])})),function(){const e=document.createElement("a");e.id="PopAllNormalWrinklerButton",e.textContent="Pop All Normal",e.className="option",e.onclick=function(){Tn()},e.onmouseout=function(){Game.tooltip.shouldHide=1},e.onmouseover=function(){Game.tooltip.dynamic=1,Game.tooltip.draw(this,(()=>Sn("wb","PopAllNormal")),"this"),Game.tooltip.wobble()},l("sectionLeftExtra").children[0].append(e);const t=document.createElement("a");t.id="PopFattestWrinklerButton",t.textContent="Pop Single Fattest",t.className="option",t.onclick=function(){null!==Ze[1]&&(Game.wrinklers[Ze[1]].hp=0)},t.onmouseout=function(){Game.tooltip.shouldHide=1},t.onmouseover=function(){Game.tooltip.dynamic=1,Game.tooltip.draw(this,(()=>Sn("wb","PopFattest")),"this"),Game.tooltip.wobble()},l("sectionLeftExtra").children[0].append(t)}(),l("products").style.display="grid",l("storeBulk").style.gridRow="1/1",l("upgrades").style.display="flex",l("upgrades").style["flex-wrap"]="wrap",Object.keys(l("rows").children).forEach((e=>{const t=l("rows").children[e].children[1],o=document.createElement("div");o.id=`productLock${Number(e)+1}`,o.className="productButton",o.innerHTML="Unlocked",o.onclick=function(){!function(e){"Unlocked"===l(`productLock${e}`).innerHTML?(l(`productLock${e}`).innerHTML="Locked",l(`row${e}`).children[3].style.pointerEvents="none"):(l(`productLock${e}`).innerHTML="Unlocked",l(`row${e}`).children[3].style.pointerEvents="auto")}(Number(e)+1)},t.appendChild(o)})),Object.keys(Game.Objects).forEach((e=>{const t=Game.Objects[e];null!==l(`product${t.id}`).onmouseover&&(A[e]=l(`product${t.id}`).onmouseover,l(`product${t.id}`).onmouseover=function(){Game.tooltip.dynamic=1,Game.tooltip.draw(this,(()=>Sn("b",`${e}`)),"store"),Game.tooltip.wobble()})})),Game.canLumps()&&(y=l("lumps").onmouseover,l("lumps").onmouseover=function(){Game.tooltip.dynamic=1,Game.tooltip.draw(this,(()=>Sn("s","Lump")),"this"),Game.tooltip.wobble()}),T=Game.LoadMinigames,Game.LoadMinigames=function(){T(),Game.Objects.Farm.minigameLoaded&&(l("gardenTool-1").onmouseover=function(){Game.tooltip.dynamic=1,Game.tooltip.draw(this,(()=>Sn("ha","HarvestAllButton")),"this"),Game.tooltip.wobble()},Array.from(l("gardenPlot").children).forEach((e=>{const t=e.id.slice(-3);e.onmouseover=function(){Game.tooltip.dynamic=1,Game.tooltip.draw(this,(()=>Sn("p",[`${t[0]}`,`${t[2]}`])),"this"),Game.tooltip.wobble()}}))),Fn(),function(){if(Game.Objects.Temple.minigameLoaded){for(let e=0;e<11;e+=1)l(`templeGod${e}`).onmouseover=function(){Game.tooltip.dynamic=1,Game.tooltip.draw(this,(()=>Sn("pag",e)),"this"),Game.tooltip.wobble()};for(let e=0;e<3;e+=1)l(`templeSlot${e}`).onmouseover=function(){Game.tooltip.dynamic=1,Game.tooltip.draw(this,(()=>Sn("pas",[e,Game.Objects.Temple.minigame.slot[e]])),"this"),Game.tooltip.wobble()}}}(),Nn()},Game.LoadMinigames(),l("backgroundLeftCanvas").onmouseover=function(){to=1},l("backgroundLeftCanvas").onmouseout=function(){to=0,Game.tooltip.hide(),Object.keys(Game.wrinklers).forEach((e=>{no[e]=0}))},la(),Nn(),Game.CalculateGains(),eo=Game.OnAscend,Game.prefs.popups?Game.Popup("Cookie Monster version 2.031.9 loaded!"):Game.Notify("Cookie Monster version 2.031.9 loaded!","","",1,1),Game.Win("Third-party")}function ma(e,t){if(!Game.Objects.Temple.minigameLoaded)return 0;Uo();const{minigame:o}=Game.Objects.Temple,n=o.godsById[e].slot;"0"===n?ke=o.slot[t]:"1"===n?Ce=o.slot[t]:"2"===n&&(Me=o.slot[t]),0===t?ke=e:1===t?Ce=e:2===t&&(Me=e);const a=pe;return _o(),Zo(),a!==pe&&_o(),Ge-Game.cookiesPs}function pa(e,t,o){1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[e]&&"hidden"===document.visibilityState&&!1===na&&new Notification(t,{body:o,badge:"https://orteil.dashnet.org/cookieclicker/favicon.ico"})}function ua(){if(ko!==Game.OnAscend&&(ko=Game.OnAscend,Game.OnAscend?(l("game").style.bottom="0px",1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.BotBar&&(l("CMBotBar").style.display="none"),1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.TimerBar&&(l("CMTimerBar").style.display="none")):(Wn(),Do()),No()),!Game.OnAscend&&0===Game.AscendTimer){M!==Object.keys(Game.mods).length&&(En(),xn(),M=Object.keys(Game.mods).length),ye&&(wn(!0),gn(),Game.Has("Golden switch [off]")?(Uo(),Pt["Golden switch [off]"].bought=0,_o(),He=Ge):He=Game.cookiesPs,Gn(),bn(),Mn(),kn(),An(),function(){for(let e=0;e<11;e+=1)for(let t=0;t<3;t+=1)Et[e][t]=ma(e,t)}(),yn(),function(){let e=0;if(Game.Objects.Bank.minigameLoaded){const t=Game.Objects.Bank.minigame.goods;let o=0;Object.keys(t).forEach((e=>{const n=t[e];o+=n.stock*n.val})),e+=o*Game.cookiesPsRawHighest}e+=function(){let e=0;Uo();let t=2;5!==ge&&18!==ge||(t-=1),5!==fe&&18!==fe||(t-=1),ge=5,fe=18;for(let e=0;e{Ft[t].amount>0&&(e=t)})),Ft[e].amount-=1,ce-=1}return Object.keys(Ft).forEach((t=>{const o=Ft[t];e+=Ht(Game.Objects[o.name],Game.Objects[t].basePrice,o.amount,Game.Objects[t].free,o.amount)})),e}(),Bt=e}(),ye=0);const e=Game.auraMult("Fierce Hoarder")>0;!le&&e?(le=!0,se=1):le&&!e&&(le=!1,se=1),se&&(hn(),se=0),function(){vn(),mn(),wn(!1),function(){et=0;let e=0;Object.keys(Game.wrinklers).forEach((t=>{2===Game.wrinklers[t].phase&&(e+=1)}));let t=1;if(Ft.Temple.minigameLoaded){const e=Game.hasGod("scorn");1===e?t*=1.15:2===e?t*=1.1:3===e&&(t*=1.05)}tt=e,et=e*(.05*e*1.1)*(.05*Game.Has("Sacrilegious corruption")+1)*(.05*Game.Has("Wrinklerspawn")+1)*t}(),ln(),Cn();const e=Game.HowManyCookiesReset(Math.floor(Game.HowMuchPrestige(Game.cookiesReset+Game.cookiesEarned))+1)-(Game.cookiesEarned+Game.cookiesReset);wt=xo(e/So())}(),B!==(Game.TickerEffect&&"fortune"===Game.TickerEffect.type)&&(B=Game.TickerEffect&&"fortune"===Game.TickerEffect.type,B&&(aa(3,"FortuneFlash",!1),ia(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.FortuneSoundURL,"FortuneSound","FortuneVolume",!1),pa("FortuneNotification","Fortune Cookie found","A Fortune Cookie has appeared on the Ticker."))),S!==Game.shimmerTypes.reindeer.spawned&&(S=Game.shimmerTypes.reindeer.spawned,Object.keys(Game.shimmers).forEach((e=>{Game.shimmers[e].spawnLead&&"reindeer"===Game.shimmers[e].type&&(Gt=Game.shimmers[e])})),aa(3,"SeaFlash",!1),ia(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.SeaSoundURL,"SeaSound","SeaVolume",!1),pa("SeaNotification","Reindeer sighted!","A Reindeer has spawned. Click it now!")),Game.Objects.Farm.minigameLoaded&&E!==Game.Objects.Farm.minigame.nextStep&&(0!==E&&E0){let e=0;Object.keys(Game.wrinklers).forEach((t=>{2===Game.wrinklers[t].phase&&(e+=1)})),e>D?(D=e,e===Game.getWrinklersMax()&&Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.WrinklerMaxFlash?aa(3,"WrinklerMaxFlash",!1):aa(3,"WrinklerFlash",!1),e===Game.getWrinklersMax()&&Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.WrinklerMaxSound?ia(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.WrinklerMaxSoundURL,"WrinklerMaxSound","WrinklerMaxVolume",!1):ia(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.WrinklerSoundURL,"WrinklerSound","WrinklerVolume",!1),e===Game.getWrinklersMax()&&Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.WrinklerMaxNotification?pa("WrinklerMaxNotification","Maximum Wrinklers Reached","You have reached your maximum ammount of wrinklers"):pa("WrinklerNotification","A Wrinkler appeared","A new wrinkler has appeared")):D=e}}()}O=0,St={},Object.keys(Game.shimmers).forEach((e=>{St[Game.shimmers[e].id]=Game.shimmers[e],Game.shimmers[e].spawnLead&&"golden"===Game.shimmers[e].type&&(bt=Game.shimmers[e],O+=1)})),Object.keys(Mo).forEach((e=>{void 0===St[e]&&(Mo[e].parentNode.removeChild(Mo[e]),delete Mo[e])})),F!==Game.shimmerTypes.golden.n?(F=Game.shimmerTypes.golden.n,F&&(P{void 0===Mo[Game.shimmers[e].id]&&function(e){const t=document.createElement("div");t.id=`GCTimer${e.id}`,t.style.width="96px",t.style.height="96px",t.style.position="absolute",t.style.zIndex="10000000001",t.style.textAlign="center",t.style.lineHeight="96px",t.style.fontFamily='"Kavoon", Georgia, serif',t.style.fontSize="35px",t.style.cursor="pointer",t.style.display="block",t.style.pointerEvents="none",0===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.GCTimer&&(t.style.display="none"),t.style.left=e.l.style.left,t.style.top=e.l.style.top,t.onclick=function(){e.pop()},t.onmouseover=function(){e.l.style.filter="brightness(125%) drop-shadow(0px 0px 3px rgba(255,255,255,1))",e.l.style.webkitFilter="brightness(125%) drop-shadow(0px 0px 3px rgba(255,255,255,1))"},t.onmouseout=function(){e.l.style.filter="",e.l.style.webkitFilter=""},Mo[e.id]=t,l("shimmers").appendChild(t)}(Game.shimmers[e])}))),Bn(),P=O,0===O&&(bt=0)):1===Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.GCTimer&&F&&Object.keys(Mo).forEach((e=>{Mo[e].style.opacity=St[e].l.style.opacity,Mo[e].style.transform=St[e].l.style.transform,Mo[e].textContent=Math.ceil(St[e].life/Game.fps)}))}const ha={Favourite:1,Calculation:1,Notation:1,Colours:1,BarsDisplay:1,Tooltip:1,Statistics:1,Notification:1,NotificationGeneral:1,NotificationGC:1,NotificationFC:1,NotificationSea:1,NotificationGard:1,NotificationMagi:1,NotificationWrink:1,NotificationWrinkMax:1,Miscellaneous:1,Lucky:1,Chain:1,Spells:1,Garden:1,Prestige:1,Wrink:1,Sea:1,Achievs:1,Misc:1,infoMenu:1,optionsMenu:1},ga={init:function(){na=!0;let e=!0;m(),p("cookieMonsterMod"),Game.version!==Number("2.031")&&(e=confirm("Cookie Monster version 2.031.9 is meant for Game version 2.031. Loading a different version may cause errors. Do you still want to load Cookie Monster?")),e&&(da(),Game.registerHook("click",rn),Game.registerHook("draw",an),Game.registerHook("logic",ua),na=!1)},load:function(e){En(),i("cookieMonsterMod",e,zn,ha,ua),oa(),"2.031.9"!==Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.version&&(Game.prefs.popups?Game.Popup("A new version of Cookie Monster has been loaded, check out the release notes in the info tab!"):Game.Notify("A new version of Cookie Monster has been loaded, check out the release notes in the info tab!","","",0,1))},save:function(){const e=Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod;return e.version="2.031.9",JSON.stringify(e)}};Game.registerMod("CookieMonster",ga)})()})(); +/******/ (() => { // webpackBootstrap +/******/ var __webpack_modules__ = ({ + +/***/ 877: +/***/ (function(module) { + +/** + * jscolor - JavaScript Color Picker + * + * @link http://jscolor.com + * @license For open source use: GPLv3 + * For commercial use: JSColor Commercial License + * @author Jan Odvarko - East Desire + * + * See usage examples at http://jscolor.com/examples/ + */ + + +(function (global, factory) { + + 'use strict'; + + if ( true && typeof module.exports === 'object') { + // Export jscolor as a module + module.exports = global.document ? + factory (global) : + function (win) { + if (!win.document) { + throw new Error('jscolor needs a window with document'); + } + return factory(win); + } + return; + } + + // Default use (no module export) + factory(global); + +})(typeof window !== 'undefined' ? window : this, function (window) { // BEGIN factory + +// BEGIN jscolor code + + +'use strict'; + + +var jscolor = (function () { // BEGIN jscolor + +var jsc = { + + + initialized : false, + + instances : [], // created instances of jscolor + + readyQueue : [], // functions waiting to be called after init + + + register : function () { + if (typeof window !== 'undefined' && window.document) { + window.document.addEventListener('DOMContentLoaded', jsc.pub.init, false); + } + }, + + + installBySelector : function (selector, rootNode) { + rootNode = rootNode ? jsc.node(rootNode) : window.document; + if (!rootNode) { + throw new Error('Missing root node'); + } + + var elms = rootNode.querySelectorAll(selector); + + // for backward compatibility with DEPRECATED installation/configuration using className + var matchClass = new RegExp('(^|\\s)(' + jsc.pub.lookupClass + ')(\\s*(\\{[^}]*\\})|\\s|$)', 'i'); + + for (var i = 0; i < elms.length; i += 1) { + + if (elms[i].jscolor && elms[i].jscolor instanceof jsc.pub) { + continue; // jscolor already installed on this element + } + + if (elms[i].type !== undefined && elms[i].type.toLowerCase() == 'color' && jsc.isColorAttrSupported) { + continue; // skips inputs of type 'color' if supported by the browser + } + + var dataOpts, m; + + if ( + (dataOpts = jsc.getDataAttr(elms[i], 'jscolor')) !== null || + (elms[i].className && (m = elms[i].className.match(matchClass))) // installation using className (DEPRECATED) + ) { + var targetElm = elms[i]; + + var optsStr = ''; + if (dataOpts !== null) { + optsStr = dataOpts; + + } else if (m) { // installation using className (DEPRECATED) + console.warn('Installation using class name is DEPRECATED. Use data-jscolor="" attribute instead.' + jsc.docsRef); + if (m[4]) { + optsStr = m[4]; + } + } + + var opts = null; + if (optsStr.trim()) { + try { + opts = jsc.parseOptionsStr(optsStr); + } catch (e) { + console.warn(e + '\n' + optsStr); + } + } + + try { + new jsc.pub(targetElm, opts); + } catch (e) { + console.warn(e); + } + } + } + }, + + + parseOptionsStr : function (str) { + var opts = null; + + try { + opts = JSON.parse(str); + + } catch (eParse) { + if (!jsc.pub.looseJSON) { + throw new Error('Could not parse jscolor options as JSON: ' + eParse); + } else { + // loose JSON syntax is enabled -> try to evaluate the options string as JavaScript object + try { + opts = (new Function ('var opts = (' + str + '); return typeof opts === "object" ? opts : {};'))(); + } catch (eEval) { + throw new Error('Could not evaluate jscolor options: ' + eEval); + } + } + } + return opts; + }, + + + getInstances : function () { + var inst = []; + for (var i = 0; i < jsc.instances.length; i += 1) { + // if the targetElement still exists, the instance is considered "alive" + if (jsc.instances[i] && jsc.instances[i].targetElement) { + inst.push(jsc.instances[i]); + } + } + return inst; + }, + + + createEl : function (tagName) { + var el = window.document.createElement(tagName); + jsc.setData(el, 'gui', true); + return el; + }, + + + node : function (nodeOrSelector) { + if (!nodeOrSelector) { + return null; + } + + if (typeof nodeOrSelector === 'string') { + // query selector + var sel = nodeOrSelector; + var el = null; + try { + el = window.document.querySelector(sel); + } catch (e) { + console.warn(e); + return null; + } + if (!el) { + console.warn('No element matches the selector: %s', sel); + } + return el; + } + + if (jsc.isNode(nodeOrSelector)) { + // DOM node + return nodeOrSelector; + } + + console.warn('Invalid node of type %s: %s', typeof nodeOrSelector, nodeOrSelector); + return null; + }, + + + // See https://stackoverflow.com/questions/384286/ + isNode : function (val) { + if (typeof Node === 'object') { + return val instanceof Node; + } + return val && typeof val === 'object' && typeof val.nodeType === 'number' && typeof val.nodeName === 'string'; + }, + + + nodeName : function (node) { + if (node && node.nodeName) { + return node.nodeName.toLowerCase(); + } + return false; + }, + + + removeChildren : function (node) { + while (node.firstChild) { + node.removeChild(node.firstChild); + } + }, + + + isTextInput : function (el) { + return el && jsc.nodeName(el) === 'input' && el.type.toLowerCase() === 'text'; + }, + + + isButton : function (el) { + if (!el) { + return false; + } + var n = jsc.nodeName(el); + return ( + (n === 'button') || + (n === 'input' && ['button', 'submit', 'reset'].indexOf(el.type.toLowerCase()) > -1) + ); + }, + + + isButtonEmpty : function (el) { + switch (jsc.nodeName(el)) { + case 'input': return (!el.value || el.value.trim() === ''); + case 'button': return (el.textContent.trim() === ''); + } + return null; // could not determine element's text + }, + + + // See https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md + isPassiveEventSupported : (function () { + var supported = false; + + try { + var opts = Object.defineProperty({}, 'passive', { + get: function () { supported = true; } + }); + window.addEventListener('testPassive', null, opts); + window.removeEventListener('testPassive', null, opts); + } catch (e) {} + + return supported; + })(), + + + isColorAttrSupported : (function () { + var elm = window.document.createElement('input'); + if (elm.setAttribute) { + elm.setAttribute('type', 'color'); + if (elm.type.toLowerCase() == 'color') { + return true; + } + } + return false; + })(), + + + dataProp : '_data_jscolor', + + + // usage: + // setData(obj, prop, value) + // setData(obj, {prop:value, ...}) + // + setData : function () { + var obj = arguments[0]; + + if (arguments.length === 3) { + // setting a single property + var data = obj.hasOwnProperty(jsc.dataProp) ? obj[jsc.dataProp] : (obj[jsc.dataProp] = {}); + var prop = arguments[1]; + var value = arguments[2]; + + data[prop] = value; + return true; + + } else if (arguments.length === 2 && typeof arguments[1] === 'object') { + // setting multiple properties + var data = obj.hasOwnProperty(jsc.dataProp) ? obj[jsc.dataProp] : (obj[jsc.dataProp] = {}); + var map = arguments[1]; + + for (var prop in map) { + if (map.hasOwnProperty(prop)) { + data[prop] = map[prop]; + } + } + return true; + } + + throw new Error('Invalid arguments'); + }, + + + // usage: + // removeData(obj, prop, [prop...]) + // + removeData : function () { + var obj = arguments[0]; + if (!obj.hasOwnProperty(jsc.dataProp)) { + return true; // data object does not exist + } + for (var i = 1; i < arguments.length; i += 1) { + var prop = arguments[i]; + delete obj[jsc.dataProp][prop]; + } + return true; + }, + + + getData : function (obj, prop, setDefault) { + if (!obj.hasOwnProperty(jsc.dataProp)) { + // data object does not exist + if (setDefault !== undefined) { + obj[jsc.dataProp] = {}; // create data object + } else { + return undefined; // no value to return + } + } + var data = obj[jsc.dataProp]; + + if (!data.hasOwnProperty(prop) && setDefault !== undefined) { + data[prop] = setDefault; + } + return data[prop]; + }, + + + getDataAttr : function (el, name) { + var attrName = 'data-' + name; + var attrValue = el.getAttribute(attrName); + return attrValue; + }, + + + setDataAttr : function (el, name, value) { + var attrName = 'data-' + name; + el.setAttribute(attrName, value); + }, + + + _attachedGroupEvents : {}, + + + attachGroupEvent : function (groupName, el, evnt, func) { + if (!jsc._attachedGroupEvents.hasOwnProperty(groupName)) { + jsc._attachedGroupEvents[groupName] = []; + } + jsc._attachedGroupEvents[groupName].push([el, evnt, func]); + el.addEventListener(evnt, func, false); + }, + + + detachGroupEvents : function (groupName) { + if (jsc._attachedGroupEvents.hasOwnProperty(groupName)) { + for (var i = 0; i < jsc._attachedGroupEvents[groupName].length; i += 1) { + var evt = jsc._attachedGroupEvents[groupName][i]; + evt[0].removeEventListener(evt[1], evt[2], false); + } + delete jsc._attachedGroupEvents[groupName]; + } + }, + + + preventDefault : function (e) { + if (e.preventDefault) { e.preventDefault(); } + e.returnValue = false; + }, + + + captureTarget : function (target) { + // IE + if (target.setCapture) { + jsc._capturedTarget = target; + jsc._capturedTarget.setCapture(); + } + }, + + + releaseTarget : function () { + // IE + if (jsc._capturedTarget) { + jsc._capturedTarget.releaseCapture(); + jsc._capturedTarget = null; + } + }, + + + triggerEvent : function (el, eventName, bubbles, cancelable) { + if (!el) { + return; + } + + var ev = null; + + if (typeof Event === 'function') { + ev = new Event(eventName, { + bubbles: bubbles, + cancelable: cancelable + }); + } else { + // IE + ev = window.document.createEvent('Event'); + ev.initEvent(eventName, bubbles, cancelable); + } + + if (!ev) { + return false; + } + + // so that we know that the event was triggered internally + jsc.setData(ev, 'internal', true); + + el.dispatchEvent(ev); + return true; + }, + + + triggerInputEvent : function (el, eventName, bubbles, cancelable) { + if (!el) { + return; + } + if (jsc.isTextInput(el)) { + jsc.triggerEvent(el, eventName, bubbles, cancelable); + } + }, + + + eventKey : function (ev) { + var keys = { + 9: 'Tab', + 13: 'Enter', + 27: 'Escape', + }; + if (typeof ev.code === 'string') { + return ev.code; + } else if (ev.keyCode !== undefined && keys.hasOwnProperty(ev.keyCode)) { + return keys[ev.keyCode]; + } + return null; + }, + + + strList : function (str) { + if (!str) { + return []; + } + return str.replace(/^\s+|\s+$/g, '').split(/\s+/); + }, + + + // The className parameter (str) can only contain a single class name + hasClass : function (elm, className) { + if (!className) { + return false; + } + if (elm.classList !== undefined) { + return elm.classList.contains(className); + } + // polyfill + return -1 != (' ' + elm.className.replace(/\s+/g, ' ') + ' ').indexOf(' ' + className + ' '); + }, + + + // The className parameter (str) can contain multiple class names separated by whitespace + addClass : function (elm, className) { + var classNames = jsc.strList(className); + + if (elm.classList !== undefined) { + for (var i = 0; i < classNames.length; i += 1) { + elm.classList.add(classNames[i]); + } + return; + } + // polyfill + for (var i = 0; i < classNames.length; i += 1) { + if (!jsc.hasClass(elm, classNames[i])) { + elm.className += (elm.className ? ' ' : '') + classNames[i]; + } + } + }, + + + // The className parameter (str) can contain multiple class names separated by whitespace + removeClass : function (elm, className) { + var classNames = jsc.strList(className); + + if (elm.classList !== undefined) { + for (var i = 0; i < classNames.length; i += 1) { + elm.classList.remove(classNames[i]); + } + return; + } + // polyfill + for (var i = 0; i < classNames.length; i += 1) { + var repl = new RegExp( + '^\\s*' + classNames[i] + '\\s*|' + + '\\s*' + classNames[i] + '\\s*$|' + + '\\s+' + classNames[i] + '(\\s+)', + 'g' + ); + elm.className = elm.className.replace(repl, '$1'); + } + }, + + + getCompStyle : function (elm) { + var compStyle = window.getComputedStyle ? window.getComputedStyle(elm) : elm.currentStyle; + + // Note: In Firefox, getComputedStyle returns null in a hidden iframe, + // that's why we need to check if the returned value is non-empty + if (!compStyle) { + return {}; + } + return compStyle; + }, + + + // Note: + // Setting a property to NULL reverts it to the state before it was first set + // with the 'reversible' flag enabled + // + setStyle : function (elm, styles, important, reversible) { + // using '' for standard priority (IE10 apparently doesn't like value undefined) + var priority = important ? 'important' : ''; + var origStyle = null; + + for (var prop in styles) { + if (styles.hasOwnProperty(prop)) { + var setVal = null; + + if (styles[prop] === null) { + // reverting a property value + + if (!origStyle) { + // get the original style object, but dont't try to create it if it doesn't exist + origStyle = jsc.getData(elm, 'origStyle'); + } + if (origStyle && origStyle.hasOwnProperty(prop)) { + // we have property's original value -> use it + setVal = origStyle[prop]; + } + + } else { + // setting a property value + + if (reversible) { + if (!origStyle) { + // get the original style object and if it doesn't exist, create it + origStyle = jsc.getData(elm, 'origStyle', {}); + } + if (!origStyle.hasOwnProperty(prop)) { + // original property value not yet stored -> store it + origStyle[prop] = elm.style[prop]; + } + } + setVal = styles[prop]; + } + + if (setVal !== null) { + elm.style.setProperty(prop, setVal, priority); + } + } + } + }, + + + hexColor : function (r, g, b) { + return '#' + ( + ('0' + Math.round(r).toString(16)).substr(-2) + + ('0' + Math.round(g).toString(16)).substr(-2) + + ('0' + Math.round(b).toString(16)).substr(-2) + ).toUpperCase(); + }, + + + hexaColor : function (r, g, b, a) { + return '#' + ( + ('0' + Math.round(r).toString(16)).substr(-2) + + ('0' + Math.round(g).toString(16)).substr(-2) + + ('0' + Math.round(b).toString(16)).substr(-2) + + ('0' + Math.round(a * 255).toString(16)).substr(-2) + ).toUpperCase(); + }, + + + rgbColor : function (r, g, b) { + return 'rgb(' + + Math.round(r) + ',' + + Math.round(g) + ',' + + Math.round(b) + + ')'; + }, + + + rgbaColor : function (r, g, b, a) { + return 'rgba(' + + Math.round(r) + ',' + + Math.round(g) + ',' + + Math.round(b) + ',' + + (Math.round((a===undefined || a===null ? 1 : a) * 100) / 100) + + ')'; + }, + + + linearGradient : (function () { + + function getFuncName () { + var stdName = 'linear-gradient'; + var prefixes = ['', '-webkit-', '-moz-', '-o-', '-ms-']; + var helper = window.document.createElement('div'); + + for (var i = 0; i < prefixes.length; i += 1) { + var tryFunc = prefixes[i] + stdName; + var tryVal = tryFunc + '(to right, rgba(0,0,0,0), rgba(0,0,0,0))'; + + helper.style.background = tryVal; + if (helper.style.background) { // CSS background successfully set -> function name is supported + return tryFunc; + } + } + return stdName; // fallback to standard 'linear-gradient' without vendor prefix + } + + var funcName = getFuncName(); + + return function () { + return funcName + '(' + Array.prototype.join.call(arguments, ', ') + ')'; + }; + + })(), + + + setBorderRadius : function (elm, value) { + jsc.setStyle(elm, {'border-radius' : value || '0'}); + }, + + + setBoxShadow : function (elm, value) { + jsc.setStyle(elm, {'box-shadow': value || 'none'}); + }, + + + getElementPos : function (e, relativeToViewport) { + var x=0, y=0; + var rect = e.getBoundingClientRect(); + x = rect.left; + y = rect.top; + if (!relativeToViewport) { + var viewPos = jsc.getViewPos(); + x += viewPos[0]; + y += viewPos[1]; + } + return [x, y]; + }, + + + getElementSize : function (e) { + return [e.offsetWidth, e.offsetHeight]; + }, + + + // get pointer's X/Y coordinates relative to viewport + getAbsPointerPos : function (e) { + var x = 0, y = 0; + if (typeof e.changedTouches !== 'undefined' && e.changedTouches.length) { + // touch devices + x = e.changedTouches[0].clientX; + y = e.changedTouches[0].clientY; + } else if (typeof e.clientX === 'number') { + x = e.clientX; + y = e.clientY; + } + return { x: x, y: y }; + }, + + + // get pointer's X/Y coordinates relative to target element + getRelPointerPos : function (e) { + var target = e.target || e.srcElement; + var targetRect = target.getBoundingClientRect(); + + var x = 0, y = 0; + + var clientX = 0, clientY = 0; + if (typeof e.changedTouches !== 'undefined' && e.changedTouches.length) { + // touch devices + clientX = e.changedTouches[0].clientX; + clientY = e.changedTouches[0].clientY; + } else if (typeof e.clientX === 'number') { + clientX = e.clientX; + clientY = e.clientY; + } + + x = clientX - targetRect.left; + y = clientY - targetRect.top; + return { x: x, y: y }; + }, + + + getViewPos : function () { + var doc = window.document.documentElement; + return [ + (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0), + (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0) + ]; + }, + + + getViewSize : function () { + var doc = window.document.documentElement; + return [ + (window.innerWidth || doc.clientWidth), + (window.innerHeight || doc.clientHeight), + ]; + }, + + + // r: 0-255 + // g: 0-255 + // b: 0-255 + // + // returns: [ 0-360, 0-100, 0-100 ] + // + RGB_HSV : function (r, g, b) { + r /= 255; + g /= 255; + b /= 255; + var n = Math.min(Math.min(r,g),b); + var v = Math.max(Math.max(r,g),b); + var m = v - n; + if (m === 0) { return [ null, 0, 100 * v ]; } + var h = r===n ? 3+(b-g)/m : (g===n ? 5+(r-b)/m : 1+(g-r)/m); + return [ + 60 * (h===6?0:h), + 100 * (m/v), + 100 * v + ]; + }, + + + // h: 0-360 + // s: 0-100 + // v: 0-100 + // + // returns: [ 0-255, 0-255, 0-255 ] + // + HSV_RGB : function (h, s, v) { + var u = 255 * (v / 100); + + if (h === null) { + return [ u, u, u ]; + } + + h /= 60; + s /= 100; + + var i = Math.floor(h); + var f = i%2 ? h-i : 1-(h-i); + var m = u * (1 - s); + var n = u * (1 - s * f); + switch (i) { + case 6: + case 0: return [u,n,m]; + case 1: return [n,u,m]; + case 2: return [m,u,n]; + case 3: return [m,n,u]; + case 4: return [n,m,u]; + case 5: return [u,m,n]; + } + }, + + + parseColorString : function (str) { + var ret = { + rgba: null, + format: null // 'hex' | 'hexa' | 'rgb' | 'rgba' + }; + + var m; + + if (m = str.match(/^\W*([0-9A-F]{3,8})\W*$/i)) { + // HEX notation + + if (m[1].length === 8) { + // 8-char notation (= with alpha) + ret.format = 'hexa'; + ret.rgba = [ + parseInt(m[1].substr(0,2),16), + parseInt(m[1].substr(2,2),16), + parseInt(m[1].substr(4,2),16), + parseInt(m[1].substr(6,2),16) / 255 + ]; + + } else if (m[1].length === 6) { + // 6-char notation + ret.format = 'hex'; + ret.rgba = [ + parseInt(m[1].substr(0,2),16), + parseInt(m[1].substr(2,2),16), + parseInt(m[1].substr(4,2),16), + null + ]; + + } else if (m[1].length === 3) { + // 3-char notation + ret.format = 'hex'; + ret.rgba = [ + parseInt(m[1].charAt(0) + m[1].charAt(0),16), + parseInt(m[1].charAt(1) + m[1].charAt(1),16), + parseInt(m[1].charAt(2) + m[1].charAt(2),16), + null + ]; + + } else { + return false; + } + + return ret; + } + + if (m = str.match(/^\W*rgba?\(([^)]*)\)\W*$/i)) { + // rgb(...) or rgba(...) notation + + var par = m[1].split(','); + var re = /^\s*(\d+|\d*\.\d+|\d+\.\d*)\s*$/; + var mR, mG, mB, mA; + if ( + par.length >= 3 && + (mR = par[0].match(re)) && + (mG = par[1].match(re)) && + (mB = par[2].match(re)) + ) { + ret.format = 'rgb'; + ret.rgba = [ + parseFloat(mR[1]) || 0, + parseFloat(mG[1]) || 0, + parseFloat(mB[1]) || 0, + null + ]; + + if ( + par.length >= 4 && + (mA = par[3].match(re)) + ) { + ret.format = 'rgba'; + ret.rgba[3] = parseFloat(mA[1]) || 0; + } + return ret; + } + } + + return false; + }, + + + parsePaletteValue : function (mixed) { + var vals = []; + + if (typeof mixed === 'string') { // input is a string of space separated color values + // rgb() and rgba() may contain spaces too, so let's find all color values by regex + mixed.replace(/#[0-9A-F]{3}([0-9A-F]{3})?|rgba?\(([^)]*)\)/ig, function (val) { + vals.push(val); + }); + } else if (Array.isArray(mixed)) { // input is an array of color values + vals = mixed; + } + + // convert all values into uniform color format + + var colors = []; + + for (var i = 0; i < vals.length; i++) { + var color = jsc.parseColorString(vals[i]); + if (color) { + colors.push(color); + } + } + + return colors; + }, + + + containsTranparentColor : function (colors) { + for (var i = 0; i < colors.length; i++) { + var a = colors[i].rgba[3]; + if (a !== null && a < 1.0) { + return true; + } + } + return false; + }, + + + isAlphaFormat : function (format) { + switch (format.toLowerCase()) { + case 'hexa': + case 'rgba': + return true; + } + return false; + }, + + + // Canvas scaling for retina displays + // + // adapted from https://www.html5rocks.com/en/tutorials/canvas/hidpi/ + // + scaleCanvasForHighDPR : function (canvas) { + var dpr = window.devicePixelRatio || 1; + canvas.width *= dpr; + canvas.height *= dpr; + var ctx = canvas.getContext('2d'); + ctx.scale(dpr, dpr); + }, + + + genColorPreviewCanvas : function (color, separatorPos, specWidth, scaleForHighDPR) { + + var sepW = Math.round(jsc.pub.previewSeparator.length); + var sqSize = jsc.pub.chessboardSize; + var sqColor1 = jsc.pub.chessboardColor1; + var sqColor2 = jsc.pub.chessboardColor2; + + var cWidth = specWidth ? specWidth : sqSize * 2; + var cHeight = sqSize * 2; + + var canvas = jsc.createEl('canvas'); + var ctx = canvas.getContext('2d'); + + canvas.width = cWidth; + canvas.height = cHeight; + if (scaleForHighDPR) { + jsc.scaleCanvasForHighDPR(canvas); + } + + // transparency chessboard - background + ctx.fillStyle = sqColor1; + ctx.fillRect(0, 0, cWidth, cHeight); + + // transparency chessboard - squares + ctx.fillStyle = sqColor2; + for (var x = 0; x < cWidth; x += sqSize * 2) { + ctx.fillRect(x, 0, sqSize, sqSize); + ctx.fillRect(x + sqSize, sqSize, sqSize, sqSize); + } + + if (color) { + // actual color in foreground + ctx.fillStyle = color; + ctx.fillRect(0, 0, cWidth, cHeight); + } + + var start = null; + switch (separatorPos) { + case 'left': + start = 0; + ctx.clearRect(0, 0, sepW/2, cHeight); + break; + case 'right': + start = cWidth - sepW; + ctx.clearRect(cWidth - (sepW/2), 0, sepW/2, cHeight); + break; + } + if (start !== null) { + ctx.lineWidth = 1; + for (var i = 0; i < jsc.pub.previewSeparator.length; i += 1) { + ctx.beginPath(); + ctx.strokeStyle = jsc.pub.previewSeparator[i]; + ctx.moveTo(0.5 + start + i, 0); + ctx.lineTo(0.5 + start + i, cHeight); + ctx.stroke(); + } + } + + return { + canvas: canvas, + width: cWidth, + height: cHeight, + }; + }, + + + // if position or width is not set => fill the entire element (0%-100%) + genColorPreviewGradient : function (color, position, width) { + var params = []; + + if (position && width) { + params = [ + 'to ' + {'left':'right', 'right':'left'}[position], + color + ' 0%', + color + ' ' + width + 'px', + 'rgba(0,0,0,0) ' + (width + 1) + 'px', + 'rgba(0,0,0,0) 100%', + ]; + } else { + params = [ + 'to right', + color + ' 0%', + color + ' 100%', + ]; + } + + return jsc.linearGradient.apply(this, params); + }, + + + redrawPosition : function () { + + if (!jsc.picker || !jsc.picker.owner) { + return; // picker is not shown + } + + var thisObj = jsc.picker.owner; + + var tp, vp; + + if (thisObj.fixed) { + // Fixed elements are positioned relative to viewport, + // therefore we can ignore the scroll offset + tp = jsc.getElementPos(thisObj.targetElement, true); // target pos + vp = [0, 0]; // view pos + } else { + tp = jsc.getElementPos(thisObj.targetElement); // target pos + vp = jsc.getViewPos(); // view pos + } + + var ts = jsc.getElementSize(thisObj.targetElement); // target size + var vs = jsc.getViewSize(); // view size + var pd = jsc.getPickerDims(thisObj); + var ps = [pd.borderW, pd.borderH]; // picker outer size + var a, b, c; + switch (thisObj.position.toLowerCase()) { + case 'left': a=1; b=0; c=-1; break; + case 'right':a=1; b=0; c=1; break; + case 'top': a=0; b=1; c=-1; break; + default: a=0; b=1; c=1; break; + } + var l = (ts[b]+ps[b])/2; + + // compute picker position + if (!thisObj.smartPosition) { + var pp = [ + tp[a], + tp[b]+ts[b]-l+l*c + ]; + } else { + var pp = [ + -vp[a]+tp[a]+ps[a] > vs[a] ? + (-vp[a]+tp[a]+ts[a]/2 > vs[a]/2 && tp[a]+ts[a]-ps[a] >= 0 ? tp[a]+ts[a]-ps[a] : tp[a]) : + tp[a], + -vp[b]+tp[b]+ts[b]+ps[b]-l+l*c > vs[b] ? + (-vp[b]+tp[b]+ts[b]/2 > vs[b]/2 && tp[b]+ts[b]-l-l*c >= 0 ? tp[b]+ts[b]-l-l*c : tp[b]+ts[b]-l+l*c) : + (tp[b]+ts[b]-l+l*c >= 0 ? tp[b]+ts[b]-l+l*c : tp[b]+ts[b]-l-l*c) + ]; + } + + var x = pp[a]; + var y = pp[b]; + var positionValue = thisObj.fixed ? 'fixed' : 'absolute'; + var contractShadow = + (pp[0] + ps[0] > tp[0] || pp[0] < tp[0] + ts[0]) && + (pp[1] + ps[1] < tp[1] + ts[1]); + + jsc._drawPosition(thisObj, x, y, positionValue, contractShadow); + }, + + + _drawPosition : function (thisObj, x, y, positionValue, contractShadow) { + var vShadow = contractShadow ? 0 : thisObj.shadowBlur; // px + + jsc.picker.wrap.style.position = positionValue; + jsc.picker.wrap.style.left = x + 'px'; + jsc.picker.wrap.style.top = y + 'px'; + + jsc.setBoxShadow( + jsc.picker.boxS, + thisObj.shadow ? + new jsc.BoxShadow(0, vShadow, thisObj.shadowBlur, 0, thisObj.shadowColor) : + null); + }, + + + getPickerDims : function (thisObj) { + var w = 2 * thisObj.controlBorderWidth + thisObj.width; + var h = 2 * thisObj.controlBorderWidth + thisObj.height; + + var sliderSpace = 2 * thisObj.controlBorderWidth + 2 * jsc.getControlPadding(thisObj) + thisObj.sliderSize; + + if (jsc.getSliderChannel(thisObj)) { + w += sliderSpace; + } + if (thisObj.hasAlphaChannel()) { + w += sliderSpace; + } + + var pal = jsc.getPaletteDims(thisObj, w); + + if (pal.height) { + h += pal.height + thisObj.padding; + } + if (thisObj.closeButton) { + h += 2 * thisObj.controlBorderWidth + thisObj.padding + thisObj.buttonHeight; + } + + var pW = w + (2 * thisObj.padding); + var pH = h + (2 * thisObj.padding); + + return { + contentW: w, + contentH: h, + paddedW: pW, + paddedH: pH, + borderW: pW + (2 * thisObj.borderWidth), + borderH: pH + (2 * thisObj.borderWidth), + palette: pal, + }; + }, + + + getPaletteDims : function (thisObj, width) { + var cols = 0, rows = 0, cellW = 0, cellH = 0, height = 0; + var sampleCount = thisObj._palette ? thisObj._palette.length : 0; + + if (sampleCount) { + cols = thisObj.paletteCols; + rows = cols > 0 ? Math.ceil(sampleCount / cols) : 0; + + // color sample's dimensions (includes border) + cellW = Math.max(1, Math.floor((width - ((cols - 1) * thisObj.paletteSpacing)) / cols)); + cellH = thisObj.paletteHeight ? Math.min(thisObj.paletteHeight, cellW) : cellW; + } + + if (rows) { + height = + rows * cellH + + (rows - 1) * thisObj.paletteSpacing; + } + + return { + cols: cols, + rows: rows, + cellW: cellW, + cellH: cellH, + width: width, + height: height, + }; + }, + + + getControlPadding : function (thisObj) { + return Math.max( + thisObj.padding / 2, + (2 * thisObj.pointerBorderWidth + thisObj.pointerThickness) - thisObj.controlBorderWidth + ); + }, + + + getPadYChannel : function (thisObj) { + switch (thisObj.mode.charAt(1).toLowerCase()) { + case 'v': return 'v'; break; + } + return 's'; + }, + + + getSliderChannel : function (thisObj) { + if (thisObj.mode.length > 2) { + switch (thisObj.mode.charAt(2).toLowerCase()) { + case 's': return 's'; break; + case 'v': return 'v'; break; + } + } + return null; + }, + + + // calls function specified in picker's property + triggerCallback : function (thisObj, prop) { + if (!thisObj[prop]) { + return; // callback func not specified + } + var callback = null; + + if (typeof thisObj[prop] === 'string') { + // string with code + try { + callback = new Function (thisObj[prop]); + } catch (e) { + console.error(e); + } + } else { + // function + callback = thisObj[prop]; + } + + if (callback) { + callback.call(thisObj); + } + }, + + + // Triggers a color change related event(s) on all picker instances. + // It is possible to specify multiple events separated with a space. + triggerGlobal : function (eventNames) { + var inst = jsc.getInstances(); + for (var i = 0; i < inst.length; i += 1) { + inst[i].trigger(eventNames); + } + }, + + + _pointerMoveEvent : { + mouse: 'mousemove', + touch: 'touchmove' + }, + _pointerEndEvent : { + mouse: 'mouseup', + touch: 'touchend' + }, + + + _pointerOrigin : null, + _capturedTarget : null, + + + onDocumentKeyUp : function (e) { + if (['Tab', 'Escape'].indexOf(jsc.eventKey(e)) !== -1) { + if (jsc.picker && jsc.picker.owner) { + jsc.picker.owner.tryHide(); + } + } + }, + + + onWindowResize : function (e) { + jsc.redrawPosition(); + }, + + + onWindowScroll : function (e) { + jsc.redrawPosition(); + }, + + + onParentScroll : function (e) { + // hide the picker when one of the parent elements is scrolled + if (jsc.picker && jsc.picker.owner) { + jsc.picker.owner.tryHide(); + } + }, + + + onDocumentMouseDown : function (e) { + var target = e.target || e.srcElement; + + if (target.jscolor && target.jscolor instanceof jsc.pub) { // clicked targetElement -> show picker + if (target.jscolor.showOnClick && !target.disabled) { + target.jscolor.show(); + } + } else if (jsc.getData(target, 'gui')) { // clicked jscolor's GUI element + var control = jsc.getData(target, 'control'); + if (control) { + // jscolor's control + jsc.onControlPointerStart(e, target, jsc.getData(target, 'control'), 'mouse'); + } + } else { + // mouse is outside the picker's controls -> hide the color picker! + if (jsc.picker && jsc.picker.owner) { + jsc.picker.owner.tryHide(); + } + } + }, + + + onPickerTouchStart : function (e) { + var target = e.target || e.srcElement; + + if (jsc.getData(target, 'control')) { + jsc.onControlPointerStart(e, target, jsc.getData(target, 'control'), 'touch'); + } + }, + + + onControlPointerStart : function (e, target, controlName, pointerType) { + var thisObj = jsc.getData(target, 'instance'); + + jsc.preventDefault(e); + jsc.captureTarget(target); + + var registerDragEvents = function (doc, offset) { + jsc.attachGroupEvent('drag', doc, jsc._pointerMoveEvent[pointerType], + jsc.onDocumentPointerMove(e, target, controlName, pointerType, offset)); + jsc.attachGroupEvent('drag', doc, jsc._pointerEndEvent[pointerType], + jsc.onDocumentPointerEnd(e, target, controlName, pointerType)); + }; + + registerDragEvents(window.document, [0, 0]); + + if (window.parent && window.frameElement) { + var rect = window.frameElement.getBoundingClientRect(); + var ofs = [-rect.left, -rect.top]; + registerDragEvents(window.parent.window.document, ofs); + } + + var abs = jsc.getAbsPointerPos(e); + var rel = jsc.getRelPointerPos(e); + jsc._pointerOrigin = { + x: abs.x - rel.x, + y: abs.y - rel.y + }; + + switch (controlName) { + case 'pad': + // if the value slider is at the bottom, move it up + if (jsc.getSliderChannel(thisObj) === 'v' && thisObj.channels.v === 0) { + thisObj.fromHSVA(null, null, 100, null); + } + jsc.setPad(thisObj, e, 0, 0); + break; + + case 'sld': + jsc.setSld(thisObj, e, 0); + break; + + case 'asld': + jsc.setASld(thisObj, e, 0); + break; + } + thisObj.trigger('input'); + }, + + + onDocumentPointerMove : function (e, target, controlName, pointerType, offset) { + return function (e) { + var thisObj = jsc.getData(target, 'instance'); + switch (controlName) { + case 'pad': + jsc.setPad(thisObj, e, offset[0], offset[1]); + break; + + case 'sld': + jsc.setSld(thisObj, e, offset[1]); + break; + + case 'asld': + jsc.setASld(thisObj, e, offset[1]); + break; + } + thisObj.trigger('input'); + } + }, + + + onDocumentPointerEnd : function (e, target, controlName, pointerType) { + return function (e) { + var thisObj = jsc.getData(target, 'instance'); + jsc.detachGroupEvents('drag'); + jsc.releaseTarget(); + + // Always trigger changes AFTER detaching outstanding mouse handlers, + // in case some color change that occured in user-defined onChange/onInput handler + // intruded into current mouse events + thisObj.trigger('input'); + thisObj.trigger('change'); + }; + }, + + + onPaletteSampleClick : function (e) { + var target = e.currentTarget; + var thisObj = jsc.getData(target, 'instance'); + var color = jsc.getData(target, 'color'); + + // when format is flexible, use the original format of this color sample + if (thisObj.format.toLowerCase() === 'any') { + thisObj._setFormat(color.format); // adapt format + if (!jsc.isAlphaFormat(thisObj.getFormat())) { + color.rgba[3] = 1.0; // when switching to a format that doesn't support alpha, set full opacity + } + } + + // if this color doesn't specify alpha, use alpha of 1.0 (if applicable) + if (color.rgba[3] === null) { + if (thisObj.paletteSetsAlpha === true || (thisObj.paletteSetsAlpha === 'auto' && thisObj._paletteHasTransparency)) { + color.rgba[3] = 1.0; + } + } + + thisObj.fromRGBA.apply(thisObj, color.rgba); + + thisObj.trigger('input'); + thisObj.trigger('change'); + + if (thisObj.hideOnPaletteClick) { + thisObj.hide(); + } + }, + + + setPad : function (thisObj, e, ofsX, ofsY) { + var pointerAbs = jsc.getAbsPointerPos(e); + var x = ofsX + pointerAbs.x - jsc._pointerOrigin.x - thisObj.padding - thisObj.controlBorderWidth; + var y = ofsY + pointerAbs.y - jsc._pointerOrigin.y - thisObj.padding - thisObj.controlBorderWidth; + + var xVal = x * (360 / (thisObj.width - 1)); + var yVal = 100 - (y * (100 / (thisObj.height - 1))); + + switch (jsc.getPadYChannel(thisObj)) { + case 's': thisObj.fromHSVA(xVal, yVal, null, null); break; + case 'v': thisObj.fromHSVA(xVal, null, yVal, null); break; + } + }, + + + setSld : function (thisObj, e, ofsY) { + var pointerAbs = jsc.getAbsPointerPos(e); + var y = ofsY + pointerAbs.y - jsc._pointerOrigin.y - thisObj.padding - thisObj.controlBorderWidth; + var yVal = 100 - (y * (100 / (thisObj.height - 1))); + + switch (jsc.getSliderChannel(thisObj)) { + case 's': thisObj.fromHSVA(null, yVal, null, null); break; + case 'v': thisObj.fromHSVA(null, null, yVal, null); break; + } + }, + + + setASld : function (thisObj, e, ofsY) { + var pointerAbs = jsc.getAbsPointerPos(e); + var y = ofsY + pointerAbs.y - jsc._pointerOrigin.y - thisObj.padding - thisObj.controlBorderWidth; + var yVal = 1.0 - (y * (1.0 / (thisObj.height - 1))); + + if (yVal < 1.0) { + // if format is flexible and the current format doesn't support alpha, switch to a suitable one + var fmt = thisObj.getFormat(); + if (thisObj.format.toLowerCase() === 'any' && !jsc.isAlphaFormat(fmt)) { + thisObj._setFormat(fmt === 'hex' ? 'hexa' : 'rgba'); + } + } + + thisObj.fromHSVA(null, null, null, yVal); + }, + + + createPadCanvas : function () { + + var ret = { + elm: null, + draw: null + }; + + var canvas = jsc.createEl('canvas'); + var ctx = canvas.getContext('2d'); + + var drawFunc = function (width, height, type) { + canvas.width = width; + canvas.height = height; + + ctx.clearRect(0, 0, canvas.width, canvas.height); + + var hGrad = ctx.createLinearGradient(0, 0, canvas.width, 0); + hGrad.addColorStop(0 / 6, '#F00'); + hGrad.addColorStop(1 / 6, '#FF0'); + hGrad.addColorStop(2 / 6, '#0F0'); + hGrad.addColorStop(3 / 6, '#0FF'); + hGrad.addColorStop(4 / 6, '#00F'); + hGrad.addColorStop(5 / 6, '#F0F'); + hGrad.addColorStop(6 / 6, '#F00'); + + ctx.fillStyle = hGrad; + ctx.fillRect(0, 0, canvas.width, canvas.height); + + var vGrad = ctx.createLinearGradient(0, 0, 0, canvas.height); + switch (type.toLowerCase()) { + case 's': + vGrad.addColorStop(0, 'rgba(255,255,255,0)'); + vGrad.addColorStop(1, 'rgba(255,255,255,1)'); + break; + case 'v': + vGrad.addColorStop(0, 'rgba(0,0,0,0)'); + vGrad.addColorStop(1, 'rgba(0,0,0,1)'); + break; + } + ctx.fillStyle = vGrad; + ctx.fillRect(0, 0, canvas.width, canvas.height); + }; + + ret.elm = canvas; + ret.draw = drawFunc; + + return ret; + }, + + + createSliderGradient : function () { + + var ret = { + elm: null, + draw: null + }; + + var canvas = jsc.createEl('canvas'); + var ctx = canvas.getContext('2d'); + + var drawFunc = function (width, height, color1, color2) { + canvas.width = width; + canvas.height = height; + + ctx.clearRect(0, 0, canvas.width, canvas.height); + + var grad = ctx.createLinearGradient(0, 0, 0, canvas.height); + grad.addColorStop(0, color1); + grad.addColorStop(1, color2); + + ctx.fillStyle = grad; + ctx.fillRect(0, 0, canvas.width, canvas.height); + }; + + ret.elm = canvas; + ret.draw = drawFunc; + + return ret; + }, + + + createASliderGradient : function () { + + var ret = { + elm: null, + draw: null + }; + + var canvas = jsc.createEl('canvas'); + var ctx = canvas.getContext('2d'); + + var drawFunc = function (width, height, color) { + canvas.width = width; + canvas.height = height; + + ctx.clearRect(0, 0, canvas.width, canvas.height); + + var sqSize = canvas.width / 2; + var sqColor1 = jsc.pub.chessboardColor1; + var sqColor2 = jsc.pub.chessboardColor2; + + // dark gray background + ctx.fillStyle = sqColor1; + ctx.fillRect(0, 0, canvas.width, canvas.height); + + if (sqSize > 0) { // to avoid infinite loop + for (var y = 0; y < canvas.height; y += sqSize * 2) { + // light gray squares + ctx.fillStyle = sqColor2; + ctx.fillRect(0, y, sqSize, sqSize); + ctx.fillRect(sqSize, y + sqSize, sqSize, sqSize); + } + } + + var grad = ctx.createLinearGradient(0, 0, 0, canvas.height); + grad.addColorStop(0, color); + grad.addColorStop(1, 'rgba(0,0,0,0)'); + + ctx.fillStyle = grad; + ctx.fillRect(0, 0, canvas.width, canvas.height); + }; + + ret.elm = canvas; + ret.draw = drawFunc; + + return ret; + }, + + + BoxShadow : (function () { + var BoxShadow = function (hShadow, vShadow, blur, spread, color, inset) { + this.hShadow = hShadow; + this.vShadow = vShadow; + this.blur = blur; + this.spread = spread; + this.color = color; + this.inset = !!inset; + }; + + BoxShadow.prototype.toString = function () { + var vals = [ + Math.round(this.hShadow) + 'px', + Math.round(this.vShadow) + 'px', + Math.round(this.blur) + 'px', + Math.round(this.spread) + 'px', + this.color + ]; + if (this.inset) { + vals.push('inset'); + } + return vals.join(' '); + }; + + return BoxShadow; + })(), + + + flags : { + leaveValue : 1 << 0, + leaveAlpha : 1 << 1, + leavePreview : 1 << 2, + }, + + + enumOpts : { + format: ['auto', 'any', 'hex', 'hexa', 'rgb', 'rgba'], + previewPosition: ['left', 'right'], + mode: ['hsv', 'hvs', 'hs', 'hv'], + position: ['left', 'right', 'top', 'bottom'], + alphaChannel: ['auto', true, false], + paletteSetsAlpha: ['auto', true, false], + }, + + + deprecatedOpts : { + // : ( can be null) + 'styleElement': 'previewElement', + 'onFineChange': 'onInput', + 'overwriteImportant': 'forceStyle', + 'closable': 'closeButton', + 'insetWidth': 'controlBorderWidth', + 'insetColor': 'controlBorderColor', + 'refine': null, + }, + + + docsRef : ' ' + 'See https://jscolor.com/docs/', + + + // + // Usage: + // var myPicker = new JSColor( [, ]) + // + // (constructor is accessible via both 'jscolor' and 'JSColor' name) + // + + pub : function (targetElement, opts) { + + var THIS = this; + + if (!opts) { + opts = {}; + } + + this.channels = { + r: 255, // red [0-255] + g: 255, // green [0-255] + b: 255, // blue [0-255] + h: 0, // hue [0-360] + s: 0, // saturation [0-100] + v: 100, // value (brightness) [0-100] + a: 1.0, // alpha (opacity) [0.0 - 1.0] + }; + + // General options + // + this.format = 'auto'; // 'auto' | 'any' | 'hex' | 'hexa' | 'rgb' | 'rgba' - Format of the input/output value + this.value = undefined; // INITIAL color value in any supported format. To change it later, use method fromString(), fromHSVA(), fromRGBA() or channel() + this.alpha = undefined; // INITIAL alpha value. To change it later, call method channel('A', ) + this.onChange = undefined; // called when color changes. Value can be either a function or a string with JS code. + this.onInput = undefined; // called repeatedly as the color is being changed, e.g. while dragging a slider. Value can be either a function or a string with JS code. + this.valueElement = undefined; // element that will be used to display and input the color value + this.alphaElement = undefined; // element that will be used to display and input the alpha (opacity) value + this.previewElement = undefined; // element that will preview the picked color using CSS background + this.previewPosition = 'left'; // 'left' | 'right' - position of the color preview in previewElement + this.previewSize = 32; // (px) width of the color preview displayed in previewElement + this.previewPadding = 8; // (px) space between color preview and content of the previewElement + this.required = true; // whether the associated text input must always contain a color value. If false, the input can be left empty. + this.hash = true; // whether to prefix the HEX color code with # symbol (only applicable for HEX format) + this.uppercase = true; // whether to show the HEX color code in upper case (only applicable for HEX format) + this.forceStyle = true; // whether to overwrite CSS style of the previewElement using !important flag + + // Color Picker options + // + this.width = 181; // width of the color spectrum (in px) + this.height = 101; // height of the color spectrum (in px) + this.mode = 'HSV'; // 'HSV' | 'HVS' | 'HS' | 'HV' - layout of the color picker controls + this.alphaChannel = 'auto'; // 'auto' | true | false - if alpha channel is enabled, the alpha slider will be visible. If 'auto', it will be determined according to color format + this.position = 'bottom'; // 'left' | 'right' | 'top' | 'bottom' - position relative to the target element + this.smartPosition = true; // automatically change picker position when there is not enough space for it + this.showOnClick = true; // whether to show the picker when user clicks its target element + this.hideOnLeave = true; // whether to automatically hide the picker when user leaves its target element (e.g. upon clicking the document) + this.palette = []; // colors to be displayed in the palette, specified as an array or a string of space separated color values (in any supported format) + this.paletteCols = 10; // number of columns in the palette + this.paletteSetsAlpha = 'auto'; // 'auto' | true | false - if true, palette colors that don't specify alpha will set alpha to 1.0 + this.paletteHeight = 16; // maximum height (px) of a row in the palette + this.paletteSpacing = 4; // distance (px) between color samples in the palette + this.hideOnPaletteClick = false; // when set to true, clicking the palette will also hide the color picker + this.sliderSize = 16; // px + this.crossSize = 8; // px + this.closeButton = false; // whether to display the Close button + this.closeText = 'Close'; + this.buttonColor = 'rgba(0,0,0,1)'; // CSS color + this.buttonHeight = 18; // px + this.padding = 12; // px + this.backgroundColor = 'rgba(255,255,255,1)'; // CSS color + this.borderWidth = 1; // px + this.borderColor = 'rgba(187,187,187,1)'; // CSS color + this.borderRadius = 8; // px + this.controlBorderWidth = 1; // px + this.controlBorderColor = 'rgba(187,187,187,1)'; // CSS color + this.shadow = true; // whether to display a shadow + this.shadowBlur = 15; // px + this.shadowColor = 'rgba(0,0,0,0.2)'; // CSS color + this.pointerColor = 'rgba(76,76,76,1)'; // CSS color + this.pointerBorderWidth = 1; // px + this.pointerBorderColor = 'rgba(255,255,255,1)'; // CSS color + this.pointerThickness = 2; // px + this.zIndex = 5000; + this.container = undefined; // where to append the color picker (BODY element by default) + + // Experimental + // + this.minS = 0; // min allowed saturation (0 - 100) + this.maxS = 100; // max allowed saturation (0 - 100) + this.minV = 0; // min allowed value (brightness) (0 - 100) + this.maxV = 100; // max allowed value (brightness) (0 - 100) + this.minA = 0.0; // min allowed alpha (opacity) (0.0 - 1.0) + this.maxA = 1.0; // max allowed alpha (opacity) (0.0 - 1.0) + + + // Getter: option(name) + // Setter: option(name, value) + // option({name:value, ...}) + // + this.option = function () { + if (!arguments.length) { + throw new Error('No option specified'); + } + + if (arguments.length === 1 && typeof arguments[0] === 'string') { + // getting a single option + try { + return getOption(arguments[0]); + } catch (e) { + console.warn(e); + } + return false; + + } else if (arguments.length >= 2 && typeof arguments[0] === 'string') { + // setting a single option + try { + if (!setOption(arguments[0], arguments[1])) { + return false; + } + } catch (e) { + console.warn(e); + return false; + } + this.redraw(); // immediately redraws the picker, if it's displayed + this.exposeColor(); // in case some preview-related or format-related option was changed + return true; + + } else if (arguments.length === 1 && typeof arguments[0] === 'object') { + // setting multiple options + var opts = arguments[0]; + var success = true; + for (var opt in opts) { + if (opts.hasOwnProperty(opt)) { + try { + if (!setOption(opt, opts[opt])) { + success = false; + } + } catch (e) { + console.warn(e); + success = false; + } + } + } + this.redraw(); // immediately redraws the picker, if it's displayed + this.exposeColor(); // in case some preview-related or format-related option was changed + return success; + } + + throw new Error('Invalid arguments'); + } + + + // Getter: channel(name) + // Setter: channel(name, value) + // + this.channel = function (name, value) { + if (typeof name !== 'string') { + throw new Error('Invalid value for channel name: ' + name); + } + + if (value === undefined) { + // getting channel value + if (!this.channels.hasOwnProperty(name.toLowerCase())) { + console.warn('Getting unknown channel: ' + name); + return false; + } + return this.channels[name.toLowerCase()]; + + } else { + // setting channel value + var res = false; + switch (name.toLowerCase()) { + case 'r': res = this.fromRGBA(value, null, null, null); break; + case 'g': res = this.fromRGBA(null, value, null, null); break; + case 'b': res = this.fromRGBA(null, null, value, null); break; + case 'h': res = this.fromHSVA(value, null, null, null); break; + case 's': res = this.fromHSVA(null, value, null, null); break; + case 'v': res = this.fromHSVA(null, null, value, null); break; + case 'a': res = this.fromHSVA(null, null, null, value); break; + default: + console.warn('Setting unknown channel: ' + name); + return false; + } + if (res) { + this.redraw(); // immediately redraws the picker, if it's displayed + return true; + } + } + + return false; + } + + + // Triggers given input event(s) by: + // - executing on callback specified as picker's option + // - triggering standard DOM event listeners attached to the value element + // + // It is possible to specify multiple events separated with a space. + // + this.trigger = function (eventNames) { + var evs = jsc.strList(eventNames); + for (var i = 0; i < evs.length; i += 1) { + var ev = evs[i].toLowerCase(); + + // trigger a callback + var callbackProp = null; + switch (ev) { + case 'input': callbackProp = 'onInput'; break; + case 'change': callbackProp = 'onChange'; break; + } + if (callbackProp) { + jsc.triggerCallback(this, callbackProp); + } + + // trigger standard DOM event listeners on the value element + jsc.triggerInputEvent(this.valueElement, ev, true, true); + } + }; + + + // h: 0-360 + // s: 0-100 + // v: 0-100 + // a: 0.0-1.0 + // + this.fromHSVA = function (h, s, v, a, flags) { // null = don't change + if (h === undefined) { h = null; } + if (s === undefined) { s = null; } + if (v === undefined) { v = null; } + if (a === undefined) { a = null; } + + if (h !== null) { + if (isNaN(h)) { return false; } + this.channels.h = Math.max(0, Math.min(360, h)); + } + if (s !== null) { + if (isNaN(s)) { return false; } + this.channels.s = Math.max(0, Math.min(100, this.maxS, s), this.minS); + } + if (v !== null) { + if (isNaN(v)) { return false; } + this.channels.v = Math.max(0, Math.min(100, this.maxV, v), this.minV); + } + if (a !== null) { + if (isNaN(a)) { return false; } + this.channels.a = this.hasAlphaChannel() ? + Math.max(0, Math.min(1, this.maxA, a), this.minA) : + 1.0; // if alpha channel is disabled, the color should stay 100% opaque + } + + var rgb = jsc.HSV_RGB( + this.channels.h, + this.channels.s, + this.channels.v + ); + this.channels.r = rgb[0]; + this.channels.g = rgb[1]; + this.channels.b = rgb[2]; + + this.exposeColor(flags); + return true; + }; + + + // r: 0-255 + // g: 0-255 + // b: 0-255 + // a: 0.0-1.0 + // + this.fromRGBA = function (r, g, b, a, flags) { // null = don't change + if (r === undefined) { r = null; } + if (g === undefined) { g = null; } + if (b === undefined) { b = null; } + if (a === undefined) { a = null; } + + if (r !== null) { + if (isNaN(r)) { return false; } + r = Math.max(0, Math.min(255, r)); + } + if (g !== null) { + if (isNaN(g)) { return false; } + g = Math.max(0, Math.min(255, g)); + } + if (b !== null) { + if (isNaN(b)) { return false; } + b = Math.max(0, Math.min(255, b)); + } + if (a !== null) { + if (isNaN(a)) { return false; } + this.channels.a = this.hasAlphaChannel() ? + Math.max(0, Math.min(1, this.maxA, a), this.minA) : + 1.0; // if alpha channel is disabled, the color should stay 100% opaque + } + + var hsv = jsc.RGB_HSV( + r===null ? this.channels.r : r, + g===null ? this.channels.g : g, + b===null ? this.channels.b : b + ); + if (hsv[0] !== null) { + this.channels.h = Math.max(0, Math.min(360, hsv[0])); + } + if (hsv[2] !== 0) { // fully black color stays black through entire saturation range, so let's not change saturation + this.channels.s = Math.max(0, this.minS, Math.min(100, this.maxS, hsv[1])); + } + this.channels.v = Math.max(0, this.minV, Math.min(100, this.maxV, hsv[2])); + + // update RGB according to final HSV, as some values might be trimmed + var rgb = jsc.HSV_RGB(this.channels.h, this.channels.s, this.channels.v); + this.channels.r = rgb[0]; + this.channels.g = rgb[1]; + this.channels.b = rgb[2]; + + this.exposeColor(flags); + return true; + }; + + + // DEPRECATED. Use .fromHSVA() instead + // + this.fromHSV = function (h, s, v, flags) { + console.warn('fromHSV() method is DEPRECATED. Using fromHSVA() instead.' + jsc.docsRef); + return this.fromHSVA(h, s, v, null, flags); + }; + + + // DEPRECATED. Use .fromRGBA() instead + // + this.fromRGB = function (r, g, b, flags) { + console.warn('fromRGB() method is DEPRECATED. Using fromRGBA() instead.' + jsc.docsRef); + return this.fromRGBA(r, g, b, null, flags); + }; + + + this.fromString = function (str, flags) { + if (!this.required && str.trim() === '') { + // setting empty string to an optional color input + this.setPreviewElementBg(null); + this.setValueElementValue(''); + return true; + } + + var color = jsc.parseColorString(str); + if (!color) { + return false; // could not parse + } + if (this.format.toLowerCase() === 'any') { + this._setFormat(color.format); // adapt format + if (!jsc.isAlphaFormat(this.getFormat())) { + color.rgba[3] = 1.0; // when switching to a format that doesn't support alpha, set full opacity + } + } + this.fromRGBA( + color.rgba[0], + color.rgba[1], + color.rgba[2], + color.rgba[3], + flags + ); + return true; + }; + + + this.toString = function (format) { + if (format === undefined) { + format = this.getFormat(); // format not specified -> use the current format + } + switch (format.toLowerCase()) { + case 'hex': return this.toHEXString(); break; + case 'hexa': return this.toHEXAString(); break; + case 'rgb': return this.toRGBString(); break; + case 'rgba': return this.toRGBAString(); break; + } + return false; + }; + + + this.toHEXString = function () { + return jsc.hexColor( + this.channels.r, + this.channels.g, + this.channels.b + ); + }; + + + this.toHEXAString = function () { + return jsc.hexaColor( + this.channels.r, + this.channels.g, + this.channels.b, + this.channels.a + ); + }; + + + this.toRGBString = function () { + return jsc.rgbColor( + this.channels.r, + this.channels.g, + this.channels.b + ); + }; + + + this.toRGBAString = function () { + return jsc.rgbaColor( + this.channels.r, + this.channels.g, + this.channels.b, + this.channels.a + ); + }; + + + this.toGrayscale = function () { + return ( + 0.213 * this.channels.r + + 0.715 * this.channels.g + + 0.072 * this.channels.b + ); + }; + + + this.toCanvas = function () { + return jsc.genColorPreviewCanvas(this.toRGBAString()).canvas; + }; + + + this.toDataURL = function () { + return this.toCanvas().toDataURL(); + }; + + + this.toBackground = function () { + return jsc.pub.background(this.toRGBAString()); + }; + + + this.isLight = function () { + return this.toGrayscale() > 255 / 2; + }; + + + this.hide = function () { + if (isPickerOwner()) { + detachPicker(); + } + }; + + + this.show = function () { + drawPicker(); + }; + + + this.redraw = function () { + if (isPickerOwner()) { + drawPicker(); + } + }; + + + this.getFormat = function () { + return this._currentFormat; + }; + + + this._setFormat = function (format) { + this._currentFormat = format.toLowerCase(); + }; + + + this.hasAlphaChannel = function () { + if (this.alphaChannel === 'auto') { + return ( + this.format.toLowerCase() === 'any' || // format can change on the fly (e.g. from hex to rgba), so let's consider the alpha channel enabled + jsc.isAlphaFormat(this.getFormat()) || // the current format supports alpha channel + this.alpha !== undefined || // initial alpha value is set, so we're working with alpha channel + this.alphaElement !== undefined // the alpha value is redirected, so we're working with alpha channel + ); + } + + return this.alphaChannel; // the alpha channel is explicitly set + }; + + + this.processValueInput = function (str) { + if (!this.fromString(str)) { + // could not parse the color value - let's just expose the current color + this.exposeColor(); + } + }; + + + this.processAlphaInput = function (str) { + if (!this.fromHSVA(null, null, null, parseFloat(str))) { + // could not parse the alpha value - let's just expose the current color + this.exposeColor(); + } + }; + + + this.exposeColor = function (flags) { + var colorStr = this.toString(); + var fmt = this.getFormat(); + + // reflect current color in data- attribute + jsc.setDataAttr(this.targetElement, 'current-color', colorStr); + + if (!(flags & jsc.flags.leaveValue) && this.valueElement) { + if (fmt === 'hex' || fmt === 'hexa') { + if (!this.uppercase) { colorStr = colorStr.toLowerCase(); } + if (!this.hash) { colorStr = colorStr.replace(/^#/, ''); } + } + this.setValueElementValue(colorStr); + } + + if (!(flags & jsc.flags.leaveAlpha) && this.alphaElement) { + var alphaVal = Math.round(this.channels.a * 100) / 100; + this.setAlphaElementValue(alphaVal); + } + + if (!(flags & jsc.flags.leavePreview) && this.previewElement) { + var previewPos = null; // 'left' | 'right' (null -> fill the entire element) + + if ( + jsc.isTextInput(this.previewElement) || // text input + (jsc.isButton(this.previewElement) && !jsc.isButtonEmpty(this.previewElement)) // button with text + ) { + previewPos = this.previewPosition; + } + + this.setPreviewElementBg(this.toRGBAString()); + } + + if (isPickerOwner()) { + redrawPad(); + redrawSld(); + redrawASld(); + } + }; + + + this.setPreviewElementBg = function (color) { + if (!this.previewElement) { + return; + } + + var position = null; // color preview position: null | 'left' | 'right' + var width = null; // color preview width: px | null = fill the entire element + if ( + jsc.isTextInput(this.previewElement) || // text input + (jsc.isButton(this.previewElement) && !jsc.isButtonEmpty(this.previewElement)) // button with text + ) { + position = this.previewPosition; + width = this.previewSize; + } + + var backgrounds = []; + + if (!color) { + // there is no color preview to display -> let's remove any previous background image + backgrounds.push({ + image: 'none', + position: 'left top', + size: 'auto', + repeat: 'no-repeat', + origin: 'padding-box', + }); + } else { + // CSS gradient for background color preview + backgrounds.push({ + image: jsc.genColorPreviewGradient( + color, + position, + width ? width - jsc.pub.previewSeparator.length : null + ), + position: 'left top', + size: 'auto', + repeat: position ? 'repeat-y' : 'repeat', + origin: 'padding-box', + }); + + // data URL of generated PNG image with a gray transparency chessboard + var preview = jsc.genColorPreviewCanvas( + 'rgba(0,0,0,0)', + position ? {'left':'right', 'right':'left'}[position] : null, + width, + true + ); + backgrounds.push({ + image: 'url(\'' + preview.canvas.toDataURL() + '\')', + position: (position || 'left') + ' top', + size: preview.width + 'px ' + preview.height + 'px', + repeat: position ? 'repeat-y' : 'repeat', + origin: 'padding-box', + }); + } + + var bg = { + image: [], + position: [], + size: [], + repeat: [], + origin: [], + }; + for (var i = 0; i < backgrounds.length; i += 1) { + bg.image.push(backgrounds[i].image); + bg.position.push(backgrounds[i].position); + bg.size.push(backgrounds[i].size); + bg.repeat.push(backgrounds[i].repeat); + bg.origin.push(backgrounds[i].origin); + } + + // set previewElement's background-images + var sty = { + 'background-image': bg.image.join(', '), + 'background-position': bg.position.join(', '), + 'background-size': bg.size.join(', '), + 'background-repeat': bg.repeat.join(', '), + 'background-origin': bg.origin.join(', '), + }; + jsc.setStyle(this.previewElement, sty, this.forceStyle); + + + // set/restore previewElement's padding + var padding = { + left: null, + right: null, + }; + if (position) { + padding[position] = (this.previewSize + this.previewPadding) + 'px'; + } + + var sty = { + 'padding-left': padding.left, + 'padding-right': padding.right, + }; + jsc.setStyle(this.previewElement, sty, this.forceStyle, true); + }; + + + this.setValueElementValue = function (str) { + if (this.valueElement) { + if (jsc.nodeName(this.valueElement) === 'input') { + this.valueElement.value = str; + } else { + this.valueElement.innerHTML = str; + } + } + }; + + + this.setAlphaElementValue = function (str) { + if (this.alphaElement) { + if (jsc.nodeName(this.alphaElement) === 'input') { + this.alphaElement.value = str; + } else { + this.alphaElement.innerHTML = str; + } + } + }; + + + this._processParentElementsInDOM = function () { + if (this._parentElementsProcessed) { return; } + this._parentElementsProcessed = true; + + var elm = this.targetElement; + do { + // If the target element or one of its parent nodes has fixed position, + // then use fixed positioning instead + var compStyle = jsc.getCompStyle(elm); + if (compStyle.position && compStyle.position.toLowerCase() === 'fixed') { + this.fixed = true; + } + + if (elm !== this.targetElement) { + // Ensure to attach onParentScroll only once to each parent element + // (multiple targetElements can share the same parent nodes) + // + // Note: It's not just offsetParents that can be scrollable, + // that's why we loop through all parent nodes + if (!jsc.getData(elm, 'hasScrollListener')) { + elm.addEventListener('scroll', jsc.onParentScroll, false); + jsc.setData(elm, 'hasScrollListener', true); + } + } + } while ((elm = elm.parentNode) && jsc.nodeName(elm) !== 'body'); + }; + + + this.tryHide = function () { + if (this.hideOnLeave) { + this.hide(); + } + }; + + + this.set__palette = function (val) { + this.palette = val; + this._palette = jsc.parsePaletteValue(val); + this._paletteHasTransparency = jsc.containsTranparentColor(this._palette); + }; + + + function setOption (option, value) { + if (typeof option !== 'string') { + throw new Error('Invalid value for option name: ' + option); + } + + // enum option + if (jsc.enumOpts.hasOwnProperty(option)) { + if (typeof value === 'string') { // enum string values are case insensitive + value = value.toLowerCase(); + } + if (jsc.enumOpts[option].indexOf(value) === -1) { + throw new Error('Option \'' + option + '\' has invalid value: ' + value); + } + } + + // deprecated option + if (jsc.deprecatedOpts.hasOwnProperty(option)) { + var oldOpt = option; + var newOpt = jsc.deprecatedOpts[option]; + if (newOpt) { + // if we have a new name for this option, let's log a warning and use the new name + console.warn('Option \'%s\' is DEPRECATED, using \'%s\' instead.' + jsc.docsRef, oldOpt, newOpt); + option = newOpt; + } else { + // new name not available for the option + throw new Error('Option \'' + option + '\' is DEPRECATED'); + } + } + + var setter = 'set__' + option; + + if (typeof THIS[setter] === 'function') { // a setter exists for this option + THIS[setter](value); + return true; + + } else if (option in THIS) { // option exists as a property + THIS[option] = value; + return true; + } + + throw new Error('Unrecognized configuration option: ' + option); + } + + + function getOption (option) { + if (typeof option !== 'string') { + throw new Error('Invalid value for option name: ' + option); + } + + // deprecated option + if (jsc.deprecatedOpts.hasOwnProperty(option)) { + var oldOpt = option; + var newOpt = jsc.deprecatedOpts[option]; + if (newOpt) { + // if we have a new name for this option, let's log a warning and use the new name + console.warn('Option \'%s\' is DEPRECATED, using \'%s\' instead.' + jsc.docsRef, oldOpt, newOpt); + option = newOpt; + } else { + // new name not available for the option + throw new Error('Option \'' + option + '\' is DEPRECATED'); + } + } + + var getter = 'get__' + option; + + if (typeof THIS[getter] === 'function') { // a getter exists for this option + return THIS[getter](value); + + } else if (option in THIS) { // option exists as a property + return THIS[option]; + } + + throw new Error('Unrecognized configuration option: ' + option); + } + + + function detachPicker () { + jsc.removeClass(THIS.targetElement, jsc.pub.activeClassName); + jsc.picker.wrap.parentNode.removeChild(jsc.picker.wrap); + delete jsc.picker.owner; + } + + + function drawPicker () { + + // At this point, when drawing the picker, we know what the parent elements are + // and we can do all related DOM operations, such as registering events on them + // or checking their positioning + THIS._processParentElementsInDOM(); + + if (!jsc.picker) { + jsc.picker = { + owner: null, // owner picker instance + wrap : jsc.createEl('div'), + box : jsc.createEl('div'), + boxS : jsc.createEl('div'), // shadow area + boxB : jsc.createEl('div'), // border + pad : jsc.createEl('div'), + padB : jsc.createEl('div'), // border + padM : jsc.createEl('div'), // mouse/touch area + padCanvas : jsc.createPadCanvas(), + cross : jsc.createEl('div'), + crossBY : jsc.createEl('div'), // border Y + crossBX : jsc.createEl('div'), // border X + crossLY : jsc.createEl('div'), // line Y + crossLX : jsc.createEl('div'), // line X + sld : jsc.createEl('div'), // slider + sldB : jsc.createEl('div'), // border + sldM : jsc.createEl('div'), // mouse/touch area + sldGrad : jsc.createSliderGradient(), + sldPtrS : jsc.createEl('div'), // slider pointer spacer + sldPtrIB : jsc.createEl('div'), // slider pointer inner border + sldPtrMB : jsc.createEl('div'), // slider pointer middle border + sldPtrOB : jsc.createEl('div'), // slider pointer outer border + asld : jsc.createEl('div'), // alpha slider + asldB : jsc.createEl('div'), // border + asldM : jsc.createEl('div'), // mouse/touch area + asldGrad : jsc.createASliderGradient(), + asldPtrS : jsc.createEl('div'), // slider pointer spacer + asldPtrIB : jsc.createEl('div'), // slider pointer inner border + asldPtrMB : jsc.createEl('div'), // slider pointer middle border + asldPtrOB : jsc.createEl('div'), // slider pointer outer border + pal : jsc.createEl('div'), // palette + btn : jsc.createEl('div'), + btnT : jsc.createEl('span'), // text + }; + + jsc.picker.pad.appendChild(jsc.picker.padCanvas.elm); + jsc.picker.padB.appendChild(jsc.picker.pad); + jsc.picker.cross.appendChild(jsc.picker.crossBY); + jsc.picker.cross.appendChild(jsc.picker.crossBX); + jsc.picker.cross.appendChild(jsc.picker.crossLY); + jsc.picker.cross.appendChild(jsc.picker.crossLX); + jsc.picker.padB.appendChild(jsc.picker.cross); + jsc.picker.box.appendChild(jsc.picker.padB); + jsc.picker.box.appendChild(jsc.picker.padM); + + jsc.picker.sld.appendChild(jsc.picker.sldGrad.elm); + jsc.picker.sldB.appendChild(jsc.picker.sld); + jsc.picker.sldB.appendChild(jsc.picker.sldPtrOB); + jsc.picker.sldPtrOB.appendChild(jsc.picker.sldPtrMB); + jsc.picker.sldPtrMB.appendChild(jsc.picker.sldPtrIB); + jsc.picker.sldPtrIB.appendChild(jsc.picker.sldPtrS); + jsc.picker.box.appendChild(jsc.picker.sldB); + jsc.picker.box.appendChild(jsc.picker.sldM); + + jsc.picker.asld.appendChild(jsc.picker.asldGrad.elm); + jsc.picker.asldB.appendChild(jsc.picker.asld); + jsc.picker.asldB.appendChild(jsc.picker.asldPtrOB); + jsc.picker.asldPtrOB.appendChild(jsc.picker.asldPtrMB); + jsc.picker.asldPtrMB.appendChild(jsc.picker.asldPtrIB); + jsc.picker.asldPtrIB.appendChild(jsc.picker.asldPtrS); + jsc.picker.box.appendChild(jsc.picker.asldB); + jsc.picker.box.appendChild(jsc.picker.asldM); + + jsc.picker.box.appendChild(jsc.picker.pal); + + jsc.picker.btn.appendChild(jsc.picker.btnT); + jsc.picker.box.appendChild(jsc.picker.btn); + + jsc.picker.boxB.appendChild(jsc.picker.box); + jsc.picker.wrap.appendChild(jsc.picker.boxS); + jsc.picker.wrap.appendChild(jsc.picker.boxB); + + jsc.picker.wrap.addEventListener('touchstart', jsc.onPickerTouchStart, + jsc.isPassiveEventSupported ? {passive: false} : false); + } + + var p = jsc.picker; + + var displaySlider = !!jsc.getSliderChannel(THIS); + var displayAlphaSlider = THIS.hasAlphaChannel(); + var pickerDims = jsc.getPickerDims(THIS); + var crossOuterSize = (2 * THIS.pointerBorderWidth + THIS.pointerThickness + 2 * THIS.crossSize); + var controlPadding = jsc.getControlPadding(THIS); + var borderRadius = Math.min( + THIS.borderRadius, + Math.round(THIS.padding * Math.PI)); // px + var padCursor = 'crosshair'; + + // wrap + p.wrap.className = 'jscolor-picker-wrap'; + p.wrap.style.clear = 'both'; + p.wrap.style.width = pickerDims.borderW + 'px'; + p.wrap.style.height = pickerDims.borderH + 'px'; + p.wrap.style.zIndex = THIS.zIndex; + + // picker + p.box.className = 'jscolor-picker'; + p.box.style.width = pickerDims.paddedW + 'px'; + p.box.style.height = pickerDims.paddedH + 'px'; + p.box.style.position = 'relative'; + + // picker shadow + p.boxS.className = 'jscolor-picker-shadow'; + p.boxS.style.position = 'absolute'; + p.boxS.style.left = '0'; + p.boxS.style.top = '0'; + p.boxS.style.width = '100%'; + p.boxS.style.height = '100%'; + jsc.setBorderRadius(p.boxS, borderRadius + 'px'); + + // picker border + p.boxB.className = 'jscolor-picker-border'; + p.boxB.style.position = 'relative'; + p.boxB.style.border = THIS.borderWidth + 'px solid'; + p.boxB.style.borderColor = THIS.borderColor; + p.boxB.style.background = THIS.backgroundColor; + jsc.setBorderRadius(p.boxB, borderRadius + 'px'); + + // IE hack: + // If the element is transparent, IE will trigger the event on the elements under it, + // e.g. on Canvas or on elements with border + p.padM.style.background = 'rgba(255,0,0,.2)'; + p.sldM.style.background = 'rgba(0,255,0,.2)'; + p.asldM.style.background = 'rgba(0,0,255,.2)'; + + p.padM.style.opacity = + p.sldM.style.opacity = + p.asldM.style.opacity = + '0'; + + // pad + p.pad.style.position = 'relative'; + p.pad.style.width = THIS.width + 'px'; + p.pad.style.height = THIS.height + 'px'; + + // pad - color spectrum (HSV and HVS) + p.padCanvas.draw(THIS.width, THIS.height, jsc.getPadYChannel(THIS)); + + // pad border + p.padB.style.position = 'absolute'; + p.padB.style.left = THIS.padding + 'px'; + p.padB.style.top = THIS.padding + 'px'; + p.padB.style.border = THIS.controlBorderWidth + 'px solid'; + p.padB.style.borderColor = THIS.controlBorderColor; + + // pad mouse area + p.padM.style.position = 'absolute'; + p.padM.style.left = 0 + 'px'; + p.padM.style.top = 0 + 'px'; + p.padM.style.width = (THIS.padding + 2 * THIS.controlBorderWidth + THIS.width + controlPadding) + 'px'; + p.padM.style.height = (2 * THIS.controlBorderWidth + 2 * THIS.padding + THIS.height) + 'px'; + p.padM.style.cursor = padCursor; + jsc.setData(p.padM, { + instance: THIS, + control: 'pad', + }) + + // pad cross + p.cross.style.position = 'absolute'; + p.cross.style.left = + p.cross.style.top = + '0'; + p.cross.style.width = + p.cross.style.height = + crossOuterSize + 'px'; + + // pad cross border Y and X + p.crossBY.style.position = + p.crossBX.style.position = + 'absolute'; + p.crossBY.style.background = + p.crossBX.style.background = + THIS.pointerBorderColor; + p.crossBY.style.width = + p.crossBX.style.height = + (2 * THIS.pointerBorderWidth + THIS.pointerThickness) + 'px'; + p.crossBY.style.height = + p.crossBX.style.width = + crossOuterSize + 'px'; + p.crossBY.style.left = + p.crossBX.style.top = + (Math.floor(crossOuterSize / 2) - Math.floor(THIS.pointerThickness / 2) - THIS.pointerBorderWidth) + 'px'; + p.crossBY.style.top = + p.crossBX.style.left = + '0'; + + // pad cross line Y and X + p.crossLY.style.position = + p.crossLX.style.position = + 'absolute'; + p.crossLY.style.background = + p.crossLX.style.background = + THIS.pointerColor; + p.crossLY.style.height = + p.crossLX.style.width = + (crossOuterSize - 2 * THIS.pointerBorderWidth) + 'px'; + p.crossLY.style.width = + p.crossLX.style.height = + THIS.pointerThickness + 'px'; + p.crossLY.style.left = + p.crossLX.style.top = + (Math.floor(crossOuterSize / 2) - Math.floor(THIS.pointerThickness / 2)) + 'px'; + p.crossLY.style.top = + p.crossLX.style.left = + THIS.pointerBorderWidth + 'px'; + + + // slider + p.sld.style.overflow = 'hidden'; + p.sld.style.width = THIS.sliderSize + 'px'; + p.sld.style.height = THIS.height + 'px'; + + // slider gradient + p.sldGrad.draw(THIS.sliderSize, THIS.height, '#000', '#000'); + + // slider border + p.sldB.style.display = displaySlider ? 'block' : 'none'; + p.sldB.style.position = 'absolute'; + p.sldB.style.left = (THIS.padding + THIS.width + 2 * THIS.controlBorderWidth + 2 * controlPadding) + 'px'; + p.sldB.style.top = THIS.padding + 'px'; + p.sldB.style.border = THIS.controlBorderWidth + 'px solid'; + p.sldB.style.borderColor = THIS.controlBorderColor; + + // slider mouse area + p.sldM.style.display = displaySlider ? 'block' : 'none'; + p.sldM.style.position = 'absolute'; + p.sldM.style.left = (THIS.padding + THIS.width + 2 * THIS.controlBorderWidth + controlPadding) + 'px'; + p.sldM.style.top = 0 + 'px'; + p.sldM.style.width = ( + (THIS.sliderSize + 2 * controlPadding + 2 * THIS.controlBorderWidth) + + (displayAlphaSlider ? 0 : Math.max(0, THIS.padding - controlPadding)) // remaining padding to the right edge + ) + 'px'; + p.sldM.style.height = (2 * THIS.controlBorderWidth + 2 * THIS.padding + THIS.height) + 'px'; + p.sldM.style.cursor = 'default'; + jsc.setData(p.sldM, { + instance: THIS, + control: 'sld', + }); + + // slider pointer inner and outer border + p.sldPtrIB.style.border = + p.sldPtrOB.style.border = + THIS.pointerBorderWidth + 'px solid ' + THIS.pointerBorderColor; + + // slider pointer outer border + p.sldPtrOB.style.position = 'absolute'; + p.sldPtrOB.style.left = -(2 * THIS.pointerBorderWidth + THIS.pointerThickness) + 'px'; + p.sldPtrOB.style.top = '0'; + + // slider pointer middle border + p.sldPtrMB.style.border = THIS.pointerThickness + 'px solid ' + THIS.pointerColor; + + // slider pointer spacer + p.sldPtrS.style.width = THIS.sliderSize + 'px'; + p.sldPtrS.style.height = jsc.pub.sliderInnerSpace + 'px'; + + + // alpha slider + p.asld.style.overflow = 'hidden'; + p.asld.style.width = THIS.sliderSize + 'px'; + p.asld.style.height = THIS.height + 'px'; + + // alpha slider gradient + p.asldGrad.draw(THIS.sliderSize, THIS.height, '#000'); + + // alpha slider border + p.asldB.style.display = displayAlphaSlider ? 'block' : 'none'; + p.asldB.style.position = 'absolute'; + p.asldB.style.left = ( + (THIS.padding + THIS.width + 2 * THIS.controlBorderWidth + controlPadding) + + (displaySlider ? (THIS.sliderSize + 3 * controlPadding + 2 * THIS.controlBorderWidth) : 0) + ) + 'px'; + p.asldB.style.top = THIS.padding + 'px'; + p.asldB.style.border = THIS.controlBorderWidth + 'px solid'; + p.asldB.style.borderColor = THIS.controlBorderColor; + + // alpha slider mouse area + p.asldM.style.display = displayAlphaSlider ? 'block' : 'none'; + p.asldM.style.position = 'absolute'; + p.asldM.style.left = ( + (THIS.padding + THIS.width + 2 * THIS.controlBorderWidth + controlPadding) + + (displaySlider ? (THIS.sliderSize + 2 * controlPadding + 2 * THIS.controlBorderWidth) : 0) + ) + 'px'; + p.asldM.style.top = 0 + 'px'; + p.asldM.style.width = ( + (THIS.sliderSize + 2 * controlPadding + 2 * THIS.controlBorderWidth) + + Math.max(0, THIS.padding - controlPadding) // remaining padding to the right edge + ) + 'px'; + p.asldM.style.height = (2 * THIS.controlBorderWidth + 2 * THIS.padding + THIS.height) + 'px'; + p.asldM.style.cursor = 'default'; + jsc.setData(p.asldM, { + instance: THIS, + control: 'asld', + }) + + // alpha slider pointer inner and outer border + p.asldPtrIB.style.border = + p.asldPtrOB.style.border = + THIS.pointerBorderWidth + 'px solid ' + THIS.pointerBorderColor; + + // alpha slider pointer outer border + p.asldPtrOB.style.position = 'absolute'; + p.asldPtrOB.style.left = -(2 * THIS.pointerBorderWidth + THIS.pointerThickness) + 'px'; + p.asldPtrOB.style.top = '0'; + + // alpha slider pointer middle border + p.asldPtrMB.style.border = THIS.pointerThickness + 'px solid ' + THIS.pointerColor; + + // alpha slider pointer spacer + p.asldPtrS.style.width = THIS.sliderSize + 'px'; + p.asldPtrS.style.height = jsc.pub.sliderInnerSpace + 'px'; + + + // palette + p.pal.className = 'jscolor-palette'; + p.pal.style.display = pickerDims.palette.rows ? 'block' : 'none'; + p.pal.style.position = 'absolute'; + p.pal.style.left = THIS.padding + 'px'; + p.pal.style.top = (2 * THIS.controlBorderWidth + 2 * THIS.padding + THIS.height) + 'px'; + + // palette's color samples + + p.pal.innerHTML = ''; + + var chessboard = jsc.genColorPreviewCanvas('rgba(0,0,0,0)'); + + var si = 0; // color sample's index + for (var r = 0; r < pickerDims.palette.rows; r++) { + for (var c = 0; c < pickerDims.palette.cols && si < THIS._palette.length; c++, si++) { + var sampleColor = THIS._palette[si]; + var sampleCssColor = jsc.rgbaColor.apply(null, sampleColor.rgba); + + var sc = jsc.createEl('div'); // color sample's color + sc.style.width = (pickerDims.palette.cellW - 2 * THIS.controlBorderWidth) + 'px'; + sc.style.height = (pickerDims.palette.cellH - 2 * THIS.controlBorderWidth) + 'px'; + sc.style.backgroundColor = sampleCssColor; + + var sw = jsc.createEl('div'); // color sample's wrap + sw.className = 'jscolor-palette-sample'; + sw.style.display = 'block'; + sw.style.position = 'absolute'; + sw.style.left = ( + pickerDims.palette.cols <= 1 ? 0 : + Math.round(10 * (c * ((pickerDims.contentW - pickerDims.palette.cellW) / (pickerDims.palette.cols - 1)))) / 10 + ) + 'px'; + sw.style.top = (r * (pickerDims.palette.cellH + THIS.paletteSpacing)) + 'px'; + sw.style.border = THIS.controlBorderWidth + 'px solid'; + sw.style.borderColor = THIS.controlBorderColor; + sw.style.cursor = 'pointer'; + if (sampleColor.rgba[3] !== null && sampleColor.rgba[3] < 1.0) { // only create chessboard background if the sample has transparency + sw.style.backgroundImage = 'url(\'' + chessboard.canvas.toDataURL() + '\')'; + sw.style.backgroundRepeat = 'repeat'; + sw.style.backgroundPosition = 'center center'; + } + jsc.setData(sw, { + instance: THIS, + control: 'palette-sample', + color: sampleColor, + }) + sw.addEventListener('click', jsc.onPaletteSampleClick, false); + sw.appendChild(sc); + p.pal.appendChild(sw); + } + } + + + // the Close button + function setBtnBorder () { + var insetColors = THIS.controlBorderColor.split(/\s+/); + var outsetColor = insetColors.length < 2 ? insetColors[0] : insetColors[1] + ' ' + insetColors[0] + ' ' + insetColors[0] + ' ' + insetColors[1]; + p.btn.style.borderColor = outsetColor; + } + var btnPadding = 15; // px + p.btn.className = 'jscolor-btn-close'; + p.btn.style.display = THIS.closeButton ? 'block' : 'none'; + p.btn.style.position = 'absolute'; + p.btn.style.left = THIS.padding + 'px'; + p.btn.style.bottom = THIS.padding + 'px'; + p.btn.style.padding = '0 ' + btnPadding + 'px'; + p.btn.style.maxWidth = (pickerDims.contentW - 2 * THIS.controlBorderWidth - 2 * btnPadding) + 'px'; + p.btn.style.overflow = 'hidden'; + p.btn.style.height = THIS.buttonHeight + 'px'; + p.btn.style.whiteSpace = 'nowrap'; + p.btn.style.border = THIS.controlBorderWidth + 'px solid'; + setBtnBorder(); + p.btn.style.color = THIS.buttonColor; + p.btn.style.font = '12px sans-serif'; + p.btn.style.textAlign = 'center'; + p.btn.style.cursor = 'pointer'; + p.btn.onmousedown = function () { + THIS.hide(); + }; + p.btnT.style.lineHeight = THIS.buttonHeight + 'px'; + p.btnT.innerHTML = ''; + p.btnT.appendChild(window.document.createTextNode(THIS.closeText)); + + // reposition the pointers + redrawPad(); + redrawSld(); + redrawASld(); + + // If we are changing the owner without first closing the picker, + // make sure to first deal with the old owner + if (jsc.picker.owner && jsc.picker.owner !== THIS) { + jsc.removeClass(jsc.picker.owner.targetElement, jsc.pub.activeClassName); + } + + // Set a new picker owner + jsc.picker.owner = THIS; + + // The redrawPosition() method needs picker.owner to be set, that's why we call it here, + // after setting the owner + if (THIS.container === window.document.body) { + jsc.redrawPosition(); + } else { + jsc._drawPosition(THIS, 0, 0, 'relative', false); + } + + if (p.wrap.parentNode !== THIS.container) { + THIS.container.appendChild(p.wrap); + } + + jsc.addClass(THIS.targetElement, jsc.pub.activeClassName); + } + + + function redrawPad () { + // redraw the pad pointer + var yChannel = jsc.getPadYChannel(THIS); + var x = Math.round((THIS.channels.h / 360) * (THIS.width - 1)); + var y = Math.round((1 - THIS.channels[yChannel] / 100) * (THIS.height - 1)); + var crossOuterSize = (2 * THIS.pointerBorderWidth + THIS.pointerThickness + 2 * THIS.crossSize); + var ofs = -Math.floor(crossOuterSize / 2); + jsc.picker.cross.style.left = (x + ofs) + 'px'; + jsc.picker.cross.style.top = (y + ofs) + 'px'; + + // redraw the slider + switch (jsc.getSliderChannel(THIS)) { + case 's': + var rgb1 = jsc.HSV_RGB(THIS.channels.h, 100, THIS.channels.v); + var rgb2 = jsc.HSV_RGB(THIS.channels.h, 0, THIS.channels.v); + var color1 = 'rgb(' + + Math.round(rgb1[0]) + ',' + + Math.round(rgb1[1]) + ',' + + Math.round(rgb1[2]) + ')'; + var color2 = 'rgb(' + + Math.round(rgb2[0]) + ',' + + Math.round(rgb2[1]) + ',' + + Math.round(rgb2[2]) + ')'; + jsc.picker.sldGrad.draw(THIS.sliderSize, THIS.height, color1, color2); + break; + case 'v': + var rgb = jsc.HSV_RGB(THIS.channels.h, THIS.channels.s, 100); + var color1 = 'rgb(' + + Math.round(rgb[0]) + ',' + + Math.round(rgb[1]) + ',' + + Math.round(rgb[2]) + ')'; + var color2 = '#000'; + jsc.picker.sldGrad.draw(THIS.sliderSize, THIS.height, color1, color2); + break; + } + + // redraw the alpha slider + jsc.picker.asldGrad.draw(THIS.sliderSize, THIS.height, THIS.toHEXString()); + } + + + function redrawSld () { + var sldChannel = jsc.getSliderChannel(THIS); + if (sldChannel) { + // redraw the slider pointer + var y = Math.round((1 - THIS.channels[sldChannel] / 100) * (THIS.height - 1)); + jsc.picker.sldPtrOB.style.top = (y - (2 * THIS.pointerBorderWidth + THIS.pointerThickness) - Math.floor(jsc.pub.sliderInnerSpace / 2)) + 'px'; + } + + // redraw the alpha slider + jsc.picker.asldGrad.draw(THIS.sliderSize, THIS.height, THIS.toHEXString()); + } + + + function redrawASld () { + var y = Math.round((1 - THIS.channels.a) * (THIS.height - 1)); + jsc.picker.asldPtrOB.style.top = (y - (2 * THIS.pointerBorderWidth + THIS.pointerThickness) - Math.floor(jsc.pub.sliderInnerSpace / 2)) + 'px'; + } + + + function isPickerOwner () { + return jsc.picker && jsc.picker.owner === THIS; + } + + + function onValueKeyDown (ev) { + if (jsc.eventKey(ev) === 'Enter') { + if (THIS.valueElement) { + THIS.processValueInput(THIS.valueElement.value); + } + THIS.tryHide(); + } + } + + + function onAlphaKeyDown (ev) { + if (jsc.eventKey(ev) === 'Enter') { + if (THIS.alphaElement) { + THIS.processAlphaInput(THIS.alphaElement.value); + } + THIS.tryHide(); + } + } + + + function onValueChange (ev) { + if (jsc.getData(ev, 'internal')) { + return; // skip if the event was internally triggered by jscolor + } + + var oldVal = THIS.valueElement.value; + + THIS.processValueInput(THIS.valueElement.value); // this might change the value + + jsc.triggerCallback(THIS, 'onChange'); + + if (THIS.valueElement.value !== oldVal) { + // value was additionally changed -> let's trigger the change event again, even though it was natively dispatched + jsc.triggerInputEvent(THIS.valueElement, 'change', true, true); + } + } + + + function onAlphaChange (ev) { + if (jsc.getData(ev, 'internal')) { + return; // skip if the event was internally triggered by jscolor + } + + var oldVal = THIS.alphaElement.value; + + THIS.processAlphaInput(THIS.alphaElement.value); // this might change the value + + jsc.triggerCallback(THIS, 'onChange'); + + // triggering valueElement's onChange (because changing alpha changes the entire color, e.g. with rgba format) + jsc.triggerInputEvent(THIS.valueElement, 'change', true, true); + + if (THIS.alphaElement.value !== oldVal) { + // value was additionally changed -> let's trigger the change event again, even though it was natively dispatched + jsc.triggerInputEvent(THIS.alphaElement, 'change', true, true); + } + } + + + function onValueInput (ev) { + if (jsc.getData(ev, 'internal')) { + return; // skip if the event was internally triggered by jscolor + } + + if (THIS.valueElement) { + THIS.fromString(THIS.valueElement.value, jsc.flags.leaveValue); + } + + jsc.triggerCallback(THIS, 'onInput'); + + // triggering valueElement's onInput + // (not needed, it was dispatched normally by the browser) + } + + + function onAlphaInput (ev) { + if (jsc.getData(ev, 'internal')) { + return; // skip if the event was internally triggered by jscolor + } + + if (THIS.alphaElement) { + THIS.fromHSVA(null, null, null, parseFloat(THIS.alphaElement.value), jsc.flags.leaveAlpha); + } + + jsc.triggerCallback(THIS, 'onInput'); + + // triggering valueElement's onInput (because changing alpha changes the entire color, e.g. with rgba format) + jsc.triggerInputEvent(THIS.valueElement, 'input', true, true); + } + + + // let's process the DEPRECATED 'options' property (this will be later removed) + if (jsc.pub.options) { + // let's set custom default options, if specified + for (var opt in jsc.pub.options) { + if (jsc.pub.options.hasOwnProperty(opt)) { + try { + setOption(opt, jsc.pub.options[opt]); + } catch (e) { + console.warn(e); + } + } + } + } + + + // let's apply configuration presets + // + var presetsArr = []; + + if (opts.preset) { + if (typeof opts.preset === 'string') { + presetsArr = opts.preset.split(/\s+/); + } else if (Array.isArray(opts.preset)) { + presetsArr = opts.preset.slice(); // slice() to clone + } else { + console.warn('Unrecognized preset value'); + } + } + + // always use the 'default' preset. If it's not listed, append it to the end. + if (presetsArr.indexOf('default') === -1) { + presetsArr.push('default'); + } + + // let's apply the presets in reverse order, so that should there be any overlapping options, + // the formerly listed preset will override the latter + for (var i = presetsArr.length - 1; i >= 0; i -= 1) { + var pres = presetsArr[i]; + if (!pres) { + continue; // preset is empty string + } + if (!jsc.pub.presets.hasOwnProperty(pres)) { + console.warn('Unknown preset: %s', pres); + continue; + } + for (var opt in jsc.pub.presets[pres]) { + if (jsc.pub.presets[pres].hasOwnProperty(opt)) { + try { + setOption(opt, jsc.pub.presets[pres][opt]); + } catch (e) { + console.warn(e); + } + } + } + } + + + // let's set specific options for this color picker + var nonProperties = [ + // these options won't be set as instance properties + 'preset', + ]; + for (var opt in opts) { + if (opts.hasOwnProperty(opt)) { + if (nonProperties.indexOf(opt) === -1) { + try { + setOption(opt, opts[opt]); + } catch (e) { + console.warn(e); + } + } + } + } + + + // + // Install the color picker on chosen element(s) + // + + + // Determine picker's container element + if (this.container === undefined) { + this.container = window.document.body; // default container is BODY element + + } else { // explicitly set to custom element + this.container = jsc.node(this.container); + } + + if (!this.container) { + throw new Error('Cannot instantiate color picker without a container element'); + } + + + // Fetch the target element + this.targetElement = jsc.node(targetElement); + + if (!this.targetElement) { + // temporarily customized error message to help with migrating from versions prior to 2.2 + if (typeof targetElement === 'string' && /^[a-zA-Z][\w:.-]*$/.test(targetElement)) { + // targetElement looks like valid ID + var possiblyId = targetElement; + throw new Error('If \'' + possiblyId + '\' is supposed to be an ID, please use \'#' + possiblyId + '\' or any valid CSS selector.'); + } + + throw new Error('Cannot instantiate color picker without a target element'); + } + + if (this.targetElement.jscolor && this.targetElement.jscolor instanceof jsc.pub) { + throw new Error('Color picker already installed on this element'); + } + + + // link this instance with the target element + this.targetElement.jscolor = this; + jsc.addClass(this.targetElement, jsc.pub.className); + + // register this instance + jsc.instances.push(this); + + + // if target is BUTTON + if (jsc.isButton(this.targetElement)) { + + if (this.targetElement.type.toLowerCase() !== 'button') { + // on buttons, always force type to be 'button', e.g. in situations the target