comfy-ts 2.5.0 → 2.7.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 +15 -2
- package/dist/{DefinedWorkflow-CnzmQrBh.js → DefinedWorkflow-BJgt5t0x.js} +14 -3
- package/dist/DefinedWorkflow-BJgt5t0x.js.map +1 -0
- package/dist/{DraftsSt-C1MbWnEp.js → DraftsSt-dizp3VcC.js} +2 -2
- package/dist/{DraftsSt-C1MbWnEp.js.map → DraftsSt-dizp3VcC.js.map} +1 -1
- package/dist/cli.js +5 -5
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +7 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -18
- package/dist/index.d.ts +24 -18
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-D47Zas-a.js → run-serve-D1Tsuru9.js} +494 -20
- package/dist/run-serve-D1Tsuru9.js.map +1 -0
- package/dist/{run-tui-t2TRBN0H.js → run-tui-JxlEbb_f.js} +511 -331
- package/dist/run-tui-JxlEbb_f.js.map +1 -0
- package/dist/serve-web.js +273 -0
- package/dist/{state-DY3Mp9Cl.js → state-CaHeDL-0.js} +7 -13
- package/dist/state-CaHeDL-0.js.map +1 -0
- package/dist/web.d.ts +24 -18
- package/dist/web.js +7 -2
- package/dist/web.js.map +1 -1
- package/examples/web/tsconfig.json +4 -1
- package/package.json +7 -5
- package/src/cli/comfy-ts-cli.ts +1 -1
- package/src/cli/serve/ServeApp.ts +383 -14
- package/src/cli/serve/describeVar.ts +6 -1
- package/src/cli/serve/promptEnhancers.ts +69 -0
- package/src/cli/serve/run-serve.ts +41 -7
- package/src/cli/serve/safeName.ts +12 -0
- package/src/cli/serve/web/api.ts +128 -0
- package/src/cli/serve/web/clipboard.ts +25 -0
- package/src/cli/serve/web/components/App.tsx +53 -0
- package/src/cli/serve/web/components/Gallery.tsx +186 -0
- package/src/cli/serve/web/components/PromptEnhancer.tsx +254 -0
- package/src/cli/serve/web/components/Sidebar.tsx +42 -0
- package/src/cli/serve/web/components/VarsForm.tsx +184 -0
- package/src/cli/serve/web/components/controls/BasicControls.tsx +95 -0
- package/src/cli/serve/web/components/controls/ImageControl.tsx +71 -0
- package/src/cli/serve/web/components/controls/LorasControl.tsx +340 -0
- package/src/cli/serve/web/components/controls/SeedControl.tsx +43 -0
- package/src/cli/serve/web/components/controls/SizeControl.tsx +49 -0
- package/src/cli/serve/web/llm.ts +254 -0
- package/src/cli/serve/web/main.tsx +18 -0
- package/src/cli/serve/web/state/EnhancerSt.ts +481 -0
- package/src/cli/serve/web/state/FormSt.ts +180 -0
- package/src/cli/serve/web/state/RunSt.ts +136 -0
- package/src/cli/serve/web/state/WebSt.ts +235 -0
- package/src/cli/serve/web/state/payload.ts +110 -0
- package/src/cli/serve/web/styles.ts +261 -0
- package/src/cli/serve/web/tsconfig.json +15 -0
- package/src/cli/serve/webBundle.ts +66 -0
- package/src/cli/tui/imageEscapes.ts +105 -0
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +21 -8
- package/src/cli/tui/protocolImage.ts +39 -0
- package/src/cli/tui/protocolImagePainter.ts +56 -23
- package/src/cli/tui/run-tui.tsx +3 -2
- package/src/cli/tui/state/LorasSt.ts +22 -9
- package/src/cli/tui/state/PreviewSt.ts +31 -13
- package/src/cli/tui/state/SettingsSt.ts +1 -1
- package/src/state.ts +6 -0
- package/src/vars/ComfyVars.ts +4 -1
- package/dist/DefinedWorkflow-CnzmQrBh.js.map +0 -1
- package/dist/run-serve-D47Zas-a.js.map +0 -1
- package/dist/run-tui-t2TRBN0H.js.map +0 -1
- package/dist/state-DY3Mp9Cl.js.map +0 -1
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// loras as a PALETTE. The row shows only the loras you put in it; clicking a
|
|
2
|
+
// card PAUSES or RESUMES it in place, so you can run a few images with a lora
|
|
3
|
+
// and a few without, never reopening the popup to add it back. Model/clip
|
|
4
|
+
// strengths sit on the card too. The popup is the only place that lists ALL
|
|
5
|
+
// loras: tap one there to add it to the palette, ✕ on a card removes it.
|
|
6
|
+
// The PALETTE is derived, never read off the draft: loras that are ON, plus the
|
|
7
|
+
// ones paused in this session. Reading "every key in the record" was the bug —
|
|
8
|
+
// LorasVar writes `false` for every lora ever unticked, so a real draft with 35
|
|
9
|
+
// keys and 2 on showed all 35. A pause removes the key (and remembers the
|
|
10
|
+
// strength), so a draft only ever lists what is actually on. The 🖼/🏷
|
|
11
|
+
// toggles hide images/titles on every lora surface (NSFW screens, persisted on
|
|
12
|
+
// WebSt); with both hidden the row collapses to a count. Names come from
|
|
13
|
+
// descriptor optionLabels; the value keeps raw enum keys, replaced by copy
|
|
14
|
+
import { observer, useLocalObservable } from 'mobx-react-lite'
|
|
15
|
+
import { useEffect, type ReactNode } from 'react'
|
|
16
|
+
import { fetchLoraInfo, loraPreviewSrc, type LoraInfo } from 'src/cli/serve/web/api.ts'
|
|
17
|
+
import type { LoraStrength } from 'src/vars/ComfyVars.ts'
|
|
18
|
+
import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
|
|
19
|
+
import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
|
|
20
|
+
import {
|
|
21
|
+
loraIsOn,
|
|
22
|
+
loraStrengthPair,
|
|
23
|
+
setLoraEnabled,
|
|
24
|
+
setLoraStrength,
|
|
25
|
+
type LoraStrengthPair,
|
|
26
|
+
} from 'src/cli/serve/web/state/payload.ts'
|
|
27
|
+
|
|
28
|
+
const CARD_CAP = 60
|
|
29
|
+
|
|
30
|
+
function asRecord(raw: unknown): Record<string, unknown> {
|
|
31
|
+
if (raw != null && typeof raw === 'object' && !Array.isArray(raw)) return raw as Record<string, unknown>
|
|
32
|
+
return {}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type LocalSt = {
|
|
36
|
+
open: boolean
|
|
37
|
+
filter: string
|
|
38
|
+
info: Map<string, LoraInfo | 'loading' | 'error'>
|
|
39
|
+
previewFailed: Set<string>
|
|
40
|
+
/** strength of a PAUSED lora, so resuming restores it (LorasVar.prev) */
|
|
41
|
+
prevStrength: Map<string, LoraStrengthPair>
|
|
42
|
+
/** loras paused in THIS session: they leave the draft record but stay in the palette,
|
|
43
|
+
* which is what makes "a few images with, a few without" one click each way */
|
|
44
|
+
paused: Set<string>
|
|
45
|
+
setOpen(open: boolean): void
|
|
46
|
+
setFilter(raw: string): void
|
|
47
|
+
noteInfo(name: string, v: LoraInfo | 'loading' | 'error'): void
|
|
48
|
+
notePreviewFailed(name: string): void
|
|
49
|
+
notePrevStrength(name: string, pair: LoraStrengthPair): void
|
|
50
|
+
setPaused(name: string, paused: boolean): void
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const LorasControl = observer(function LorasControl(p: { v: VarSt; host: string; st: WebSt }) {
|
|
54
|
+
const local = useLocalObservable<LocalSt>(() => ({
|
|
55
|
+
open: false,
|
|
56
|
+
filter: '',
|
|
57
|
+
info: new Map(),
|
|
58
|
+
previewFailed: new Set(),
|
|
59
|
+
prevStrength: new Map(),
|
|
60
|
+
paused: new Set(),
|
|
61
|
+
setOpen(open: boolean) {
|
|
62
|
+
this.open = open
|
|
63
|
+
},
|
|
64
|
+
setFilter(raw: string) {
|
|
65
|
+
this.filter = raw
|
|
66
|
+
},
|
|
67
|
+
noteInfo(name: string, v: LoraInfo | 'loading' | 'error') {
|
|
68
|
+
this.info.set(name, v)
|
|
69
|
+
},
|
|
70
|
+
notePreviewFailed(name: string) {
|
|
71
|
+
this.previewFailed.add(name)
|
|
72
|
+
},
|
|
73
|
+
notePrevStrength(name: string, pair: LoraStrengthPair) {
|
|
74
|
+
this.prevStrength.set(name, pair)
|
|
75
|
+
},
|
|
76
|
+
setPaused(name: string, paused: boolean) {
|
|
77
|
+
if (paused) this.paused.add(name)
|
|
78
|
+
else this.paused.delete(name)
|
|
79
|
+
},
|
|
80
|
+
}))
|
|
81
|
+
const record = asRecord(p.v.value)
|
|
82
|
+
const options = p.v.desc.options ?? []
|
|
83
|
+
const labels = p.v.desc.optionLabels ?? {}
|
|
84
|
+
const label = (name: string): string => labels[name] ?? name
|
|
85
|
+
// the PALETTE is what the row shows: the loras that are ON, plus the ones paused in this
|
|
86
|
+
// session. It is NOT "every key in the record" — LorasVar writes `false` for every lora
|
|
87
|
+
// ever unticked, so that reading put the whole catalog in the row (his repro: a draft
|
|
88
|
+
// with 35 keys and 2 on). A paused lora leaves the record entirely and lives here instead
|
|
89
|
+
const isOn = (name: string): boolean => loraIsOn(record[name])
|
|
90
|
+
const isInPalette = (name: string): boolean => isOn(name) || local.paused.has(name)
|
|
91
|
+
const selectedNames = options.filter(isInPalette)
|
|
92
|
+
const showImages = p.st.showLoraImages
|
|
93
|
+
const showTitles = p.st.showLoraTitles
|
|
94
|
+
|
|
95
|
+
/** add to the palette (a strength) or REMOVE from it entirely (null) */
|
|
96
|
+
const setEntry = (name: string, st: LoraStrength | null): void => {
|
|
97
|
+
local.setPaused(name, false)
|
|
98
|
+
const next = { ...record }
|
|
99
|
+
if (st == null) delete next[name]
|
|
100
|
+
else next[name] = st
|
|
101
|
+
p.v.set(next)
|
|
102
|
+
}
|
|
103
|
+
const toggleOn = (name: string, on: boolean): void => {
|
|
104
|
+
if (!on) local.notePrevStrength(name, loraStrengthPair(record[name]))
|
|
105
|
+
local.setPaused(name, !on)
|
|
106
|
+
p.v.set(setLoraEnabled(record, name, on, on ? local.prevStrength.get(name) : undefined))
|
|
107
|
+
}
|
|
108
|
+
const setStrength = (name: string, pair: LoraStrengthPair): void => {
|
|
109
|
+
if (!isOn(name)) {
|
|
110
|
+
// editing an OFF lora's strength remembers it for when it comes back on
|
|
111
|
+
local.notePrevStrength(name, pair)
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
p.v.set(setLoraStrength(record, name, pair))
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** model/clip inputs. A PAUSED lora still edits its strengths — they are what comes back */
|
|
118
|
+
const strengthInputs = (name: string): ReactNode => {
|
|
119
|
+
const pair = isOn(name) ? loraStrengthPair(record[name]) : (local.prevStrength.get(name) ?? { model: 1, clip: 1 })
|
|
120
|
+
return (
|
|
121
|
+
<>
|
|
122
|
+
<span className="st-label">m</span>
|
|
123
|
+
<input
|
|
124
|
+
type="number"
|
|
125
|
+
step={0.05}
|
|
126
|
+
value={pair.model}
|
|
127
|
+
onChange={(e) => {
|
|
128
|
+
const n = parseFloat(e.target.value)
|
|
129
|
+
if (Number.isFinite(n)) setStrength(name, { model: n, clip: pair.clip })
|
|
130
|
+
}}
|
|
131
|
+
/>
|
|
132
|
+
<span className="st-label">c</span>
|
|
133
|
+
<input
|
|
134
|
+
type="number"
|
|
135
|
+
step={0.05}
|
|
136
|
+
value={pair.clip}
|
|
137
|
+
onChange={(e) => {
|
|
138
|
+
const n = parseFloat(e.target.value)
|
|
139
|
+
if (Number.isFinite(n)) setStrength(name, { model: pair.model, clip: n })
|
|
140
|
+
}}
|
|
141
|
+
/>
|
|
142
|
+
</>
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// trigger words for the active section load once per open (bounded: active loras only)
|
|
147
|
+
const open = local.open
|
|
148
|
+
const host = p.host
|
|
149
|
+
const activeKey = selectedNames.join('\n')
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
if (!open) return
|
|
152
|
+
for (const name of activeKey.split('\n')) {
|
|
153
|
+
if (name === '' || local.info.has(name)) continue
|
|
154
|
+
local.noteInfo(name, 'loading')
|
|
155
|
+
fetchLoraInfo({ host, name })
|
|
156
|
+
.then((i) => local.noteInfo(name, i))
|
|
157
|
+
.catch(() => local.noteInfo(name, 'error'))
|
|
158
|
+
}
|
|
159
|
+
}, [open, activeKey, host, local])
|
|
160
|
+
|
|
161
|
+
// esc closes wherever focus is, not only inside the filter input
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (!open) return
|
|
164
|
+
const onKey = (e: KeyboardEvent): void => {
|
|
165
|
+
if (e.key === 'Escape') local.setOpen(false)
|
|
166
|
+
}
|
|
167
|
+
window.addEventListener('keydown', onKey)
|
|
168
|
+
return () => window.removeEventListener('keydown', onKey)
|
|
169
|
+
}, [open, local])
|
|
170
|
+
|
|
171
|
+
const needle = local.filter.toLowerCase()
|
|
172
|
+
const matchesFilter = (name: string): boolean =>
|
|
173
|
+
name.toLowerCase().includes(needle) || label(name).toLowerCase().includes(needle)
|
|
174
|
+
const matches = options.filter(matchesFilter)
|
|
175
|
+
const cards = matches.filter((o) => !isInPalette(o)).slice(0, CARD_CAP)
|
|
176
|
+
|
|
177
|
+
const thumb = (name: string): ReactNode => {
|
|
178
|
+
if (!showImages) return null
|
|
179
|
+
return local.previewFailed.has(name) ? (
|
|
180
|
+
<div className="lora-thumb none">no preview</div>
|
|
181
|
+
) : (
|
|
182
|
+
<img
|
|
183
|
+
key={name}
|
|
184
|
+
className="lora-thumb"
|
|
185
|
+
loading="lazy"
|
|
186
|
+
src={loraPreviewSrc({ host: p.host, name })}
|
|
187
|
+
alt={label(name)}
|
|
188
|
+
onError={() => local.notePreviewFailed(name)}
|
|
189
|
+
/>
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const visibilityToggles = (
|
|
194
|
+
<>
|
|
195
|
+
<button
|
|
196
|
+
type="button"
|
|
197
|
+
className={showImages ? 'mode sel' : 'mode'}
|
|
198
|
+
title={showImages ? 'hide lora images' : 'show lora images'}
|
|
199
|
+
onClick={() => p.st.toggleLoraImages()}
|
|
200
|
+
>
|
|
201
|
+
🖼
|
|
202
|
+
</button>
|
|
203
|
+
<button
|
|
204
|
+
type="button"
|
|
205
|
+
className={showTitles ? 'mode sel' : 'mode'}
|
|
206
|
+
title={showTitles ? 'hide lora titles' : 'show lora titles'}
|
|
207
|
+
onClick={() => p.st.toggleLoraTitles()}
|
|
208
|
+
>
|
|
209
|
+
🏷
|
|
210
|
+
</button>
|
|
211
|
+
</>
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<div>
|
|
216
|
+
<div className="row-inline">
|
|
217
|
+
{!showImages && !showTitles ? (
|
|
218
|
+
<span className="hint">
|
|
219
|
+
{selectedNames.length} lora{selectedNames.length === 1 ? '' : 's'} in the palette
|
|
220
|
+
</span>
|
|
221
|
+
) : (
|
|
222
|
+
selectedNames.map((name) => (
|
|
223
|
+
<span
|
|
224
|
+
key={name}
|
|
225
|
+
className={`${showImages ? 'lora-chip card' : 'lora-chip'}${isOn(name) ? '' : ' off'}`}
|
|
226
|
+
>
|
|
227
|
+
{/* THE palette gesture: the card itself pauses and resumes, so trying a
|
|
228
|
+
few images with a lora and a few without never opens the popup */}
|
|
229
|
+
<button
|
|
230
|
+
type="button"
|
|
231
|
+
className="lora-toggle"
|
|
232
|
+
title={isOn(name) ? `${name}\nclick to pause` : `${name}\npaused — click to resume`}
|
|
233
|
+
onClick={() => toggleOn(name, !isOn(name))}
|
|
234
|
+
>
|
|
235
|
+
{thumb(name)}
|
|
236
|
+
{showTitles ? <span className="chip-title">{label(name)}</span> : null}
|
|
237
|
+
<span className="chip-state">{isOn(name) ? '● on' : '⏸ paused'}</span>
|
|
238
|
+
</button>
|
|
239
|
+
<span className="chip-controls">
|
|
240
|
+
{strengthInputs(name)}
|
|
241
|
+
<button
|
|
242
|
+
type="button"
|
|
243
|
+
title="remove from the palette (the popup adds it back)"
|
|
244
|
+
onClick={() => setEntry(name, null)}
|
|
245
|
+
>
|
|
246
|
+
✕
|
|
247
|
+
</button>
|
|
248
|
+
</span>
|
|
249
|
+
</span>
|
|
250
|
+
))
|
|
251
|
+
)}
|
|
252
|
+
<button type="button" onClick={() => local.setOpen(true)}>
|
|
253
|
+
{selectedNames.length === 0 ? `add loras… (${options.length})` : '+ add…'}
|
|
254
|
+
</button>
|
|
255
|
+
{visibilityToggles}
|
|
256
|
+
</div>
|
|
257
|
+
|
|
258
|
+
{local.open ? (
|
|
259
|
+
<div className="modal-overlay" onClick={() => local.setOpen(false)}>
|
|
260
|
+
<div className="modal" onClick={(e) => e.stopPropagation()}>
|
|
261
|
+
<div className="modal-head">
|
|
262
|
+
<input
|
|
263
|
+
type="text"
|
|
264
|
+
autoFocus
|
|
265
|
+
placeholder={`filter ${options.length} loras`}
|
|
266
|
+
value={local.filter}
|
|
267
|
+
onChange={(e) => local.setFilter(e.target.value)}
|
|
268
|
+
/>
|
|
269
|
+
{visibilityToggles}
|
|
270
|
+
<button type="button" title="close (esc)" onClick={() => local.setOpen(false)}>
|
|
271
|
+
✕
|
|
272
|
+
</button>
|
|
273
|
+
</div>
|
|
274
|
+
<div className="modal-body">
|
|
275
|
+
{selectedNames.length > 0 ? (
|
|
276
|
+
<div className="lora-active-section">
|
|
277
|
+
<div className="section-title">your palette ({selectedNames.length})</div>
|
|
278
|
+
{selectedNames.filter(matchesFilter).map((name) => {
|
|
279
|
+
const info = local.info.get(name)
|
|
280
|
+
return (
|
|
281
|
+
<div key={name} className={isOn(name) ? 'lora-active-row' : 'lora-active-row off'}>
|
|
282
|
+
{thumb(name)}
|
|
283
|
+
<div className="lora-active-text">
|
|
284
|
+
<div className="lora-label" title={name}>
|
|
285
|
+
{showTitles ? label(name) : '···'}
|
|
286
|
+
</div>
|
|
287
|
+
{typeof info === 'object' && info.triggerWords.length > 0 ? (
|
|
288
|
+
<div className="hint">{info.triggerWords.join(', ')}</div>
|
|
289
|
+
) : (
|
|
290
|
+
<div className="hint">{name}</div>
|
|
291
|
+
)}
|
|
292
|
+
</div>
|
|
293
|
+
<input
|
|
294
|
+
type="checkbox"
|
|
295
|
+
checked={isOn(name)}
|
|
296
|
+
title={isOn(name) ? 'pause (stays in the palette)' : 'resume'}
|
|
297
|
+
onChange={(e) => toggleOn(name, e.target.checked)}
|
|
298
|
+
/>
|
|
299
|
+
{strengthInputs(name)}
|
|
300
|
+
<button
|
|
301
|
+
type="button"
|
|
302
|
+
title="remove from the list"
|
|
303
|
+
onClick={() => setEntry(name, null)}
|
|
304
|
+
>
|
|
305
|
+
✕
|
|
306
|
+
</button>
|
|
307
|
+
</div>
|
|
308
|
+
)
|
|
309
|
+
})}
|
|
310
|
+
</div>
|
|
311
|
+
) : null}
|
|
312
|
+
<div className="section-title">all loras — tap to add to the palette</div>
|
|
313
|
+
<div className="lora-grid">
|
|
314
|
+
{cards.map((name) => (
|
|
315
|
+
<button
|
|
316
|
+
key={name}
|
|
317
|
+
type="button"
|
|
318
|
+
className="lora-card"
|
|
319
|
+
title={name}
|
|
320
|
+
onClick={() => setEntry(name, [1, 1])}
|
|
321
|
+
>
|
|
322
|
+
{thumb(name)}
|
|
323
|
+
<div className="lora-label">{showTitles ? label(name) : name.slice(0, 2) + '···'}</div>
|
|
324
|
+
</button>
|
|
325
|
+
))}
|
|
326
|
+
</div>
|
|
327
|
+
{matches.length - selectedNames.filter(matchesFilter).length > CARD_CAP ? (
|
|
328
|
+
<div className="loras-more">
|
|
329
|
+
… {matches.length - selectedNames.filter(matchesFilter).length - CARD_CAP} more — refine the
|
|
330
|
+
filter
|
|
331
|
+
</div>
|
|
332
|
+
) : null}
|
|
333
|
+
{matches.length === 0 ? <div className="loras-more">no lora matches '{local.filter}'</div> : null}
|
|
334
|
+
</div>
|
|
335
|
+
</div>
|
|
336
|
+
</div>
|
|
337
|
+
) : null}
|
|
338
|
+
</div>
|
|
339
|
+
)
|
|
340
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// seed: mode buttons + value + 🎲. Drafts are live, so the mode configures the
|
|
2
|
+
// SERVER's per-draft seed policy (generate posts no seed key; step 4 applies
|
|
3
|
+
// the draft's {mode, value})
|
|
4
|
+
import { observer } from 'mobx-react-lite'
|
|
5
|
+
import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
|
|
6
|
+
import { asSeedForm, randomSeed } from 'src/cli/serve/web/state/payload.ts'
|
|
7
|
+
|
|
8
|
+
const MODES: { mode: string; label: string; hint: string }[] = [
|
|
9
|
+
{ mode: '=', label: 'fixed', hint: 'this exact seed, every run' },
|
|
10
|
+
{ mode: '+', label: '+1', hint: 'increments after each run' },
|
|
11
|
+
{ mode: '-', label: '-1', hint: 'decrements after each run' },
|
|
12
|
+
{ mode: '?', label: 'random', hint: 'a fresh random seed each run' },
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
export const SeedControl = observer(function SeedControl(p: { v: VarSt }) {
|
|
16
|
+
const seed = asSeedForm(p.v.value)
|
|
17
|
+
const setValue = (n: number): void => {
|
|
18
|
+
// parseInt('') is NaN, so clearing the box never snaps the seed to 0
|
|
19
|
+
if (Number.isFinite(n)) p.v.set({ mode: seed.mode, value: Math.max(0, Math.floor(n)) })
|
|
20
|
+
}
|
|
21
|
+
return (
|
|
22
|
+
<div>
|
|
23
|
+
<div className="row-inline">
|
|
24
|
+
{MODES.map((m) => (
|
|
25
|
+
<button
|
|
26
|
+
key={m.mode}
|
|
27
|
+
type="button"
|
|
28
|
+
className={seed.mode === m.mode ? 'mode sel' : 'mode'}
|
|
29
|
+
title={m.hint}
|
|
30
|
+
onClick={() => p.v.set({ mode: m.mode, value: seed.value })}
|
|
31
|
+
>
|
|
32
|
+
{m.label}
|
|
33
|
+
</button>
|
|
34
|
+
))}
|
|
35
|
+
<input type="number" min={0} value={seed.value} onChange={(e) => setValue(parseInt(e.target.value, 10))} />
|
|
36
|
+
<button type="button" title="roll a random seed now" onClick={() => setValue(randomSeed())}>
|
|
37
|
+
🎲
|
|
38
|
+
</button>
|
|
39
|
+
</div>
|
|
40
|
+
<div className="hint">{MODES.find((m) => m.mode === seed.mode)?.hint ?? seed.mode}</div>
|
|
41
|
+
</div>
|
|
42
|
+
)
|
|
43
|
+
})
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// size: preset select + free WxH inputs + ⇄ swap
|
|
2
|
+
import { observer } from 'mobx-react-lite'
|
|
3
|
+
import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
|
|
4
|
+
import { asSizeForm } from 'src/cli/serve/web/state/payload.ts'
|
|
5
|
+
|
|
6
|
+
export const SizeControl = observer(function SizeControl(p: { v: VarSt }) {
|
|
7
|
+
const size = asSizeForm(p.v.value)
|
|
8
|
+
const presets = p.v.desc.presets ?? []
|
|
9
|
+
const current = presets.find((pr) => pr.width === size.width && pr.height === size.height)
|
|
10
|
+
const setDim = (patch: { width?: number; height?: number }): void => {
|
|
11
|
+
const width = patch.width ?? size.width
|
|
12
|
+
const height = patch.height ?? size.height
|
|
13
|
+
if (Number.isFinite(width) && Number.isFinite(height) && width > 0 && height > 0)
|
|
14
|
+
p.v.set({ width: Math.floor(width), height: Math.floor(height) })
|
|
15
|
+
}
|
|
16
|
+
return (
|
|
17
|
+
<div className="row-inline">
|
|
18
|
+
<select
|
|
19
|
+
value={current?.label ?? '__custom__'}
|
|
20
|
+
onChange={(e) => {
|
|
21
|
+
const preset = presets.find((pr) => pr.label === e.target.value)
|
|
22
|
+
if (preset != null) p.v.set({ width: preset.width, height: preset.height })
|
|
23
|
+
}}
|
|
24
|
+
>
|
|
25
|
+
{current == null ? <option value="__custom__">custom</option> : null}
|
|
26
|
+
{presets.map((pr) => (
|
|
27
|
+
<option key={pr.label} value={pr.label}>
|
|
28
|
+
{pr.label} ({pr.width}×{pr.height})
|
|
29
|
+
</option>
|
|
30
|
+
))}
|
|
31
|
+
</select>
|
|
32
|
+
<input type="number" min={1} value={size.width} onChange={(e) => setDim({ width: Number(e.target.value) })} />
|
|
33
|
+
×
|
|
34
|
+
<input
|
|
35
|
+
type="number"
|
|
36
|
+
min={1}
|
|
37
|
+
value={size.height}
|
|
38
|
+
onChange={(e) => setDim({ height: Number(e.target.value) })}
|
|
39
|
+
/>
|
|
40
|
+
<button
|
|
41
|
+
type="button"
|
|
42
|
+
title="swap width and height"
|
|
43
|
+
onClick={() => p.v.set({ width: size.height, height: size.width })}
|
|
44
|
+
>
|
|
45
|
+
⇄
|
|
46
|
+
</button>
|
|
47
|
+
</div>
|
|
48
|
+
)
|
|
49
|
+
})
|