@kitlangton/knobs 0.0.0-stage → 0.1.0
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 +21 -0
- package/README.md +1270 -2
- package/dist/dev/chunk-e13znr7c.js +155 -0
- package/dist/dev/chunk-kdewv0mt.js +1334 -0
- package/dist/dev/chunk-ktsn42p7.js +15668 -0
- package/dist/dev/chunk-qtt698hp.js +1118 -0
- package/dist/dev/index.js +1389 -0
- package/dist/index.js +2367 -0
- package/dist/panel.js +23635 -0
- package/dist/react.js +326 -0
- package/dist/solid.js +336 -0
- package/dist/themes.js +235 -0
- package/dist/types/core/adapter.d.ts +21 -0
- package/dist/types/core/code.d.ts +3 -0
- package/dist/types/core/color.d.ts +27 -0
- package/dist/types/core/easing.d.ts +21 -0
- package/dist/types/core/internal.d.ts +18 -0
- package/dist/types/core/keys.d.ts +21 -0
- package/dist/types/core/mutate.d.ts +21 -0
- package/dist/types/core/ramp.d.ts +150 -0
- package/dist/types/core/random.d.ts +2 -0
- package/dist/types/core/readout.d.ts +73 -0
- package/dist/types/core/remote.d.ts +258 -0
- package/dist/types/core/schema.d.ts +526 -0
- package/dist/types/core/spring.d.ts +38 -0
- package/dist/types/core/storage.d.ts +8 -0
- package/dist/types/core/store.d.ts +474 -0
- package/dist/types/core/theme.d.ts +27 -0
- package/dist/types/core/variants.d.ts +17 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/panel/attach.d.ts +5 -0
- package/dist/types/panel/choice.d.ts +56 -0
- package/dist/types/panel/die.d.ts +121 -0
- package/dist/types/panel/editors.d.ts +159 -0
- package/dist/types/panel/folds.d.ts +14 -0
- package/dist/types/panel/give.d.ts +73 -0
- package/dist/types/panel/gpu/atlas.d.ts +40 -0
- package/dist/types/panel/gpu/color.d.ts +128 -0
- package/dist/types/panel/gpu/die.wgsl.d.ts +1 -0
- package/dist/types/panel/gpu/renderer.d.ts +712 -0
- package/dist/types/panel/gpu/shader.wgsl.d.ts +2 -0
- package/dist/types/panel/haptics.d.ts +8 -0
- package/dist/types/panel/has.d.ts +14 -0
- package/dist/types/panel/hints.d.ts +45 -0
- package/dist/types/panel/icons.d.ts +30 -0
- package/dist/types/panel/index.d.ts +10 -0
- package/dist/types/panel/inspector.d.ts +20 -0
- package/dist/types/panel/measure.d.ts +6 -0
- package/dist/types/panel/menu.d.ts +38 -0
- package/dist/types/panel/morph.d.ts +38 -0
- package/dist/types/panel/motion.d.ts +77 -0
- package/dist/types/panel/page-hints.d.ts +82 -0
- package/dist/types/panel/page.d.ts +423 -0
- package/dist/types/panel/panel.d.ts +43 -0
- package/dist/types/panel/position.d.ts +5 -0
- package/dist/types/panel/prefs.d.ts +28 -0
- package/dist/types/panel/presets.d.ts +48 -0
- package/dist/types/panel/ramps.d.ts +14 -0
- package/dist/types/panel/readout-row.d.ts +21 -0
- package/dist/types/panel/reveal.d.ts +15 -0
- package/dist/types/panel/rolling-css.d.ts +2 -0
- package/dist/types/panel/search.d.ts +36 -0
- package/dist/types/panel/seg.d.ts +15 -0
- package/dist/types/panel/session.d.ts +21 -0
- package/dist/types/panel/slider.d.ts +92 -0
- package/dist/types/panel/smear.d.ts +7 -0
- package/dist/types/panel/spin.d.ts +13 -0
- package/dist/types/panel/styles.d.ts +11 -0
- package/dist/types/panel/swipe.d.ts +114 -0
- package/dist/types/panel/switcher.d.ts +20 -0
- package/dist/types/panel/tabs.d.ts +31 -0
- package/dist/types/panel/thumb.d.ts +36 -0
- package/dist/types/react/Knobs.d.ts +15 -0
- package/dist/types/react/VariantSwitcher.d.ts +10 -0
- package/dist/types/react/index.d.ts +3 -0
- package/dist/types/react/useControls.d.ts +11 -0
- package/dist/types/solid/index.d.ts +50 -0
- package/dist/types/themes/index.d.ts +1 -0
- package/dist/types/ui/bento-css.d.ts +1 -0
- package/dist/types/ui/bento-model.d.ts +96 -0
- package/dist/types/ui/bento.d.ts +77 -0
- package/dist/types/ui/commands.d.ts +11 -0
- package/dist/types/ui/confirm.d.ts +13 -0
- package/dist/types/ui/index.d.ts +20 -0
- package/dist/types/ui/layer.d.ts +70 -0
- package/dist/types/ui/look.d.ts +53 -0
- package/dist/types/ui/menu.d.ts +63 -0
- package/dist/types/ui/overlay-css.d.ts +1 -0
- package/dist/types/ui/overlay-model.d.ts +87 -0
- package/dist/types/ui/palette.d.ts +38 -0
- package/dist/types/ui/popover.d.ts +35 -0
- package/dist/types/ui/react.d.ts +45 -0
- package/dist/types/ui/readout-css.d.ts +1 -0
- package/dist/types/ui/readout-model.d.ts +137 -0
- package/dist/types/ui/readouts.d.ts +85 -0
- package/dist/types/ui/rgba.d.ts +6 -0
- package/dist/types/ui/solid.d.ts +40 -0
- package/dist/types/ui/split-model.d.ts +81 -0
- package/dist/types/ui/split.d.ts +75 -0
- package/dist/types/ui/timeline-model.d.ts +83 -0
- package/dist/types/ui/timeline.d.ts +76 -0
- package/dist/types/ui/toast.d.ts +19 -0
- package/dist/types/ui/tooltip.d.ts +19 -0
- package/dist/types/ui/tree-model.d.ts +125 -0
- package/dist/types/ui/tree.d.ts +95 -0
- package/dist/ui-react.js +6558 -0
- package/dist/ui-solid.js +6511 -0
- package/dist/ui.js +9238 -0
- package/package.json +99 -4
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import type { CurveInterp, CurvePoint, GradientSpace, GradientStop } from "./ramp.js";
|
|
2
|
+
import { type Field, type FieldMeta, type GraphSeries, type GraphThreshold, type ToolbarShortcut, type Schema, type State, type Value } from "./schema.js";
|
|
3
|
+
import type { SpringValue } from "./spring.js";
|
|
4
|
+
import type { StoragePort } from "./storage.js";
|
|
5
|
+
import { type ChangeMeta, type GestureEvent, type ControlAction, type GroupPreset, type Controls, type DensityMode, type GroupPresetDisplay, type HostHistory, type PanelKeys, type PersistMode, type PanelModule, type RendererMode, type SectionFolded, type ThemeMode } from "./store.js";
|
|
6
|
+
/** A choice option with its own label: `{ id: "md", label: "Medium" }` (`value` works for `id`). */
|
|
7
|
+
export interface ChoiceOption {
|
|
8
|
+
readonly id?: string;
|
|
9
|
+
readonly value?: string;
|
|
10
|
+
readonly label?: string;
|
|
11
|
+
}
|
|
12
|
+
interface DescriptorMeta extends FieldMeta {
|
|
13
|
+
readonly key: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Two flat number keys drawn as one spring card (a curve and two sliders). Values stay flat:
|
|
17
|
+
* `onSet("duration", 0.4)`, `values.bounce`. When the bound keys have number descriptors of their
|
|
18
|
+
* own, their ranges, labels and defaults are used (and they aren't drawn again); otherwise the
|
|
19
|
+
* spring's `default` and the standard spring ranges are.
|
|
20
|
+
*/
|
|
21
|
+
export interface SpringBindingDescriptor extends DescriptorMeta {
|
|
22
|
+
readonly kind: "spring";
|
|
23
|
+
readonly bind: {
|
|
24
|
+
readonly duration: string;
|
|
25
|
+
readonly bounce: string;
|
|
26
|
+
};
|
|
27
|
+
readonly default?: SpringValue;
|
|
28
|
+
}
|
|
29
|
+
/** A button row: pressing it calls `onAction(key)`. */
|
|
30
|
+
export interface ActionDescriptor extends DescriptorMeta {
|
|
31
|
+
readonly kind: "action";
|
|
32
|
+
readonly default?: undefined;
|
|
33
|
+
readonly bind?: undefined;
|
|
34
|
+
}
|
|
35
|
+
/** A row of buttons; pressing one calls `onAction(item.key)`. */
|
|
36
|
+
export interface ToolbarDescriptor extends DescriptorMeta {
|
|
37
|
+
readonly kind: "toolbar";
|
|
38
|
+
readonly items: readonly {
|
|
39
|
+
readonly key: string;
|
|
40
|
+
readonly label: string;
|
|
41
|
+
readonly icon?: string;
|
|
42
|
+
readonly shortcut?: string | ToolbarShortcut;
|
|
43
|
+
readonly global?: boolean;
|
|
44
|
+
readonly disabled?: boolean;
|
|
45
|
+
}[];
|
|
46
|
+
readonly default?: undefined;
|
|
47
|
+
readonly bind?: undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A readout row (`watch`, `sparkline`, `graph`, `meter`, `table`, `log`): it shows what
|
|
51
|
+
* `controls.watch(key, value)` pushes and holds no value. Options as their field constructors take.
|
|
52
|
+
*/
|
|
53
|
+
export interface ReadoutDescriptor extends DescriptorMeta {
|
|
54
|
+
readonly kind: "watch" | "sparkline" | "graph" | "meter" | "table" | "log";
|
|
55
|
+
readonly unit?: string;
|
|
56
|
+
readonly decimals?: number;
|
|
57
|
+
readonly hz?: number;
|
|
58
|
+
readonly min?: number;
|
|
59
|
+
readonly max?: number;
|
|
60
|
+
readonly history?: number;
|
|
61
|
+
readonly height?: number;
|
|
62
|
+
readonly color?: string;
|
|
63
|
+
readonly series?: readonly (GraphSeries | string)[];
|
|
64
|
+
readonly thresholds?: readonly (GraphThreshold | number)[];
|
|
65
|
+
readonly segments?: number;
|
|
66
|
+
readonly warn?: number;
|
|
67
|
+
readonly critical?: number;
|
|
68
|
+
readonly columns?: readonly string[];
|
|
69
|
+
readonly lines?: number;
|
|
70
|
+
readonly get?: () => unknown;
|
|
71
|
+
readonly format?: (value: number) => string;
|
|
72
|
+
readonly default?: undefined;
|
|
73
|
+
readonly bind?: undefined;
|
|
74
|
+
}
|
|
75
|
+
export type ControlDescriptor = ValueDescriptor | SpringBindingDescriptor | ActionDescriptor | ToolbarDescriptor | ReadoutDescriptor;
|
|
76
|
+
export interface ValueDescriptor extends DescriptorMeta {
|
|
77
|
+
readonly bind?: undefined;
|
|
78
|
+
readonly kind: "knob" | "number" | "choice" | "toggle" | "bool" | "spring" | "color" | "point" | "easing" | "vec2" | "vec3" | "range" | "angle" | "seed" | "keybind" | "gradient" | "curve";
|
|
79
|
+
/**
|
|
80
|
+
* Springs take `{ duration, bounce }`, colours a CSS string, points and vec2 `{ x, y }`, vec3
|
|
81
|
+
* `{ x, y, z }`, easings `[x1, y1, x2, y2]`, ranges `[low, high]`, keybinds a combination
|
|
82
|
+
* string (`"Meta+K"`), gradients `[{ at, color }]` and curves `[{ x, y }]`.
|
|
83
|
+
*/
|
|
84
|
+
readonly default: Value;
|
|
85
|
+
readonly min?: number;
|
|
86
|
+
readonly max?: number;
|
|
87
|
+
readonly step?: number;
|
|
88
|
+
readonly unit?: string;
|
|
89
|
+
/** Readout digits after the point (the step's own by default). */
|
|
90
|
+
readonly decimals?: number;
|
|
91
|
+
/** Choices: segments or a drop-down menu (see `Choice.display`); automatic by default. */
|
|
92
|
+
readonly display?: "menu" | "segmented";
|
|
93
|
+
/** Strings, or `{ id, label }` options; past four, or when they don't fit, a menu. */
|
|
94
|
+
readonly choices?: readonly (string | ChoiceOption)[];
|
|
95
|
+
readonly options?: readonly (string | ChoiceOption)[];
|
|
96
|
+
readonly swiftType?: string;
|
|
97
|
+
/** Vectors: show the link toggle for uniform scaling (`linked` starts it on). */
|
|
98
|
+
readonly link?: boolean;
|
|
99
|
+
readonly linked?: boolean;
|
|
100
|
+
/** Vectors: what the cells are called (`["x", "z"]`), their letters and accessible names. */
|
|
101
|
+
readonly axes?: readonly string[];
|
|
102
|
+
/** Angles: carry past the ends a whole turn (on for a full turn by default). */
|
|
103
|
+
readonly wrap?: boolean;
|
|
104
|
+
/** Gradients: blend in `oklab` (default) or `srgb`. */
|
|
105
|
+
readonly space?: GradientSpace;
|
|
106
|
+
/** Curves: the y range, `[0, 1]` by default (`min` and `max` work too). */
|
|
107
|
+
readonly range?: readonly [number, number];
|
|
108
|
+
/** Curves: `smooth` (monotone cubic, default), `linear` or `step`. */
|
|
109
|
+
readonly interp?: CurveInterp;
|
|
110
|
+
/** Curves: `false` hides the built-in shape chips. */
|
|
111
|
+
readonly shapes?: boolean;
|
|
112
|
+
/** Gradients and curves: named ramps or shapes offered as chips. */
|
|
113
|
+
readonly presets?: Readonly<Record<string, readonly GradientStop[] | readonly CurvePoint[]>>;
|
|
114
|
+
}
|
|
115
|
+
export interface RemoteControlsOptions {
|
|
116
|
+
readonly enabled?: boolean | (() => boolean);
|
|
117
|
+
/** Ships the panel as product UI, live in production: `() => import("knobs/panel")` (see `ControlsOptions.ship`). */
|
|
118
|
+
readonly ship?: () => Promise<PanelModule>;
|
|
119
|
+
/** How long (ms) a key changed here outranks incoming values for it; 600 by default. */
|
|
120
|
+
readonly echo?: number;
|
|
121
|
+
/**
|
|
122
|
+
* `onSet` sends `null` when a key returns to its default (and a key's reset is an `onSet` of
|
|
123
|
+
* `null` too), as the socket protocol expects. `false` sends the value itself, and resets reach
|
|
124
|
+
* only `onReset`.
|
|
125
|
+
*/
|
|
126
|
+
readonly nullDefaults?: boolean;
|
|
127
|
+
readonly values?: State;
|
|
128
|
+
readonly presets?: Readonly<Record<string, State>>;
|
|
129
|
+
/** Numbered presets per group, e.g. the phone's preset sets (see `ControlsOptions.groupPresets`). */
|
|
130
|
+
readonly groupPresets?: Readonly<Record<string, readonly GroupPreset[]>>;
|
|
131
|
+
/** Display labels by group id, section id and preset id (see `ControlsOptions.groupLabels`). */
|
|
132
|
+
readonly groupLabels?: Readonly<Record<string, string>>;
|
|
133
|
+
readonly sectionLabels?: Readonly<Record<string, string>>;
|
|
134
|
+
readonly presetLabels?: Readonly<Record<string, string>>;
|
|
135
|
+
/** Shorthand for `presetLabels.default`, e.g. "Native". */
|
|
136
|
+
readonly defaultLabel?: string;
|
|
137
|
+
/** How a page card shows its group presets (see `ControlsOptions.groupPresetDisplay`). */
|
|
138
|
+
readonly groupPresetDisplay?: GroupPresetDisplay;
|
|
139
|
+
/** One muted line under a group's card title or a section's heading on a page, by id. */
|
|
140
|
+
readonly groupDescriptions?: Readonly<Record<string, string>>;
|
|
141
|
+
readonly sectionDescriptions?: Readonly<Record<string, string>>;
|
|
142
|
+
/** How groups and a page's sections start, folded or open (see `ControlsOptions.groupFolded`). */
|
|
143
|
+
readonly groupFolded?: Readonly<Record<string, boolean>>;
|
|
144
|
+
readonly sectionFolded?: SectionFolded;
|
|
145
|
+
readonly actions?: readonly ControlAction<State>[];
|
|
146
|
+
readonly storage?: StoragePort | null;
|
|
147
|
+
/** What `storage` keeps (see `ControlsOptions.persist`). */
|
|
148
|
+
readonly persist?: PersistMode;
|
|
149
|
+
/** What Random and Mutate draw from (see `ControlsOptions.random`). */
|
|
150
|
+
readonly random?: () => number;
|
|
151
|
+
/** Whether Random and Mutate may change a key (see `ControlsOptions.tunable`). */
|
|
152
|
+
readonly tunable?: (key: string, values: State) => boolean;
|
|
153
|
+
/** An undo stack the host owns (see `HostHistory`). */
|
|
154
|
+
readonly history?: HostHistory;
|
|
155
|
+
readonly theme?: ThemeMode;
|
|
156
|
+
readonly density?: DensityMode;
|
|
157
|
+
readonly renderer?: RendererMode;
|
|
158
|
+
/** Default key bindings for its panels (see `MountPanelOptions.keys`). */
|
|
159
|
+
readonly keys?: PanelKeys;
|
|
160
|
+
/** `false`: its panels show no modified marks or resets (see `MountPanelOptions.marks`). */
|
|
161
|
+
readonly marks?: boolean;
|
|
162
|
+
readonly onSet?: (key: string, value: Value | null, meta: ChangeMeta) => void;
|
|
163
|
+
/**
|
|
164
|
+
* A change of several keys at once (a preset, Random, Mutate, resetting a selection, undoing or
|
|
165
|
+
* redoing any of them), in one call instead of an `onSet` per key. The entries are what `onSet`
|
|
166
|
+
* would have received, `null` again meaning back to the default. A change of one key still goes
|
|
167
|
+
* to `onSet`, or here as a single entry when there's no `onSet`. Resetting everything or a
|
|
168
|
+
* group stays `onReset`'s, as with `onSet`.
|
|
169
|
+
*/
|
|
170
|
+
readonly onSetBatch?: (changes: Array<{
|
|
171
|
+
key: string;
|
|
172
|
+
value: Value | null;
|
|
173
|
+
}>, meta: ChangeMeta) => void;
|
|
174
|
+
/** A key went into the hand or out of it: a drag, an inline edit, a burst of arrow keys. */
|
|
175
|
+
readonly onGesture?: (event: GestureEvent) => void;
|
|
176
|
+
/** A key, a group, or (`{}`) everything was reset. */
|
|
177
|
+
readonly onReset?: (target: {
|
|
178
|
+
key?: string;
|
|
179
|
+
group?: string;
|
|
180
|
+
}) => void;
|
|
181
|
+
/** An action row was pressed. */
|
|
182
|
+
readonly onAction?: (key: string) => void;
|
|
183
|
+
/**
|
|
184
|
+
* A group preset was chosen. When given, the peer applies its own preset (and sends back its
|
|
185
|
+
* state) instead of receiving `onSet` for each key.
|
|
186
|
+
*/
|
|
187
|
+
readonly onPreset?: (target: {
|
|
188
|
+
group: string;
|
|
189
|
+
index: number;
|
|
190
|
+
name: string;
|
|
191
|
+
}) => void;
|
|
192
|
+
}
|
|
193
|
+
export interface RemoteControls extends Controls<Schema> {
|
|
194
|
+
readonly descriptors: readonly ControlDescriptor[];
|
|
195
|
+
/**
|
|
196
|
+
* Swaps in another set of descriptors (another variation, another item) without tearing the
|
|
197
|
+
* panel down. Rows with the same key keep their DOM and spring to their new value; new rows
|
|
198
|
+
* enter and missing ones leave. `values` are the complete values (missing keys sit at their
|
|
199
|
+
* defaults), held back for any key in hand as `sync` does.
|
|
200
|
+
*
|
|
201
|
+
* Undo history starts over when the descriptors change shape or `land` is set: it belonged to
|
|
202
|
+
* the previous set. `land: true` (a different item arrived) also places every value at once,
|
|
203
|
+
* without springing or rolling. `mixed` names the keys whose values differ across a
|
|
204
|
+
* multi-selection (see `SyncOptions.mixed`).
|
|
205
|
+
*/
|
|
206
|
+
update(descriptors: readonly ControlDescriptor[], values?: State, options?: {
|
|
207
|
+
land?: boolean;
|
|
208
|
+
mixed?: readonly string[];
|
|
209
|
+
}): void;
|
|
210
|
+
swift(group?: string): string;
|
|
211
|
+
}
|
|
212
|
+
export declare function descriptorToField(d: ControlDescriptor): Field;
|
|
213
|
+
/**
|
|
214
|
+
* Converts descriptors into a schema. A spring binding becomes its two flat number fields, at the
|
|
215
|
+
* binding's place (their own descriptors, if any, give their ranges and labels).
|
|
216
|
+
*/
|
|
217
|
+
export declare function fromDescriptors(descriptors: readonly ControlDescriptor[]): Schema;
|
|
218
|
+
export declare function formatSwift(descriptors: readonly ControlDescriptor[], values: State, group?: string): string;
|
|
219
|
+
export declare function createRemoteControls(id: string, descriptors: readonly ControlDescriptor[], options?: RemoteControlsOptions): RemoteControls;
|
|
220
|
+
/** A titled section of settings, as a hosted prototype reports them (viewer.js `pv:settings`). */
|
|
221
|
+
export interface SettingsGroup {
|
|
222
|
+
readonly title?: string;
|
|
223
|
+
readonly items: readonly SettingsItem[];
|
|
224
|
+
}
|
|
225
|
+
export type SettingsItem = {
|
|
226
|
+
readonly id: string;
|
|
227
|
+
readonly label: string;
|
|
228
|
+
readonly kind: "choice";
|
|
229
|
+
readonly choices: readonly {
|
|
230
|
+
readonly id: string;
|
|
231
|
+
readonly label?: string;
|
|
232
|
+
}[];
|
|
233
|
+
readonly value?: string | null;
|
|
234
|
+
} | {
|
|
235
|
+
readonly id: string;
|
|
236
|
+
readonly label: string;
|
|
237
|
+
readonly kind: "toggle";
|
|
238
|
+
readonly value?: boolean;
|
|
239
|
+
} | {
|
|
240
|
+
readonly id: string;
|
|
241
|
+
readonly label: string;
|
|
242
|
+
readonly kind: "action";
|
|
243
|
+
readonly value?: boolean;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Settings sections as descriptors and values, one row per item: choices (a menu past four
|
|
247
|
+
* options), switches and buttons, each section's title its group.
|
|
248
|
+
*
|
|
249
|
+
* The prototype owns these values, so each setting's default is its `home`: the value the
|
|
250
|
+
* prototype first reported. Pass the first call's `values` back as `home` (merging in settings
|
|
251
|
+
* that appear later) so the shape stays put while the values move; without it, the values
|
|
252
|
+
* reported now are the defaults.
|
|
253
|
+
*/
|
|
254
|
+
export declare function fromSettings(groups: readonly SettingsGroup[], home?: State): {
|
|
255
|
+
descriptors: ControlDescriptor[];
|
|
256
|
+
values: State;
|
|
257
|
+
};
|
|
258
|
+
export {};
|