diff --git a/README.md b/README.md
index a288dbe9..a0ba531c 100644
--- a/README.md
+++ b/README.md
@@ -194,6 +194,7 @@ You will find four different builds in the lib.
| index.mjs | esmodule | An es module, mostly used in Webpack 2 and rollup. | Yes |
| index.browser.js | umd | Can be used directly in browser | No (It's in development) |
| index.min.js | umd | Can be used directly in browser | No (It's in production) |
+| Index.esm.js | esmodule | An es module, mostly used in browser es module | No (It's in development) |
## Development
diff --git a/build/rollup.config.base.js b/build/rollup.config.base.js
index 2ef97e9f..387ac10f 100644
--- a/build/rollup.config.base.js
+++ b/build/rollup.config.base.js
@@ -55,6 +55,27 @@ const babelConfig = {
runtimeHelpers: true,
babelrc: false,
},
+ esm: {
+ presets: [
+ 'flow',
+ [ 'env', {
+ modules: false,
+ targets: {
+ browsers: [ 'last 2 versions', 'not ie <= 8' ],
+ },
+ }],
+ 'stage-0',
+ ],
+ exclude: 'node_modules/**',
+ plugins: [
+ 'external-helpers',
+ 'transform-decorators-legacy',
+ 'transform-runtime',
+ ],
+ externalHelpers: true,
+ runtimeHelpers: true,
+ babelrc: false,
+ },
umd: {
presets: [
'flow',
@@ -122,7 +143,7 @@ export default function(mode) {
return {
input: 'src/index.js',
external(id) {
- return !/min|umd|iife/.test(mode) && externalRegExp.test(id);
+ return !/min|umd|iife|esm/.test(mode) && externalRegExp.test(id);
},
plugins: [
babel(babelConfig[mode]),
@@ -133,7 +154,7 @@ export default function(mode) {
}),
resolve({
customResolveOptions: {
- moduleDirectory: /min|umd|iife/.test(mode) ? [ 'src', 'node_modules' ] : [ 'src' ],
+ moduleDirectory: /min|umd|iife|esm/.test(mode) ? [ 'src', 'node_modules' ] : [ 'src' ],
},
}),
visualizer({
diff --git a/build/rollup.config.esm.js b/build/rollup.config.esm.js
new file mode 100644
index 00000000..18a708d3
--- /dev/null
+++ b/build/rollup.config.esm.js
@@ -0,0 +1,13 @@
+import base, { banner } from './rollup.config.base';
+import replace from 'rollup-plugin-replace';
+const config = base('esm');
+config.plugins.unshift(replace({
+ 'process.env.NODE_ENV': '"development"',
+}));
+export default Object.assign(config, {
+ output: {
+ format: 'es',
+ file: 'lib/index.esm.js',
+ banner,
+ },
+});
diff --git a/bundle-size/common.html b/bundle-size/common.html
index f9517f44..f15d1f9d 100644
--- a/bundle-size/common.html
+++ b/bundle-size/common.html
@@ -2163,6 +2163,9 @@
RollUp Visualizer
displayable: function() {
return this.rgb().displayable();
},
+ hex: function() {
+ return this.rgb().hex();
+ },
toString: function() {
return this.rgb() + "";
}
@@ -2229,6 +2232,9 @@ RollUp Visualizer
&& (0 <= this.b && this.b <= 255)
&& (0 <= this.opacity && this.opacity <= 1);
},
+ hex: function() {
+ return "#" + hex(this.r) + hex(this.g) + hex(this.b);
+ },
toString: function() {
var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
return (a === 1 ? "rgb(" : "rgba(")
@@ -2239,6 +2245,11 @@ RollUp Visualizer
}
}));
+ function hex(value) {
+ value = Math.max(0, Math.min(255, Math.round(value) || 0));
+ return (value < 16 ? "0" : "") + value.toString(16);
+ }
+
function hsla(h, s, l, a) {
if (a <= 0) h = s = l = NaN;
else if (l <= 0 || l >= 1) h = s = NaN;
@@ -2323,10 +2334,11 @@ RollUp Visualizer
var deg2rad = Math.PI / 180;
var rad2deg = 180 / Math.PI;
- var Kn = 18,
- Xn = 0.950470, // D65 standard referent
+ // https://beta.observablehq.com/@mbostock/lab-and-rgb
+ var K = 18,
+ Xn = 0.96422,
Yn = 1,
- Zn = 1.088830,
+ Zn = 0.82521,
t0 = 4 / 29,
t1 = 6 / 29,
t2 = 3 * t1 * t1,
@@ -2335,16 +2347,19 @@ RollUp Visualizer
function labConvert(o) {
if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
if (o instanceof Hcl) {
+ if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
var h = o.h * deg2rad;
return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
}
if (!(o instanceof Rgb)) o = rgbConvert(o);
- var b = rgb2xyz(o.r),
- a = rgb2xyz(o.g),
- l = rgb2xyz(o.b),
- x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
- y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
- z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
+ var r = rgb2lrgb(o.r),
+ g = rgb2lrgb(o.g),
+ b = rgb2lrgb(o.b),
+ y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
+ if (r === g && g === b) x = z = y; else {
+ x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
+ z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
+ }
return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
}
@@ -2361,22 +2376,22 @@ RollUp Visualizer
define(Lab, lab, extend(Color, {
brighter: function(k) {
- return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
+ return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
},
darker: function(k) {
- return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
+ return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
},
rgb: function() {
var y = (this.l + 16) / 116,
x = isNaN(this.a) ? y : y + this.a / 500,
z = isNaN(this.b) ? y : y - this.b / 200;
- y = Yn * lab2xyz(y);
x = Xn * lab2xyz(x);
+ y = Yn * lab2xyz(y);
z = Zn * lab2xyz(z);
return new Rgb(
- xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
- xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
- xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
+ lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
+ lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
+ lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
this.opacity
);
}
@@ -2390,17 +2405,18 @@ RollUp Visualizer
return t > t1 ? t * t * t : t2 * (t - t0);
}
- function xyz2rgb(x) {
+ function lrgb2rgb(x) {
return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
}
- function rgb2xyz(x) {
+ function rgb2lrgb(x) {
return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
}
function hclConvert(o) {
if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
if (!(o instanceof Lab)) o = labConvert(o);
+ if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0, o.l, o.opacity);
var h = Math.atan2(o.b, o.a) * rad2deg;
return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
}
@@ -2418,10 +2434,10 @@ RollUp Visualizer
define(Hcl, hcl, extend(Color, {
brighter: function(k) {
- return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
+ return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
},
darker: function(k) {
- return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
+ return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
},
rgb: function() {
return labConvert(this).rgb();
@@ -2750,22 +2766,22 @@ RollUp Visualizer
range$$1 = unit,
interpolate$$1 = value,
clamp = false,
- piecewise,
+ piecewise$$1,
output,
input;
function rescale() {
- piecewise = Math.min(domain.length, range$$1.length) > 2 ? polymap : bimap;
+ piecewise$$1 = Math.min(domain.length, range$$1.length) > 2 ? polymap : bimap;
output = input = null;
return scale;
}
function scale(x) {
- return (output || (output = piecewise(domain, range$$1, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
+ return (output || (output = piecewise$$1(domain, range$$1, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
}
scale.invert = function(y) {
- return (input || (input = piecewise(range$$1, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
+ return (input || (input = piecewise$$1(range$$1, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
};
scale.domain = function(_) {
@@ -2837,19 +2853,53 @@ RollUp Visualizer
};
}
- function formatDefault(x, p) {
- x = x.toPrecision(p);
+ // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
+ var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
+
+ function formatSpecifier(specifier) {
+ return new FormatSpecifier(specifier);
+ }
+
+ formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
+
+ function FormatSpecifier(specifier) {
+ if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
+ var match;
+ this.fill = match[1] || " ";
+ this.align = match[2] || ">";
+ this.sign = match[3] || "-";
+ this.symbol = match[4] || "";
+ this.zero = !!match[5];
+ this.width = match[6] && +match[6];
+ this.comma = !!match[7];
+ this.precision = match[8] && +match[8].slice(1);
+ this.trim = !!match[9];
+ this.type = match[10] || "";
+ }
+
+ FormatSpecifier.prototype.toString = function() {
+ return this.fill
+ + this.align
+ + this.sign
+ + this.symbol
+ + (this.zero ? "0" : "")
+ + (this.width == null ? "" : Math.max(1, this.width | 0))
+ + (this.comma ? "," : "")
+ + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
+ + (this.trim ? "~" : "")
+ + this.type;
+ };
- out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
- switch (x[i]) {
+ // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
+ function formatTrim(s) {
+ out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
+ switch (s[i]) {
case ".": i0 = i1 = i; break;
case "0": if (i0 === 0) i0 = i; i1 = i; break;
- case "e": break out;
- default: if (i0 > 0) i0 = 0; break;
+ default: if (i0 > 0) { if (!+s[i]) break out; i0 = 0; } break;
}
}
-
- return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
+ return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
}
var prefixExponent;
@@ -2878,7 +2928,6 @@ RollUp Visualizer
}
var formatTypes = {
- "": formatDefault,
"%": function(x, p) { return (x * 100).toFixed(p); },
"b": function(x) { return Math.round(x).toString(2); },
"c": function(x) { return x + ""; },
@@ -2894,61 +2943,6 @@ RollUp Visualizer
"x": function(x) { return Math.round(x).toString(16); }
};
- // [[fill]align][sign][symbol][0][width][,][.precision][type]
- var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
-
- function formatSpecifier(specifier) {
- return new FormatSpecifier(specifier);
- }
-
- formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
-
- function FormatSpecifier(specifier) {
- if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
-
- var match,
- fill = match[1] || " ",
- align = match[2] || ">",
- sign = match[3] || "-",
- symbol = match[4] || "",
- zero = !!match[5],
- width = match[6] && +match[6],
- comma = !!match[7],
- precision = match[8] && +match[8].slice(1),
- type = match[9] || "";
-
- // The "n" type is an alias for ",g".
- if (type === "n") comma = true, type = "g";
-
- // Map invalid types to the default format.
- else if (!formatTypes[type]) type = "";
-
- // If zero fill is specified, padding goes after sign and before digits.
- if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
-
- this.fill = fill;
- this.align = align;
- this.sign = sign;
- this.symbol = symbol;
- this.zero = zero;
- this.width = width;
- this.comma = comma;
- this.precision = precision;
- this.type = type;
- }
-
- FormatSpecifier.prototype.toString = function() {
- return this.fill
- + this.align
- + this.sign
- + this.symbol
- + (this.zero ? "0" : "")
- + (this.width == null ? "" : Math.max(1, this.width | 0))
- + (this.comma ? "," : "")
- + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
- + this.type;
- };
-
function identity$3(x) {
return x;
}
@@ -2973,8 +2967,18 @@ RollUp Visualizer
width = specifier.width,
comma = specifier.comma,
precision = specifier.precision,
+ trim = specifier.trim,
type = specifier.type;
+ // The "n" type is an alias for ",g".
+ if (type === "n") comma = true, type = "g";
+
+ // The "" type, and any invalid type, is an alias for ".12~g".
+ else if (!formatTypes[type]) precision == null && (precision = 12), trim = true, type = "g";
+
+ // If zero fill is specified, padding goes after sign and before digits.
+ if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
+
// Compute the prefix and suffix.
// For SI-prefix, the suffix is lazily computed.
var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
@@ -2984,13 +2988,13 @@ RollUp Visualizer
// Is this an integer type?
// Can this type generate exponential notation?
var formatType = formatTypes[type],
- maybeSuffix = !type || /[defgprs%]/.test(type);
+ maybeSuffix = /[defgprs%]/.test(type);
// Set the default precision if not specified,
// or clamp the specified precision to the supported range.
// For significant precision, it must be in [1, 21].
// For fixed precision, it must be in [0, 20].
- precision = precision == null ? (type ? 6 : 12)
+ precision = precision == null ? 6
: /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
: Math.max(0, Math.min(20, precision));
@@ -3009,6 +3013,9 @@ RollUp Visualizer
var valueNegative = value < 0;
value = formatType(Math.abs(value), precision);
+ // Trim insignificant zeros.
+ if (trim) value = formatTrim(value);
+
// If a negative value rounds to zero during formatting, treat as positive.
if (valueNegative && +value === 0) valueNegative = false;
@@ -3324,6 +3331,7 @@ RollUp Visualizer
return (end - start) / k;
});
};
+ var milliseconds = millisecond.range;
var durationSecond = 1e3;
var durationMinute = 6e4;
@@ -3340,6 +3348,7 @@ RollUp Visualizer
}, function(date) {
return date.getUTCSeconds();
});
+ var seconds = second.range;
var minute = newInterval(function(date) {
date.setTime(Math.floor(date / durationMinute) * durationMinute);
@@ -3350,6 +3359,7 @@ RollUp Visualizer
}, function(date) {
return date.getMinutes();
});
+ var minutes = minute.range;
var hour = newInterval(function(date) {
var offset = date.getTimezoneOffset() * durationMinute % durationHour;
@@ -3362,6 +3372,7 @@ RollUp Visualizer
}, function(date) {
return date.getHours();
});
+ var hours = hour.range;
var day = newInterval(function(date) {
date.setHours(0, 0, 0, 0);
@@ -3372,6 +3383,7 @@ RollUp Visualizer
}, function(date) {
return date.getDate() - 1;
});
+ var days = day.range;
function weekday(i) {
return newInterval(function(date) {
@@ -3392,6 +3404,8 @@ RollUp Visualizer
var friday = weekday(5);
var saturday = weekday(6);
+ var sundays = sunday.range;
+
var month = newInterval(function(date) {
date.setDate(1);
date.setHours(0, 0, 0, 0);
@@ -3402,6 +3416,7 @@ RollUp Visualizer
}, function(date) {
return date.getMonth();
});
+ var months = month.range;
var year = newInterval(function(date) {
date.setMonth(0, 1);
@@ -3424,6 +3439,7 @@ RollUp Visualizer
date.setFullYear(date.getFullYear() + step * k);
});
};
+ var years = year.range;
var utcMinute = newInterval(function(date) {
date.setUTCSeconds(0, 0);
@@ -3434,6 +3450,7 @@ RollUp Visualizer
}, function(date) {
return date.getUTCMinutes();
});
+ var utcMinutes = utcMinute.range;
var utcHour = newInterval(function(date) {
date.setUTCMinutes(0, 0, 0);
@@ -3444,6 +3461,7 @@ RollUp Visualizer
}, function(date) {
return date.getUTCHours();
});
+ var utcHours = utcHour.range;
var utcDay = newInterval(function(date) {
date.setUTCHours(0, 0, 0, 0);
@@ -3454,6 +3472,7 @@ RollUp Visualizer
}, function(date) {
return date.getUTCDate() - 1;
});
+ var utcDays = utcDay.range;
function utcWeekday(i) {
return newInterval(function(date) {
@@ -3474,6 +3493,8 @@ RollUp Visualizer
var utcFriday = utcWeekday(5);
var utcSaturday = utcWeekday(6);
+ var utcSundays = utcSunday.range;
+
var utcMonth = newInterval(function(date) {
date.setUTCDate(1);
date.setUTCHours(0, 0, 0, 0);
@@ -3484,6 +3505,7 @@ RollUp Visualizer
}, function(date) {
return date.getUTCMonth();
});
+ var utcMonths = utcMonth.range;
var utcYear = newInterval(function(date) {
date.setUTCMonth(0, 1);
@@ -3506,6 +3528,7 @@ RollUp Visualizer
date.setUTCFullYear(date.getUTCFullYear() + step * k);
});
};
+ var utcYears = utcYear.range;
function localDate(d) {
if (0 <= d.y && d.y < 100) {
diff --git a/bundle-size/es.html b/bundle-size/es.html
index 7e289266..806ea673 100644
--- a/bundle-size/es.html
+++ b/bundle-size/es.html
@@ -2163,6 +2163,9 @@ RollUp Visualizer
displayable: function() {
return this.rgb().displayable();
},
+ hex: function() {
+ return this.rgb().hex();
+ },
toString: function() {
return this.rgb() + "";
}
@@ -2229,6 +2232,9 @@ RollUp Visualizer
&& (0 <= this.b && this.b <= 255)
&& (0 <= this.opacity && this.opacity <= 1);
},
+ hex: function() {
+ return "#" + hex(this.r) + hex(this.g) + hex(this.b);
+ },
toString: function() {
var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
return (a === 1 ? "rgb(" : "rgba(")
@@ -2239,6 +2245,11 @@ RollUp Visualizer
}
}));
+ function hex(value) {
+ value = Math.max(0, Math.min(255, Math.round(value) || 0));
+ return (value < 16 ? "0" : "") + value.toString(16);
+ }
+
function hsla(h, s, l, a) {
if (a <= 0) h = s = l = NaN;
else if (l <= 0 || l >= 1) h = s = NaN;
@@ -2323,10 +2334,11 @@ RollUp Visualizer
var deg2rad = Math.PI / 180;
var rad2deg = 180 / Math.PI;
- var Kn = 18,
- Xn = 0.950470, // D65 standard referent
+ // https://beta.observablehq.com/@mbostock/lab-and-rgb
+ var K = 18,
+ Xn = 0.96422,
Yn = 1,
- Zn = 1.088830,
+ Zn = 0.82521,
t0 = 4 / 29,
t1 = 6 / 29,
t2 = 3 * t1 * t1,
@@ -2335,16 +2347,19 @@ RollUp Visualizer
function labConvert(o) {
if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
if (o instanceof Hcl) {
+ if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity);
var h = o.h * deg2rad;
return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
}
if (!(o instanceof Rgb)) o = rgbConvert(o);
- var b = rgb2xyz(o.r),
- a = rgb2xyz(o.g),
- l = rgb2xyz(o.b),
- x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
- y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
- z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
+ var r = rgb2lrgb(o.r),
+ g = rgb2lrgb(o.g),
+ b = rgb2lrgb(o.b),
+ y = xyz2lab((0.2225045 * r + 0.7168786 * g + 0.0606169 * b) / Yn), x, z;
+ if (r === g && g === b) x = z = y; else {
+ x = xyz2lab((0.4360747 * r + 0.3850649 * g + 0.1430804 * b) / Xn);
+ z = xyz2lab((0.0139322 * r + 0.0971045 * g + 0.7141733 * b) / Zn);
+ }
return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
}
@@ -2361,22 +2376,22 @@ RollUp Visualizer
define(Lab, lab, extend(Color, {
brighter: function(k) {
- return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
+ return new Lab(this.l + K * (k == null ? 1 : k), this.a, this.b, this.opacity);
},
darker: function(k) {
- return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
+ return new Lab(this.l - K * (k == null ? 1 : k), this.a, this.b, this.opacity);
},
rgb: function() {
var y = (this.l + 16) / 116,
x = isNaN(this.a) ? y : y + this.a / 500,
z = isNaN(this.b) ? y : y - this.b / 200;
- y = Yn * lab2xyz(y);
x = Xn * lab2xyz(x);
+ y = Yn * lab2xyz(y);
z = Zn * lab2xyz(z);
return new Rgb(
- xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
- xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
- xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
+ lrgb2rgb( 3.1338561 * x - 1.6168667 * y - 0.4906146 * z),
+ lrgb2rgb(-0.9787684 * x + 1.9161415 * y + 0.0334540 * z),
+ lrgb2rgb( 0.0719453 * x - 0.2289914 * y + 1.4052427 * z),
this.opacity
);
}
@@ -2390,17 +2405,18 @@ RollUp Visualizer
return t > t1 ? t * t * t : t2 * (t - t0);
}
- function xyz2rgb(x) {
+ function lrgb2rgb(x) {
return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
}
- function rgb2xyz(x) {
+ function rgb2lrgb(x) {
return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
}
function hclConvert(o) {
if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
if (!(o instanceof Lab)) o = labConvert(o);
+ if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0, o.l, o.opacity);
var h = Math.atan2(o.b, o.a) * rad2deg;
return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
}
@@ -2418,10 +2434,10 @@ RollUp Visualizer
define(Hcl, hcl, extend(Color, {
brighter: function(k) {
- return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
+ return new Hcl(this.h, this.c, this.l + K * (k == null ? 1 : k), this.opacity);
},
darker: function(k) {
- return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
+ return new Hcl(this.h, this.c, this.l - K * (k == null ? 1 : k), this.opacity);
},
rgb: function() {
return labConvert(this).rgb();
@@ -2750,22 +2766,22 @@ RollUp Visualizer
range$$1 = unit,
interpolate$$1 = value,
clamp = false,
- piecewise,
+ piecewise$$1,
output,
input;
function rescale() {
- piecewise = Math.min(domain.length, range$$1.length) > 2 ? polymap : bimap;
+ piecewise$$1 = Math.min(domain.length, range$$1.length) > 2 ? polymap : bimap;
output = input = null;
return scale;
}
function scale(x) {
- return (output || (output = piecewise(domain, range$$1, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
+ return (output || (output = piecewise$$1(domain, range$$1, clamp ? deinterpolateClamp(deinterpolate) : deinterpolate, interpolate$$1)))(+x);
}
scale.invert = function(y) {
- return (input || (input = piecewise(range$$1, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
+ return (input || (input = piecewise$$1(range$$1, domain, deinterpolateLinear, clamp ? reinterpolateClamp(reinterpolate) : reinterpolate)))(+y);
};
scale.domain = function(_) {
@@ -2837,19 +2853,53 @@ RollUp Visualizer
};
}
- function formatDefault(x, p) {
- x = x.toPrecision(p);
+ // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
+ var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
+
+ function formatSpecifier(specifier) {
+ return new FormatSpecifier(specifier);
+ }
+
+ formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
+
+ function FormatSpecifier(specifier) {
+ if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
+ var match;
+ this.fill = match[1] || " ";
+ this.align = match[2] || ">";
+ this.sign = match[3] || "-";
+ this.symbol = match[4] || "";
+ this.zero = !!match[5];
+ this.width = match[6] && +match[6];
+ this.comma = !!match[7];
+ this.precision = match[8] && +match[8].slice(1);
+ this.trim = !!match[9];
+ this.type = match[10] || "";
+ }
+
+ FormatSpecifier.prototype.toString = function() {
+ return this.fill
+ + this.align
+ + this.sign
+ + this.symbol
+ + (this.zero ? "0" : "")
+ + (this.width == null ? "" : Math.max(1, this.width | 0))
+ + (this.comma ? "," : "")
+ + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
+ + (this.trim ? "~" : "")
+ + this.type;
+ };
- out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
- switch (x[i]) {
+ // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
+ function formatTrim(s) {
+ out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
+ switch (s[i]) {
case ".": i0 = i1 = i; break;
case "0": if (i0 === 0) i0 = i; i1 = i; break;
- case "e": break out;
- default: if (i0 > 0) i0 = 0; break;
+ default: if (i0 > 0) { if (!+s[i]) break out; i0 = 0; } break;
}
}
-
- return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
+ return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
}
var prefixExponent;
@@ -2878,7 +2928,6 @@ RollUp Visualizer
}
var formatTypes = {
- "": formatDefault,
"%": function(x, p) { return (x * 100).toFixed(p); },
"b": function(x) { return Math.round(x).toString(2); },
"c": function(x) { return x + ""; },
@@ -2894,61 +2943,6 @@ RollUp Visualizer
"x": function(x) { return Math.round(x).toString(16); }
};
- // [[fill]align][sign][symbol][0][width][,][.precision][type]
- var re = /^(?:(.)?([<>=^]))?([+\-\( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?([a-z%])?$/i;
-
- function formatSpecifier(specifier) {
- return new FormatSpecifier(specifier);
- }
-
- formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
-
- function FormatSpecifier(specifier) {
- if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
-
- var match,
- fill = match[1] || " ",
- align = match[2] || ">",
- sign = match[3] || "-",
- symbol = match[4] || "",
- zero = !!match[5],
- width = match[6] && +match[6],
- comma = !!match[7],
- precision = match[8] && +match[8].slice(1),
- type = match[9] || "";
-
- // The "n" type is an alias for ",g".
- if (type === "n") comma = true, type = "g";
-
- // Map invalid types to the default format.
- else if (!formatTypes[type]) type = "";
-
- // If zero fill is specified, padding goes after sign and before digits.
- if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
-
- this.fill = fill;
- this.align = align;
- this.sign = sign;
- this.symbol = symbol;
- this.zero = zero;
- this.width = width;
- this.comma = comma;
- this.precision = precision;
- this.type = type;
- }
-
- FormatSpecifier.prototype.toString = function() {
- return this.fill
- + this.align
- + this.sign
- + this.symbol
- + (this.zero ? "0" : "")
- + (this.width == null ? "" : Math.max(1, this.width | 0))
- + (this.comma ? "," : "")
- + (this.precision == null ? "" : "." + Math.max(0, this.precision | 0))
- + this.type;
- };
-
function identity$3(x) {
return x;
}
@@ -2973,8 +2967,18 @@ RollUp Visualizer
width = specifier.width,
comma = specifier.comma,
precision = specifier.precision,
+ trim = specifier.trim,
type = specifier.type;
+ // The "n" type is an alias for ",g".
+ if (type === "n") comma = true, type = "g";
+
+ // The "" type, and any invalid type, is an alias for ".12~g".
+ else if (!formatTypes[type]) precision == null && (precision = 12), trim = true, type = "g";
+
+ // If zero fill is specified, padding goes after sign and before digits.
+ if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
+
// Compute the prefix and suffix.
// For SI-prefix, the suffix is lazily computed.
var prefix = symbol === "$" ? currency[0] : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
@@ -2984,13 +2988,13 @@ RollUp Visualizer
// Is this an integer type?
// Can this type generate exponential notation?
var formatType = formatTypes[type],
- maybeSuffix = !type || /[defgprs%]/.test(type);
+ maybeSuffix = /[defgprs%]/.test(type);
// Set the default precision if not specified,
// or clamp the specified precision to the supported range.
// For significant precision, it must be in [1, 21].
// For fixed precision, it must be in [0, 20].
- precision = precision == null ? (type ? 6 : 12)
+ precision = precision == null ? 6
: /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
: Math.max(0, Math.min(20, precision));
@@ -3009,6 +3013,9 @@ RollUp Visualizer
var valueNegative = value < 0;
value = formatType(Math.abs(value), precision);
+ // Trim insignificant zeros.
+ if (trim) value = formatTrim(value);
+
// If a negative value rounds to zero during formatting, treat as positive.
if (valueNegative && +value === 0) valueNegative = false;
@@ -3324,6 +3331,7 @@ RollUp Visualizer
return (end - start) / k;
});
};
+ var milliseconds = millisecond.range;
var durationSecond = 1e3;
var durationMinute = 6e4;
@@ -3340,6 +3348,7 @@ RollUp Visualizer
}, function(date) {
return date.getUTCSeconds();
});
+ var seconds = second.range;
var minute = newInterval(function(date) {
date.setTime(Math.floor(date / durationMinute) * durationMinute);
@@ -3350,6 +3359,7 @@ RollUp Visualizer
}, function(date) {
return date.getMinutes();
});
+ var minutes = minute.range;
var hour = newInterval(function(date) {
var offset = date.getTimezoneOffset() * durationMinute % durationHour;
@@ -3362,6 +3372,7 @@ RollUp Visualizer
}, function(date) {
return date.getHours();
});
+ var hours = hour.range;
var day = newInterval(function(date) {
date.setHours(0, 0, 0, 0);
@@ -3372,6 +3383,7 @@ RollUp Visualizer
}, function(date) {
return date.getDate() - 1;
});
+ var days = day.range;
function weekday(i) {
return newInterval(function(date) {
@@ -3392,6 +3404,8 @@ RollUp Visualizer
var friday = weekday(5);
var saturday = weekday(6);
+ var sundays = sunday.range;
+
var month = newInterval(function(date) {
date.setDate(1);
date.setHours(0, 0, 0, 0);
@@ -3402,6 +3416,7 @@ RollUp Visualizer
}, function(date) {
return date.getMonth();
});
+ var months = month.range;
var year = newInterval(function(date) {
date.setMonth(0, 1);
@@ -3424,6 +3439,7 @@ RollUp Visualizer
date.setFullYear(date.getFullYear() + step * k);
});
};
+ var years = year.range;
var utcMinute = newInterval(function(date) {
date.setUTCSeconds(0, 0);
@@ -3434,6 +3450,7 @@ RollUp Visualizer
}, function(date) {
return date.getUTCMinutes();
});
+ var utcMinutes = utcMinute.range;
var utcHour = newInterval(function(date) {
date.setUTCMinutes(0, 0, 0);
@@ -3444,6 +3461,7 @@ RollUp Visualizer
}, function(date) {
return date.getUTCHours();
});
+ var utcHours = utcHour.range;
var utcDay = newInterval(function(date) {
date.setUTCHours(0, 0, 0, 0);
@@ -3454,6 +3472,7 @@ RollUp Visualizer
}, function(date) {
return date.getUTCDate() - 1;
});
+ var utcDays = utcDay.range;
function utcWeekday(i) {
return newInterval(function(date) {
@@ -3474,6 +3493,8 @@ RollUp Visualizer
var utcFriday = utcWeekday(5);
var utcSaturday = utcWeekday(6);
+ var utcSundays = utcSunday.range;
+
var utcMonth = newInterval(function(date) {
date.setUTCDate(1);
date.setUTCHours(0, 0, 0, 0);
@@ -3484,6 +3505,7 @@ RollUp Visualizer
}, function(date) {
return date.getUTCMonth();
});
+ var utcMonths = utcMonth.range;
var utcYear = newInterval(function(date) {
date.setUTCMonth(0, 1);
@@ -3506,6 +3528,7 @@ RollUp Visualizer
date.setUTCFullYear(date.getUTCFullYear() + step * k);
});
};
+ var utcYears = utcYear.range;
function localDate(d) {
if (0 <= d.y && d.y < 100) {
diff --git a/bundle-size/esm.html b/bundle-size/esm.html
new file mode 100644
index 00000000..0edc9c5c
--- /dev/null
+++ b/bundle-size/esm.html
@@ -0,0 +1,4429 @@
+
+ RollUp Visualizer
+
+
+
+
+
RollUp Visualizer
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/bundle-size/min.html b/bundle-size/min.html
index 08663cf6..07c6351f 100644
--- a/bundle-size/min.html
+++ b/bundle-size/min.html
@@ -121,7 +121,7 @@ RollUp Visualizer
-
+
+
+
+
+
+
+