diff --git a/build.js b/build.js index 5323bd6..c4fde8c 100644 --- a/build.js +++ b/build.js @@ -20,12 +20,6 @@ async function write_cdn_umd() { `; Deno.writeTextFileSync("npm/tinycolor.js", preamble + output[0].code); Deno.writeTextFileSync("npm/dist/tinycolor-min.js", preamble + minified.code); - - // Keeping these (without preamble) until we can confirm they aren't used by CDNs - // after moving to the npm/ path. At that point these files can be removed in - // https://github.com/bgrins/TinyColor/issues/260. - Deno.writeTextFileSync("tinycolor.js", output[0].code); - Deno.writeTextFileSync("dist/tinycolor-min.js", minified.code); } // Write necessary files for testing & publishing commonjs to npm. diff --git a/demo/server.jsx b/demo/server.jsx index 667bd02..a5e1f18 100644 --- a/demo/server.jsx +++ b/demo/server.jsx @@ -104,7 +104,7 @@ const handler = (req) => { if (pathname === "/") { return serveFile(req, "./index.html"); } - if (["/demo/demo.css", "/tinycolor.js"].includes(pathname)) { + if (["/demo/demo.css", "/npm/tinycolor.js"].includes(pathname)) { return serveFile(req, `.${pathname}`); } if (pathname.startsWith("/api/")) { diff --git a/dist/tinycolor-min.js b/dist/tinycolor-min.js deleted file mode 100644 index d2eb93b..0000000 --- a/dist/tinycolor-min.js +++ /dev/null @@ -1 +0,0 @@ -!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).tinycolor=r()}(this,(function(){"use strict";const t=/^\s+/,r=/\s+$/;function e(a,n){if(n=n||{},(a=a||"")instanceof e)return a;if(!(this instanceof e))return new e(a,n);var i=function(e){var a={r:0,g:0,b:0},n=1,i=null,o=null,h=null,s=!1,f=!1;"string"==typeof e&&(e=function(e){e=e.replace(t,"").replace(r,"").toLowerCase();var a,n=!1;if(v[e])e=v[e],n=!0;else if("transparent"==e)return{r:0,g:0,b:0,a:0,format:"name"};if(a=N.rgb.exec(e))return{r:a[1],g:a[2],b:a[3]};if(a=N.rgba.exec(e))return{r:a[1],g:a[2],b:a[3],a:a[4]};if(a=N.hsl.exec(e))return{h:a[1],s:a[2],l:a[3]};if(a=N.hsla.exec(e))return{h:a[1],s:a[2],l:a[3],a:a[4]};if(a=N.hsv.exec(e))return{h:a[1],s:a[2],v:a[3]};if(a=N.hsva.exec(e))return{h:a[1],s:a[2],v:a[3],a:a[4]};if(a=N.hex8.exec(e))return{r:k(a[1]),g:k(a[2]),b:k(a[3]),a:R(a[4]),format:n?"name":"hex8"};if(a=N.hex6.exec(e))return{r:k(a[1]),g:k(a[2]),b:k(a[3]),format:n?"name":"hex"};if(a=N.hex4.exec(e))return{r:k(a[1]+""+a[1]),g:k(a[2]+""+a[2]),b:k(a[3]+""+a[3]),a:R(a[4]+""+a[4]),format:n?"name":"hex8"};if(a=N.hex3.exec(e))return{r:k(a[1]+""+a[1]),g:k(a[2]+""+a[2]),b:k(a[3]+""+a[3]),format:n?"name":"hex"};return!1}(e));"object"==typeof e&&(T(e.r)&&T(e.g)&&T(e.b)?(u=e.r,l=e.g,c=e.b,a={r:255*x(u,255),g:255*x(l,255),b:255*x(c,255)},s=!0,f="%"===String(e.r).substr(-1)?"prgb":"rgb"):T(e.h)&&T(e.s)&&T(e.v)?(i=S(e.s),o=S(e.v),a=function(t,r,e){t=6*x(t,360),r=x(r,100),e=x(e,100);var a=Math.floor(t),n=t-a,i=e*(1-r),o=e*(1-n*r),h=e*(1-(1-n)*r),s=a%6,f=[e,o,i,i,h,e][s],u=[h,e,e,o,i,i][s],l=[i,i,h,e,e,o][s];return{r:255*f,g:255*u,b:255*l}}(e.h,i,o),s=!0,f="hsv"):T(e.h)&&T(e.s)&&T(e.l)&&(i=S(e.s),h=S(e.l),a=function(t,r,e){var a,n,i;function o(t,r,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?t+6*(r-t)*e:e<.5?r:e<2/3?t+(r-t)*(2/3-e)*6:t}if(t=x(t,360),r=x(r,100),e=x(e,100),0===r)a=n=i=e;else{var h=e<.5?e*(1+r):e+r-e*r,s=2*e-h;a=o(s,h,t+1/3),n=o(s,h,t),i=o(s,h,t-1/3)}return{r:255*a,g:255*n,b:255*i}}(e.h,i,h),s=!0,f="hsl"),e.hasOwnProperty("a")&&(n=e.a));var u,l,c;return n=y(n),{ok:s,format:e.format||f,r:Math.min(255,Math.max(a.r,0)),g:Math.min(255,Math.max(a.g,0)),b:Math.min(255,Math.max(a.b,0)),a:n}}(a);this._originalInput=a,this._r=i.r,this._g=i.g,this._b=i.b,this._a=i.a,this._roundA=Math.round(100*this._a)/100,this._format=n.format||i.format,this._gradientType=n.gradientType,this._r<1&&(this._r=Math.round(this._r)),this._g<1&&(this._g=Math.round(this._g)),this._b<1&&(this._b=Math.round(this._b)),this._ok=i.ok}function a(t,r,e){t=x(t,255),r=x(r,255),e=x(e,255);var a,n,i=Math.max(t,r,e),o=Math.min(t,r,e),h=(i+o)/2;if(i==o)a=n=0;else{var s=i-o;switch(n=h>.5?s/(2-i-o):s/(i+o),i){case t:a=(r-e)/s+(r>1)+720)%360;--r;)n.h=(n.h+i)%360,o.push(e(n));return o}function _(t,r){r=r||6;for(var a=e(t).toHsv(),n=a.h,i=a.s,o=a.v,h=[],s=1/r;r--;)h.push(e({h:n,s:i,v:o})),o=(o+s)%1;return h}e.prototype={isDark:function(){return this.getBrightness()<128},isLight:function(){return!this.isDark()},isValid:function(){return this._ok},getOriginalInput:function(){return this._originalInput},getFormat:function(){return this._format},getAlpha:function(){return this._a},getBrightness:function(){var t=this.toRgb();return(299*t.r+587*t.g+114*t.b)/1e3},getLuminance:function(){var t,r,e,a=this.toRgb();return t=a.r/255,r=a.g/255,e=a.b/255,.2126*(t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4))+.7152*(r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4))+.0722*(e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4))},setAlpha:function(t){return this._a=y(t),this._roundA=Math.round(100*this._a)/100,this},toHsv:function(){var t=n(this._r,this._g,this._b);return{h:360*t.h,s:t.s,v:t.v,a:this._a}},toHsvString:function(){var t=n(this._r,this._g,this._b),r=Math.round(360*t.h),e=Math.round(100*t.s),a=Math.round(100*t.v);return 1==this._a?"hsv("+r+", "+e+"%, "+a+"%)":"hsva("+r+", "+e+"%, "+a+"%, "+this._roundA+")"},toHsl:function(){var t=a(this._r,this._g,this._b);return{h:360*t.h,s:t.s,l:t.l,a:this._a}},toHslString:function(){var t=a(this._r,this._g,this._b),r=Math.round(360*t.h),e=Math.round(100*t.s),n=Math.round(100*t.l);return 1==this._a?"hsl("+r+", "+e+"%, "+n+"%)":"hsla("+r+", "+e+"%, "+n+"%, "+this._roundA+")"},toHex:function(t){return i(this._r,this._g,this._b,t)},toHexString:function(t){return"#"+this.toHex(t)},toHex8:function(t){return function(t,r,e,a,n){var i=[w(Math.round(t).toString(16)),w(Math.round(r).toString(16)),w(Math.round(e).toString(16)),w(H(a))];if(n&&i[0].charAt(0)==i[0].charAt(1)&&i[1].charAt(0)==i[1].charAt(1)&&i[2].charAt(0)==i[2].charAt(1)&&i[3].charAt(0)==i[3].charAt(1))return i[0].charAt(0)+i[1].charAt(0)+i[2].charAt(0)+i[3].charAt(0);return i.join("")}(this._r,this._g,this._b,this._a,t)},toHex8String:function(t){return"#"+this.toHex8(t)},toRgb:function(){return{r:Math.round(this._r),g:Math.round(this._g),b:Math.round(this._b),a:this._a}},toRgbString:function(){return 1==this._a?"rgb("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+")":"rgba("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+", "+this._roundA+")"},toPercentageRgb:function(){return{r:Math.round(100*x(this._r,255))+"%",g:Math.round(100*x(this._g,255))+"%",b:Math.round(100*x(this._b,255))+"%",a:this._a}},toPercentageRgbString:function(){return 1==this._a?"rgb("+Math.round(100*x(this._r,255))+"%, "+Math.round(100*x(this._g,255))+"%, "+Math.round(100*x(this._b,255))+"%)":"rgba("+Math.round(100*x(this._r,255))+"%, "+Math.round(100*x(this._g,255))+"%, "+Math.round(100*x(this._b,255))+"%, "+this._roundA+")"},toName:function(){return 0===this._a?"transparent":!(this._a<1)&&(M[i(this._r,this._g,this._b,!0)]||!1)},toFilter:function(t){var r="#"+o(this._r,this._g,this._b,this._a),a=r,n=this._gradientType?"GradientType = 1, ":"";if(t){var i=e(t);a="#"+o(i._r,i._g,i._b,i._a)}return"progid:DXImageTransform.Microsoft.gradient("+n+"startColorstr="+r+",endColorstr="+a+")"},toString:function(t){var r=!!t;t=t||this._format;var e=!1,a=this._a<1&&this._a>=0;return r||!a||"hex"!==t&&"hex6"!==t&&"hex3"!==t&&"hex4"!==t&&"hex8"!==t&&"name"!==t?("rgb"===t&&(e=this.toRgbString()),"prgb"===t&&(e=this.toPercentageRgbString()),"hex"!==t&&"hex6"!==t||(e=this.toHexString()),"hex3"===t&&(e=this.toHexString(!0)),"hex4"===t&&(e=this.toHex8String(!0)),"hex8"===t&&(e=this.toHex8String()),"name"===t&&(e=this.toName()),"hsl"===t&&(e=this.toHslString()),"hsv"===t&&(e=this.toHsvString()),e||this.toHexString()):"name"===t&&0===this._a?this.toName():this.toRgbString()},clone:function(){return e(this.toString())},_applyModification:function(t,r){var e=t.apply(null,[this].concat([].slice.call(r)));return this._r=e._r,this._g=e._g,this._b=e._b,this.setAlpha(e._a),this},lighten:function(){return this._applyModification(u,arguments)},brighten:function(){return this._applyModification(l,arguments)},darken:function(){return this._applyModification(c,arguments)},desaturate:function(){return this._applyModification(h,arguments)},saturate:function(){return this._applyModification(s,arguments)},greyscale:function(){return this._applyModification(f,arguments)},spin:function(){return this._applyModification(d,arguments)},_applyCombination:function(t,r){return t.apply(null,[this].concat([].slice.call(r)))},analogous:function(){return this._applyCombination(p,arguments)},complement:function(){return this._applyCombination(g,arguments)},monochromatic:function(){return this._applyCombination(_,arguments)},splitcomplement:function(){return this._applyCombination(m,arguments)},triad:function(){return this._applyCombination(b,[3])},tetrad:function(){return this._applyCombination(b,[4])}},e.fromRatio=function(t,r){if("object"==typeof t){var a={};for(var n in t)t.hasOwnProperty(n)&&(a[n]="a"===n?t[n]:S(t[n]));t=a}return e(t,r)},e.equals=function(t,r){return!(!t||!r)&&e(t).toRgbString()==e(r).toRgbString()},e.random=function(){return e.fromRatio({r:Math.random(),g:Math.random(),b:Math.random()})},e.mix=function(t,r,a){a=0===a?0:a||50;var n=e(t).toRgb(),i=e(r).toRgb(),o=a/100;return e({r:(i.r-n.r)*o+n.r,g:(i.g-n.g)*o+n.g,b:(i.b-n.b)*o+n.b,a:(i.a-n.a)*o+n.a})},e.readability=function(t,r){var a=e(t),n=e(r);return(Math.max(a.getLuminance(),n.getLuminance())+.05)/(Math.min(a.getLuminance(),n.getLuminance())+.05)},e.isReadable=function(t,r,a){var n,i,o=e.readability(t,r);switch(i=!1,(n=function(t){var r,e;r=((t=t||{level:"AA",size:"small"}).level||"AA").toUpperCase(),e=(t.size||"small").toLowerCase(),"AA"!==r&&"AAA"!==r&&(r="AA");"small"!==e&&"large"!==e&&(e="small");return{level:r,size:e}}(a)).level+n.size){case"AAsmall":case"AAAlarge":i=o>=4.5;break;case"AAlarge":i=o>=3;break;case"AAAsmall":i=o>=7}return i},e.mostReadable=function(t,r,a){var n,i,o,h,s=null,f=0;i=(a=a||{}).includeFallbackColors,o=a.level,h=a.size;for(var u=0;uf&&(f=n,s=e(r[u]));return e.isReadable(t,s,{level:o,size:h})||!i?s:(a.includeFallbackColors=!1,e.mostReadable(t,["#fff","#000"],a))};var v=e.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"663399",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},M=e.hexNames=function(t){var r={};for(var e in t)t.hasOwnProperty(e)&&(r[t[e]]=e);return r}(v);function y(t){return t=parseFloat(t),(isNaN(t)||t<0||t>1)&&(t=1),t}function x(t,r){(function(t){return"string"==typeof t&&-1!=t.indexOf(".")&&1===parseFloat(t)})(t)&&(t="100%");var e=function(t){return"string"==typeof t&&-1!=t.indexOf("%")}(t);return t=Math.min(r,Math.max(0,parseFloat(t))),e&&(t=parseInt(t*r,10)/100),Math.abs(t-r)<1e-6?1:t%r/parseFloat(r)}function A(t){return Math.min(1,Math.max(0,t))}function k(t){return parseInt(t,16)}function w(t){return 1==t.length?"0"+t:""+t}function S(t){return t<=1&&(t=100*t+"%"),t}function H(t){return Math.round(255*parseFloat(t)).toString(16)}function R(t){return k(t)/255}var F,C,q,N=(C="[\\s|\\(]+("+(F="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)")+")[,|\\s]+("+F+")[,|\\s]+("+F+")\\s*\\)?",q="[\\s|\\(]+("+F+")[,|\\s]+("+F+")[,|\\s]+("+F+")[,|\\s]+("+F+")\\s*\\)?",{CSS_UNIT:new RegExp(F),rgb:new RegExp("rgb"+C),rgba:new RegExp("rgba"+q),hsl:new RegExp("hsl"+C),hsla:new RegExp("hsla"+q),hsv:new RegExp("hsv"+C),hsva:new RegExp("hsva"+q),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/});function T(t){return!!N.CSS_UNIT.exec(t)}return e})); \ No newline at end of file diff --git a/index.html b/index.html index 8b7471c..07f210b 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ TinyColor - Fast, small color manipulation in JavaScript - +