@octanejs/colorful 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/UPSTREAM.md +56 -0
  4. package/package.json +63 -0
  5. package/src/components/HexAlphaColorPicker.tsrx +14 -0
  6. package/src/components/HexColorInput.tsrx +26 -0
  7. package/src/components/HexColorPicker.tsrx +14 -0
  8. package/src/components/HslColorPicker.tsrx +14 -0
  9. package/src/components/HslStringColorPicker.tsrx +14 -0
  10. package/src/components/HslaColorPicker.tsrx +14 -0
  11. package/src/components/HslaStringColorPicker.tsrx +14 -0
  12. package/src/components/HsvColorPicker.tsrx +14 -0
  13. package/src/components/HsvStringColorPicker.tsrx +14 -0
  14. package/src/components/HsvaColorPicker.tsrx +14 -0
  15. package/src/components/HsvaStringColorPicker.tsrx +14 -0
  16. package/src/components/RgbColorPicker.tsrx +14 -0
  17. package/src/components/RgbStringColorPicker.tsrx +14 -0
  18. package/src/components/RgbaColorPicker.tsrx +14 -0
  19. package/src/components/RgbaStringColorPicker.tsrx +14 -0
  20. package/src/components/common/Alpha.tsrx +43 -0
  21. package/src/components/common/AlphaColorPicker.tsrx +75 -0
  22. package/src/components/common/ColorInput.tsrx +59 -0
  23. package/src/components/common/ColorPicker.tsrx +73 -0
  24. package/src/components/common/Hue.tsrx +41 -0
  25. package/src/components/common/Interactive.tsrx +167 -0
  26. package/src/components/common/Pointer.tsrx +16 -0
  27. package/src/components/common/Saturation.tsrx +46 -0
  28. package/src/css/styles.css +108 -0
  29. package/src/css/styles.ts +107 -0
  30. package/src/hooks/useColorManipulation.tsrx +55 -0
  31. package/src/hooks/useEventCallback.tsrx +12 -0
  32. package/src/hooks/useStyleSheet.tsrx +28 -0
  33. package/src/index.ts +18 -0
  34. package/src/types.ts +61 -0
  35. package/src/utils/clamp.ts +6 -0
  36. package/src/utils/compare.ts +32 -0
  37. package/src/utils/convert.ts +209 -0
  38. package/src/utils/format.ts +1 -0
  39. package/src/utils/nonce.ts +13 -0
  40. package/src/utils/round.ts +3 -0
  41. package/src/utils/validate.ts +13 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020-present Vlad Shilov <omgovich@ya.ru>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # @octanejs/colorful
