svelte-tweakpane-ui 1.0.1 → 1.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.
Files changed (55) hide show
  1. package/dist/control/ButtonGrid.svelte +6 -7
  2. package/dist/control/Checkbox.svelte.d.ts +2 -4
  3. package/dist/control/Color.svelte.d.ts +2 -4
  4. package/dist/control/CubicBezier.svelte +2 -2
  5. package/dist/control/Image.svelte.d.ts +2 -4
  6. package/dist/control/IntervalSlider.svelte.d.ts +2 -4
  7. package/dist/control/List.svelte +7 -13
  8. package/dist/control/List.svelte.d.ts +3 -5
  9. package/dist/control/Point.svelte.d.ts +29 -31
  10. package/dist/control/RadioGrid.svelte.d.ts +2 -4
  11. package/dist/control/Ring.svelte.d.ts +2 -4
  12. package/dist/control/RotationEuler.svelte.d.ts +66 -4
  13. package/dist/control/RotationQuaternion.svelte.d.ts +2 -4
  14. package/dist/control/Slider.svelte.d.ts +2 -4
  15. package/dist/control/Text.svelte.d.ts +2 -4
  16. package/dist/control/Textarea.svelte +1 -3
  17. package/dist/control/Textarea.svelte.d.ts +2 -4
  18. package/dist/control/Wheel.svelte.d.ts +3 -9
  19. package/dist/core/Blade.svelte +5 -6
  20. package/dist/core/TabGroup.svelte +4 -5
  21. package/dist/core/TabPage.svelte +2 -2
  22. package/dist/extra/AutoObject.svelte +3 -5
  23. package/dist/extra/AutoValue.svelte.d.ts +6 -4
  24. package/dist/extra/Element.svelte +1 -3
  25. package/dist/index.js +5 -5
  26. package/dist/internal/ClsPad.svelte +2 -6
  27. package/dist/internal/ClsPad.svelte.d.ts +10 -0
  28. package/dist/internal/GenericBinding.svelte.d.ts +2 -4
  29. package/dist/internal/GenericBladeFolding.svelte +1 -1
  30. package/dist/internal/GenericInput.svelte +4 -6
  31. package/dist/internal/GenericInput.svelte.d.ts +2 -4
  32. package/dist/internal/GenericInputFolding.svelte +2 -2
  33. package/dist/internal/GenericInputFolding.svelte.d.ts +2 -4
  34. package/dist/internal/GenericMonitor.svelte +1 -1
  35. package/dist/internal/GenericMonitor.svelte.d.ts +2 -4
  36. package/dist/internal/GenericPane.svelte +26 -15
  37. package/dist/internal/GenericSlider.svelte +10 -12
  38. package/dist/internal/GenericSlider.svelte.d.ts +2 -4
  39. package/dist/internal/InternalMonitorBoolean.svelte.d.ts +2 -4
  40. package/dist/internal/InternalMonitorNumber.svelte.d.ts +2 -4
  41. package/dist/internal/InternalMonitorString.svelte.d.ts +2 -4
  42. package/dist/internal/InternalPaneDraggable.svelte +20 -19
  43. package/dist/internal/InternalPaneFixed.svelte +1 -3
  44. package/dist/internal/InternalPaneInline.svelte +1 -1
  45. package/dist/monitor/FpsGraph.svelte +2 -2
  46. package/dist/monitor/Monitor.svelte.d.ts +23 -31
  47. package/dist/monitor/Profiler.svelte +2 -2
  48. package/dist/monitor/WaveformMonitor.svelte.d.ts +2 -4
  49. package/dist/theme.d.ts +1 -3
  50. package/dist/theme.js +25 -32
  51. package/dist/utils.d.ts +5 -2
  52. package/dist/utils.js +34 -28
  53. package/package.json +17 -11
  54. package/{README.md → readme.md} +1 -1
  55. /package/{LICENSE → license.txt} +0 -0
