dialkit 1.1.0 → 1.2.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/README.md +171 -1
- package/dist/index.cjs +876 -337
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -6
- package/dist/index.d.ts +41 -6
- package/dist/index.js +878 -341
- package/dist/index.js.map +1 -1
- package/dist/solid/index.cjs +1011 -544
- package/dist/solid/index.cjs.map +1 -1
- package/dist/solid/index.d.cts +33 -3
- package/dist/solid/index.d.ts +33 -3
- package/dist/solid/index.js +864 -398
- package/dist/solid/index.js.map +1 -1
- package/dist/store/index.cjs +52 -12
- package/dist/store/index.cjs.map +1 -1
- package/dist/store/index.d.cts +25 -3
- package/dist/store/index.d.ts +25 -3
- package/dist/store/index.js +52 -12
- package/dist/store/index.js.map +1 -1
- package/dist/styles.css +256 -25
- package/dist/svelte/components/ControlRenderer.svelte +12 -0
- package/dist/svelte/components/ControlRenderer.svelte.d.ts.map +1 -1
- package/dist/svelte/components/DialRoot.svelte +22 -8
- package/dist/svelte/components/DialRoot.svelte.d.ts +3 -0
- package/dist/svelte/components/DialRoot.svelte.d.ts.map +1 -1
- package/dist/svelte/components/Folder.svelte +17 -8
- package/dist/svelte/components/Folder.svelte.d.ts.map +1 -1
- package/dist/svelte/components/Panel.svelte +14 -9
- package/dist/svelte/components/Panel.svelte.d.ts.map +1 -1
- package/dist/svelte/components/PresetManager.svelte +7 -6
- package/dist/svelte/components/PresetManager.svelte.d.ts.map +1 -1
- package/dist/svelte/components/SegmentedControl.svelte +30 -74
- package/dist/svelte/components/SegmentedControl.svelte.d.ts.map +1 -1
- package/dist/svelte/components/SelectControl.svelte +2 -1
- package/dist/svelte/components/SelectControl.svelte.d.ts.map +1 -1
- package/dist/svelte/components/ShortcutListener.svelte +265 -0
- package/dist/svelte/components/ShortcutListener.svelte.d.ts +13 -0
- package/dist/svelte/components/ShortcutListener.svelte.d.ts.map +1 -0
- package/dist/svelte/components/ShortcutsMenu.svelte +128 -0
- package/dist/svelte/components/ShortcutsMenu.svelte.d.ts +7 -0
- package/dist/svelte/components/ShortcutsMenu.svelte.d.ts.map +1 -0
- package/dist/svelte/components/Slider.svelte +16 -29
- package/dist/svelte/components/Slider.svelte.d.ts +3 -0
- package/dist/svelte/components/Slider.svelte.d.ts.map +1 -1
- package/dist/svelte/components/SpringControl.svelte +17 -15
- package/dist/svelte/components/SpringControl.svelte.d.ts.map +1 -1
- package/dist/svelte/components/Toggle.svelte +13 -2
- package/dist/svelte/components/Toggle.svelte.d.ts +3 -0
- package/dist/svelte/components/Toggle.svelte.d.ts.map +1 -1
- package/dist/svelte/components/TransitionControl.svelte +28 -25
- package/dist/svelte/components/TransitionControl.svelte.d.ts.map +1 -1
- package/dist/svelte/createDialKit.svelte.d.ts +2 -1
- package/dist/svelte/createDialKit.svelte.d.ts.map +1 -1
- package/dist/svelte/createDialKit.svelte.js +1 -1
- package/dist/svelte/index.d.ts +6 -2
- package/dist/svelte/index.d.ts.map +1 -1
- package/dist/svelte/index.js +4 -0
- package/dist/svelte/theme-css.d.ts +1 -1
- package/dist/svelte/theme-css.d.ts.map +1 -1
- package/dist/svelte/theme-css.js +257 -26
- package/dist/vue/index.cjs +3056 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.cts +675 -0
- package/dist/vue/index.d.ts +675 -0
- package/dist/vue/index.js +3014 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +24 -4
|
@@ -0,0 +1,3056 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/vue/index.ts
|
|
21
|
+
var vue_exports = {};
|
|
22
|
+
__export(vue_exports, {
|
|
23
|
+
ButtonGroup: () => ButtonGroup,
|
|
24
|
+
ColorControl: () => ColorControl,
|
|
25
|
+
DialRoot: () => DialRoot,
|
|
26
|
+
DialStore: () => DialStore,
|
|
27
|
+
EasingVisualization: () => EasingVisualization,
|
|
28
|
+
Folder: () => Folder,
|
|
29
|
+
PresetManager: () => PresetManager,
|
|
30
|
+
SelectControl: () => SelectControl,
|
|
31
|
+
ShortcutKey: () => ShortcutKey,
|
|
32
|
+
ShortcutListener: () => ShortcutListener,
|
|
33
|
+
ShortcutsMenu: () => ShortcutsMenu,
|
|
34
|
+
Slider: () => Slider,
|
|
35
|
+
SpringControl: () => SpringControl,
|
|
36
|
+
SpringVisualization: () => SpringVisualization,
|
|
37
|
+
TextControl: () => TextControl,
|
|
38
|
+
Toggle: () => Toggle,
|
|
39
|
+
TransitionControl: () => TransitionControl,
|
|
40
|
+
useDialKit: () => useDialKit,
|
|
41
|
+
useShortcutContext: () => useShortcutContext,
|
|
42
|
+
vDialKit: () => vDialKit
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(vue_exports);
|
|
45
|
+
|
|
46
|
+
// src/vue/useDialKit.ts
|
|
47
|
+
var import_vue = require("vue");
|
|
48
|
+
|
|
49
|
+
// src/store/DialStore.ts
|
|
50
|
+
var EMPTY_VALUES = Object.freeze({});
|
|
51
|
+
var DialStoreClass = class {
|
|
52
|
+
constructor() {
|
|
53
|
+
this.panels = /* @__PURE__ */ new Map();
|
|
54
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
55
|
+
this.globalListeners = /* @__PURE__ */ new Set();
|
|
56
|
+
this.snapshots = /* @__PURE__ */ new Map();
|
|
57
|
+
this.actionListeners = /* @__PURE__ */ new Map();
|
|
58
|
+
this.presets = /* @__PURE__ */ new Map();
|
|
59
|
+
this.activePreset = /* @__PURE__ */ new Map();
|
|
60
|
+
this.baseValues = /* @__PURE__ */ new Map();
|
|
61
|
+
}
|
|
62
|
+
registerPanel(id, name, config, shortcuts) {
|
|
63
|
+
const controls = this.parseConfig(config, "", shortcuts);
|
|
64
|
+
const values = this.flattenValues(config, "");
|
|
65
|
+
this.initTransitionModes(config, "", values);
|
|
66
|
+
this.panels.set(id, { id, name, controls, values, shortcuts: shortcuts ?? {} });
|
|
67
|
+
this.snapshots.set(id, { ...values });
|
|
68
|
+
this.baseValues.set(id, { ...values });
|
|
69
|
+
this.notifyGlobal();
|
|
70
|
+
}
|
|
71
|
+
updatePanel(id, name, config, shortcuts) {
|
|
72
|
+
const existing = this.panels.get(id);
|
|
73
|
+
if (!existing) {
|
|
74
|
+
this.registerPanel(id, name, config, shortcuts);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const controls = this.parseConfig(config, "", shortcuts);
|
|
78
|
+
const controlsByPath = this.mapControlsByPath(controls);
|
|
79
|
+
const defaultValues = this.flattenValues(config, "");
|
|
80
|
+
const nextValues = {};
|
|
81
|
+
for (const [path, defaultValue] of Object.entries(defaultValues)) {
|
|
82
|
+
nextValues[path] = this.normalizePreservedValue(
|
|
83
|
+
existing.values[path],
|
|
84
|
+
defaultValue,
|
|
85
|
+
controlsByPath.get(path)
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
this.initTransitionModes(config, "", nextValues);
|
|
89
|
+
for (const [path, mode] of Object.entries(existing.values)) {
|
|
90
|
+
if (!path.endsWith(".__mode")) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const transitionPath = path.slice(0, -"__mode".length - 1);
|
|
94
|
+
const transitionControl = controlsByPath.get(transitionPath);
|
|
95
|
+
if (transitionControl?.type === "transition") {
|
|
96
|
+
nextValues[path] = mode;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const nextPanel = { id, name, controls, values: nextValues, shortcuts: shortcuts ?? existing.shortcuts };
|
|
100
|
+
this.panels.set(id, nextPanel);
|
|
101
|
+
this.snapshots.set(id, { ...nextValues });
|
|
102
|
+
const previousBaseValues = this.baseValues.get(id) ?? {};
|
|
103
|
+
const nextBaseValues = {};
|
|
104
|
+
for (const [path, defaultValue] of Object.entries(defaultValues)) {
|
|
105
|
+
nextBaseValues[path] = this.normalizePreservedValue(
|
|
106
|
+
previousBaseValues[path],
|
|
107
|
+
defaultValue,
|
|
108
|
+
controlsByPath.get(path)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
for (const [path, value] of Object.entries(nextValues)) {
|
|
112
|
+
if (path.endsWith(".__mode")) {
|
|
113
|
+
nextBaseValues[path] = value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
this.baseValues.set(id, nextBaseValues);
|
|
117
|
+
this.notify(id);
|
|
118
|
+
this.notifyGlobal();
|
|
119
|
+
}
|
|
120
|
+
unregisterPanel(id) {
|
|
121
|
+
this.panels.delete(id);
|
|
122
|
+
this.listeners.delete(id);
|
|
123
|
+
this.snapshots.delete(id);
|
|
124
|
+
this.actionListeners.delete(id);
|
|
125
|
+
this.baseValues.delete(id);
|
|
126
|
+
this.notifyGlobal();
|
|
127
|
+
}
|
|
128
|
+
updateValue(panelId, path, value) {
|
|
129
|
+
const panel = this.panels.get(panelId);
|
|
130
|
+
if (!panel) return;
|
|
131
|
+
panel.values[path] = value;
|
|
132
|
+
const activeId = this.activePreset.get(panelId);
|
|
133
|
+
if (activeId) {
|
|
134
|
+
const presets = this.presets.get(panelId) ?? [];
|
|
135
|
+
const preset = presets.find((p) => p.id === activeId);
|
|
136
|
+
if (preset) preset.values[path] = value;
|
|
137
|
+
} else {
|
|
138
|
+
const base = this.baseValues.get(panelId);
|
|
139
|
+
if (base) base[path] = value;
|
|
140
|
+
}
|
|
141
|
+
this.snapshots.set(panelId, { ...panel.values });
|
|
142
|
+
this.notify(panelId);
|
|
143
|
+
}
|
|
144
|
+
updateSpringMode(panelId, path, mode) {
|
|
145
|
+
this.updateTransitionMode(panelId, path, mode);
|
|
146
|
+
}
|
|
147
|
+
getSpringMode(panelId, path) {
|
|
148
|
+
const mode = this.getTransitionMode(panelId, path);
|
|
149
|
+
if (mode === "easing") return "simple";
|
|
150
|
+
return mode;
|
|
151
|
+
}
|
|
152
|
+
updateTransitionMode(panelId, path, mode) {
|
|
153
|
+
const panel = this.panels.get(panelId);
|
|
154
|
+
if (!panel) return;
|
|
155
|
+
panel.values[`${path}.__mode`] = mode;
|
|
156
|
+
this.snapshots.set(panelId, { ...panel.values });
|
|
157
|
+
this.notify(panelId);
|
|
158
|
+
}
|
|
159
|
+
getTransitionMode(panelId, path) {
|
|
160
|
+
const panel = this.panels.get(panelId);
|
|
161
|
+
if (!panel) return "simple";
|
|
162
|
+
return panel.values[`${path}.__mode`] || "simple";
|
|
163
|
+
}
|
|
164
|
+
getValue(panelId, path) {
|
|
165
|
+
const panel = this.panels.get(panelId);
|
|
166
|
+
return panel?.values[path];
|
|
167
|
+
}
|
|
168
|
+
getValues(panelId) {
|
|
169
|
+
return this.snapshots.get(panelId) ?? EMPTY_VALUES;
|
|
170
|
+
}
|
|
171
|
+
getPanels() {
|
|
172
|
+
return Array.from(this.panels.values());
|
|
173
|
+
}
|
|
174
|
+
getPanel(id) {
|
|
175
|
+
return this.panels.get(id);
|
|
176
|
+
}
|
|
177
|
+
subscribe(panelId, listener) {
|
|
178
|
+
if (!this.listeners.has(panelId)) {
|
|
179
|
+
this.listeners.set(panelId, /* @__PURE__ */ new Set());
|
|
180
|
+
}
|
|
181
|
+
this.listeners.get(panelId).add(listener);
|
|
182
|
+
return () => {
|
|
183
|
+
this.listeners.get(panelId)?.delete(listener);
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
subscribeGlobal(listener) {
|
|
187
|
+
this.globalListeners.add(listener);
|
|
188
|
+
return () => this.globalListeners.delete(listener);
|
|
189
|
+
}
|
|
190
|
+
subscribeActions(panelId, listener) {
|
|
191
|
+
if (!this.actionListeners.has(panelId)) {
|
|
192
|
+
this.actionListeners.set(panelId, /* @__PURE__ */ new Set());
|
|
193
|
+
}
|
|
194
|
+
this.actionListeners.get(panelId).add(listener);
|
|
195
|
+
return () => {
|
|
196
|
+
this.actionListeners.get(panelId)?.delete(listener);
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
triggerAction(panelId, path) {
|
|
200
|
+
this.actionListeners.get(panelId)?.forEach((fn) => fn(path));
|
|
201
|
+
}
|
|
202
|
+
savePreset(panelId, name) {
|
|
203
|
+
const panel = this.panels.get(panelId);
|
|
204
|
+
if (!panel) throw new Error(`Panel ${panelId} not found`);
|
|
205
|
+
const id = `preset-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
206
|
+
const preset = {
|
|
207
|
+
id,
|
|
208
|
+
name,
|
|
209
|
+
values: { ...panel.values }
|
|
210
|
+
};
|
|
211
|
+
const existing = this.presets.get(panelId) ?? [];
|
|
212
|
+
this.presets.set(panelId, [...existing, preset]);
|
|
213
|
+
this.activePreset.set(panelId, id);
|
|
214
|
+
this.snapshots.set(panelId, { ...panel.values });
|
|
215
|
+
this.notify(panelId);
|
|
216
|
+
return id;
|
|
217
|
+
}
|
|
218
|
+
loadPreset(panelId, presetId) {
|
|
219
|
+
const panel = this.panels.get(panelId);
|
|
220
|
+
if (!panel) return;
|
|
221
|
+
const presets = this.presets.get(panelId) ?? [];
|
|
222
|
+
const preset = presets.find((p) => p.id === presetId);
|
|
223
|
+
if (!preset) return;
|
|
224
|
+
panel.values = { ...preset.values };
|
|
225
|
+
this.snapshots.set(panelId, { ...panel.values });
|
|
226
|
+
this.activePreset.set(panelId, presetId);
|
|
227
|
+
this.notify(panelId);
|
|
228
|
+
}
|
|
229
|
+
deletePreset(panelId, presetId) {
|
|
230
|
+
const presets = this.presets.get(panelId) ?? [];
|
|
231
|
+
this.presets.set(panelId, presets.filter((p) => p.id !== presetId));
|
|
232
|
+
if (this.activePreset.get(panelId) === presetId) {
|
|
233
|
+
this.activePreset.set(panelId, null);
|
|
234
|
+
}
|
|
235
|
+
const panel = this.panels.get(panelId);
|
|
236
|
+
if (panel) {
|
|
237
|
+
this.snapshots.set(panelId, { ...panel.values });
|
|
238
|
+
}
|
|
239
|
+
this.notify(panelId);
|
|
240
|
+
}
|
|
241
|
+
getPresets(panelId) {
|
|
242
|
+
return this.presets.get(panelId) ?? [];
|
|
243
|
+
}
|
|
244
|
+
getActivePresetId(panelId) {
|
|
245
|
+
return this.activePreset.get(panelId) ?? null;
|
|
246
|
+
}
|
|
247
|
+
clearActivePreset(panelId) {
|
|
248
|
+
const panel = this.panels.get(panelId);
|
|
249
|
+
const base = this.baseValues.get(panelId);
|
|
250
|
+
if (panel && base) {
|
|
251
|
+
panel.values = { ...base };
|
|
252
|
+
this.snapshots.set(panelId, { ...panel.values });
|
|
253
|
+
}
|
|
254
|
+
this.activePreset.set(panelId, null);
|
|
255
|
+
this.notify(panelId);
|
|
256
|
+
}
|
|
257
|
+
resolveShortcutTarget(key, modifier) {
|
|
258
|
+
for (const panel of this.panels.values()) {
|
|
259
|
+
for (const [path, shortcut] of Object.entries(panel.shortcuts)) {
|
|
260
|
+
if (!shortcut.key) continue;
|
|
261
|
+
if (shortcut.key.toLowerCase() !== key.toLowerCase()) continue;
|
|
262
|
+
const scMod = shortcut.modifier ?? void 0;
|
|
263
|
+
if (scMod !== modifier) continue;
|
|
264
|
+
const control = this.findControlByPath(panel.controls, path);
|
|
265
|
+
if (control) {
|
|
266
|
+
return { panelId: panel.id, path, control };
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
resolveScrollOnlyTargets() {
|
|
273
|
+
const results = [];
|
|
274
|
+
for (const panel of this.panels.values()) {
|
|
275
|
+
for (const [path, shortcut] of Object.entries(panel.shortcuts)) {
|
|
276
|
+
if ((shortcut.interaction ?? "scroll") !== "scroll-only") continue;
|
|
277
|
+
const control = this.findControlByPath(panel.controls, path);
|
|
278
|
+
if (control) {
|
|
279
|
+
results.push({ panelId: panel.id, path, control, shortcut });
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return results;
|
|
284
|
+
}
|
|
285
|
+
findControlByPath(controls, path) {
|
|
286
|
+
for (const control of controls) {
|
|
287
|
+
if (control.path === path) return control;
|
|
288
|
+
if (control.type === "folder" && control.children) {
|
|
289
|
+
const found = this.findControlByPath(control.children, path);
|
|
290
|
+
if (found) return found;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
notify(panelId) {
|
|
296
|
+
this.listeners.get(panelId)?.forEach((fn) => fn());
|
|
297
|
+
}
|
|
298
|
+
notifyGlobal() {
|
|
299
|
+
this.globalListeners.forEach((fn) => fn());
|
|
300
|
+
}
|
|
301
|
+
initTransitionModes(config, prefix, values) {
|
|
302
|
+
for (const [key, value] of Object.entries(config)) {
|
|
303
|
+
if (key === "_collapsed") continue;
|
|
304
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
305
|
+
if (this.isEasingConfig(value)) {
|
|
306
|
+
values[`${path}.__mode`] = "easing";
|
|
307
|
+
} else if (this.isSpringConfig(value)) {
|
|
308
|
+
const hasPhysics = value.stiffness !== void 0 || value.damping !== void 0 || value.mass !== void 0;
|
|
309
|
+
const hasTime = value.visualDuration !== void 0 || value.bounce !== void 0;
|
|
310
|
+
values[`${path}.__mode`] = hasPhysics && !hasTime ? "advanced" : "simple";
|
|
311
|
+
} else if (typeof value === "object" && value !== null && !Array.isArray(value) && !this.isActionConfig(value) && !this.isSelectConfig(value) && !this.isColorConfig(value) && !this.isTextConfig(value)) {
|
|
312
|
+
this.initTransitionModes(value, path, values);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
parseConfig(config, prefix, shortcuts) {
|
|
317
|
+
const controls = [];
|
|
318
|
+
for (const [key, value] of Object.entries(config)) {
|
|
319
|
+
if (key === "_collapsed") continue;
|
|
320
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
321
|
+
const label = this.formatLabel(key);
|
|
322
|
+
const shortcut = shortcuts?.[path];
|
|
323
|
+
if (Array.isArray(value) && value.length <= 4 && typeof value[0] === "number") {
|
|
324
|
+
controls.push({
|
|
325
|
+
type: "slider",
|
|
326
|
+
path,
|
|
327
|
+
label,
|
|
328
|
+
min: value[1],
|
|
329
|
+
max: value[2],
|
|
330
|
+
step: value[3] ?? this.inferStep(value[1], value[2]),
|
|
331
|
+
shortcut
|
|
332
|
+
});
|
|
333
|
+
} else if (typeof value === "number") {
|
|
334
|
+
const { min, max, step } = this.inferRange(value);
|
|
335
|
+
controls.push({ type: "slider", path, label, min, max, step, shortcut });
|
|
336
|
+
} else if (typeof value === "boolean") {
|
|
337
|
+
controls.push({ type: "toggle", path, label, shortcut });
|
|
338
|
+
} else if (this.isSpringConfig(value) || this.isEasingConfig(value)) {
|
|
339
|
+
controls.push({ type: "transition", path, label });
|
|
340
|
+
} else if (this.isActionConfig(value)) {
|
|
341
|
+
controls.push({ type: "action", path, label: value.label || label });
|
|
342
|
+
} else if (this.isSelectConfig(value)) {
|
|
343
|
+
controls.push({ type: "select", path, label, options: value.options });
|
|
344
|
+
} else if (this.isColorConfig(value)) {
|
|
345
|
+
controls.push({ type: "color", path, label });
|
|
346
|
+
} else if (this.isTextConfig(value)) {
|
|
347
|
+
controls.push({ type: "text", path, label, placeholder: value.placeholder });
|
|
348
|
+
} else if (typeof value === "string") {
|
|
349
|
+
if (this.isHexColor(value)) {
|
|
350
|
+
controls.push({ type: "color", path, label });
|
|
351
|
+
} else {
|
|
352
|
+
controls.push({ type: "text", path, label });
|
|
353
|
+
}
|
|
354
|
+
} else if (typeof value === "object" && value !== null) {
|
|
355
|
+
const folderConfig = value;
|
|
356
|
+
const defaultOpen = "_collapsed" in folderConfig ? !folderConfig._collapsed : true;
|
|
357
|
+
controls.push({
|
|
358
|
+
type: "folder",
|
|
359
|
+
path,
|
|
360
|
+
label,
|
|
361
|
+
defaultOpen,
|
|
362
|
+
children: this.parseConfig(folderConfig, path, shortcuts)
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return controls;
|
|
367
|
+
}
|
|
368
|
+
flattenValues(config, prefix) {
|
|
369
|
+
const values = {};
|
|
370
|
+
for (const [key, value] of Object.entries(config)) {
|
|
371
|
+
if (key === "_collapsed") continue;
|
|
372
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
373
|
+
if (Array.isArray(value) && value.length <= 4 && typeof value[0] === "number") {
|
|
374
|
+
values[path] = value[0];
|
|
375
|
+
} else if (typeof value === "number" || typeof value === "boolean" || typeof value === "string") {
|
|
376
|
+
values[path] = value;
|
|
377
|
+
} else if (this.isSpringConfig(value) || this.isEasingConfig(value)) {
|
|
378
|
+
values[path] = value;
|
|
379
|
+
} else if (this.isActionConfig(value)) {
|
|
380
|
+
values[path] = value;
|
|
381
|
+
} else if (this.isSelectConfig(value)) {
|
|
382
|
+
const firstOption = value.options[0];
|
|
383
|
+
const firstValue = typeof firstOption === "string" ? firstOption : firstOption.value;
|
|
384
|
+
values[path] = value.default ?? firstValue;
|
|
385
|
+
} else if (this.isColorConfig(value)) {
|
|
386
|
+
values[path] = value.default ?? "#000000";
|
|
387
|
+
} else if (this.isTextConfig(value)) {
|
|
388
|
+
values[path] = value.default ?? "";
|
|
389
|
+
} else if (typeof value === "object" && value !== null) {
|
|
390
|
+
Object.assign(values, this.flattenValues(value, path));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return values;
|
|
394
|
+
}
|
|
395
|
+
isSpringConfig(value) {
|
|
396
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === "spring";
|
|
397
|
+
}
|
|
398
|
+
isEasingConfig(value) {
|
|
399
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === "easing";
|
|
400
|
+
}
|
|
401
|
+
isActionConfig(value) {
|
|
402
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === "action";
|
|
403
|
+
}
|
|
404
|
+
isSelectConfig(value) {
|
|
405
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === "select" && "options" in value && Array.isArray(value.options);
|
|
406
|
+
}
|
|
407
|
+
isColorConfig(value) {
|
|
408
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === "color";
|
|
409
|
+
}
|
|
410
|
+
isTextConfig(value) {
|
|
411
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === "text";
|
|
412
|
+
}
|
|
413
|
+
isHexColor(value) {
|
|
414
|
+
return /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/.test(value);
|
|
415
|
+
}
|
|
416
|
+
formatLabel(key) {
|
|
417
|
+
return key.replace(/([A-Z])/g, " $1").replace(/^./, (str) => str.toUpperCase()).trim();
|
|
418
|
+
}
|
|
419
|
+
inferRange(value) {
|
|
420
|
+
if (value >= 0 && value <= 1) {
|
|
421
|
+
return { min: 0, max: 1, step: 0.01 };
|
|
422
|
+
} else if (value >= 0 && value <= 10) {
|
|
423
|
+
return { min: 0, max: value * 3 || 10, step: 0.1 };
|
|
424
|
+
} else if (value >= 0 && value <= 100) {
|
|
425
|
+
return { min: 0, max: value * 3 || 100, step: 1 };
|
|
426
|
+
} else if (value >= 0) {
|
|
427
|
+
return { min: 0, max: value * 3 || 1e3, step: 10 };
|
|
428
|
+
} else {
|
|
429
|
+
return { min: value * 3, max: -value * 3, step: 1 };
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
inferStep(min, max) {
|
|
433
|
+
const range = max - min;
|
|
434
|
+
if (range <= 1) return 0.01;
|
|
435
|
+
if (range <= 10) return 0.1;
|
|
436
|
+
if (range <= 100) return 1;
|
|
437
|
+
return 10;
|
|
438
|
+
}
|
|
439
|
+
normalizePreservedValue(existingValue, defaultValue, control) {
|
|
440
|
+
if (existingValue === void 0 || !control) {
|
|
441
|
+
return defaultValue;
|
|
442
|
+
}
|
|
443
|
+
switch (control.type) {
|
|
444
|
+
case "slider": {
|
|
445
|
+
if (typeof existingValue !== "number" || typeof defaultValue !== "number") {
|
|
446
|
+
return defaultValue;
|
|
447
|
+
}
|
|
448
|
+
const min = control.min ?? Number.NEGATIVE_INFINITY;
|
|
449
|
+
const max = control.max ?? Number.POSITIVE_INFINITY;
|
|
450
|
+
const clamped = Math.min(max, Math.max(min, existingValue));
|
|
451
|
+
if (typeof control.step !== "number" || control.step <= 0) {
|
|
452
|
+
return clamped;
|
|
453
|
+
}
|
|
454
|
+
return this.roundToStep(clamped, min, max, control.step);
|
|
455
|
+
}
|
|
456
|
+
case "toggle":
|
|
457
|
+
return typeof existingValue === "boolean" ? existingValue : defaultValue;
|
|
458
|
+
case "select": {
|
|
459
|
+
if (typeof existingValue !== "string") {
|
|
460
|
+
return defaultValue;
|
|
461
|
+
}
|
|
462
|
+
const options = control.options ?? [];
|
|
463
|
+
const validValues = new Set(options.map((option) => typeof option === "string" ? option : option.value));
|
|
464
|
+
return validValues.has(existingValue) ? existingValue : defaultValue;
|
|
465
|
+
}
|
|
466
|
+
case "color":
|
|
467
|
+
case "text":
|
|
468
|
+
return typeof existingValue === "string" ? existingValue : defaultValue;
|
|
469
|
+
case "transition":
|
|
470
|
+
if (this.isSpringConfig(defaultValue)) {
|
|
471
|
+
return this.isSpringConfig(existingValue) ? existingValue : defaultValue;
|
|
472
|
+
}
|
|
473
|
+
if (this.isEasingConfig(defaultValue)) {
|
|
474
|
+
return this.isEasingConfig(existingValue) ? existingValue : defaultValue;
|
|
475
|
+
}
|
|
476
|
+
return defaultValue;
|
|
477
|
+
case "action":
|
|
478
|
+
return defaultValue;
|
|
479
|
+
default:
|
|
480
|
+
return defaultValue;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
roundToStep(value, min, max, step) {
|
|
484
|
+
const snapped = min + Math.round((value - min) / step) * step;
|
|
485
|
+
const clamped = Math.min(max, Math.max(min, snapped));
|
|
486
|
+
const precision = this.stepPrecision(step);
|
|
487
|
+
return Number(clamped.toFixed(precision));
|
|
488
|
+
}
|
|
489
|
+
stepPrecision(step) {
|
|
490
|
+
const text = String(step);
|
|
491
|
+
const decimalIndex = text.indexOf(".");
|
|
492
|
+
return decimalIndex === -1 ? 0 : text.length - decimalIndex - 1;
|
|
493
|
+
}
|
|
494
|
+
mapControlsByPath(controls) {
|
|
495
|
+
const map = /* @__PURE__ */ new Map();
|
|
496
|
+
const visit = (nodes) => {
|
|
497
|
+
for (const node of nodes) {
|
|
498
|
+
if (node.type === "folder" && node.children) {
|
|
499
|
+
visit(node.children);
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
map.set(node.path, node);
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
visit(controls);
|
|
506
|
+
return map;
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
var DialStore = new DialStoreClass();
|
|
510
|
+
|
|
511
|
+
// src/vue/useDialKit.ts
|
|
512
|
+
var dialKitInstance = 0;
|
|
513
|
+
function useDialKit(name, config, options) {
|
|
514
|
+
const panelId = `${name}-${++dialKitInstance}`;
|
|
515
|
+
const configRef = (0, import_vue.shallowRef)(config);
|
|
516
|
+
const onActionRef = (0, import_vue.ref)(options?.onAction);
|
|
517
|
+
const shortcutsRef = (0, import_vue.shallowRef)(options?.shortcuts);
|
|
518
|
+
const values = (0, import_vue.ref)(DialStore.getValues(panelId));
|
|
519
|
+
const mounted = (0, import_vue.ref)(false);
|
|
520
|
+
const serializedConfig = (0, import_vue.computed)(() => JSON.stringify(config));
|
|
521
|
+
const serializedShortcuts = (0, import_vue.computed)(() => JSON.stringify(options?.shortcuts));
|
|
522
|
+
let unsubscribeValues;
|
|
523
|
+
let unsubscribeActions;
|
|
524
|
+
const register = () => {
|
|
525
|
+
DialStore.registerPanel(panelId, name, configRef.value, shortcutsRef.value);
|
|
526
|
+
values.value = DialStore.getValues(panelId);
|
|
527
|
+
unsubscribeValues = DialStore.subscribe(panelId, () => {
|
|
528
|
+
values.value = DialStore.getValues(panelId);
|
|
529
|
+
});
|
|
530
|
+
unsubscribeActions = DialStore.subscribeActions(panelId, (action) => {
|
|
531
|
+
onActionRef.value?.(action);
|
|
532
|
+
});
|
|
533
|
+
};
|
|
534
|
+
(0, import_vue.watch)(() => options?.onAction, (next) => {
|
|
535
|
+
onActionRef.value = next;
|
|
536
|
+
});
|
|
537
|
+
(0, import_vue.watch)(() => options?.shortcuts, (next) => {
|
|
538
|
+
shortcutsRef.value = next;
|
|
539
|
+
});
|
|
540
|
+
(0, import_vue.watch)([serializedConfig, serializedShortcuts], () => {
|
|
541
|
+
configRef.value = config;
|
|
542
|
+
shortcutsRef.value = options?.shortcuts;
|
|
543
|
+
if (mounted.value) {
|
|
544
|
+
DialStore.updatePanel(panelId, name, configRef.value, shortcutsRef.value);
|
|
545
|
+
values.value = DialStore.getValues(panelId);
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
(0, import_vue.onMounted)(register);
|
|
549
|
+
(0, import_vue.onMounted)(() => {
|
|
550
|
+
mounted.value = true;
|
|
551
|
+
});
|
|
552
|
+
(0, import_vue.onUnmounted)(() => {
|
|
553
|
+
unsubscribeValues?.();
|
|
554
|
+
unsubscribeActions?.();
|
|
555
|
+
DialStore.unregisterPanel(panelId);
|
|
556
|
+
});
|
|
557
|
+
return (0, import_vue.computed)(() => buildResolvedValues(configRef.value, values.value, ""));
|
|
558
|
+
}
|
|
559
|
+
function buildResolvedValues(config, flatValues, prefix) {
|
|
560
|
+
const result = {};
|
|
561
|
+
for (const [key, configValue] of Object.entries(config)) {
|
|
562
|
+
if (key === "_collapsed") continue;
|
|
563
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
564
|
+
if (Array.isArray(configValue) && configValue.length <= 4 && typeof configValue[0] === "number") {
|
|
565
|
+
result[key] = flatValues[path] ?? configValue[0];
|
|
566
|
+
} else if (typeof configValue === "number" || typeof configValue === "boolean" || typeof configValue === "string") {
|
|
567
|
+
result[key] = flatValues[path] ?? configValue;
|
|
568
|
+
} else if (isSpringConfig(configValue) || isEasingConfig(configValue)) {
|
|
569
|
+
result[key] = flatValues[path] ?? configValue;
|
|
570
|
+
} else if (isActionConfig(configValue)) {
|
|
571
|
+
result[key] = flatValues[path] ?? configValue;
|
|
572
|
+
} else if (isSelectConfig(configValue)) {
|
|
573
|
+
const defaultValue = configValue.default ?? getFirstOptionValue(configValue.options);
|
|
574
|
+
result[key] = flatValues[path] ?? defaultValue;
|
|
575
|
+
} else if (isColorConfig(configValue)) {
|
|
576
|
+
result[key] = flatValues[path] ?? configValue.default ?? "#000000";
|
|
577
|
+
} else if (isTextConfig(configValue)) {
|
|
578
|
+
result[key] = flatValues[path] ?? configValue.default ?? "";
|
|
579
|
+
} else if (typeof configValue === "object" && configValue !== null) {
|
|
580
|
+
result[key] = buildResolvedValues(configValue, flatValues, path);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return result;
|
|
584
|
+
}
|
|
585
|
+
function hasType(value, type) {
|
|
586
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === type;
|
|
587
|
+
}
|
|
588
|
+
function isSpringConfig(value) {
|
|
589
|
+
return hasType(value, "spring");
|
|
590
|
+
}
|
|
591
|
+
function isEasingConfig(value) {
|
|
592
|
+
return hasType(value, "easing");
|
|
593
|
+
}
|
|
594
|
+
function isActionConfig(value) {
|
|
595
|
+
return hasType(value, "action");
|
|
596
|
+
}
|
|
597
|
+
function isSelectConfig(value) {
|
|
598
|
+
return hasType(value, "select") && "options" in value && Array.isArray(value.options);
|
|
599
|
+
}
|
|
600
|
+
function isColorConfig(value) {
|
|
601
|
+
return hasType(value, "color");
|
|
602
|
+
}
|
|
603
|
+
function isTextConfig(value) {
|
|
604
|
+
return hasType(value, "text");
|
|
605
|
+
}
|
|
606
|
+
function getFirstOptionValue(options) {
|
|
607
|
+
const first = options[0];
|
|
608
|
+
return typeof first === "string" ? first : first.value;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// src/vue/directives/dialkit.ts
|
|
612
|
+
var import_vue17 = require("vue");
|
|
613
|
+
|
|
614
|
+
// src/vue/components/DialRoot.ts
|
|
615
|
+
var import_vue16 = require("vue");
|
|
616
|
+
|
|
617
|
+
// src/vue/components/Panel.ts
|
|
618
|
+
var import_vue15 = require("vue");
|
|
619
|
+
var import_motion_v5 = require("motion-v");
|
|
620
|
+
|
|
621
|
+
// src/icons.ts
|
|
622
|
+
var ICON_CHEVRON = "M6 9.5L12 15.5L18 9.5";
|
|
623
|
+
var ICON_CHECK = "M5 12.75L10 19L19 5";
|
|
624
|
+
var ICON_CLIPBOARD = {
|
|
625
|
+
board: "M8 6C8 4.34315 9.34315 3 11 3H13C14.6569 3 16 4.34315 16 6V7H8V6Z",
|
|
626
|
+
sparkle: "M19.2405 16.1852L18.5436 14.3733C18.4571 14.1484 18.241 14 18 14C17.759 14 17.5429 14.1484 17.4564 14.3733L16.7595 16.1852C16.658 16.4493 16.4493 16.658 16.1852 16.7595L14.3733 17.4564C14.1484 17.5429 14 17.759 14 18C14 18.241 14.1484 18.4571 14.3733 18.5436L16.1852 19.2405C16.4493 19.342 16.658 19.5507 16.7595 19.8148L17.4564 21.6267C17.5429 21.8516 17.759 22 18 22C18.241 22 18.4571 21.8516 18.5436 21.6267L19.2405 19.8148C19.342 19.5507 19.5507 19.342 19.8148 19.2405L21.6267 18.5436C21.8516 18.4571 22 18.241 22 18C22 17.759 21.8516 17.5429 21.6267 17.4564L19.8148 16.7595C19.5507 16.658 19.342 16.4493 19.2405 16.1852Z",
|
|
627
|
+
body: "M16 5H17C18.6569 5 20 6.34315 20 8V11M8 5H7C5.34315 5 4 6.34315 4 8V18C4 19.6569 5.34315 21 7 21H12"
|
|
628
|
+
};
|
|
629
|
+
var ICON_ADD_PRESET = [
|
|
630
|
+
"M4 6H20",
|
|
631
|
+
"M4 12H10",
|
|
632
|
+
"M15 15L21 15",
|
|
633
|
+
"M18 12V18",
|
|
634
|
+
"M4 18H10"
|
|
635
|
+
];
|
|
636
|
+
var ICON_TRASH = [
|
|
637
|
+
"M5 6.5L5.80734 18.2064C5.91582 19.7794 7.22348 21 8.80023 21H15.1998C16.7765 21 18.0842 19.7794 18.1927 18.2064L19 6.5",
|
|
638
|
+
"M10 11V16",
|
|
639
|
+
"M14 11V16",
|
|
640
|
+
"M3.5 6H20.5",
|
|
641
|
+
"M8.07092 5.74621C8.42348 3.89745 10.0485 2.5 12 2.5C13.9515 2.5 15.5765 3.89745 15.9291 5.74621"
|
|
642
|
+
];
|
|
643
|
+
var ICON_PANEL = {
|
|
644
|
+
path: "M6.84766 11.75C6.78583 11.9899 6.75 12.2408 6.75 12.5C6.75 12.7592 6.78583 13.0101 6.84766 13.25H2C1.58579 13.25 1.25 12.9142 1.25 12.5C1.25 12.0858 1.58579 11.75 2 11.75H6.84766ZM14 11.75C14.4142 11.75 14.75 12.0858 14.75 12.5C14.75 12.9142 14.4142 13.25 14 13.25H12.6523C12.7142 13.0101 12.75 12.7592 12.75 12.5C12.75 12.2408 12.7142 11.9899 12.6523 11.75H14ZM3.09766 7.25C3.03583 7.48994 3 7.74075 3 8C3 8.25925 3.03583 8.51006 3.09766 8.75H2C1.58579 8.75 1.25 8.41421 1.25 8C1.25 7.58579 1.58579 7.25 2 7.25H3.09766ZM14 7.25C14.4142 7.25 14.75 7.58579 14.75 8C14.75 8.41421 14.4142 8.75 14 8.75H8.90234C8.96417 8.51006 9 8.25925 9 8C9 7.74075 8.96417 7.48994 8.90234 7.25H14ZM7.59766 2.75C7.53583 2.98994 7.5 3.24075 7.5 3.5C7.5 3.75925 7.53583 4.01006 7.59766 4.25H2C1.58579 4.25 1.25 3.91421 1.25 3.5C1.25 3.08579 1.58579 2.75 2 2.75H7.59766ZM14 2.75C14.4142 2.75 14.75 3.08579 14.75 3.5C14.75 3.91421 14.4142 4.25 14 4.25H13.4023C13.4642 4.01006 13.5 3.75925 13.5 3.5C13.5 3.24075 13.4642 2.98994 13.4023 2.75H14Z",
|
|
645
|
+
circles: [
|
|
646
|
+
{ cx: "6", cy: "8", r: "0.998596" },
|
|
647
|
+
{ cx: "10.4999", cy: "3.5", r: "0.998657" },
|
|
648
|
+
{ cx: "9.75015", cy: "12.5", r: "0.997986" }
|
|
649
|
+
]
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
// src/vue/components/Folder.ts
|
|
653
|
+
var import_vue2 = require("vue");
|
|
654
|
+
var import_motion_v = require("motion-v");
|
|
655
|
+
var Folder = (0, import_vue2.defineComponent)({
|
|
656
|
+
name: "DialKitFolder",
|
|
657
|
+
props: {
|
|
658
|
+
title: { type: String, required: true },
|
|
659
|
+
defaultOpen: { type: Boolean, default: true },
|
|
660
|
+
isRoot: { type: Boolean, default: false },
|
|
661
|
+
inline: { type: Boolean, default: false },
|
|
662
|
+
toolbar: {
|
|
663
|
+
type: null,
|
|
664
|
+
required: false,
|
|
665
|
+
default: null
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
emits: ["openChange"],
|
|
669
|
+
setup(props, { emit, slots }) {
|
|
670
|
+
const isOpen = (0, import_vue2.ref)(props.defaultOpen);
|
|
671
|
+
const isCollapsed = (0, import_vue2.ref)(!props.defaultOpen);
|
|
672
|
+
const contentRef = (0, import_vue2.ref)(null);
|
|
673
|
+
const contentHeight = (0, import_vue2.ref)(void 0);
|
|
674
|
+
const windowHeight = (0, import_vue2.ref)(typeof window !== "undefined" ? window.innerHeight : 800);
|
|
675
|
+
let resizeHandler = null;
|
|
676
|
+
if (props.isRoot) {
|
|
677
|
+
resizeHandler = () => {
|
|
678
|
+
windowHeight.value = window.innerHeight;
|
|
679
|
+
};
|
|
680
|
+
window.addEventListener("resize", resizeHandler);
|
|
681
|
+
}
|
|
682
|
+
(0, import_vue2.onUnmounted)(() => {
|
|
683
|
+
if (resizeHandler) window.removeEventListener("resize", resizeHandler);
|
|
684
|
+
});
|
|
685
|
+
const handleToggle = () => {
|
|
686
|
+
if (props.inline && props.isRoot) return;
|
|
687
|
+
const next = !isOpen.value;
|
|
688
|
+
isOpen.value = next;
|
|
689
|
+
isCollapsed.value = !next;
|
|
690
|
+
emit("openChange", next);
|
|
691
|
+
};
|
|
692
|
+
let ro = null;
|
|
693
|
+
(0, import_vue2.onMounted)(() => {
|
|
694
|
+
if (!props.isRoot || typeof ResizeObserver === "undefined") return;
|
|
695
|
+
const el = contentRef.value;
|
|
696
|
+
if (!el) return;
|
|
697
|
+
ro = new ResizeObserver(() => {
|
|
698
|
+
if (isOpen.value) {
|
|
699
|
+
const next = el.offsetHeight;
|
|
700
|
+
if (contentHeight.value !== next) {
|
|
701
|
+
contentHeight.value = next;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
ro.observe(el);
|
|
706
|
+
if (isOpen.value) {
|
|
707
|
+
contentHeight.value = el.offsetHeight;
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
(0, import_vue2.onUnmounted)(() => {
|
|
711
|
+
ro?.disconnect();
|
|
712
|
+
});
|
|
713
|
+
const renderHeader = () => (0, import_vue2.h)("div", {
|
|
714
|
+
class: `dialkit-folder-header ${props.isRoot ? "dialkit-panel-header" : ""}`,
|
|
715
|
+
onClick: handleToggle
|
|
716
|
+
}, [
|
|
717
|
+
(0, import_vue2.h)("div", { class: "dialkit-folder-header-top" }, [
|
|
718
|
+
props.isRoot ? isOpen.value ? (0, import_vue2.h)("div", { class: "dialkit-folder-title-row" }, [
|
|
719
|
+
(0, import_vue2.h)("span", { class: "dialkit-folder-title dialkit-folder-title-root" }, props.title)
|
|
720
|
+
]) : null : (0, import_vue2.h)("div", { class: "dialkit-folder-title-row" }, [
|
|
721
|
+
(0, import_vue2.h)("span", { class: "dialkit-folder-title" }, props.title)
|
|
722
|
+
]),
|
|
723
|
+
props.isRoot && !props.inline ? (0, import_vue2.h)("svg", { class: "dialkit-panel-icon", viewBox: "0 0 16 16", fill: "none" }, [
|
|
724
|
+
(0, import_vue2.h)("path", {
|
|
725
|
+
opacity: "0.5",
|
|
726
|
+
d: ICON_PANEL.path,
|
|
727
|
+
fill: "currentColor"
|
|
728
|
+
}),
|
|
729
|
+
...ICON_PANEL.circles.map((c) => (0, import_vue2.h)("circle", { cx: c.cx, cy: c.cy, r: c.r, fill: "currentColor", stroke: "currentColor", "stroke-width": "1.25" }))
|
|
730
|
+
]) : null,
|
|
731
|
+
!props.isRoot ? (0, import_vue2.h)(import_motion_v.motion.svg, {
|
|
732
|
+
class: "dialkit-folder-icon",
|
|
733
|
+
viewBox: "0 0 24 24",
|
|
734
|
+
fill: "none",
|
|
735
|
+
stroke: "currentColor",
|
|
736
|
+
"stroke-width": "2.5",
|
|
737
|
+
"stroke-linecap": "round",
|
|
738
|
+
"stroke-linejoin": "round",
|
|
739
|
+
initial: false,
|
|
740
|
+
animate: { rotate: isOpen.value ? 0 : 180 },
|
|
741
|
+
transition: { type: "spring", visualDuration: 0.35, bounce: 0.15 }
|
|
742
|
+
}, [(0, import_vue2.h)("path", { d: ICON_CHEVRON })]) : null
|
|
743
|
+
]),
|
|
744
|
+
props.isRoot && props.toolbar && isOpen.value ? (0, import_vue2.h)("div", { class: "dialkit-panel-toolbar", onClick: (event) => event.stopPropagation() }, [props.toolbar()]) : null
|
|
745
|
+
]);
|
|
746
|
+
const renderChildren = () => (0, import_vue2.h)("div", { class: "dialkit-folder-inner" }, slots.default ? slots.default() : []);
|
|
747
|
+
const renderContent = () => {
|
|
748
|
+
if (props.isRoot) {
|
|
749
|
+
return isOpen.value ? (0, import_vue2.h)("div", { class: "dialkit-folder-content" }, [renderChildren()]) : null;
|
|
750
|
+
}
|
|
751
|
+
return (0, import_vue2.h)(import_motion_v.AnimatePresence, { initial: false }, {
|
|
752
|
+
default: () => isOpen.value ? [(0, import_vue2.h)(import_motion_v.motion.div, {
|
|
753
|
+
key: "dialkit-folder-content",
|
|
754
|
+
class: "dialkit-folder-content",
|
|
755
|
+
initial: { height: 0, opacity: 0 },
|
|
756
|
+
animate: { height: "auto", opacity: 1 },
|
|
757
|
+
exit: { height: 0, opacity: 0 },
|
|
758
|
+
transition: { type: "spring", visualDuration: 0.35, bounce: 0.1 },
|
|
759
|
+
style: { clipPath: "inset(0 -20px)" }
|
|
760
|
+
}, [renderChildren()])] : []
|
|
761
|
+
});
|
|
762
|
+
};
|
|
763
|
+
const folderContent = () => (0, import_vue2.h)("div", {
|
|
764
|
+
ref: props.isRoot ? contentRef : void 0,
|
|
765
|
+
class: `dialkit-folder ${props.isRoot ? "dialkit-folder-root" : ""}`
|
|
766
|
+
}, [
|
|
767
|
+
renderHeader(),
|
|
768
|
+
renderContent()
|
|
769
|
+
]);
|
|
770
|
+
return () => {
|
|
771
|
+
if (props.isRoot) {
|
|
772
|
+
if (props.inline) {
|
|
773
|
+
return (0, import_vue2.h)("div", { class: "dialkit-panel-inner dialkit-panel-inline" }, [folderContent()]);
|
|
774
|
+
}
|
|
775
|
+
const panelStyle = isOpen.value ? {
|
|
776
|
+
width: 280,
|
|
777
|
+
height: contentHeight.value !== void 0 ? Math.min(contentHeight.value + 10, windowHeight.value - 32) : "auto",
|
|
778
|
+
borderRadius: 14,
|
|
779
|
+
boxShadow: "var(--dial-shadow)",
|
|
780
|
+
cursor: void 0,
|
|
781
|
+
overflowY: "auto"
|
|
782
|
+
} : {
|
|
783
|
+
width: 42,
|
|
784
|
+
height: 42,
|
|
785
|
+
borderRadius: 21,
|
|
786
|
+
boxShadow: "var(--dial-shadow-collapsed)",
|
|
787
|
+
overflow: "hidden",
|
|
788
|
+
cursor: "pointer"
|
|
789
|
+
};
|
|
790
|
+
return (0, import_vue2.h)(import_motion_v.motion.div, {
|
|
791
|
+
class: "dialkit-panel-inner",
|
|
792
|
+
style: panelStyle,
|
|
793
|
+
onClick: !isOpen.value ? handleToggle : void 0,
|
|
794
|
+
"data-collapsed": String(isCollapsed.value),
|
|
795
|
+
whilePress: !isOpen.value ? { scale: 0.9 } : void 0,
|
|
796
|
+
transition: { type: "spring", visualDuration: 0.15, bounce: 0.3 }
|
|
797
|
+
}, [folderContent()]);
|
|
798
|
+
}
|
|
799
|
+
return folderContent();
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
// src/vue/components/Slider.ts
|
|
805
|
+
var import_vue3 = require("vue");
|
|
806
|
+
var import_motion_v2 = require("motion-v");
|
|
807
|
+
|
|
808
|
+
// src/shortcut-utils.ts
|
|
809
|
+
function decimalsForStep(step) {
|
|
810
|
+
const s = step.toString();
|
|
811
|
+
const dot = s.indexOf(".");
|
|
812
|
+
return dot === -1 ? 0 : s.length - dot - 1;
|
|
813
|
+
}
|
|
814
|
+
function roundValue(val, step) {
|
|
815
|
+
const raw = Math.round(val / step) * step;
|
|
816
|
+
return parseFloat(raw.toFixed(decimalsForStep(step)));
|
|
817
|
+
}
|
|
818
|
+
function getEffectiveStep(control, shortcut) {
|
|
819
|
+
const min = control.min ?? 0;
|
|
820
|
+
const max = control.max ?? 1;
|
|
821
|
+
const range = max - min;
|
|
822
|
+
const mode = shortcut.mode ?? "normal";
|
|
823
|
+
return mode === "fine" ? range * 0.01 : mode === "coarse" ? range * 0.1 : control.step ?? 1;
|
|
824
|
+
}
|
|
825
|
+
function applySliderDelta(panelId, path, control, effectiveStep, direction) {
|
|
826
|
+
const currentValue = DialStore.getValue(panelId, path);
|
|
827
|
+
const min = control.min ?? 0;
|
|
828
|
+
const max = control.max ?? 1;
|
|
829
|
+
const newValue = Math.max(min, Math.min(max, currentValue + direction * effectiveStep));
|
|
830
|
+
DialStore.updateValue(panelId, path, roundValue(newValue, effectiveStep));
|
|
831
|
+
}
|
|
832
|
+
function snapToDecile(rawValue, min, max) {
|
|
833
|
+
const normalized = (rawValue - min) / (max - min);
|
|
834
|
+
const nearest = Math.round(normalized * 10) / 10;
|
|
835
|
+
if (Math.abs(normalized - nearest) <= 0.03125) {
|
|
836
|
+
return min + nearest * (max - min);
|
|
837
|
+
}
|
|
838
|
+
return rawValue;
|
|
839
|
+
}
|
|
840
|
+
function isInputFocused() {
|
|
841
|
+
const el = document.activeElement;
|
|
842
|
+
if (!el) return false;
|
|
843
|
+
const tag = el.tagName;
|
|
844
|
+
if (tag === "INPUT" || tag === "TEXTAREA") return true;
|
|
845
|
+
if (el.contentEditable === "true") return true;
|
|
846
|
+
return false;
|
|
847
|
+
}
|
|
848
|
+
function getActiveModifier(e) {
|
|
849
|
+
if (e.altKey) return "alt";
|
|
850
|
+
if (e.shiftKey) return "shift";
|
|
851
|
+
if (e.metaKey) return "meta";
|
|
852
|
+
return void 0;
|
|
853
|
+
}
|
|
854
|
+
function findControl(controls, path) {
|
|
855
|
+
for (const control of controls) {
|
|
856
|
+
if (control.path === path) return control;
|
|
857
|
+
if (control.type === "folder" && control.children) {
|
|
858
|
+
const found = findControl(control.children, path);
|
|
859
|
+
if (found) return found;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
return null;
|
|
863
|
+
}
|
|
864
|
+
var DRAG_SENSITIVITY = 4;
|
|
865
|
+
function formatInteractionLabel(interaction) {
|
|
866
|
+
switch (interaction) {
|
|
867
|
+
case "drag":
|
|
868
|
+
return "Drag";
|
|
869
|
+
case "move":
|
|
870
|
+
return "Move";
|
|
871
|
+
case "scroll-only":
|
|
872
|
+
return "Scroll";
|
|
873
|
+
default:
|
|
874
|
+
return "Scroll";
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
function formatSliderShortcut(sc) {
|
|
878
|
+
const interaction = sc.interaction ?? "scroll";
|
|
879
|
+
const actionLabel = formatInteractionLabel(interaction);
|
|
880
|
+
if (!sc.key) return actionLabel;
|
|
881
|
+
const mod = formatModifier(sc.modifier);
|
|
882
|
+
return `${mod}${sc.key.toUpperCase()}+${actionLabel}`;
|
|
883
|
+
}
|
|
884
|
+
function formatToggleShortcut(sc) {
|
|
885
|
+
if (!sc.key) return "Press";
|
|
886
|
+
const mod = formatModifier(sc.modifier);
|
|
887
|
+
return `${mod}${sc.key.toUpperCase()}`;
|
|
888
|
+
}
|
|
889
|
+
function formatModifier(modifier) {
|
|
890
|
+
return modifier === "alt" ? "\u2325" : modifier === "shift" ? "\u21E7" : modifier === "meta" ? "\u2318" : "";
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
// src/vue/components/Slider.ts
|
|
894
|
+
var CLICK_THRESHOLD = 3;
|
|
895
|
+
var DEAD_ZONE = 32;
|
|
896
|
+
var MAX_CURSOR_RANGE = 200;
|
|
897
|
+
var MAX_STRETCH = 8;
|
|
898
|
+
var Slider = (0, import_vue3.defineComponent)({
|
|
899
|
+
name: "DialKitSlider",
|
|
900
|
+
props: {
|
|
901
|
+
label: { type: String, required: true },
|
|
902
|
+
value: { type: Number, required: true },
|
|
903
|
+
min: { type: Number, required: false },
|
|
904
|
+
max: { type: Number, required: false },
|
|
905
|
+
step: { type: Number, required: false },
|
|
906
|
+
unit: { type: String, required: false },
|
|
907
|
+
shortcut: { type: Object, default: void 0 },
|
|
908
|
+
shortcutActive: { type: Boolean, default: false }
|
|
909
|
+
},
|
|
910
|
+
emits: ["change"],
|
|
911
|
+
setup(props, { emit }) {
|
|
912
|
+
const min = (0, import_vue3.computed)(() => props.min ?? 0);
|
|
913
|
+
const max = (0, import_vue3.computed)(() => props.max ?? 1);
|
|
914
|
+
const step = (0, import_vue3.computed)(() => props.step ?? 0.01);
|
|
915
|
+
const wrapperRef = (0, import_vue3.ref)(null);
|
|
916
|
+
const trackRef = (0, import_vue3.ref)(null);
|
|
917
|
+
const fillRef = (0, import_vue3.ref)(null);
|
|
918
|
+
const handleRef = (0, import_vue3.ref)(null);
|
|
919
|
+
const labelRef = (0, import_vue3.ref)(null);
|
|
920
|
+
const valueSpanRef = (0, import_vue3.ref)(null);
|
|
921
|
+
const inputRef = (0, import_vue3.ref)(null);
|
|
922
|
+
const isInteracting = (0, import_vue3.ref)(false);
|
|
923
|
+
const isDragging = (0, import_vue3.ref)(false);
|
|
924
|
+
const isHovered = (0, import_vue3.ref)(false);
|
|
925
|
+
const isValueHovered = (0, import_vue3.ref)(false);
|
|
926
|
+
const isValueEditable = (0, import_vue3.ref)(false);
|
|
927
|
+
const showInput = (0, import_vue3.ref)(false);
|
|
928
|
+
const inputValue = (0, import_vue3.ref)("");
|
|
929
|
+
const fillPercent = (0, import_motion_v2.motionValue)((props.value - min.value) / (max.value - min.value) * 100);
|
|
930
|
+
const rubberStretchPx = (0, import_motion_v2.motionValue)(0);
|
|
931
|
+
const handleOpacityMv = (0, import_motion_v2.motionValue)(0);
|
|
932
|
+
const handleScaleXMv = (0, import_motion_v2.motionValue)(0.25);
|
|
933
|
+
const handleScaleYMv = (0, import_motion_v2.motionValue)(1);
|
|
934
|
+
const percentage = (0, import_vue3.computed)(() => (props.value - min.value) / (max.value - min.value) * 100);
|
|
935
|
+
const isActive = (0, import_vue3.computed)(() => isInteracting.value || isHovered.value);
|
|
936
|
+
const displayValue = (0, import_vue3.computed)(() => props.value.toFixed(decimalsForStep(step.value)));
|
|
937
|
+
let pointerDownPos = null;
|
|
938
|
+
let isClickFlag = true;
|
|
939
|
+
let wrapperRect = null;
|
|
940
|
+
let scaleVal = 1;
|
|
941
|
+
let hoverTimeout = null;
|
|
942
|
+
let snapAnim = null;
|
|
943
|
+
let rubberAnim = null;
|
|
944
|
+
let handleOpacityAnim = null;
|
|
945
|
+
let handleScaleXAnim = null;
|
|
946
|
+
let handleScaleYAnim = null;
|
|
947
|
+
const applyFillStyles = (pct) => {
|
|
948
|
+
if (fillRef.value) fillRef.value.style.width = `${pct}%`;
|
|
949
|
+
if (handleRef.value) handleRef.value.style.left = `max(5px, calc(${pct}% - 9px))`;
|
|
950
|
+
};
|
|
951
|
+
const applyRubberStyles = (stretch) => {
|
|
952
|
+
if (!trackRef.value) return;
|
|
953
|
+
trackRef.value.style.width = `calc(100% + ${Math.abs(stretch)}px)`;
|
|
954
|
+
trackRef.value.style.transform = `translateX(${stretch < 0 ? stretch : 0}px)`;
|
|
955
|
+
};
|
|
956
|
+
const applyHandleVisualStyles = () => {
|
|
957
|
+
if (!handleRef.value) return;
|
|
958
|
+
handleRef.value.style.opacity = String(handleOpacityMv.get());
|
|
959
|
+
handleRef.value.style.transform = `translateY(-50%) scaleX(${handleScaleXMv.get()}) scaleY(${handleScaleYMv.get()})`;
|
|
960
|
+
};
|
|
961
|
+
const positionToValue = (clientX) => {
|
|
962
|
+
if (!wrapperRect) return props.value;
|
|
963
|
+
const screenX = clientX - wrapperRect.left;
|
|
964
|
+
const sceneX = screenX / scaleVal;
|
|
965
|
+
const nativeWidth = wrapperRef.value ? wrapperRef.value.offsetWidth : wrapperRect.width;
|
|
966
|
+
const pct = Math.max(0, Math.min(1, sceneX / nativeWidth));
|
|
967
|
+
const rawValue = min.value + pct * (max.value - min.value);
|
|
968
|
+
return Math.max(min.value, Math.min(max.value, rawValue));
|
|
969
|
+
};
|
|
970
|
+
const percentFromValue = (value) => (value - min.value) / (max.value - min.value) * 100;
|
|
971
|
+
const computeRubberStretch = (clientX, sign) => {
|
|
972
|
+
if (!wrapperRect) return 0;
|
|
973
|
+
const distancePast = sign < 0 ? wrapperRect.left - clientX : clientX - wrapperRect.right;
|
|
974
|
+
const overflow = Math.max(0, distancePast - DEAD_ZONE);
|
|
975
|
+
return sign * MAX_STRETCH * Math.sqrt(Math.min(overflow / MAX_CURSOR_RANGE, 1));
|
|
976
|
+
};
|
|
977
|
+
const leftThreshold = () => {
|
|
978
|
+
const HANDLE_BUFFER = 8;
|
|
979
|
+
const LABEL_CSS_LEFT = 10;
|
|
980
|
+
const trackWidth = wrapperRef.value?.offsetWidth;
|
|
981
|
+
if (trackWidth && labelRef.value) {
|
|
982
|
+
return (LABEL_CSS_LEFT + labelRef.value.offsetWidth + HANDLE_BUFFER) / trackWidth * 100;
|
|
983
|
+
}
|
|
984
|
+
return 30;
|
|
985
|
+
};
|
|
986
|
+
const rightThreshold = () => {
|
|
987
|
+
const HANDLE_BUFFER = 8;
|
|
988
|
+
const VALUE_CSS_RIGHT = 10;
|
|
989
|
+
const trackWidth = wrapperRef.value?.offsetWidth;
|
|
990
|
+
if (trackWidth && valueSpanRef.value) {
|
|
991
|
+
return (trackWidth - VALUE_CSS_RIGHT - valueSpanRef.value.offsetWidth - HANDLE_BUFFER) / trackWidth * 100;
|
|
992
|
+
}
|
|
993
|
+
return 78;
|
|
994
|
+
};
|
|
995
|
+
const valueDodge = () => percentage.value < leftThreshold() || percentage.value > rightThreshold();
|
|
996
|
+
const handleOpacity = () => {
|
|
997
|
+
if (!isActive.value) return 0;
|
|
998
|
+
if (valueDodge()) return 0.1;
|
|
999
|
+
if (isDragging.value) return 0.9;
|
|
1000
|
+
return 0.5;
|
|
1001
|
+
};
|
|
1002
|
+
const animateHandleState = () => {
|
|
1003
|
+
const targetOpacity = handleOpacity();
|
|
1004
|
+
const targetScaleX = isActive.value ? 1 : 0.25;
|
|
1005
|
+
const targetScaleY = isActive.value && valueDodge() ? 0.75 : 1;
|
|
1006
|
+
handleOpacityAnim?.stop();
|
|
1007
|
+
handleScaleXAnim?.stop();
|
|
1008
|
+
handleScaleYAnim?.stop();
|
|
1009
|
+
handleOpacityAnim = (0, import_motion_v2.animate)(handleOpacityMv, targetOpacity, { duration: 0.15 });
|
|
1010
|
+
handleScaleXAnim = (0, import_motion_v2.animate)(handleScaleXMv, targetScaleX, {
|
|
1011
|
+
type: "spring",
|
|
1012
|
+
visualDuration: 0.25,
|
|
1013
|
+
bounce: 0.15
|
|
1014
|
+
});
|
|
1015
|
+
handleScaleYAnim = (0, import_motion_v2.animate)(handleScaleYMv, targetScaleY, {
|
|
1016
|
+
type: "spring",
|
|
1017
|
+
visualDuration: 0.2,
|
|
1018
|
+
bounce: 0.1
|
|
1019
|
+
});
|
|
1020
|
+
};
|
|
1021
|
+
const handlePointerDown = (event) => {
|
|
1022
|
+
if (showInput.value) return;
|
|
1023
|
+
event.preventDefault();
|
|
1024
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
1025
|
+
pointerDownPos = { x: event.clientX, y: event.clientY };
|
|
1026
|
+
isClickFlag = true;
|
|
1027
|
+
isInteracting.value = true;
|
|
1028
|
+
if (wrapperRef.value) {
|
|
1029
|
+
wrapperRect = wrapperRef.value.getBoundingClientRect();
|
|
1030
|
+
scaleVal = wrapperRect.width / wrapperRef.value.offsetWidth;
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
const handlePointerMove = (event) => {
|
|
1034
|
+
if (!isInteracting.value || !pointerDownPos) return;
|
|
1035
|
+
const dx = event.clientX - pointerDownPos.x;
|
|
1036
|
+
const dy = event.clientY - pointerDownPos.y;
|
|
1037
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
1038
|
+
if (isClickFlag && distance > CLICK_THRESHOLD) {
|
|
1039
|
+
isClickFlag = false;
|
|
1040
|
+
isDragging.value = true;
|
|
1041
|
+
}
|
|
1042
|
+
if (!isClickFlag) {
|
|
1043
|
+
if (wrapperRect) {
|
|
1044
|
+
if (event.clientX < wrapperRect.left) {
|
|
1045
|
+
rubberStretchPx.jump(computeRubberStretch(event.clientX, -1));
|
|
1046
|
+
} else if (event.clientX > wrapperRect.right) {
|
|
1047
|
+
rubberStretchPx.jump(computeRubberStretch(event.clientX, 1));
|
|
1048
|
+
} else {
|
|
1049
|
+
rubberStretchPx.jump(0);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
const nextValue = positionToValue(event.clientX);
|
|
1053
|
+
const nextPct = percentFromValue(nextValue);
|
|
1054
|
+
if (snapAnim) {
|
|
1055
|
+
snapAnim.stop();
|
|
1056
|
+
snapAnim = null;
|
|
1057
|
+
}
|
|
1058
|
+
fillPercent.jump(nextPct);
|
|
1059
|
+
emit("change", roundValue(nextValue, step.value));
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
const handlePointerUp = (event) => {
|
|
1063
|
+
if (!isInteracting.value) return;
|
|
1064
|
+
if (isClickFlag) {
|
|
1065
|
+
const rawValue = positionToValue(event.clientX);
|
|
1066
|
+
const discreteSteps2 = (max.value - min.value) / step.value;
|
|
1067
|
+
const snappedValue = discreteSteps2 <= 10 ? Math.max(min.value, Math.min(max.value, min.value + Math.round((rawValue - min.value) / step.value) * step.value)) : snapToDecile(rawValue, min.value, max.value);
|
|
1068
|
+
const nextPct = percentFromValue(snappedValue);
|
|
1069
|
+
snapAnim?.stop();
|
|
1070
|
+
snapAnim = (0, import_motion_v2.animate)(fillPercent, nextPct, {
|
|
1071
|
+
type: "spring",
|
|
1072
|
+
stiffness: 300,
|
|
1073
|
+
damping: 25,
|
|
1074
|
+
mass: 0.8,
|
|
1075
|
+
onComplete: () => {
|
|
1076
|
+
snapAnim = null;
|
|
1077
|
+
}
|
|
1078
|
+
});
|
|
1079
|
+
emit("change", roundValue(snappedValue, step.value));
|
|
1080
|
+
}
|
|
1081
|
+
if (rubberStretchPx.get() !== 0) {
|
|
1082
|
+
rubberAnim?.stop();
|
|
1083
|
+
rubberAnim = (0, import_motion_v2.animate)(rubberStretchPx, 0, {
|
|
1084
|
+
type: "spring",
|
|
1085
|
+
visualDuration: 0.35,
|
|
1086
|
+
bounce: 0.15
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
isInteracting.value = false;
|
|
1090
|
+
isDragging.value = false;
|
|
1091
|
+
pointerDownPos = null;
|
|
1092
|
+
};
|
|
1093
|
+
const handlePointerCancel = () => {
|
|
1094
|
+
if (!isInteracting.value) return;
|
|
1095
|
+
isInteracting.value = false;
|
|
1096
|
+
isDragging.value = false;
|
|
1097
|
+
rubberStretchPx.jump(0);
|
|
1098
|
+
pointerDownPos = null;
|
|
1099
|
+
};
|
|
1100
|
+
const handleInputSubmit = () => {
|
|
1101
|
+
const parsed = parseFloat(inputValue.value);
|
|
1102
|
+
if (!Number.isNaN(parsed)) {
|
|
1103
|
+
const clamped = Math.max(min.value, Math.min(max.value, parsed));
|
|
1104
|
+
emit("change", roundValue(clamped, step.value));
|
|
1105
|
+
}
|
|
1106
|
+
showInput.value = false;
|
|
1107
|
+
isValueHovered.value = false;
|
|
1108
|
+
isValueEditable.value = false;
|
|
1109
|
+
};
|
|
1110
|
+
const handleValueClick = (event) => {
|
|
1111
|
+
if (!isValueEditable.value) return;
|
|
1112
|
+
event.stopPropagation();
|
|
1113
|
+
event.preventDefault();
|
|
1114
|
+
showInput.value = true;
|
|
1115
|
+
inputValue.value = props.value.toFixed(decimalsForStep(step.value));
|
|
1116
|
+
};
|
|
1117
|
+
const handleInputKeydown = (event) => {
|
|
1118
|
+
if (event.key === "Enter") {
|
|
1119
|
+
handleInputSubmit();
|
|
1120
|
+
} else if (event.key === "Escape") {
|
|
1121
|
+
showInput.value = false;
|
|
1122
|
+
isValueHovered.value = false;
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
(0, import_vue3.watch)(() => props.value, () => {
|
|
1126
|
+
if (!isInteracting.value && !snapAnim) {
|
|
1127
|
+
fillPercent.jump(percentage.value);
|
|
1128
|
+
}
|
|
1129
|
+
});
|
|
1130
|
+
(0, import_vue3.watch)([isInteracting, isHovered, isDragging, () => props.value], () => {
|
|
1131
|
+
animateHandleState();
|
|
1132
|
+
});
|
|
1133
|
+
(0, import_vue3.watch)([isValueHovered, showInput, isValueEditable], () => {
|
|
1134
|
+
if (hoverTimeout) {
|
|
1135
|
+
clearTimeout(hoverTimeout);
|
|
1136
|
+
hoverTimeout = null;
|
|
1137
|
+
}
|
|
1138
|
+
if (isValueHovered.value && !showInput.value && !isValueEditable.value) {
|
|
1139
|
+
hoverTimeout = setTimeout(() => {
|
|
1140
|
+
isValueEditable.value = true;
|
|
1141
|
+
animateHandleState();
|
|
1142
|
+
}, 800);
|
|
1143
|
+
} else if (!isValueHovered.value && !showInput.value) {
|
|
1144
|
+
isValueEditable.value = false;
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1147
|
+
(0, import_vue3.watch)(showInput, async (visible) => {
|
|
1148
|
+
if (!visible) return;
|
|
1149
|
+
await (0, import_vue3.nextTick)();
|
|
1150
|
+
inputRef.value?.focus();
|
|
1151
|
+
inputRef.value?.select();
|
|
1152
|
+
});
|
|
1153
|
+
const discreteSteps = (0, import_vue3.computed)(() => (max.value - min.value) / step.value);
|
|
1154
|
+
const hashMarks = (0, import_vue3.computed)(() => {
|
|
1155
|
+
const marks = [];
|
|
1156
|
+
if (discreteSteps.value <= 10) {
|
|
1157
|
+
const count = Math.max(0, Math.floor(discreteSteps.value) - 1);
|
|
1158
|
+
for (let i = 0; i < count; i += 1) {
|
|
1159
|
+
const pct = (i + 1) * step.value / (max.value - min.value) * 100;
|
|
1160
|
+
marks.push((0, import_vue3.h)("div", { class: "dialkit-slider-hashmark", style: { left: `${pct}%` } }));
|
|
1161
|
+
}
|
|
1162
|
+
return marks;
|
|
1163
|
+
}
|
|
1164
|
+
for (let i = 0; i < 9; i += 1) {
|
|
1165
|
+
const pct = (i + 1) * 10;
|
|
1166
|
+
marks.push((0, import_vue3.h)("div", { class: "dialkit-slider-hashmark", style: { left: `${pct}%` } }));
|
|
1167
|
+
}
|
|
1168
|
+
return marks;
|
|
1169
|
+
});
|
|
1170
|
+
let unsubFill = null;
|
|
1171
|
+
let unsubRubber = null;
|
|
1172
|
+
let unsubHandleOpacity = null;
|
|
1173
|
+
let unsubHandleScaleX = null;
|
|
1174
|
+
let unsubHandleScaleY = null;
|
|
1175
|
+
(0, import_vue3.onMounted)(() => {
|
|
1176
|
+
unsubFill = fillPercent.on("change", applyFillStyles);
|
|
1177
|
+
unsubRubber = rubberStretchPx.on("change", applyRubberStyles);
|
|
1178
|
+
unsubHandleOpacity = handleOpacityMv.on("change", applyHandleVisualStyles);
|
|
1179
|
+
unsubHandleScaleX = handleScaleXMv.on("change", applyHandleVisualStyles);
|
|
1180
|
+
unsubHandleScaleY = handleScaleYMv.on("change", applyHandleVisualStyles);
|
|
1181
|
+
applyFillStyles(fillPercent.get());
|
|
1182
|
+
applyRubberStyles(rubberStretchPx.get());
|
|
1183
|
+
applyHandleVisualStyles();
|
|
1184
|
+
animateHandleState();
|
|
1185
|
+
});
|
|
1186
|
+
(0, import_vue3.onUnmounted)(() => {
|
|
1187
|
+
if (hoverTimeout) clearTimeout(hoverTimeout);
|
|
1188
|
+
snapAnim?.stop();
|
|
1189
|
+
rubberAnim?.stop();
|
|
1190
|
+
handleOpacityAnim?.stop();
|
|
1191
|
+
handleScaleXAnim?.stop();
|
|
1192
|
+
handleScaleYAnim?.stop();
|
|
1193
|
+
unsubFill?.();
|
|
1194
|
+
unsubRubber?.();
|
|
1195
|
+
unsubHandleOpacity?.();
|
|
1196
|
+
unsubHandleScaleX?.();
|
|
1197
|
+
unsubHandleScaleY?.();
|
|
1198
|
+
});
|
|
1199
|
+
return () => (0, import_vue3.h)("div", { ref: wrapperRef, class: "dialkit-slider-wrapper" }, [
|
|
1200
|
+
(0, import_vue3.h)("div", {
|
|
1201
|
+
ref: trackRef,
|
|
1202
|
+
class: `dialkit-slider ${isActive.value ? "dialkit-slider-active" : ""}`,
|
|
1203
|
+
onPointerdown: handlePointerDown,
|
|
1204
|
+
onPointermove: handlePointerMove,
|
|
1205
|
+
onPointerup: handlePointerUp,
|
|
1206
|
+
onPointercancel: handlePointerCancel,
|
|
1207
|
+
onMouseenter: () => {
|
|
1208
|
+
isHovered.value = true;
|
|
1209
|
+
animateHandleState();
|
|
1210
|
+
},
|
|
1211
|
+
onMouseleave: () => {
|
|
1212
|
+
isHovered.value = false;
|
|
1213
|
+
animateHandleState();
|
|
1214
|
+
}
|
|
1215
|
+
}, [
|
|
1216
|
+
(0, import_vue3.h)("div", { class: "dialkit-slider-hashmarks" }, hashMarks.value),
|
|
1217
|
+
(0, import_vue3.h)("div", {
|
|
1218
|
+
ref: fillRef,
|
|
1219
|
+
class: "dialkit-slider-fill",
|
|
1220
|
+
style: {
|
|
1221
|
+
width: `${fillPercent.get()}%`
|
|
1222
|
+
}
|
|
1223
|
+
}),
|
|
1224
|
+
(0, import_vue3.h)("div", {
|
|
1225
|
+
ref: handleRef,
|
|
1226
|
+
class: "dialkit-slider-handle",
|
|
1227
|
+
style: {
|
|
1228
|
+
left: `max(5px, calc(${fillPercent.get()}% - 9px))`,
|
|
1229
|
+
transform: "translateY(-50%) scaleX(0.25) scaleY(1)",
|
|
1230
|
+
opacity: 0
|
|
1231
|
+
}
|
|
1232
|
+
}),
|
|
1233
|
+
(0, import_vue3.h)("span", { ref: labelRef, class: "dialkit-slider-label" }, [
|
|
1234
|
+
props.label,
|
|
1235
|
+
props.shortcut ? (0, import_vue3.h)("span", {
|
|
1236
|
+
class: `dialkit-shortcut-pill${props.shortcutActive ? " dialkit-shortcut-pill-active" : ""}`
|
|
1237
|
+
}, formatSliderShortcut(props.shortcut)) : null
|
|
1238
|
+
]),
|
|
1239
|
+
showInput.value ? (0, import_vue3.h)("input", {
|
|
1240
|
+
ref: inputRef,
|
|
1241
|
+
type: "text",
|
|
1242
|
+
class: "dialkit-slider-input",
|
|
1243
|
+
value: inputValue.value,
|
|
1244
|
+
onInput: (event) => {
|
|
1245
|
+
inputValue.value = event.target.value;
|
|
1246
|
+
},
|
|
1247
|
+
onKeydown: handleInputKeydown,
|
|
1248
|
+
onBlur: handleInputSubmit,
|
|
1249
|
+
onClick: (event) => event.stopPropagation(),
|
|
1250
|
+
onMousedown: (event) => event.stopPropagation()
|
|
1251
|
+
}) : (0, import_vue3.h)("span", {
|
|
1252
|
+
ref: valueSpanRef,
|
|
1253
|
+
class: `dialkit-slider-value ${isValueEditable.value ? "dialkit-slider-value-editable" : ""}`,
|
|
1254
|
+
onMouseenter: () => {
|
|
1255
|
+
isValueHovered.value = true;
|
|
1256
|
+
},
|
|
1257
|
+
onMouseleave: () => {
|
|
1258
|
+
isValueHovered.value = false;
|
|
1259
|
+
},
|
|
1260
|
+
onClick: handleValueClick,
|
|
1261
|
+
onMousedown: (event) => {
|
|
1262
|
+
if (isValueEditable.value) event.stopPropagation();
|
|
1263
|
+
},
|
|
1264
|
+
style: { cursor: isValueEditable.value ? "text" : "default" }
|
|
1265
|
+
}, displayValue.value)
|
|
1266
|
+
])
|
|
1267
|
+
]);
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
|
|
1271
|
+
// src/vue/components/Toggle.ts
|
|
1272
|
+
var import_vue5 = require("vue");
|
|
1273
|
+
|
|
1274
|
+
// src/vue/components/SegmentedControl.ts
|
|
1275
|
+
var import_vue4 = require("vue");
|
|
1276
|
+
var import_motion = require("motion");
|
|
1277
|
+
var SegmentedControl = (0, import_vue4.defineComponent)({
|
|
1278
|
+
name: "DialKitSegmentedControl",
|
|
1279
|
+
props: {
|
|
1280
|
+
options: {
|
|
1281
|
+
type: Array,
|
|
1282
|
+
required: true
|
|
1283
|
+
},
|
|
1284
|
+
value: {
|
|
1285
|
+
type: String,
|
|
1286
|
+
required: true
|
|
1287
|
+
}
|
|
1288
|
+
},
|
|
1289
|
+
emits: ["change"],
|
|
1290
|
+
setup(props, { emit }) {
|
|
1291
|
+
const containerRef = (0, import_vue4.ref)(null);
|
|
1292
|
+
const pillRef = (0, import_vue4.ref)(null);
|
|
1293
|
+
const buttonRefs = /* @__PURE__ */ new Map();
|
|
1294
|
+
const pillReady = (0, import_vue4.ref)(false);
|
|
1295
|
+
let hasAnimated = false;
|
|
1296
|
+
let pillAnim = null;
|
|
1297
|
+
const measurePill = () => {
|
|
1298
|
+
const button = buttonRefs.get(props.value);
|
|
1299
|
+
const container = containerRef.value;
|
|
1300
|
+
if (!button || !container) return null;
|
|
1301
|
+
const containerRect = container.getBoundingClientRect();
|
|
1302
|
+
const buttonRect = button.getBoundingClientRect();
|
|
1303
|
+
return {
|
|
1304
|
+
left: buttonRect.left - containerRect.left,
|
|
1305
|
+
width: buttonRect.width
|
|
1306
|
+
};
|
|
1307
|
+
};
|
|
1308
|
+
const setPillImmediate = (left, width) => {
|
|
1309
|
+
if (!pillRef.value) return;
|
|
1310
|
+
pillRef.value.style.left = `${left}px`;
|
|
1311
|
+
pillRef.value.style.width = `${width}px`;
|
|
1312
|
+
pillRef.value.style.visibility = "visible";
|
|
1313
|
+
};
|
|
1314
|
+
const updatePill = (shouldAnimate) => {
|
|
1315
|
+
const next = measurePill();
|
|
1316
|
+
if (!next) return;
|
|
1317
|
+
if (!pillReady.value) {
|
|
1318
|
+
setPillImmediate(next.left, next.width);
|
|
1319
|
+
pillReady.value = true;
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
if (!shouldAnimate || !hasAnimated || !pillRef.value) {
|
|
1323
|
+
pillAnim?.stop();
|
|
1324
|
+
pillAnim = null;
|
|
1325
|
+
setPillImmediate(next.left, next.width);
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
pillAnim?.stop();
|
|
1329
|
+
pillAnim = (0, import_motion.animate)(
|
|
1330
|
+
pillRef.value,
|
|
1331
|
+
{
|
|
1332
|
+
left: next.left,
|
|
1333
|
+
width: next.width
|
|
1334
|
+
},
|
|
1335
|
+
{
|
|
1336
|
+
type: "spring",
|
|
1337
|
+
visualDuration: 0.2,
|
|
1338
|
+
bounce: 0.15,
|
|
1339
|
+
onComplete: () => {
|
|
1340
|
+
pillAnim = null;
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
);
|
|
1344
|
+
};
|
|
1345
|
+
let ro;
|
|
1346
|
+
(0, import_vue4.onMounted)(() => {
|
|
1347
|
+
(0, import_vue4.nextTick)(() => {
|
|
1348
|
+
updatePill(false);
|
|
1349
|
+
hasAnimated = true;
|
|
1350
|
+
});
|
|
1351
|
+
if (typeof ResizeObserver !== "undefined" && containerRef.value) {
|
|
1352
|
+
ro = new ResizeObserver(() => updatePill(false));
|
|
1353
|
+
ro.observe(containerRef.value);
|
|
1354
|
+
}
|
|
1355
|
+
});
|
|
1356
|
+
(0, import_vue4.onUnmounted)(() => {
|
|
1357
|
+
pillAnim?.stop();
|
|
1358
|
+
ro?.disconnect();
|
|
1359
|
+
});
|
|
1360
|
+
(0, import_vue4.watch)(
|
|
1361
|
+
() => props.value,
|
|
1362
|
+
() => {
|
|
1363
|
+
updatePill(true);
|
|
1364
|
+
},
|
|
1365
|
+
{ flush: "post" }
|
|
1366
|
+
);
|
|
1367
|
+
return () => (0, import_vue4.h)("div", { ref: containerRef, class: "dialkit-segmented" }, [
|
|
1368
|
+
(0, import_vue4.h)("div", {
|
|
1369
|
+
ref: pillRef,
|
|
1370
|
+
class: "dialkit-segmented-pill",
|
|
1371
|
+
style: {
|
|
1372
|
+
left: "0px",
|
|
1373
|
+
width: "0px",
|
|
1374
|
+
visibility: pillReady.value ? "visible" : "hidden"
|
|
1375
|
+
}
|
|
1376
|
+
}),
|
|
1377
|
+
...props.options.map((option) => (0, import_vue4.h)("button", {
|
|
1378
|
+
ref: ((el) => {
|
|
1379
|
+
if (el instanceof HTMLElement) {
|
|
1380
|
+
buttonRefs.set(option.value, el);
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
buttonRefs.delete(option.value);
|
|
1384
|
+
}),
|
|
1385
|
+
class: "dialkit-segmented-button",
|
|
1386
|
+
"data-active": String(props.value === option.value),
|
|
1387
|
+
onClick: () => emit("change", option.value)
|
|
1388
|
+
}, option.label))
|
|
1389
|
+
]);
|
|
1390
|
+
}
|
|
1391
|
+
});
|
|
1392
|
+
|
|
1393
|
+
// src/vue/components/Toggle.ts
|
|
1394
|
+
var Toggle = (0, import_vue5.defineComponent)({
|
|
1395
|
+
name: "DialKitToggle",
|
|
1396
|
+
props: {
|
|
1397
|
+
label: { type: String, required: true },
|
|
1398
|
+
checked: { type: Boolean, required: true },
|
|
1399
|
+
shortcut: { type: Object, default: void 0 },
|
|
1400
|
+
shortcutActive: { type: Boolean, default: false }
|
|
1401
|
+
},
|
|
1402
|
+
emits: ["change"],
|
|
1403
|
+
setup(props, { emit }) {
|
|
1404
|
+
return () => (0, import_vue5.h)("div", { class: "dialkit-labeled-control" }, [
|
|
1405
|
+
(0, import_vue5.h)("span", { class: "dialkit-labeled-control-label" }, [
|
|
1406
|
+
props.label,
|
|
1407
|
+
props.shortcut ? (0, import_vue5.h)("span", {
|
|
1408
|
+
class: `dialkit-shortcut-pill${props.shortcutActive ? " dialkit-shortcut-pill-active" : ""}`
|
|
1409
|
+
}, formatToggleShortcut(props.shortcut)) : null
|
|
1410
|
+
]),
|
|
1411
|
+
(0, import_vue5.h)(SegmentedControl, {
|
|
1412
|
+
options: [
|
|
1413
|
+
{ value: "off", label: "Off" },
|
|
1414
|
+
{ value: "on", label: "On" }
|
|
1415
|
+
],
|
|
1416
|
+
value: props.checked ? "on" : "off",
|
|
1417
|
+
onChange: (value) => emit("change", value === "on")
|
|
1418
|
+
})
|
|
1419
|
+
]);
|
|
1420
|
+
}
|
|
1421
|
+
});
|
|
1422
|
+
|
|
1423
|
+
// src/vue/components/SpringControl.ts
|
|
1424
|
+
var import_vue7 = require("vue");
|
|
1425
|
+
|
|
1426
|
+
// src/vue/components/SpringVisualization.ts
|
|
1427
|
+
var import_vue6 = require("vue");
|
|
1428
|
+
function generateSpringCurve(stiffness, damping, mass, duration) {
|
|
1429
|
+
const points = [];
|
|
1430
|
+
const steps = 100;
|
|
1431
|
+
const dt = duration / steps;
|
|
1432
|
+
let position = 0;
|
|
1433
|
+
let velocity = 0;
|
|
1434
|
+
const target = 1;
|
|
1435
|
+
for (let i = 0; i <= steps; i += 1) {
|
|
1436
|
+
const time = i * dt;
|
|
1437
|
+
points.push([time, position]);
|
|
1438
|
+
const springForce = -stiffness * (position - target);
|
|
1439
|
+
const dampingForce = -damping * velocity;
|
|
1440
|
+
const acceleration = (springForce + dampingForce) / mass;
|
|
1441
|
+
velocity += acceleration * dt;
|
|
1442
|
+
position += velocity * dt;
|
|
1443
|
+
}
|
|
1444
|
+
return points;
|
|
1445
|
+
}
|
|
1446
|
+
var SpringVisualization = (0, import_vue6.defineComponent)({
|
|
1447
|
+
name: "DialKitSpringVisualization",
|
|
1448
|
+
props: {
|
|
1449
|
+
spring: {
|
|
1450
|
+
type: Object,
|
|
1451
|
+
required: true
|
|
1452
|
+
},
|
|
1453
|
+
isSimpleMode: {
|
|
1454
|
+
type: Boolean,
|
|
1455
|
+
required: true
|
|
1456
|
+
}
|
|
1457
|
+
},
|
|
1458
|
+
setup(props) {
|
|
1459
|
+
const width = 256;
|
|
1460
|
+
const height = 140;
|
|
1461
|
+
const pathData = (0, import_vue6.computed)(() => {
|
|
1462
|
+
let stiffness;
|
|
1463
|
+
let damping;
|
|
1464
|
+
let mass;
|
|
1465
|
+
if (props.isSimpleMode) {
|
|
1466
|
+
const visualDuration = props.spring.visualDuration ?? 0.3;
|
|
1467
|
+
const bounce = props.spring.bounce ?? 0.2;
|
|
1468
|
+
mass = 1;
|
|
1469
|
+
stiffness = (2 * Math.PI / visualDuration) ** 2;
|
|
1470
|
+
const dampingRatio = 1 - bounce;
|
|
1471
|
+
damping = 2 * dampingRatio * Math.sqrt(stiffness * mass);
|
|
1472
|
+
} else {
|
|
1473
|
+
stiffness = props.spring.stiffness ?? 400;
|
|
1474
|
+
damping = props.spring.damping ?? 17;
|
|
1475
|
+
mass = props.spring.mass ?? 1;
|
|
1476
|
+
}
|
|
1477
|
+
const duration = 2;
|
|
1478
|
+
const points = generateSpringCurve(stiffness, damping, mass, duration);
|
|
1479
|
+
const values = points.map(([, value]) => value);
|
|
1480
|
+
const minValue = Math.min(...values);
|
|
1481
|
+
const maxValue = Math.max(...values);
|
|
1482
|
+
const valueRange = maxValue - minValue;
|
|
1483
|
+
return points.map(([time, value], index) => {
|
|
1484
|
+
const x = time / duration * width;
|
|
1485
|
+
const normalizedValue = (value - minValue) / (valueRange || 1);
|
|
1486
|
+
const y = height - (normalizedValue * height * 0.6 + height * 0.2);
|
|
1487
|
+
return `${index === 0 ? "M" : "L"} ${x} ${y}`;
|
|
1488
|
+
}).join(" ");
|
|
1489
|
+
});
|
|
1490
|
+
return () => (0, import_vue6.h)("svg", { viewBox: `0 0 ${width} ${height}`, class: "dialkit-spring-viz" }, [
|
|
1491
|
+
...Array.from({ length: 3 }).flatMap((_, index) => {
|
|
1492
|
+
const lineIndex = index + 1;
|
|
1493
|
+
const x = width / 4 * lineIndex;
|
|
1494
|
+
const y = height / 4 * lineIndex;
|
|
1495
|
+
return [
|
|
1496
|
+
(0, import_vue6.h)("line", { x1: x, y1: 0, x2: x, y2: height, stroke: "rgba(255, 255, 255, 0.08)", "stroke-width": 1 }),
|
|
1497
|
+
(0, import_vue6.h)("line", { x1: 0, y1: y, x2: width, y2: y, stroke: "rgba(255, 255, 255, 0.08)", "stroke-width": 1 })
|
|
1498
|
+
];
|
|
1499
|
+
}),
|
|
1500
|
+
(0, import_vue6.h)("line", {
|
|
1501
|
+
x1: 0,
|
|
1502
|
+
y1: height / 2,
|
|
1503
|
+
x2: width,
|
|
1504
|
+
y2: height / 2,
|
|
1505
|
+
stroke: "rgba(255, 255, 255, 0.15)",
|
|
1506
|
+
"stroke-width": 1,
|
|
1507
|
+
"stroke-dasharray": "4,4"
|
|
1508
|
+
}),
|
|
1509
|
+
(0, import_vue6.h)("path", {
|
|
1510
|
+
d: pathData.value,
|
|
1511
|
+
fill: "none",
|
|
1512
|
+
stroke: "rgba(255, 255, 255, 0.6)",
|
|
1513
|
+
"stroke-width": 2,
|
|
1514
|
+
"stroke-linecap": "round",
|
|
1515
|
+
"stroke-linejoin": "round"
|
|
1516
|
+
})
|
|
1517
|
+
]);
|
|
1518
|
+
}
|
|
1519
|
+
});
|
|
1520
|
+
|
|
1521
|
+
// src/vue/components/SpringControl.ts
|
|
1522
|
+
var SpringControl = (0, import_vue7.defineComponent)({
|
|
1523
|
+
name: "DialKitSpringControl",
|
|
1524
|
+
props: {
|
|
1525
|
+
panelId: { type: String, required: true },
|
|
1526
|
+
path: { type: String, required: true },
|
|
1527
|
+
label: { type: String, required: true },
|
|
1528
|
+
spring: {
|
|
1529
|
+
type: Object,
|
|
1530
|
+
required: true
|
|
1531
|
+
}
|
|
1532
|
+
},
|
|
1533
|
+
emits: ["change"],
|
|
1534
|
+
setup(props, { emit }) {
|
|
1535
|
+
const mode = (0, import_vue7.ref)(DialStore.getSpringMode(props.panelId, props.path));
|
|
1536
|
+
let unsub;
|
|
1537
|
+
(0, import_vue7.onMounted)(() => {
|
|
1538
|
+
unsub = DialStore.subscribe(props.panelId, () => {
|
|
1539
|
+
mode.value = DialStore.getSpringMode(props.panelId, props.path);
|
|
1540
|
+
});
|
|
1541
|
+
});
|
|
1542
|
+
(0, import_vue7.onUnmounted)(() => {
|
|
1543
|
+
unsub?.();
|
|
1544
|
+
});
|
|
1545
|
+
const isSimpleMode = () => mode.value === "simple";
|
|
1546
|
+
const cache = {
|
|
1547
|
+
simple: props.spring.visualDuration !== void 0 ? { ...props.spring } : { type: "spring", visualDuration: 0.3, bounce: 0.2 },
|
|
1548
|
+
advanced: props.spring.stiffness !== void 0 ? { ...props.spring } : { type: "spring", stiffness: 200, damping: 25, mass: 1 }
|
|
1549
|
+
};
|
|
1550
|
+
const handleModeChange = (nextMode) => {
|
|
1551
|
+
if (isSimpleMode()) {
|
|
1552
|
+
cache.simple = { ...props.spring };
|
|
1553
|
+
} else {
|
|
1554
|
+
cache.advanced = { ...props.spring };
|
|
1555
|
+
}
|
|
1556
|
+
DialStore.updateSpringMode(props.panelId, props.path, nextMode);
|
|
1557
|
+
if (nextMode === "simple") {
|
|
1558
|
+
emit("change", cache.simple);
|
|
1559
|
+
} else {
|
|
1560
|
+
emit("change", cache.advanced);
|
|
1561
|
+
}
|
|
1562
|
+
};
|
|
1563
|
+
const handleUpdate = (key, value) => {
|
|
1564
|
+
if (isSimpleMode()) {
|
|
1565
|
+
const { stiffness, damping, mass, ...rest } = props.spring;
|
|
1566
|
+
emit("change", { ...rest, [key]: value });
|
|
1567
|
+
} else {
|
|
1568
|
+
const { visualDuration, bounce, ...rest } = props.spring;
|
|
1569
|
+
emit("change", { ...rest, [key]: value });
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1572
|
+
return () => (0, import_vue7.h)(Folder, { title: props.label, defaultOpen: true }, {
|
|
1573
|
+
default: () => [
|
|
1574
|
+
(0, import_vue7.h)("div", { style: { display: "flex", flexDirection: "column", gap: "6px" } }, [
|
|
1575
|
+
(0, import_vue7.h)(SpringVisualization, { spring: props.spring, isSimpleMode: isSimpleMode() }),
|
|
1576
|
+
(0, import_vue7.h)("div", { class: "dialkit-labeled-control" }, [
|
|
1577
|
+
(0, import_vue7.h)("span", { class: "dialkit-labeled-control-label" }, "Type"),
|
|
1578
|
+
(0, import_vue7.h)(SegmentedControl, {
|
|
1579
|
+
options: [
|
|
1580
|
+
{ value: "simple", label: "Time" },
|
|
1581
|
+
{ value: "advanced", label: "Physics" }
|
|
1582
|
+
],
|
|
1583
|
+
value: mode.value,
|
|
1584
|
+
onChange: handleModeChange
|
|
1585
|
+
})
|
|
1586
|
+
]),
|
|
1587
|
+
...isSimpleMode() ? [
|
|
1588
|
+
(0, import_vue7.h)(Slider, {
|
|
1589
|
+
label: "Duration",
|
|
1590
|
+
value: props.spring.visualDuration ?? 0.3,
|
|
1591
|
+
min: 0.1,
|
|
1592
|
+
max: 1,
|
|
1593
|
+
step: 0.05,
|
|
1594
|
+
unit: "s",
|
|
1595
|
+
onChange: (next) => handleUpdate("visualDuration", next)
|
|
1596
|
+
}),
|
|
1597
|
+
(0, import_vue7.h)(Slider, {
|
|
1598
|
+
label: "Bounce",
|
|
1599
|
+
value: props.spring.bounce ?? 0.2,
|
|
1600
|
+
min: 0,
|
|
1601
|
+
max: 1,
|
|
1602
|
+
step: 0.05,
|
|
1603
|
+
onChange: (next) => handleUpdate("bounce", next)
|
|
1604
|
+
})
|
|
1605
|
+
] : [
|
|
1606
|
+
(0, import_vue7.h)(Slider, {
|
|
1607
|
+
label: "Stiffness",
|
|
1608
|
+
value: props.spring.stiffness ?? 400,
|
|
1609
|
+
min: 1,
|
|
1610
|
+
max: 1e3,
|
|
1611
|
+
step: 10,
|
|
1612
|
+
onChange: (next) => handleUpdate("stiffness", next)
|
|
1613
|
+
}),
|
|
1614
|
+
(0, import_vue7.h)(Slider, {
|
|
1615
|
+
label: "Damping",
|
|
1616
|
+
value: props.spring.damping ?? 17,
|
|
1617
|
+
min: 1,
|
|
1618
|
+
max: 100,
|
|
1619
|
+
step: 1,
|
|
1620
|
+
onChange: (next) => handleUpdate("damping", next)
|
|
1621
|
+
}),
|
|
1622
|
+
(0, import_vue7.h)(Slider, {
|
|
1623
|
+
label: "Mass",
|
|
1624
|
+
value: props.spring.mass ?? 1,
|
|
1625
|
+
min: 0.1,
|
|
1626
|
+
max: 10,
|
|
1627
|
+
step: 0.1,
|
|
1628
|
+
onChange: (next) => handleUpdate("mass", next)
|
|
1629
|
+
})
|
|
1630
|
+
]
|
|
1631
|
+
])
|
|
1632
|
+
]
|
|
1633
|
+
});
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1636
|
+
|
|
1637
|
+
// src/vue/components/TransitionControl.ts
|
|
1638
|
+
var import_vue9 = require("vue");
|
|
1639
|
+
|
|
1640
|
+
// src/vue/components/EasingVisualization.ts
|
|
1641
|
+
var import_vue8 = require("vue");
|
|
1642
|
+
var EasingVisualization = (0, import_vue8.defineComponent)({
|
|
1643
|
+
name: "DialKitEasingVisualization",
|
|
1644
|
+
props: {
|
|
1645
|
+
easing: {
|
|
1646
|
+
type: Object,
|
|
1647
|
+
required: true
|
|
1648
|
+
}
|
|
1649
|
+
},
|
|
1650
|
+
setup(props) {
|
|
1651
|
+
const size = 200;
|
|
1652
|
+
const pad = 10;
|
|
1653
|
+
const inner = size - pad * 2;
|
|
1654
|
+
const unit = inner / 2;
|
|
1655
|
+
const curve = (0, import_vue8.computed)(() => {
|
|
1656
|
+
const [x1, y1, x2, y2] = props.easing.ease;
|
|
1657
|
+
const toSvg = (nx, ny) => ({
|
|
1658
|
+
x: pad + (nx + 0.5) * unit,
|
|
1659
|
+
y: pad + (1.5 - ny) * unit
|
|
1660
|
+
});
|
|
1661
|
+
const start = toSvg(0, 0);
|
|
1662
|
+
const end = toSvg(1, 1);
|
|
1663
|
+
const p1 = toSvg(x1, y1);
|
|
1664
|
+
const p2 = toSvg(x2, y2);
|
|
1665
|
+
return `M ${start.x} ${start.y} C ${p1.x} ${p1.y}, ${p2.x} ${p2.y}, ${end.x} ${end.y}`;
|
|
1666
|
+
});
|
|
1667
|
+
return () => (0, import_vue8.h)("svg", {
|
|
1668
|
+
viewBox: `0 0 ${size} ${size}`,
|
|
1669
|
+
preserveAspectRatio: "xMidYMid slice",
|
|
1670
|
+
class: "dialkit-spring-viz dialkit-easing-viz"
|
|
1671
|
+
}, [
|
|
1672
|
+
(0, import_vue8.h)("line", {
|
|
1673
|
+
x1: pad + (0 + 0.5) * unit,
|
|
1674
|
+
y1: pad + (1.5 - 0) * unit,
|
|
1675
|
+
x2: pad + (1 + 0.5) * unit,
|
|
1676
|
+
y2: pad + (1.5 - 1) * unit,
|
|
1677
|
+
stroke: "rgba(255, 255, 255, 0.15)",
|
|
1678
|
+
"stroke-width": 1,
|
|
1679
|
+
"stroke-dasharray": "4,4"
|
|
1680
|
+
}),
|
|
1681
|
+
(0, import_vue8.h)("path", {
|
|
1682
|
+
d: curve.value,
|
|
1683
|
+
fill: "none",
|
|
1684
|
+
stroke: "rgba(255, 255, 255, 0.6)",
|
|
1685
|
+
"stroke-width": 2,
|
|
1686
|
+
"stroke-linecap": "round"
|
|
1687
|
+
})
|
|
1688
|
+
]);
|
|
1689
|
+
}
|
|
1690
|
+
});
|
|
1691
|
+
|
|
1692
|
+
// src/vue/components/TransitionControl.ts
|
|
1693
|
+
function formatEase(ease) {
|
|
1694
|
+
return ease.map((value) => Number(value.toFixed(2))).join(", ");
|
|
1695
|
+
}
|
|
1696
|
+
function parseEase(value) {
|
|
1697
|
+
const parts = value.split(",").map((part) => Number.parseFloat(part.trim()));
|
|
1698
|
+
if (parts.length === 4 && parts.every((part) => Number.isFinite(part))) {
|
|
1699
|
+
return parts;
|
|
1700
|
+
}
|
|
1701
|
+
return null;
|
|
1702
|
+
}
|
|
1703
|
+
var EaseTextInput = (0, import_vue9.defineComponent)({
|
|
1704
|
+
name: "DialKitEaseTextInput",
|
|
1705
|
+
props: {
|
|
1706
|
+
ease: {
|
|
1707
|
+
type: Array,
|
|
1708
|
+
required: true
|
|
1709
|
+
},
|
|
1710
|
+
onChange: {
|
|
1711
|
+
type: Function,
|
|
1712
|
+
required: true
|
|
1713
|
+
}
|
|
1714
|
+
},
|
|
1715
|
+
setup(props) {
|
|
1716
|
+
const editing = (0, import_vue9.ref)(false);
|
|
1717
|
+
const draft = (0, import_vue9.ref)("");
|
|
1718
|
+
const handleFocus = () => {
|
|
1719
|
+
draft.value = formatEase(props.ease);
|
|
1720
|
+
editing.value = true;
|
|
1721
|
+
};
|
|
1722
|
+
const handleBlur = () => {
|
|
1723
|
+
const parsed = parseEase(draft.value);
|
|
1724
|
+
if (parsed) props.onChange(parsed);
|
|
1725
|
+
editing.value = false;
|
|
1726
|
+
};
|
|
1727
|
+
const handleKeydown = (event) => {
|
|
1728
|
+
if (event.key === "Enter") {
|
|
1729
|
+
event.target.blur();
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
1732
|
+
return () => (0, import_vue9.h)("div", { class: "dialkit-labeled-control" }, [
|
|
1733
|
+
(0, import_vue9.h)("span", { class: "dialkit-labeled-control-label" }, "Ease"),
|
|
1734
|
+
(0, import_vue9.h)("input", {
|
|
1735
|
+
type: "text",
|
|
1736
|
+
class: "dialkit-text-input",
|
|
1737
|
+
value: editing.value ? draft.value : formatEase(props.ease),
|
|
1738
|
+
spellcheck: false,
|
|
1739
|
+
onInput: (event) => {
|
|
1740
|
+
draft.value = event.target.value;
|
|
1741
|
+
},
|
|
1742
|
+
onFocus: handleFocus,
|
|
1743
|
+
onBlur: handleBlur,
|
|
1744
|
+
onKeydown: handleKeydown
|
|
1745
|
+
})
|
|
1746
|
+
]);
|
|
1747
|
+
}
|
|
1748
|
+
});
|
|
1749
|
+
var TransitionControl = (0, import_vue9.defineComponent)({
|
|
1750
|
+
name: "DialKitTransitionControl",
|
|
1751
|
+
props: {
|
|
1752
|
+
panelId: { type: String, required: true },
|
|
1753
|
+
path: { type: String, required: true },
|
|
1754
|
+
label: { type: String, required: true },
|
|
1755
|
+
value: {
|
|
1756
|
+
type: Object,
|
|
1757
|
+
required: true
|
|
1758
|
+
}
|
|
1759
|
+
},
|
|
1760
|
+
emits: ["change"],
|
|
1761
|
+
setup(props, { emit }) {
|
|
1762
|
+
const mode = (0, import_vue9.ref)(DialStore.getTransitionMode(props.panelId, props.path));
|
|
1763
|
+
let unsub;
|
|
1764
|
+
(0, import_vue9.onMounted)(() => {
|
|
1765
|
+
unsub = DialStore.subscribe(props.panelId, () => {
|
|
1766
|
+
mode.value = DialStore.getTransitionMode(props.panelId, props.path);
|
|
1767
|
+
});
|
|
1768
|
+
});
|
|
1769
|
+
(0, import_vue9.onUnmounted)(() => unsub?.());
|
|
1770
|
+
const cache = {
|
|
1771
|
+
easing: props.value.type === "easing" ? { ...props.value } : { type: "easing", duration: 0.3, ease: [1, -0.4, 0.5, 1] },
|
|
1772
|
+
simple: props.value.type === "spring" && props.value.visualDuration !== void 0 ? { ...props.value } : { type: "spring", visualDuration: 0.3, bounce: 0.2 },
|
|
1773
|
+
advanced: props.value.type === "spring" && props.value.stiffness !== void 0 ? { ...props.value } : { type: "spring", stiffness: 200, damping: 25, mass: 1 }
|
|
1774
|
+
};
|
|
1775
|
+
const spring = () => {
|
|
1776
|
+
if (props.value.type === "spring") {
|
|
1777
|
+
if (mode.value === "simple") cache.simple = props.value;
|
|
1778
|
+
else if (mode.value === "advanced") cache.advanced = props.value;
|
|
1779
|
+
return props.value;
|
|
1780
|
+
}
|
|
1781
|
+
return cache.simple;
|
|
1782
|
+
};
|
|
1783
|
+
const easing = () => {
|
|
1784
|
+
if (props.value.type === "easing") {
|
|
1785
|
+
cache.easing = props.value;
|
|
1786
|
+
return props.value;
|
|
1787
|
+
}
|
|
1788
|
+
return cache.easing;
|
|
1789
|
+
};
|
|
1790
|
+
const handleModeChange = (nextMode) => {
|
|
1791
|
+
DialStore.updateTransitionMode(props.panelId, props.path, nextMode);
|
|
1792
|
+
if (nextMode === "easing") {
|
|
1793
|
+
emit("change", cache.easing);
|
|
1794
|
+
} else if (nextMode === "simple") {
|
|
1795
|
+
emit("change", cache.simple);
|
|
1796
|
+
} else {
|
|
1797
|
+
emit("change", cache.advanced);
|
|
1798
|
+
}
|
|
1799
|
+
};
|
|
1800
|
+
const updateEase = (index, value) => {
|
|
1801
|
+
const current = easing();
|
|
1802
|
+
const next = [...current.ease];
|
|
1803
|
+
next[index] = value;
|
|
1804
|
+
emit("change", { ...current, ease: next });
|
|
1805
|
+
};
|
|
1806
|
+
const handleSpringUpdate = (key, value) => {
|
|
1807
|
+
const current = spring();
|
|
1808
|
+
if (mode.value === "simple") {
|
|
1809
|
+
const { stiffness, damping, mass, ...rest } = current;
|
|
1810
|
+
emit("change", { ...rest, [key]: value });
|
|
1811
|
+
} else {
|
|
1812
|
+
const { visualDuration, bounce, ...rest } = current;
|
|
1813
|
+
emit("change", { ...rest, [key]: value });
|
|
1814
|
+
}
|
|
1815
|
+
};
|
|
1816
|
+
return () => {
|
|
1817
|
+
const isEasing = mode.value === "easing";
|
|
1818
|
+
const isSimpleSpring = mode.value === "simple";
|
|
1819
|
+
const currentSpring = spring();
|
|
1820
|
+
const currentEasing = easing();
|
|
1821
|
+
return (0, import_vue9.h)(Folder, { title: props.label, defaultOpen: true }, {
|
|
1822
|
+
default: () => [
|
|
1823
|
+
(0, import_vue9.h)("div", { style: { display: "flex", flexDirection: "column", gap: "6px" } }, [
|
|
1824
|
+
isEasing ? (0, import_vue9.h)(EasingVisualization, { easing: currentEasing }) : (0, import_vue9.h)(SpringVisualization, { spring: currentSpring, isSimpleMode: isSimpleSpring }),
|
|
1825
|
+
(0, import_vue9.h)("div", { class: "dialkit-labeled-control" }, [
|
|
1826
|
+
(0, import_vue9.h)("span", { class: "dialkit-labeled-control-label" }, "Type"),
|
|
1827
|
+
(0, import_vue9.h)(SegmentedControl, {
|
|
1828
|
+
options: [
|
|
1829
|
+
{ value: "easing", label: "Easing" },
|
|
1830
|
+
{ value: "simple", label: "Time" },
|
|
1831
|
+
{ value: "advanced", label: "Physics" }
|
|
1832
|
+
],
|
|
1833
|
+
value: mode.value,
|
|
1834
|
+
onChange: handleModeChange
|
|
1835
|
+
})
|
|
1836
|
+
]),
|
|
1837
|
+
...isEasing ? [
|
|
1838
|
+
(0, import_vue9.h)(Slider, { label: "x1", value: currentEasing.ease[0], min: 0, max: 1, step: 0.01, onChange: (next) => updateEase(0, next) }),
|
|
1839
|
+
(0, import_vue9.h)(Slider, { label: "y1", value: currentEasing.ease[1], min: -1, max: 2, step: 0.01, onChange: (next) => updateEase(1, next) }),
|
|
1840
|
+
(0, import_vue9.h)(Slider, { label: "x2", value: currentEasing.ease[2], min: 0, max: 1, step: 0.01, onChange: (next) => updateEase(2, next) }),
|
|
1841
|
+
(0, import_vue9.h)(Slider, { label: "y2", value: currentEasing.ease[3], min: -1, max: 2, step: 0.01, onChange: (next) => updateEase(3, next) }),
|
|
1842
|
+
(0, import_vue9.h)(Slider, {
|
|
1843
|
+
label: "Duration",
|
|
1844
|
+
value: currentEasing.duration,
|
|
1845
|
+
min: 0.1,
|
|
1846
|
+
max: 2,
|
|
1847
|
+
step: 0.05,
|
|
1848
|
+
unit: "s",
|
|
1849
|
+
onChange: (next) => emit("change", { ...currentEasing, duration: next })
|
|
1850
|
+
}),
|
|
1851
|
+
(0, import_vue9.h)(EaseTextInput, {
|
|
1852
|
+
ease: currentEasing.ease,
|
|
1853
|
+
onChange: (next) => emit("change", { ...currentEasing, ease: next })
|
|
1854
|
+
})
|
|
1855
|
+
] : isSimpleSpring ? [
|
|
1856
|
+
(0, import_vue9.h)(Slider, {
|
|
1857
|
+
label: "Duration",
|
|
1858
|
+
value: currentSpring.visualDuration ?? 0.3,
|
|
1859
|
+
min: 0.1,
|
|
1860
|
+
max: 1,
|
|
1861
|
+
step: 0.05,
|
|
1862
|
+
unit: "s",
|
|
1863
|
+
onChange: (next) => handleSpringUpdate("visualDuration", next)
|
|
1864
|
+
}),
|
|
1865
|
+
(0, import_vue9.h)(Slider, {
|
|
1866
|
+
label: "Bounce",
|
|
1867
|
+
value: currentSpring.bounce ?? 0.2,
|
|
1868
|
+
min: 0,
|
|
1869
|
+
max: 1,
|
|
1870
|
+
step: 0.05,
|
|
1871
|
+
onChange: (next) => handleSpringUpdate("bounce", next)
|
|
1872
|
+
})
|
|
1873
|
+
] : [
|
|
1874
|
+
(0, import_vue9.h)(Slider, {
|
|
1875
|
+
label: "Stiffness",
|
|
1876
|
+
value: currentSpring.stiffness ?? 400,
|
|
1877
|
+
min: 1,
|
|
1878
|
+
max: 1e3,
|
|
1879
|
+
step: 10,
|
|
1880
|
+
onChange: (next) => handleSpringUpdate("stiffness", next)
|
|
1881
|
+
}),
|
|
1882
|
+
(0, import_vue9.h)(Slider, {
|
|
1883
|
+
label: "Damping",
|
|
1884
|
+
value: currentSpring.damping ?? 17,
|
|
1885
|
+
min: 1,
|
|
1886
|
+
max: 100,
|
|
1887
|
+
step: 1,
|
|
1888
|
+
onChange: (next) => handleSpringUpdate("damping", next)
|
|
1889
|
+
}),
|
|
1890
|
+
(0, import_vue9.h)(Slider, {
|
|
1891
|
+
label: "Mass",
|
|
1892
|
+
value: currentSpring.mass ?? 1,
|
|
1893
|
+
min: 0.1,
|
|
1894
|
+
max: 10,
|
|
1895
|
+
step: 0.1,
|
|
1896
|
+
onChange: (next) => handleSpringUpdate("mass", next)
|
|
1897
|
+
})
|
|
1898
|
+
]
|
|
1899
|
+
])
|
|
1900
|
+
]
|
|
1901
|
+
});
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
});
|
|
1905
|
+
|
|
1906
|
+
// src/vue/components/TextControl.ts
|
|
1907
|
+
var import_vue10 = require("vue");
|
|
1908
|
+
var textControlInstance = 0;
|
|
1909
|
+
var TextControl = (0, import_vue10.defineComponent)({
|
|
1910
|
+
name: "DialKitTextControl",
|
|
1911
|
+
props: {
|
|
1912
|
+
label: { type: String, required: true },
|
|
1913
|
+
value: { type: String, required: true },
|
|
1914
|
+
placeholder: { type: String, required: false }
|
|
1915
|
+
},
|
|
1916
|
+
emits: ["change"],
|
|
1917
|
+
setup(props, { emit }) {
|
|
1918
|
+
const inputId = (0, import_vue10.ref)(`dialkit-text-${++textControlInstance}`);
|
|
1919
|
+
return () => (0, import_vue10.h)("div", { class: "dialkit-text-control" }, [
|
|
1920
|
+
(0, import_vue10.h)("label", { class: "dialkit-text-label", for: inputId.value }, props.label),
|
|
1921
|
+
(0, import_vue10.h)("input", {
|
|
1922
|
+
id: inputId.value,
|
|
1923
|
+
type: "text",
|
|
1924
|
+
class: "dialkit-text-input",
|
|
1925
|
+
value: props.value,
|
|
1926
|
+
placeholder: props.placeholder,
|
|
1927
|
+
onInput: (event) => emit("change", event.target.value)
|
|
1928
|
+
})
|
|
1929
|
+
]);
|
|
1930
|
+
}
|
|
1931
|
+
});
|
|
1932
|
+
|
|
1933
|
+
// src/vue/components/SelectControl.ts
|
|
1934
|
+
var import_vue11 = require("vue");
|
|
1935
|
+
var import_motion_v3 = require("motion-v");
|
|
1936
|
+
function toTitleCase(value) {
|
|
1937
|
+
return value.replace(/\b\w/g, (char) => char.toUpperCase());
|
|
1938
|
+
}
|
|
1939
|
+
function normalizeOptions(options) {
|
|
1940
|
+
return options.map(
|
|
1941
|
+
(option) => typeof option === "string" ? { value: option, label: toTitleCase(option) } : option
|
|
1942
|
+
);
|
|
1943
|
+
}
|
|
1944
|
+
var SelectControl = (0, import_vue11.defineComponent)({
|
|
1945
|
+
name: "DialKitSelectControl",
|
|
1946
|
+
props: {
|
|
1947
|
+
label: { type: String, required: true },
|
|
1948
|
+
value: { type: String, required: true },
|
|
1949
|
+
options: {
|
|
1950
|
+
type: Array,
|
|
1951
|
+
required: true
|
|
1952
|
+
}
|
|
1953
|
+
},
|
|
1954
|
+
emits: ["change"],
|
|
1955
|
+
setup(props, { emit }) {
|
|
1956
|
+
const isOpen = (0, import_vue11.ref)(false);
|
|
1957
|
+
const pos = (0, import_vue11.ref)(null);
|
|
1958
|
+
const portalTarget = (0, import_vue11.ref)(null);
|
|
1959
|
+
const triggerRef = (0, import_vue11.ref)(null);
|
|
1960
|
+
const dropdownRef = (0, import_vue11.ref)(null);
|
|
1961
|
+
const normalizedOptions = () => normalizeOptions(props.options);
|
|
1962
|
+
const selectedLabel = () => normalizedOptions().find((option) => option.value === props.value)?.label ?? props.value;
|
|
1963
|
+
const updatePos = () => {
|
|
1964
|
+
if (!triggerRef.value) return;
|
|
1965
|
+
const rect = triggerRef.value.getBoundingClientRect();
|
|
1966
|
+
const dropdownHeight = 8 + normalizedOptions().length * 36;
|
|
1967
|
+
const spaceBelow = window.innerHeight - rect.bottom - 4;
|
|
1968
|
+
const above = spaceBelow < dropdownHeight && rect.top > spaceBelow;
|
|
1969
|
+
pos.value = {
|
|
1970
|
+
top: above ? rect.top - 4 : rect.bottom + 4,
|
|
1971
|
+
left: rect.left,
|
|
1972
|
+
width: rect.width,
|
|
1973
|
+
above
|
|
1974
|
+
};
|
|
1975
|
+
};
|
|
1976
|
+
const openDropdown = () => {
|
|
1977
|
+
updatePos();
|
|
1978
|
+
isOpen.value = true;
|
|
1979
|
+
};
|
|
1980
|
+
const closeDropdown = () => {
|
|
1981
|
+
isOpen.value = false;
|
|
1982
|
+
};
|
|
1983
|
+
const setDropdownRef = (node) => {
|
|
1984
|
+
if (node instanceof HTMLElement) {
|
|
1985
|
+
dropdownRef.value = node;
|
|
1986
|
+
return;
|
|
1987
|
+
}
|
|
1988
|
+
if (node && typeof node === "object" && "$el" in node) {
|
|
1989
|
+
const el = node.$el;
|
|
1990
|
+
dropdownRef.value = el instanceof HTMLElement ? el : null;
|
|
1991
|
+
return;
|
|
1992
|
+
}
|
|
1993
|
+
dropdownRef.value = null;
|
|
1994
|
+
};
|
|
1995
|
+
const toggleDropdown = () => {
|
|
1996
|
+
if (isOpen.value) closeDropdown();
|
|
1997
|
+
else openDropdown();
|
|
1998
|
+
};
|
|
1999
|
+
(0, import_vue11.watch)(isOpen, (open, _, onCleanup) => {
|
|
2000
|
+
if (!open) return;
|
|
2001
|
+
const handleViewportChange = () => updatePos();
|
|
2002
|
+
const handleDocumentClick = (event) => {
|
|
2003
|
+
const target = event.target;
|
|
2004
|
+
if (triggerRef.value?.contains(target) || dropdownRef.value?.contains(target)) return;
|
|
2005
|
+
closeDropdown();
|
|
2006
|
+
};
|
|
2007
|
+
updatePos();
|
|
2008
|
+
document.addEventListener("mousedown", handleDocumentClick);
|
|
2009
|
+
window.addEventListener("resize", handleViewportChange);
|
|
2010
|
+
window.addEventListener("scroll", handleViewportChange, true);
|
|
2011
|
+
onCleanup(() => {
|
|
2012
|
+
document.removeEventListener("mousedown", handleDocumentClick);
|
|
2013
|
+
window.removeEventListener("resize", handleViewportChange);
|
|
2014
|
+
window.removeEventListener("scroll", handleViewportChange, true);
|
|
2015
|
+
});
|
|
2016
|
+
});
|
|
2017
|
+
(0, import_vue11.onMounted)(() => {
|
|
2018
|
+
const root = triggerRef.value?.closest(".dialkit-root");
|
|
2019
|
+
portalTarget.value = root ?? document.body;
|
|
2020
|
+
});
|
|
2021
|
+
return () => (0, import_vue11.h)("div", { class: "dialkit-select-row" }, [
|
|
2022
|
+
(0, import_vue11.h)("button", {
|
|
2023
|
+
ref: triggerRef,
|
|
2024
|
+
class: "dialkit-select-trigger",
|
|
2025
|
+
"data-open": String(isOpen.value),
|
|
2026
|
+
onClick: toggleDropdown
|
|
2027
|
+
}, [
|
|
2028
|
+
(0, import_vue11.h)("span", { class: "dialkit-select-label" }, props.label),
|
|
2029
|
+
(0, import_vue11.h)("div", { class: "dialkit-select-right" }, [
|
|
2030
|
+
(0, import_vue11.h)("span", { class: "dialkit-select-value" }, selectedLabel()),
|
|
2031
|
+
(0, import_vue11.h)(import_motion_v3.motion.svg, {
|
|
2032
|
+
class: "dialkit-select-chevron",
|
|
2033
|
+
viewBox: "0 0 24 24",
|
|
2034
|
+
fill: "none",
|
|
2035
|
+
stroke: "currentColor",
|
|
2036
|
+
"stroke-width": "2.5",
|
|
2037
|
+
"stroke-linecap": "round",
|
|
2038
|
+
"stroke-linejoin": "round",
|
|
2039
|
+
animate: { rotate: isOpen.value ? 180 : 0 },
|
|
2040
|
+
transition: { type: "spring", visualDuration: 0.2, bounce: 0.15 }
|
|
2041
|
+
}, [(0, import_vue11.h)("path", { d: "M6 9.5L12 15.5L18 9.5" })])
|
|
2042
|
+
])
|
|
2043
|
+
]),
|
|
2044
|
+
portalTarget.value ? (0, import_vue11.h)(import_vue11.Teleport, { to: portalTarget.value }, [
|
|
2045
|
+
(0, import_vue11.h)(import_motion_v3.AnimatePresence, null, {
|
|
2046
|
+
default: () => isOpen.value && pos.value ? [(0, import_vue11.h)(import_motion_v3.motion.div, {
|
|
2047
|
+
key: "dialkit-select-dropdown",
|
|
2048
|
+
ref: setDropdownRef,
|
|
2049
|
+
class: "dialkit-select-dropdown",
|
|
2050
|
+
initial: { opacity: 0, y: pos.value.above ? 8 : -8, scale: 0.95 },
|
|
2051
|
+
animate: { opacity: 1, y: 0, scale: 1 },
|
|
2052
|
+
exit: { opacity: 0, y: pos.value.above ? 8 : -8, scale: 0.95 },
|
|
2053
|
+
transition: { type: "spring", visualDuration: 0.15, bounce: 0 },
|
|
2054
|
+
style: {
|
|
2055
|
+
position: "fixed",
|
|
2056
|
+
left: `${pos.value.left}px`,
|
|
2057
|
+
width: `${pos.value.width}px`,
|
|
2058
|
+
...pos.value.above ? {
|
|
2059
|
+
bottom: `${window.innerHeight - pos.value.top}px`,
|
|
2060
|
+
transformOrigin: "bottom"
|
|
2061
|
+
} : {
|
|
2062
|
+
top: `${pos.value.top}px`,
|
|
2063
|
+
transformOrigin: "top"
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
}, normalizedOptions().map((option) => (0, import_vue11.h)("button", {
|
|
2067
|
+
key: option.value,
|
|
2068
|
+
class: "dialkit-select-option",
|
|
2069
|
+
"data-selected": String(option.value === props.value),
|
|
2070
|
+
onClick: () => {
|
|
2071
|
+
emit("change", option.value);
|
|
2072
|
+
closeDropdown();
|
|
2073
|
+
}
|
|
2074
|
+
}, option.label)))] : []
|
|
2075
|
+
})
|
|
2076
|
+
]) : null
|
|
2077
|
+
]);
|
|
2078
|
+
}
|
|
2079
|
+
});
|
|
2080
|
+
|
|
2081
|
+
// src/vue/components/ColorControl.ts
|
|
2082
|
+
var import_vue12 = require("vue");
|
|
2083
|
+
var HEX_COLOR_REGEX = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;
|
|
2084
|
+
function expandShorthandHex(hex) {
|
|
2085
|
+
if (hex.length !== 4) return hex;
|
|
2086
|
+
return `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}`;
|
|
2087
|
+
}
|
|
2088
|
+
var colorControlInstance = 0;
|
|
2089
|
+
var ColorControl = (0, import_vue12.defineComponent)({
|
|
2090
|
+
name: "DialKitColorControl",
|
|
2091
|
+
props: {
|
|
2092
|
+
label: { type: String, required: true },
|
|
2093
|
+
value: { type: String, required: true }
|
|
2094
|
+
},
|
|
2095
|
+
emits: ["change"],
|
|
2096
|
+
setup(props, { emit }) {
|
|
2097
|
+
const textInputId = (0, import_vue12.ref)(`dialkit-color-${++colorControlInstance}`);
|
|
2098
|
+
const isEditing = (0, import_vue12.ref)(false);
|
|
2099
|
+
const editValue = (0, import_vue12.ref)(props.value);
|
|
2100
|
+
const colorInputRef = (0, import_vue12.ref)(null);
|
|
2101
|
+
(0, import_vue12.watch)(() => props.value, (value) => {
|
|
2102
|
+
if (!isEditing.value) editValue.value = value;
|
|
2103
|
+
});
|
|
2104
|
+
const submit = () => {
|
|
2105
|
+
isEditing.value = false;
|
|
2106
|
+
if (HEX_COLOR_REGEX.test(editValue.value)) {
|
|
2107
|
+
emit("change", editValue.value);
|
|
2108
|
+
} else {
|
|
2109
|
+
editValue.value = props.value;
|
|
2110
|
+
}
|
|
2111
|
+
};
|
|
2112
|
+
return () => (0, import_vue12.h)("div", { class: "dialkit-color-control" }, [
|
|
2113
|
+
(0, import_vue12.h)("label", { class: "dialkit-color-label", for: textInputId.value }, props.label),
|
|
2114
|
+
(0, import_vue12.h)("div", { class: "dialkit-color-inputs" }, [
|
|
2115
|
+
isEditing.value ? (0, import_vue12.h)("input", {
|
|
2116
|
+
id: textInputId.value,
|
|
2117
|
+
type: "text",
|
|
2118
|
+
class: "dialkit-color-hex-input",
|
|
2119
|
+
value: editValue.value,
|
|
2120
|
+
autofocus: true,
|
|
2121
|
+
onInput: (event) => {
|
|
2122
|
+
editValue.value = event.target.value;
|
|
2123
|
+
},
|
|
2124
|
+
onBlur: submit,
|
|
2125
|
+
onKeydown: (event) => {
|
|
2126
|
+
if (event.key === "Enter") submit();
|
|
2127
|
+
if (event.key === "Escape") {
|
|
2128
|
+
isEditing.value = false;
|
|
2129
|
+
editValue.value = props.value;
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
}) : (0, import_vue12.h)("span", { class: "dialkit-color-hex", onClick: () => {
|
|
2133
|
+
isEditing.value = true;
|
|
2134
|
+
} }, (props.value ?? "").toUpperCase()),
|
|
2135
|
+
(0, import_vue12.h)("button", {
|
|
2136
|
+
class: "dialkit-color-swatch",
|
|
2137
|
+
style: { backgroundColor: props.value },
|
|
2138
|
+
title: "Pick color",
|
|
2139
|
+
"aria-label": `Pick color for ${props.label}`,
|
|
2140
|
+
onClick: () => colorInputRef.value?.click()
|
|
2141
|
+
}),
|
|
2142
|
+
(0, import_vue12.h)("input", {
|
|
2143
|
+
ref: colorInputRef,
|
|
2144
|
+
type: "color",
|
|
2145
|
+
class: "dialkit-color-picker-native",
|
|
2146
|
+
"aria-label": `${props.label} color picker`,
|
|
2147
|
+
value: props.value.length === 4 ? expandShorthandHex(props.value) : props.value.slice(0, 7),
|
|
2148
|
+
onInput: (event) => emit("change", event.target.value)
|
|
2149
|
+
})
|
|
2150
|
+
])
|
|
2151
|
+
]);
|
|
2152
|
+
}
|
|
2153
|
+
});
|
|
2154
|
+
|
|
2155
|
+
// src/vue/components/PresetManager.ts
|
|
2156
|
+
var import_vue13 = require("vue");
|
|
2157
|
+
var import_motion_v4 = require("motion-v");
|
|
2158
|
+
var PresetManager = (0, import_vue13.defineComponent)({
|
|
2159
|
+
name: "DialKitPresetManager",
|
|
2160
|
+
props: {
|
|
2161
|
+
panelId: { type: String, required: true },
|
|
2162
|
+
presets: {
|
|
2163
|
+
type: Array,
|
|
2164
|
+
required: true
|
|
2165
|
+
},
|
|
2166
|
+
activePresetId: {
|
|
2167
|
+
type: String,
|
|
2168
|
+
required: false,
|
|
2169
|
+
default: null
|
|
2170
|
+
}
|
|
2171
|
+
},
|
|
2172
|
+
setup(props) {
|
|
2173
|
+
const isOpen = (0, import_vue13.ref)(false);
|
|
2174
|
+
const pos = (0, import_vue13.ref)({ top: 0, left: 0, width: 0 });
|
|
2175
|
+
const triggerRef = (0, import_vue13.ref)(null);
|
|
2176
|
+
const dropdownRef = (0, import_vue13.ref)(null);
|
|
2177
|
+
const hasPresets = () => props.presets.length > 0;
|
|
2178
|
+
const activePreset = () => props.presets.find((preset) => preset.id === props.activePresetId);
|
|
2179
|
+
const open = () => {
|
|
2180
|
+
if (!hasPresets()) return;
|
|
2181
|
+
const rect = triggerRef.value?.getBoundingClientRect();
|
|
2182
|
+
if (rect) {
|
|
2183
|
+
pos.value = { top: rect.bottom + 4, left: rect.left, width: rect.width };
|
|
2184
|
+
}
|
|
2185
|
+
isOpen.value = true;
|
|
2186
|
+
};
|
|
2187
|
+
const close = () => {
|
|
2188
|
+
isOpen.value = false;
|
|
2189
|
+
};
|
|
2190
|
+
const setDropdownRef = (node) => {
|
|
2191
|
+
if (node instanceof HTMLElement) {
|
|
2192
|
+
dropdownRef.value = node;
|
|
2193
|
+
return;
|
|
2194
|
+
}
|
|
2195
|
+
if (node && typeof node === "object" && "$el" in node) {
|
|
2196
|
+
const el = node.$el;
|
|
2197
|
+
dropdownRef.value = el instanceof HTMLElement ? el : null;
|
|
2198
|
+
return;
|
|
2199
|
+
}
|
|
2200
|
+
dropdownRef.value = null;
|
|
2201
|
+
};
|
|
2202
|
+
const toggle = () => {
|
|
2203
|
+
if (isOpen.value) close();
|
|
2204
|
+
else open();
|
|
2205
|
+
};
|
|
2206
|
+
(0, import_vue13.watch)(isOpen, (open2, _, onCleanup) => {
|
|
2207
|
+
if (!open2) return;
|
|
2208
|
+
const handler = (event) => {
|
|
2209
|
+
const target = event.target;
|
|
2210
|
+
if (triggerRef.value?.contains(target) || dropdownRef.value?.contains(target)) return;
|
|
2211
|
+
close();
|
|
2212
|
+
};
|
|
2213
|
+
document.addEventListener("mousedown", handler);
|
|
2214
|
+
onCleanup(() => {
|
|
2215
|
+
document.removeEventListener("mousedown", handler);
|
|
2216
|
+
});
|
|
2217
|
+
});
|
|
2218
|
+
const handleSelect = (presetId) => {
|
|
2219
|
+
if (presetId) {
|
|
2220
|
+
DialStore.loadPreset(props.panelId, presetId);
|
|
2221
|
+
} else {
|
|
2222
|
+
DialStore.clearActivePreset(props.panelId);
|
|
2223
|
+
}
|
|
2224
|
+
close();
|
|
2225
|
+
};
|
|
2226
|
+
const handleDelete = (event, presetId) => {
|
|
2227
|
+
event.stopPropagation();
|
|
2228
|
+
DialStore.deletePreset(props.panelId, presetId);
|
|
2229
|
+
};
|
|
2230
|
+
return () => (0, import_vue13.h)("div", { class: "dialkit-preset-manager" }, [
|
|
2231
|
+
(0, import_vue13.h)("button", {
|
|
2232
|
+
ref: triggerRef,
|
|
2233
|
+
class: "dialkit-preset-trigger",
|
|
2234
|
+
onClick: toggle,
|
|
2235
|
+
"data-open": String(isOpen.value),
|
|
2236
|
+
"data-has-preset": String(!!activePreset()),
|
|
2237
|
+
"data-disabled": String(!hasPresets())
|
|
2238
|
+
}, [
|
|
2239
|
+
(0, import_vue13.h)("span", { class: "dialkit-preset-label" }, activePreset()?.name ?? "Version 1"),
|
|
2240
|
+
(0, import_vue13.h)(import_motion_v4.motion.svg, {
|
|
2241
|
+
class: "dialkit-select-chevron",
|
|
2242
|
+
viewBox: "0 0 24 24",
|
|
2243
|
+
fill: "none",
|
|
2244
|
+
stroke: "currentColor",
|
|
2245
|
+
"stroke-width": "2.5",
|
|
2246
|
+
"stroke-linecap": "round",
|
|
2247
|
+
"stroke-linejoin": "round",
|
|
2248
|
+
animate: { rotate: isOpen.value ? 180 : 0, opacity: hasPresets() ? 0.6 : 0.25 },
|
|
2249
|
+
transition: { type: "spring", visualDuration: 0.2, bounce: 0.15 }
|
|
2250
|
+
}, [(0, import_vue13.h)("path", { d: ICON_CHEVRON })])
|
|
2251
|
+
]),
|
|
2252
|
+
(0, import_vue13.h)(import_vue13.Teleport, { to: "body" }, [
|
|
2253
|
+
(0, import_vue13.h)(import_motion_v4.AnimatePresence, null, {
|
|
2254
|
+
default: () => isOpen.value ? [(0, import_vue13.h)(import_motion_v4.motion.div, {
|
|
2255
|
+
key: "dialkit-preset-dropdown",
|
|
2256
|
+
ref: setDropdownRef,
|
|
2257
|
+
class: "dialkit-root dialkit-preset-dropdown",
|
|
2258
|
+
style: {
|
|
2259
|
+
position: "fixed",
|
|
2260
|
+
top: `${pos.value.top}px`,
|
|
2261
|
+
left: `${pos.value.left}px`,
|
|
2262
|
+
minWidth: `${pos.value.width}px`
|
|
2263
|
+
},
|
|
2264
|
+
initial: { opacity: 0, y: 4, scale: 0.97 },
|
|
2265
|
+
animate: { opacity: 1, y: 0, scale: 1 },
|
|
2266
|
+
exit: { opacity: 0, y: 4, scale: 0.97, pointerEvents: "none" },
|
|
2267
|
+
transition: { type: "spring", visualDuration: 0.15, bounce: 0 }
|
|
2268
|
+
}, [
|
|
2269
|
+
(0, import_vue13.h)("div", {
|
|
2270
|
+
class: "dialkit-preset-item",
|
|
2271
|
+
"data-active": String(!props.activePresetId),
|
|
2272
|
+
onClick: () => handleSelect(null)
|
|
2273
|
+
}, [(0, import_vue13.h)("span", { class: "dialkit-preset-name" }, "Version 1")]),
|
|
2274
|
+
...props.presets.map((preset) => (0, import_vue13.h)("div", {
|
|
2275
|
+
key: preset.id,
|
|
2276
|
+
class: "dialkit-preset-item",
|
|
2277
|
+
"data-active": String(preset.id === props.activePresetId),
|
|
2278
|
+
onClick: () => handleSelect(preset.id)
|
|
2279
|
+
}, [
|
|
2280
|
+
(0, import_vue13.h)("span", { class: "dialkit-preset-name" }, preset.name),
|
|
2281
|
+
(0, import_vue13.h)("button", {
|
|
2282
|
+
class: "dialkit-preset-delete",
|
|
2283
|
+
onClick: (event) => handleDelete(event, preset.id),
|
|
2284
|
+
title: "Delete preset"
|
|
2285
|
+
}, [
|
|
2286
|
+
(0, import_vue13.h)("svg", {
|
|
2287
|
+
viewBox: "0 0 24 24",
|
|
2288
|
+
fill: "none",
|
|
2289
|
+
stroke: "currentColor",
|
|
2290
|
+
"stroke-width": "2",
|
|
2291
|
+
"stroke-linecap": "round",
|
|
2292
|
+
"stroke-linejoin": "round"
|
|
2293
|
+
}, ICON_TRASH.map((d) => (0, import_vue13.h)("path", { d })))
|
|
2294
|
+
])
|
|
2295
|
+
]))
|
|
2296
|
+
])] : []
|
|
2297
|
+
})
|
|
2298
|
+
])
|
|
2299
|
+
]);
|
|
2300
|
+
}
|
|
2301
|
+
});
|
|
2302
|
+
|
|
2303
|
+
// src/vue/components/ShortcutListener.ts
|
|
2304
|
+
var import_vue14 = require("vue");
|
|
2305
|
+
var ShortcutKey = /* @__PURE__ */ Symbol("DialKitShortcut");
|
|
2306
|
+
function useShortcutContext() {
|
|
2307
|
+
return (0, import_vue14.inject)(ShortcutKey, {
|
|
2308
|
+
activePanelId: (0, import_vue14.ref)(null),
|
|
2309
|
+
activePath: (0, import_vue14.ref)(null)
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
var ShortcutListener = (0, import_vue14.defineComponent)({
|
|
2313
|
+
name: "DialKitShortcutListener",
|
|
2314
|
+
setup(_, { slots }) {
|
|
2315
|
+
const activePanelId = (0, import_vue14.ref)(null);
|
|
2316
|
+
const activePath = (0, import_vue14.ref)(null);
|
|
2317
|
+
const activeKeys = /* @__PURE__ */ new Set();
|
|
2318
|
+
let isDragging = false;
|
|
2319
|
+
let lastMouseX = null;
|
|
2320
|
+
let dragAccumulator = 0;
|
|
2321
|
+
(0, import_vue14.provide)(ShortcutKey, { activePanelId, activePath });
|
|
2322
|
+
const resolveActiveTarget = (interaction) => {
|
|
2323
|
+
for (const key of activeKeys) {
|
|
2324
|
+
const panels = DialStore.getPanels();
|
|
2325
|
+
for (const panel of panels) {
|
|
2326
|
+
for (const [path, shortcut] of Object.entries(panel.shortcuts)) {
|
|
2327
|
+
if (!shortcut.key) continue;
|
|
2328
|
+
if (shortcut.key.toLowerCase() !== key) continue;
|
|
2329
|
+
if ((shortcut.interaction ?? "scroll") !== interaction) continue;
|
|
2330
|
+
const control = DialStore.getPanel(panel.id)?.controls ? findControl(panel.controls, path) : null;
|
|
2331
|
+
if (control && control.type === "slider") {
|
|
2332
|
+
return { panelId: panel.id, path, control, shortcut };
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
return null;
|
|
2338
|
+
};
|
|
2339
|
+
const handleKeyDown = (e) => {
|
|
2340
|
+
if (isInputFocused()) return;
|
|
2341
|
+
const key = e.key.toLowerCase();
|
|
2342
|
+
if (key === "arrowleft" || key === "arrowright" || key === "arrowup" || key === "arrowdown") {
|
|
2343
|
+
if (activeKeys.size > 0) {
|
|
2344
|
+
const target2 = resolveActiveTarget("scroll") || resolveActiveTarget("drag") || resolveActiveTarget("move");
|
|
2345
|
+
if (target2 && target2.control.type === "slider") {
|
|
2346
|
+
e.preventDefault();
|
|
2347
|
+
const direction = key === "arrowright" || key === "arrowup" ? 1 : -1;
|
|
2348
|
+
const effectiveStep = getEffectiveStep(target2.control, target2.shortcut);
|
|
2349
|
+
applySliderDelta(target2.panelId, target2.path, target2.control, effectiveStep, direction);
|
|
2350
|
+
return;
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
const wasAlreadyHeld = activeKeys.has(key);
|
|
2355
|
+
activeKeys.add(key);
|
|
2356
|
+
const modifier = getActiveModifier(e);
|
|
2357
|
+
const target = DialStore.resolveShortcutTarget(key, modifier);
|
|
2358
|
+
if (target) {
|
|
2359
|
+
activePanelId.value = target.panelId;
|
|
2360
|
+
activePath.value = target.path;
|
|
2361
|
+
if (!wasAlreadyHeld && target.control.type === "toggle") {
|
|
2362
|
+
const currentValue = DialStore.getValue(target.panelId, target.path);
|
|
2363
|
+
DialStore.updateValue(target.panelId, target.path, !currentValue);
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
if (!wasAlreadyHeld) {
|
|
2367
|
+
lastMouseX = null;
|
|
2368
|
+
dragAccumulator = 0;
|
|
2369
|
+
}
|
|
2370
|
+
};
|
|
2371
|
+
const handleKeyUp = (e) => {
|
|
2372
|
+
const key = e.key.toLowerCase();
|
|
2373
|
+
activeKeys.delete(key);
|
|
2374
|
+
isDragging = false;
|
|
2375
|
+
lastMouseX = null;
|
|
2376
|
+
dragAccumulator = 0;
|
|
2377
|
+
if (activeKeys.size === 0) {
|
|
2378
|
+
activePanelId.value = null;
|
|
2379
|
+
activePath.value = null;
|
|
2380
|
+
} else {
|
|
2381
|
+
let found = false;
|
|
2382
|
+
for (const remainingKey of activeKeys) {
|
|
2383
|
+
const modifier = getActiveModifier(e);
|
|
2384
|
+
const target = DialStore.resolveShortcutTarget(remainingKey, modifier);
|
|
2385
|
+
if (target) {
|
|
2386
|
+
activePanelId.value = target.panelId;
|
|
2387
|
+
activePath.value = target.path;
|
|
2388
|
+
found = true;
|
|
2389
|
+
break;
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
if (!found) {
|
|
2393
|
+
activePanelId.value = null;
|
|
2394
|
+
activePath.value = null;
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
};
|
|
2398
|
+
const handleWheel = (e) => {
|
|
2399
|
+
if (isInputFocused()) return;
|
|
2400
|
+
const modifier = getActiveModifier(e);
|
|
2401
|
+
if (activeKeys.size > 0) {
|
|
2402
|
+
for (const key of activeKeys) {
|
|
2403
|
+
const target = DialStore.resolveShortcutTarget(key, modifier);
|
|
2404
|
+
if (!target) continue;
|
|
2405
|
+
const { panelId, path, control } = target;
|
|
2406
|
+
const interaction = control.shortcut?.interaction ?? "scroll";
|
|
2407
|
+
if (interaction !== "scroll" || control.type !== "slider") continue;
|
|
2408
|
+
e.preventDefault();
|
|
2409
|
+
const effectiveStep = getEffectiveStep(control, control.shortcut);
|
|
2410
|
+
const direction = e.deltaY > 0 ? -1 : 1;
|
|
2411
|
+
applySliderDelta(panelId, path, control, effectiveStep, direction);
|
|
2412
|
+
return;
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
const scrollOnlyTargets = DialStore.resolveScrollOnlyTargets();
|
|
2416
|
+
for (const { panelId, path, control, shortcut } of scrollOnlyTargets) {
|
|
2417
|
+
if (control.type !== "slider") continue;
|
|
2418
|
+
e.preventDefault();
|
|
2419
|
+
const effectiveStep = getEffectiveStep(control, shortcut);
|
|
2420
|
+
const direction = e.deltaY > 0 ? -1 : 1;
|
|
2421
|
+
applySliderDelta(panelId, path, control, effectiveStep, direction);
|
|
2422
|
+
return;
|
|
2423
|
+
}
|
|
2424
|
+
};
|
|
2425
|
+
const handleMouseDown = (e) => {
|
|
2426
|
+
if (isInputFocused()) return;
|
|
2427
|
+
if (activeKeys.size === 0) return;
|
|
2428
|
+
const target = resolveActiveTarget("drag");
|
|
2429
|
+
if (target) {
|
|
2430
|
+
isDragging = true;
|
|
2431
|
+
lastMouseX = e.clientX;
|
|
2432
|
+
dragAccumulator = 0;
|
|
2433
|
+
e.preventDefault();
|
|
2434
|
+
}
|
|
2435
|
+
};
|
|
2436
|
+
const handleMouseUp = () => {
|
|
2437
|
+
isDragging = false;
|
|
2438
|
+
lastMouseX = null;
|
|
2439
|
+
dragAccumulator = 0;
|
|
2440
|
+
};
|
|
2441
|
+
const handleMouseMove = (e) => {
|
|
2442
|
+
if (isInputFocused()) return;
|
|
2443
|
+
if (activeKeys.size === 0) return;
|
|
2444
|
+
if (isDragging) {
|
|
2445
|
+
const target = resolveActiveTarget("drag");
|
|
2446
|
+
if (target && lastMouseX !== null) {
|
|
2447
|
+
const deltaX = e.clientX - lastMouseX;
|
|
2448
|
+
lastMouseX = e.clientX;
|
|
2449
|
+
dragAccumulator += deltaX;
|
|
2450
|
+
const effectiveStep = getEffectiveStep(target.control, target.shortcut);
|
|
2451
|
+
const steps = Math.trunc(dragAccumulator / DRAG_SENSITIVITY);
|
|
2452
|
+
if (steps !== 0) {
|
|
2453
|
+
dragAccumulator -= steps * DRAG_SENSITIVITY;
|
|
2454
|
+
applySliderDelta(target.panelId, target.path, target.control, effectiveStep, steps);
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
return;
|
|
2458
|
+
}
|
|
2459
|
+
const moveTarget = resolveActiveTarget("move");
|
|
2460
|
+
if (moveTarget) {
|
|
2461
|
+
if (lastMouseX === null) {
|
|
2462
|
+
lastMouseX = e.clientX;
|
|
2463
|
+
return;
|
|
2464
|
+
}
|
|
2465
|
+
const deltaX = e.clientX - lastMouseX;
|
|
2466
|
+
lastMouseX = e.clientX;
|
|
2467
|
+
dragAccumulator += deltaX;
|
|
2468
|
+
const effectiveStep = getEffectiveStep(moveTarget.control, moveTarget.shortcut);
|
|
2469
|
+
const steps = Math.trunc(dragAccumulator / DRAG_SENSITIVITY);
|
|
2470
|
+
if (steps !== 0) {
|
|
2471
|
+
dragAccumulator -= steps * DRAG_SENSITIVITY;
|
|
2472
|
+
applySliderDelta(moveTarget.panelId, moveTarget.path, moveTarget.control, effectiveStep, steps);
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
};
|
|
2476
|
+
const handleWindowBlur = () => {
|
|
2477
|
+
activeKeys.clear();
|
|
2478
|
+
isDragging = false;
|
|
2479
|
+
lastMouseX = null;
|
|
2480
|
+
dragAccumulator = 0;
|
|
2481
|
+
activePanelId.value = null;
|
|
2482
|
+
activePath.value = null;
|
|
2483
|
+
};
|
|
2484
|
+
(0, import_vue14.onMounted)(() => {
|
|
2485
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
2486
|
+
window.addEventListener("keyup", handleKeyUp);
|
|
2487
|
+
window.addEventListener("wheel", handleWheel, { passive: false });
|
|
2488
|
+
window.addEventListener("mousedown", handleMouseDown);
|
|
2489
|
+
window.addEventListener("mouseup", handleMouseUp);
|
|
2490
|
+
window.addEventListener("mousemove", handleMouseMove);
|
|
2491
|
+
window.addEventListener("blur", handleWindowBlur);
|
|
2492
|
+
});
|
|
2493
|
+
(0, import_vue14.onUnmounted)(() => {
|
|
2494
|
+
window.removeEventListener("keydown", handleKeyDown);
|
|
2495
|
+
window.removeEventListener("keyup", handleKeyUp);
|
|
2496
|
+
window.removeEventListener("wheel", handleWheel);
|
|
2497
|
+
window.removeEventListener("mousedown", handleMouseDown);
|
|
2498
|
+
window.removeEventListener("mouseup", handleMouseUp);
|
|
2499
|
+
window.removeEventListener("mousemove", handleMouseMove);
|
|
2500
|
+
window.removeEventListener("blur", handleWindowBlur);
|
|
2501
|
+
});
|
|
2502
|
+
return () => slots.default?.();
|
|
2503
|
+
}
|
|
2504
|
+
});
|
|
2505
|
+
|
|
2506
|
+
// src/vue/components/Panel.ts
|
|
2507
|
+
var Panel = (0, import_vue15.defineComponent)({
|
|
2508
|
+
name: "DialKitPanel",
|
|
2509
|
+
props: {
|
|
2510
|
+
panel: {
|
|
2511
|
+
type: Object,
|
|
2512
|
+
required: true
|
|
2513
|
+
},
|
|
2514
|
+
defaultOpen: {
|
|
2515
|
+
type: Boolean,
|
|
2516
|
+
default: true
|
|
2517
|
+
},
|
|
2518
|
+
inline: {
|
|
2519
|
+
type: Boolean,
|
|
2520
|
+
default: false
|
|
2521
|
+
}
|
|
2522
|
+
},
|
|
2523
|
+
setup(props) {
|
|
2524
|
+
const shortcutCtx = useShortcutContext();
|
|
2525
|
+
const values = (0, import_vue15.ref)(DialStore.getValues(props.panel.id));
|
|
2526
|
+
const presets = (0, import_vue15.ref)(DialStore.getPresets(props.panel.id));
|
|
2527
|
+
const activePresetId = (0, import_vue15.ref)(DialStore.getActivePresetId(props.panel.id));
|
|
2528
|
+
const copied = (0, import_vue15.ref)(false);
|
|
2529
|
+
const hasShortcuts = () => Object.keys(DialStore.getPanel(props.panel.id)?.shortcuts ?? {}).length > 0;
|
|
2530
|
+
let unsubscribe;
|
|
2531
|
+
let copiedTimeout = null;
|
|
2532
|
+
(0, import_vue15.onMounted)(() => {
|
|
2533
|
+
unsubscribe = DialStore.subscribe(props.panel.id, () => {
|
|
2534
|
+
values.value = DialStore.getValues(props.panel.id);
|
|
2535
|
+
presets.value = DialStore.getPresets(props.panel.id);
|
|
2536
|
+
activePresetId.value = DialStore.getActivePresetId(props.panel.id);
|
|
2537
|
+
});
|
|
2538
|
+
});
|
|
2539
|
+
(0, import_vue15.onUnmounted)(() => {
|
|
2540
|
+
unsubscribe?.();
|
|
2541
|
+
if (copiedTimeout) {
|
|
2542
|
+
window.clearTimeout(copiedTimeout);
|
|
2543
|
+
}
|
|
2544
|
+
});
|
|
2545
|
+
const handleAddPreset = () => {
|
|
2546
|
+
const nextNum = presets.value.length + 2;
|
|
2547
|
+
DialStore.savePreset(props.panel.id, `Version ${nextNum}`);
|
|
2548
|
+
};
|
|
2549
|
+
const handleCopy = () => {
|
|
2550
|
+
const json = JSON.stringify(values.value, null, 2);
|
|
2551
|
+
const instruction = `Update the useDialKit configuration for "${props.panel.name}" with these values:
|
|
2552
|
+
|
|
2553
|
+
\`\`\`json
|
|
2554
|
+
${json}
|
|
2555
|
+
\`\`\`
|
|
2556
|
+
|
|
2557
|
+
Apply these values as the new defaults in the useDialKit call.`;
|
|
2558
|
+
try {
|
|
2559
|
+
if (navigator.clipboard?.writeText) {
|
|
2560
|
+
void navigator.clipboard.writeText(instruction).catch(() => void 0);
|
|
2561
|
+
}
|
|
2562
|
+
} catch {
|
|
2563
|
+
}
|
|
2564
|
+
copied.value = true;
|
|
2565
|
+
if (copiedTimeout) {
|
|
2566
|
+
window.clearTimeout(copiedTimeout);
|
|
2567
|
+
}
|
|
2568
|
+
copiedTimeout = window.setTimeout(() => {
|
|
2569
|
+
copied.value = false;
|
|
2570
|
+
}, 1500);
|
|
2571
|
+
};
|
|
2572
|
+
const renderControl = (control) => {
|
|
2573
|
+
const value = values.value[control.path];
|
|
2574
|
+
switch (control.type) {
|
|
2575
|
+
case "slider":
|
|
2576
|
+
return (0, import_vue15.h)(Slider, {
|
|
2577
|
+
key: control.path,
|
|
2578
|
+
label: control.label,
|
|
2579
|
+
value,
|
|
2580
|
+
min: control.min,
|
|
2581
|
+
max: control.max,
|
|
2582
|
+
step: control.step,
|
|
2583
|
+
shortcut: control.shortcut,
|
|
2584
|
+
shortcutActive: shortcutCtx.activePanelId.value === props.panel.id && shortcutCtx.activePath.value === control.path,
|
|
2585
|
+
onChange: (next) => DialStore.updateValue(props.panel.id, control.path, next)
|
|
2586
|
+
});
|
|
2587
|
+
case "toggle":
|
|
2588
|
+
return (0, import_vue15.h)(Toggle, {
|
|
2589
|
+
key: control.path,
|
|
2590
|
+
label: control.label,
|
|
2591
|
+
checked: value,
|
|
2592
|
+
shortcut: control.shortcut,
|
|
2593
|
+
shortcutActive: shortcutCtx.activePanelId.value === props.panel.id && shortcutCtx.activePath.value === control.path,
|
|
2594
|
+
onChange: (next) => DialStore.updateValue(props.panel.id, control.path, next)
|
|
2595
|
+
});
|
|
2596
|
+
case "spring":
|
|
2597
|
+
return (0, import_vue15.h)(SpringControl, {
|
|
2598
|
+
key: control.path,
|
|
2599
|
+
panelId: props.panel.id,
|
|
2600
|
+
path: control.path,
|
|
2601
|
+
label: control.label,
|
|
2602
|
+
spring: value,
|
|
2603
|
+
onChange: (next) => DialStore.updateValue(props.panel.id, control.path, next)
|
|
2604
|
+
});
|
|
2605
|
+
case "transition":
|
|
2606
|
+
return (0, import_vue15.h)(TransitionControl, {
|
|
2607
|
+
key: control.path,
|
|
2608
|
+
panelId: props.panel.id,
|
|
2609
|
+
path: control.path,
|
|
2610
|
+
label: control.label,
|
|
2611
|
+
value,
|
|
2612
|
+
onChange: (next) => DialStore.updateValue(props.panel.id, control.path, next)
|
|
2613
|
+
});
|
|
2614
|
+
case "folder":
|
|
2615
|
+
return (0, import_vue15.h)(Folder, {
|
|
2616
|
+
key: control.path,
|
|
2617
|
+
title: control.label,
|
|
2618
|
+
defaultOpen: control.defaultOpen ?? true
|
|
2619
|
+
}, {
|
|
2620
|
+
default: () => (control.children ?? []).map(renderControl)
|
|
2621
|
+
});
|
|
2622
|
+
case "text":
|
|
2623
|
+
return (0, import_vue15.h)(TextControl, {
|
|
2624
|
+
key: control.path,
|
|
2625
|
+
label: control.label,
|
|
2626
|
+
value,
|
|
2627
|
+
placeholder: control.placeholder,
|
|
2628
|
+
onChange: (next) => DialStore.updateValue(props.panel.id, control.path, next)
|
|
2629
|
+
});
|
|
2630
|
+
case "select":
|
|
2631
|
+
return (0, import_vue15.h)(SelectControl, {
|
|
2632
|
+
key: control.path,
|
|
2633
|
+
label: control.label,
|
|
2634
|
+
value,
|
|
2635
|
+
options: control.options ?? [],
|
|
2636
|
+
onChange: (next) => DialStore.updateValue(props.panel.id, control.path, next)
|
|
2637
|
+
});
|
|
2638
|
+
case "color":
|
|
2639
|
+
return (0, import_vue15.h)(ColorControl, {
|
|
2640
|
+
key: control.path,
|
|
2641
|
+
label: control.label,
|
|
2642
|
+
value,
|
|
2643
|
+
onChange: (next) => DialStore.updateValue(props.panel.id, control.path, next)
|
|
2644
|
+
});
|
|
2645
|
+
case "action":
|
|
2646
|
+
return (0, import_vue15.h)("button", {
|
|
2647
|
+
key: control.path,
|
|
2648
|
+
class: "dialkit-button",
|
|
2649
|
+
onClick: () => DialStore.triggerAction(props.panel.id, control.path)
|
|
2650
|
+
}, control.label);
|
|
2651
|
+
default:
|
|
2652
|
+
return null;
|
|
2653
|
+
}
|
|
2654
|
+
};
|
|
2655
|
+
return () => {
|
|
2656
|
+
const toolbarNode = (0, import_vue15.h)(import_vue15.Fragment, null, [
|
|
2657
|
+
(0, import_vue15.h)(import_motion_v5.motion.button, {
|
|
2658
|
+
class: "dialkit-toolbar-add",
|
|
2659
|
+
onClick: handleAddPreset,
|
|
2660
|
+
title: "Add preset",
|
|
2661
|
+
whilePress: { scale: 0.9 },
|
|
2662
|
+
transition: { type: "spring", visualDuration: 0.15, bounce: 0.3 }
|
|
2663
|
+
}, [
|
|
2664
|
+
(0, import_vue15.h)("svg", {
|
|
2665
|
+
viewBox: "0 0 24 24",
|
|
2666
|
+
fill: "none",
|
|
2667
|
+
stroke: "currentColor",
|
|
2668
|
+
"stroke-width": "2.5",
|
|
2669
|
+
"stroke-linecap": "round",
|
|
2670
|
+
"stroke-linejoin": "round"
|
|
2671
|
+
}, ICON_ADD_PRESET.map((d) => (0, import_vue15.h)("path", { d })))
|
|
2672
|
+
]),
|
|
2673
|
+
(0, import_vue15.h)(PresetManager, {
|
|
2674
|
+
panelId: props.panel.id,
|
|
2675
|
+
presets: presets.value,
|
|
2676
|
+
activePresetId: activePresetId.value
|
|
2677
|
+
}),
|
|
2678
|
+
(0, import_vue15.h)(import_motion_v5.motion.button, {
|
|
2679
|
+
class: "dialkit-toolbar-copy",
|
|
2680
|
+
onClick: handleCopy,
|
|
2681
|
+
title: "Copy parameters",
|
|
2682
|
+
whilePress: { scale: 0.95 },
|
|
2683
|
+
transition: { type: "spring", visualDuration: 0.15, bounce: 0.3 }
|
|
2684
|
+
}, [
|
|
2685
|
+
(0, import_vue15.h)("span", { class: "dialkit-toolbar-copy-icon-wrap" }, [
|
|
2686
|
+
(0, import_vue15.h)("span", {
|
|
2687
|
+
class: "dialkit-toolbar-copy-icon",
|
|
2688
|
+
style: { opacity: copied.value ? 0 : 1, transition: "opacity 120ms ease" }
|
|
2689
|
+
}, [
|
|
2690
|
+
(0, import_vue15.h)("svg", {
|
|
2691
|
+
viewBox: "0 0 24 24",
|
|
2692
|
+
fill: "none",
|
|
2693
|
+
width: 16,
|
|
2694
|
+
height: 16
|
|
2695
|
+
}, [
|
|
2696
|
+
(0, import_vue15.h)("path", {
|
|
2697
|
+
d: ICON_CLIPBOARD.board,
|
|
2698
|
+
stroke: "currentColor",
|
|
2699
|
+
"stroke-width": 2,
|
|
2700
|
+
"stroke-linejoin": "round"
|
|
2701
|
+
}),
|
|
2702
|
+
(0, import_vue15.h)("path", {
|
|
2703
|
+
d: ICON_CLIPBOARD.sparkle,
|
|
2704
|
+
fill: "currentColor"
|
|
2705
|
+
}),
|
|
2706
|
+
(0, import_vue15.h)("path", {
|
|
2707
|
+
d: ICON_CLIPBOARD.body,
|
|
2708
|
+
stroke: "currentColor",
|
|
2709
|
+
"stroke-width": 2,
|
|
2710
|
+
"stroke-linecap": "round",
|
|
2711
|
+
"stroke-linejoin": "round"
|
|
2712
|
+
})
|
|
2713
|
+
])
|
|
2714
|
+
]),
|
|
2715
|
+
(0, import_vue15.h)(import_motion_v5.AnimatePresence, { initial: false, mode: "popLayout" }, {
|
|
2716
|
+
default: () => copied.value ? [(0, import_vue15.h)(import_motion_v5.motion.span, {
|
|
2717
|
+
key: "check",
|
|
2718
|
+
class: "dialkit-toolbar-copy-icon",
|
|
2719
|
+
initial: { scale: 0.5, opacity: 0 },
|
|
2720
|
+
animate: { scale: 1, opacity: 1 },
|
|
2721
|
+
exit: { scale: 0.5, opacity: 0 },
|
|
2722
|
+
transition: { type: "spring", visualDuration: 0.3, bounce: 0.2 }
|
|
2723
|
+
}, [
|
|
2724
|
+
(0, import_vue15.h)("svg", {
|
|
2725
|
+
viewBox: "0 0 24 24",
|
|
2726
|
+
fill: "none",
|
|
2727
|
+
stroke: "currentColor",
|
|
2728
|
+
"stroke-width": 2,
|
|
2729
|
+
"stroke-linecap": "round",
|
|
2730
|
+
"stroke-linejoin": "round",
|
|
2731
|
+
width: 16,
|
|
2732
|
+
height: 16
|
|
2733
|
+
}, [(0, import_vue15.h)("path", { d: ICON_CHECK })])
|
|
2734
|
+
])] : []
|
|
2735
|
+
})
|
|
2736
|
+
]),
|
|
2737
|
+
"Copy"
|
|
2738
|
+
])
|
|
2739
|
+
]);
|
|
2740
|
+
return (0, import_vue15.h)("div", { class: "dialkit-panel-wrapper" }, [
|
|
2741
|
+
(0, import_vue15.h)(Folder, {
|
|
2742
|
+
title: props.panel.name,
|
|
2743
|
+
defaultOpen: props.defaultOpen,
|
|
2744
|
+
isRoot: true,
|
|
2745
|
+
inline: props.inline,
|
|
2746
|
+
toolbar: () => toolbarNode
|
|
2747
|
+
}, {
|
|
2748
|
+
default: () => props.panel.controls.map(renderControl)
|
|
2749
|
+
})
|
|
2750
|
+
]);
|
|
2751
|
+
};
|
|
2752
|
+
}
|
|
2753
|
+
});
|
|
2754
|
+
|
|
2755
|
+
// src/vue/components/DialRoot.ts
|
|
2756
|
+
var import_meta = {};
|
|
2757
|
+
var isDevDefault = typeof process !== "undefined" && process?.env?.NODE_ENV ? process.env.NODE_ENV !== "production" : typeof import_meta !== "undefined" && import_meta.env?.MODE ? import_meta.env.MODE !== "production" : true;
|
|
2758
|
+
var DialRoot = (0, import_vue16.defineComponent)({
|
|
2759
|
+
name: "DialKitDialRoot",
|
|
2760
|
+
props: {
|
|
2761
|
+
position: {
|
|
2762
|
+
type: String,
|
|
2763
|
+
default: "top-right"
|
|
2764
|
+
},
|
|
2765
|
+
defaultOpen: {
|
|
2766
|
+
type: Boolean,
|
|
2767
|
+
default: true
|
|
2768
|
+
},
|
|
2769
|
+
mode: {
|
|
2770
|
+
type: String,
|
|
2771
|
+
default: "popover"
|
|
2772
|
+
},
|
|
2773
|
+
theme: {
|
|
2774
|
+
type: String,
|
|
2775
|
+
default: "system"
|
|
2776
|
+
},
|
|
2777
|
+
productionEnabled: {
|
|
2778
|
+
type: Boolean,
|
|
2779
|
+
default: isDevDefault
|
|
2780
|
+
}
|
|
2781
|
+
},
|
|
2782
|
+
setup(props) {
|
|
2783
|
+
const panels = (0, import_vue16.ref)([]);
|
|
2784
|
+
const mounted = (0, import_vue16.ref)(false);
|
|
2785
|
+
let unsubscribe;
|
|
2786
|
+
(0, import_vue16.onMounted)(() => {
|
|
2787
|
+
mounted.value = true;
|
|
2788
|
+
panels.value = DialStore.getPanels();
|
|
2789
|
+
unsubscribe = DialStore.subscribeGlobal(() => {
|
|
2790
|
+
panels.value = DialStore.getPanels();
|
|
2791
|
+
});
|
|
2792
|
+
});
|
|
2793
|
+
(0, import_vue16.onUnmounted)(() => {
|
|
2794
|
+
unsubscribe?.();
|
|
2795
|
+
});
|
|
2796
|
+
const renderContent = () => (0, import_vue16.h)(ShortcutListener, null, {
|
|
2797
|
+
default: () => (0, import_vue16.h)("div", { class: "dialkit-root", "data-mode": props.mode, "data-theme": props.theme }, [
|
|
2798
|
+
(0, import_vue16.h)("div", {
|
|
2799
|
+
class: "dialkit-panel",
|
|
2800
|
+
"data-position": props.mode === "inline" ? void 0 : props.position,
|
|
2801
|
+
"data-mode": props.mode
|
|
2802
|
+
}, panels.value.map((panel) => (0, import_vue16.h)(Panel, {
|
|
2803
|
+
key: panel.id,
|
|
2804
|
+
panel,
|
|
2805
|
+
defaultOpen: props.mode === "inline" || props.defaultOpen,
|
|
2806
|
+
inline: props.mode === "inline"
|
|
2807
|
+
})))
|
|
2808
|
+
])
|
|
2809
|
+
});
|
|
2810
|
+
return () => {
|
|
2811
|
+
if (!props.productionEnabled || !mounted.value || typeof window === "undefined" || panels.value.length === 0) {
|
|
2812
|
+
return null;
|
|
2813
|
+
}
|
|
2814
|
+
if (props.mode === "inline") {
|
|
2815
|
+
return renderContent();
|
|
2816
|
+
}
|
|
2817
|
+
return (0, import_vue16.h)(import_vue16.Teleport, { to: "body" }, renderContent());
|
|
2818
|
+
};
|
|
2819
|
+
}
|
|
2820
|
+
});
|
|
2821
|
+
|
|
2822
|
+
// src/vue/directives/dialkit.ts
|
|
2823
|
+
var states = /* @__PURE__ */ new WeakMap();
|
|
2824
|
+
function normalizeDirectiveValue(value) {
|
|
2825
|
+
if (!value) return {};
|
|
2826
|
+
if (value === "inline" || value === "popover") {
|
|
2827
|
+
return { mode: value };
|
|
2828
|
+
}
|
|
2829
|
+
return value;
|
|
2830
|
+
}
|
|
2831
|
+
function mountDialRoot(el, value) {
|
|
2832
|
+
if (typeof window === "undefined") return;
|
|
2833
|
+
const host = document.createElement("div");
|
|
2834
|
+
el.appendChild(host);
|
|
2835
|
+
const props = (0, import_vue17.shallowRef)(normalizeDirectiveValue(value));
|
|
2836
|
+
const RootHost = (0, import_vue17.defineComponent)({
|
|
2837
|
+
name: "DialKitDirectiveHost",
|
|
2838
|
+
setup() {
|
|
2839
|
+
return () => (0, import_vue17.h)(DialRoot, props.value);
|
|
2840
|
+
}
|
|
2841
|
+
});
|
|
2842
|
+
const app = (0, import_vue17.createApp)(RootHost);
|
|
2843
|
+
app.mount(host);
|
|
2844
|
+
states.set(el, { app, host, props });
|
|
2845
|
+
}
|
|
2846
|
+
function unmountDialRoot(el) {
|
|
2847
|
+
const state = states.get(el);
|
|
2848
|
+
if (!state) return;
|
|
2849
|
+
state.app.unmount();
|
|
2850
|
+
state.host.remove();
|
|
2851
|
+
states.delete(el);
|
|
2852
|
+
}
|
|
2853
|
+
var vDialKit = {
|
|
2854
|
+
mounted(el, binding) {
|
|
2855
|
+
mountDialRoot(el, binding.value);
|
|
2856
|
+
},
|
|
2857
|
+
updated(el, binding) {
|
|
2858
|
+
const state = states.get(el);
|
|
2859
|
+
if (!state) {
|
|
2860
|
+
mountDialRoot(el, binding.value);
|
|
2861
|
+
return;
|
|
2862
|
+
}
|
|
2863
|
+
state.props.value = normalizeDirectiveValue(binding.value);
|
|
2864
|
+
},
|
|
2865
|
+
beforeUnmount(el) {
|
|
2866
|
+
unmountDialRoot(el);
|
|
2867
|
+
}
|
|
2868
|
+
};
|
|
2869
|
+
|
|
2870
|
+
// src/vue/components/ShortcutsMenu.ts
|
|
2871
|
+
var import_vue18 = require("vue");
|
|
2872
|
+
function formatShortcutKey(sc) {
|
|
2873
|
+
if (!sc.key) return "\u2014";
|
|
2874
|
+
const mod = sc.modifier === "alt" ? "\u2325" : sc.modifier === "shift" ? "\u21E7" : sc.modifier === "meta" ? "\u2318" : "";
|
|
2875
|
+
return `${mod}${sc.key.toUpperCase()}`;
|
|
2876
|
+
}
|
|
2877
|
+
function formatInteraction(sc) {
|
|
2878
|
+
const interaction = sc.interaction ?? "scroll";
|
|
2879
|
+
switch (interaction) {
|
|
2880
|
+
case "scroll":
|
|
2881
|
+
return sc.key ? "key+scroll" : "scroll";
|
|
2882
|
+
case "drag":
|
|
2883
|
+
return "key+drag";
|
|
2884
|
+
case "move":
|
|
2885
|
+
return "key+move";
|
|
2886
|
+
case "scroll-only":
|
|
2887
|
+
return "scroll";
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
var ShortcutsMenu = (0, import_vue18.defineComponent)({
|
|
2891
|
+
name: "DialKitShortcutsMenu",
|
|
2892
|
+
props: {
|
|
2893
|
+
panelId: {
|
|
2894
|
+
type: String,
|
|
2895
|
+
required: true
|
|
2896
|
+
}
|
|
2897
|
+
},
|
|
2898
|
+
setup(props) {
|
|
2899
|
+
const isOpen = (0, import_vue18.ref)(false);
|
|
2900
|
+
const triggerRef = (0, import_vue18.ref)(null);
|
|
2901
|
+
const dropdownRef = (0, import_vue18.ref)(null);
|
|
2902
|
+
const pos = (0, import_vue18.ref)({ top: 0, right: 0 });
|
|
2903
|
+
const open = () => {
|
|
2904
|
+
const rect = triggerRef.value?.getBoundingClientRect();
|
|
2905
|
+
if (rect) {
|
|
2906
|
+
pos.value = { top: rect.bottom + 4, right: window.innerWidth - rect.right };
|
|
2907
|
+
}
|
|
2908
|
+
isOpen.value = true;
|
|
2909
|
+
};
|
|
2910
|
+
const close = () => {
|
|
2911
|
+
isOpen.value = false;
|
|
2912
|
+
};
|
|
2913
|
+
const toggle = () => {
|
|
2914
|
+
if (isOpen.value) close();
|
|
2915
|
+
else open();
|
|
2916
|
+
};
|
|
2917
|
+
let mousedownHandler = null;
|
|
2918
|
+
const addOutsideClickListener = () => {
|
|
2919
|
+
mousedownHandler = (e) => {
|
|
2920
|
+
const target = e.target;
|
|
2921
|
+
if (triggerRef.value?.contains(target) || dropdownRef.value?.contains(target)) return;
|
|
2922
|
+
close();
|
|
2923
|
+
};
|
|
2924
|
+
document.addEventListener("mousedown", mousedownHandler);
|
|
2925
|
+
};
|
|
2926
|
+
const removeOutsideClickListener = () => {
|
|
2927
|
+
if (mousedownHandler) {
|
|
2928
|
+
document.removeEventListener("mousedown", mousedownHandler);
|
|
2929
|
+
mousedownHandler = null;
|
|
2930
|
+
}
|
|
2931
|
+
};
|
|
2932
|
+
(0, import_vue18.onUnmounted)(() => {
|
|
2933
|
+
removeOutsideClickListener();
|
|
2934
|
+
});
|
|
2935
|
+
return () => {
|
|
2936
|
+
const panel = DialStore.getPanel(props.panelId);
|
|
2937
|
+
if (!panel) return null;
|
|
2938
|
+
const shortcuts = Object.entries(panel.shortcuts);
|
|
2939
|
+
if (shortcuts.length === 0) return null;
|
|
2940
|
+
const findLabel = (controls, path) => {
|
|
2941
|
+
for (const c of controls) {
|
|
2942
|
+
if (c.path === path) return c.label;
|
|
2943
|
+
if (c.type === "folder" && c.children) {
|
|
2944
|
+
const found = findLabel(c.children, path);
|
|
2945
|
+
if (found) return found;
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
return path;
|
|
2949
|
+
};
|
|
2950
|
+
const rows = shortcuts.map(([path, shortcut]) => ({
|
|
2951
|
+
path,
|
|
2952
|
+
shortcut,
|
|
2953
|
+
label: findLabel(panel.controls, path)
|
|
2954
|
+
}));
|
|
2955
|
+
if (isOpen.value) {
|
|
2956
|
+
if (!mousedownHandler) addOutsideClickListener();
|
|
2957
|
+
} else {
|
|
2958
|
+
removeOutsideClickListener();
|
|
2959
|
+
}
|
|
2960
|
+
return [
|
|
2961
|
+
(0, import_vue18.h)("button", {
|
|
2962
|
+
ref: triggerRef,
|
|
2963
|
+
class: "dialkit-shortcuts-trigger",
|
|
2964
|
+
onClick: toggle,
|
|
2965
|
+
title: "Keyboard shortcuts"
|
|
2966
|
+
}, [
|
|
2967
|
+
(0, import_vue18.h)("svg", {
|
|
2968
|
+
viewBox: "0 0 24 24",
|
|
2969
|
+
fill: "none",
|
|
2970
|
+
stroke: "currentColor",
|
|
2971
|
+
"stroke-width": "2",
|
|
2972
|
+
"stroke-linecap": "round",
|
|
2973
|
+
"stroke-linejoin": "round"
|
|
2974
|
+
}, [
|
|
2975
|
+
(0, import_vue18.h)("rect", { x: "2", y: "6", width: "20", height: "12", rx: "2" }),
|
|
2976
|
+
(0, import_vue18.h)("path", { d: "M6 10H6.01" }),
|
|
2977
|
+
(0, import_vue18.h)("path", { d: "M10 10H10.01" }),
|
|
2978
|
+
(0, import_vue18.h)("path", { d: "M14 10H14.01" }),
|
|
2979
|
+
(0, import_vue18.h)("path", { d: "M18 10H18.01" }),
|
|
2980
|
+
(0, import_vue18.h)("path", { d: "M8 14H16" })
|
|
2981
|
+
])
|
|
2982
|
+
]),
|
|
2983
|
+
isOpen.value ? (0, import_vue18.h)(import_vue18.Teleport, { to: "body" }, [
|
|
2984
|
+
(0, import_vue18.h)("div", {
|
|
2985
|
+
ref: dropdownRef,
|
|
2986
|
+
class: "dialkit-root dialkit-shortcuts-dropdown",
|
|
2987
|
+
style: {
|
|
2988
|
+
position: "fixed",
|
|
2989
|
+
top: `${pos.value.top}px`,
|
|
2990
|
+
right: `${pos.value.right}px`
|
|
2991
|
+
}
|
|
2992
|
+
}, [
|
|
2993
|
+
(0, import_vue18.h)("div", { class: "dialkit-shortcuts-title" }, "Keyboard Shortcuts"),
|
|
2994
|
+
(0, import_vue18.h)(
|
|
2995
|
+
"div",
|
|
2996
|
+
{ class: "dialkit-shortcuts-list" },
|
|
2997
|
+
rows.map(
|
|
2998
|
+
(row) => (0, import_vue18.h)("div", { key: row.path, class: "dialkit-shortcuts-row" }, [
|
|
2999
|
+
(0, import_vue18.h)("span", { class: "dialkit-shortcuts-row-key" }, formatShortcutKey(row.shortcut)),
|
|
3000
|
+
(0, import_vue18.h)("span", { class: "dialkit-shortcuts-row-label" }, row.label),
|
|
3001
|
+
(0, import_vue18.h)("span", { class: "dialkit-shortcuts-row-mode" }, formatInteraction(row.shortcut))
|
|
3002
|
+
])
|
|
3003
|
+
)
|
|
3004
|
+
),
|
|
3005
|
+
(0, import_vue18.h)("div", { class: "dialkit-shortcuts-hint" }, "See pill badges on controls for keys")
|
|
3006
|
+
])
|
|
3007
|
+
]) : null
|
|
3008
|
+
];
|
|
3009
|
+
};
|
|
3010
|
+
}
|
|
3011
|
+
});
|
|
3012
|
+
|
|
3013
|
+
// src/vue/components/ButtonGroup.ts
|
|
3014
|
+
var import_vue19 = require("vue");
|
|
3015
|
+
var ButtonGroup = (0, import_vue19.defineComponent)({
|
|
3016
|
+
name: "DialKitButtonGroup",
|
|
3017
|
+
props: {
|
|
3018
|
+
buttons: {
|
|
3019
|
+
type: Array,
|
|
3020
|
+
required: true
|
|
3021
|
+
}
|
|
3022
|
+
},
|
|
3023
|
+
setup(props) {
|
|
3024
|
+
return () => (0, import_vue19.h)(
|
|
3025
|
+
"div",
|
|
3026
|
+
{ class: "dialkit-button-group" },
|
|
3027
|
+
props.buttons.map(
|
|
3028
|
+
(button) => (0, import_vue19.h)("button", { class: "dialkit-button", onClick: button.onClick }, button.label)
|
|
3029
|
+
)
|
|
3030
|
+
);
|
|
3031
|
+
}
|
|
3032
|
+
});
|
|
3033
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3034
|
+
0 && (module.exports = {
|
|
3035
|
+
ButtonGroup,
|
|
3036
|
+
ColorControl,
|
|
3037
|
+
DialRoot,
|
|
3038
|
+
DialStore,
|
|
3039
|
+
EasingVisualization,
|
|
3040
|
+
Folder,
|
|
3041
|
+
PresetManager,
|
|
3042
|
+
SelectControl,
|
|
3043
|
+
ShortcutKey,
|
|
3044
|
+
ShortcutListener,
|
|
3045
|
+
ShortcutsMenu,
|
|
3046
|
+
Slider,
|
|
3047
|
+
SpringControl,
|
|
3048
|
+
SpringVisualization,
|
|
3049
|
+
TextControl,
|
|
3050
|
+
Toggle,
|
|
3051
|
+
TransitionControl,
|
|
3052
|
+
useDialKit,
|
|
3053
|
+
useShortcutContext,
|
|
3054
|
+
vDialKit
|
|
3055
|
+
});
|
|
3056
|
+
//# sourceMappingURL=index.cjs.map
|