Comments (5)
Vladimir,
Thanks for tracking this down. Can you explain what input is failing for you, and what the expected behavior is so we can make sure it is fixed? I want to make sure that we can spec out what should happen with negative values so we can add it to the test suite.
from tinycolor.
Same thing here. Since color is measured on a circular scale, any increases or decreases in the value should just keep on going around the circle instead of going out-of-range.
For example, tinycolor.js should normalize an out-of-range value of 361 as just 1. Conversely, it should change -1 into 359. A very high number such as 721 should be just 1. My version is similar to Vladimir's, except it allows input values beyond 360. Fiddle.
return { h: ( m1 < 0 ? m1 % 360 + 360 : m1 % 360 ), s: match[2], l: match[3] };
P.S. I have been getting some mileage out of this library, and I love it. :)
from tinycolor.
Yes I think this is what CSS colors are doing: http://jsfiddle.net/dd1t8zvq/. From http://www.w3.org/TR/css3-color/#hsl-color: "As an angle, it implicitly wraps around such that -120=240 and 480=120".
@timothyausten would you be able create a pull request with your change and a small test case?
from tinycolor.
Pull request created.
from tinycolor.
According to this article https://en.wikipedia.org/wiki/Modulo_operation#Remainder_calculation_for_the_modulo_operation
you can use floored division function:
modulo(x,y){
return x - y * Math.floor(x / y)
}
tinycolor(h: modulo(hue, 360), s: 100, l: 50)
from tinycolor.
Related Issues (20)
- In built way to automatically Darken or Lighten by amount depending on the color luminance
- Is toFloatString() implemented?
- React 18 types mismatch
- Feature: include alpha in Hex HOT 2
- Is there a way to reverse a colour, like a negative image?
- Support for LCH?
- Octal literal in strict mode
- tinycolor.mix(color1, color2, amount = 50) not working in React native HOT 1
- Doesn't work with calc HOT 1
- tinycolor is not a function HOT 39
- remove `engines` field from package.json
- Task: Publish 1.6.0 to npm
- Remove tinycolor.js and dist/tinycolor-min.js once we confirm they aren't used HOT 1
- Include a Changelog HOT 4
- asset files includes ES6 syntax HOT 2
- Task: Publish 1.6.1
- [Question] Overlay Colors
- why tinycolor({h: 0, s: 100,v: 0}).toHsv() result {h: 0, s: 0, v: 0} ? HOT 2
- [Question] OKLCH support?
- RGBA fails to parse if alpha is missing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinycolor.