EastDesire / jscolor

JavaScript color picker with opacity (alpha channel) and customizable palette. Single file of plain JS with no dependencies.

Home Page:http://jscolor.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Importing via npm seems to break in safari

DanielNoord opened this issue · comments

I noticed this bug while working on Cookie Monster, a mod for the game Cookie Clicker, and a bug report there.

We import jscolor through npm and our mod functions fine on chrome (and I believe firefox).
However, Safari does not load and indicates a faulty regex expression. When loading our code into the console correct colour coding of the input stops when it reaches the code produced by lines 874-876 in jscolor.js:

	parsePaletteValue : function (mixed) {
		var vals = [];

		if (typeof mixed === 'string') { // input is a string of space separated color values
			// rgb() and rgba() may contain spaces too, so let's find all color values by regex
			mixed.replace(/#[0-9A-F]{3}([0-9A-F]{3})?|rgba?\(([^)]*)\)/ig, function (val) {
				vals.push(val);
			});
		} else if (Array.isArray(mixed)) { // input is an array of color values
			vals = mixed;
		}

After mini-fication through webpack this becomes:

parsePaletteValue:function(e){var t=[];"string"==typeof e?e.replace(/#[0-9A-F]{3}([0-9A-F]{3})?|rgba?\(([^)]*)\)/gi,(function(e){t.push(e)})):Array.isArray(e)&&(t=e);

I think Safari is struggling to understand this regex? I don't immediately see why it would not understand this and a quick search on google also did not indicate any obvious compatibility problems with Safari and regex.
Is this something that could be fixed on your end? Or do we need to do something to make the code work on Safari. It is strange that this does seem to work on chrome and other browsers.

My mistake, this turned out to be an issue on our end.
Closing this issue!