-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e601b1
commit dd665d4
Showing
56 changed files
with
862 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
// Copyright 2022-2023 the Chili authors. All rights reserved. AGPL-3.0 license. | ||
|
||
import { Color, Result } from "../foundation"; | ||
import { Result } from "../foundation"; | ||
import { IConverter } from "./converter"; | ||
|
||
export class ColorConverter implements IConverter<Color> { | ||
convert(value: Color): Result<string> { | ||
return Result.success(value.toHexStr()); | ||
export class ColorConverter implements IConverter<number> { | ||
convert(value: number): Result<string> { | ||
return Result.success("#" + value.toString(16).padStart(6, "0")); | ||
} | ||
|
||
convertBack(value: string): Result<Color> { | ||
return Color.fromHexStr(value); | ||
convertBack(value: string): Result<number> { | ||
if (value.startsWith("#")) { | ||
value = value.substring(1); | ||
} | ||
let result = parseInt(value, 16); | ||
if (Number.isNaN(value)) return Result.error("Invalid hex string: " + value); | ||
return Result.success(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.