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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Eric Mika
|
|
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,36 @@
|
|
|
1
|
+
# svelte-tweakpane-ui
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
🎛️ **_Svelte Tweakpane UI_** wraps user-interface elements from the excellent [Tweakpane](https://cocopon.github.io/tweakpane/) library in a collection of 31 idiomatic, reactive, type-safe, carefully-crafted [Svelte](https://svelte.dev) components.
|
|
6
|
+
|
|
7
|
+
The library makes it easy to quickly and declaratively add knobs and dials to your projects using components that feel like they belong in the DOM. It also augments Tweakpane with a few [extra features](https://kitschpatrol.com/svelte-tweakpane-ui/docs/features) for your convenience and enjoyment.
|
|
8
|
+
|
|
9
|
+
[The components](https://kitschpatrol.com/svelte-tweakpane-ui/docs#components) should be useful for integrating controls and value monitoring in parametrically driven artworks or simulations.
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
**_Please see the documentation site for much more information:_**
|
|
14
|
+
**[https://kitschpatrol.com/svelte-tweakpane-ui](https://kitschpatrol.com/svelte-tweakpane-ui)**
|
|
15
|
+
|
|
16
|
+
## Quick start
|
|
17
|
+
|
|
18
|
+
1. Add _Svelte Tweakpane UI_ to your Svelte project:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm install svelte-tweakpane-ui
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
2. Import and use Tweakpane components in your `.svelte` files:
|
|
25
|
+
|
|
26
|
+
```svelte
|
|
27
|
+
<script lang="ts">
|
|
28
|
+
import { Button } from 'svelte-tweakpane-ui';
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<Button on:click={() => alert('Hi from STUI')} />
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
_Note: This library is not to be confused with Karl Moore's [`svelte-tweakpane`](https://github.com/pierogis/svelte-tweakpane)._
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<script context="module"></script>
|
|
2
|
+
|
|
3
|
+
<script>
|
|
4
|
+
import * as pluginModule from '@tweakpane/plugin-essentials';
|
|
5
|
+
import Blade from '../core/Blade.svelte';
|
|
6
|
+
import ClsPad from '../internal/ClsPad.svelte';
|
|
7
|
+
import { fillWith } from '../utils';
|
|
8
|
+
import { getGridDimensions } from '../utils.js';
|
|
9
|
+
import { BROWSER } from 'esm-env';
|
|
10
|
+
import { createEventDispatcher } from 'svelte';
|
|
11
|
+
export let columns = void 0;
|
|
12
|
+
export let rows = void 0;
|
|
13
|
+
export let buttons = [];
|
|
14
|
+
export let label = void 0;
|
|
15
|
+
const dispatch = createEventDispatcher();
|
|
16
|
+
let options;
|
|
17
|
+
let gridBlade;
|
|
18
|
+
let gridDimensions;
|
|
19
|
+
function cells(x, y) {
|
|
20
|
+
const index = y * gridDimensions.columns + x;
|
|
21
|
+
if (index >= 0 && index < buttons.length) {
|
|
22
|
+
return {
|
|
23
|
+
title: `${buttons[index]}`
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return { title: '' };
|
|
27
|
+
}
|
|
28
|
+
$: gridDimensions = getGridDimensions(buttons.length, columns, rows);
|
|
29
|
+
$: options = {
|
|
30
|
+
cells,
|
|
31
|
+
label,
|
|
32
|
+
size: [gridDimensions.columns, gridDimensions.rows],
|
|
33
|
+
view: 'buttongrid'
|
|
34
|
+
};
|
|
35
|
+
$: gridBlade &&
|
|
36
|
+
gridBlade.on('click', (ev) => {
|
|
37
|
+
dispatch('click', {
|
|
38
|
+
cell: { x: ev.index[0], y: ev.index[1] },
|
|
39
|
+
index: ev.index[1] * gridDimensions.columns + ev.index[0],
|
|
40
|
+
label: ev.cell.title
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<Blade bind:ref={gridBlade} {options} plugin={pluginModule} {...$$restProps} />
|
|
46
|
+
{#if !BROWSER}
|
|
47
|
+
<ClsPad keysAdd={fillWith('containerUnitSize', gridDimensions.rows)} theme={$$props.theme} />
|
|
48
|
+
<ClsPad keysAdd={fillWith('containerVerticalPadding', 2)} theme={$$props.theme} />
|
|
49
|
+
{/if}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { SvelteComponent } from 'svelte';
|
|
2
|
+
export type ButtonGridClickEvent = CustomEvent<{
|
|
3
|
+
cell: {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
index: number;
|
|
8
|
+
label: string;
|
|
9
|
+
}>;
|
|
10
|
+
import type { ButtonGridApi as ButtonGridRef } from '@tweakpane/plugin-essentials';
|
|
11
|
+
import type { ButtonGridBladeParams as ButtonGridOptions } from '@tweakpane/plugin-essentials/dist/types/button-grid/plugin.d.ts';
|
|
12
|
+
declare const __propDef: {
|
|
13
|
+
props: Omit<
|
|
14
|
+
{
|
|
15
|
+
/**
|
|
16
|
+
* Blade configuration exposing Tweakpane's internal
|
|
17
|
+
* [`BladeParams`](https://tweakpane.github.io/docs/api/interfaces/BaseBladeParams.html).
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
options: ButtonGridOptions;
|
|
21
|
+
/**
|
|
22
|
+
* Prevent interactivity and gray out the control.
|
|
23
|
+
* @default `false`
|
|
24
|
+
*/
|
|
25
|
+
disabled?: boolean | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Custom color scheme.
|
|
28
|
+
* @default `undefined` \
|
|
29
|
+
* Inherits default Tweakpane theme equivalent to `ThemeUtils.presets.standard`, or the theme
|
|
30
|
+
* set with `setGlobalDefaultTheme()`.
|
|
31
|
+
*/
|
|
32
|
+
theme?: import('..').Theme | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Reference to internal Tweakpane
|
|
35
|
+
* [`BladeApi`](https://tweakpane.github.io/docs/api/classes/BladeApi.html) for this blade.
|
|
36
|
+
*
|
|
37
|
+
* This is primarily for internal use, when implementing convenience components wrapping Blade's
|
|
38
|
+
* functionality.
|
|
39
|
+
* @bindable
|
|
40
|
+
* @readonly
|
|
41
|
+
*/
|
|
42
|
+
ref?: ButtonGridRef | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Imported Tweakpane `TpPluginBundle` (Aliased as `Plugin`) module to register before creating
|
|
45
|
+
* the blade.
|
|
46
|
+
*
|
|
47
|
+
* This is primarily for internal use, when implementing convenience components wrapping Blade's
|
|
48
|
+
* functionality in combination with a Tweakpane plugin.
|
|
49
|
+
* @default `undefined`
|
|
50
|
+
*/
|
|
51
|
+
plugin?: import('tweakpane').TpPluginBundle | undefined;
|
|
52
|
+
},
|
|
53
|
+
'options' | 'ref' | 'plugin'
|
|
54
|
+
> & {
|
|
55
|
+
/**
|
|
56
|
+
* Array of names, each of which will become the title of a button in the grid.
|
|
57
|
+
* */
|
|
58
|
+
buttons: string[];
|
|
59
|
+
/**
|
|
60
|
+
* Number of columns to arrange the buttons into.
|
|
61
|
+
*
|
|
62
|
+
* Setting `columns` without setting `rows` will lock the column count and allow the row
|
|
63
|
+
* count to change dynamically based on the number of buttons.
|
|
64
|
+
* @default `undefined` \
|
|
65
|
+
* Dynamic based on quantity of `buttons`.
|
|
66
|
+
* */
|
|
67
|
+
columns?: number | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Text displayed next to the button grid.
|
|
70
|
+
* @default `undefined`
|
|
71
|
+
*/
|
|
72
|
+
label?: string | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Number of rows to arrange the buttons into.
|
|
75
|
+
*
|
|
76
|
+
* Setting `rows` without setting `columns` will lock the column count and allow the column
|
|
77
|
+
* count to change dynamically based on the number of buttons.
|
|
78
|
+
* @default `undefined` \
|
|
79
|
+
* Dynamic based on quantity of `buttons`.
|
|
80
|
+
* */
|
|
81
|
+
rows?: number | undefined;
|
|
82
|
+
};
|
|
83
|
+
slots: {};
|
|
84
|
+
events: {
|
|
85
|
+
/**
|
|
86
|
+
* Fires when a button is clicked.
|
|
87
|
+
*
|
|
88
|
+
* Note that the values described in the `ButtonGridClickEvent` type are available on the
|
|
89
|
+
* `event.detail` parameter.
|
|
90
|
+
* @event
|
|
91
|
+
* */
|
|
92
|
+
click: ButtonGridClickEvent;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
export type ButtonGridProps = typeof __propDef.props;
|
|
96
|
+
export type ButtonGridEvents = typeof __propDef.events;
|
|
97
|
+
export type ButtonGridSlots = typeof __propDef.slots;
|
|
98
|
+
/**
|
|
99
|
+
* A grid of `<Button>` components.
|
|
100
|
+
*
|
|
101
|
+
* Integrates the [Button Grid](https://github.com/tweakpane/plugin-essentials#button-grid) control
|
|
102
|
+
* from Tweakpane-creator [Hiroki Kokubun's](https://cocopon.me) [Essentials
|
|
103
|
+
* plugin](https://github.com/tweakpane/plugin-essentials).
|
|
104
|
+
*
|
|
105
|
+
* See `<RadioGrid>` for a radio-flavored variation.
|
|
106
|
+
*
|
|
107
|
+
* _Svelte Tweakpane UI_ also includes some additional logic to manage default grid dimensions:
|
|
108
|
+
*
|
|
109
|
+
* - If no `rows` or `columns` props are provided, it will create a grid with the squarest possible aspect ratio for the given quantity of `values`.
|
|
110
|
+
*
|
|
111
|
+
* - If a single `rows` or `columns` prop is provided, it lets the undefined axis grow / shrink as needed to accommodate the quantity of `values`.
|
|
112
|
+
*
|
|
113
|
+
* - If both `rows` _and_ `columns` props area provided, then buttons may be clipped if `rows * columns < values.length`.
|
|
114
|
+
*
|
|
115
|
+
* @emits {ButtonGridClickEvent} click - When a button in the grid is clicked.
|
|
116
|
+
*
|
|
117
|
+
* Usage outside of a `<Pane>` component will implicitly wrap the button grid in `<Pane
|
|
118
|
+
* position='inline'>`.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```svelte
|
|
122
|
+
* <script lang="ts">
|
|
123
|
+
* import {
|
|
124
|
+
* Button,
|
|
125
|
+
* ButtonGrid,
|
|
126
|
+
* type ButtonGridClickEvent,
|
|
127
|
+
* Pane
|
|
128
|
+
* } from 'svelte-tweakpane-ui';
|
|
129
|
+
*
|
|
130
|
+
* const keyboard = [
|
|
131
|
+
* ...Array.from({ length: 26 }, (_, i) => String.fromCharCode(65 + i)),
|
|
132
|
+
* ',',
|
|
133
|
+
* '.',
|
|
134
|
+
* '!',
|
|
135
|
+
* '⌫'
|
|
136
|
+
* ];
|
|
137
|
+
*
|
|
138
|
+
* let textBuffer = '';
|
|
139
|
+
*
|
|
140
|
+
* function handleClick(e: ButtonGridClickEvent) {
|
|
141
|
+
* textBuffer =
|
|
142
|
+
* e.detail.label === '⌫'
|
|
143
|
+
* ? textBuffer.slice(0, -1)
|
|
144
|
+
* : textBuffer + e.detail.label;
|
|
145
|
+
* }
|
|
146
|
+
* </script>
|
|
147
|
+
*
|
|
148
|
+
* <Pane position="inline" title="Austerity Keyboard">
|
|
149
|
+
* <ButtonGrid on:click={handleClick} buttons={keyboard} />
|
|
150
|
+
* <Button on:click={() => (textBuffer += '\u2002')} title=" " />
|
|
151
|
+
* </Pane>
|
|
152
|
+
*
|
|
153
|
+
* <div class="demo">
|
|
154
|
+
* <p>{textBuffer}</p>
|
|
155
|
+
* </div>
|
|
156
|
+
*
|
|
157
|
+
* <style>
|
|
158
|
+
* .demo {
|
|
159
|
+
* aspect-ratio: 1;
|
|
160
|
+
* width: 100%;
|
|
161
|
+
* background: linear-gradient(45deg, orange, magenta);
|
|
162
|
+
* }
|
|
163
|
+
*
|
|
164
|
+
* .demo > p {
|
|
165
|
+
* margin: 0;
|
|
166
|
+
* padding: 0.5rem;
|
|
167
|
+
* font-family: monospace;
|
|
168
|
+
* font-size: 2rem;
|
|
169
|
+
* line-height: 1.2;
|
|
170
|
+
* color: white;
|
|
171
|
+
* word-break: break-all;
|
|
172
|
+
* white-space: pre-wrap;
|
|
173
|
+
* }
|
|
174
|
+
*
|
|
175
|
+
* .demo > p::after {
|
|
176
|
+
* content: '_';
|
|
177
|
+
* opacity: 0.5;
|
|
178
|
+
* }
|
|
179
|
+
* </style>
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
* @sourceLink
|
|
183
|
+
* [ButtonGrid.svelte](https://github.com/kitschpatrol/svelte-tweakpane-ui/blob/main/src/lib/control/ButtonGrid.svelte)
|
|
184
|
+
*/
|
|
185
|
+
export default class ButtonGrid extends SvelteComponent<
|
|
186
|
+
ButtonGridProps,
|
|
187
|
+
ButtonGridEvents,
|
|
188
|
+
ButtonGridSlots
|
|
189
|
+
> {}
|
|
190
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { SvelteComponent } from 'svelte';
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: Omit<
|
|
4
|
+
Omit<
|
|
5
|
+
{
|
|
6
|
+
/**
|
|
7
|
+
* The binding's target object with values to manipulate.
|
|
8
|
+
* @bindable
|
|
9
|
+
*/
|
|
10
|
+
object: import('@tweakpane/core').Bindable & {
|
|
11
|
+
[x: string]: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** The key for the value in the target `object` that the control should manipulate. */
|
|
14
|
+
key: string | number;
|
|
15
|
+
/**
|
|
16
|
+
* Prevent interactivity and gray out the control.
|
|
17
|
+
* @default `false`
|
|
18
|
+
*/
|
|
19
|
+
disabled?: boolean | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Text displayed next to control.
|
|
22
|
+
* @default `undefined`
|
|
23
|
+
*/
|
|
24
|
+
label?: string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Tweakpane's internal options object.
|
|
27
|
+
*
|
|
28
|
+
* See [`BindingParams`](https://tweakpane.github.io/docs/api/types/BindingParams.html).
|
|
29
|
+
*
|
|
30
|
+
* Valid types are contingent on the type of the value `key` points to in `object`.
|
|
31
|
+
*
|
|
32
|
+
* This is intended internal use, when implementing convenience components wrapping Binding's
|
|
33
|
+
* functionality. Options of interest are instead exposed as top-level props in _Svelte
|
|
34
|
+
* Tweakpane UI_.
|
|
35
|
+
* @default `undefined`
|
|
36
|
+
*/
|
|
37
|
+
options?: import('@tweakpane/core').BaseInputParams | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Custom color scheme.
|
|
40
|
+
*
|
|
41
|
+
* @default `undefined` \
|
|
42
|
+
* Inherits default Tweakpane theme equivalent to `ThemeUtils.presets.standard`, or the theme
|
|
43
|
+
* set with `setGlobalDefaultTheme()`.
|
|
44
|
+
*/
|
|
45
|
+
theme?: import('..').Theme | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Reference to internal Tweakpane
|
|
48
|
+
* [`BindingApi`](https://tweakpane.github.io/docs/api/classes/_internal_.BindingApi.html) for
|
|
49
|
+
* this control.
|
|
50
|
+
*
|
|
51
|
+
* This is primarily for internal use, when implementing convenience components wrapping
|
|
52
|
+
* Binding's functionality.
|
|
53
|
+
* @bindable
|
|
54
|
+
* @readonly
|
|
55
|
+
*/
|
|
56
|
+
ref?: import('../internal/GenericInput.svelte').GenericInputRef | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Imported Tweakpane `TpPluginBundle` (aliased as `Plugin`) module to automatically register in
|
|
59
|
+
* the binding's containing `<Pane>`.
|
|
60
|
+
*
|
|
61
|
+
* This is primarily for internal use, when implementing convenience components wrapping
|
|
62
|
+
* Binding's functionality in combination with a Tweakpane plugin.
|
|
63
|
+
* @default `undefined`
|
|
64
|
+
*/
|
|
65
|
+
plugin?: import('tweakpane').TpPluginBundle | undefined;
|
|
66
|
+
},
|
|
67
|
+
'object' | 'key'
|
|
68
|
+
> & {
|
|
69
|
+
/**
|
|
70
|
+
* The value to control.
|
|
71
|
+
* @bindable
|
|
72
|
+
*/
|
|
73
|
+
value: boolean;
|
|
74
|
+
},
|
|
75
|
+
'options' | 'ref' | 'plugin'
|
|
76
|
+
>;
|
|
77
|
+
events: {
|
|
78
|
+
[evt: string]: CustomEvent<any>;
|
|
79
|
+
};
|
|
80
|
+
slots: {};
|
|
81
|
+
};
|
|
82
|
+
export type CheckboxProps = typeof __propDef.props;
|
|
83
|
+
export type CheckboxEvents = typeof __propDef.events;
|
|
84
|
+
export type CheckboxSlots = typeof __propDef.slots;
|
|
85
|
+
/**
|
|
86
|
+
* A checkbox.
|
|
87
|
+
*
|
|
88
|
+
* Wraps Tweakpane's [boolean input binding](https://tweakpane.github.io/docs/input-bindings/#boolean).
|
|
89
|
+
*
|
|
90
|
+
* Usage outside of a `<Pane>` component will implicitly wrap the checkbox in `<Pane
|
|
91
|
+
* position='inline'>`.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```svelte
|
|
95
|
+
* <script lang="ts">
|
|
96
|
+
* import { Checkbox } from 'svelte-tweakpane-ui';
|
|
97
|
+
*
|
|
98
|
+
* let reticulationEnabled: boolean = false;
|
|
99
|
+
* </script>
|
|
100
|
+
*
|
|
101
|
+
* <Checkbox bind:value={reticulationEnabled} label="Reticulation" />
|
|
102
|
+
* <pre>Enabled: {reticulationEnabled}</pre>
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @sourceLink
|
|
106
|
+
* [Checkbox.svelte](https://github.com/kitschpatrol/svelte-tweakpane-ui/blob/main/src/lib/control/Checkbox.svelte)
|
|
107
|
+
*/
|
|
108
|
+
export default class Checkbox extends SvelteComponent<
|
|
109
|
+
CheckboxProps,
|
|
110
|
+
CheckboxEvents,
|
|
111
|
+
CheckboxSlots
|
|
112
|
+
> {}
|
|
113
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<script context="module"></script>
|
|
2
|
+
|
|
3
|
+
<script>
|
|
4
|
+
import { isColorObject, isObject, isRgbColorObject, isRgbaColorObject } from '@tweakpane/core';
|
|
5
|
+
import ClsPad from '../internal/ClsPad.svelte';
|
|
6
|
+
import GenericInputFolding from '../internal/GenericInputFolding.svelte';
|
|
7
|
+
import { objectToTuple, tupleToObject } from '../utils';
|
|
8
|
+
import { fillWith } from '../utils';
|
|
9
|
+
import { BROWSER } from 'esm-env';
|
|
10
|
+
export let value;
|
|
11
|
+
export let expanded = void 0;
|
|
12
|
+
export let type = void 0;
|
|
13
|
+
let internalValue;
|
|
14
|
+
let options;
|
|
15
|
+
let ref;
|
|
16
|
+
const buttonClass = 'tp-colswv_b';
|
|
17
|
+
function updateInternalValue() {
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
if (value.length === 4) {
|
|
20
|
+
internalValue = tupleToObject(value, ['r', 'g', 'b', 'a']);
|
|
21
|
+
} else if (value.length === 3) {
|
|
22
|
+
internalValue = tupleToObject(value, ['r', 'g', 'b']);
|
|
23
|
+
} else {
|
|
24
|
+
console.error('Unreachable');
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
internalValue = value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function updateValue() {
|
|
31
|
+
if (Array.isArray(value) && isColorObject(internalValue)) {
|
|
32
|
+
if (isRgbaColorObject(internalValue)) {
|
|
33
|
+
value = objectToTuple(internalValue, ['r', 'g', 'b', 'a']);
|
|
34
|
+
} else if (isRgbColorObject(internalValue)) {
|
|
35
|
+
value = objectToTuple(internalValue, ['r', 'g', 'b']);
|
|
36
|
+
} else {
|
|
37
|
+
console.error('Unreachable');
|
|
38
|
+
}
|
|
39
|
+
} else if (typeof value === 'string') {
|
|
40
|
+
value = internalValue;
|
|
41
|
+
} else if (isObject(value)) {
|
|
42
|
+
value = internalValue;
|
|
43
|
+
} else {
|
|
44
|
+
console.error('Unreachable');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function addListeners() {
|
|
48
|
+
ref.on('change', () => {
|
|
49
|
+
ref.refresh();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
$: value, updateInternalValue();
|
|
53
|
+
$: internalValue, updateValue();
|
|
54
|
+
$: ref !== void 0 && addListeners();
|
|
55
|
+
$: options = {
|
|
56
|
+
color: {
|
|
57
|
+
type
|
|
58
|
+
},
|
|
59
|
+
view: 'color'
|
|
60
|
+
};
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<GenericInputFolding
|
|
64
|
+
bind:value={internalValue}
|
|
65
|
+
bind:expanded
|
|
66
|
+
bind:ref
|
|
67
|
+
{buttonClass}
|
|
68
|
+
{options}
|
|
69
|
+
{...$$restProps}
|
|
70
|
+
/>
|
|
71
|
+
{#if !BROWSER && expanded && $$props.picker === 'inline'}
|
|
72
|
+
<!-- Main swatch -->
|
|
73
|
+
<ClsPad keysAdd={fillWith('containerUnitSize', 6)} theme={$$props.theme} />
|
|
74
|
+
<ClsPad keysAdd={fillWith('containerUnitSpacing', 3)} theme={$$props.theme} />
|
|
75
|
+
{#if isRgbaColorObject(internalValue)}
|
|
76
|
+
<ClsPad keysAdd={fillWith('containerUnitSize', 1)} theme={$$props.theme} />
|
|
77
|
+
<ClsPad extra={2} keysAdd={fillWith('containerVerticalPadding', 2)} theme={$$props.theme} />
|
|
78
|
+
{/if}
|
|
79
|
+
{/if}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { SvelteComponent } from 'svelte';
|
|
2
|
+
import type {
|
|
3
|
+
RgbColorObject,
|
|
4
|
+
RgbaColorObject
|
|
5
|
+
} from '@tweakpane/core/dist/input-binding/color/model/color.js';
|
|
6
|
+
import type { Simplify } from '../utils';
|
|
7
|
+
export type ColorValueRgbTuple = [r: number, g: number, b: number];
|
|
8
|
+
export type ColorValueRgbaTuple = [r: number, g: number, b: number, a: number];
|
|
9
|
+
export type ColorValueRgbObject = Simplify<RgbColorObject>;
|
|
10
|
+
export type ColorValueRgbaObject = Simplify<RgbaColorObject>;
|
|
11
|
+
export type ColorValueString = string;
|
|
12
|
+
export type ColorValue = Simplify<
|
|
13
|
+
| ColorValueRgbObject
|
|
14
|
+
| ColorValueRgbTuple
|
|
15
|
+
| ColorValueRgbaObject
|
|
16
|
+
| ColorValueRgbaTuple
|
|
17
|
+
| ColorValueString
|
|
18
|
+
>;
|
|
19
|
+
import type { ColorInputParams as ColorOptions } from 'tweakpane';
|
|
20
|
+
declare const __propDef: {
|
|
21
|
+
props: Omit<
|
|
22
|
+
Omit<
|
|
23
|
+
{
|
|
24
|
+
/**
|
|
25
|
+
* The binding's target object with values to manipulate.
|
|
26
|
+
* @bindable
|
|
27
|
+
*/
|
|
28
|
+
object: import('@tweakpane/core').Bindable & {
|
|
29
|
+
[x: string]: ColorValue;
|
|
30
|
+
};
|
|
31
|
+
/** The key for the value in the target `object` that the control should manipulate. */
|
|
32
|
+
key: string | number;
|
|
33
|
+
/**
|
|
34
|
+
* Prevent interactivity and gray out the control.
|
|
35
|
+
* @default `false`
|
|
36
|
+
*/
|
|
37
|
+
disabled?: boolean | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Text displayed next to control.
|
|
40
|
+
* @default `undefined`
|
|
41
|
+
*/
|
|
42
|
+
label?: string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Tweakpane's internal options object.
|
|
45
|
+
*
|
|
46
|
+
* See [`BindingParams`](https://tweakpane.github.io/docs/api/types/BindingParams.html).
|
|
47
|
+
*
|
|
48
|
+
* Valid types are contingent on the type of the value `key` points to in `object`.
|
|
49
|
+
*
|
|
50
|
+
* This is intended internal use, when implementing convenience components wrapping Binding's
|
|
51
|
+
* functionality. Options of interest are instead exposed as top-level props in _Svelte
|
|
52
|
+
* Tweakpane UI_.
|
|
53
|
+
* @default `undefined`
|
|
54
|
+
*/
|
|
55
|
+
options?: ColorOptions | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Custom color scheme.
|
|
58
|
+
*
|
|
59
|
+
* @default `undefined` \
|
|
60
|
+
* Inherits default Tweakpane theme equivalent to `ThemeUtils.presets.standard`, or the theme
|
|
61
|
+
* set with `setGlobalDefaultTheme()`.
|
|
62
|
+
*/
|
|
63
|
+
theme?: import('..').Theme | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Reference to internal Tweakpane
|
|
66
|
+
* [`BindingApi`](https://tweakpane.github.io/docs/api/classes/_internal_.BindingApi.html) for
|
|
67
|
+
* this control.
|
|
68
|
+
*
|
|
69
|
+
* This is primarily for internal use, when implementing convenience components wrapping
|
|
70
|
+
* Binding's functionality.
|
|
71
|
+
* @bindable
|
|
72
|
+
* @readonly
|
|
73
|
+
*/
|
|
74
|
+
ref?: import('../internal/GenericInput.svelte').GenericInputRef | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Imported Tweakpane `TpPluginBundle` (aliased as `Plugin`) module to automatically register in
|
|
77
|
+
* the binding's containing `<Pane>`.
|
|
78
|
+
*
|
|
79
|
+
* This is primarily for internal use, when implementing convenience components wrapping
|
|
80
|
+
* Binding's functionality in combination with a Tweakpane plugin.
|
|
81
|
+
* @default `undefined`
|
|
82
|
+
*/
|
|
83
|
+
plugin?: import('tweakpane').TpPluginBundle | undefined;
|
|
84
|
+
},
|
|
85
|
+
'object' | 'key'
|
|
86
|
+
> & {
|
|
87
|
+
/**
|
|
88
|
+
* A color value to control.
|
|
89
|
+
*
|
|
90
|
+
* Use either a color-like string (e.g. #ff00ff), or an object with `r`, `b`, `g`, and
|
|
91
|
+
* optional `a` keys.
|
|
92
|
+
* @bindable
|
|
93
|
+
*/
|
|
94
|
+
value: ColorValue;
|
|
95
|
+
} & {
|
|
96
|
+
/**
|
|
97
|
+
* DOM class name of the button used to expand and collapse the input's picker.
|
|
98
|
+
* @default `undefined`
|
|
99
|
+
*/
|
|
100
|
+
buttonClass?: string | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Expand or collapse the input's picker.
|
|
103
|
+
* @default `false`
|
|
104
|
+
* @bindable
|
|
105
|
+
*/
|
|
106
|
+
expanded?: boolean | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* The style of value "picker" to use in the input.
|
|
109
|
+
* @default `'popup'`
|
|
110
|
+
*/
|
|
111
|
+
picker?: 'inline' | 'popup' | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Allow users to interactively expand / contract the picker.
|
|
114
|
+
* @default `true`
|
|
115
|
+
*/
|
|
116
|
+
userExpandable?: boolean | undefined;
|
|
117
|
+
},
|
|
118
|
+
'options' | 'ref' | 'plugin' | 'buttonClass'
|
|
119
|
+
> & {
|
|
120
|
+
/**
|
|
121
|
+
* A color value to control.
|
|
122
|
+
*
|
|
123
|
+
* Use either a color-like string (e.g. #ff00ff), or an object with `r`, `b`, `g`, and
|
|
124
|
+
* optional `a` keys.
|
|
125
|
+
* @bindable
|
|
126
|
+
* */
|
|
127
|
+
value: ColorValue;
|
|
128
|
+
/**
|
|
129
|
+
* Whether to treat values as floats from 0.0 to 1.0, or integers from 0 to 255.
|
|
130
|
+
* @default `'int'`
|
|
131
|
+
* */
|
|
132
|
+
type?: 'float' | 'int' | undefined;
|
|
133
|
+
};
|
|
134
|
+
events: {
|
|
135
|
+
[evt: string]: CustomEvent<any>;
|
|
136
|
+
};
|
|
137
|
+
slots: {};
|
|
138
|
+
};
|
|
139
|
+
export type ColorProps = typeof __propDef.props;
|
|
140
|
+
export type ColorEvents = typeof __propDef.events;
|
|
141
|
+
export type ColorSlots = typeof __propDef.slots;
|
|
142
|
+
/**
|
|
143
|
+
* A color picker.
|
|
144
|
+
*
|
|
145
|
+
* Wraps Tweakpane's [color input binding](https://tweakpane.github.io/docs/input-bindings/#color).
|
|
146
|
+
*
|
|
147
|
+
* Usage outside of a `<Pane>` component will implicitly wrap the color picker in `<Pane
|
|
148
|
+
* position='inline'>`.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```svelte
|
|
152
|
+
* <script lang="ts">
|
|
153
|
+
* import { Color } from 'svelte-tweakpane-ui';
|
|
154
|
+
*
|
|
155
|
+
* let startColor = '#fff000';
|
|
156
|
+
* let endColor = '#ff00ff';
|
|
157
|
+
* </script>
|
|
158
|
+
*
|
|
159
|
+
* <Color bind:value={startColor} label="Start Color" />
|
|
160
|
+
* <Color bind:value={endColor} label="End Color" />
|
|
161
|
+
*
|
|
162
|
+
* <div class="demo" style:--a={startColor} style:--b={endColor} />
|
|
163
|
+
*
|
|
164
|
+
* <style>
|
|
165
|
+
* .demo {
|
|
166
|
+
* aspect-ratio: 1;
|
|
167
|
+
* width: 100%;
|
|
168
|
+
* background: linear-gradient(to top, var(--a), var(--b));
|
|
169
|
+
* }
|
|
170
|
+
* </style>
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @sourceLink
|
|
174
|
+
* [Color.svelte](https://github.com/kitschpatrol/svelte-tweakpane-ui/blob/main/src/lib/control/Color.svelte)
|
|
175
|
+
*/
|
|
176
|
+
export default class Color extends SvelteComponent<ColorProps, ColorEvents, ColorSlots> {}
|
|
177
|
+
export {};
|