package/dist/theme.js CHANGED
@@ -33,12 +33,12 @@ const standard = {
33
33
  monitorBackgroundColor: 'rgba(0, 0, 0, 0.2)',
34
34
  monitorForegroundColor: 'rgba(187, 188, 196, 0.7)',
35
35
  pluginImageDraggingColor: 'hsla(230, 100%, 66%, 1)'
36
- // pluginThumbnailListHeight: '400px', pluginThumbnailListThumbSize: '20px',
36
+ // PluginThumbnailListHeight: '400px', pluginThumbnailListThumbSize: '20px',
37
37
  // pluginThumbnailListWidth: '200px'
38
38
  };
39
- export const keys = Object.keys(standard).reduce((accumulator, key) => {
40
- accumulator[key] = key;
41
- return accumulator;
39
+ export const keys = Object.keys(standard).reduce((acc, key) => {
40
+ acc[key] = key;
41
+ return acc;
42
42
  }, {});
43
43
  const light = {
44
44
  baseBackgroundColor: 'hsla(230, 5%, 90%, 1.00)',
@@ -239,34 +239,33 @@ const keyToCssVariableMap = new Map([
239
239
  function stringToCssValue(v) {
240
240
  if (v === undefined) {
241
241
  return undefined;
242
- } else if (typeof v === 'string') {
242
+ }
243
+ if (typeof v === 'string') {
243
244
  return v;
244
- } else if (isRgbaColorObject(v)) {
245
+ }
246
+ if (isRgbaColorObject(v)) {
245
247
  return `rgba(${v.r}, ${v.g}, ${v.b}, ${v.a})`;
246
- } else if (isRgbColorObject(v)) {
248
+ }
249
+ if (isRgbColorObject(v)) {
247
250
  return `rgb(${v.r}, ${v.g}, ${v.b})`;
248
- } else {
249
- throw new Error(`Unknown CSS theme value object: ${v}`);
250
251
  }
251
252
  }
252
253
  function expandVariableKey(name) {
253
- // pass explicit variables through
254
+ // Pass explicit variables through
254
255
  if (name.startsWith('--tp-')) {
255
256
  return name;
256
- } else {
257
- const variableName = keyToCssVariableMap.get(name);
258
- if (variableName) {
259
- return variableName;
260
- } else {
261
- throw new Error(`Unknown Tweakpane CSS theme map variable key: "${name}"`);
262
- }
263
257
  }
258
+ const variableName = keyToCssVariableMap.get(name);
259
+ if (variableName) {
260
+ return variableName;
261
+ }
262
+ throw new Error(`Unknown Tweakpane CSS theme map variable key: "${name}"`);
264
263
  }
265
264
  /**
266
265
  * Used during SSR to calculate metrics Returns CSS string.
267
266
  */
268
267
  export function getValueOrFallback(theme, key) {
269
- return theme === undefined || theme[key] === undefined
268
+ return theme?.[key] === undefined
270
269
  ? stringToCssValue(standard[key])
271
270
  : stringToCssValue(theme[key]);
272
271
  }
@@ -276,7 +275,6 @@ export function applyTheme(element, theme) {
276
275
  for (const k of Object.keys(standard)) {
277
276
  const key = expandVariableKey(k);
278
277
  if (element.style.getPropertyValue(key).length > 0) {
279
- // console.log(`Unsetting via undefined theme ${key}`);
280
278
  element.style.removeProperty(key);
281
279
  }
282
280
  }
@@ -284,27 +282,22 @@ export function applyTheme(element, theme) {
284
282
  for (const [k, v] of Object.entries(theme)) {
285
283
  const key = expandVariableKey(k);
286
284
  const value = stringToCssValue(v);
287
- // console.log(`Inspecting ${key}: ${value}`);
288
- // only set the variable if it deviates from the standard theme or the root theme (set
285
+ // Only set the variable if it deviates from the standard theme or the root theme (set
289
286
  // by setGlobalDefaultTheme).... but if theme is explicitly standard and not undefined,
290
287
  // then apply it anyway so that any global theme is overridden TODO normalize color
291
288
  // representation for comparison? TODO tests for this logic
292
289
  const standardValue = standard[k] || undefined;
293
290
  const rootValue = rootDocument.style.getPropertyValue(key) || undefined;
294
- const isDeviationFromRoot = (rootValue && value !== rootValue) || false;
295
- const isDeviationFromStandard = (standardValue && value !== standardValue) || false;
291
+ const isDeviationFromRoot = (rootValue && value !== rootValue) ?? false;
292
+ const isDeviationFromStandard = (standardValue && value !== standardValue) ?? false;
296
293
  if (
297
294
  theme !== undefined &&
298
295
  value !== undefined &&
299
296
  (isDeviationFromRoot || (!rootValue && isDeviationFromStandard))
300
297
  ) {
301
- // console.log(`Setting ${key} to ${value}`);
302
298
  element.style.setProperty(key, value);
303
- } else {
304
- if (element.style.getPropertyValue(key).length > 0) {
305
- // console.log(`Unsetting ${key}`);
306
- element.style.removeProperty(key);
307
- }
299
+ } else if (element.style.getPropertyValue(key).length > 0) {
300
+ element.style.removeProperty(key);
308
301
  }
309
302
  }
310
303
  }
@@ -314,12 +307,12 @@ export function applyTheme(element, theme) {
314
307
  * mode toggle.
315
308
  */
316
309
  export function setGlobalDefaultTheme(theme) {
317
- // wait for dom ready... better outside?
318
- if (typeof window !== 'undefined' && window.document) {
310
+ // Wait for dom ready... better outside?
311
+ if (window?.document) {
319
312
  applyTheme(getWindowDocument().documentElement, theme);
320
313
  }
321
314
  }
322
- // library exports
315
+ // Library exports
323
316
  export default {
324
317
  /**
325
318
  * A collection of default theme color schemes, matching those provided in the Tweakpane
package/dist/utils.d.ts CHANGED
@@ -8,7 +8,7 @@ export type SimplifyDeep<Type> = Type extends Theme
8
8
  ? Type
9
9
  : {
10
10
  [TypeKey in keyof Type]: SimplifyDeep<Type[TypeKey]>;
11
- };
11
+ };
12
12
  export type HasKey<U, V extends PropertyKey> = V extends keyof U ? U[V] : unknown;
13
13
  import type { Bindable, BladeApi, BladeController, TpPluginBundle, View } from '@tweakpane/core';
14
14
  export type BindingObject = Bindable;
@@ -71,7 +71,10 @@ export declare function enforceReadonly(
71
71
  export declare function isRootPane(container: Container): boolean;
72
72
  export declare function clamp(value: number, min: number, max: number): number;
73
73
  export declare function getElementIndex(element: HTMLElement): number;
74
- export declare function removeKeys<T extends object>(object: T, ...keys: string[]): T;
74
+ export declare function removeKeys<T extends Record<string, unknown>>(
75
+ object: T,
76
+ ...keys: string[]
77
+ ): T;
75
78
  export declare function updateCollapsibility(
76
79
  isUserExpandableEnabled: boolean,
77
80
  element: HTMLElement,
package/dist/utils.js CHANGED
@@ -1,23 +1,26 @@
1
- // type aliases and utility functions
2
- // utility functions
1
+ /* eslint-disable @typescript-eslint/no-unnecessary-type-arguments */
2
+ // Utility functions
3
3
  /**
4
4
  * For CLS SSR calculation
5
5
  */
6
6
  export function rowsForMonitor(buffer, rows, graph) {
7
7
  if (graph) {
8
8
  return Math.max(rows ?? 3, 3);
9
- } else if (buffer === undefined && rows === undefined) {
9
+ }
10
+ if (buffer === undefined && rows === undefined) {
10
11
  return 1;
11
- } else if (buffer === undefined && rows !== undefined) {
12
+ }
13
+ if (buffer === undefined && rows !== undefined) {
12
14
  return 1;
13
- } else if (buffer !== undefined && rows === undefined) {
15
+ }
16
+ if (buffer !== undefined && rows === undefined) {
14
17
  return buffer > 1 ? 3 : 1;
15
- } else if (buffer === 1) {
18
+ }
19
+ if (buffer === 1) {
16
20
  return 1;
17
- } else {
18
- // both defined
19
- return rows ?? 1; // TODO
20
21
  }
22
+ // Both defined
23
+ return rows ?? 1; // TODO
21
24
  }
22
25
  /**
23
26
  * Fills an array of length `quantity` with a `value`
@@ -65,7 +68,9 @@ export function enforceReadonly(
65
68
  const componentString = componentName ? `<${componentName}> ` : '';
66
69
  const propertyString = propertyName ? `property "${propertyName}" ` : '';
67
70
  console.error(
68
- `Svelte component ${componentString}property ${propertyString}is intended for readonly use.\nAssigning\n"${external}"\nto\n"${internal}"\nis not allowed.`
71
+ `Svelte component "${componentString}" property "${propertyString}" is intended for readonly use.\nAssigning\n"${String(
72
+ external
73
+ )}"\nto\n"${String(internal)}"\nis not allowed.`
69
74
  );
70
75
  }
71
76
  }
@@ -73,43 +78,44 @@ export function isRootPane(container) {
73
78
  return container.constructor.name === 'Pane';
74
79
  }
75
80
  export function clamp(value, min, max) {
76
- // prioritize min over max
81
+ // Prioritize min over max
77
82
  return Math.min(Math.max(value, min), max);
78
83
  }
79
84
  export function getElementIndex(element) {
80
85
  let index = 0;
86
+ // eslint-disable-next-line @typescript-eslint/ban-types
81
87
  let sibling = element;
82
88
  while ((sibling = sibling.previousElementSibling) !== null) {
83
89
  index++;
84
90
  }
85
91
  return index;
86
92
  }
87
- // doesn't create a new object, only works with string keys
93
+ // Doesn't create a new object, only works with string keys
88
94
  export function removeKeys(object, ...keys) {
89
95
  for (const key of keys) {
90
96
  if (key in object) {
97
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
91
98
  delete object[key];
92
99
  }
93
100
  }
94
101
  return object;
95
102
  }
96
103
  function clickBlocker(event) {
97
- // only block user clicks, not programmatic ones
98
- console.log(event.detail);
104
+ // Only block user clicks, not programmatic ones
99
105
  if (event.isTrusted) event.stopPropagation();
100
106
  }
101
- // used by folder and pane TODO rewrite to use getSwatchButton etc.
107
+ // Used by folder and pane TODO rewrite to use getSwatchButton etc.
102
108
  export function updateCollapsibility(isUserExpandableEnabled, element, titleBarClass, iconClass) {
103
109
  if (element) {
104
110
  const titleBarElement = element.querySelector(`.${titleBarClass}`);
105
- if (titleBarElement !== undefined) {
111
+ if (titleBarElement) {
106
112
  const iconElement = iconClass ? element.querySelector(`.${iconClass}`) : undefined;
107
113
  if (isUserExpandableEnabled) {
108
114
  titleBarElement.removeEventListener('click', clickBlocker, { capture: true });
109
115
  titleBarElement.style.cursor = 'pointer';
110
116
  if (iconElement) iconElement.style.display = 'block';
111
117
  } else {
112
- //expanded = true;
118
+ // Expanded = true;
113
119
  titleBarElement.addEventListener('click', clickBlocker, { capture: true });
114
120
  titleBarElement.style.cursor = 'default';
115
121
  if (iconElement) iconElement.style.display = 'none';
@@ -130,7 +136,8 @@ export function updateCollapsibility(isUserExpandableEnabled, element, titleBarC
130
136
  * If both constraints are provided, values may be clipped.
131
137
  */
132
138
  export function getGridDimensions(itemCount, maxColumns, maxRows) {
133
- let rows, columns;
139
+ let rows;
140
+ let columns;
134
141
  if (maxColumns && maxRows) {
135
142
  // No flexing; items can exceed the available slots
136
143
  rows = Math.min(Math.ceil(itemCount / maxColumns), maxRows);
@@ -151,6 +158,7 @@ export function getGridDimensions(itemCount, maxColumns, maxRows) {
151
158
  return { columns, rows };
152
159
  }
153
160
  export function tupleToObject(tuple, keys) {
161
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
154
162
  const result = {};
155
163
  for (const [index, key] of keys.entries()) {
156
164
  // Assert that the assignment is safe
@@ -161,7 +169,7 @@ export function tupleToObject(tuple, keys) {
161
169
  export function objectToTuple(object, keys) {
162
170
  return keys.map((key) => object[key]);
163
171
  }
164
- // tweakpane helpers
172
+ // Tweakpane helpers
165
173
  export function pickerIsOpen(blade) {
166
174
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
167
175
  return blade.controller.valueController?.foldable_?.valMap_?.expanded?.value_;
@@ -174,7 +182,7 @@ export function getSwatchButton(blade) {
174
182
  blade.controller?.valueController?.view?.buttonElement;
175
183
  return swatch;
176
184
  }
177
- // utility functions
185
+ // Utility functions
178
186
  function quaternionToCssTransform(quaternion) {
179
187
  const [x, y, z, w] = Array.isArray(quaternion)
180
188
  ? quaternion
@@ -197,22 +205,20 @@ function quaternionToCssTransform(quaternion) {
197
205
  }
198
206
  function eulerToCssTransform(
199
207
  rotation,
200
- units = 'rad' // rad is component default
208
+ units = 'rad' // Rad is component default
201
209
  ) {
202
210
  const [x, y, z] = Array.isArray(rotation) ? rotation : [rotation.x, rotation.y, rotation.z];
203
- // note negative z
211
+ // Note negative z
204
212
  return `rotateX(${x}${units}) rotateY(${y}${units}) rotateZ(${-z}${units})`;
205
213
  }
206
214
  function cubicBezierToEaseFunction(cubicBezier) {
207
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
208
- const [x1, y1, x2, y2] = Array.isArray(cubicBezier)
215
+ const [_x1, y1, _x2, y2] = Array.isArray(cubicBezier)
209
216
  ? cubicBezier
210
217
  : [cubicBezier.x1, cubicBezier.y1, cubicBezier.x2, cubicBezier.y2];
211
- return (t) => {
212
- return (1 - t) ** 3 * 0 + (1 - t) ** 2 * t * 3 * y1 + (1 - t) * t ** 2 * 3 * y2 + t ** 3 * 1;
213
- };
218
+ return (t) =>
219
+ (1 - t) ** 3 * 0 + (1 - t) ** 2 * t * 3 * y1 + (1 - t) * t ** 2 * 3 * y2 + t ** 3 * 1;
214
220
  }
215
- // library exports
221
+ // Library exports
216
222
  export default {
217
223
  /**
218
224
  * Convenience function for creating easing functions ready for Svelte's tween and animation
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "svelte-tweakpane-ui",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
+ "description": "Wraps UI elements from Tweakpane in a collection of idiomatic Svelte components, and augments Tweakpane with a few extra features for your convenience and enjoyment.",
5
6
  "repository": {
6
7
  "type": "git",
7
- "url": "https://github.com/kitschpatrol/svelte-tweakpane-ui"
8
+ "url": "git+https://github.com/kitschpatrol/svelte-tweakpane-ui.git"
8
9
  },
9
10
  "homepage": "https:///kitschpatrol.com/svelte-tweakpane-ui",
10
11
  "bugs": {
@@ -187,30 +188,34 @@
187
188
  "@0b5vr/tweakpane-plugin-rotation": "^0.2.0",
188
189
  "@kitschpatrol/tweakpane-image-plugin": "^2.0.0",
189
190
  "@kitschpatrol/tweakpane-textarea-plugin": "^2.0.1",
190
- "@tweakpane/core": "^2.0.1",
191
+ "@tweakpane/core": "^2.0.2",
191
192
  "@tweakpane/plugin-camerakit": "^0.3.0",
192
- "@tweakpane/plugin-essentials": "^0.2.0",
193
+ "@tweakpane/plugin-essentials": "^0.2.1",
193
194
  "esm-env": "^1.0.0",
194
195
  "nanoid": "^5.0.4",
195
196
  "svelte-local-storage-store": "^0.6.4",
196
- "tweakpane": "^4.0.1",
197
+ "tweakpane": "^4.0.2",
197
198
  "tweakpane-plugin-waveform": "^1.0.0"
198
199
  },
199
200
  "devDependencies": {
200
- "@kitschpatrol/shared-config": "^2.0.1",
201
+ "@kitschpatrol/shared-config": "^4.0.0",
201
202
  "@phenomnomnominal/tsquery": "^6.1.3",
202
203
  "@stkb/rewrap": "^0.1.0",
203
- "@sveltejs/adapter-static": "^2.0.3",
204
- "@sveltejs/kit": "^1.27.7",
204
+ "@sveltejs/adapter-static": "^3.0.0",
205
+ "@sveltejs/kit": "^2.0.1",
205
206
  "@sveltejs/package": "^2.2.3",
206
- "@types/eslint": "^8.44.8",
207
+ "@sveltejs/vite-plugin-svelte": "^3.0.1",
208
+ "@types/eslint": "^8.44.9",
207
209
  "@types/fs-extra": "^11.0.4",
208
- "@types/node": "^20.10.4",
210
+ "@types/node": "^20.10.5",
211
+ "bumpp": "^9.2.1",
212
+ "eslint": "^8.56.0",
209
213
  "fs-extra": "^11.2.0",
210
214
  "glob": "^10.3.10",
211
215
  "npm-run-all": "^4.1.5",
212
216
  "postcss-html": "^1.5.0",
213
217
  "publint": "^0.2.6",
218
+ "read-package-up": "^11.0.0",
214
219
  "svelte": "^4.2.8",
215
220
  "svelte-check": "^3.6.2",
216
221
  "svelte-language-server": "^0.16.1",
@@ -219,7 +224,7 @@
219
224
  "tslib": "^2.6.2",
220
225
  "tsx": "^4.6.2",
221
226
  "typescript": "^5.3.3",
222
- "vite": "^4.5.1",
227
+ "vite": "^5.0.10",
223
228
  "yaml": "^2.3.4"
224
229
  },
225
230
  "scripts": {
@@ -251,6 +256,7 @@
251
256
  "kit-examples": "tsx ./scripts/generate-kit-examples.ts",
252
257
  "kit-preview": "vite preview",
253
258
  "lint": "shared-config --check",
259
+ "release": "pnpm bumpp --commit 'Release: %s' --tag '%s' && pnpm publish --otp $(op read 'op://Personal/Npmjs/one-time password?attribute=otp')",
254
260
  "rewrap": "rewrap -i --column 100 `find src \\( -name '*.svelte' -o -name '*.ts' -o -name '*.html' \\) -type f | grep -v src/examples`",
255
261
  "type-check": "tsc --noEmit"
256
262
  }
@@ -9,7 +9,7 @@
9
9
 
10
10
  The library makes it easy to quickly and declaratively add knobs and dials to your projects using components that feel like they were made for Svelte. It also augments Tweakpane with a few [extra features](https://kitschpatrol.com/svelte-tweakpane-ui/docs/features) for your convenience and enjoyment.
11
11
 
12
- [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.
12
+ [The components](https://kitschpatrol.com/svelte-tweakpane-ui/docs#components) should be useful for integrating controls and value monitoring in parametrically driven artworks, data visualizations, creative tools, simulations, etc.
13
13
 
14
14
  ## Demo
15
15
 
File without changes