css-color-parser-h 2.0.4 → 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/@types/index.d.ts +219 -143
- 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.js +741 -154
- package/dist/css-color-parser-h.umd.min.js +1 -1
- package/example.html +9 -47
- package/package.json +3 -2
- package/readme.md +52 -41
- package/dist/css-color-parser-h.common.js +0 -841
- package/dist/css-color-parser-h.common.min.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(){"use strict";var t={n:function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(n,{a:n}),n},d:function(r,n){for(var e in n)t.o(n,e)&&!t.o(r,e)&&Object.defineProperty(r,e,{enumerable:!0,get:n[e]})},o:function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},r={};t.r(r),t.d(r,{CssColorParser:function(){return s},fromArray:function(){return _},fromColorStr:function(){return m},fromHSL:function(){return y},fromHWB:function(){return v},fromJson:function(){return S},fromRandom:function(){return d},parseCssColorStr:function(){return g},parseHEX:function(){return f},parseHSLA:function(){return l},parseHWB:function(){return b},parseKeyWord:function(){return p},parseRGBA:function(){return h}});var n=function(){function t(){}return t.type=function(t,r,n){var e=typeof r;if(e!==n)throw new Error("Expected ".concat(t," to be typeof ").concat(n,", actual typeof was ").concat(e))},t.types=function(t,r,n){var e=typeof r;if(!n.includes(e))throw new Error("Expected ".concat(t," to be typeof ").concat(n.join("|"),", actual typeof was ").concat(e))},t.numValue=function(r,n,e,o){t.numMinValue(r,n,e),t.numMaxValue(r,n,o)},t.numMinValue=function(t,r,n){if(r<n)throw new Error("Expected ".concat(t," to > ").concat(n,", actual value was ").concat(r))},t.numMaxValue=function(t,r,n){if(r>n)throw new Error("Expected ".concat(t," to < ").concat(n,", actual value was ").concat(r))},t.numIsInt=function(t,r,n){var e=Math.floor(r)===r;if(e!==n)throw new Error("Expected ".concat(t," to ").concat(n?"Integer":"Float",", actual value was ").concat(e?"Integer":"Float"))},t}();function e(t,r){return null==t||isNaN(t)&&"number"==typeof r?r:t}function o(t,r,n){return n>r?n=r:n<t&&(n=t),n}function i(t,r){void 0===t&&(t=0);var n=Math.pow(10,r);return Math.round(t*n)/n}var a=function(){function t(){}return t.clearStrSpace=function(t){return t.replace(/\s/g,"")},t.trimStr=function(t){return(t=t.replace(/\s+/g," ")).trim()},t.parse3BitsHEX=function(r){var n=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i.exec(r);if(n){var o=e(n[4],"f");return[t._parseResStrForRgb(parseInt(n[1]+n[1],16)),t._parseResStrForRgb(parseInt(n[2]+n[2],16)),t._parseResStrForRgb(parseInt(n[3]+n[3],16)),t._parsePercent(parseInt(o+o,16)/255)]}return null},t.parse6BitsHEX=function(r){var n=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i.exec(r);if(n){var o=e(n[4],"ff");return[t._parseResStrForRgb(parseInt(n[1],16)),t._parseResStrForRgb(parseInt(n[2],16)),t._parseResStrForRgb(parseInt(n[3],16)),t._parsePercent(parseInt(o,16)/255)]}return null},t.parseRGBA=function(r){var n=/^rgba?\(([0-9.]+%?),([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(r);return n?[t._parseResStrForRgb(n[1]),t._parseResStrForRgb(n[2]),t._parseResStrForRgb(n[3]),t._parsePercent(n[4])]:null},t.parseHSLA=function(r){var n=/^hsla?\(([0-9.]+)(?:deg)?,([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(r);return n?[t._parseResStrForHue(n[1]),t._parsePercent(n[2]),t._parsePercent(n[3]),t._parsePercent(n[4])]:null},t.parseHWB=function(r){var n=/^hwb\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return n?[t._parseResStrForHue(n[1]),t._parsePercent(n[2]),t._parsePercent(n[3]),t._parsePercent(n[4])]:null},t.parseRGBA2=function(r){var n=/^rgba?\s?\(\s?([0-9.]+%?)\s?([0-9.]+%?)\s?([0-9.]+%?)(?:\s?\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return n?[t._parseResStrForRgb(n[1]),t._parseResStrForRgb(n[2]),t._parseResStrForRgb(n[3]),t._parsePercent(n[4])]:null},t.parseHSLA2=function(r){var n=/^hsla?\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return n?[t._parseResStrForHue(n[1]),t._parsePercent(n[2]),t._parsePercent(n[3]),t._parsePercent(n[4])]:null},t._parseResStrForRgb=function(t){return"string"==typeof t&&(t=parseFloat(t)/("%"===t.substr(-1)?100/255:1)),isNaN(t)&&(t=1),o(0,255,t)},t._parseResStrForHue=function(t){return"string"==typeof t&&(t=parseFloat(t)),isNaN(t)&&(t=0),o(0,360,t)},t._parsePercent=function(t){return"string"==typeof t&&(t=parseFloat(t)/("%"===t.substr(-1)?100:1)),isNaN(t)&&(t=1),o(0,1,t)},t}(),s=function(){function t(t,r,n,e){this.r=255,this.g=255,this.b=255,this.a=1,this._outColorPrecision=2,this._outAlphaPrecision=2,this.setColor(t,r,n,e)}return t.prototype.setOutPrecision=function(t,r){return n.type("colorPrecision",t,"number"),n.type("outAlphaPrecision",r,"number"),n.numMinValue("colorPrecision",t,0),n.numMinValue("outAlphaPrecision",r,0),n.numIsInt("colorPrecision",t,!0),n.numIsInt("outAlphaPrecision",r,!0),this._outColorPrecision=t,this._outAlphaPrecision=r,this},t.prototype.setColor=function(t,r,n,i){return this.r=o(0,255,e(Number(t),0)),this.g=o(0,255,e(Number(r),0)),this.b=o(0,255,e(Number(n),0)),this.a=o(0,1,e(Number(i),1)),this},t.prototype.setAlpha=function(t){return this.a=o(0,1,e(Number(t),1)),this},t.prototype.setRed=function(t){return this.r=o(0,255,e(Number(t),0)),this},t.prototype.setGreen=function(t){return this.g=o(0,255,e(Number(t),0)),this},t.prototype.setBlue=function(t){return this.b=o(0,255,e(Number(t),0)),this},t.prototype.toRGBA=function(){var t=this.toJson();return 1===t.a?"rgb(".concat(t.r,",").concat(t.g,",").concat(t.b,")"):"rgba(".concat(t.r,",").concat(t.g,",").concat(t.b,",").concat(t.a,")")},t.prototype.toString=function(){return this.toRGBA()},t.prototype.toNormalize=function(){return[i(this.r/255,this._outColorPrecision),i(this.g/255,this._outColorPrecision),i(this.b/255,this._outColorPrecision),i(this.a,this._outAlphaPrecision)]},t.prototype.toHEX=function(){var t=this.toJson(),r=t.r.toString(16);r.length<2&&(r="0".concat(r));var n=t.g.toString(16);n.length<2&&(n="0".concat(n));var e=t.b.toString(16);if(e.length<2&&(e="0".concat(e)),this.a<1){var o=parseInt((255*this.a).toFixed()).toString(16);return o.length<2&&(o="0".concat(o)),"#".concat(r).concat(n).concat(e).concat(o)}return"#".concat(r).concat(n).concat(e)},t.prototype.toArray=function(){var t=this.toJson();return[t.r,t.g,t.b,t.a]},t.prototype.toJson=function(){return{r:i(this.r,this._outColorPrecision),g:i(this.g,this._outColorPrecision),b:i(this.b,this._outColorPrecision),a:i(this.a,this._outAlphaPrecision)}},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(t){if(this===t)return!0;var r=this.toJson(),n=t.toJson();return r.r===n.r&&r.g===n.g&&r.b===n.g&&r.a===n.a},t.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},t.prototype.multiplyByScalar=function(t,r){void 0===r&&(r=!0);var n=this.r*t,e=this.g*t,o=this.b*t,i=r?this.a*t:this.a;return this.setColor(n,e,o,i)},t.prototype.divideByScalar=function(t,r){void 0===r&&(r=!0);var n=this.r/t,e=this.g/t,o=this.b/t,i=r?this.a/t:this.a;return this.setColor(n,e,o,i)},t.prototype.add=function(t,r){void 0===r&&(r=!0);var n=this.r+t.r,e=this.g+t.g,o=this.b+t.b,i=r?this.a+t.a:this.a;return this.setColor(n,e,o,i)},t.prototype.subtract=function(t,r){void 0===r&&(r=!0);var n=this.r-t.r,e=this.g-t.g,o=this.b-t.b,i=r?this.a-t.a:this.a;return this.setColor(n,e,o,i)},t.prototype.multiply=function(t,r){void 0===r&&(r=!0);var n=this.r*t.r,e=this.g*t.g,o=this.b*t.b,i=r?this.a*t.a:this.a;return this.setColor(n,e,o,i)},t.prototype.divide=function(t,r){void 0===r&&(r=!0);var n=this.r/t.r,e=this.g/t.g,o=this.b/t.b,i=r?this.a/t.a:this.a;return this.setColor(n,e,o,i)},t.prototype.addNumberForRGB=function(t){return this.r=this.r+t,this.g=this.g+t,this.b=this.b+t,this},t.prototype.addNumberForAlpha=function(t){return this.a=this.a+t,this},t.parseHEX=function(r){var n=a.clearStrSpace(r),e=a.parse3BitsHEX(n);return e||(e=a.parse6BitsHEX(n)),e&&t.fromArray(e)},t.parseRGBA=function(r){var n=a.clearStrSpace(r),e=a.parseRGBA(n);if(!e){var o=a.trimStr(r);e=a.parseRGBA2(o)}return e&&t.fromArray(e)},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,n){return new t(Math.random()*Math.abs(n.r-r.r)+Math.min(r.r,n.r),Math.random()*Math.abs(n.g-r.g)+Math.min(r.g,n.g),Math.random()*Math.abs(n.b-r.b)+Math.min(r.b,n.b),Math.random()*Math.abs(n.a-r.a)+Math.min(r.a,n.a))},t.fromNormalize=function(r){var n=255*r[0],e=255*r[1],o=255*r[2],i=r[3];return t.fromArray([n,e,o,i])},t}(),u=require("color-convert"),c=t.n(u);function p(t){var r=a.clearStrSpace(t),n=c().keyword.rgb(r);return n&&_(n)}function f(t){return s.parseHEX(t)}function h(t){return s.parseRGBA(t)}function l(t){var r=a.clearStrSpace(t),n=a.parseHSLA(r);if(!n){var e=a.trimStr(t);n=a.parseHSLA2(e)}return n&&y(n[0],n[1],n[2],n[3])}function b(t){var r=a.trimStr(t),n=a.parseHWB(r);return n&&v(n[0],n[1],n[2],n[3])}function g(t){return n.type("color",t,"string"),f(t)||h(t)||p(t)||l(t)||b(t)}function m(t){return g(t)}function y(t,r,n,i){var a=c().hsl.rgb(o(0,360,t),o(0,100,100*r),o(0,100,100*n));return new s(a[0],a[1],a[2],e(Number(i),1))}function v(t,r,n,i){var a=c().hwb.rgb(o(0,360,t),o(0,100,100*r),o(0,100,100*n));return new s(a[0],a[1],a[2],e(Number(i),1))}function d(t,r){if("string"==typeof t&&(t=g(t)),"string"==typeof r&&(r=g(r)),!t||!r)throw new Error("fail to create object from random");return s.fromRandom(t,r)}function S(t){return s.fromJson(t)}function _(t){return s.fromArray(t)}var R=exports;for(var P in r)R[P]=r[P];r.__esModule&&Object.defineProperty(R,"__esModule",{value:!0})}();
|