8 lines
21 KiB
JavaScript
8 lines
21 KiB
JavaScript
/*!
|
|
* iro.js v4.5.0
|
|
* 2016-2019 James Daniel
|
|
* Licensed under MPL 2.0
|
|
* github.com/jaames/iro.js
|
|
*/
|
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.iro=e()}(this,function(){"use strict";var c=function(){},i={},h=[],u=[];function p(t,e){var n,o,r,i,s=arguments,a=u;for(i=arguments.length;2<i--;)h.push(s[i]);for(e&&null!=e.children&&(h.length||h.push(e.children),delete e.children);h.length;)if((o=h.pop())&&void 0!==o.pop)for(i=o.length;i--;)h.push(o[i]);else"boolean"==typeof o&&(o=null),(r="function"!=typeof t)&&(null==o?o="":"number"==typeof o?o=String(o):"string"!=typeof o&&(r=!1)),r&&n?a[a.length-1]+=o:a===u?a=[o]:a.push(o),n=r;var l=new c;return l.nodeName=t,l.children=a,l.attributes=null==e?void 0:e,l.key=null==e?void 0:e.key,l}function M(t,e){for(var n in e)t[n]=e[n];return t}function l(t,e){null!=t&&("function"==typeof t?t(e):t.current=e)}var e="function"==typeof Promise?Promise.resolve().then.bind(Promise.resolve()):setTimeout,f=/acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i,n=[];function s(t){!t._dirty&&(t._dirty=!0)&&1==n.push(t)&&e(o)}function o(){for(var t;t=n.pop();)t._dirty&&I(t)}function S(t,e){return t.normalizedNodeName===e||t.nodeName.toLowerCase()===e.toLowerCase()}function E(t){var e=M({},t.attributes);e.children=t.children;var n=t.nodeName.defaultProps;if(void 0!==n)for(var o in n)void 0===e[o]&&(e[o]=n[o]);return e}function N(t){var e=t.parentNode;e&&e.removeChild(t)}function d(t,e,n,o,r){if("className"===e&&(e="class"),"key"===e);else if("ref"===e)l(n,null),l(o,t);else if("class"!==e||r)if("style"===e){if(o&&"string"!=typeof o&&"string"!=typeof n||(t.style.cssText=o||""),o&&"object"==typeof o){if("string"!=typeof n)for(var i in n)i in o||(t.style[i]="");for(var i in o)t.style[i]="number"==typeof o[i]&&!1===f.test(i)?o[i]+"px":o[i]}}else if("dangerouslySetInnerHTML"===e)o&&(t.innerHTML=o.__html||"");else if("o"==e[0]&&"n"==e[1]){var s=e!==(e=e.replace(/Capture$/,""));e=e.toLowerCase().substring(2),o?n||t.addEventListener(e,v,s):t.removeEventListener(e,v,s),(t._listeners||(t._listeners={}))[e]=o}else if("list"!==e&&"type"!==e&&!r&&e in t){try{t[e]=null==o?"":o}catch(t){}null!=o&&!1!==o||"spellcheck"==e||t.removeAttribute(e)}else{var a=r&&e!==(e=e.replace(/^xlink:?/,""));null==o||!1===o?a?t.removeAttributeNS("http://www.w3.org/1999/xlink",e.toLowerCase()):t.removeAttribute(e):"function"!=typeof o&&(a?t.setAttributeNS("http://www.w3.org/1999/xlink",e.toLowerCase(),o):t.setAttribute(e,o))}else t.className=o||""}function v(t){return this._listeners[t.type](t)}var H=[],T=0,g=!1,_=!1;function P(){for(var t;t=H.shift();)t.componentDidMount&&t.componentDidMount()}function A(t,e,n,o,r,i){T++||(g=null!=r&&void 0!==r.ownerSVGElement,_=null!=t&&!("__preactattr_"in t));var s=U(t,e,n,o,i);return r&&s.parentNode!==r&&r.appendChild(s),--T||(_=!1,i||P()),s}function U(t,e,n,o,r){var i=t,s=g;if(null!=e&&"boolean"!=typeof e||(e=""),"string"==typeof e||"number"==typeof e)return t&&void 0!==t.splitText&&t.parentNode&&(!t._component||r)?t.nodeValue!=e&&(t.nodeValue=e):(i=document.createTextNode(e),t&&(t.parentNode&&t.parentNode.replaceChild(i,t),O(t,!0))),i.__preactattr_=!0,i;var a=e.nodeName;if("function"==typeof a)return function(t,e,n,o){var r=t&&t._component,i=r,s=t,a=r&&t._componentConstructor===e.nodeName,l=a,c=E(e);for(;r&&!l&&(r=r._parentComponent);)l=r.constructor===e.nodeName;r&&l&&(!o||r._component)?(j(r,c,3,n,o),t=r.base):(i&&!a&&(L(i),t=s=null),r=R(e.nodeName,c,n),t&&!r.nextBase&&(r.nextBase=t,s=null),j(r,c,1,n,o),t=r.base,s&&t!==s&&(s._component=null,O(s,!1)));return t}(t,e,n,o);if(g="svg"===a||"foreignObject"!==a&&g,a=String(a),(!t||!S(t,a))&&(i=function(t,e){var n=e?document.createElementNS("http://www.w3.org/2000/svg",t):document.createElement(t);return n.normalizedNodeName=t,n}(a,g),t)){for(;t.firstChild;)i.appendChild(t.firstChild);t.parentNode&&t.parentNode.replaceChild(i,t),O(t,!0)}var l=i.firstChild,c=i.__preactattr_,h=e.children;if(null==c){c=i.__preactattr_={};for(var u=i.attributes,p=u.length;p--;)c[u[p].name]=u[p].value}return!_&&h&&1===h.length&&"string"==typeof h[0]&&null!=l&&void 0!==l.splitText&&null==l.nextSibling?l.nodeValue!=h[0]&&(l.nodeValue=h[0]):(h&&h.length||null!=l)&&function(t,e,n,o,r){var i,s,a,l,c,h=t.childNodes,u=[],p={},f=0,d=0,v=h.length,g=0,_=e?e.length:0;if(0!==v)for(var m=0;m<v;m++){var y=h[m],b=y.__preactattr_;null!=(w=_&&b?y._component?y._component.__key:b.key:null)?(f++,p[w]=y):(b||(void 0!==y.splitText?!r||y.nodeValue.trim():r))&&(u[g++]=y)}if(0!==_)for(m=0;m<_;m++){var w;if(l=e[m],(c=null)!=(w=l.key))f&&void 0!==p[w]&&(c=p[w],p[w]=void 0,f--);else if(d<g)for(i=d;i<g;i++)if(void 0!==u[i]&&(x=s=u[i],C=r,"string"==typeof(k=l)||"number"==typeof k?void 0!==x.splitText:"string"==typeof k.nodeName?!x._componentConstructor&&S(x,k.nodeName):C||x._componentConstructor===k.nodeName)){c=s,u[i]=void 0,i===g-1&&g--,i===d&&d++;break}c=U(c,l,n,o),a=h[m],c&&c!==t&&c!==a&&(null==a?t.appendChild(c):c===a.nextSibling?N(a):t.insertBefore(c,a))}var x,k,C;if(f)for(var m in p)void 0!==p[m]&&O(p[m],!1);for(;d<=g;)void 0!==(c=u[g--])&&O(c,!1)}(i,h,n,o,_||null!=c.dangerouslySetInnerHTML),function(t,e,n){var o;for(o in n)e&&null!=e[o]||null==n[o]||d(t,o,n[o],n[o]=void 0,g);for(o in e)"children"===o||"innerHTML"===o||o in n&&e[o]===("value"===o||"checked"===o?t[o]:n[o])||d(t,o,n[o],n[o]=e[o],g)}(i,e.attributes,c),g=s,i}function O(t,e){var n=t._component;n?L(n):(null!=t.__preactattr_&&l(t.__preactattr_.ref,null),!1!==e&&null!=t.__preactattr_||N(t),r(t))}function r(t){for(t=t.lastChild;t;){var e=t.previousSibling;O(t,!0),t=e}}var a=[];function R(t,e,n){var o,r=a.length;for(t.prototype&&t.prototype.render?(o=new t(e,n),y.call(o,e,n)):((o=new y(e,n)).constructor=t,o.render=m);r--;)if(a[r].constructor===t)return o.nextBase=a[r].nextBase,a.splice(r,1),o;return o}function m(t,e,n){return this.constructor(t,n)}function j(t,e,n,o,r){t._disable||(t._disable=!0,t.__ref=e.ref,t.__key=e.key,delete e.ref,delete e.key,void 0===t.constructor.getDerivedStateFromProps&&(!t.base||r?t.componentWillMount&&t.componentWillMount():t.componentWillReceiveProps&&t.componentWillReceiveProps(e,o)),o&&o!==t.context&&(t.prevContext||(t.prevContext=t.context),t.context=o),t.prevProps||(t.prevProps=t.props),t.props=e,t._disable=!1,0!==n&&(1!==n&&!1===i.syncComponentUpdates&&t.base?s(t):I(t,1,r)),l(t.__ref,t))}function I(t,e,n,o){if(!t._disable){var r,i,s,a=t.props,l=t.state,c=t.context,h=t.prevProps||a,u=t.prevState||l,p=t.prevContext||c,f=t.base,d=t.nextBase,v=f||d,g=t._component,_=!1,m=p;if(t.constructor.getDerivedStateFromProps&&(l=M(M({},l),t.constructor.getDerivedStateFromProps(a,l)),t.state=l),f&&(t.props=h,t.state=u,t.context=p,2!==e&&t.shouldComponentUpdate&&!1===t.shouldComponentUpdate(a,l,c)?_=!0:t.componentWillUpdate&&t.componentWillUpdate(a,l,c),t.props=a,t.state=l,t.context=c),t.prevProps=t.prevState=t.prevContext=t.nextBase=null,t._dirty=!1,!_){r=t.render(a,l,c),t.getChildContext&&(c=M(M({},c),t.getChildContext())),f&&t.getSnapshotBeforeUpdate&&(m=t.getSnapshotBeforeUpdate(h,u));var y,b,w=r&&r.nodeName;if("function"==typeof w){var x=E(r);(i=g)&&i.constructor===w&&x.key==i.__key?j(i,x,1,c,!1):(y=i,t._component=i=R(w,x,c),i.nextBase=i.nextBase||d,i._parentComponent=t,j(i,x,0,c,!1),I(i,1,n,!0)),b=i.base}else s=v,(y=g)&&(s=t._component=null),!v&&1!==e||(s&&(s._component=null),b=A(s,r,c,n||!f,v&&v.parentNode,!0));if(v&&b!==v&&i!==g){var k=v.parentNode;k&&b!==k&&(k.replaceChild(b,v),y||(v._component=null,O(v,!1)))}if(y&&L(y),(t.base=b)&&!o){for(var C=t,S=t;S=S._parentComponent;)(C=S).base=b;b._component=C,b._componentConstructor=C.constructor}}for(!f||n?H.push(t):_||t.componentDidUpdate&&t.componentDidUpdate(h,u,m);t._renderCallbacks.length;)t._renderCallbacks.pop().call(t);T||o||P()}}function L(t){var e=t.base;t._disable=!0,t.componentWillUnmount&&t.componentWillUnmount(),t.base=null;var n=t._component;n?L(n):e&&(null!=e.__preactattr_&&l(e.__preactattr_.ref,null),N(t.nextBase=e),a.push(t),r(e)),l(t.__ref,null)}function y(t,e){this._dirty=!0,this.context=e,this.props=t,this.state=this.state||{},this._renderCallbacks=[]}function b(t,e,n,o){void 0===o&&(o={});for(var r=0;r<e.length;r++)t.addEventListener(e[r],n,o)}function w(t,e,n,o){void 0===o&&(o={});for(var r=0;r<e.length;r++)t.removeEventListener(e[r],n,o)}M(y.prototype,{setState:function(t,e){this.prevState||(this.prevState=this.state),this.state=M(M({},this.state),"function"==typeof t?t(this.state,this.props):t),e&&this._renderCallbacks.push(e),s(this)},forceUpdate:function(t){t&&this._renderCallbacks.push(t),I(this,2)},render:function(){}});var x="mousedown",k="mousemove",C="mouseup",D="touchstart",W="touchmove",B="touchend",t=function(e){function t(t){e.call(this,t),this.uid=(Math.random()+1).toString(36).substring(5)}return e&&(t.__proto__=e),((t.prototype=Object.create(e&&e.prototype)).constructor=t).prototype.componentDidMount=function(){b(this.base,[x,D],this,{passive:!1})},t.prototype.componentWillUnmount=function(){w(this.base,[x,D],this)},t.prototype.handleEvent=function(t){t.preventDefault();var e=t.touches?t.changedTouches[0]:t,n=e.clientX,o=e.clientY,r=this.base.getBoundingClientRect();switch(t.type){case x:case D:b(document,[k,W,C,B],this,{passive:!1}),this.handleInput(n,o,r,"START");break;case k:case W:this.handleInput(n,o,r,"MOVE");break;case C:case B:this.handleInput(n,o,r,"END"),w(document,[k,W,C,B],this,{passive:!1})}},t}(y);function V(t){var e=window.navigator.userAgent,n=/^((?!chrome|android).)*safari/i.test(e),o=/iPhone|iPod|iPad/i.test(e),r=window.location;return n||o?r.protocol+"//"+r.host+r.pathname+r.search+t:t}function F(t,e,n,o,r){var i=r-o<=180?0:1;return o*=Math.PI/180,r*=Math.PI/180,"M "+(t+n*Math.cos(r))+" "+(e+n*Math.sin(r))+" A "+n+" "+n+" 0 "+i+" 0 "+(t+n*Math.cos(o))+" "+(e+n*Math.sin(o))}function $(t){var e=t.r,n=t.url;return p("svg",{class:"iro__handle",x:t.x,y:t.y,style:{overflow:"visible"}},n&&p("use",Object.assign({},{xlinkHref:V(n)},t.origin)),!n&&p("circle",{class:"iro__handle__inner",r:e,fill:"none","stroke-width":2,stroke:"#000"}),!n&&p("circle",{class:"iro__handle__outer",r:e-2,fill:"none","stroke-width":2,stroke:"#fff"}))}$.defaultProps={x:0,y:0,r:8,url:null,origin:{x:0,y:0}};var G=Array.apply(null,{length:360}).map(function(t,e){return e}),z=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype._transformAngle=function(t,e){var n=this.props.wheelAngle;return((t="clockwise"===this.props.wheelDirection?-360+t-(e?-n:n):n-t)%360+360)%360},e.prototype.render=function(t){var e=this,n=t.width,o=t.borderWidth,r=t.handleRadius,i=t.color.hsv,s=n/2-o,a=this._transformAngle(i.h,!0)*(Math.PI/180),l=i.s/100*(s-t.padding-r-o),c=s+o,h=s+o;return p("svg",{class:"iro__wheel",width:n,height:n,style:{overflow:"visible",display:"block"}},p("defs",null,p("radialGradient",{id:this.uid},p("stop",{offset:"0%","stop-color":"#fff"}),p("stop",{offset:"100%","stop-color":"#fff","stop-opacity":"0"}))),p("g",{class:"iro__wheel__hue","stroke-width":s,fill:"none"},G.map(function(t){return p("path",{key:t,d:F(c,h,s/2,t,t+1.5),stroke:"hsl("+e._transformAngle(t)+", 100%, 50%)"})})),p("circle",{class:"iro__wheel__saturation",cx:c,cy:h,r:s,fill:"url("+V("#"+this.uid)+")"}),t.wheelLightness&&p("circle",{class:"iro__wheel__lightness",cx:c,cy:h,r:s,fill:"#000",opacity:1-i.v/100}),p("circle",{class:"iro__wheel__border",cx:c,cy:h,r:s,fill:"none",stroke:t.borderColor,"stroke-width":o}),p($,{r:r,url:t.handleSvg,origin:t.handleOrigin,x:c+l*Math.cos(a),y:h+l*Math.sin(a)}))},e.prototype.handleInput=function(t,e,n,o){var r=n.left,i=n.top,s=this.props,a=s.width/2,l=a-s.padding-s.handleRadius-s.borderWidth;t=a-(t-r),e=a-(e-i);var c=Math.atan2(e,t),h=this._transformAngle(Math.round(c*(180/Math.PI))+180),u=Math.min(Math.sqrt(t*t+e*e),l);s.onInput(o,{h:h,s:Math.round(100/l*u)})},e}(t);function q(t,e){var n=-1<t.indexOf("%"),o=parseFloat(t);return n?e/100*o:o}function X(t){return parseInt(t,16)}function Y(t){return t.toString(16).padStart(2,"0")}function J(t){this._onChange=!1,this._value={h:0,s:0,v:0,a:1},t&&this.set(t)}var K="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)",Q="[\\s|\\(]+("+K+")[,|\\s]+("+K+")[,|\\s]+("+K+")\\s*\\)?",Z="[\\s|\\(]+("+K+")[,|\\s]+("+K+")[,|\\s]+("+K+")[,|\\s]+("+K+")\\s*\\)?",tt=new RegExp("rgb"+Q),et=new RegExp("rgba"+Z),nt=new RegExp("hsl"+Q),ot=new RegExp("hsla"+Z),rt="^(?:#?|0x?)",it="([0-9a-fA-F]{1})",st="([0-9a-fA-F]{2})",at=new RegExp(rt+it+it+it+"$"),lt=new RegExp(rt+it+it+it+it+"$"),ct=new RegExp(rt+st+st+st+"$"),ht=new RegExp(rt+st+st+st+st+"$"),ut={hsv:{configurable:!0},rgb:{configurable:!0},hsl:{configurable:!0},rgbString:{configurable:!0},hexString:{configurable:!0},hslString:{configurable:!0}};J.prototype.set=function(t){var e="string"==typeof t,n="object"==typeof t;if(e&&/^(?:#?|0x?)[0-9a-fA-F]{3,8}$/.test(t))this.hexString=t;else if(e&&/^rgba?/.test(t))this.rgbString=t;else if(e&&/^hsla?/.test(t))this.hslString=t;else if(n&&t instanceof J)this.hsv=t.hsv;else if(n&&"r"in t&&"g"in t&&"b"in t)this.rgb=t;else if(n&&"h"in t&&"s"in t&&"v"in t)this.hsv=t;else{if(!(n&&"h"in t&&"s"in t&&"l"in t))throw new Error("invalid color value");this.hsl=t}},J.prototype.setChannel=function(t,e,n){var o;this[t]=Object.assign({},this[t],((o={})[e]=n,o))},J.prototype.clone=function(){return new J(this)},J.hsvToRgb=function(t){var e=t.h/60,n=t.s/100,o=t.v/100,r=Math.floor(e),i=e-r,s=o*(1-n),a=o*(1-i*n),l=o*(1-(1-i)*n),c=r%6;return{r:255*[o,a,s,s,l,o][c],g:255*[l,o,o,a,s,s][c],b:255*[s,s,l,o,o,a][c]}},J.rgbToHsv=function(t){var e,n=t.r/255,o=t.g/255,r=t.b/255,i=Math.max(n,o,r),s=Math.min(n,o,r),a=i-s,l=i,c=0===i?0:a/i;switch(i){case s:e=0;break;case n:e=(o-r)/a+(o<r?6:0);break;case o:e=(r-n)/a+2;break;case r:e=(n-o)/a+4}return{h:60*e,s:100*c,v:100*l}},J.hsvToHsl=function(t){var e=t.s/100,n=t.v/100,o=(2-e)*n,r=o<=1?o:2-o,i=r<1e-9?0:e*n/r;return{h:t.h,s:100*i,l:50*o}},J.hslToHsv=function(t){var e=2*t.l,n=t.s*(e<=100?e:200-e)/100,o=e+n<1e-9?0:2*n/(e+n);return{h:t.h,s:100*o,v:(e+n)/2}},ut.hsv.get=function(){var t=this._value;return{h:t.h,s:t.s,v:t.v}},ut.hsv.set=function(t){var e=this._value;if(t=Object.assign({},e,t),this._onChange){var n={};for(var o in e)n[o]=t[o]!=e[o];this._value=t,(n.h||n.s||n.v||n.a)&&this._onChange(this,n)}else this._value=t},ut.rgb.get=function(){var t=J.hsvToRgb(this._value),e=t.r,n=t.g,o=t.b;return{r:Math.round(e),g:Math.round(n),b:Math.round(o)}},ut.rgb.set=function(t){this.hsv=Object.assign({},J.rgbToHsv(t),{a:void 0===t.a?1:t.a})},ut.hsl.get=function(){var t=J.hsvToHsl(this._value),e=t.h,n=t.s,o=t.l;return{h:Math.round(e),s:Math.round(n),l:Math.round(o)}},ut.hsl.set=function(t){this.hsv=Object.assign({},J.hslToHsv(t),{a:void 0===t.a?1:t.a})},ut.rgbString.get=function(){var t=this.rgb;return"rgb("+t.r+", "+t.g+", "+t.b+")"},ut.rgbString.set=function(t){var e,n,o,r,i=1;if((e=tt.exec(t))?(n=q(e[1],255),o=q(e[2],255),r=q(e[3],255)):(e=et.exec(t))&&(n=q(e[1],255),o=q(e[2],255),r=q(e[3],255),i=q(e[4],1)),!e)throw new Error("invalid rgb string");this.rgb={r:n,g:o,b:r,a:i}},ut.hexString.get=function(){var t=this.rgb;return"#"+Y(t.r)+Y(t.g)+Y(t.b)},ut.hexString.set=function(t){var e,n,o,r,i=255;if((e=at.exec(t))?(n=17*X(e[1]),o=17*X(e[2]),r=17*X(e[3])):(e=lt.exec(t))?(n=17*X(e[1]),o=17*X(e[2]),r=17*X(e[3]),i=17*X(e[4])):(e=ct.exec(t))?(n=X(e[1]),o=X(e[2]),r=X(e[3])):(e=ht.exec(t))&&(n=X(e[1]),o=X(e[2]),r=X(e[3]),i=X(e[4])),!e)throw new Error("invalid hex string");this.rgb={r:n,g:o,b:r,a:i/255}},ut.hslString.get=function(){var t=this.hsl;return"hsl("+t.h+", "+t.s+"%, "+t.l+"%)"},ut.hslString.set=function(t){var e,n,o,r,i=1;if((e=nt.exec(t))?(n=q(e[1],360),o=q(e[2],100),r=q(e[3],100)):(e=ot.exec(t))&&(n=q(e[1],360),o=q(e[2],100),r=q(e[3],100),i=q(e[4],1)),!e)throw new Error("invalid hsl string");this.hsl={h:n,s:o,l:r,a:i}},Object.defineProperties(J.prototype,ut);var pt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype.renderGradient=function(t){var e=t.color.hsv,n=[];switch(t.sliderType){case"hue":n=[{offset:"0",color:"#f00"},{offset:"16.666",color:"#ff0"},{offset:"33.333",color:"#0f0"},{offset:"50",color:"#0ff"},{offset:"66.666",color:"#00f"},{offset:"83.333",color:"#f0f"},{offset:"100",color:"#f00"}];break;case"saturation":var o=J.hsvToHsl({h:e.h,s:0,v:e.v}),r=J.hsvToHsl({h:e.h,s:100,v:e.v});n=[{offset:"0",color:"hsl("+o.h+", "+o.s+"%, "+o.l+"%)"},{offset:"100",color:"hsl("+r.h+", "+r.s+"%, "+r.l+"%)"}];break;case"value":default:var i=J.hsvToHsl({h:e.h,s:e.s,v:100});n=[{offset:"0",color:"#000"},{offset:"100",color:"hsl("+i.h+", "+i.s+"%, "+i.l+"%)"}]}return p("linearGradient",{id:this.uid},n.map(function(t){return p("stop",{offset:t.offset+"%","stop-color":t.color})}))},e.prototype.render=function(t){var e=t.width,n=t.sliderHeight,o=t.borderWidth,r=t.handleRadius;n=n||2*t.padding+2*r+2*o,this.width=e;var i,s=(this.height=n)/2,a=e-2*s,l=t.color.hsv;switch(t.sliderType){case"hue":i=l.h/=3.6;break;case"saturation":i=l.s;break;case"value":default:i=l.v}return p("svg",{class:"iro__slider",width:e,height:n,style:{marginTop:t.sliderMargin,overflow:"visible",display:"block"}},p("defs",null,this.renderGradient(t)),p("rect",{class:"iro__slider__value",rx:s,ry:s,x:o/2,y:o/2,width:e-o,height:n-o,"stroke-width":o,stroke:t.borderColor,fill:"url("+V("#"+this.uid)+")"}),p($,{r:r,url:t.handleSvg,origin:t.handleOrigin,x:s+i/100*a,y:n/2}))},e.prototype.getValueFromPoint=function(t,e,n){var o=n.left,r=this.width-this.height;t-=o+this.height/2;var i=Math.max(Math.min(t,r),0);return Math.round(100/r*i)},e.prototype.handleInput=function(t,e,n,o){var r,i,s=this.getValueFromPoint(t,e,n);switch(this.props.sliderType){case"hue":i="h",s*=3.6;break;case"saturation":i="s";break;case"value":default:i="v"}this.props.onInput(o,((r={})[i]=s,r))},e}(t);var ft=function(e){function i(t){e.call(this,t),this.emitHook("init:before"),this._events={},this._deferredEvents={},this._colorUpdateActive=!1,this._colorUpdateSrc=null,this.id=t.id,this.color=new J(t.color),this.deferredEmit("color:init",this.color,{h:!1,s:!1,v:!1,a:!1}),this.color._onChange=this.updateColor.bind(this),this.state=Object.assign({},t,{color:this.color}),this.emitHook("init:state"),t.layout?this.layout=t.layout:this.layout=[{component:z,options:{}},{component:pt,options:{}}],this.emitHook("init:after")}return e&&(i.__proto__=e),((i.prototype=Object.create(e&&e.prototype)).constructor=i).prototype.on=function(t,e){var n=this,o=this._events;(Array.isArray(t)?t:[t]).forEach(function(t){n.emitHook("event:on",t,e),(o[t]||(o[t]=[])).push(e),n._deferredEvents[t]&&(n._deferredEvents[t].forEach(function(t){e.apply(null,t)}),n._deferredEvents[t]=[])})},i.prototype.off=function(t,n){var o=this;(Array.isArray(t)?t:[t]).forEach(function(t){var e=o._events[t];o.emitHook("event:off",t,n),e&&e.splice(e.indexOf(n),1)})},i.prototype.emit=function(t){for(var e,n=[],o=arguments.length-1;0<o--;)n[o]=arguments[o+1];(e=this).emitHook.apply(e,[t].concat(n));for(var r=this._events[t]||[],i=0;i<r.length;i++)r[i].apply(this,n)},i.prototype.deferredEmit=function(t){for(var e,n=[],o=arguments.length-1;0<o--;)n[o]=arguments[o+1];var r=this._deferredEvents;(e=this).emit.apply(e,[t].concat(n)),(r[t]||(r[t]=[])).push(n)},i.prototype.resize=function(t){this.setState({width:t})},i.prototype.reset=function(){this.color.set(this.props.color)},i.addHook=function(t,e){var n=i.pluginHooks;(n[t]||(n[t]=[])).push(e)},i.prototype.emitHook=function(t){for(var e=[],n=arguments.length-1;0<n--;)e[n]=arguments[n+1];for(var o=i.pluginHooks[t]||[],r=0;r<o.length;r++)o[r].apply(this,e)},i.prototype.onMount=function(t){this.el=t,this.deferredEmit("mount",this)},i.prototype.updateColor=function(t,e){this.emitHook("color:beforeUpdate",t,e),this.setState({color:t}),this.emitHook("color:afterUpdate",t,e),this._colorUpdateActive||(this._colorUpdateActive=!0,"input"==this._colorUpdateSrc&&this.emit("input:change",t,e),this.emit("color:change",t,e),this._colorUpdateActive=!1)},i.prototype.handleInput=function(t,e){"START"===t&&this.emit("input:start",this.color),"MOVE"===t&&this.emit("input:move",this.color),this._colorUpdateSrc="input",this.color.hsv=e,"END"===t&&this.emit("input:end",this.color),this._colorUpdateSrc=null},i.prototype.render=function(t,o){var r=this;return p("div",{class:"iro__colorPicker",id:t.id,style:{display:o.display,width:o.width}},this.layout.map(function(t){var e=t.component,n=t.options;return p(e,Object.assign({},o,n,{onInput:function(t,e){return r.handleInput(t,e)},parent:r}))}))},i}(y);ft.pluginHooks={},ft.defaultProps={width:300,height:300,handleRadius:8,handleSvg:null,handleOrigin:{x:0,y:0},color:"#fff",borderColor:"#fff",borderWidth:0,display:"block",id:null,wheelLightness:!0,wheelAngle:0,wheelDirection:"anticlockwise",sliderHeight:null,sliderMargin:12,padding:6,layout:null};var dt,vt,gt,_t=(mt.prototype=(dt=ft).prototype,Object.assign(mt,dt),mt.__component=dt,mt);function mt(e,t){var n=null,o=document.createElement("div");return function(t,e,n){A(n,t,{},!1,e,!1)}(p(dt,Object.assign({},{ref:function(t){return n=t}},t)),o),function(t){"loading"!==document.readyState?t():b(document,["DOMContentLoaded"],t)}(function(){var t=e instanceof Element?e:document.querySelector(e);t.appendChild(n.base),n.onMount(t)}),n}return gt=[],(vt={Color:J,ColorPicker:_t,ui:{h:p,Component:t,Handle:$,Slider:pt,Wheel:z},util:{resolveUrl:V,createArcPath:F,parseUnit:q,parseHexInt:X,intToHex:Y},version:"4.5.0"}).use=function(t,e){void 0===e&&(e={}),-1<gt.indexOf(t)||(t(vt,e),gt.push(t))},vt.installedPlugins=gt,vt});
|
|
//# sourceMappingURL=iro.min.js.map
|