css-color-parser-h 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css-color-parser-h.cjs +2550 -0
- package/dist/css-color-parser-h.min.cjs +1 -0
- package/dist/css-color-parser-h.min.mjs +1 -0
- package/dist/css-color-parser-h.mjs +2532 -0
- package/dist/css-color-parser-h.umd.min.js +1 -1
- package/package.json +3 -2
- package/readme.md +5 -3
- package/dist/css-color-parser-h.common.js +0 -959
- package/dist/css-color-parser-h.common.min.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(){"use strict";var r={n:function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,{a:e}),e},d:function(t,e){for(var o in e)r.o(e,o)&&!r.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},o:function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},r:function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})}},t={};r.r(t),r.d(t,{CssColorParser:function(){return i},CssColorParserPlus:function(){return f}});var e=function(){function r(){}return r.type=function(r,t,e){var o=typeof t;if(o!==e)throw new Error("Expected ".concat(r," to be typeof ").concat(e,", actual typeof was ").concat(o))},r.types=function(r,t,e){var o=typeof t;if(!e.includes(o))throw new Error("Expected ".concat(r," to be typeof ").concat(e.join("|"),", actual typeof was ").concat(o))},r.numValue=function(t,e,o,n){r.numMinValue(t,e,o),r.numMaxValue(t,e,n)},r.numMinValue=function(r,t,e){if(t<e)throw new Error("Expected ".concat(r," to > ").concat(e,", actual value was ").concat(t))},r.numMaxValue=function(r,t,e){if(t>e)throw new Error("Expected ".concat(r," to < ").concat(e,", actual value was ").concat(t))},r.numIsInt=function(r,t,e){var o=Math.floor(t)===t;if(o!==e)throw new Error("Expected ".concat(r," to ").concat(e?"Integer":"Float",", actual value was ").concat(o?"Integer":"Float"))},r}();function o(r,t){return null==r||isNaN(r)&&"number"==typeof t?t:r}function n(r,t,e){return e>t?e=t:e<r&&(e=r),e}function a(r,t){void 0===r&&(r=0);var e=Math.pow(10,t);return Math.round(r*e)/e}var s=function(){function r(){}return r.clearStrSpace=function(r){return r.replace(/\s/g,"")},r.trimStr=function(r){return(r=r.replace(/\s+/g," ")).trim()},r.parse3BitsHEX=function(t){var e=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i.exec(t);if(e){var n=o(e[4],"f");return[r._parseResStrForRgb(parseInt(e[1]+e[1],16)),r._parseResStrForRgb(parseInt(e[2]+e[2],16)),r._parseResStrForRgb(parseInt(e[3]+e[3],16)),r._parsePercent(parseInt(n+n,16)/255)]}return null},r.parse6BitsHEX=function(t){var e=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i.exec(t);if(e){var n=o(e[4],"ff");return[r._parseResStrForRgb(parseInt(e[1],16)),r._parseResStrForRgb(parseInt(e[2],16)),r._parseResStrForRgb(parseInt(e[3],16)),r._parsePercent(parseInt(n,16)/255)]}return null},r.parseRGBA=function(t){var e=/^rgba?\(([0-9.]+%?),([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(t);return e?[r._parseResStrForRgb(e[1]),r._parseResStrForRgb(e[2]),r._parseResStrForRgb(e[3]),r._parsePercent(e[4])]:null},r.parseHSLA=function(t){var e=/^hsla?\(([0-9.]+)(?:deg)?,([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(t);return e?[r._parseResStrForHue(e[1]),r._parsePercent(e[2]),r._parsePercent(e[3]),r._parsePercent(e[4])]:null},r.parseHWB=function(t){var e=/^hwb\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(t);return e?[r._parseResStrForHue(e[1]),r._parsePercent(e[2]),r._parsePercent(e[3]),r._parsePercent(e[4])]:null},r.parseRGBA2=function(t){var e=/^rgba?\s?\(\s?([0-9.]+%?)\s?([0-9.]+%?)\s?([0-9.]+%?)(?:\s?\/\s?([0-9.]+%?))?\s?\)$/i.exec(t);return e?[r._parseResStrForRgb(e[1]),r._parseResStrForRgb(e[2]),r._parseResStrForRgb(e[3]),r._parsePercent(e[4])]:null},r.parseHSLA2=function(t){var e=/^hsla?\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(t);return e?[r._parseResStrForHue(e[1]),r._parsePercent(e[2]),r._parsePercent(e[3]),r._parsePercent(e[4])]:null},r._parseResStrForRgb=function(r){return"string"==typeof r&&(r=parseFloat(r)/("%"===r.substr(-1)?100/255:1)),isNaN(r)&&(r=1),n(0,255,r)},r._parseResStrForHue=function(r){return"string"==typeof r&&(r=parseFloat(r)),isNaN(r)&&(r=0),n(0,360,r)},r._parsePercent=function(r){return"string"==typeof r&&(r=parseFloat(r)/("%"===r.substr(-1)?100:1)),isNaN(r)&&(r=1),n(0,1,r)},r}(),i=function(){function r(r,t,e,o){this.r=255,this.g=255,this.b=255,this.a=1,this._outColorPrecision=2,this._outAlphaPrecision=2,this.setColor(r,t,e,o)}return r.prototype.setOutPrecision=function(r,t){return e.type("colorPrecision",r,"number"),e.type("outAlphaPrecision",t,"number"),e.numMinValue("colorPrecision",r,0),e.numMinValue("outAlphaPrecision",t,0),e.numIsInt("colorPrecision",r,!0),e.numIsInt("outAlphaPrecision",t,!0),this._outColorPrecision=r,this._outAlphaPrecision=t,this},r.prototype.setColor=function(r,t,e,a){return this.r=n(0,255,o(Number(r),0)),this.g=n(0,255,o(Number(t),0)),this.b=n(0,255,o(Number(e),0)),this.a=n(0,1,o(Number(a),1)),this},r.prototype.setAlpha=function(r){return this.a=n(0,1,o(Number(r),1)),this},r.prototype.setRed=function(r){return this.r=n(0,255,o(Number(r),0)),this},r.prototype.setGreen=function(r){return this.g=n(0,255,o(Number(r),0)),this},r.prototype.setBlue=function(r){return this.b=n(0,255,o(Number(r),0)),this},r.prototype.toRGBA=function(){var r=this.toJson();return 1===r.a?"rgb(".concat(r.r,",").concat(r.g,",").concat(r.b,")"):"rgba(".concat(r.r,",").concat(r.g,",").concat(r.b,",").concat(r.a,")")},r.prototype.toString=function(){return this.toRGBA()},r.prototype.toNormalize=function(){return[a(this.r/255,this._outColorPrecision),a(this.g/255,this._outColorPrecision),a(this.b/255,this._outColorPrecision),a(this.a,this._outAlphaPrecision)]},r.prototype.toHEX=function(){var r=this.toJson(),t=r.r.toString(16);t.length<2&&(t="0".concat(t));var e=r.g.toString(16);e.length<2&&(e="0".concat(e));var o=r.b.toString(16);if(o.length<2&&(o="0".concat(o)),this.a<1){var n=parseInt((255*this.a).toFixed()).toString(16);return n.length<2&&(n="0".concat(n)),"#".concat(t).concat(e).concat(o).concat(n)}return"#".concat(t).concat(e).concat(o)},r.prototype.toArray=function(){var r=this.toJson();return[r.r,r.g,r.b,r.a]},r.prototype.toJson=function(){return{r:a(this.r,this._outColorPrecision),g:a(this.g,this._outColorPrecision),b:a(this.b,this._outColorPrecision),a:a(this.a,this._outAlphaPrecision)}},r.prototype.toInvert=function(){return new r(255-this.r,255-this.g,255-this.b,1-this.a)},r.prototype.clone=function(){return new r(this.r,this.g,this.b,this.a)},r.prototype.equals=function(r){if(this===r)return!0;var t=this.toJson(),e=r.toJson();return t.r===e.r&&t.g===e.g&&t.b===e.g&&t.a===e.a},r.prototype.setInvert=function(){return this.r=255-this.r,this.g=255-this.g,this.b=255-this.b,this.a=1-this.a,this},r.prototype.multiplyByScalar=function(r,t){void 0===t&&(t=!0);var e=this.r*r,o=this.g*r,n=this.b*r,a=t?this.a*r:this.a;return this.setColor(e,o,n,a)},r.prototype.divideByScalar=function(r,t){void 0===t&&(t=!0);var e=this.r/r,o=this.g/r,n=this.b/r,a=t?this.a/r:this.a;return this.setColor(e,o,n,a)},r.prototype.add=function(r,t){void 0===t&&(t=!0);var e=this.r+r.r,o=this.g+r.g,n=this.b+r.b,a=t?this.a+r.a:this.a;return this.setColor(e,o,n,a)},r.prototype.subtract=function(r,t){void 0===t&&(t=!0);var e=this.r-r.r,o=this.g-r.g,n=this.b-r.b,a=t?this.a-r.a:this.a;return this.setColor(e,o,n,a)},r.prototype.multiply=function(r,t){void 0===t&&(t=!0);var e=this.r*r.r,o=this.g*r.g,n=this.b*r.b,a=t?this.a*r.a:this.a;return this.setColor(e,o,n,a)},r.prototype.divide=function(r,t){void 0===t&&(t=!0);var e=this.r/r.r,o=this.g/r.g,n=this.b/r.b,a=t?this.a/r.a:this.a;return this.setColor(e,o,n,a)},r.prototype.addNumberForRGB=function(r){return this.r=this.r+r,this.g=this.g+r,this.b=this.b+r,this},r.prototype.addNumberForAlpha=function(r){return this.a=this.a+r,this},r.parseHEX=function(t){var e=s.clearStrSpace(t),o=s.parse3BitsHEX(e);return o||(o=s.parse6BitsHEX(e)),o&&r.fromArray(o)},r.parseRGBA=function(t){var e=s.clearStrSpace(t),o=s.parseRGBA(e);if(!o){var n=s.trimStr(t);o=s.parseRGBA2(n)}return o&&r.fromArray(o)},r.fromJson=function(t){return new r(t.r,t.g,t.b,t.a)},r.fromArray=function(t){return new r(t[0],t[1],t[2],t[3])},r.fromRandom=function(t,e){return new r(Math.random()*Math.abs(e.r-t.r)+Math.min(t.r,e.r),Math.random()*Math.abs(e.g-t.g)+Math.min(t.g,e.g),Math.random()*Math.abs(e.b-t.b)+Math.min(t.b,e.b),Math.random()*Math.abs(e.a-t.a)+Math.min(t.a,e.a))},r.fromNormalize=function(t){var e=255*t[0],o=255*t[1],n=255*t[2],a=t[3];return r.fromArray([e,o,n,a])},r}(),u=require("tslib"),c=require("color-convert"),p=r.n(c),h=function(r){function t(){return null!==r&&r.apply(this,arguments)||this}return(0,u.__extends)(t,r),t.prototype.toInvert=function(){return new t(255-this.r,255-this.g,255-this.b,1-this.a)},t.prototype.clone=function(){return new t(this.r,this.g,this.b,this.a)},t.prototype.equals=function(r){if(this===(r=t.parseColor(r)))return!0;var e=this.toJson(),o=r.toJson();return e.r===o.r&&e.g===o.g&&e.b===o.g&&e.a===o.a},t.prototype.add=function(e,o){void 0===o&&(o=!0);var n=t.parseColor(e);return r.prototype.add.call(this,n,o)},t.prototype.subtract=function(e,o){void 0===o&&(o=!0);var n=t.parseColor(e);return r.prototype.subtract.call(this,n,o)},t.prototype.multiply=function(e,o){void 0===o&&(o=!0);var n=t.parseColor(e);return r.prototype.multiply.call(this,n,o)},t.prototype.divide=function(e,o){void 0===o&&(o=!0);var n=t.parseColor(e);return r.prototype.divide.call(this,n,o)},t.parseColor=function(r){return r instanceof i?r:t.parseCssColorStr(r)},t.parseCssColorStr=function(r){return e.type("color",r,"string"),t.parseHEX(r)||t.parseRGBA(r)||t.parseKeyWord(r)||t.parseHSLA(r)||t.parseHWB(r)},t.parseKeyWord=function(r){var e=s.clearStrSpace(r),o=p().keyword.rgb(e);return o&&t.fromArray(o)},t.parseHSLA=function(r){var e=s.clearStrSpace(r),o=s.parseHSLA(e);if(!o){var n=s.trimStr(r);o=s.parseHSLA2(n)}return o&&t.fromHSL(o[0],o[1],o[2],o[3])},t.parseHWB=function(r){var e=s.trimStr(r),o=s.parseHWB(e);return o&&t.fromHWB(o[0],o[1],o[2],o[3])},t.fromHSL=function(r,e,a,s){var i=p().hsl.rgb(n(0,360,r),n(0,100,100*e),n(0,100,100*a));return new t(i[0],i[1],i[2],o(Number(s),1))},t.fromHWB=function(r,e,a,s){var i=p().hwb.rgb(n(0,360,r),n(0,100,100*e),n(0,100,100*a));return new t(i[0],i[1],i[2],o(Number(s),1))},t.parseHEX=function(r){var e=s.clearStrSpace(r),o=s.parse3BitsHEX(e);return o||(o=s.parse6BitsHEX(e)),o&&t.fromArray(o)},t.parseRGBA=function(r){var e=s.clearStrSpace(r),o=s.parseRGBA(e);if(!o){var n=s.trimStr(r);o=s.parseRGBA2(n)}return o&&t.fromArray(o)},t.fromJson=function(r){return new t(r.r,r.g,r.b,r.a)},t.fromArray=function(r){return new t(r[0],r[1],r[2],r[3])},t.fromRandom=function(r,e){return r=t.parseColor(r),e=t.parseColor(e),new t(Math.random()*Math.abs(e.r-r.r)+Math.min(r.r,e.r),Math.random()*Math.abs(e.g-r.g)+Math.min(r.g,e.g),Math.random()*Math.abs(e.b-r.b)+Math.min(r.b,e.b),Math.random()*Math.abs(e.a-r.a)+Math.min(r.a,e.a))},t.fromNormalize=function(r){var e=255*r[0],o=255*r[1],n=255*r[2],a=r[3];return t.fromArray([e,o,n,a])},t}(i),f=h,l=exports;for(var b in t)l[b]=t[b];t.__esModule&&Object.defineProperty(l,"__esModule",{value:!0})}();
|