2
+
3
+ Exact Octane binding for [`react-colorful@5.8.0`](https://github.com/omgovich/react-colorful).
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm add @octanejs/colorful
9
+ ```
10
+
11
+ ## Use
12
+
13
+ ```tsrx
14
+ import { useState } from 'octane';
15
+ import { HexColorPicker } from '@octanejs/colorful';
16
+
17
+ export function Picker() @{
18
+ const [color, setColor] = useState('#aabbcc');
19
+ <HexColorPicker color={color} onChange={setColor} />
20
+ }
21
+ ```
22
+
23
+ The package exports all 14 upstream picker variants, `HexColorInput`, the six
24
+ public color-model types, and `setNonce`. Pickers inject the upstream stylesheet
25
+ once into their closest `Document` or `ShadowRoot`, including iframe documents.
26
+
27
+ `HexColorInput` retains the upstream public `onChange(color)` callback. Its
28
+ internal text host uses Octane's native `input` event, so consumers do not need
29
+ to rename the component callback.
30
+
31
+ See [UPSTREAM.md](./UPSTREAM.md) for the pinned release and adaptation record.
package/UPSTREAM.md ADDED
@@ -0,0 +1,56 @@
1
+ # Upstream provenance
2
+
3
+ `@octanejs/colorful` is an Octane adaptation of
4
+ [`react-colorful@5.8.0`](https://github.com/omgovich/react-colorful/tree/v5.8.0).
5
+
6
+ - npm version: `5.8.0`
7
+ - npm integrity: `sha512-Wy9OzPfjSN9bF12OB8N7UQvlsZ0I+7wHxpN+bV5BjNQGxOj6IiwkRjevJK9yOBjJWGQvAaf1OXtn8rUeEatAng==`
8
+ - npm shasum: `9bc89aac3e8c847b503489614e2d28227b36641f`
9
+ - repository tag: `v5.8.0`
10
+ - repository commit: `d914e7647c40a8bbdb286985176e769d76061732`
11
+ - license: MIT
12
+ - React oracle: `react@19.2.7` / `react-dom@19.2.7` with `@types/react@19.2.17` / `@types/react-dom@19.2.3` via the dedicated `react-colorful-react-oracle` pnpm catalog (exact pins; not `catalog:default`)
13
+ - Pristine upstream `check-types` types: `@types/react@17.0.83` / `@types/react-dom@17.0.26` via npm aliases (`@types/react-colorful-pristine`, `@types/react-dom-colorful-pristine`)
14
+
15
+ The byte-preserved tag sources and tests live under `upstream/tag`; the
16
+ published declaration and package authorities live under `upstream/npm`.
17
+ Neither directory is included in the published package.
18
+
19
+ Framework-neutral color utilities are source-correspondent. React components,
20
+ hooks, JSX, synthetic event wrappers, and DOM prop types are adapted to Octane
21
+ components, hooks, `.tsrx`, native events, and Octane intrinsic prop types.
22
+ The public component callback named `onChange` remains unchanged; only the
23
+ internal text-input host wiring uses Octane's native `onInput`. Structured
24
+ ledger: `react-colorful-native-event-attributes` in `audit/react-parity.json`.
25
+
26
+ ## Test-suite disposition
27
+
28
+ | Upstream artifact | Disposition | Evidence |
29
+ | --- | --- | --- |
30
+ | `tag/tests/components.test.js` (35 cases) | **ported** one-for-one titles → `tests/upstream/components.test.ts` | adapted-octane lane |
31
+ | `tag/tests/utils.test.js` (27 cases) | **ported** one-for-one titles → `tests/upstream/utils.test.ts` | adapted-octane lane |
32
+ | `tag/tests/csp.test.js` (1 case) | **ported** → `tests/upstream/csp.test.ts` | adapted-octane lane |
33
+ | `tag/tests/shadowDom.test.js` (1 case) | **ported** → `tests/upstream/shadowDom.test.ts` | adapted-octane lane |
34
+ | `tag/tests/__snapshots__/*` | **pristine-only** (Jest snapshots); adapted asserts structure | pristine-upstream lane |
35
+ | Upstream `check-types` (`tsc --noEmit` on `src`) | **pristine** via `typetests/tsconfig.pristine.json` | pristine-types lane |
36
+ | Upstream `tag/src` ↔ Octane `src` program membership | **fail-closed fileDispositions** in `audit/type-parity.json` (`.tsx`/hook `.ts` → `.tsrx`; CSS-module decl + isomorphic layout effect are pristine-only with adapted evidence) | program inventories + `react-parity:validate` |
37
+ | Public type probes | **one-for-one** React (`audit/type-probes/public-api.test.ts`) ↔ Octane (`typetests/public-api.test.ts`) under `audit/type-parity.json`, including paired `HostInputEvent` proofs (`FormEvent` vs `InputEvent`) for `react-colorful-native-event-attributes` | type inventories + `pnpm test:type-parity` |
38
+ | Octane source + adapted probe | **adapted types** via `typetests/tsconfig.adapted.json` | adapted-types lane |
39
+
40
+ ### Port-authored classifications
41
+
42
+ Every authored runtime and type test is classified exactly once in
43
+ `audit/test-classifications.json` (fail-closed discovery over `tests/`,
44
+ `audit/type-probes/`, and `typetests/`). The table below is a summary only.
45
+
46
+ | File | Classification |
47
+ | --- | --- |
48
+ | `tests/upstream/**` | adapted-upstream-suite |
49
+ | `audit/type-probes/public-api.test.ts` | paired-repo-authored-react-type-oracle |
50
+ | `typetests/public-api.test.ts` | adapted-upstream-suite |
51
+ | `tests/runtime/exports.test.ts` | octane-only-framework-contract |
52
+ | `tests/runtime/owner-document.test.ts` | octane-only-framework-contract |
53
+ | `tests/hydration/**` | octane-only-framework-contract |
54
+ | `tests/ssr/**` | octane-only-framework-contract |
55
+ | `tests/browser/**` | octane-only-framework-contract |
56
+ | `tests/differential/**` | react-octane-differential |
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@octanejs/colorful",
3
+ "version": "0.0.1",
4
+ "description": "Exact Octane binding for react-colorful 5.8.0",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=22.22.2"
9
+ },
10
+ "author": {
11
+ "name": "Dominic Gannaway",
12
+ "email": "dg@domgan.com"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/octanejs/octane.git",
20
+ "directory": "packages/colorful"
21
+ },
22
+ "main": "./src/index.ts",
23
+ "module": "./src/index.ts",
24
+ "types": "./src/index.ts",
25
+ "files": [
26
+ "src",
27
+ "README.md",
28
+ "UPSTREAM.md",
29
+ "LICENSE"
30
+ ],
31
+ "exports": {
32
+ ".": "./src/index.ts"
33
+ },
34
+ "peerDependencies": {
35
+ "octane": "0.1.35"
36
+ },
37
+ "devDependencies": {
38
+ "@tsrx/react": "^0.2.56",
39
+ "@types/react": "19.2.17",
40
+ "@types/react-dom": "19.2.3",
41
+ "playwright": "^1.61.1",
42
+ "react": "19.2.7",
43
+ "react-colorful": "5.8.0",
44
+ "react-dom": "19.2.7",
45
+ "vite": "^8.1.5",
46
+ "vitest": "^4.1.10",
47
+ "@testing-library/react": "16.3.2",
48
+ "jest": "30.4.2",
49
+ "jest-environment-jsdom": "30.4.1",
50
+ "@swc/jest": "0.2.39",
51
+ "@swc/core": "1.15.41",
52
+ "@types/react-colorful-pristine": "npm:@types/react@17.0.83",
53
+ "@types/react-dom-colorful-pristine": "npm:@types/react-dom@17.0.26",
54
+ "octane": "0.1.35"
55
+ },
56
+ "scripts": {
57
+ "test": "pnpm upstream:verify && pnpm typecheck && vitest run --root ../.. --project colorful --project colorful-upstream --project colorful-ssr --project colorful-hydration --project colorful-differential",
58
+ "upstream:verify": "node audit/upstream-inventory.mjs",
59
+ "test:type-parity": "node ../../scripts/react-parity/react-colorful-types.mjs",
60
+ "typecheck": "tsrx-tsc --noEmit -p tsconfig.json && tsrx-tsc --noEmit -p typetests/tsconfig.adapted.json && tsc --noEmit -p typetests/tsconfig.pristine.json && tsc --noEmit -p audit/type-probes/tsconfig.pristine.json",
61
+ "test:pristine": "node ../../scripts/react-parity/jest-full-runner.mjs --config packages/colorful/tests/upstream-jest.config.cjs --root packages/colorful/upstream/tag"
62
+ }
63
+ }
@@ -0,0 +1,14 @@
1
+ import { AlphaColorPicker } from './common/AlphaColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps } from '../types';
3
+ import { equalHex } from '../utils/compare';
4
+ import { hexToHsva, hsvaToHex } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<string> = {
7
+ defaultColor: '0001',
8
+ toHsva: hexToHsva,
9
+ fromHsva: hsvaToHex,
10
+ equal: equalHex,
11
+ };
12
+
13
+ export const HexAlphaColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
14
+ <AlphaColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,26 @@
1
+ import { useCallback } from 'octane';
2
+ import type { ColorInputBaseProps } from '../types';
3
+ import { validHex } from '../utils/validate';
4
+ import { ColorInput } from './common/ColorInput.tsrx';
5
+
6
+ export interface HexColorInputProps extends ColorInputBaseProps {
7
+ prefixed?: boolean;
8
+ alpha?: boolean;
9
+ }
10
+
11
+ const prefix = (value: string) => '#' + value;
12
+
13
+ export const HexColorInput = ({ prefixed, alpha, ...rest }: HexColorInputProps) => {
14
+ const escape = useCallback(
15
+ (value: string) => value.replace(/([^0-9A-F]+)/gi, '').substring(0, alpha ? 8 : 6),
16
+ [alpha],
17
+ );
18
+ const validate = useCallback((value: string) => validHex(value, alpha), [alpha]);
19
+ return <ColorInput
20
+ {...rest}
21
+ escape={escape}
22
+ format={prefixed ? prefix : undefined}
23
+ process={prefix}
24
+ validate={validate}
25
+ />;
26
+ };
@@ -0,0 +1,14 @@
1
+ import { ColorPicker } from './common/ColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps } from '../types';
3
+ import { equalHex } from '../utils/compare';
4
+ import { hexToHsva, hsvaToHex } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<string> = {
7
+ defaultColor: '000',
8
+ toHsva: hexToHsva,
9
+ fromHsva: ({ h, s, v }) => hsvaToHex({ h, s, v, a: 1 }),
10
+ equal: equalHex,
11
+ };
12
+
13
+ export const HexColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
14
+ <ColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,14 @@
1
+ import { ColorPicker } from './common/ColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps, HslColor } from '../types';
3
+ import { equalColorObjects } from '../utils/compare';
4
+ import { hslaToHsva, hsvaToHsla, hslaToHsl } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<HslColor> = {
7
+ defaultColor: { h: 0, s: 0, l: 0 },
8
+ toHsva: ({ h, s, l }) => hslaToHsva({ h, s, l, a: 1 }),
9
+ fromHsva: (hsva) => hslaToHsl(hsvaToHsla(hsva)),
10
+ equal: equalColorObjects,
11
+ };
12
+
13
+ export const HslColorPicker = (props: Partial<ColorPickerBaseProps<HslColor>>) =>
14
+ <ColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,14 @@
1
+ import { ColorPicker } from './common/ColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps } from '../types';
3
+ import { equalColorString } from '../utils/compare';
4
+ import { hslStringToHsva, hsvaToHslString } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<string> = {
7
+ defaultColor: 'hsl(0, 0%, 0%)',
8
+ toHsva: hslStringToHsva,
9
+ fromHsva: hsvaToHslString,
10
+ equal: equalColorString,
11
+ };
12
+
13
+ export const HslStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
14
+ <ColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,14 @@
1
+ import { AlphaColorPicker } from './common/AlphaColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps, HslaColor } from '../types';
3
+ import { equalColorObjects } from '../utils/compare';
4
+ import { hslaToHsva, hsvaToHsla } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<HslaColor> = {
7
+ defaultColor: { h: 0, s: 0, l: 0, a: 1 },
8
+ toHsva: hslaToHsva,
9
+ fromHsva: hsvaToHsla,
10
+ equal: equalColorObjects,
11
+ };
12
+
13
+ export const HslaColorPicker = (props: Partial<ColorPickerBaseProps<HslaColor>>) =>
14
+ <AlphaColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,14 @@
1
+ import { AlphaColorPicker } from './common/AlphaColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps } from '../types';
3
+ import { equalColorString } from '../utils/compare';
4
+ import { hslaStringToHsva, hsvaToHslaString } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<string> = {
7
+ defaultColor: 'hsla(0, 0%, 0%, 1)',
8
+ toHsva: hslaStringToHsva,
9
+ fromHsva: hsvaToHslaString,
10
+ equal: equalColorString,
11
+ };
12
+
13
+ export const HslaStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
14
+ <AlphaColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,14 @@
1
+ import { ColorPicker } from './common/ColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps, HsvColor } from '../types';
3
+ import { equalColorObjects } from '../utils/compare';
4
+ import { hsvaToHsv } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<HsvColor> = {
7
+ defaultColor: { h: 0, s: 0, v: 0 },
8
+ toHsva: ({ h, s, v }) => ({ h, s, v, a: 1 }),
9
+ fromHsva: hsvaToHsv,
10
+ equal: equalColorObjects,
11
+ };
12
+
13
+ export const HsvColorPicker = (props: Partial<ColorPickerBaseProps<HsvColor>>) =>
14
+ <ColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,14 @@
1
+ import { ColorPicker } from './common/ColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps } from '../types';
3
+ import { equalColorString } from '../utils/compare';
4
+ import { hsvStringToHsva, hsvaToHsvString } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<string> = {
7
+ defaultColor: 'hsv(0, 0%, 0%)',
8
+ toHsva: hsvStringToHsva,
9
+ fromHsva: hsvaToHsvString,
10
+ equal: equalColorString,
11
+ };
12
+
13
+ export const HsvStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
14
+ <ColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,14 @@
1
+ import { AlphaColorPicker } from './common/AlphaColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps, HsvaColor } from '../types';
3
+ import { equalColorObjects } from '../utils/compare';
4
+ import { roundHsva } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<HsvaColor> = {
7
+ defaultColor: { h: 0, s: 0, v: 0, a: 1 },
8
+ toHsva: (hsva) => hsva,
9
+ fromHsva: roundHsva,
10
+ equal: equalColorObjects,
11
+ };
12
+
13
+ export const HsvaColorPicker = (props: Partial<ColorPickerBaseProps<HsvaColor>>) =>
14
+ <AlphaColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,14 @@
1
+ import { AlphaColorPicker } from './common/AlphaColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps } from '../types';
3
+ import { equalColorString } from '../utils/compare';
4
+ import { hsvaStringToHsva, hsvaToHsvaString } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<string> = {
7
+ defaultColor: 'hsva(0, 0%, 0%, 1)',
8
+ toHsva: hsvaStringToHsva,
9
+ fromHsva: hsvaToHsvaString,
10
+ equal: equalColorString,
11
+ };
12
+
13
+ export const HsvaStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
14
+ <AlphaColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,14 @@
1
+ import { ColorPicker } from './common/ColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps, RgbColor } from '../types';
3
+ import { equalColorObjects } from '../utils/compare';
4
+ import { rgbaToHsva, hsvaToRgba, rgbaToRgb } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<RgbColor> = {
7
+ defaultColor: { r: 0, g: 0, b: 0 },
8
+ toHsva: ({ r, g, b }) => rgbaToHsva({ r, g, b, a: 1 }),
9
+ fromHsva: (hsva) => rgbaToRgb(hsvaToRgba(hsva)),
10
+ equal: equalColorObjects,
11
+ };
12
+
13
+ export const RgbColorPicker = (props: Partial<ColorPickerBaseProps<RgbColor>>) =>
14
+ <ColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,14 @@
1
+ import { ColorPicker } from './common/ColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps } from '../types';
3
+ import { equalColorString } from '../utils/compare';
4
+ import { rgbStringToHsva, hsvaToRgbString } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<string> = {
7
+ defaultColor: 'rgb(0, 0, 0)',
8
+ toHsva: rgbStringToHsva,
9
+ fromHsva: hsvaToRgbString,
10
+ equal: equalColorString,
11
+ };
12
+
13
+ export const RgbStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
14
+ <ColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,14 @@
1
+ import { AlphaColorPicker } from './common/AlphaColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps, RgbaColor } from '../types';
3
+ import { equalColorObjects } from '../utils/compare';
4
+ import { rgbaToHsva, hsvaToRgba } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<RgbaColor> = {
7
+ defaultColor: { r: 0, g: 0, b: 0, a: 1 },
8
+ toHsva: rgbaToHsva,
9
+ fromHsva: hsvaToRgba,
10
+ equal: equalColorObjects,
11
+ };
12
+
13
+ export const RgbaColorPicker = (props: Partial<ColorPickerBaseProps<RgbaColor>>) =>
14
+ <AlphaColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,14 @@
1
+ import { AlphaColorPicker } from './common/AlphaColorPicker.tsrx';
2
+ import type { ColorModel, ColorPickerBaseProps } from '../types';
3
+ import { equalColorString } from '../utils/compare';
4
+ import { rgbaStringToHsva, hsvaToRgbaString } from '../utils/convert';
5
+
6
+ const colorModel: ColorModel<string> = {
7
+ defaultColor: 'rgba(0, 0, 0, 1)',
8
+ toHsva: rgbaStringToHsva,
9
+ fromHsva: hsvaToRgbaString,
10
+ equal: equalColorString,
11
+ };
12
+
13
+ export const RgbaStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
14
+ <AlphaColorPicker {...props} colorModel={colorModel} />;
@@ -0,0 +1,43 @@
1
+ import type { HsvaColor } from '../../types';
2
+ import { clamp } from '../../utils/clamp';
3
+ import { hsvaToHslaString } from '../../utils/convert';
4
+ import { formatClassName } from '../../utils/format';
5
+ import { round } from '../../utils/round';
6
+ import { Interactive, type Interaction } from './Interactive.tsrx';
7
+ import { Pointer } from './Pointer.tsrx';
8
+
9
+ interface Props {
10
+ className?: string;
11
+ hsva: HsvaColor;
12
+ onChange: (newAlpha: { a: number }) => void;
13
+ onChangeEnd?: () => void;
14
+ }
15
+
16
+ export const Alpha = ({ className, hsva, onChange, onChangeEnd }: Props) => {
17
+ const handleMove = (interaction: Interaction) => onChange({ a: interaction.left });
18
+ const handleKey = (offset: Interaction) => onChange({ a: clamp(hsva.a + offset.left) });
19
+ const colorFrom = hsvaToHslaString(Object.assign({}, hsva, { a: 0 }));
20
+ const colorTo = hsvaToHslaString(Object.assign({}, hsva, { a: 1 }));
21
+ const gradientStyle = { backgroundImage: `linear-gradient(90deg, ${colorFrom}, ${colorTo})` };
22
+ const nodeClassName = formatClassName(['react-colorful__alpha', className]);
23
+ const ariaValue = round(hsva.a * 100);
24
+ return <div class={nodeClassName}>
25
+ <div class="react-colorful__alpha-gradient" style={gradientStyle} />
26
+ <Interactive
27
+ onMove={handleMove}
28
+ onKey={handleKey}
29
+ onEnd={onChangeEnd}
30
+ aria-label="Alpha"
31
+ aria-valuetext={`${ariaValue}%`}
32
+ aria-valuenow={ariaValue}
33
+ aria-valuemin={0}
34
+ aria-valuemax={100}
35
+ >
36
+ <Pointer
37
+ className="react-colorful__alpha-pointer"
38
+ left={hsva.a}
39
+ color={hsvaToHslaString(hsva)}
40
+ />
41
+ </Interactive>
42
+ </div>;
43
+ };
@@ -0,0 +1,75 @@
1
+ import { useRef } from 'octane';
2
+ import type { Octane } from 'octane/jsx-runtime';
3
+ import { useColorManipulation } from '../../hooks/useColorManipulation.tsrx';
4
+ import { useStyleSheet } from '../../hooks/useStyleSheet.tsrx';
5
+ import type { AnyColor, ColorModel, ColorPickerBaseProps } from '../../types';
6
+ import { Alpha } from './Alpha.tsrx';
7
+ import { Hue } from './Hue.tsrx';
8
+ import { Saturation } from './Saturation.tsrx';
9
+
10
+ interface Props<T extends AnyColor> extends Partial<ColorPickerBaseProps<T>> {
11
+ colorModel: ColorModel<T>;
12
+ }
13
+
14
+ interface RootProps {
15
+ hostProps: Octane.JSX.IntrinsicElements['div'];
16
+ nodeRef: { current: HTMLDivElement | null };
17
+ className: Octane.JSX.IntrinsicElements['div']['className'];
18
+ classValue: Octane.JSX.IntrinsicElements['div']['class'];
19
+ hsva: import('../../types').HsvaColor;
20
+ onChange: (color: Partial<import('../../types').HsvaColor>) => void;
21
+ onChangeEnd: () => void;
22
+ }
23
+
24
+ function AlphaColorPickerRoot({
25
+ hostProps,
26
+ nodeRef,
27
+ className,
28
+ classValue,
29
+ hsva,
30
+ onChange,
31
+ onChangeEnd,
32
+ }: RootProps) {
33
+ return <div
34
+ {...hostProps}
35
+ ref={[hostProps.ref ?? null, nodeRef]}
36
+ class={['react-colorful', className, classValue]}
37
+ >
38
+ <Saturation hsva={hsva} onChange={onChange} onChangeEnd={onChangeEnd} />
39
+ <Hue hue={hsva.h} onChange={onChange} onChangeEnd={onChangeEnd} />
40
+ <Alpha
41
+ hsva={hsva}
42
+ onChange={onChange}
43
+ onChangeEnd={onChangeEnd}
44
+ className="react-colorful__last-control"
45
+ />
46
+ </div>;
47
+ }
48
+
49
+ export const AlphaColorPicker = <T extends AnyColor,>({
50
+ class: classValue,
51
+ className,
52
+ colorModel,
53
+ color = colorModel.defaultColor,
54
+ onChange,
55
+ onChangeEnd,
56
+ ...rest
57
+ }: Props<T>) => {
58
+ const nodeRef = useRef<HTMLDivElement | null>(null);
59
+ useStyleSheet(nodeRef);
60
+ const [hsva, updateHsva, commitChange] = useColorManipulation(
61
+ colorModel,
62
+ color,
63
+ onChange,
64
+ onChangeEnd,
65
+ );
66
+ return <AlphaColorPickerRoot
67
+ hostProps={rest}
68
+ nodeRef={nodeRef}
69
+ className={className}
70
+ classValue={classValue}
71
+ hsva={hsva}
72
+ onChange={updateHsva}
73
+ onChangeEnd={commitChange}
74
+ />;
75
+ };
@@ -0,0 +1,59 @@
1
+ import { useCallback, useEffect, useState } from 'octane';
2
+ import { useEventCallback } from '../../hooks/useEventCallback.tsrx';
3
+ import type { ColorInputBaseProps } from '../../types';
4
+
5
+ interface Props extends ColorInputBaseProps {
6
+ escape: (value: string) => string;
7
+ validate: (value: string) => boolean;
8
+ format?: (value: string) => string;
9
+ process?: (value: string) => string;
10
+ }
11
+
12
+ export const ColorInput = (props: Props) => {
13
+ const {
14
+ color = '',
15
+ onChange,
16
+ onBlur,
17
+ onInput,
18
+ escape,
19
+ validate,
20
+ format,
21
+ process,
22
+ ...rest
23
+ } = props;
24
+ const [value, setValue] = useState(() => escape(color));
25
+ const onChangeCallback = useEventCallback<string>(onChange);
26
+ const onBlurCallback = useEventCallback<
27
+ FocusEvent & { currentTarget: HTMLInputElement & EventTarget }
28
+ >(onBlur);
29
+
30
+ const handleInput = useCallback((event: InputEvent & {
31
+ currentTarget: HTMLInputElement & EventTarget;
32
+ }) => {
33
+ const target = event.currentTarget;
34
+ const inputValue = escape(target.value);
35
+ setValue(inputValue);
36
+ if (validate(inputValue)) onChangeCallback(process ? process(inputValue) : inputValue);
37
+ onInput?.(event);
38
+ }, [escape, process, validate, onChangeCallback, onInput]);
39
+
40
+ const handleBlur = useCallback((event: FocusEvent & {
41
+ currentTarget: HTMLInputElement & EventTarget;
42
+ }) => {
43
+ const target = event.currentTarget;
44
+ if (!validate(target.value)) setValue(escape(color));
45
+ onBlurCallback(event);
46
+ }, [color, escape, validate, onBlurCallback]);
47
+
48
+ useEffect(() => {
49
+ setValue(escape(color));
50
+ }, [color, escape]);
51
+
52
+ return <input
53
+ {...rest}
54
+ value={format ? format(value) : value}
55
+ spellCheck="false"
56
+ onInput={handleInput}
57
+ onBlur={handleBlur}
58
+ />;
59
+ };