tiny-essentials
Version:
Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.
1 lines • 8.28 kB
JavaScript
(()=>{"use strict";var e={d:(r,t)=>{for(var s in t)e.o(t,s)&&!e.o(r,s)&&Object.defineProperty(r,s,{enumerable:!0,get:t[s]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r)},r={};e.d(r,{TinyColorValidator:()=>s});class t{static#e=/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;static#r=/^#([A-Fa-f0-9]{8})$/;static#t="(0|1|0?\\.\\d+)";static#s="(0|[1-9]\\d?|1\\d{2}|2[0-4]\\d|25[0-5])";static#a="(0|[1-9]\\d?|[1-2]\\d{2}|3[0-5]\\d|360)";static#i="(0|[1-9]?\\d|100)";static#n=new RegExp(`^rgb\\(\\s*${t.#s}\\s*,\\s*${t.#s}\\s*,\\s*${t.#s}\\s*\\)$`);static#o=new RegExp(`^rgba\\(\\s*${t.#s}\\s*,\\s*${t.#s}\\s*,\\s*${t.#s}\\s*,\\s*${t.#t}\\s*\\)$`);static#l=new RegExp(`^hsl\\(\\s*${t.#a}\\s*,\\s*${t.#i}%\\s*,\\s*${t.#i}%\\s*\\)$`);static#p=new RegExp(`^hsla\\(\\s*${t.#a}\\s*,\\s*${t.#i}%\\s*,\\s*${t.#i}%\\s*,\\s*${t.#t}\\s*\\)$`);static#u=new RegExp(`^hwb\\(\\s*${t.#a}(deg|grad|rad|turn)?\\s*${t.#i}%\\s*${t.#i}%\\s*\\)$`);static#c="(-?\\d+)";static#g=new RegExp(`^lab\\(\\s*${t.#i}%?\\s*${t.#c}%?\\s*${t.#c}%?\\s*\\)$`);static#d=new RegExp(`^lch\\(\\s*${t.#i}%?\\s*${t.#i}%?\\s*${t.#a}(deg|grad|rad|turn)?\\s*\\)$`);static#h=new Set(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"]);static#E=new Set(["transparent","currentColor"]);static getNames(){return Array.from(t.#h)}static addName(e){const r=t.#h.size;return t.#h.add(e.toLowerCase()),t.#h.size>r}static removeName(e){return t.#h.delete(e.toLowerCase())}static hasName(e){return t.#h.has(e.toLowerCase())}static getSpecialNames(){return Array.from(t.#E)}static addSpecialName(e){const r=t.#E.size;return t.#E.add(e),t.#E.size>r}static removeSpecialName(e){return t.#E.delete(e)}static hasSpecialName(e){return t.#E.has(e)}#m;get code(){return this.#m}#b;get type(){return this.#b}constructor(e){this.#m=e,this.#b=t.isColor(this.#m)}static isHex(e){if("string"!=typeof e)throw new TypeError("isHex: input must be a string.");return t.#e.test(e.trim())}isHex(){return t.isHex(this.#m)}static isHexa(e){if("string"!=typeof e)throw new TypeError("isHexa: input must be a string.");return t.#r.test(e.trim())}isHexa(){return t.isHexa(this.#m)}static isRgb(e){if("string"!=typeof e)throw new TypeError("isRgb: input must be a string.");return t.#n.test(e.trim())}isRgb(){return t.isRgb(this.#m)}static isRgba(e){if("string"!=typeof e)throw new TypeError("isRgba: input must be a string.");return t.#o.test(e.trim())}isRgba(){return t.isRgba(this.#m)}static isHsl(e){if("string"!=typeof e)throw new TypeError("isHsl: input must be a string.");return t.#l.test(e.trim())}isHsl(){return t.isHsl(this.#m)}static isHsla(e){if("string"!=typeof e)throw new TypeError("isHsla: input must be a string.");return t.#p.test(e.trim())}isHsla(){return t.isHsla(this.#m)}static isHwb(e){if("string"!=typeof e)throw new TypeError("isHwb: input must be a string.");return t.#u.test(e.trim())}isHwb(){return t.isHwb(this.#m)}static isLab(e){if("string"!=typeof e)throw new TypeError("isLab: input must be a string.");return t.#g.test(e.trim())}isLab(){return t.isLab(this.#m)}static isLch(e){if("string"!=typeof e)throw new TypeError("isLch: input must be a string.");return t.#d.test(e.trim())}isLch(){return t.isLch(this.#m)}static isName(e){if("string"!=typeof e)throw new TypeError("isName: input must be a string.");return t.#h.has(e.trim().toLowerCase())}isName(){return t.isName(this.#m)}static isSpecialName(e){if("string"!=typeof e)throw new TypeError("isSpecialName: input must be a string.");return t.#E.has(e.trim())}isSpecialName(){return t.isSpecialName(this.#m)}static isColor(e){if("string"!=typeof e)throw new TypeError("isColor: input must be a string.");return t.isHex(e)?"hex":t.isHexa(e)?"hexa":t.isRgb(e)?"rgb":t.isRgba(e)?"rgba":t.isHsl(e)?"hsl":t.isHsla(e)?"hsla":t.isHwb(e)?"hwb":t.isLab(e)?"lab":t.isLch(e)?"lch":t.isName(e)?"name":t.isSpecialName(e)?"specialName":null}parse(){switch(this.#b){case"hex":return t.parseHex(this.code);case"hexa":return t.parseHexa(this.code);case"rgb":return t.parseRgb(this.code);case"rgba":return t.parseRgba(this.code);case"hsl":return t.parseHsl(this.code);case"hsla":return t.parseHsla(this.code);case"hwb":return t.parseHwb(this.code);case"lab":return t.parseLab(this.code);case"lch":return t.parseLch(this.code);case"name":case"specialName":return this.#m.trim().toLowerCase();default:return null}}static parseHex(e){if("string"!=typeof e)throw new TypeError("parseHex: input must be a string.");const r=new RegExp(t.#e,"gm").exec(e.trim());return r?r[1]:null}parseHex(){return t.parseHex(this.#m)}static parseHexa(e){if("string"!=typeof e)throw new TypeError("parseHexa: input must be a string.");const r=new RegExp(t.#r,"gm").exec(e.trim());return r?r[1]:null}parseHexa(){return t.parseHexa(this.#m)}static parseRgb(e){if("string"!=typeof e)throw new TypeError("parseRgb: input must be a string.");const r=new RegExp(t.#n,"gm").exec(e.trim());return r?[parseFloat(r[1]),parseFloat(r[2]),parseFloat(r[3])]:null}parseRgb(){return t.parseRgb(this.#m)}static parseRgba(e){if("string"!=typeof e)throw new TypeError("parseRgba: input must be a string.");const r=new RegExp(t.#o,"gm").exec(e.trim());return r?[parseFloat(r[1]),parseFloat(r[2]),parseFloat(r[3]),parseFloat(r[4])]:null}parseRgba(){return t.parseRgba(this.#m)}static parseHsl(e){if("string"!=typeof e)throw new TypeError("parseHsl: input must be a string.");const r=new RegExp(t.#l,"gm").exec(e.trim());return r?[parseFloat(r[1]),parseFloat(r[2]),parseFloat(r[3])]:null}parseHsl(){return t.parseHsl(this.#m)}static parseHsla(e){if("string"!=typeof e)throw new TypeError("parseHsla: input must be a string.");const r=new RegExp(t.#p,"gm").exec(e.trim());return r?[parseFloat(r[1]),parseFloat(r[2]),parseFloat(r[3]),parseFloat(r[4])]:null}parseHsla(){return t.parseHsla(this.#m)}static parseHwb(e){if("string"!=typeof e)throw new TypeError("parseHwb: input must be a string.");const r=new RegExp(t.#u,"gm").exec(e.trim());return r?[parseFloat(r[1]),r[2]??null,parseFloat(r[3]),parseFloat(r[4])]:null}parseHwb(){return t.parseHwb(this.#m)}static parseLab(e){if("string"!=typeof e)throw new TypeError("parseLab: input must be a string.");const r=new RegExp(t.#g,"gm").exec(e.trim());return r?[parseFloat(r[1]),parseFloat(r[2]),parseFloat(r[3])]:null}parseLab(){return t.parseLab(this.#m)}static parseLch(e){if("string"!=typeof e)throw new TypeError("parseLch: input must be a string.");const r=new RegExp(t.#d,"gm").exec(e.trim());return r?[parseFloat(r[1]),parseFloat(r[2]),parseFloat(r[3]),r[4]??null]:null}parseLch(){return t.parseLch(this.#m)}}const s=t;window.TinyColorValidator=r.TinyColorValidator})();