import t from"jquery";function e(t){return(e="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})(t)}function r(t){return(r="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})(t)}function n(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function o(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function i(t){for(var e=1;e=e&&t<=r))throw Error("Invalid Rating, expected value between "+e+" and "+r);return t}function d(t,e){return r(t)===e}function h(t){return void 0!==t}var g=function(t){return d(t,"function")},m=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;function v(t){if(!m.test(t))return null;var e=m.exec(t);return{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}}function y(t,e,r){var n=r/100*(e-t);return 1===(n=Math.round(t+n).toString(16)).length&&(n="0"+n),n}function b(t,e,r){if(!t||!e)return null;r=h(r)?r:0,t=v(t),e=v(e);var n=y(t.r,e.r,r),o=y(t.b,e.b,r);return"#"+n+y(t.g,e.g,r)+o}var w={};function k(t){return w[t]||(w[t]=new String(t))}var x=new WeakMap;function S(t,e,r){r=k(r);var n=x.get(t);n||x.set(t,n=new WeakMap);var o=n.get(r);o||n.set(r,o=new Map);var i=o.get(e);if(i)return i;function a(r){var n=r.detail;e.call(t,r,n)}return o.set(e,a),a}S.get=function(t,e,r){r=k(r);var n=x.get(t);if(!n)return e;var o=n.get(r);return o&&o.get(e)||e};var O=g(window.Event)?window.Event:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.bubbles,n=void 0!==r&&r,o=e.cancelable,i=void 0!==o&&o,a=document.createEvent("Event");return a.initEvent(t,n,i),a},j=g(window.CustomEvent)?window.CustomEvent:(j.prototype=Object.create(O.prototype),j),E={trigger:function(t,e){var r={bubbles:!0};return h(e)?this.node.dispatchEvent(new j(t,i({detail:e},r))):this.node.dispatchEvent(new O(t,r)),this},on:function(t,e){return this.node.addEventListener(t,S(this.node,e,t)),this},off:function(t,e){return this.node.removeEventListener(t,S.get(this.node,e,t)),this}},C=/^rateyo(.+)$/;function F(t,e,r){var n=t.className.trim(),o=n&&n.split(/\s/)||[],i={};if(o=o.reduce((function(t,e,r){return i.hasOwnProperty(e)||(t.push(e),i[e]=r),t}),[]),e===F.add){if(i.hasOwnProperty(r))return;o.push(r)}else if(e===F.remove){if(!i.hasOwnProperty(r))return;o.splice(i[r],1)}t.className=o.join(" ")}function P(t){this.node=t}function A(t){var e=this;this.collection=[],Array.prototype.forEach.call(t,(function(t){e.collection.push(new P(t))}))}F.add="add",F.remove="remove",P.prototype={empty:function(){return this.node.innerHTML="",this},addClass:function(t){return F(this.node,F.add,t),this},removeClass:function(t){return F(this.node,F.remove,t),this},appendTo:function(t){return(P.isEl(t)?t.node:t).appendChild(this.node),this},css:function(t,e){return this.node.style[t]=e,this},width:function(t){if(!h(t))return this.node.getBoundingClientRect().width;this.css("width",t+(d(t,"number")?"px":""))},find:function(t){return M(this.node.querySelectorAll(t))},attr:function(t){for(var e in t)t.hasOwnProperty(e)&&this.node.setAttribute(e,t[e]);return this},removeAttr:function(t){return this.node.removeAttribute(t),this},children:function(){return M(this.node.childNodes)},remove:function(){return this.node.remove()},offset:function(){var t=this.node.getBoundingClientRect();return{top:t.top,left:t.left,bottom:t.bottom,right:t.right}},dataAttrOptions:function(){var t=this.node.dataset;return Object.keys(t).reduce((function(e,r){var n=r.match(C);if(!n)return e;var o=n[1];return e[o[0].toLowerCase()+o.slice(1)]=t[r],e}),{})}},P.prototype=i(i({},P.prototype),E),P.isEl=function(t){return t instanceof P},A.isCollection=function(t){return t instanceof A},A.prototype={};var q=function(t){if(!P.prototype.hasOwnProperty(t))return"continue";A.prototype[t]=function(){for(var e=arguments.length,r=new Array(e),n=0;n1&&void 0!==arguments[1]?arguments[1]:{};if(!(this instanceof W))return new W(t,e);if(V.has(t))return V.get(t);var r=this;this.node=t;var n=M(t);e=i(i(i({},s),e),n.dataAttrOptions()),n.empty().addClass("jq-ry-container");var o,d,g,m,v,y,w=M(document.createElement("div")).addClass("jq-ry-group-wrapper").appendTo(n),k=M(document.createElement("div")).addClass("jq-ry-normal-group").addClass("jq-ry-group").appendTo(w),x=M(document.createElement("div")).addClass("jq-ry-rated-group").addClass("jq-ry-group").appendTo(w),S=0,O=e.rating,j=!1;function E(t){h(t)||(t=e.rating),O=t;var r=t/o,n=r*g;r>1&&(n+=(Math.ceil(r)-1)*v),z(e.ratedFill),(n=e.rtl?100-n:n)<0?n=0:n>100&&(n=100),x.css("width",n+"%")}function C(){y=d*e.numStars+m*(e.numStars-1),g=d/y*100,v=m/y*100,n.width(y),E()}function F(t){var r=e.starWidth=t;return d=window.parseFloat(e.starWidth.replace("px","")),k.find("svg").attr({width:e.starWidth,height:r}),x.find("svg").attr({width:e.starWidth,height:r}),C(),n}function P(t){return e.spacing=t,m=parseFloat(e.spacing.replace("px","")),k.find("svg:not(:first-child)").css("margin-left",t),x.find("svg:not(:first-child)").css("margin-left",t),C(),n}function A(t){return e.normalFill=t,(e.rtl?x:k).find("svg").attr({fill:e.normalFill}),n}var q=e.ratedFill;function z(t){if(e.multiColor){var r=(O-S)/e.maxValue*100,o=e.multiColor||{};t=b(o.startColor||u,o.endColor||c,r)}else q=t;return e.ratedFill=t,(e.rtl?k:x).find("svg").attr({fill:e.ratedFill}),n}function I(t){t=!!t,e.rtl=t,A(e.normalFill),E()}function T(t){e.multiColor=t,z(t||q)}function N(t){e.numStars=t,o=e.maxValue/e.numStars,k.empty(),x.empty();for(var r=0;rt&&X(t),E(),n}function L(t){return e.precision=t,X(e.rating),n}function $(t){return e.halfStar=t,n}function _(t){return e.fullStar=t,n}function B(t){var r=t%o,n=o/2,i=e.halfStar,a=e.fullStar;return a||i?(a||i&&r>n?t+=o-r:(t-=r,r>0&&(t+=n)),t):t}function R(t){var r=k.offset().left,n=r+k.width(),i=e.maxValue,a=t.pageX,s=0;if(an)s=i;else{var u=(a-r)/(n-r);if(m>0)for(var c=u*=100;c>0;)c>g?(s+=o,c-=g+v):(s+=c/g*o,c=0);else s=u*e.maxValue;s=B(s)}return e.rtl&&(s=i-s),parseFloat(s)}function H(t){return e.readOnly=t,n.attr({readonly:!0}),nt(),t||(n.removeAttr("readonly"),rt()),n}function X(t){var r=t,o=e.maxValue;return"string"==typeof r&&("%"===r[r.length-1]&&(r=r.substr(0,r.length-1),D(o=100)),r=parseFloat(r)),p(r,S,o),r=parseFloat(r.toFixed(e.precision)),f(parseFloat(r),S,o),e.rating=r,E(),j&&n.trigger("rateyo.set",{rating:r}),n}function Y(t){return e.onInit=t,n}function G(t){return e.onSet=t,n}function J(t){return e.onChange=t,n}function K(t){if(e.hover){var r=R(t).toFixed(e.precision),o=e.maxValue;E(r=f(parseFloat(r),S,o)),n.trigger("rateyo.change",{rating:r})}}function Q(){!l()&&e.hover&&(E(),n.trigger("rateyo.change",{rating:e.rating}))}function U(t){var n=R(t).toFixed(e.precision);n=parseFloat(n),r.rating(n)}function Z(t,n){e.onInit&&"function"==typeof e.onInit&&e.onInit.apply(this,[n.rating,r])}function tt(t,n){e.onChange&&"function"==typeof e.onChange&&e.onChange.apply(this,[n.rating,r])}function et(t,n){e.onSet&&"function"==typeof e.onSet&&e.onSet.apply(this,[n.rating,r])}function rt(){n.on("mousemove",K).on("mouseenter",K).on("mouseleave",Q).on("click",U).on("rateyo.init",Z).on("rateyo.change",tt).on("rateyo.set",et)}function nt(){n.off("mousemove",K).off("mouseenter",K).off("mouseleave",Q).off("click",U).off("rateyo.init",Z).off("rateyo.change",tt).off("rateyo.set",et)}this.rating=function(t){return h(t)?(X(t),n):e.rating},this.destroy=function(){return e.readOnly||nt(),V.delete(t),n.removeClass("jq-ry-container").children().remove(),n},this.method=function(t){if(!t)throw Error("Method name not specified!");if(!h(this[t]))throw Error("Method "+t+" doesn't exist!");var e=Array.prototype.slice.apply(arguments,[]),r=e.slice(1),n=this[t];return n.apply(this,r)},this.option=function(t,r){if(!h(t))return e;var n;switch(t){case"starWidth":n=F;break;case"numStars":n=N;break;case"normalFill":n=A;break;case"ratedFill":n=z;break;case"multiColor":n=T;break;case"maxValue":n=D;break;case"precision":n=L;break;case"rating":n=X;break;case"halfStar":n=$;break;case"fullStar":n=_;break;case"readOnly":n=H;break;case"spacing":n=P;break;case"rtl":n=I;break;case"onInit":n=Y;break;case"onSet":n=G;break;case"onChange":n=J;break;default:throw Error("No such option as "+t)}return h(r)?n(r):e[t]},N(e.numStars),H(e.readOnly),e.rtl&&I(e.rtl),V.set(t,this),this.rating(e.rating,!0),j=!0,n.trigger("rateyo.init",{rating:e.rating})}Object.defineProperty(W.prototype,"on",{value:function(t,e){return M(this.node).on(t,e),this}}),Object.defineProperty(W.prototype,"off",{value:function(t,e){return M(this.node).off(t,e),this}}),Object.defineProperty(W,"has",{value:function(t){return V.has(t)}}),Object.defineProperty(W,"get",{value:function(t){return V.get(t)}}),Object.defineProperty(W,"_$",{get:function(){return M}});var T=W._$,N=T.El.prototype.trigger;function D(r){var n=t(this);if(0===n.length)return n;var o=Array.prototype.slice.apply(arguments,[]);if(0===o.length)r=o[0]={};else{if(1!==o.length||"object"!==e(o[0])){if(o.length>=1&&"string"==typeof o[0]){var i=o[0],a=o.slice(1),s=[];return t.each(n,(function(t,e){var r=W.get(e);if(!r)throw Error("Trying to set options before even initialization");var n=r[i];if(!n)throw Error("Method "+i+" does not exist!");var o=n.apply(r,a);s.push(o)})),s=1===s.length?s[0]:s}throw Error("Invalid Arguments")}r=o[0]}return t.each(n,(function(){return new W(this,t.extend({},r))}))}T.El.prototype.trigger=function(){for(var e,r=arguments.length,n=new Array(r),o=0;o