Commit 50dc76eb authored by Chris Klinger's avatar Chris Klinger
Browse files

Initial code commit

parent 1ff141f6
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ArduinoJson.h>
#include "names.h"
#include "web_interface.h"
#include "web_iro_js.h"
const char* ssid = "your_ssid";
const char* password = "your_wifi_password";
const char* deviceName = "wifi-rgb";
#define BUILTIN_LED 2 // internal ESP-12 LED on GPIO2
#define REDPIN 12
#define GREENPIN 14
#define BLUEPIN 5
ESP8266WebServer server(80);
IPAddress clientIP(192, 168, 178, 254); //the IP of the device
IPAddress gateway(192, 168, 178, 1); //the gateway
IPAddress subnet(255, 255, 255, 0); //the subnet mask
void setup(void) {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.hostname(deviceName);
WiFi.config(clientIP, gateway, subnet); // Remove for DHCP
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
digitalWrite(BUILTIN_LED, LOW); // Turn the LED ON by making the voltage LOW after wifi is connected
// adjust the PWM range
// see https://esp8266.github.io/Arduino/versions/2.0.0/doc/reference.html#analog-output
analogWriteRange(255);
// Root and 404
server.on("/", handleRoot);
server.onNotFound(handleNotFound);
// REST-API
server.on("/api/v1/state", HTTP_POST, handleApiRequest);
// iro.js User Interface and Javascript
server.on("/ui", HTTP_GET, []() {
server.send(200, "text/html", WEBINTERFACE);
});
server.on("/iro.min.js", HTTP_GET, []() {
server.send(200, "application/javascript", IRO_JS);
});
server.begin();
Serial.println("WifiRGB HTTP server started");
}
void loop(void) {
server.handleClient();
}
void handleRoot() {
server.send(200, "text/plain", "hello from esp8266 wifi rgb!");
}
void handleNotFound() {
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++) {
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
}
void handleApiRequest() {
if (server.hasArg("plain") == false) { //Check if body received
server.send(200, "text/plain", "Body not received");
return;
}
DynamicJsonBuffer jsonBuffer(190);
JsonObject& root = jsonBuffer.parseObject(server.arg("plain"));
Serial.println("JSON Body: ");
root.printTo(Serial);
Serial.println();
const char* state = root["state"]; // "ON" or "OFF"
if(strcmp("OFF", state) == 0) {
Serial.println("Switching OFF!");
// Set Output
analogWrite(REDPIN, 0);
analogWrite(GREENPIN, 0);
analogWrite(BLUEPIN, 0);
server.send(200, "application/json", server.arg("plain"));
return;
}
int brightness = root["brightness"];
Serial.print("Brightness: ");
Serial.println(brightness);
RGB rgb = {0, 0, 0};
root["color"].printTo(Serial);
// If RGB mode: Parse RGB values
if(strcmp("rgb", root["color"]["mode"]) == 0) {
Serial.println("Reading RGB values...");
rgb.r = root["color"]["r"];
rgb.b = root["color"]["g"];
rgb.g = root["color"]["b"];
}
// Parse HSV
if(strcmp("hsv", root["color"]["mode"]) == 0) {
Serial.println("Reading HSV values...");
rgb = hsvToRgb(root["color"]["h"], root["color"]["s"], root["color"]["v"]);
}
// DEBUG: Parsed values
Serial.println("Parsed Values:");
Serial.print("r=");
Serial.print(rgb.r);
Serial.print(", g=");
Serial.print(rgb.g);
Serial.print(", b=");
Serial.println(rgb.b);
// Map Brightness
byte mappedRed = map(rgb.r, 0, 100, 0, brightness);
byte mappedGreen = map(rgb.g, 0, 100, 0, brightness);
byte mappedBlue = map(rgb.b, 0, 100, 0, brightness);
Serial.println("Brighness Mapped RGB Values:");
Serial.print("r=");
Serial.print(mappedRed);
Serial.print(", g=");
Serial.print(mappedGreen);
Serial.print(", b=");
Serial.println(mappedBlue);
// TODO: support different modes
const char* jsonrgbmode = root["mode"]; // "SOLID"
// Set Output
analogWrite(REDPIN, mappedRed);
analogWrite(GREENPIN, mappedGreen);
analogWrite(BLUEPIN, mappedBlue);
server.send(200, "application/json", server.arg("plain"));
}
// this is a modified version of https://gist.github.com/hdznrrd/656996
RGB hsvToRgb(double h, double s, double v) {
int i;
double f, p, q, t;
byte r, g, b;
h = max(0.0, min(360.0, h));
s = max(0.0, min(100.0, s));
v = max(0.0, min(100.0, v));
s /= 100;
v /= 100;
if (s == 0) {
// Achromatic (grey)
r = g = b = round(v * 255);
return {0,0,0};
}
h /= 60; // sector 0 to 5
i = floor(h);
f = h - i; // factorial part of h
p = v * (1 - s);
q = v * (1 - s * f);
t = v * (1 - s * (1 - f));
switch (i) {
case 0:
r = round(255 * v);
g = round(255 * t);
b = round(255 * p);
break;
case 1:
r = round(255 * q);
g = round(255 * v);
b = round(255 * p);
break;
case 2:
r = round(255 * p);
g = round(255 * v);
b = round(255 * t);
break;
case 3:
r = round(255 * p);
g = round(255 * q);
b = round(255 * v);
break;
case 4:
r = round(255 * t);
g = round(255 * p);
b = round(255 * v);
break;
default: // case 5:
r = round(255 * v);
g = round(255 * p);
b = round(255 * q);
}
return {r, g, b};
}
struct RGB {
byte r;
byte g;
byte b;
};
const char WEBINTERFACE[] PROGMEM = R"=====(
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WifiRGB Controller Interface</title>
<script type="text/javascript" src="iro.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<style>
body {
color: #fff;
background: #272727;
text-align: center;
}
#color-picker-container svg {
margin: 48px auto;
}
</style>
</head>
<body>
<div id="color-picker-container"></div>
<script type="text/javascript">
var size = 0;
if (window.innerWidth > window.innerHeight) {
size = window.innerHeight * 0.8;
} else {
size = window.innerWidth * 0.8;
}
var demoColorPicker = new iro.ColorPicker("#color-picker-container", {
// color picker options
// Option guide: https://rakujira.jp/projects/iro/docs/guide.html#Color-Picker-Options
width: size,
height: size,
color: {r: 0, g: 0, b: 0},
anticlockwise: true,
borderWidth: 10,
borderColor: "#313131"
});
demoColorPicker.on("color:change", function(color, changes) {
// Log the color's hex RGB value to the dev console
console.log(color.rgb);
console.log(color.hsv.v);
// If the "H" channel has changed, log the color's HSV value too
//if (changes.h) {
// console.log(color.hsv);
//}
var json = {state:"ON",brightness:color.hsv.v,color:{r:color.rgb.r,g:color.rgb.g,b:color.rgb.b},mode:"SOLID"};
console.log(json);
console.log(JSON.stringify(json));
$.ajax( "/api/v1/state", { data: JSON.stringify(json), dataType: "json", method: "POST", contentType: "application/json"})
.done(function( data ) {
console.log( "Response: " );
console.log( data );
})
.fail(function( data ) {
console.log( "Error: " );
console.log( data );
});
});
</script>
</body>
</html>
)=====";
const char IRO_JS[] PROGMEM = R"=====(
//iro.js v3.4.1
//2016-2018 James Daniel
//Released under the MIT license
//github.com/jaames/iro.js
//
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.iro=e():t.iro=e()}(this,function(){return function(t){function e(s){if(r[s])return r[s].exports;var n=r[s]={i:s,l:!1,exports:{}};return t[s].call(n.exports,n,n.exports,e),n.l=!0,n.exports}var r={};return e.m=t,e.c=r,e.i=function(t){return t},e.d=function(t,r,s){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:s})},e.n=function(t){var r=t&&t.t?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=4)}([function(t,e,r){"use strict";function s(t){var e,r,s,n,i,o,a,h,c=t.h/360,u=t.s/100,l=t.v/100;switch(n=k(6*c),i=6*c-n,o=l*(1-u),a=l*(1-i*u),h=l*(1-(1-i)*u),n%6){case 0:e=l,r=h,s=o;break;case 1:e=a,r=l,s=o;break;case 2:e=o,r=l,s=h;break;case 3:e=o,r=a,s=l;break;case 4:e=h,r=o,s=l;break;case 5:e=l,r=o,s=a}return{r:w(255*e),g:w(255*r),b:w(255*s)}}function n(t){var e,r=t.r/255,s=t.g/255,n=t.b/255,i=Math.max(r,s,n),o=Math.min(r,s,n),a=i-o;switch(i){case o:e=0;break;case r:e=(s-n)/a+(s<n?6:0);break;case s:e=(n-r)/a+2;break;case n:e=(r-s)/a+4}return e/=6,{h:360*e,s:0==i?0:a/i*100,v:100*i}}function i(t){var e=t.s/100,r=t.v/100,s=.5*r*(2-e);return e=r*e/(1-Math.abs(2*s-1)),{h:t.h,s:100*e||0,l:100*s}}function o(t){var e=t.s/100,r=t.l/100;return r*=2,e*=r<=1?r:2-r,{h:t.h,s:2*e/(r+e)*100,v:(r+e)/2*100}}function a(t){return"rgb"+(t.a?"a":"")+"("+t.r+", "+t.g+", "+t.b+(t.a?", "+t.a:"")+")"}function h(t){return"hsl"+(t.a?"a":"")+"("+t.h+", "+t.s+"%, "+t.l+"%"+(t.a?", "+t.a:"")+")"}function c(t){var e="#";return e+=t.r.toString(16).padStart(2,"0"),e+=t.g.toString(16).padStart(2,"0"),e+=t.b.toString(16).padStart(2,"0")}function u(t,e){var r=t.match(/(\S+)\((\d+)(%?)(?:\D+?)(\d+)(%?)(?:\D+?)(\d+)(%?)(?:\D+?)?([0-9\.]+?)?\)/i),s=parseInt(r[2]),n=parseInt(r[4]),i=parseInt(r[6]);return[r[1],"%"==r[3]?s/100*e[0]:s,"%"==r[5]?n/100*e[1]:n,"%"==r[7]?i/100*e[2]:i,parseFloat(r[8])||void 0]}function l(t){var e=u(t,[255,255,255]);return{r:e[1],g:e[2],b:e[3]}}function f(t){var e=u(t,[360,100,100]);return{h:e[2],s:e[3],l:e[4]}}function v(t){t=t.replace("#","");var e=parseInt("0x"+t),r=3==t.length,s=r?15:255,n=r?4:8,i=r?17:1;return{r:(e>>2*n&s)*i,g:(e>>n&s)*i,b:(e&s)*i}}function p(t){return t instanceof x?t:new x(t)}function d(t,e,r){return t<=e?e:t>=r?r:t}function g(t,e){var r={};for(var s in t)r[s]=e[s]!=t[s];return r}function m(t,e,r){var s=p(t).rgb,n=p(e).rgb;return r=d(r/100||.5,0,1),new x({r:k(s.r+(n.r-s.r)*r),g:k(s.g+(n.g-s.g)*r),b:k(s.b+(n.b-s.b)*r)})}function _(t,e){var r=p(t),s=r.hsv;return s.v=d(s.v+e,0,100),r.hsv=s,r}function y(t,e){var r=p(t),s=r.hsv;return s.v=d(s.v-e,0,100),r.hsv=s,r}var b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},w=Math.round,k=Math.floor,x=function(t){this.e=!1,this.u={h:void 0,s:void 0,v:void 0},t&&this.set(t)};x.mix=m,x.lighten=_,x.darken=y,x.hsv2Rgb=s,x.rgb2Hsv=n,x.hsv2Hsl=i,x.hsl2Hsv=o,x.hsl2Str=h,x.rgb2Str=a,x.rgb2Hex=c,x.parseHexStr=v,x.parseHslStr=f,x.parseRgbStr=l,x.prototype={constructor:x,set:function(t){"object"==(void 0===t?"undefined":b(t))?t instanceof x?this.hsv=x.hsv:"r"in t?this.rgb=t:"v"in t?this.hsv=t:"l"in t&&(this.hsl=t):"string"==typeof t&&(/^rgb/.test(t)?this.rgbString=t:/^hsl/.test(t)?this.hslString=t:/^#[0-9A-Fa-f]/.test(t)&&(this.hexString=t))},setChannel:function(t,e,r){var s=this[t];s[e]=r,this[t]=s},clone:function(){return new x(this)},compare:function(t,e){return e=e||"hsv",g(this[e],p(t)[e])},mix:function(t,e){this.hsv=m(this,t,e).hsv},lighten:function(t){_(this,t)},darken:function(t){y(this,t)}},Object.defineProperties(x.prototype,{hsv:{get:function(){var t=this.u;return{h:t.h,s:t.s,v:t.v}},set:function(t){if(this.e){var e=this.u;for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r]);var s=g(e,t);this.u=t,(s.h||s.s||s.v)&&this.e(this,s)}else this.u=t}},rgb:{get:function(){var t=s(this.u);return{r:w(t.r),g:w(t.g),b:w(t.b)}},set:function(t){this.hsv=n(t)}},hsl:{get:function(){var t=i(this.u);return{h:w(t.h),s:w(t.s),l:w(t.l)}},set:function(t){this.hsv=o(t)}},rgbString:{get:function(){return a(this.rgb)},set:function(t){this.rgb=l(t)}},hexString:{get:function(){return c(this.rgb)},set:function(t){this.rgb=v(t)}},hslString:{get:function(){return h(this.hsl)},set:function(t){this.hsl=x.parseHslStr(t)}}}),t.exports=x},function(t,e,r){"use strict";var s=function(){var t=document.createElement("style");document.head.appendChild(t),t.appendChild(document.createTextNode("")),this.style=t;var e=t.sheet;this.sheet=e,this.rules=e.rules||e.cssRules,this.map={}};s.prototype={constructor:s,setRule:function(t,e,r){var s=this.sheet,n=s.rules||s.cssRules,i=this.map;if(e=e.replace(/([A-Z])/g,function(t){return"-"+t.toLowerCase()}),i.hasOwnProperty(t))i[t].setProperty(e,r);else{var o=n.length,a=e+": "+r;try{s.insertRule(t+" {"+a+";}",o)}catch(e){s.addRule(t,a,o)}finally{n=s.rules||s.cssRules,i[t]=n[o].style}}}},Object.defineProperties(s.prototype,{enabled:{get:function(){return!this.sheet.disabled},set:function(t){this.sheet.disabled=!t}},cssText:{get:function(){var t=this.map,e=[];for(var r in t)e.push(r.replace(/,\W/g,",\n")+" {\n\t"+t[r].cssText.replace(/;\W/g,";\n\t")+"\n}");return e.join("\n")}},css:{get:function(){var t=this.map,e={};for(var r in t){var s=t[r];e[r]={};for(var n=0;n<s.length;n++){var i=s[n];e[r][i]=s.getPropertyValue(i)}}return e}}}),t.exports=s},function(t,e,r){"use strict";var s=function(t,e){var r=t.g({f:"iro__marker"});r._(0,0,e.r,{f:"iro__marker__outer",fill:"none",k:5,M:"#000"}),r._(0,0,e.r,{f:"iro__marker__inner",fill:"none",k:2,M:"#fff"}),this.g=r};s.prototype={constructor:s,move:function(t,e){this.g.S("translate",[t,e])}},t.exports=s},function(t,e,r){"use strict";function s(t){return t&&t.t?t:{default:t}}function n(t,e,r){for(var s=0;s<e.length;s++)t.addEventListener(e[s],r)}function i(t,e,r){for(var s=0;s<e.length;s++)t.removeEventListener(e[s],r)}function o(t){document.readyState==_?t():n(document,[m],function e(r){document.readyState==_&&(t(),i(document,[m],e))})}var a=r(7),h=s(a),c=r(5),u=s(c),l=r(6),f=s(l),v=r(0),p=s(v),d=r(1),g=s(d),m="readystatechange",_="complete",y=function(t,e){var r=this;e=e||{},this.C={},this.T=!1,this.A=!1,this.css=e.css||e.styles||void 0,o(function(){r.j(t,e)})};y.prototype={constructor:y,j:function(t,e){var r=this;t="string"==typeof t?document.querySelector(t):t;var s=e.width||parseInt(t.width)||320,i=e.height||parseInt(t.height)||320,o=e.padding+2||6,a=e.borderWidth||0,c=e.markerRadius||8,l=e.sliderMargin||24,v=e.sliderHeight||2*c+2*o+2*a,d=Math.min(i-v-l,s),m=d/2-a,_=(s-d)/2,y={r:c},b={w:a,color:e.borderColor||"#fff"};this.el=t,this.svg=new f.default(t,s,i,e.display),this.ui=[new h.default(this.svg,{cX:_+d/2,cY:d/2,r:m,rMax:m-(c+o),marker:y,border:b,lightness:void 0==e.wheelLightness||e.wheelLightness,anticlockwise:e.anticlockwise}),new u.default(this.svg,{sliderType:"v",x:_+a,y:d+l,w:d-2*a,h:v-2*a,r:v/2-a,marker:y,border:b})],this.stylesheet=new g.default,this.color=new p.default,this.color.e=this.H.bind(this),this.color.set(e.color||e.defaultValue||"#fff"),this.on("history:stateChange",function(t){r.svg.updateUrls(t)}),n(this.svg.el,["mousedown","touchstart"],this),this.emit("mount",this)},H:function(t,e){for(var r=t.rgbString,s=this.css,n=0;n<this.ui.length;n++)this.ui[n].update(t,e);for(var i in s){var o=s[i];for(var a in o)this.stylesheet.setRule(i,a,r)}this.A||(this.A=!0,this.emit("color:change",t,e),this.A=!1)},on:function(t,e){var r=this.C;(r[t]||(r[t]=[])).push(e)},off:function(t,e){var r=this.C[t];r&&r.splice(r.indexOf(e),1)},emit:function(t){for(var e=this.C,r=(e[t]||[]).concat(e["*"]||[]),s=arguments.length,n=Array(s>1?s-1:0),i=1;i<s;i++)n[i-1]=arguments[i];for(var o=0;o<r.length;o++)r[o].apply(null,n)},handleEvent:function(t){var e=t.touches?t.changedTouches[0]:t,r=this.svg.el.getBoundingClientRect(),s=e.clientX-r.left,o=e.clientY-r.top;switch(t.type){case"mousedown":case"touchstart":for(var a=0;a<this.ui.length;a++){var h=this.ui[a];h.checkHit(s,o)&&(this.T=h,n(document,["mousemove","touchmove","mouseup","touchend"],this),this.emit("input:start",this.color),this.color.hsv=this.T.input(s,o))}break;case"mousemove":case"touchmove":this.color.hsv=this.T.input(s,o);break;case"mouseup":case"touchend":this.T=!1,this.emit("input:end",this.color),i(document,["mousemove","touchmove","mouseup","touchend"],this)}this.T&&t.preventDefault()}},t.exports=y},function(t,e,r){"use strict";function s(t){return t&&t.t?t:{default:t}}var n=r(3),i=s(n),o=r(0),a=s(o),h=r(1),c=s(h);t.exports={Color:a.default,ColorPicker:i.default,Stylesheet:c.default,version:"3.4.1"}},function(t,e,r){"use strict";function s(t){return t&&t.t?t:{default:t}}var n=r(2),i=s(n),o=r(0),a=s(o),h=function(t,e){var r=e.r,s=e.w,n=e.h,o=e.x,a=e.y,h=e.border.w;e.range={min:o+r,max:o+s-r,w:s-2*r},e.sliderType=e.sliderType||"v",this.type="slider",this.P=e;var c=r+h/2,u=t.g({f:"iro__slider"}),l=u.R("rect",{f:"iro__slider__value",rx:c,ry:c,x:o-h/2,y:a-h/2,width:s+h,height:n+h,k:h,M:e.border.color});l.setGradient("fill",t.O("linear",{0:{color:"#000"},100:{color:"#fff"}})),this.I=l.O,this.marker=new i.default(u,e.marker)};h.prototype={constructor:h,update:function(t,e){var r=this.P,s=r.range,n=t.hsv,i=a.default.hsv2Hsl({h:n.h,s:n.s,v:100});if("v"==r.sliderType&&((e.h||e.s)&&this.I.stops[1].W({L:"hsl("+i.h+","+i.s+"%,"+i.l+"%)"}),e.v)){var o=n.v/100;this.marker.move(s.min+o*s.w,r.y+r.h/2)}},input:function(t,e){var r=this.P,s=r.range,n=Math.max(Math.min(t,s.max),s.min)-s.min;return{v:Math.round(100/s.w*n)}},checkHit:function(t,e){var r=this.P;return t>r.x&&t<r.x+r.w&&e>r.y&&e<r.y+r.h}},t.exports=h},function(t,e,r){"use strict";var s=0,n={f:"class",M:"stroke",k:"stroke-width",fill:"fill",G:"opacity",X:"offset",L:"stop-color",Y:"stop-opacity"},i={translate:"setTranslate",scale:"setScale",rotate:"setRotate"},o=window.navigator.userAgent.toLowerCase(),a=/msie|trident|edge/.test(o),h=/^((?!chrome|android).)*safari/i.test(o),c=function(t,e,r,s){var n=document.createElementNS("http://www.w3.org/2000/svg",r);this.el=n,this.W(s),(e.el||e).appendChild(n),this.U=t,this.D={},this.V=!!n.transform&&n.transform.baseVal};c.prototype={constructor:c,R:function(t,e){return new c(this.U,this,t,e)},g:function(t){return this.R("g",t)},F:function(t,e,r,s,n,i){var o=n-s<=180?0:1;s*=Math.PI/180,n*=Math.PI/180;var a=t+r*Math.cos(n),h=e+r*Math.sin(n),c=t+r*Math.cos(s),u=e+r*Math.sin(s);return i=i||{},i.d=["M",a,h,"A",r,r,0,o,0,c,u].join(" "),this.R("path",i)},_:function(t,e,r,s){return s=s||{},s.cx=t,s.cy=e,s.r=r,this.R("circle",s)},S:function(t,e){if(a)this.W({transform:t+"("+e.join(", ")+")"});else{var r,s,n=this.D;n[t]?r=n[t]:(r=this.U.el.createSVGTransform(),n[t]=r,this.V.appendItem(r)),s=t in i?i[t]:t,r[s].apply(r,e)}},W:function(t){for(var e in t){var r=e in n?n[e]:e;this.el.setAttribute(r,t[e])}},setGradient:function(t,e){var r={};r[t]=e.getUrl(),e.q[t]=this,this.O=e,this.W(r)}};var u=function(t,e,r){var n=[],i=t.N.R(e+"Gradient",{id:"iroGradient"+s++});for(var o in r){var a=r[o];n.push(i.R("stop",{X:o+"%",L:a.color,Y:void 0===a.G?1:a.G}))}this.el=i.el,this.stops=n,this.q={}};u.prototype.getUrl=function(t){return"url("+(h?t||window.location.href:"")+"#"+this.el.id+")"};var l=function(t,e,r,s){c.call(this,this,t,"svg",{width:e,height:r,style:"display:"+(s||"block")}),this.N=this.R("defs"),this.B=[]};l.prototype=Object.create(c.prototype),l.prototype.constructor=l,l.prototype.O=function(t,e){var r=new u(this,t,e);return this.B.push(r),r},l.prototype.updateUrls=function(t){if(h)for(var e=this.B,r=0;r<e.length;r++)for(var s in e[r].q){var n={};n[s]=e[r].getUrl(t),e[r].q[s].W(n)}},t.exports=l},function(t,e,r){"use strict";var s=r(2),n=function(t){return t&&t.t?t:{default:t}}(s),i=Math.PI,o=Math.sqrt,a=Math.abs,h=Math.round,c=function(t,e){this.P=e,this.type="wheel";var r=e.cY,s=e.cX,i=e.r,o=e.border,a=t.g({f:"iro__wheel"});a._(s,r,i+o.w/2,{f:"iro__wheel__border",fill:"#fff",M:o.color,k:o.w});for(var h=a.g({f:"iro__wheel__hue",k:i,fill:"none"}),c=0;c<360;c++)h.F(s,r,i/2,c,c+1.5,{M:"hsl("+(e.anticlockwise?360-c:c)+",100%,50%)"});a._(s,r,i,{f:"iro__wheel__saturation"}).setGradient("fill",t.O("radial",{0:{color:"#fff"},100:{color:"#fff",G:0}})),this.Z=a._(s,r,i,{f:"iro__wheel__lightness",G:0}),this.marker=new n.default(a,e.marker)};c.prototype={constructor:c,update:function(t,e){var r=this.P,s=t.hsv;if(e.v&&r.lightness&&this.Z.W({G:(1-s.v/100).toFixed(2)}),e.h||e.s){var n=(r.anticlockwise?360-s.h:s.h)*(i/180),o=s.s/100*r.rMax;this.marker.move(r.cX+o*Math.cos(n),r.cY+o*Math.sin(n))}},input:function(t,e){var r=this.P,s=r.rMax,n=r.cX-t,a=r.cY-e,c=Math.atan2(a,n),u=h(c*(180/i))+180,l=Math.min(o(n*n+a*a),s);return u=r.anticlockwise?360-u:u,{h:u,s:h(100/s*l)}},checkHit:function(t,e){var r=this.P,s=a(t-r.cX),n=a(e-r.cY);return o(s*s+n*n)<r.r}},t.exports=c}])});
)=====";
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment