Git Product home page Git Product logo

Comments (3)

drwpow avatar drwpow commented on August 23, 2024

It should accept an object; these tests even sure that’s still working right now.

I believe maybe there’s just confusion around the types—those are output types, not input types. In your example, if you called better.from(…).oklabVal you would indeed get a [number, number, number, number] type ([0.4856949, -0.03971, -0.14459, 1]) which matches (note: worth noting that this library will “snap” values to the closest sRGB color, so it’s intentionally lossy, in case you are ever returned a different value it just calculated the nearest-displayable color since Oklab’s range is boundless).

However, if you then tried and take that 4-length array and pass it back into better.from(), that’s where it would err because it’s just an array—it has no clue what colorspace that is. And so better.from() only accepts sRGB arrays as input, hence the object format.

Additional Info

The reason for returning an array for all colorspaces for better.from(…).*Val is more an implementation detail. When converting between colorspaces you use color matrixes that have an ordering to them, and they have to be converted to arrays anyway to preserve that ordering. And ordering also matters in CSS color functions (e.g. when using rgb(…) you can’t rearrange the channels). But again, an array gives no hints as to what colorspace it is, hence the object input differing here.

Unless I’m misunderstanding I don’t think there’s an issue with the README? Perhaps just the exported types aren’t what you expected?

from better-color-tools.

StarLederer avatar StarLederer commented on August 23, 2024

It should accept an object;
better.from() only accepts sRGB arrays as input

There is definitely a misunderstanding somewhere because i see these sentences as contradictory.

I believe maybe there’s just confusion around the types—those are output types, not input types

I am pretty sure those are input types and ColorOutput is the output type.

// parse.ts
export function from(rawColor: Color): ColorOutput {
  // ...
}

I don't know if this actually works at runtime but type checker is not happy with me providing it an object.

from better-color-tools.

drwpow avatar drwpow commented on August 23, 2024

Thanks for clarifying. I was able to push a better update to the types, and also converted the tests to TypeScript to prevent this from happening again. Please try the latest version and let me know if you have any additional problems 🙏

from better-color-tools.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.