openpencil/packages/docs/programmable/sdk/api/advanced/use-okhcl.md

62 lines
1.7 KiB
Markdown
Raw Normal View History

2026-03-30 12:11:31 +00:00
---
title: useOkHCL
description: Persist OkHCL intent for selected node fills and strokes.
2026-03-30 12:11:31 +00:00
---
# useOkHCL
`useOkHCL()` is the editor-aware adapter for OkHCL fill and stroke metadata. It reads stored color
intent, updates nodes with undo, reports preview gamut information, and remembers the selected
field format for each fill or stroke.
2026-03-30 12:11:31 +00:00
Use [`useColorModel()`](../composables/use-color-model) for framework-agnostic conversion, channel
editing, and slider presentation. Use `useOkHCL()` only where those edits need to be persisted to an
OpenPencil editor.
2026-03-30 12:11:31 +00:00
## Usage
```ts
import { useOkHCL } from '@open-pencil/vue'
const okhcl = useOkHCL()
const color = okhcl.getFillOkHCLColor(node, 0)
okhcl.updateFillOkHCL(node, 0, { c: 0.2 })
```
## Format state
```ts
const format = okhcl.getFieldFormat(node, 0, 'fill')
okhcl.setFillFieldFormat(node, 0, 'okhcl')
2026-03-30 12:11:31 +00:00
```
Selecting `okhcl` initializes intent from the fill or stroke's current RGBA color. The returned
`fieldOptions` can be used to build a format selector.
## Preview information
```ts
const preview = okhcl.getFillPreviewInfo(node, 0)
// { previewColorSpace, clipped }
```
Preview information reflects the document render color space and whether the stored OkHCL intent
needed gamut mapping.
2026-03-30 12:11:31 +00:00
## Returns
- `getFillOkHCLColor()` / `getStrokeOkHCLColor()`
- `getFillPreviewInfo()` / `getStrokePreviewInfo()`
- `getFieldFormat()`
- `setFillFieldFormat()` / `setStrokeFieldFormat()`
- `updateFillOkHCL()` / `updateStrokeOkHCL()`
- `fieldOptions`
2026-03-30 12:11:31 +00:00
## Related APIs
- [useColorModel](../composables/use-color-model)
2026-03-30 12:11:31 +00:00
- [useFillControls](../composables/use-fill-controls)
- [useStrokeControls](../composables/use-stroke-controls)
- [ColorPickerRoot](../components/color-picker-root)