mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-24 06:32:12 -03:00
feat: add .opencode to gitignore and refactor lora routes
- Add .opencode directory to gitignore for agent-related files - Refactor lora_routes.py with consistent string formatting and improved route registration - Add DualRangeSlider Vue component for enhanced UI controls
This commit is contained in:
@@ -104,7 +104,7 @@ onMounted(async () => {
|
||||
|
||||
// Handle external value updates (e.g., loading workflow, paste)
|
||||
props.widget.onSetValue = (v) => {
|
||||
state.restoreFromConfig(v)
|
||||
state.restoreFromConfig(v as LoraPoolConfig | LegacyLoraPoolConfig)
|
||||
state.refreshPreview()
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
<!-- LoRA Count -->
|
||||
<div class="setting-section">
|
||||
<label class="setting-label">LoRA Count</label>
|
||||
<div class="count-mode-selector">
|
||||
<label class="radio-label">
|
||||
<div class="count-mode-tabs">
|
||||
<label class="count-mode-tab" :class="{ active: countMode === 'fixed' }">
|
||||
<input
|
||||
type="radio"
|
||||
name="count-mode"
|
||||
@@ -16,20 +16,9 @@
|
||||
:checked="countMode === 'fixed'"
|
||||
@change="$emit('update:countMode', 'fixed')"
|
||||
/>
|
||||
<span>Fixed:</span>
|
||||
<input
|
||||
type="number"
|
||||
class="number-input"
|
||||
:value="countFixed"
|
||||
:disabled="countMode !== 'fixed'"
|
||||
min="1"
|
||||
max="100"
|
||||
@input="$emit('update:countFixed', parseInt(($event.target as HTMLInputElement).value))"
|
||||
/>
|
||||
<span class="count-mode-tab-label">Fixed</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="count-mode-selector">
|
||||
<label class="radio-label">
|
||||
<label class="count-mode-tab" :class="{ active: countMode === 'range' }">
|
||||
<input
|
||||
type="radio"
|
||||
name="count-mode"
|
||||
@@ -37,101 +26,82 @@
|
||||
:checked="countMode === 'range'"
|
||||
@change="$emit('update:countMode', 'range')"
|
||||
/>
|
||||
<span>Range:</span>
|
||||
<input
|
||||
type="number"
|
||||
class="number-input"
|
||||
:value="countMin"
|
||||
:disabled="countMode !== 'range'"
|
||||
min="1"
|
||||
max="100"
|
||||
@input="$emit('update:countMin', parseInt(($event.target as HTMLInputElement).value))"
|
||||
/>
|
||||
<span>to</span>
|
||||
<input
|
||||
type="number"
|
||||
class="number-input"
|
||||
:value="countMax"
|
||||
:disabled="countMode !== 'range'"
|
||||
min="1"
|
||||
max="100"
|
||||
@input="$emit('update:countMax', parseInt(($event.target as HTMLInputElement).value))"
|
||||
/>
|
||||
<span class="count-mode-tab-label">Range</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="slider-container">
|
||||
<SingleSlider
|
||||
v-if="countMode === 'fixed'"
|
||||
:min="1"
|
||||
:max="10"
|
||||
:value="countFixed"
|
||||
:step="1"
|
||||
:default-range="{ min: 1, max: 5 }"
|
||||
@update:value="$emit('update:countFixed', $event)"
|
||||
/>
|
||||
<DualRangeSlider
|
||||
v-else
|
||||
:min="1"
|
||||
:max="10"
|
||||
:value-min="countMin"
|
||||
:value-max="countMax"
|
||||
:step="1"
|
||||
:default-range="{ min: 1, max: 5 }"
|
||||
@update:value-min="$emit('update:countMin', $event)"
|
||||
@update:value-max="$emit('update:countMax', $event)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Model Strength Range -->
|
||||
<div class="setting-section">
|
||||
<label class="setting-label">Model Strength Range</label>
|
||||
<div class="strength-inputs">
|
||||
<div class="strength-input-group">
|
||||
<label>Min:</label>
|
||||
<input
|
||||
type="number"
|
||||
class="number-input"
|
||||
:value="modelStrengthMin"
|
||||
min="0"
|
||||
max="10"
|
||||
step="0.1"
|
||||
@input="$emit('update:modelStrengthMin', parseFloat(($event.target as HTMLInputElement).value))"
|
||||
/>
|
||||
</div>
|
||||
<div class="strength-input-group">
|
||||
<label>Max:</label>
|
||||
<input
|
||||
type="number"
|
||||
class="number-input"
|
||||
:value="modelStrengthMax"
|
||||
min="0"
|
||||
max="10"
|
||||
step="0.1"
|
||||
@input="$emit('update:modelStrengthMax', parseFloat(($event.target as HTMLInputElement).value))"
|
||||
/>
|
||||
</div>
|
||||
<div class="slider-container">
|
||||
<DualRangeSlider
|
||||
:min="-10"
|
||||
:max="10"
|
||||
:value-min="modelStrengthMin"
|
||||
:value-max="modelStrengthMax"
|
||||
:step="0.1"
|
||||
:default-range="{ min: -2, max: 3 }"
|
||||
@update:value-min="$emit('update:modelStrengthMin', $event)"
|
||||
@update:value-max="$emit('update:modelStrengthMax', $event)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Clip Strength Range -->
|
||||
<div class="setting-section">
|
||||
<label class="setting-label">Clip Strength Range</label>
|
||||
<div class="checkbox-group">
|
||||
<label class="checkbox-label">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="useSameClipStrength"
|
||||
@change="$emit('update:useSameClipStrength', ($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
<span>Same as model</span>
|
||||
<div class="section-header-with-toggle">
|
||||
<label class="setting-label">
|
||||
Clip Strength Range - {{ useSameClipStrength ? 'Use Model Strength' : 'Custom Range' }}
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
class="toggle-switch"
|
||||
:class="{ 'toggle-switch--active': useSameClipStrength }"
|
||||
@click="$emit('update:useSameClipStrength', !useSameClipStrength)"
|
||||
role="switch"
|
||||
:aria-checked="useSameClipStrength"
|
||||
title="Lock clip strength to model strength"
|
||||
>
|
||||
<span class="toggle-switch__track"></span>
|
||||
<span class="toggle-switch__thumb"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="strength-inputs" :class="{ disabled: isClipStrengthDisabled }">
|
||||
<div class="strength-input-group">
|
||||
<label>Min:</label>
|
||||
<input
|
||||
type="number"
|
||||
class="number-input"
|
||||
:value="clipStrengthMin"
|
||||
:disabled="isClipStrengthDisabled"
|
||||
min="0"
|
||||
max="10"
|
||||
step="0.1"
|
||||
@input="$emit('update:clipStrengthMin', parseFloat(($event.target as HTMLInputElement).value))"
|
||||
/>
|
||||
</div>
|
||||
<div class="strength-input-group">
|
||||
<label>Max:</label>
|
||||
<input
|
||||
type="number"
|
||||
class="number-input"
|
||||
:value="clipStrengthMax"
|
||||
:disabled="isClipStrengthDisabled"
|
||||
min="0"
|
||||
max="10"
|
||||
step="0.1"
|
||||
@input="$emit('update:clipStrengthMax', parseFloat(($event.target as HTMLInputElement).value))"
|
||||
/>
|
||||
</div>
|
||||
<div class="slider-container">
|
||||
<DualRangeSlider
|
||||
:min="-10"
|
||||
:max="10"
|
||||
:value-min="clipStrengthMin"
|
||||
:value-max="clipStrengthMax"
|
||||
:step="0.1"
|
||||
:default-range="{ min: -1, max: 2 }"
|
||||
:disabled="isClipStrengthDisabled"
|
||||
@update:value-min="$emit('update:clipStrengthMin', $event)"
|
||||
@update:value-max="$emit('update:clipStrengthMax', $event)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -200,6 +170,8 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import LastUsedPreview from './LastUsedPreview.vue'
|
||||
import SingleSlider from '../shared/SingleSlider.vue'
|
||||
import DualRangeSlider from '../shared/DualRangeSlider.vue'
|
||||
import type { LoraEntry } from '../../composables/types'
|
||||
|
||||
defineProps<{
|
||||
@@ -255,123 +227,155 @@ const areLorasEqual = (a: LoraEntry[] | null, b: LoraEntry[] | null): boolean =>
|
||||
.randomizer-settings {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
color: #e4e4e7;
|
||||
}
|
||||
|
||||
.settings-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.settings-title {
|
||||
font-size: 11px;
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.05em;
|
||||
color: #a1a1aa;
|
||||
color: var(--fg-color, #fff);
|
||||
opacity: 0.6;
|
||||
margin: 0;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.setting-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.setting-label {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: #d4d4d8;
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.count-mode-selector,
|
||||
.roll-mode-selector {
|
||||
.section-header-with-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 8px;
|
||||
background: rgba(30, 30, 36, 0.5);
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.section-header-with-toggle .setting-label {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
/* Count Mode Tabs */
|
||||
.count-mode-tabs {
|
||||
display: flex;
|
||||
background: rgba(26, 32, 44, 0.9);
|
||||
border: 1px solid rgba(226, 232, 240, 0.2);
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.radio-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
color: #e4e4e7;
|
||||
cursor: pointer;
|
||||
.count-mode-tab {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.radio-label input[type='radio'] {
|
||||
position: relative;
|
||||
padding: 8px 12px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.radio-label input[type='radio']:disabled {
|
||||
cursor: not-allowed;
|
||||
.count-mode-tab input[type="radio"] {
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
.number-input {
|
||||
width: 60px;
|
||||
padding: 4px 8px;
|
||||
background: rgba(20, 20, 24, 0.6);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-radius: 3px;
|
||||
color: #e4e4e7;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.number-input:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.strength-inputs {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
padding: 6px 8px;
|
||||
background: rgba(30, 30, 36, 0.5);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.strength-inputs.disabled {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.strength-input-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.strength-input-group label {
|
||||
.count-mode-tab-label {
|
||||
font-size: 12px;
|
||||
color: #d4d4d8;
|
||||
font-weight: 500;
|
||||
color: rgba(226, 232, 240, 0.7);
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.checkbox-group {
|
||||
padding: 6px 8px;
|
||||
background: rgba(30, 30, 36, 0.5);
|
||||
.count-mode-tab:hover .count-mode-tab-label {
|
||||
color: rgba(226, 232, 240, 0.9);
|
||||
}
|
||||
|
||||
.count-mode-tab.active .count-mode-tab-label {
|
||||
color: rgba(191, 219, 254, 1);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.count-mode-tab.active {
|
||||
background: rgba(66, 153, 225, 0.2);
|
||||
}
|
||||
|
||||
.count-mode-tab.active::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 2px;
|
||||
background: rgba(66, 153, 225, 0.9);
|
||||
}
|
||||
|
||||
.slider-container {
|
||||
background: rgba(26, 32, 44, 0.9);
|
||||
border: 1px solid rgba(226, 232, 240, 0.2);
|
||||
border-radius: 4px;
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
.checkbox-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
color: #e4e4e7;
|
||||
/* Toggle Switch (same style as LicenseSection) */
|
||||
.toggle-switch {
|
||||
position: relative;
|
||||
width: 36px;
|
||||
height: 20px;
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.checkbox-label input[type='checkbox'] {
|
||||
cursor: pointer;
|
||||
.toggle-switch__track {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: var(--comfy-input-bg, #333);
|
||||
border: 1px solid var(--border-color, #444);
|
||||
border-radius: 10px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.toggle-switch--active .toggle-switch__track {
|
||||
background: rgba(66, 153, 225, 0.3);
|
||||
border-color: rgba(66, 153, 225, 0.6);
|
||||
}
|
||||
|
||||
.toggle-switch__thumb {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
background: var(--fg-color, #fff);
|
||||
border-radius: 50%;
|
||||
transition: all 0.2s;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.toggle-switch--active .toggle-switch__thumb {
|
||||
transform: translateX(16px);
|
||||
background: #4299e1;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.toggle-switch:hover .toggle-switch__thumb {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Roll buttons with tooltip container */
|
||||
|
||||
295
vue-widgets/src/components/shared/DualRangeSlider.vue
Normal file
295
vue-widgets/src/components/shared/DualRangeSlider.vue
Normal file
@@ -0,0 +1,295 @@
|
||||
<template>
|
||||
<div class="dual-range-slider" :class="{ disabled }" @wheel="onWheel">
|
||||
<div class="slider-track" ref="trackEl">
|
||||
<!-- Background track -->
|
||||
<div class="slider-track__bg"></div>
|
||||
<!-- Active track (colored range between handles) -->
|
||||
<div
|
||||
class="slider-track__active"
|
||||
:style="{ left: minPercent + '%', width: (maxPercent - minPercent) + '%' }"
|
||||
></div>
|
||||
<!-- Default range indicators -->
|
||||
<div
|
||||
v-if="defaultRange"
|
||||
class="slider-track__default"
|
||||
:style="{
|
||||
left: defaultMinPercent + '%',
|
||||
width: (defaultMaxPercent - defaultMinPercent) + '%'
|
||||
}"
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<!-- Handles with value labels -->
|
||||
<div
|
||||
class="slider-handle slider-handle--min"
|
||||
:style="{ left: minPercent + '%' }"
|
||||
@mousedown="startDrag('min', $event)"
|
||||
@touchstart="startDrag('min', $event)"
|
||||
>
|
||||
<div class="slider-handle__thumb"></div>
|
||||
<div class="slider-handle__value">{{ formatValue(valueMin) }}</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="slider-handle slider-handle--max"
|
||||
:style="{ left: maxPercent + '%' }"
|
||||
@mousedown="startDrag('max', $event)"
|
||||
@touchstart="startDrag('max', $event)"
|
||||
>
|
||||
<div class="slider-handle__thumb"></div>
|
||||
<div class="slider-handle__value">{{ formatValue(valueMax) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onUnmounted } from 'vue'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
min: number
|
||||
max: number
|
||||
valueMin: number
|
||||
valueMax: number
|
||||
step: number
|
||||
defaultRange?: { min: number; max: number }
|
||||
disabled?: boolean
|
||||
}>(), {
|
||||
disabled: false
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:valueMin': [value: number]
|
||||
'update:valueMax': [value: number]
|
||||
}>()
|
||||
|
||||
const trackEl = ref<HTMLElement | null>(null)
|
||||
const dragging = ref<'min' | 'max' | null>(null)
|
||||
|
||||
const minPercent = computed(() => {
|
||||
const range = props.max - props.min
|
||||
return ((props.valueMin - props.min) / range) * 100
|
||||
})
|
||||
|
||||
const maxPercent = computed(() => {
|
||||
const range = props.max - props.min
|
||||
return ((props.valueMax - props.min) / range) * 100
|
||||
})
|
||||
|
||||
const defaultMinPercent = computed(() => {
|
||||
if (!props.defaultRange) return 0
|
||||
const range = props.max - props.min
|
||||
return ((props.defaultRange.min - props.min) / range) * 100
|
||||
})
|
||||
|
||||
const defaultMaxPercent = computed(() => {
|
||||
if (!props.defaultRange) return 100
|
||||
const range = props.max - props.min
|
||||
return ((props.defaultRange.max - props.min) / range) * 100
|
||||
})
|
||||
|
||||
const formatValue = (val: number): string => {
|
||||
if (Number.isInteger(val)) return val.toString()
|
||||
return val.toFixed(stepToDecimals(props.step))
|
||||
}
|
||||
|
||||
const stepToDecimals = (step: number): number => {
|
||||
const str = step.toString()
|
||||
const decimalIndex = str.indexOf('.')
|
||||
return decimalIndex === -1 ? 0 : str.length - decimalIndex - 1
|
||||
}
|
||||
|
||||
const snapToStep = (value: number): number => {
|
||||
const steps = Math.round((value - props.min) / props.step)
|
||||
return Math.max(props.min, Math.min(props.max, props.min + steps * props.step))
|
||||
}
|
||||
|
||||
const startDrag = (handle: 'min' | 'max', event: MouseEvent | TouchEvent) => {
|
||||
if (props.disabled) return
|
||||
|
||||
event.preventDefault()
|
||||
dragging.value = handle
|
||||
|
||||
document.addEventListener('mousemove', onDrag)
|
||||
document.addEventListener('mouseup', stopDrag)
|
||||
document.addEventListener('touchmove', onDrag, { passive: false })
|
||||
document.addEventListener('touchend', stopDrag)
|
||||
}
|
||||
|
||||
const onDrag = (event: MouseEvent | TouchEvent) => {
|
||||
if (!trackEl.value || !dragging.value) return
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
const clientX = 'touches' in event ? event.touches[0].clientX : event.clientX
|
||||
const rect = trackEl.value.getBoundingClientRect()
|
||||
const percent = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width))
|
||||
const rawValue = props.min + percent * (props.max - props.min)
|
||||
const value = snapToStep(rawValue)
|
||||
|
||||
if (dragging.value === 'min') {
|
||||
const maxAllowed = props.valueMax - props.step
|
||||
const newValue = Math.min(value, maxAllowed)
|
||||
emit('update:valueMin', newValue)
|
||||
} else {
|
||||
const minAllowed = props.valueMin + props.step
|
||||
const newValue = Math.max(value, minAllowed)
|
||||
emit('update:valueMax', newValue)
|
||||
}
|
||||
}
|
||||
|
||||
const onWheel = (event: WheelEvent) => {
|
||||
if (props.disabled) return
|
||||
|
||||
const rect = trackEl.value?.getBoundingClientRect()
|
||||
if (!rect) return
|
||||
|
||||
const rootRect = (event.currentTarget as HTMLElement).getBoundingClientRect()
|
||||
if (event.clientX < rootRect.left || event.clientX > rootRect.right ||
|
||||
event.clientY < rootRect.top || event.clientY > rootRect.bottom) return
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
const delta = event.deltaY > 0 ? -1 : 1
|
||||
const relativeX = event.clientX - rect.left
|
||||
const rangeWidth = rect.width
|
||||
|
||||
const minPixel = (minPercent.value / 100) * rangeWidth
|
||||
const maxPixel = (maxPercent.value / 100) * rangeWidth
|
||||
|
||||
if (relativeX < minPixel) {
|
||||
const newValue = snapToStep(props.valueMin + delta * props.step)
|
||||
const maxAllowed = props.valueMax - props.step
|
||||
emit('update:valueMin', Math.min(newValue, maxAllowed))
|
||||
} else if (relativeX > maxPixel) {
|
||||
const newValue = snapToStep(props.valueMax + delta * props.step)
|
||||
const minAllowed = props.valueMin + props.step
|
||||
emit('update:valueMax', Math.max(newValue, minAllowed))
|
||||
} else {
|
||||
const newMin = snapToStep(props.valueMin - delta * props.step)
|
||||
const newMax = snapToStep(props.valueMax + delta * props.step)
|
||||
|
||||
if (newMin < props.valueMin) {
|
||||
emit('update:valueMin', Math.max(newMin, props.min))
|
||||
emit('update:valueMax', Math.min(newMax, props.max))
|
||||
} else {
|
||||
if (newMin < newMax - props.step) {
|
||||
emit('update:valueMin', newMin)
|
||||
emit('update:valueMax', newMax)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const stopDrag = () => {
|
||||
dragging.value = null
|
||||
document.removeEventListener('mousemove', onDrag)
|
||||
document.removeEventListener('mouseup', stopDrag)
|
||||
document.removeEventListener('touchmove', onDrag)
|
||||
document.removeEventListener('touchend', stopDrag)
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
stopDrag()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dual-range-slider {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 32px;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.dual-range-slider.disabled {
|
||||
opacity: 0.4;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.slider-track {
|
||||
position: absolute;
|
||||
top: 14px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 4px;
|
||||
background: var(--comfy-input-bg, #333);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.slider-track__bg {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(66, 153, 225, 0.15);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.slider-track__active {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
background: rgba(66, 153, 225, 0.6);
|
||||
border-radius: 2px;
|
||||
transition: left 0.05s linear, width 0.05s linear;
|
||||
}
|
||||
|
||||
.slider-track__default {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
background: rgba(66, 153, 225, 0.1);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.slider-handle {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
transform: translateX(-50%);
|
||||
cursor: grab;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.slider-handle:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.slider-handle__thumb {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
background: var(--fg-color, #fff);
|
||||
border-radius: 50%;
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 0;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
|
||||
transition: transform 0.15s ease;
|
||||
}
|
||||
|
||||
.slider-handle:hover .slider-handle__thumb {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.slider-handle:active .slider-handle__thumb {
|
||||
transform: scale(1.15);
|
||||
}
|
||||
|
||||
.slider-handle__value {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
font-size: 10px;
|
||||
font-family: 'SF Mono', 'Roboto Mono', monospace;
|
||||
color: var(--fg-color, #fff);
|
||||
opacity: 0.8;
|
||||
white-space: nowrap;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.slider-handle--min .slider-handle__value {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.slider-handle--max .slider-handle__value {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
235
vue-widgets/src/components/shared/SingleSlider.vue
Normal file
235
vue-widgets/src/components/shared/SingleSlider.vue
Normal file
@@ -0,0 +1,235 @@
|
||||
<template>
|
||||
<div class="single-slider" :class="{ disabled }" @wheel="onWheel">
|
||||
<div class="slider-track" ref="trackEl">
|
||||
<div class="slider-track__bg"></div>
|
||||
<div
|
||||
class="slider-track__active"
|
||||
:style="{ width: percent + '%' }"
|
||||
></div>
|
||||
<div
|
||||
v-if="defaultRange"
|
||||
class="slider-track__default"
|
||||
:style="{
|
||||
left: defaultMinPercent + '%',
|
||||
width: (defaultMaxPercent - defaultMinPercent) + '%'
|
||||
}"
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="slider-handle"
|
||||
:style="{ left: percent + '%' }"
|
||||
@mousedown="startDrag($event)"
|
||||
@touchstart="startDrag($event)"
|
||||
>
|
||||
<div class="slider-handle__thumb"></div>
|
||||
<div class="slider-handle__value">{{ formatValue(value) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onUnmounted } from 'vue'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
min: number
|
||||
max: number
|
||||
value: number
|
||||
step: number
|
||||
defaultRange?: { min: number; max: number }
|
||||
disabled?: boolean
|
||||
}>(), {
|
||||
disabled: false
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:value': [value: number]
|
||||
}>()
|
||||
|
||||
const trackEl = ref<HTMLElement | null>(null)
|
||||
const dragging = ref(false)
|
||||
|
||||
const percent = computed(() => {
|
||||
const range = props.max - props.min
|
||||
return ((props.value - props.min) / range) * 100
|
||||
})
|
||||
|
||||
const defaultMinPercent = computed(() => {
|
||||
if (!props.defaultRange) return 0
|
||||
const range = props.max - props.min
|
||||
return ((props.defaultRange.min - props.min) / range) * 100
|
||||
})
|
||||
|
||||
const defaultMaxPercent = computed(() => {
|
||||
if (!props.defaultRange) return 100
|
||||
const range = props.max - props.min
|
||||
return ((props.defaultRange.max - props.min) / range) * 100
|
||||
})
|
||||
|
||||
const formatValue = (val: number): string => {
|
||||
if (Number.isInteger(val)) return val.toString()
|
||||
return val.toFixed(stepToDecimals(props.step))
|
||||
}
|
||||
|
||||
const stepToDecimals = (step: number): number => {
|
||||
const str = step.toString()
|
||||
const decimalIndex = str.indexOf('.')
|
||||
return decimalIndex === -1 ? 0 : str.length - decimalIndex - 1
|
||||
}
|
||||
|
||||
const snapToStep = (value: number): number => {
|
||||
const steps = Math.round((value - props.min) / props.step)
|
||||
return Math.max(props.min, Math.min(props.max, props.min + steps * props.step))
|
||||
}
|
||||
|
||||
const startDrag = (event: MouseEvent | TouchEvent) => {
|
||||
if (props.disabled) return
|
||||
|
||||
event.preventDefault()
|
||||
dragging.value = true
|
||||
|
||||
document.addEventListener('mousemove', onDrag)
|
||||
document.addEventListener('mouseup', stopDrag)
|
||||
document.addEventListener('touchmove', onDrag, { passive: false })
|
||||
document.addEventListener('touchend', stopDrag)
|
||||
|
||||
onDrag(event)
|
||||
}
|
||||
|
||||
const onDrag = (event: MouseEvent | TouchEvent) => {
|
||||
if (!trackEl.value || !dragging.value) return
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
const clientX = 'touches' in event ? event.touches[0].clientX : event.clientX
|
||||
const rect = trackEl.value.getBoundingClientRect()
|
||||
const percent = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width))
|
||||
const rawValue = props.min + percent * (props.max - props.min)
|
||||
const value = snapToStep(rawValue)
|
||||
|
||||
emit('update:value', value)
|
||||
}
|
||||
|
||||
const onWheel = (event: WheelEvent) => {
|
||||
if (props.disabled) return
|
||||
|
||||
const rect = trackEl.value?.getBoundingClientRect()
|
||||
if (!rect) return
|
||||
|
||||
const rootRect = (event.currentTarget as HTMLElement).getBoundingClientRect()
|
||||
if (event.clientX < rootRect.left || event.clientX > rootRect.right ||
|
||||
event.clientY < rootRect.top || event.clientY > rootRect.bottom) return
|
||||
|
||||
event.preventDefault()
|
||||
|
||||
const delta = event.deltaY > 0 ? -1 : 1
|
||||
const newValue = snapToStep(props.value + delta * props.step)
|
||||
emit('update:value', newValue)
|
||||
}
|
||||
|
||||
const stopDrag = () => {
|
||||
dragging.value = false
|
||||
document.removeEventListener('mousemove', onDrag)
|
||||
document.removeEventListener('mouseup', stopDrag)
|
||||
document.removeEventListener('touchmove', onDrag)
|
||||
document.removeEventListener('touchend', stopDrag)
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
stopDrag()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.single-slider {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 32px;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.single-slider.disabled {
|
||||
opacity: 0.4;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.slider-track {
|
||||
position: absolute;
|
||||
top: 14px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 4px;
|
||||
background: var(--comfy-input-bg, #333);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.slider-track__bg {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(66, 153, 225, 0.15);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.slider-track__active {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
background: rgba(66, 153, 225, 0.6);
|
||||
border-radius: 2px;
|
||||
transition: width 0.05s linear;
|
||||
}
|
||||
|
||||
.slider-track__default {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
background: rgba(66, 153, 225, 0.1);
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.slider-handle {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
transform: translateX(-50%);
|
||||
cursor: grab;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.slider-handle:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.slider-handle__thumb {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
background: var(--fg-color, #fff);
|
||||
border-radius: 50%;
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 0;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
|
||||
transition: transform 0.15s ease;
|
||||
}
|
||||
|
||||
.slider-handle:hover .slider-handle__thumb {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.slider-handle:active .slider-handle__thumb {
|
||||
transform: scale(1.15);
|
||||
}
|
||||
|
||||
.slider-handle__value {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
font-size: 10px;
|
||||
font-family: 'SF Mono', 'Roboto Mono', monospace;
|
||||
color: var(--fg-color, #fff);
|
||||
opacity: 0.8;
|
||||
white-space: nowrap;
|
||||
pointer-events: none;
|
||||
}
|
||||
</style>
|
||||
@@ -7,8 +7,8 @@ import type { LoraPoolConfig, LegacyLoraPoolConfig, RandomizerConfig } from './c
|
||||
const LORA_POOL_WIDGET_MIN_WIDTH = 500
|
||||
const LORA_POOL_WIDGET_MIN_HEIGHT = 400
|
||||
const LORA_RANDOMIZER_WIDGET_MIN_WIDTH = 500
|
||||
const LORA_RANDOMIZER_WIDGET_MIN_HEIGHT = 462
|
||||
const LORA_RANDOMIZER_WIDGET_MAX_HEIGHT = 462
|
||||
const LORA_RANDOMIZER_WIDGET_MIN_HEIGHT = 430
|
||||
const LORA_RANDOMIZER_WIDGET_MAX_HEIGHT = LORA_RANDOMIZER_WIDGET_MIN_HEIGHT
|
||||
|
||||
// @ts-ignore - ComfyUI external module
|
||||
import { app } from '../../../scripts/app.js'
|
||||
@@ -231,7 +231,7 @@ app.registerExtension({
|
||||
const isRandomizerNode = node.comfyClass === 'Lora Randomizer (LoraManager)'
|
||||
|
||||
// For randomizer nodes, add a callback to update connected trigger words
|
||||
const callback = isRandomizerNode ? (value: any) => {
|
||||
const callback = isRandomizerNode ? () => {
|
||||
updateDownstreamLoaders(node)
|
||||
} : null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user