svelte-tweakpane-ui 1.0.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 +36 -0
- package/dist/control/ButtonGrid.svelte +49 -0
- package/dist/control/ButtonGrid.svelte.d.ts +190 -0
- package/dist/control/Checkbox.svelte +6 -0
- package/dist/control/Checkbox.svelte.d.ts +113 -0
- package/dist/control/Color.svelte +79 -0
- package/dist/control/Color.svelte.d.ts +177 -0
- package/dist/control/CubicBezier.svelte +74 -0
- package/dist/control/CubicBezier.svelte.d.ts +204 -0
- package/dist/control/Image.svelte +23 -0
- package/dist/control/Image.svelte.d.ts +177 -0
- package/dist/control/IntervalSlider.svelte +37 -0
- package/dist/control/IntervalSlider.svelte.d.ts +196 -0
- package/dist/control/List.svelte +69 -0
- package/dist/control/List.svelte.d.ts +122 -0
- package/dist/control/Point.svelte +100 -0
- package/dist/control/Point.svelte.d.ts +374 -0
- package/dist/control/RadioGrid.svelte +42 -0
- package/dist/control/RadioGrid.svelte.d.ts +231 -0
- package/dist/control/Ring.svelte +19 -0
- package/dist/control/Ring.svelte.d.ts +220 -0
- package/dist/control/RotationEuler.svelte +67 -0
- package/dist/control/RotationEuler.svelte.d.ts +273 -0
- package/dist/control/RotationQuaternion.svelte +65 -0
- package/dist/control/RotationQuaternion.svelte.d.ts +276 -0
- package/dist/control/Slider.svelte +6 -0
- package/dist/control/Slider.svelte.d.ts +165 -0
- package/dist/control/Text.svelte +25 -0
- package/dist/control/Text.svelte.d.ts +129 -0
- package/dist/control/Textarea.svelte +47 -0
- package/dist/control/Textarea.svelte.d.ts +149 -0
- package/dist/control/Wheel.svelte +15 -0
- package/dist/control/Wheel.svelte.d.ts +186 -0
- package/dist/core/Binding.svelte +68 -0
- package/dist/core/Binding.svelte.d.ts +116 -0
- package/dist/core/Blade.svelte +61 -0
- package/dist/core/Blade.svelte.d.ts +90 -0
- package/dist/core/Button.svelte +59 -0
- package/dist/core/Button.svelte.d.ts +65 -0
- package/dist/core/Folder.svelte +69 -0
- package/dist/core/Folder.svelte.d.ts +78 -0
- package/dist/core/Pane.svelte +51 -0
- package/dist/core/Pane.svelte.d.ts +500 -0
- package/dist/core/Separator.svelte +14 -0
- package/dist/core/Separator.svelte.d.ts +85 -0
- package/dist/core/TabGroup.svelte +64 -0
- package/dist/core/TabGroup.svelte.d.ts +72 -0
- package/dist/core/TabPage.svelte +85 -0
- package/dist/core/TabPage.svelte.d.ts +82 -0
- package/dist/extra/AutoObject.svelte +46 -0
- package/dist/extra/AutoObject.svelte.d.ts +108 -0
- package/dist/extra/AutoValue.svelte +11 -0
- package/dist/extra/AutoValue.svelte.d.ts +123 -0
- package/dist/extra/Element.svelte +53 -0
- package/dist/extra/Element.svelte.d.ts +170 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.js +39 -0
- package/dist/internal/ClsPad.svelte +34 -0
- package/dist/internal/ClsPad.svelte.d.ts +95 -0
- package/dist/internal/GenericBinding.svelte +22 -0
- package/dist/internal/GenericBinding.svelte.d.ts +116 -0
- package/dist/internal/GenericBladeFolding.svelte +38 -0
- package/dist/internal/GenericBladeFolding.svelte.d.ts +95 -0
- package/dist/internal/GenericInput.svelte +19 -0
- package/dist/internal/GenericInput.svelte.d.ts +116 -0
- package/dist/internal/GenericInputFolding.svelte +40 -0
- package/dist/internal/GenericInputFolding.svelte.d.ts +140 -0
- package/dist/internal/GenericMonitor.svelte +24 -0
- package/dist/internal/GenericMonitor.svelte.d.ts +139 -0
- package/dist/internal/GenericPane.svelte +100 -0
- package/dist/internal/GenericPane.svelte.d.ts +84 -0
- package/dist/internal/GenericSlider.svelte +27 -0
- package/dist/internal/GenericSlider.svelte.d.ts +146 -0
- package/dist/internal/InternalMonitorBoolean.svelte +17 -0
- package/dist/internal/InternalMonitorBoolean.svelte.d.ts +154 -0
- package/dist/internal/InternalMonitorNumber.svelte +31 -0
- package/dist/internal/InternalMonitorNumber.svelte.d.ts +178 -0
- package/dist/internal/InternalMonitorString.svelte +23 -0
- package/dist/internal/InternalMonitorString.svelte.d.ts +162 -0
- package/dist/internal/InternalPaneDraggable.svelte +368 -0
- package/dist/internal/InternalPaneDraggable.svelte.d.ts +178 -0
- package/dist/internal/InternalPaneFixed.svelte +28 -0
- package/dist/internal/InternalPaneFixed.svelte.d.ts +119 -0
- package/dist/internal/InternalPaneInline.svelte +29 -0
- package/dist/internal/InternalPaneInline.svelte.d.ts +106 -0
- package/dist/monitor/FpsGraph.svelte +86 -0
- package/dist/monitor/FpsGraph.svelte.d.ts +230 -0
- package/dist/monitor/Monitor.svelte +14 -0
- package/dist/monitor/Monitor.svelte.d.ts +526 -0
- package/dist/monitor/Profiler.svelte +72 -0
- package/dist/monitor/Profiler.svelte.d.ts +265 -0
- package/dist/monitor/WaveformMonitor.svelte +26 -0
- package/dist/monitor/WaveformMonitor.svelte.d.ts +176 -0
- package/dist/theme.d.ts +91 -0
- package/dist/theme.js +332 -0
- package/dist/utils.d.ts +157 -0
- package/dist/utils.js +238 -0
- package/package.json +280 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { SvelteComponent } from 'svelte';
|
|
2
|
+
import type { Simplify } from '../utils';
|
|
3
|
+
export type IntervalSliderValueTuple = [min: number, max: number];
|
|
4
|
+
export type IntervalSliderValueObject = {
|
|
5
|
+
min: number;
|
|
6
|
+
max: number;
|
|
7
|
+
};
|
|
8
|
+
export type IntervalSliderValue = Simplify<IntervalSliderValueObject | IntervalSliderValueTuple>;
|
|
9
|
+
declare const __propDef: {
|
|
10
|
+
props: Omit<
|
|
11
|
+
Omit<
|
|
12
|
+
{
|
|
13
|
+
/**
|
|
14
|
+
* The binding's target object with values to manipulate.
|
|
15
|
+
* @bindable
|
|
16
|
+
*/
|
|
17
|
+
object: import('@tweakpane/core').Bindable & {
|
|
18
|
+
[x: string]: IntervalSliderValue;
|
|
19
|
+
};
|
|
20
|
+
/** The key for the value in the target `object` that the control should manipulate. */
|
|
21
|
+
key: string | number;
|
|
22
|
+
/**
|
|
23
|
+
* Prevent interactivity and gray out the control.
|
|
24
|
+
* @default `false`
|
|
25
|
+
*/
|
|
26
|
+
disabled?: boolean | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Text displayed next to control.
|
|
29
|
+
* @default `undefined`
|
|
30
|
+
*/
|
|
31
|
+
label?: string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Tweakpane's internal options object.
|
|
34
|
+
*
|
|
35
|
+
* See [`BindingParams`](https://tweakpane.github.io/docs/api/types/BindingParams.html).
|
|
36
|
+
*
|
|
37
|
+
* Valid types are contingent on the type of the value `key` points to in `object`.
|
|
38
|
+
*
|
|
39
|
+
* This is intended internal use, when implementing convenience components wrapping Binding's
|
|
40
|
+
* functionality. Options of interest are instead exposed as top-level props in _Svelte
|
|
41
|
+
* Tweakpane UI_.
|
|
42
|
+
* @default `undefined`
|
|
43
|
+
*/
|
|
44
|
+
options?: import('tweakpane').NumberInputParams | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Custom color scheme.
|
|
47
|
+
*
|
|
48
|
+
* @default `undefined` \
|
|
49
|
+
* Inherits default Tweakpane theme equivalent to `ThemeUtils.presets.standard`, or the theme
|
|
50
|
+
* set with `setGlobalDefaultTheme()`.
|
|
51
|
+
*/
|
|
52
|
+
theme?: import('..').Theme | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Reference to internal Tweakpane
|
|
55
|
+
* [`BindingApi`](https://tweakpane.github.io/docs/api/classes/_internal_.BindingApi.html) for
|
|
56
|
+
* this control.
|
|
57
|
+
*
|
|
58
|
+
* This is primarily for internal use, when implementing convenience components wrapping
|
|
59
|
+
* Binding's functionality.
|
|
60
|
+
* @bindable
|
|
61
|
+
* @readonly
|
|
62
|
+
*/
|
|
63
|
+
ref?: import('tweakpane').SliderInputBindingApi | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Imported Tweakpane `TpPluginBundle` (aliased as `Plugin`) module to automatically register in
|
|
66
|
+
* the binding's containing `<Pane>`.
|
|
67
|
+
*
|
|
68
|
+
* This is primarily for internal use, when implementing convenience components wrapping
|
|
69
|
+
* Binding's functionality in combination with a Tweakpane plugin.
|
|
70
|
+
* @default `undefined`
|
|
71
|
+
*/
|
|
72
|
+
plugin?: import('tweakpane').TpPluginBundle | undefined;
|
|
73
|
+
},
|
|
74
|
+
'object' | 'key'
|
|
75
|
+
> & {
|
|
76
|
+
/**
|
|
77
|
+
* Interval value to control.
|
|
78
|
+
*
|
|
79
|
+
* Tuples are a convenience addition to the vanilla JS Tweakpane API.
|
|
80
|
+
* @bindable
|
|
81
|
+
*/
|
|
82
|
+
value: IntervalSliderValue;
|
|
83
|
+
} & {
|
|
84
|
+
/**
|
|
85
|
+
* Minimum value.
|
|
86
|
+
*
|
|
87
|
+
* Specifying both a `min` and a `max` prop turns the control into a slider.
|
|
88
|
+
* @default `undefined`
|
|
89
|
+
*/
|
|
90
|
+
min?: number | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Maximum value.
|
|
93
|
+
*
|
|
94
|
+
* Specifying both a `min` and a `max` prop turns the control into a slider.
|
|
95
|
+
* @default `undefined`
|
|
96
|
+
*/
|
|
97
|
+
max?: number | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* A function to customize the point value's formatting (e.g. rounding, etc.).
|
|
100
|
+
* @default `undefined` \
|
|
101
|
+
* Normal `.toString()` formatting.
|
|
102
|
+
*/
|
|
103
|
+
format?: ((value: number) => string) | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* The unit scale for key-based input for all dimensions (e.g. the up and down arrow keys).
|
|
106
|
+
* @default `1` \
|
|
107
|
+
* Or `stepValue` if defined.
|
|
108
|
+
*/
|
|
109
|
+
keyScale?: number | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* The unit scale for pointer-based input for all dimensions.
|
|
112
|
+
* @default `undefined` \
|
|
113
|
+
* [Dynamic based on magnitude of
|
|
114
|
+
* `value`](https://github.com/cocopon/tweakpane/blob/66dfbea04bfe9b7f031673c955ceda1f92356e75/packages/core/src/common/number/util.ts#L54).
|
|
115
|
+
*/
|
|
116
|
+
pointerScale?: number | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* The minimum step interval.
|
|
119
|
+
* @default `undefined` \
|
|
120
|
+
* No step constraint.
|
|
121
|
+
*/
|
|
122
|
+
step?: number | undefined;
|
|
123
|
+
},
|
|
124
|
+
'options' | 'ref' | 'plugin'
|
|
125
|
+
> & {
|
|
126
|
+
/**
|
|
127
|
+
* Interval value to control.
|
|
128
|
+
*
|
|
129
|
+
* Tuples are a convenience addition to the vanilla JS Tweakpane API.
|
|
130
|
+
* @bindable
|
|
131
|
+
*/
|
|
132
|
+
value: IntervalSliderValue;
|
|
133
|
+
/**
|
|
134
|
+
* Midpoint of the interval range value.
|
|
135
|
+
* @bindable
|
|
136
|
+
* */
|
|
137
|
+
meanValue?: number | undefined;
|
|
138
|
+
};
|
|
139
|
+
events: {
|
|
140
|
+
[evt: string]: CustomEvent<any>;
|
|
141
|
+
};
|
|
142
|
+
slots: {};
|
|
143
|
+
};
|
|
144
|
+
export type IntervalSliderProps = typeof __propDef.props;
|
|
145
|
+
export type IntervalSliderEvents = typeof __propDef.events;
|
|
146
|
+
export type IntervalSliderSlots = typeof __propDef.slots;
|
|
147
|
+
/**
|
|
148
|
+
* A twin-handled slider control for specifying range values.
|
|
149
|
+
*
|
|
150
|
+
* Integrates the [Interval](https://github.com/tweakpane/plugin-essentials#interval) control from
|
|
151
|
+
* Tweakpane-creator [Hiroki Kokubun's](https://cocopon.me) [Essentials
|
|
152
|
+
* plugin](https://github.com/tweakpane/plugin-essentials).
|
|
153
|
+
*
|
|
154
|
+
* _Svelte Tweakpane UI_ extends the original implementation to by supporting tuple values in addition
|
|
155
|
+
* to object values. It also exposes a `meanValue` prop for reading or setting the midpoint of the
|
|
156
|
+
* interval range value.
|
|
157
|
+
*
|
|
158
|
+
* Usage outside of a `<Pane>` component will implicitly wrap the interval slider in `<Pane
|
|
159
|
+
* position='inline'>`.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```svelte
|
|
163
|
+
* <script lang="ts">
|
|
164
|
+
* import { IntervalSlider } from 'svelte-tweakpane-ui';
|
|
165
|
+
*
|
|
166
|
+
* // Could specify convenience type IntervalSliderValueTuple here, or
|
|
167
|
+
* // use the object {start: number, end: number} instead of a tuple
|
|
168
|
+
* let value: [number, number] = [25, 75];
|
|
169
|
+
* </script>
|
|
170
|
+
*
|
|
171
|
+
* <IntervalSlider
|
|
172
|
+
* bind:value
|
|
173
|
+
* min={0}
|
|
174
|
+
* max={100}
|
|
175
|
+
* format={(v) => `${v.toFixed(0)}%`}
|
|
176
|
+
* />
|
|
177
|
+
* <div class="demo" style:--e="{value[1]}%" style:--s="{value[0]}%" />
|
|
178
|
+
*
|
|
179
|
+
* <style>
|
|
180
|
+
* div.demo {
|
|
181
|
+
* aspect-ratio: 1;
|
|
182
|
+
* width: 100%;
|
|
183
|
+
* background: linear-gradient(45deg, magenta var(--s), orange var(--e));
|
|
184
|
+
* }
|
|
185
|
+
* </style>
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @sourceLink
|
|
189
|
+
* [IntervalSlider.svelte](https://github.com/kitschpatrol/svelte-tweakpane-ui/blob/main/src/lib/control/IntervalSlider.svelte)
|
|
190
|
+
*/
|
|
191
|
+
export default class IntervalSlider extends SvelteComponent<
|
|
192
|
+
IntervalSliderProps,
|
|
193
|
+
IntervalSliderEvents,
|
|
194
|
+
IntervalSliderSlots
|
|
195
|
+
> {}
|
|
196
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script context="module"></script>
|
|
2
|
+
|
|
3
|
+
<script generics="T extends any">
|
|
4
|
+
import Blade from '../core/Blade.svelte';
|
|
5
|
+
import ClsPad from '../internal/ClsPad.svelte';
|
|
6
|
+
import { BROWSER } from 'esm-env';
|
|
7
|
+
export let value;
|
|
8
|
+
export let options;
|
|
9
|
+
export let label = void 0;
|
|
10
|
+
let listBlade;
|
|
11
|
+
let bladeOptions;
|
|
12
|
+
function addEvent() {
|
|
13
|
+
listBlade.on('change', (ev) => {
|
|
14
|
+
value = ev.value;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function getInitialValue() {
|
|
18
|
+
if (value === void 0) {
|
|
19
|
+
const internalOptions = getInternalOptions(options);
|
|
20
|
+
if (Array.isArray(internalOptions)) {
|
|
21
|
+
value = internalOptions[0].value;
|
|
22
|
+
return value;
|
|
23
|
+
} else {
|
|
24
|
+
value = internalOptions[Object.keys(internalOptions)[0]];
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function isArrayStyleListOptions(obj) {
|
|
32
|
+
return (
|
|
33
|
+
Array.isArray(obj) &&
|
|
34
|
+
obj.every(
|
|
35
|
+
(item) => typeof item === 'object' && item !== null && 'text' in item && 'value' in item
|
|
36
|
+
)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
function isObjectStyleListOptions(obj) {
|
|
40
|
+
return typeof obj === 'object' && obj !== null && !Array.isArray(obj);
|
|
41
|
+
}
|
|
42
|
+
function getInternalOptions(options2) {
|
|
43
|
+
if (isArrayStyleListOptions(options2)) {
|
|
44
|
+
return options2;
|
|
45
|
+
} else if (isObjectStyleListOptions(options2)) {
|
|
46
|
+
return options2;
|
|
47
|
+
} else {
|
|
48
|
+
return options2.map((value2) => {
|
|
49
|
+
return { value: value2, text: JSON.stringify(value2) };
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function setValue() {
|
|
54
|
+
listBlade.value = value;
|
|
55
|
+
}
|
|
56
|
+
$: bladeOptions = {
|
|
57
|
+
value: getInitialValue(),
|
|
58
|
+
label,
|
|
59
|
+
options: getInternalOptions(options),
|
|
60
|
+
view: 'list'
|
|
61
|
+
};
|
|
62
|
+
$: listBlade && addEvent();
|
|
63
|
+
$: value, listBlade && setValue();
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<Blade bind:ref={listBlade} options={bladeOptions} {...$$restProps} />
|
|
67
|
+
{#if !BROWSER}
|
|
68
|
+
<ClsPad keysAdd={['containerUnitSize']} theme={$$props.theme} />
|
|
69
|
+
{/if}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { SvelteComponent } from 'svelte';
|
|
2
|
+
import type { Simplify } from '../utils';
|
|
3
|
+
export type ListOptionsArray<T> = T[];
|
|
4
|
+
export type ListOptionsObjectArray<T> = {
|
|
5
|
+
value: T;
|
|
6
|
+
text: string;
|
|
7
|
+
}[];
|
|
8
|
+
export type ListOptionsRecord<T> = {
|
|
9
|
+
[text: string]: T;
|
|
10
|
+
};
|
|
11
|
+
export type ListOptions<T> = Simplify<
|
|
12
|
+
ListOptionsArray<T> | ListOptionsObjectArray<T> | ListOptionsRecord<T>
|
|
13
|
+
>;
|
|
14
|
+
import type { ListBladeApi, ListBladeParams } from 'tweakpane';
|
|
15
|
+
declare class __sveltets_Render<T extends any> {
|
|
16
|
+
props(): Omit<
|
|
17
|
+
{
|
|
18
|
+
/**
|
|
19
|
+
* A collection of options to select from.
|
|
20
|
+
*
|
|
21
|
+
* The arbitrary array list type is a convenience addition to to the vanilla JS Tweakpane
|
|
22
|
+
* API.
|
|
23
|
+
*/
|
|
24
|
+
options: ListBladeParams<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Prevent interactivity and gray out the control.
|
|
27
|
+
* @default `false`
|
|
28
|
+
*/
|
|
29
|
+
disabled?: boolean | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Custom color scheme.
|
|
32
|
+
* @default `undefined` \
|
|
33
|
+
* Inherits default Tweakpane theme equivalent to `ThemeUtils.presets.standard`, or the theme
|
|
34
|
+
* set with `setGlobalDefaultTheme()`.
|
|
35
|
+
*/
|
|
36
|
+
theme?: import('..').Theme | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Reference to internal Tweakpane
|
|
39
|
+
* [`BladeApi`](https://tweakpane.github.io/docs/api/classes/BladeApi.html) for this blade.
|
|
40
|
+
*
|
|
41
|
+
* This is primarily for internal use, when implementing convenience components wrapping Blade's
|
|
42
|
+
* functionality.
|
|
43
|
+
* @bindable
|
|
44
|
+
* @readonly
|
|
45
|
+
*/
|
|
46
|
+
ref?: ListBladeApi<T> | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Imported Tweakpane `TpPluginBundle` (Aliased as `Plugin`) module to register before creating
|
|
49
|
+
* the blade.
|
|
50
|
+
*
|
|
51
|
+
* This is primarily for internal use, when implementing convenience components wrapping Blade's
|
|
52
|
+
* functionality in combination with a Tweakpane plugin.
|
|
53
|
+
* @default `undefined`
|
|
54
|
+
*/
|
|
55
|
+
plugin?: import('tweakpane').TpPluginBundle | undefined;
|
|
56
|
+
},
|
|
57
|
+
'options' | 'ref' | 'plugin'
|
|
58
|
+
> & {
|
|
59
|
+
/**
|
|
60
|
+
* Value of the selected `options` item.
|
|
61
|
+
* @bindable
|
|
62
|
+
* */
|
|
63
|
+
value: T;
|
|
64
|
+
/**
|
|
65
|
+
* Text displayed next to list.
|
|
66
|
+
* @default `undefined`
|
|
67
|
+
* */
|
|
68
|
+
label?: string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* A collection of options to select from.
|
|
71
|
+
*
|
|
72
|
+
* The arbitrary array list type is a convenience addition to to the vanilla JS Tweakpane
|
|
73
|
+
* API.
|
|
74
|
+
* */
|
|
75
|
+
options: ListOptions<T>;
|
|
76
|
+
};
|
|
77
|
+
events(): {} & {
|
|
78
|
+
[evt: string]: CustomEvent<any>;
|
|
79
|
+
};
|
|
80
|
+
slots(): {};
|
|
81
|
+
}
|
|
82
|
+
export type ListProps<T extends any> = ReturnType<__sveltets_Render<T>['props']>;
|
|
83
|
+
export type ListEvents<T extends any> = ReturnType<__sveltets_Render<T>['events']>;
|
|
84
|
+
export type ListSlots<T extends any> = ReturnType<__sveltets_Render<T>['slots']>;
|
|
85
|
+
/**
|
|
86
|
+
* An option list picker, similar to an HTML `<select>` element.
|
|
87
|
+
*
|
|
88
|
+
* Wraps Tweakpane's list blade. See Tweakpane's documentation for [list
|
|
89
|
+
* blades](https://tweakpane.github.io/docs/blades/#list).
|
|
90
|
+
*
|
|
91
|
+
* _Svelte Tweakpane UI_ extends Tweakpane's underlying implementation to allow for arbitrary arrays of
|
|
92
|
+
* values to be used as options. See the `ListOptions` type for details on how to provide specific
|
|
93
|
+
* labels to options.
|
|
94
|
+
*
|
|
95
|
+
* Tweakpane's `addBlade` list variations is used instead of the `addBinding` method to allow for
|
|
96
|
+
* additional value types. The `value` remains bindable via Svelte's reactivity.
|
|
97
|
+
*
|
|
98
|
+
* Usage outside of a `<Pane>` component will implicitly wrap the color picker in `<Pane
|
|
99
|
+
* position='inline'>`.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```svelte
|
|
103
|
+
* <script lang="ts">
|
|
104
|
+
* import { List, type ListOptions } from 'svelte-tweakpane-ui';
|
|
105
|
+
*
|
|
106
|
+
* const options: ListOptions<number> = { b: 2, a: 1, c: 3 };
|
|
107
|
+
* let selection: number = 1;
|
|
108
|
+
* </script>
|
|
109
|
+
*
|
|
110
|
+
* <List bind:value={selection} label="Alphanumerics" {options} />
|
|
111
|
+
* <pre>Selected Option: {selection}</pre>
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @sourceLink
|
|
115
|
+
* [List.svelte](https://github.com/kitschpatrol/svelte-tweakpane-ui/blob/main/src/lib/control/List.svelte)
|
|
116
|
+
*/
|
|
117
|
+
export default class List<T extends any> extends SvelteComponent<
|
|
118
|
+
ListProps<T>,
|
|
119
|
+
ListEvents<T>,
|
|
120
|
+
ListSlots<T>
|
|
121
|
+
> {}
|
|
122
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
<script context="module"></script>
|
|
2
|
+
|
|
3
|
+
<script generics="T extends PointValue2d | PointValue3d | PointValue4d">
|
|
4
|
+
import ClsPad from '../internal/ClsPad.svelte';
|
|
5
|
+
import GenericInputFolding from '../internal/GenericInputFolding.svelte';
|
|
6
|
+
import { removeKeys } from '../utils';
|
|
7
|
+
import { BROWSER } from 'esm-env';
|
|
8
|
+
export let value;
|
|
9
|
+
export let expanded = $$props.expanded ?? void 0;
|
|
10
|
+
let pointerScale = $$props['pointerScale'] ?? void 0;
|
|
11
|
+
let keyScale = $$props['keyScale'] ?? void 0;
|
|
12
|
+
let min = $$props['min'] ?? void 0;
|
|
13
|
+
let max = $$props['max'] ?? void 0;
|
|
14
|
+
let step = $$props['step'] ?? void 0;
|
|
15
|
+
let optionsX = $$props['optionsX'] ?? void 0;
|
|
16
|
+
let optionsY = $$props['optionsY'] ?? void 0;
|
|
17
|
+
let optionsZ = $$props['optionsZ'] ?? void 0;
|
|
18
|
+
let optionsW = $$props['optionsW'] ?? void 0;
|
|
19
|
+
let format = $$props['format'] ?? void 0;
|
|
20
|
+
let internalValue;
|
|
21
|
+
let options;
|
|
22
|
+
const buttonClass = 'tp-p2dv_b';
|
|
23
|
+
function updateInternalValue() {
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
if (value.length === 4) {
|
|
26
|
+
const [x, y, z, w] = value;
|
|
27
|
+
internalValue = { x, y, z, w };
|
|
28
|
+
} else if (value.length === 3) {
|
|
29
|
+
const [x, y, z] = value;
|
|
30
|
+
internalValue = { x, y, z };
|
|
31
|
+
} else {
|
|
32
|
+
const [x, y] = value;
|
|
33
|
+
internalValue = { x, y };
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
internalValue = value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function updateValue() {
|
|
40
|
+
if (Array.isArray(value)) {
|
|
41
|
+
if ('w' in internalValue) {
|
|
42
|
+
const { x, y, z, w } = internalValue;
|
|
43
|
+
value = [x, y, z, w];
|
|
44
|
+
} else if ('z' in internalValue) {
|
|
45
|
+
const { x, y, z } = internalValue;
|
|
46
|
+
value = [x, y, z];
|
|
47
|
+
} else {
|
|
48
|
+
const { x, y } = internalValue;
|
|
49
|
+
value = [x, y];
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
value = internalValue;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
$: value, updateInternalValue();
|
|
56
|
+
$: internalValue, updateValue();
|
|
57
|
+
$: options = {
|
|
58
|
+
x: optionsX,
|
|
59
|
+
y: optionsY,
|
|
60
|
+
z: optionsZ,
|
|
61
|
+
w: optionsW,
|
|
62
|
+
min,
|
|
63
|
+
max,
|
|
64
|
+
format,
|
|
65
|
+
keyScale,
|
|
66
|
+
pointerScale,
|
|
67
|
+
step
|
|
68
|
+
};
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<GenericInputFolding
|
|
72
|
+
bind:value={internalValue}
|
|
73
|
+
bind:expanded
|
|
74
|
+
{buttonClass}
|
|
75
|
+
{options}
|
|
76
|
+
{...removeKeys(
|
|
77
|
+
$$restProps,
|
|
78
|
+
...Object.keys(options),
|
|
79
|
+
'optionsX',
|
|
80
|
+
'optionsY',
|
|
81
|
+
'optionsZ',
|
|
82
|
+
'optionsW'
|
|
83
|
+
)}
|
|
84
|
+
/>
|
|
85
|
+
{#if !BROWSER && !('z' in internalValue)}
|
|
86
|
+
<!-- 2D points only -->
|
|
87
|
+
{#if expanded && $$props.picker === 'inline'}
|
|
88
|
+
{#if $$props.label !== undefined}
|
|
89
|
+
<ClsPad
|
|
90
|
+
keysAdd={['bladeValueWidth']}
|
|
91
|
+
keysSubtract={[`containerUnitSize`]}
|
|
92
|
+
theme={$$props.theme}
|
|
93
|
+
/>
|
|
94
|
+
{:else}
|
|
95
|
+
<!-- Without a label, the grid takes the full width of the control -->
|
|
96
|
+
<!-- TODO remove magic number -->
|
|
97
|
+
<div style="aspect-ratio: 1; width: calc(100% - 28px);" />
|
|
98
|
+
{/if}
|
|
99
|
+
{/if}
|
|
100
|
+
{/if}
|