7594b6811ba4b3af6f43d77714a9e513.json
6.66 KB
{"ast":null,"code":"/**\n * Take input from [0, n] and return it as [0, 1]\n * @hidden\n */\nexport function bound01(n, max) {\n if (isOnePointZero(n)) {\n n = '100%';\n }\n\n var isPercent = isPercentage(n);\n n = max === 360 ? n : Math.min(max, Math.max(0, parseFloat(n))); // Automatically convert percentage into number\n\n if (isPercent) {\n n = parseInt(String(n * max), 10) / 100;\n } // Handle floating point rounding errors\n\n\n if (Math.abs(n - max) < 0.000001) {\n return 1;\n } // Convert into [0, 1] range if it isn't already\n\n\n if (max === 360) {\n // If n is a hue given in degrees,\n // wrap around out-of-range values into [0, 360] range\n // then convert into [0, 1].\n n = (n < 0 ? n % max + max : n % max) / parseFloat(String(max));\n } else {\n // If n not a hue given in degrees\n // Convert into [0, 1] range if it isn't already.\n n = n % max / parseFloat(String(max));\n }\n\n return n;\n}\n/**\n * Force a number between 0 and 1\n * @hidden\n */\n\nexport function clamp01(val) {\n return Math.min(1, Math.max(0, val));\n}\n/**\n * Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1\n * <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>\n * @hidden\n */\n\nexport function isOnePointZero(n) {\n return typeof n === 'string' && n.includes('.') && parseFloat(n) === 1;\n}\n/**\n * Check to see if string passed in is a percentage\n * @hidden\n */\n\nexport function isPercentage(n) {\n return typeof n === 'string' && n.includes('%');\n}\n/**\n * Return a valid alpha value [0,1] with all invalid values being set to 1\n * @hidden\n */\n\nexport function boundAlpha(a) {\n a = parseFloat(a);\n\n if (isNaN(a) || a < 0 || a > 1) {\n a = 1;\n }\n\n return a;\n}\n/**\n * Replace a decimal with it's percentage value\n * @hidden\n */\n\nexport function convertToPercentage(n) {\n if (n <= 1) {\n return Number(n) * 100 + \"%\";\n }\n\n return n;\n}\n/**\n * Force a hex value to have 2 characters\n * @hidden\n */\n\nexport function pad2(c) {\n return c.length === 1 ? '0' + c : String(c);\n}","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/@ctrl/tinycolor/dist/module/util.js"],"names":["bound01","n","max","isOnePointZero","isPercent","isPercentage","Math","min","parseFloat","parseInt","String","abs","clamp01","val","includes","boundAlpha","a","isNaN","convertToPercentage","Number","pad2","c","length"],"mappings":"AAAA;AACA;AACA;AACA;AACA,OAAO,SAASA,OAAT,CAAiBC,CAAjB,EAAoBC,GAApB,EAAyB;AAC5B,MAAIC,cAAc,CAACF,CAAD,CAAlB,EAAuB;AACnBA,IAAAA,CAAC,GAAG,MAAJ;AACH;;AACD,MAAIG,SAAS,GAAGC,YAAY,CAACJ,CAAD,CAA5B;AACAA,EAAAA,CAAC,GAAGC,GAAG,KAAK,GAAR,GAAcD,CAAd,GAAkBK,IAAI,CAACC,GAAL,CAASL,GAAT,EAAcI,IAAI,CAACJ,GAAL,CAAS,CAAT,EAAYM,UAAU,CAACP,CAAD,CAAtB,CAAd,CAAtB,CAL4B,CAM5B;;AACA,MAAIG,SAAJ,EAAe;AACXH,IAAAA,CAAC,GAAGQ,QAAQ,CAACC,MAAM,CAACT,CAAC,GAAGC,GAAL,CAAP,EAAkB,EAAlB,CAAR,GAAgC,GAApC;AACH,GAT2B,CAU5B;;;AACA,MAAII,IAAI,CAACK,GAAL,CAASV,CAAC,GAAGC,GAAb,IAAoB,QAAxB,EAAkC;AAC9B,WAAO,CAAP;AACH,GAb2B,CAc5B;;;AACA,MAAIA,GAAG,KAAK,GAAZ,EAAiB;AACb;AACA;AACA;AACAD,IAAAA,CAAC,GAAG,CAACA,CAAC,GAAG,CAAJ,GAASA,CAAC,GAAGC,GAAL,GAAYA,GAApB,GAA0BD,CAAC,GAAGC,GAA/B,IAAsCM,UAAU,CAACE,MAAM,CAACR,GAAD,CAAP,CAApD;AACH,GALD,MAMK;AACD;AACA;AACAD,IAAAA,CAAC,GAAIA,CAAC,GAAGC,GAAL,GAAYM,UAAU,CAACE,MAAM,CAACR,GAAD,CAAP,CAA1B;A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**\n * Take input from [0, n] and return it as [0, 1]\n * @hidden\n */\nexport function bound01(n, max) {\n if (isOnePointZero(n)) {\n n = '100%';\n }\n var isPercent = isPercentage(n);\n n = max === 360 ? n : Math.min(max, Math.max(0, parseFloat(n)));\n // Automatically convert percentage into number\n if (isPercent) {\n n = parseInt(String(n * max), 10) / 100;\n }\n // Handle floating point rounding errors\n if (Math.abs(n - max) < 0.000001) {\n return 1;\n }\n // Convert into [0, 1] range if it isn't already\n if (max === 360) {\n // If n is a hue given in degrees,\n // wrap around out-of-range values into [0, 360] range\n // then convert into [0, 1].\n n = (n < 0 ? (n % max) + max : n % max) / parseFloat(String(max));\n }\n else {\n // If n not a hue given in degrees\n // Convert into [0, 1] range if it isn't already.\n n = (n % max) / parseFloat(String(max));\n }\n return n;\n}\n/**\n * Force a number between 0 and 1\n * @hidden\n */\nexport function clamp01(val) {\n return Math.min(1, Math.max(0, val));\n}\n/**\n * Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1\n * <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>\n * @hidden\n */\nexport function isOnePointZero(n) {\n return typeof n === 'string' && n.includes('.') && parseFloat(n) === 1;\n}\n/**\n * Check to see if string passed in is a percentage\n * @hidden\n */\nexport function isPercentage(n) {\n return typeof n === 'string' && n.includes('%');\n}\n/**\n * Return a valid alpha value [0,1] with all invalid values being set to 1\n * @hidden\n */\nexport function boundAlpha(a) {\n a = parseFloat(a);\n if (isNaN(a) || a < 0 || a > 1) {\n a = 1;\n }\n return a;\n}\n/**\n * Replace a decimal with it's percentage value\n * @hidden\n */\nexport function convertToPercentage(n) {\n if (n <= 1) {\n return Number(n) * 100 + \"%\";\n }\n return n;\n}\n/**\n * Force a hex value to have 2 characters\n * @hidden\n */\nexport function pad2(c) {\n return c.length === 1 ? '0' + c : String(c);\n}\n"]},"metadata":{},"sourceType":"module"}