@cutoff/audio-ui-react 1.0.0-preview.20260123.1125
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.
- package/LICENSE.md +690 -0
- package/README.md +228 -0
- package/dist/components/defaults/controls/Button.d.ts +51 -0
- package/dist/components/defaults/controls/Button.d.ts.map +1 -0
- package/dist/components/defaults/controls/ButtonView.d.ts +20 -0
- package/dist/components/defaults/controls/ButtonView.d.ts.map +1 -0
- package/dist/components/defaults/controls/CycleButton.d.ts +82 -0
- package/dist/components/defaults/controls/CycleButton.d.ts.map +1 -0
- package/dist/components/defaults/controls/Knob.d.ts +82 -0
- package/dist/components/defaults/controls/Knob.d.ts.map +1 -0
- package/dist/components/defaults/controls/KnobView.d.ts +43 -0
- package/dist/components/defaults/controls/KnobView.d.ts.map +1 -0
- package/dist/components/defaults/controls/Slider.d.ts +79 -0
- package/dist/components/defaults/controls/Slider.d.ts.map +1 -0
- package/dist/components/defaults/controls/SliderView.d.ts +90 -0
- package/dist/components/defaults/controls/SliderView.d.ts.map +1 -0
- package/dist/components/defaults/devices/Keys.d.ts +104 -0
- package/dist/components/defaults/devices/Keys.d.ts.map +1 -0
- package/dist/components/generic/controls/FilmStripBooleanControl.d.ts +58 -0
- package/dist/components/generic/controls/FilmStripBooleanControl.d.ts.map +1 -0
- package/dist/components/generic/controls/FilmStripContinuousControl.d.ts +82 -0
- package/dist/components/generic/controls/FilmStripContinuousControl.d.ts.map +1 -0
- package/dist/components/generic/controls/FilmStripDiscreteControl.d.ts +55 -0
- package/dist/components/generic/controls/FilmStripDiscreteControl.d.ts.map +1 -0
- package/dist/components/generic/controls/FilmstripView.d.ts +36 -0
- package/dist/components/generic/controls/FilmstripView.d.ts.map +1 -0
- package/dist/components/generic/controls/ImageKnob.d.ts +74 -0
- package/dist/components/generic/controls/ImageKnob.d.ts.map +1 -0
- package/dist/components/generic/controls/ImageKnobView.d.ts +38 -0
- package/dist/components/generic/controls/ImageKnobView.d.ts.map +1 -0
- package/dist/components/generic/controls/ImageRotarySwitch.d.ts +54 -0
- package/dist/components/generic/controls/ImageRotarySwitch.d.ts.map +1 -0
- package/dist/components/generic/controls/ImageSwitch.d.ts +62 -0
- package/dist/components/generic/controls/ImageSwitch.d.ts.map +1 -0
- package/dist/components/generic/controls/ImageSwitchView.d.ts +26 -0
- package/dist/components/generic/controls/ImageSwitchView.d.ts.map +1 -0
- package/dist/components/primitives/AdaptiveBox.d.ts +127 -0
- package/dist/components/primitives/AdaptiveBox.d.ts.map +1 -0
- package/dist/components/primitives/controls/BooleanControl.d.ts +66 -0
- package/dist/components/primitives/controls/BooleanControl.d.ts.map +1 -0
- package/dist/components/primitives/controls/ContinuousControl.d.ts +46 -0
- package/dist/components/primitives/controls/ContinuousControl.d.ts.map +1 -0
- package/dist/components/primitives/controls/DiscreteControl.d.ts +70 -0
- package/dist/components/primitives/controls/DiscreteControl.d.ts.map +1 -0
- package/dist/components/primitives/controls/OptionView.d.ts +12 -0
- package/dist/components/primitives/controls/OptionView.d.ts.map +1 -0
- package/dist/components/primitives/svg/FilmstripImage.d.ts +60 -0
- package/dist/components/primitives/svg/FilmstripImage.d.ts.map +1 -0
- package/dist/components/primitives/svg/Image.d.ts +50 -0
- package/dist/components/primitives/svg/Image.d.ts.map +1 -0
- package/dist/components/primitives/svg/LabelRing.d.ts +42 -0
- package/dist/components/primitives/svg/LabelRing.d.ts.map +1 -0
- package/dist/components/primitives/svg/LinearCursor.d.ts +72 -0
- package/dist/components/primitives/svg/LinearCursor.d.ts.map +1 -0
- package/dist/components/primitives/svg/LinearStrip.d.ts +49 -0
- package/dist/components/primitives/svg/LinearStrip.d.ts.map +1 -0
- package/dist/components/primitives/svg/RadialHtmlOverlay.d.ts +29 -0
- package/dist/components/primitives/svg/RadialHtmlOverlay.d.ts.map +1 -0
- package/dist/components/primitives/svg/RadialImage.d.ts +36 -0
- package/dist/components/primitives/svg/RadialImage.d.ts.map +1 -0
- package/dist/components/primitives/svg/RevealingPath.d.ts +37 -0
- package/dist/components/primitives/svg/RevealingPath.d.ts.map +1 -0
- package/dist/components/primitives/svg/RingArc.d.ts +21 -0
- package/dist/components/primitives/svg/RingArc.d.ts.map +1 -0
- package/dist/components/primitives/svg/RotaryImage.d.ts +43 -0
- package/dist/components/primitives/svg/RotaryImage.d.ts.map +1 -0
- package/dist/components/primitives/svg/TickRing.d.ts +53 -0
- package/dist/components/primitives/svg/TickRing.d.ts.map +1 -0
- package/dist/components/primitives/svg/ValueRing.d.ts +38 -0
- package/dist/components/primitives/svg/ValueRing.d.ts.map +1 -0
- package/dist/components/primitives/svg/ValueStrip.d.ts +59 -0
- package/dist/components/primitives/svg/ValueStrip.d.ts.map +1 -0
- package/dist/components/types.d.ts +451 -0
- package/dist/components/types.d.ts.map +1 -0
- package/dist/hooks/useAdaptiveSize.d.ts +32 -0
- package/dist/hooks/useAdaptiveSize.d.ts.map +1 -0
- package/dist/hooks/useArcAngle.d.ts +23 -0
- package/dist/hooks/useArcAngle.d.ts.map +1 -0
- package/dist/hooks/useAudioParameter.d.ts +89 -0
- package/dist/hooks/useAudioParameter.d.ts.map +1 -0
- package/dist/hooks/useBooleanInteraction.d.ts +106 -0
- package/dist/hooks/useBooleanInteraction.d.ts.map +1 -0
- package/dist/hooks/useBooleanParameterResolution.d.ts +54 -0
- package/dist/hooks/useBooleanParameterResolution.d.ts.map +1 -0
- package/dist/hooks/useContinuousInteraction.d.ts +94 -0
- package/dist/hooks/useContinuousInteraction.d.ts.map +1 -0
- package/dist/hooks/useContinuousParameterResolution.d.ts +75 -0
- package/dist/hooks/useContinuousParameterResolution.d.ts.map +1 -0
- package/dist/hooks/useDiscreteInteraction.d.ts +70 -0
- package/dist/hooks/useDiscreteInteraction.d.ts.map +1 -0
- package/dist/hooks/useDiscreteParameterResolution.d.ts +120 -0
- package/dist/hooks/useDiscreteParameterResolution.d.ts.map +1 -0
- package/dist/hooks/useNoteInteraction.d.ts +84 -0
- package/dist/hooks/useNoteInteraction.d.ts.map +1 -0
- package/dist/hooks/useThemableProps.d.ts +68 -0
- package/dist/hooks/useThemableProps.d.ts.map +1 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3197 -0
- package/dist/index.js.map +1 -0
- package/dist/stats.html +4949 -0
- package/dist/style.css +1 -0
- package/dist/utils/textUtils.d.ts +15 -0
- package/dist/utils/textUtils.d.ts.map +1 -0
- package/dist/utils/theme.d.ts +88 -0
- package/dist/utils/theme.d.ts.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ContinuousParameter, BooleanParameter, DiscreteParameter, DiscreteOption, ScaleType, AudioParameter, MidiResolution, SizeType, InteractionMode, InteractionDirection } from '@cutoff/audio-ui-core';
|
|
3
|
+
|
|
4
|
+
export type { SizeType, InteractionMode, InteractionDirection } from '@cutoff/audio-ui-core';
|
|
5
|
+
/**
|
|
6
|
+
* Variant options for the Knob component
|
|
7
|
+
*/
|
|
8
|
+
export type KnobVariant = "abstract" | "simplest" | "plainCap" | "iconCap";
|
|
9
|
+
/**
|
|
10
|
+
* Variant options for the Slider component
|
|
11
|
+
*/
|
|
12
|
+
export type SliderVariant = "abstract" | "trackless" | "trackfull" | "stripless";
|
|
13
|
+
/**
|
|
14
|
+
* Cursor size options for the Slider component.
|
|
15
|
+
* Determines which component's width is used for the cursor.
|
|
16
|
+
* - "None": No cursor is rendered
|
|
17
|
+
* - "Strip": Width of the ValueStrip (if variant supports it)
|
|
18
|
+
* - "Track": Width of the LinearStrip (track)
|
|
19
|
+
* - "Tick": Width of the TickStrip (future use)
|
|
20
|
+
* - "Label": Entire width of the Slider, to the LabelStrip (future use)
|
|
21
|
+
*/
|
|
22
|
+
export type SliderCursorSize = "None" | "Strip" | "Track" | "Tick" | "Label";
|
|
23
|
+
/**
|
|
24
|
+
* Mode for displaying value vs label.
|
|
25
|
+
* - "labelOnly": Always shows the label (default)
|
|
26
|
+
* - "valueOnly": Always shows the value
|
|
27
|
+
* - "interactive": Shows label normally, but temporarily swaps to value during interaction
|
|
28
|
+
*/
|
|
29
|
+
export type ValueLabelMode = "labelOnly" | "valueOnly" | "interactive";
|
|
30
|
+
/**
|
|
31
|
+
* Standard event object emitted by all AudioUI controls.
|
|
32
|
+
* Provides the value in all three domain representations simultaneously.
|
|
33
|
+
*/
|
|
34
|
+
export type AudioControlEvent<T = number> = {
|
|
35
|
+
/** The real-world value (e.g. -6.0 dB, 440 Hz, true/false) */
|
|
36
|
+
value: T;
|
|
37
|
+
/** The normalized value (0.0 to 1.0) used for UI rendering and host automation */
|
|
38
|
+
normalizedValue: number;
|
|
39
|
+
/** The MIDI value (integer, e.g. 0-127 or 0-16383) used for hardware/protocol communication */
|
|
40
|
+
midiValue: number;
|
|
41
|
+
/** The parameter definition driving this value */
|
|
42
|
+
parameter?: any;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Props for interactive controls (drag, wheel, keyboard)
|
|
46
|
+
* Used by both continuous and enum controls.
|
|
47
|
+
*
|
|
48
|
+
* T is the real value type emitted by the control:
|
|
49
|
+
* - number for continuous controls (Knob, Slider)
|
|
50
|
+
* - boolean for boolean controls (not commonly using this type)
|
|
51
|
+
* - custom types for enum-like controls (e.g. CycleButton)
|
|
52
|
+
*/
|
|
53
|
+
export type InteractiveControlProps<T = number> = {
|
|
54
|
+
/**
|
|
55
|
+
* Handler for value changes.
|
|
56
|
+
* Receives a rich event object with real, normalized, and MIDI representations.
|
|
57
|
+
*/
|
|
58
|
+
onChange?: (event: AudioControlEvent<T>) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Interaction mode: drag, wheel, or both.
|
|
61
|
+
* @default "both"
|
|
62
|
+
*/
|
|
63
|
+
interactionMode?: InteractionMode;
|
|
64
|
+
/**
|
|
65
|
+
* Sensitivity of the control.
|
|
66
|
+
* Represents the amount of normalized value change per pixel (drag) or unit (wheel).
|
|
67
|
+
* @default Component-specific
|
|
68
|
+
*/
|
|
69
|
+
interactionSensitivity?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Direction of the interaction.
|
|
72
|
+
* Overrides the default direction defined by the component's view.
|
|
73
|
+
*/
|
|
74
|
+
interactionDirection?: InteractionDirection;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Adaptive sizing props for responsive components
|
|
78
|
+
*/
|
|
79
|
+
export type AdaptiveSizeProps = {
|
|
80
|
+
/**
|
|
81
|
+
* Adaptive sizing mode for the component.
|
|
82
|
+
* When true, the component stretches to fill its container and
|
|
83
|
+
* ignores the `size` prop for sizing constraints.
|
|
84
|
+
*
|
|
85
|
+
* When both `adaptiveSize` and `size` are provided, `adaptiveSize`
|
|
86
|
+
* takes precedence for sizing behavior.
|
|
87
|
+
*
|
|
88
|
+
* @default false
|
|
89
|
+
*/
|
|
90
|
+
adaptiveSize?: boolean;
|
|
91
|
+
/** Size of the component
|
|
92
|
+
* @default 'normal'
|
|
93
|
+
*/
|
|
94
|
+
size?: SizeType;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Layout props that control how AdaptiveBox behaves for a control.
|
|
98
|
+
*/
|
|
99
|
+
export type AdaptiveBoxProps = {
|
|
100
|
+
/**
|
|
101
|
+
* Layout mode for the control.
|
|
102
|
+
* - "scaleToFit": Preserve aspect ratio, letterbox within container.
|
|
103
|
+
* - "fill": Fill container, allowing horizontal stretching of the SVG.
|
|
104
|
+
*
|
|
105
|
+
* @default "scaleToFit"
|
|
106
|
+
*/
|
|
107
|
+
displayMode?: "scaleToFit" | "fill";
|
|
108
|
+
/**
|
|
109
|
+
* Visibility of the label row.
|
|
110
|
+
* - "visible": Render the label and reserve space.
|
|
111
|
+
* - "hidden": Reserve space but visually hide the label.
|
|
112
|
+
* - "none": Do not reserve label space.
|
|
113
|
+
*
|
|
114
|
+
* @default "visible"
|
|
115
|
+
*/
|
|
116
|
+
labelMode?: "none" | "hidden" | "visible";
|
|
117
|
+
/**
|
|
118
|
+
* Vertical position of the label relative to the control.
|
|
119
|
+
*
|
|
120
|
+
* @default "below"
|
|
121
|
+
*/
|
|
122
|
+
labelPosition?: "above" | "below";
|
|
123
|
+
/**
|
|
124
|
+
* Horizontal alignment of the label text within its row.
|
|
125
|
+
*
|
|
126
|
+
* @default "center"
|
|
127
|
+
*/
|
|
128
|
+
labelAlign?: "start" | "center" | "end";
|
|
129
|
+
/**
|
|
130
|
+
* How to handle label text overflow.
|
|
131
|
+
* - "ellipsis": Truncate with ellipsis when text is too long
|
|
132
|
+
* - "abbreviate": Abbreviate text to 3 characters max (e.g., "Volume" -> "Vol")
|
|
133
|
+
* - "auto": Automatically abbreviate when viewBoxWidth < viewBoxHeight, otherwise ellipsis
|
|
134
|
+
*
|
|
135
|
+
* @default "auto"
|
|
136
|
+
*/
|
|
137
|
+
labelOverflow?: "ellipsis" | "abbreviate" | "auto";
|
|
138
|
+
/**
|
|
139
|
+
* Label height in the same units as SVG viewBox height.
|
|
140
|
+
* Overrides the default from the view component's static labelHeightUnits property.
|
|
141
|
+
*/
|
|
142
|
+
labelHeightUnits?: number;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Logical size props for AdaptiveBox layout calculations.
|
|
146
|
+
* These correspond to the viewBox and labelHeightUnits properties
|
|
147
|
+
* from the ControlComponentView interface, but allow per-instance override.
|
|
148
|
+
*/
|
|
149
|
+
export type AdaptiveBoxLogicalSizeProps = {
|
|
150
|
+
/**
|
|
151
|
+
* ViewBox width in the same coordinate system as the content.
|
|
152
|
+
* Overrides the default from the view component's static viewBox.width property.
|
|
153
|
+
*/
|
|
154
|
+
viewBoxWidthUnits?: number;
|
|
155
|
+
/**
|
|
156
|
+
* ViewBox height in the same coordinate system as the content.
|
|
157
|
+
* Overrides the default from the view component's static viewBox.height property.
|
|
158
|
+
*/
|
|
159
|
+
viewBoxHeightUnits?: number;
|
|
160
|
+
/**
|
|
161
|
+
* Label height in the same units as SVG viewBox height.
|
|
162
|
+
* Overrides the default from the view component's static labelHeightUnits property.
|
|
163
|
+
*/
|
|
164
|
+
labelHeightUnits?: number;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Metadata for a control component.
|
|
168
|
+
* Used for display in customization interfaces and documentation.
|
|
169
|
+
*/
|
|
170
|
+
export interface ControlComponentMetadata {
|
|
171
|
+
/** Display name/title for the component */
|
|
172
|
+
title: string;
|
|
173
|
+
/** Optional description of what the component does */
|
|
174
|
+
description?: string;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Props for themable components
|
|
178
|
+
*/
|
|
179
|
+
export type ThemableProps = {
|
|
180
|
+
/** Component primary color - any valid CSS color value
|
|
181
|
+
* @default "blue"
|
|
182
|
+
*/
|
|
183
|
+
color?: string;
|
|
184
|
+
/** Roundness for component corners/caps
|
|
185
|
+
* Normalized value between 0.0 (square) and 1.0 (fully rounded)
|
|
186
|
+
* @default 0.3
|
|
187
|
+
*/
|
|
188
|
+
roundness?: number;
|
|
189
|
+
/** Thickness for component strokes/widths
|
|
190
|
+
* Normalized value between 0.0 (smallest) and 1.0 (largest)
|
|
191
|
+
* @default 0.4
|
|
192
|
+
*/
|
|
193
|
+
thickness?: number;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* BaseProps for all components
|
|
197
|
+
*/
|
|
198
|
+
export type BaseProps = {
|
|
199
|
+
/** Additional CSS classes */
|
|
200
|
+
className?: string;
|
|
201
|
+
/** Additional inline styles */
|
|
202
|
+
style?: React.CSSProperties;
|
|
203
|
+
/** Click event handler */
|
|
204
|
+
onClick?: React.MouseEventHandler;
|
|
205
|
+
/** Mouse down event handler */
|
|
206
|
+
onMouseDown?: React.MouseEventHandler;
|
|
207
|
+
/** Mouse up event handler */
|
|
208
|
+
onMouseUp?: React.MouseEventHandler;
|
|
209
|
+
/** Mouse enter event handler */
|
|
210
|
+
onMouseEnter?: React.MouseEventHandler;
|
|
211
|
+
/** Mouse leave event handler */
|
|
212
|
+
onMouseLeave?: React.MouseEventHandler;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Props for continuous value controls (primitives like ContinuousControl).
|
|
216
|
+
*
|
|
217
|
+
* This type is size-agnostic: it does not include AdaptiveSizeProps.
|
|
218
|
+
* Built-in controls (Knob, Slider) combine this with AdaptiveSizeProps
|
|
219
|
+
* so only high-level components handle size and stretch.
|
|
220
|
+
*
|
|
221
|
+
* Supports two modes:
|
|
222
|
+
* 1. Parameter model mode: Provide `parameter` (ContinuousParameter) - all range/label info comes from the model
|
|
223
|
+
* 2. Ad-hoc mode: Provide `min`, `max`, `step`, `label` directly as props
|
|
224
|
+
*
|
|
225
|
+
* When `parameter` is provided, it takes precedence over ad-hoc props.
|
|
226
|
+
*/
|
|
227
|
+
export type ContinuousControlProps = BaseProps & InteractiveControlProps<number> & {
|
|
228
|
+
/** Current value of the control */
|
|
229
|
+
value: number;
|
|
230
|
+
/** Label displayed below the component */
|
|
231
|
+
label?: string;
|
|
232
|
+
/** Identifier for the parameter this control represents
|
|
233
|
+
* Used when creating ad-hoc parameters
|
|
234
|
+
*/
|
|
235
|
+
paramId?: string;
|
|
236
|
+
/**
|
|
237
|
+
* Custom renderer for the value display
|
|
238
|
+
* If provided and returns a value, this function will be used to render the value instead of the default formatter
|
|
239
|
+
* @param value The current value
|
|
240
|
+
* @param parameterDef The full parameter definition (includes min, max, unit, scale, etc.)
|
|
241
|
+
* @returns A string representation of the value, or undefined to fall back to default formatter
|
|
242
|
+
*/
|
|
243
|
+
valueFormatter?: (value: number, parameterDef: AudioParameter) => string | undefined;
|
|
244
|
+
/**
|
|
245
|
+
* Controls how the label and value are displayed.
|
|
246
|
+
* - "labelOnly": Always shows the label (default)
|
|
247
|
+
* - "valueOnly": Always shows the value
|
|
248
|
+
* - "interactive": Shows label normally, but temporarily swaps to value during interaction
|
|
249
|
+
* @default "labelOnly"
|
|
250
|
+
*/
|
|
251
|
+
valueAsLabel?: ValueLabelMode;
|
|
252
|
+
/**
|
|
253
|
+
* Whether the component should operate in bipolar mode
|
|
254
|
+
* In bipolar mode, the component visualizes values relative to a center point
|
|
255
|
+
* rather than from minimum to maximum
|
|
256
|
+
* @default false
|
|
257
|
+
*/
|
|
258
|
+
bipolar?: boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Audio Parameter definition (Model)
|
|
261
|
+
* If provided, overrides min/max/step/label/bipolar from ad-hoc props
|
|
262
|
+
*/
|
|
263
|
+
parameter?: ContinuousParameter;
|
|
264
|
+
/**
|
|
265
|
+
* Unit suffix for the value in ad-hoc mode (e.g. "dB", "Hz").
|
|
266
|
+
* Used only when the internal parameter model is created from the props.
|
|
267
|
+
* Ignored when a full `parameter` object is provided.
|
|
268
|
+
*/
|
|
269
|
+
unit?: string;
|
|
270
|
+
/**
|
|
271
|
+
* Scale function or shortcut for the parameter in ad-hoc mode.
|
|
272
|
+
* Controls how the normalized 0..1 range maps to the real value domain.
|
|
273
|
+
* Common shortcuts are "linear", "log", and "exp".
|
|
274
|
+
* Ignored when a full `parameter` object is provided.
|
|
275
|
+
*/
|
|
276
|
+
scale?: ScaleType;
|
|
277
|
+
/** Minimum value (ad-hoc mode, ignored if parameter provided) */
|
|
278
|
+
min?: number;
|
|
279
|
+
/** Maximum value (ad-hoc mode, ignored if parameter provided) */
|
|
280
|
+
max?: number;
|
|
281
|
+
/** Step size for value adjustments (ad-hoc mode, ignored if parameter provided)
|
|
282
|
+
* @default 1 (or calculated based on range)
|
|
283
|
+
*/
|
|
284
|
+
step?: number;
|
|
285
|
+
/** MIDI resolution in bits (ad-hoc mode, ignored if parameter provided)
|
|
286
|
+
* @default 32
|
|
287
|
+
*/
|
|
288
|
+
midiResolution?: MidiResolution;
|
|
289
|
+
/** Default value for the parameter (ad-hoc mode, ignored if parameter provided) */
|
|
290
|
+
defaultValue?: number;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Props for discrete value controls (primitives like DiscreteControl).
|
|
294
|
+
*
|
|
295
|
+
* This type is size-agnostic: it does not include AdaptiveSizeProps.
|
|
296
|
+
* Built-in controls (CycleButton) combine this with AdaptiveSizeProps
|
|
297
|
+
* so only high-level components handle size and stretch.
|
|
298
|
+
*
|
|
299
|
+
* **Important: Options vs Children**
|
|
300
|
+
*
|
|
301
|
+
* - **`options` prop**: Defines the parameter model (value, label, midiValue). Used for parameter structure.
|
|
302
|
+
* - **`children` (Option components)**: Provides visual content (ReactNodes) for rendering. Used for display.
|
|
303
|
+
*
|
|
304
|
+
* These serve different purposes and can be used together:
|
|
305
|
+
* - Use `options` when you have data-driven option definitions
|
|
306
|
+
* - Use `children` when you want to provide custom visual content (icons, styled text, etc.)
|
|
307
|
+
* - Use both: `options` for the model, `children` for visuals (matched by value)
|
|
308
|
+
*
|
|
309
|
+
* Supports four modes:
|
|
310
|
+
* 1. **Ad-Hoc Mode (Options prop)**: Model from `options` prop, visual from `children` (if provided) or default rendering
|
|
311
|
+
* 2. **Ad-Hoc Mode (Children only)**: Model inferred from OptionView children, visual from children
|
|
312
|
+
* 3. **Strict Mode (Parameter only)**: Model from `parameter` prop, visual via `renderOption` callback
|
|
313
|
+
* 4. **Hybrid Mode (Parameter + Children)**: Model from `parameter` prop, visual from children (matched by value)
|
|
314
|
+
*
|
|
315
|
+
* When `parameter` is provided, it takes precedence over ad-hoc props.
|
|
316
|
+
*/
|
|
317
|
+
export type DiscreteControlProps = BaseProps & {
|
|
318
|
+
/** Current value of the control (Controlled mode) */
|
|
319
|
+
value?: string | number;
|
|
320
|
+
/** Default value of the component (Uncontrolled mode) */
|
|
321
|
+
defaultValue?: string | number;
|
|
322
|
+
/** Handler for value changes */
|
|
323
|
+
onChange?: (event: AudioControlEvent<string | number>) => void;
|
|
324
|
+
/** Label displayed below the component */
|
|
325
|
+
label?: string;
|
|
326
|
+
/** Identifier for the parameter this control represents
|
|
327
|
+
* Used when creating ad-hoc parameters
|
|
328
|
+
*/
|
|
329
|
+
paramId?: string;
|
|
330
|
+
/**
|
|
331
|
+
* Audio Parameter definition (Model)
|
|
332
|
+
* If provided, overrides label/options from ad-hoc props
|
|
333
|
+
*/
|
|
334
|
+
parameter?: DiscreteParameter;
|
|
335
|
+
/** Option definitions for the parameter model (Ad-Hoc mode)
|
|
336
|
+
*
|
|
337
|
+
* **Parameter Model Only**: This prop defines the parameter structure (value, label, midiValue).
|
|
338
|
+
* It does NOT provide visual content - use `children` (OptionView components) for that.
|
|
339
|
+
*
|
|
340
|
+
* When both `options` and `children` are provided:
|
|
341
|
+
* - `options` defines the parameter model
|
|
342
|
+
* - `children` provide visual content (matched by value)
|
|
343
|
+
*/
|
|
344
|
+
options?: DiscreteOption[];
|
|
345
|
+
/** Child elements (OptionView components) for visual content mapping (Hybrid/Ad-Hoc mode)
|
|
346
|
+
*
|
|
347
|
+
* **Visual Content Only**: Children provide ReactNodes for rendering (icons, text, custom components).
|
|
348
|
+
* They do NOT define the parameter model - use `options` prop or `parameter` prop for that.
|
|
349
|
+
*
|
|
350
|
+
* When both `options` and `children` are provided, children are matched to options by value
|
|
351
|
+
* to create the visual content map.
|
|
352
|
+
*/
|
|
353
|
+
children?: React.ReactNode;
|
|
354
|
+
/** MIDI resolution in bits (ad-hoc mode, ignored if parameter provided)
|
|
355
|
+
* @default 7
|
|
356
|
+
*/
|
|
357
|
+
midiResolution?: MidiResolution;
|
|
358
|
+
/** MIDI mapping strategy (ad-hoc mode, ignored if parameter provided)
|
|
359
|
+
* @default "spread"
|
|
360
|
+
*/
|
|
361
|
+
midiMapping?: "spread" | "sequential" | "custom";
|
|
362
|
+
};
|
|
363
|
+
/**
|
|
364
|
+
* Props for boolean value controls (primitives).
|
|
365
|
+
*
|
|
366
|
+
* This type is size-agnostic: it does not include AdaptiveSizeProps.
|
|
367
|
+
* Built-in controls (Button) combine this with AdaptiveSizeProps
|
|
368
|
+
* so only high-level components handle size and stretch.
|
|
369
|
+
*
|
|
370
|
+
* Supports two modes:
|
|
371
|
+
* 1. Parameter model mode: Provide `parameter` (BooleanParameter) - all config comes from the model
|
|
372
|
+
* 2. Ad-hoc mode: Provide `label`, `latch` directly as props
|
|
373
|
+
*
|
|
374
|
+
* When `parameter` is provided, it takes precedence over ad-hoc props.
|
|
375
|
+
*/
|
|
376
|
+
export type BooleanControlProps = BaseProps & {
|
|
377
|
+
/** Current value (must be boolean) */
|
|
378
|
+
value: boolean;
|
|
379
|
+
/** Handler for value changes */
|
|
380
|
+
onChange?: (event: AudioControlEvent<boolean>) => void;
|
|
381
|
+
/** Label displayed below the component */
|
|
382
|
+
label?: string;
|
|
383
|
+
/** Identifier for the parameter this control represents
|
|
384
|
+
* Used when creating ad-hoc parameters
|
|
385
|
+
*/
|
|
386
|
+
paramId?: string;
|
|
387
|
+
/**
|
|
388
|
+
* Audio Parameter definition (Model)
|
|
389
|
+
* If provided, overrides label/latch from ad-hoc props
|
|
390
|
+
*/
|
|
391
|
+
parameter?: BooleanParameter;
|
|
392
|
+
/** Whether the button should latch (toggle between states) or momentary (only active while pressed)
|
|
393
|
+
* Ad-hoc mode only, ignored if parameter provided
|
|
394
|
+
* @default false
|
|
395
|
+
*/
|
|
396
|
+
latch?: boolean;
|
|
397
|
+
/** MIDI resolution in bits (ad-hoc mode, ignored if parameter provided)
|
|
398
|
+
* @default 7
|
|
399
|
+
*/
|
|
400
|
+
midiResolution?: MidiResolution;
|
|
401
|
+
};
|
|
402
|
+
/**
|
|
403
|
+
* Contract for a component acting as a visualization for a generic control.
|
|
404
|
+
* It defines the geometric requirements and interaction behavior.
|
|
405
|
+
*/
|
|
406
|
+
export interface ControlComponentView {
|
|
407
|
+
/** The viewBox dimensions required by this visualization */
|
|
408
|
+
viewBox: {
|
|
409
|
+
width: number;
|
|
410
|
+
height: number;
|
|
411
|
+
};
|
|
412
|
+
/**
|
|
413
|
+
* Label height in the same units as SVG viewBox height.
|
|
414
|
+
* Used by AdaptiveBox to calculate layout proportions.
|
|
415
|
+
*/
|
|
416
|
+
labelHeightUnits?: number;
|
|
417
|
+
/**
|
|
418
|
+
* The preferred interaction configuration for this visualization.
|
|
419
|
+
* This tells the generic control how to interpret user input.
|
|
420
|
+
*/
|
|
421
|
+
interaction: {
|
|
422
|
+
/** Supported interaction modes */
|
|
423
|
+
mode?: InteractionMode;
|
|
424
|
+
/**
|
|
425
|
+
* Direction of the interaction gesture.
|
|
426
|
+
* - vertical: Drag up/down changes value (Standard Faders/Knobs)
|
|
427
|
+
* - horizontal: Drag left/right changes value
|
|
428
|
+
* - circular: Drag in a circle around the center changes value (Rotary Knobs)
|
|
429
|
+
*/
|
|
430
|
+
direction?: InteractionDirection;
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* The minimum props that ANY control view must accept.
|
|
435
|
+
*/
|
|
436
|
+
export interface ControlComponentViewProps {
|
|
437
|
+
/** The normalized value (0..1) to display */
|
|
438
|
+
normalizedValue: number;
|
|
439
|
+
/** Content to be rendered inside the control (e.g. label, icon) */
|
|
440
|
+
children?: React.ReactNode;
|
|
441
|
+
/** Optional class name passed from the parent */
|
|
442
|
+
className?: string;
|
|
443
|
+
/** Optional style passed from the parent */
|
|
444
|
+
style?: React.CSSProperties;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* A Generic Component Type that enforces the contract + props.
|
|
448
|
+
* P = Additional custom props specific to the visualization (e.g. color, thickness).
|
|
449
|
+
*/
|
|
450
|
+
export type ControlComponent<P = Record<string, unknown>> = React.ComponentType<ControlComponentViewProps & P> & ControlComponentView & Partial<ControlComponentMetadata>;
|
|
451
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/components/types.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACH,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,SAAS,EACT,cAAc,EACd,cAAc,EACjB,MAAM,uBAAuB,CAAC;AAG/B,YAAY,EAAE,QAAQ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Ac,CAAC;CACnC,CAAC;AAIF;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACjC,4DAA4D;IAC5D,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAE3C;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,WAAW,EAAE;QACT,kCAAkC;QAClC,IAAI,CAAC,EAAE,eAAe,CAAC;QACvB;;;;;WAKG;QACH,SAAS,CAAC,EAAE,oBAAoB,CAAC;KACpC,CAAC;CACL;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACtC,6CAA6C;IAC7C,eAAe,EAAE,MAAM,CAAC;IAExB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAE3B,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,KAAK,CAAC,aAAa,CAAC,yBAAyB,GAAG,CAAC,CAAC,GAC1G,oBAAoB,GACpB,OAAO,CAAC,wBAAwB,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SizeType } from '@cutoff/audio-ui-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hook that encapsulates adaptive sizing logic for components implementing AdaptiveSizeProps.
|
|
5
|
+
*
|
|
6
|
+
* Determines sizing behavior based on `adaptiveSize` and `size` props:
|
|
7
|
+
* - When `adaptiveSize` is true, the component stretches to fill its container (no size constraints)
|
|
8
|
+
* - When `adaptiveSize` is false, size classes and styles are applied based on the `size` prop
|
|
9
|
+
*
|
|
10
|
+
* @param adaptiveSize - Whether the component should stretch to fill its container
|
|
11
|
+
* @param size - The size value (ignored when adaptiveSize is true)
|
|
12
|
+
* @param componentType - The type of component ('knob', 'button', 'keys', or 'slider')
|
|
13
|
+
* @param orientation - Optional orientation for slider components ('vertical' or 'horizontal')
|
|
14
|
+
* @returns Object containing `sizeClassName` and `sizeStyle`
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* const { sizeClassName, sizeStyle } = useAdaptiveSize(
|
|
19
|
+
* adaptiveSize,
|
|
20
|
+
* size,
|
|
21
|
+
* "knob"
|
|
22
|
+
* );
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function useAdaptiveSize(adaptiveSize: boolean | undefined, size: SizeType | undefined, componentType: "knob" | "button" | "keys" | "slider", orientation?: "vertical" | "horizontal"): {
|
|
26
|
+
sizeClassName: string | undefined;
|
|
27
|
+
sizeStyle: {
|
|
28
|
+
width: string;
|
|
29
|
+
height: string;
|
|
30
|
+
} | undefined;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=useAdaptiveSize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAdaptiveSize.d.ts","sourceRoot":"","sources":["../../src/hooks/useAdaptiveSize.ts"],"names":[],"mappings":"AAOA,OAAO,EAAsD,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAErG;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,eAAe,CAC3B,YAAY,EAAE,OAAO,YAAQ,EAC7B,IAAI,EAAE,QAAQ,YAAW,EACzB,aAAa,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,EACpD,WAAW,CAAC,EAAE,UAAU,GAAG,YAAY;;;;;;EAsB1C"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ArcAngleResult } from '@cutoff/audio-ui-core';
|
|
2
|
+
|
|
3
|
+
export type UseArcAngleResult = ArcAngleResult;
|
|
4
|
+
/**
|
|
5
|
+
* Hook to calculate arc angles for rotary controls (ValueRing, RotaryImage components, or any other circular control).
|
|
6
|
+
*
|
|
7
|
+
* Calculates the angular range based on openness and converts a normalized value (0-1)
|
|
8
|
+
* to an angle within that range.
|
|
9
|
+
*
|
|
10
|
+
* The angle system:
|
|
11
|
+
* - 0 degrees is at 3 o'clock, increasing clockwise
|
|
12
|
+
* - Standard knob (90° openness) goes from ~225° (7:30) to ~495° (4:30)
|
|
13
|
+
* - 360° corresponds to UP (12 o'clock)
|
|
14
|
+
*
|
|
15
|
+
* @param normalizedValue Normalized value between 0 and 1
|
|
16
|
+
* @param openness Openness of the arc in degrees (0-360, default 90)
|
|
17
|
+
* @param rotation Rotation angle offset in degrees (default 0)
|
|
18
|
+
* @param bipolar Whether to start the value arc from the center (12 o'clock) instead of the start angle (default false)
|
|
19
|
+
* @param positions Optional number of discrete positions. When defined, the value will snap to the nearest position. Defaults to undefined (continuous mode).
|
|
20
|
+
* @returns Calculated angles and normalized values
|
|
21
|
+
*/
|
|
22
|
+
export declare function useArcAngle(normalizedValue: number, openness?: number, rotation?: number, bipolar?: boolean, positions?: number): UseArcAngleResult;
|
|
23
|
+
//# sourceMappingURL=useArcAngle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useArcAngle.d.ts","sourceRoot":"","sources":["../../src/hooks/useArcAngle.ts"],"names":[],"mappings":"AAOA,OAAO,EAAsB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE3E,MAAM,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAE/C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CACvB,eAAe,EAAE,MAAM,EACvB,QAAQ,GAAE,MAAW,EACrB,QAAQ,GAAE,MAAU,EACpB,OAAO,GAAE,OAAe,EACxB,SAAS,CAAC,EAAE,MAAM,GACnB,iBAAiB,CAInB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { AudioParameter, AudioParameterConverter } from '@cutoff/audio-ui-core';
|
|
2
|
+
import { AudioControlEvent } from '../components/types';
|
|
3
|
+
|
|
4
|
+
export interface UseAudioParameterResult {
|
|
5
|
+
/** The normalized value (0..1) for UI rendering */
|
|
6
|
+
normalizedValue: number;
|
|
7
|
+
/** Formatted string representation of the current value */
|
|
8
|
+
formattedValue: string;
|
|
9
|
+
/** The effective label to display (computed from userLabel, valueAsLabel, or parameter name) */
|
|
10
|
+
effectiveLabel: string;
|
|
11
|
+
/** The full parameter model instance */
|
|
12
|
+
converter: AudioParameterConverter;
|
|
13
|
+
/**
|
|
14
|
+
* Set the value using a normalized (0..1) input.
|
|
15
|
+
* Automatically denormalizes and calls onChange.
|
|
16
|
+
*/
|
|
17
|
+
setNormalizedValue: (normalized: number) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Adjust the value relatively (e.g. from mouse wheel or drag).
|
|
20
|
+
* @param delta The amount to change (in normalized units, typically small like 0.01)
|
|
21
|
+
* @param sensitivity Optional multiplier (default 1.0)
|
|
22
|
+
*/
|
|
23
|
+
adjustValue: (delta: number, sensitivity?: number) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Get the default normalized value (0..1).
|
|
26
|
+
* Returns the normalized defaultValue from the parameter if defined,
|
|
27
|
+
* otherwise returns 0.0 for unipolar or 0.5 for bipolar parameters.
|
|
28
|
+
*/
|
|
29
|
+
getDefaultNormalizedValue: () => number;
|
|
30
|
+
/**
|
|
31
|
+
* Reset the value to the default value.
|
|
32
|
+
* Uses the parameter's defaultValue if defined, otherwise uses 0.0 for unipolar or 0.5 for bipolar.
|
|
33
|
+
*/
|
|
34
|
+
resetToDefault: () => void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Hook to manage audio parameter logic, normalization, and formatting.
|
|
38
|
+
*
|
|
39
|
+
* This is the primary hook for connecting audio parameter models to React components.
|
|
40
|
+
* It handles all value conversions (real ↔ normalized ↔ MIDI) and provides formatted
|
|
41
|
+
* display values. The hook ensures that all conversions go through the MIDI pivot,
|
|
42
|
+
* maintaining consistency with hardware standards.
|
|
43
|
+
*
|
|
44
|
+
* The hook provides:
|
|
45
|
+
* - `normalizedValue`: 0..1 value for UI rendering
|
|
46
|
+
* - `formattedValue`: Formatted string for display
|
|
47
|
+
* - `converter`: The AudioParameterConverter instance for advanced operations
|
|
48
|
+
* - `setNormalizedValue`: Set value from normalized input (e.g., from UI slider)
|
|
49
|
+
* - `adjustValue`: Adjust value relatively (e.g., from mouse wheel or drag)
|
|
50
|
+
*
|
|
51
|
+
* @param value The current real-world value (Source of Truth)
|
|
52
|
+
* @param onChange Callback when value changes. Receives an AudioControlEvent with all value representations.
|
|
53
|
+
* @param parameterDef The parameter definition (AudioParameter)
|
|
54
|
+
* @param userValueFormatter Optional custom renderer for the value display. If provided and returns a value, it takes precedence over the default formatter.
|
|
55
|
+
* @param userLabel Optional custom label. If provided and valueAsLabel is false, takes precedence over parameter name.
|
|
56
|
+
* @param valueAsLabel When true, displays the formatted value as the label instead of the provided label or parameter name.
|
|
57
|
+
* @returns Object containing normalizedValue, formattedValue, effectiveLabel, converter, setNormalizedValue, and adjustValue
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```tsx
|
|
61
|
+
* // Basic usage
|
|
62
|
+
* const { normalizedValue, formattedValue, adjustValue } = useAudioParameter(
|
|
63
|
+
* volume,
|
|
64
|
+
* (e) => setVolume(e.value),
|
|
65
|
+
* volumeParam
|
|
66
|
+
* );
|
|
67
|
+
*
|
|
68
|
+
* // With custom label and value formatter
|
|
69
|
+
* const { normalizedValue, formattedValue, effectiveLabel, adjustValue } = useAudioParameter(
|
|
70
|
+
* volume,
|
|
71
|
+
* (e) => setVolume(e.value),
|
|
72
|
+
* volumeParam,
|
|
73
|
+
* (val) => `${val.toFixed(1)} dB`, // Custom formatter
|
|
74
|
+
* "Master Volume", // Custom label
|
|
75
|
+
* false // Don't use value as label
|
|
76
|
+
* );
|
|
77
|
+
*
|
|
78
|
+
* // Use normalizedValue for rendering
|
|
79
|
+
* <KnobView normalizedValue={normalizedValue} />
|
|
80
|
+
*
|
|
81
|
+
* // Use adjustValue for relative changes
|
|
82
|
+
* <div onWheel={(e) => adjustValue(e.deltaY, 0.001)} />
|
|
83
|
+
*
|
|
84
|
+
* // Use effectiveLabel for display
|
|
85
|
+
* <label>{effectiveLabel}</label>
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function useAudioParameter<T extends number | boolean | string>(value: T, onChange: undefined | ((event: AudioControlEvent<T>) => void), parameterDef: AudioParameter, userValueFormatter?: (value: T, parameterDef: AudioParameter) => string | undefined, userLabel?: string, valueAsLabel?: boolean): UseAudioParameterResult;
|
|
89
|
+
//# sourceMappingURL=useAudioParameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAudioParameter.d.ts","sourceRoot":"","sources":["../../src/hooks/useAudioParameter.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,MAAM,WAAW,uBAAuB;IACpC,mDAAmD;IACnD,eAAe,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,cAAc,EAAE,MAAM,CAAC;IACvB,gGAAgG;IAChG,cAAc,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,SAAS,EAAE,uBAAuB,CAAC;IACnC;;;OAGG;IACH,kBAAkB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD;;;;OAIG;IACH,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D;;;;OAIG;IACH,yBAAyB,EAAE,MAAM,MAAM,CAAC;IACxC;;;OAGG;IACH,cAAc,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO,GAAG,MAAM,EACjE,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,SAAS,GAAG,CAAC,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,EAC7D,YAAY,EAAE,cAAc,EAC5B,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,YAAY,EAAE,cAAc,KAAK,MAAM,GAAG,SAAS,EACnF,SAAS,CAAC,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,OAAO,GACvB,uBAAuB,CA4GzB"}
|