UNPKG

tweening-color-middleware

Version:
1 lines 2.84 kB
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.TweeningColorMiddleware=r():t.TweeningColorMiddleware=r()}(this,function(){return function(t){function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,r),o.loaded=!0,o.exports}var e={};return r.m=t,r.c=e,r.p="",r(0)}([function(t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var e=function(){function t(t,r){var e=[],n=!0,o=!1,i=void 0;try{for(var u,a=t[Symbol.iterator]();!(n=(u=a.next()).done)&&(e.push(u.value),!r||e.length!==r);n=!0);}catch(l){o=!0,i=l}finally{try{!n&&a["return"]&&a["return"]()}finally{if(o)throw i}}return e}return function(r,e){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return t(r,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},o=function(t){return"string"==typeof t&&null!==t.match(/^#(?:[0-9a-f]{3}){1,2}$/i)},i=function(t){return"string"==typeof t&&t.startsWith("rgb(")},u=function(t){return"string"==typeof t&&t.startsWith("rgba(")},a=function(t){return"object"===("undefined"==typeof t?"undefined":n(t))&&"hex"===t.colorType},l=function(t){return"object"===("undefined"==typeof t?"undefined":n(t))&&"rgb"===t.colorType},c=function(t){return"object"===("undefined"==typeof t?"undefined":n(t))&&("rgba"===t.colorType||t.a<1)},f=function(t){var r=t.replace("#","");return 3===r.length&&(r=r.split("").map(function(t){return""+t+t}).join("")),{middleware:"color",colorType:"hex",r:parseInt(r.slice(0,2),16),g:parseInt(r.slice(2,4),16),b:parseInt(r.slice(4,6),16),a:1}},p=function(t){var r=t.replace(/\s/g,""),n=r.substring(4,r.length-1).split(","),o=e(n,3),i=o[0],u=o[1],a=o[2];return{middleware:"color",colorType:"rgb",r:parseFloat(i),g:parseFloat(u),b:parseFloat(a),a:1}},s=function(t){var r=t.replace(/\s/g,""),n=r.substring(5,r.length-1).split(","),o=e(n,4),i=o[0],u=o[1],a=o[2],l=o[3];return{middleware:"color",colorType:"rgba",r:parseFloat(i),g:parseFloat(u),b:parseFloat(a),a:parseFloat(l)}},d=function(t){var r=Math.ceil(t.r).toString(16),e=Math.ceil(t.g).toString(16),n=Math.ceil(t.b).toString(16);return r=1===r.length?"0"+r:r,e=1===e.length?"0"+e:e,n=1===n.length?"0"+n:n,"#"+r+e+n},y=function(t){var r=t.r,e=t.g,n=t.b;return"rgb("+r+","+e+","+n+")"},b=function(t){var r=t.r,e=t.g,n=t.b,o=t.a;return"rgba("+r+","+e+","+n+","+o+")"},g={name:"color",i:function(t){return o(t)?f(t):i(t)?p(t):u(t)?s(t):t},o:function(t){return c(t)?b(t):a(t)?d(t):l(t)?y(t):t}};r.isHexStr=o,r.isRgbStr=i,r.isRgbaStr=u,r["default"]=g}])});