parsegraph-color
Advanced tools
Comparing version 1.4.8 to 1.4.9-dev
@@ -9,4 +9,4 @@ export default class ColorChannel { | ||
value(): number; | ||
elems(): (HTMLLabelElement | HTMLDivElement)[]; | ||
elems(): (HTMLDivElement | HTMLLabelElement)[]; | ||
} | ||
//# sourceMappingURL=ColorChannel.d.ts.map |
@@ -1,1 +0,357 @@ | ||
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.parsegraph_color=n():t.parsegraph_color=n()}(this,(function(){return(()=>{"use strict";var t={d:(n,r)=>{for(var o in r)t.o(r,o)&&!t.o(n,o)&&Object.defineProperty(n,o,{enumerable:!0,get:r[o]})},o:(t,n)=>Object.prototype.hasOwnProperty.call(t,n),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},n={};t.r(n),t.d(n,{clamp:()=>r,default:()=>i,mix:()=>o});var r=function(t,n,r){return Math.min(r,Math.max(n,t))},o=function(t,n,r){return t+(n-t)*r},e=function(){function t(t,n,r,o){if(1===arguments.length)n=t,r=t,o=1;else if(3===arguments.length)o=1;else if(4!==arguments.length)throw new Error("Color must be given initial component values.");this._r=Math.min(1,Math.max(0,t)),this._g=Math.min(1,Math.max(0,n)),this._b=Math.min(1,Math.max(0,r)),this._a=Math.min(1,Math.max(0,o))}return t.prototype.r=function(){return this._r},t.prototype.g=function(){return this._g},t.prototype.b=function(){return this._b},t.prototype.a=function(){return this._a},t.prototype.setA=function(t){return this._a=Math.min(1,Math.max(0,t)),this},t.prototype.setR=function(t){return this._r=Math.min(1,Math.max(0,t)),this},t.prototype.setG=function(t){return this._g=Math.min(1,Math.max(0,t)),this},t.prototype.setB=function(t){return this._b=Math.min(1,Math.max(0,t)),this},t.prototype.multiply=function(n){return new t(this.r()*n.r(),this.g()*n.g(),this.b()*n.b(),this.a()*n.a())},t.prototype.premultiply=function(n){return new t(this.a()*this.r()+n.r()*(1-this.a()),this.a()*this.g()+n.g()*(1-this.a()),this.a()*this.b()+n.b()*(1-this.a()),1)},t.prototype.asRGB=function(){return"rgb("+Math.round(255*this._r)+", "+Math.round(255*this._g)+", "+Math.round(255*this._b)+")"},t.prototype.asRGBA=function(){return"rgba("+Math.round(255*this._r)+", "+Math.round(255*this._g)+", "+Math.round(255*this._b)+", "+this._a+")"},t.prototype.luminance=function(){return.648431*t.inverseSRGBCompanding(this.r())+.321152*t.inverseSRGBCompanding(this.g())+.155886*t.inverseSRGBCompanding(this.b())},t.prototype.toLCH=function(){var n,r,o,e,i=t.inverseSRGBCompanding(this.r()),a=t.inverseSRGBCompanding(this.g()),h=t.inverseSRGBCompanding(this.b());return o=[.96422,1,.82521],n=[116*(e=[i,a,h].map((function(t,n){return t/o[n]})).map((function(t){return t>.008856451679035631?Math.cbrt(t):(903.2962962962963*t+16)/116})))[1]-16,500*(e[0]-e[1]),200*(e[1]-e[2])],r=180*Math.atan2(n[2],n[1])/Math.PI,[n[0],Math.sqrt(Math.pow(n[1],2)+Math.pow(n[2],2)),r>=0?r:r+360]},t.prototype.interpolate=function(n,e){e=r(e,0,1);var i=this.toLCH(),a=i[0],h=i[1],s=i[2],u=n.toLCH(),p=u[0],m=u[1],f=u[2],c=o(a,p,e),M=o(h,m,e),g=o(s,f,e);return t.fromLCH(c,M,g,o(this.a(),n.a(),e))},t.prototype.clone=function(){return new t(this.r(),this.g(),this.b(),this.a())},t.prototype.equals=function(t){return this.r()===t.r()&&this.g()===t.g()&&this.b()===t.b()&&this.a()===t.a()},t.fromLCH=function(n,r,o,e){var i,a,h,s,u,p,m=(i=[(p=[n,r,o])[0],p[1]*Math.cos(p[2]*Math.PI/180),p[1]*Math.sin(p[2]*Math.PI/180)],a=24389/27,h=216/24389,s=[.96422,1,.82521],(u=[])[1]=(i[0]+16)/116,u[0]=i[1]/500+u[1],u[2]=u[1]-i[2]/200,[Math.pow(u[0],3)>h?Math.pow(u[0],3):(116*u[0]-16)/a,i[0]>8?Math.pow((i[0]+16)/116,3):i[0]/a,Math.pow(u[2],3)>h?Math.pow(u[2],3):(116*u[2]-16)/a].map((function(t,n){return t*s[n]}))),f=m[0],c=m[1],M=m[2];return new t(t.sRGBCompanding(f),t.sRGBCompanding(c),t.sRGBCompanding(M),e)},t.inverseSRGBCompanding=function(t){return t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)},t.sRGBCompanding=function(t){return t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055},t.fromRGB=function(n,r){1===arguments.length&&(r=255);var o=[];if(n.trim().substring("rgb(".length,n.length-1).split(",").forEach((function(t){o.push(parseInt(t.trim()))})),o.length<3)throw new Error("Failed to parse color");return 3===o.length&&o.push(r),new t(o[0]/255,o[1]/255,o[2]/255,o[3]/255)},t.random=function(n,r){void 0===n&&(n=1),void 0===r&&(r=1);var o=1-(n=Math.min(Math.max(0,n),1));return new t(n*Math.random()+o/2,n*Math.random()+o/2,n*Math.random()+o/2,r)},t}();const i=e;return n})()})); | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
if(typeof exports === 'object' && typeof module === 'object') | ||
module.exports = factory(); | ||
else if(typeof define === 'function' && define.amd) | ||
define([], factory); | ||
else if(typeof exports === 'object') | ||
exports["parsegraph_color"] = factory(); | ||
else | ||
root["parsegraph_color"] = factory(); | ||
})(this, function() { | ||
return /******/ (() => { // webpackBootstrap | ||
/******/ "use strict"; | ||
/******/ var __webpack_modules__ = ({ | ||
/***/ "./src/w3c.ts": | ||
/*!********************!*\ | ||
!*** ./src/w3c.ts ***! | ||
\********************/ | ||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export */ __webpack_require__.d(__webpack_exports__, { | ||
/* harmony export */ "XYZ_to_Lab": () => (/* binding */ XYZ_to_Lab), | ||
/* harmony export */ "Lab_to_XYZ": () => (/* binding */ Lab_to_XYZ), | ||
/* harmony export */ "Lab_to_LCH": () => (/* binding */ Lab_to_LCH), | ||
/* harmony export */ "LCH_to_Lab": () => (/* binding */ LCH_to_Lab) | ||
/* harmony export */ }); | ||
function XYZ_to_Lab(XYZ) { | ||
// Assuming XYZ is relative to D50, convert to CIE Lab | ||
// from CIE standard, which now defines these as a rational fraction | ||
var ε = 216 / 24389; // 6^3/29^3 | ||
var κ = 24389 / 27; // 29^3/3^3 | ||
var white = [0.96422, 1.0, 0.82521]; // D50 reference white | ||
// compute xyz, which is XYZ scaled relative to reference white | ||
var xyz = XYZ.map(function (value, i) { | ||
return value / white[i]; | ||
}); // now compute f | ||
var f = xyz.map(function (value) { | ||
return value > ε ? Math.cbrt(value) : (κ * value + 16) / 116; | ||
}); | ||
return [116 * f[1] - 16, 500 * (f[0] - f[1]), 200 * (f[1] - f[2]) // b | ||
]; | ||
} | ||
function Lab_to_XYZ(Lab) { | ||
// Convert Lab to D50-adapted XYZ | ||
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html | ||
var κ = 24389 / 27; // 29^3/3^3 | ||
var ε = 216 / 24389; // 6^3/29^3 | ||
var white = [0.96422, 1.0, 0.82521]; // D50 reference white | ||
var f = []; // compute f, starting with the luminance-related term | ||
f[1] = (Lab[0] + 16) / 116; | ||
f[0] = Lab[1] / 500 + f[1]; | ||
f[2] = f[1] - Lab[2] / 200; // compute xyz | ||
var xyz = [Math.pow(f[0], 3) > ε ? Math.pow(f[0], 3) : (116 * f[0] - 16) / κ, Lab[0] > κ * ε ? Math.pow((Lab[0] + 16) / 116, 3) : Lab[0] / κ, Math.pow(f[2], 3) > ε ? Math.pow(f[2], 3) : (116 * f[2] - 16) / κ]; // Compute XYZ by scaling xyz by reference white | ||
return xyz.map(function (value, i) { | ||
return value * white[i]; | ||
}); | ||
} | ||
function Lab_to_LCH(Lab) { | ||
// Convert to polar form | ||
var hue = Math.atan2(Lab[2], Lab[1]) * 180 / Math.PI; | ||
return [Lab[0], Math.sqrt(Math.pow(Lab[1], 2) + Math.pow(Lab[2], 2)), hue >= 0 ? hue : hue + 360 // Hue, in degrees [0 to 360) | ||
]; | ||
} | ||
function LCH_to_Lab(LCH) { | ||
// Convert from polar form | ||
return [LCH[0], LCH[1] * Math.cos(LCH[2] * Math.PI / 180), LCH[1] * Math.sin(LCH[2] * Math.PI / 180) // b | ||
]; | ||
} | ||
/***/ }) | ||
/******/ }); | ||
/************************************************************************/ | ||
/******/ // The module cache | ||
/******/ var __webpack_module_cache__ = {}; | ||
/******/ | ||
/******/ // The require function | ||
/******/ function __webpack_require__(moduleId) { | ||
/******/ // Check if module is in cache | ||
/******/ var cachedModule = __webpack_module_cache__[moduleId]; | ||
/******/ if (cachedModule !== undefined) { | ||
/******/ return cachedModule.exports; | ||
/******/ } | ||
/******/ // Create a new module (and put it into the cache) | ||
/******/ var module = __webpack_module_cache__[moduleId] = { | ||
/******/ // no module.id needed | ||
/******/ // no module.loaded needed | ||
/******/ exports: {} | ||
/******/ }; | ||
/******/ | ||
/******/ // Execute the module function | ||
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); | ||
/******/ | ||
/******/ // Return the exports of the module | ||
/******/ return module.exports; | ||
/******/ } | ||
/******/ | ||
/************************************************************************/ | ||
/******/ /* webpack/runtime/define property getters */ | ||
/******/ (() => { | ||
/******/ // define getter functions for harmony exports | ||
/******/ __webpack_require__.d = (exports, definition) => { | ||
/******/ for(var key in definition) { | ||
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | ||
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | ||
/******/ } | ||
/******/ } | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/hasOwnProperty shorthand */ | ||
/******/ (() => { | ||
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/make namespace object */ | ||
/******/ (() => { | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = (exports) => { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/************************************************************************/ | ||
var __webpack_exports__ = {}; | ||
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. | ||
(() => { | ||
/*!**********************!*\ | ||
!*** ./src/index.ts ***! | ||
\**********************/ | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export */ __webpack_require__.d(__webpack_exports__, { | ||
/* harmony export */ "clamp": () => (/* binding */ clamp), | ||
/* harmony export */ "mix": () => (/* binding */ mix), | ||
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) | ||
/* harmony export */ }); | ||
/* harmony import */ var _w3c__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./w3c */ "./src/w3c.ts"); | ||
/* eslint-disable require-jsdoc */ | ||
/* eslint-disable camelcase */ | ||
/* eslint-disable new-cap */ | ||
var clamp = function clamp(val, min, max) { | ||
return Math.min(max, Math.max(min, val)); | ||
}; | ||
var mix = function mix(a, b, interp) { | ||
return a + (b - a) * interp; | ||
}; | ||
var Color = | ||
/** @class */ | ||
function () { | ||
function Color(r, g, b, a) { | ||
if (arguments.length === 1) { | ||
g = r; | ||
b = r; | ||
a = 1; | ||
} else if (arguments.length === 3) { | ||
a = 1; | ||
} else if (arguments.length !== 4) { | ||
throw new Error("Color must be given initial component values."); | ||
} | ||
this._r = Math.min(1, Math.max(0, r)); | ||
this._g = Math.min(1, Math.max(0, g)); | ||
this._b = Math.min(1, Math.max(0, b)); | ||
this._a = Math.min(1, Math.max(0, a)); | ||
} | ||
Color.prototype.r = function () { | ||
return this._r; | ||
}; | ||
Color.prototype.g = function () { | ||
return this._g; | ||
}; | ||
Color.prototype.b = function () { | ||
return this._b; | ||
}; | ||
Color.prototype.a = function () { | ||
return this._a; | ||
}; | ||
Color.prototype.setA = function (value) { | ||
this._a = Math.min(1, Math.max(0, value)); | ||
return this; | ||
}; | ||
Color.prototype.setR = function (value) { | ||
this._r = Math.min(1, Math.max(0, value)); | ||
return this; | ||
}; | ||
Color.prototype.setG = function (value) { | ||
this._g = Math.min(1, Math.max(0, value)); | ||
return this; | ||
}; | ||
Color.prototype.setB = function (value) { | ||
this._b = Math.min(1, Math.max(0, value)); | ||
return this; | ||
}; | ||
Color.prototype.multiply = function (other) { | ||
return new Color(this.r() * other.r(), this.g() * other.g(), this.b() * other.b(), this.a() * other.a()); | ||
}; | ||
Color.prototype.premultiply = function (other) { | ||
return new Color(this.a() * this.r() + other.r() * (1.0 - this.a()), this.a() * this.g() + other.g() * (1.0 - this.a()), this.a() * this.b() + other.b() * (1.0 - this.a()), 1.0); | ||
}; | ||
Color.prototype.asRGB = function () { | ||
return "rgb(" + Math.round(this._r * 255) + ", " + Math.round(this._g * 255) + ", " + Math.round(this._b * 255) + ")"; | ||
}; | ||
Color.prototype.asRGBA = function () { | ||
return "rgba(" + Math.round(this._r * 255) + ", " + Math.round(this._g * 255) + ", " + Math.round(this._b * 255) + ", " + this._a + ")"; | ||
}; | ||
Color.prototype.luminance = function () { | ||
// sRGB color model. | ||
var x1 = Color.inverseSRGBCompanding(this.r()); | ||
var y1 = Color.inverseSRGBCompanding(this.g()); | ||
var z1 = Color.inverseSRGBCompanding(this.b()); | ||
var R_LUMINANCE = 0.648431; | ||
var G_LUMINANCE = 0.321152; | ||
var B_LUMINANCE = 0.155886; | ||
return x1 * R_LUMINANCE + y1 * G_LUMINANCE + z1 * B_LUMINANCE; | ||
}; | ||
Color.prototype.toLCH = function () { | ||
var x1 = Color.inverseSRGBCompanding(this.r()); | ||
var y1 = Color.inverseSRGBCompanding(this.g()); | ||
var z1 = Color.inverseSRGBCompanding(this.b()); | ||
return (0,_w3c__WEBPACK_IMPORTED_MODULE_0__.Lab_to_LCH)((0,_w3c__WEBPACK_IMPORTED_MODULE_0__.XYZ_to_Lab)([x1, y1, z1])); | ||
}; | ||
Color.prototype.interpolate = function (other, interp) { | ||
// console.log("Interpolating"); | ||
interp = clamp(interp, 0, 1); | ||
var _c = this.toLCH(), | ||
L1 = _c[0], | ||
C1 = _c[1], | ||
H1 = _c[2]; | ||
var _d = other.toLCH(), | ||
L2 = _d[0], | ||
C2 = _d[1], | ||
H2 = _d[2]; | ||
var L3 = mix(L1, L2, interp); | ||
var C3 = mix(C1, C2, interp); | ||
var H3 = mix(H1, H2, interp); // console.log("L3=" + L3 + ", C3=" + C3 + ", H3=" + H3); | ||
return Color.fromLCH(L3, C3, H3, mix(this.a(), other.a(), interp)); | ||
}; | ||
Color.prototype.clone = function () { | ||
return new Color(this.r(), this.g(), this.b(), this.a()); | ||
}; | ||
Color.prototype.equals = function (other) { | ||
return this.r() === other.r() && this.g() === other.g() && this.b() === other.b() && this.a() === other.a(); | ||
}; | ||
Color.fromLCH = function (L3, C3, H3, a) { | ||
var _c = (0,_w3c__WEBPACK_IMPORTED_MODULE_0__.Lab_to_XYZ)((0,_w3c__WEBPACK_IMPORTED_MODULE_0__.LCH_to_Lab)([L3, C3, H3])), | ||
x3 = _c[0], | ||
y3 = _c[1], | ||
z3 = _c[2]; | ||
return new Color(Color.sRGBCompanding(x3), Color.sRGBCompanding(y3), Color.sRGBCompanding(z3), a); | ||
}; | ||
Color.inverseSRGBCompanding = function (v) { | ||
if (v <= 0.04045) { | ||
return v / 12.92; | ||
} | ||
return Math.pow((v + 0.055) / 1.055, 2.4); | ||
}; | ||
Color.sRGBCompanding = function (v) { | ||
if (v <= 0.0031308) { | ||
return v * 12.92; | ||
} | ||
return 1.055 * Math.pow(v, 1 / 2.4) - 0.055; | ||
}; | ||
Color.fromRGB = function (rgb, defaultAlpha) { | ||
// Default alpha to 255. | ||
if (arguments.length === 1) { | ||
defaultAlpha = 255; | ||
} // Extract the color from the string, as formatted in asRGB. | ||
var value = []; | ||
rgb.trim().substring("rgb(".length, rgb.length - 1).split(",").forEach(function (c) { | ||
value.push(parseInt(c.trim())); | ||
}); | ||
if (value.length < 3) { | ||
throw new Error("Failed to parse color"); | ||
} | ||
if (value.length === 3) { | ||
value.push(defaultAlpha); | ||
} // Return a new color. | ||
return new Color(value[0] / 255, value[1] / 255, value[2] / 255, value[3] / 255); | ||
}; | ||
Color.random = function (range, alpha) { | ||
if (range === void 0) { | ||
range = 1; | ||
} | ||
if (alpha === void 0) { | ||
alpha = 1; | ||
} | ||
range = Math.min(Math.max(0, range), 1); | ||
var clamped = 1 - range; | ||
return new Color(range * Math.random() + clamped / 2, range * Math.random() + clamped / 2, range * Math.random() + clamped / 2, alpha); | ||
}; | ||
return Color; | ||
}(); | ||
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Color); | ||
})(); | ||
/******/ return __webpack_exports__; | ||
/******/ })() | ||
; | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "parsegraph-color", | ||
"version": "1.4.8", | ||
"version": "1.4.9-dev", | ||
"description": "color", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
278548
33
2444
1