comfy-ts 2.4.2 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +12 -1
  2. package/dist/{DefinedWorkflow-CnzmQrBh.js → DefinedWorkflow-BJgt5t0x.js} +14 -3
  3. package/dist/DefinedWorkflow-BJgt5t0x.js.map +1 -0
  4. package/dist/{DraftsSt-C1MbWnEp.js → DraftsSt-dizp3VcC.js} +2 -2
  5. package/dist/{DraftsSt-C1MbWnEp.js.map → DraftsSt-dizp3VcC.js.map} +1 -1
  6. package/dist/cli.js +4 -4
  7. package/dist/index.cjs +3 -2
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +3 -0
  10. package/dist/index.d.ts +3 -0
  11. package/dist/index.js +3 -2
  12. package/dist/index.js.map +1 -1
  13. package/dist/{run-serve-D47Zas-a.js → run-serve-CVu39RNd.js} +330 -16
  14. package/dist/run-serve-CVu39RNd.js.map +1 -0
  15. package/dist/{run-tui-BqNO9Ck0.js → run-tui-idFhdO4f.js} +707 -527
  16. package/dist/run-tui-idFhdO4f.js.map +1 -0
  17. package/dist/serve-web.js +280 -0
  18. package/dist/{state-D9w1aJow.js → state-C90kdjtB.js} +3 -13
  19. package/dist/state-C90kdjtB.js.map +1 -0
  20. package/dist/web.d.ts +3 -0
  21. package/dist/web.js +3 -2
  22. package/dist/web.js.map +1 -1
  23. package/package.json +9 -7
  24. package/src/cli/serve/ServeApp.ts +314 -13
  25. package/src/cli/serve/describeVar.ts +6 -1
  26. package/src/cli/serve/run-serve.ts +4 -2
  27. package/src/cli/serve/web/api.ts +105 -0
  28. package/src/cli/serve/web/clipboard.ts +25 -0
  29. package/src/cli/serve/web/components/App.tsx +53 -0
  30. package/src/cli/serve/web/components/Gallery.tsx +186 -0
  31. package/src/cli/serve/web/components/PromptEnhancer.tsx +210 -0
  32. package/src/cli/serve/web/components/Sidebar.tsx +42 -0
  33. package/src/cli/serve/web/components/VarsForm.tsx +173 -0
  34. package/src/cli/serve/web/components/controls/BasicControls.tsx +95 -0
  35. package/src/cli/serve/web/components/controls/ImageControl.tsx +71 -0
  36. package/src/cli/serve/web/components/controls/LorasControl.tsx +340 -0
  37. package/src/cli/serve/web/components/controls/SeedControl.tsx +43 -0
  38. package/src/cli/serve/web/components/controls/SizeControl.tsx +49 -0
  39. package/src/cli/serve/web/main.tsx +18 -0
  40. package/src/cli/serve/web/openrouter.ts +142 -0
  41. package/src/cli/serve/web/state/EnhancerSt.ts +370 -0
  42. package/src/cli/serve/web/state/FormSt.ts +177 -0
  43. package/src/cli/serve/web/state/RunSt.ts +136 -0
  44. package/src/cli/serve/web/state/WebSt.ts +210 -0
  45. package/src/cli/serve/web/state/payload.ts +110 -0
  46. package/src/cli/serve/web/styles.ts +259 -0
  47. package/src/cli/serve/web/tsconfig.json +15 -0
  48. package/src/cli/serve/webBundle.ts +66 -0
  49. package/src/cli/tui/imageEscapes.ts +105 -0
  50. package/src/cli/tui/imagePicker/ImagePickerSt.ts +21 -8
  51. package/src/cli/tui/protocolImage.ts +39 -0
  52. package/src/cli/tui/protocolImagePainter.ts +56 -23
  53. package/src/cli/tui/run-tui.tsx +3 -2
  54. package/src/cli/tui/state/LorasSt.ts +22 -9
  55. package/src/cli/tui/state/PreviewSt.ts +31 -13
  56. package/src/cli/tui/state/SettingsSt.ts +1 -1
  57. package/src/cli/tui/state/TuiSt.ts +4 -4
  58. package/src/vars/ComfyVars.ts +4 -1
  59. package/dist/DefinedWorkflow-CnzmQrBh.js.map +0 -1
  60. package/dist/run-serve-D47Zas-a.js.map +0 -1
  61. package/dist/run-tui-BqNO9Ck0.js.map +0 -1
  62. package/dist/state-D9w1aJow.js.map +0 -1
@@ -0,0 +1,173 @@
1
+ // the var rows: each kind dispatches to its matching control (the point of the
2
+ // web ui — architecture item 12) + the sticky run bar
3
+ import { observer } from 'mobx-react-lite'
4
+ import { useEffect } from 'react'
5
+ import {
6
+ ChoiceControl,
7
+ NumberControl,
8
+ PromptControl,
9
+ TextControl,
10
+ ToggleControl,
11
+ } from 'src/cli/serve/web/components/controls/BasicControls.tsx'
12
+ import { ImageControl } from 'src/cli/serve/web/components/controls/ImageControl.tsx'
13
+ import { LorasControl } from 'src/cli/serve/web/components/controls/LorasControl.tsx'
14
+ import { SeedControl } from 'src/cli/serve/web/components/controls/SeedControl.tsx'
15
+ import { SizeControl } from 'src/cli/serve/web/components/controls/SizeControl.tsx'
16
+ import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
17
+ import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
18
+
19
+ const VarControl = observer(function VarControl(p: { v: VarSt; host: string; st: WebSt; module: string }) {
20
+ switch (p.v.desc.kind) {
21
+ case 'prompt':
22
+ return <PromptControl v={p.v} st={p.st} module={p.module} />
23
+ case 'text':
24
+ return <TextControl v={p.v} />
25
+ case 'int':
26
+ case 'float':
27
+ return <NumberControl v={p.v} />
28
+ case 'seed':
29
+ return <SeedControl v={p.v} />
30
+ case 'toggle':
31
+ return <ToggleControl v={p.v} />
32
+ case 'choice':
33
+ return <ChoiceControl v={p.v} />
34
+ case 'loras':
35
+ return <LorasControl v={p.v} host={p.host} st={p.st} />
36
+ case 'size':
37
+ return <SizeControl v={p.v} />
38
+ case 'image':
39
+ return <ImageControl v={p.v} />
40
+ default:
41
+ // a newer server may describe a kind this bundle predates: stay usable
42
+ return <div className="hint">unsupported var kind '{p.v.desc.kind}' — use the json api</div>
43
+ }
44
+ })
45
+
46
+ const VarRow = observer(function VarRow(p: { v: VarSt; host: string; st: WebSt; module: string }) {
47
+ return (
48
+ <div className="var-row">
49
+ <div className="var-label">
50
+ {p.v.desc.label ?? p.v.name}
51
+ {p.v.dirty ? (
52
+ <button
53
+ type="button"
54
+ className="dirty-dot"
55
+ title="changed this session — click to restore the loaded value (autosaves)"
56
+ onClick={() => p.v.revert()}
57
+ >
58
+ ●
59
+ </button>
60
+ ) : null}
61
+ <span className="kind">{p.v.desc.kind}</span>
62
+ </div>
63
+ <div className="var-control">
64
+ <VarControl v={p.v} host={p.host} st={p.st} module={p.module} />
65
+ </div>
66
+ </div>
67
+ )
68
+ })
69
+
70
+ /** what is waiting on the host, and the way to drop it */
71
+ const QueuePanel = observer(function QueuePanel(p: { st: WebSt }) {
72
+ const queue = p.st.run.queue
73
+ if (queue.length === 0) return null
74
+ return (
75
+ <div className="queue">
76
+ <div className="queue-head">
77
+ <span>
78
+ queue · {queue.length} prompt{queue.length === 1 ? '' : 's'}
79
+ </span>
80
+ {p.st.run.pendingCount > 0 ? (
81
+ <button type="button" className="link" onClick={() => p.st.run.clearQueue()}>
82
+ clear {p.st.run.pendingCount} pending
83
+ </button>
84
+ ) : null}
85
+ </div>
86
+ {queue.map((e, ix) => (
87
+ <div key={e.id} className="queue-row">
88
+ <span className="queue-ix">{ix + 1}</span>
89
+ <span className="queue-name">
90
+ {e.module}/{e.draft}
91
+ </span>
92
+ {e.sent ? (
93
+ <span className="hint">on the host — past cancelling</span>
94
+ ) : (
95
+ <button type="button" title="drop this queued prompt" onClick={() => p.st.run.removeQueued(e.id)}>
96
+ ✕
97
+ </button>
98
+ )}
99
+ </div>
100
+ ))}
101
+ </div>
102
+ )
103
+ })
104
+
105
+ export const VarsForm = observer(function VarsForm(p: { st: WebSt }) {
106
+ const form = p.st.form
107
+ // ⌘⏎ / ctrl+⏎ submits from anywhere, textarea included (his ask)
108
+ useEffect(() => {
109
+ const onKey = (e: KeyboardEvent): void => {
110
+ // the enhancer modal owns ⌘⏎ while it is open (refine), so a rewrite never queues a run
111
+ if (p.st.enhancer.isOpen) return
112
+ if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
113
+ e.preventDefault()
114
+ p.st.generate()
115
+ }
116
+ }
117
+ window.addEventListener('keydown', onKey)
118
+ return () => window.removeEventListener('keydown', onKey)
119
+ }, [p.st])
120
+ if (form == null) return null
121
+ const duplicate = (): void => {
122
+ const name = window.prompt('duplicate draft as…', `${form.draft} copy`)
123
+ if (name != null) void p.st.duplicateDraft(name)
124
+ }
125
+ return (
126
+ <div>
127
+ <div className="form-head">
128
+ <h2>
129
+ <b>{form.moduleKey}</b> / {form.draft}
130
+ </h2>
131
+ <span className="hint">
132
+ {form.saveState === 'saving' ? 'saving…' : null}
133
+ {form.saveState === 'saved' ? 'autosaved' : null}
134
+ {form.saveState === 'error' ? `🔴 save failed: ${form.saveError}` : null}
135
+ </span>
136
+ <button type="button" className="link" title="save these values as a new draft" onClick={duplicate}>
137
+ duplicate…
138
+ </button>
139
+ </div>
140
+ {form.vars.map((v) => (
141
+ // keyed by DRAFT too: a draft switch must reset per-row ui state (lora filter,
142
+ // remembered strengths), not carry the other draft's over
143
+ <VarRow key={`${form.draft}/${v.name}`} v={v} host={form.host} st={p.st} module={form.moduleKey} />
144
+ ))}
145
+ <div className="runbar">
146
+ <button
147
+ type="button"
148
+ className={p.st.run.isRunning ? 'primary pulse' : 'primary'}
149
+ title="⌘⏎ / ctrl+⏎ — click again to queue another"
150
+ onClick={() => p.st.generate()}
151
+ >
152
+ {p.st.run.isRunning
153
+ ? p.st.run.progressPercent != null
154
+ ? `generating… ${Math.round(p.st.run.progressPercent)}%`
155
+ : 'generating…'
156
+ : 'generate'}
157
+ </button>
158
+ <span className="status">
159
+ {form.dirtyCount === 0
160
+ ? 'draft values'
161
+ : `${form.dirtyCount} var${form.dirtyCount > 1 ? 's' : ''} changed this session`}
162
+ </span>
163
+ {form.dirtyCount > 0 ? (
164
+ <button type="button" className="link" onClick={() => form.revertAll()}>
165
+ revert all
166
+ </button>
167
+ ) : null}
168
+ {p.st.run.error != null ? <span className="error">🔴 {p.st.run.error}</span> : null}
169
+ </div>
170
+ <QueuePanel st={p.st} />
171
+ </div>
172
+ )
173
+ })
@@ -0,0 +1,95 @@
1
+ // the small per-kind controls: prompt, text, int/float, toggle, choice —
2
+ // bigger kinds (seed, size, loras, image) have their own files
3
+ import { observer } from 'mobx-react-lite'
4
+ import { PromptEnhancer } from 'src/cli/serve/web/components/PromptEnhancer.tsx'
5
+ import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
6
+ import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
7
+
8
+ export const PromptControl = observer(function PromptControl(p: { v: VarSt; st: WebSt; module: string }) {
9
+ const text = typeof p.v.value === 'string' ? p.v.value : ''
10
+ const rows = Math.min(12, Math.max(4, text.split('\n').length + 1))
11
+ return (
12
+ <div>
13
+ <textarea rows={rows} value={text} onChange={(e) => p.v.set(e.target.value)} />
14
+ <div className="row-inline">
15
+ <span className="hint">// line = comment · "- " line = negative prompt</span>
16
+ <PromptEnhancer v={p.v} st={p.st} module={p.module} />
17
+ </div>
18
+ </div>
19
+ )
20
+ })
21
+
22
+ export const TextControl = observer(function TextControl(p: { v: VarSt }) {
23
+ return (
24
+ <input
25
+ type="text"
26
+ value={typeof p.v.value === 'string' ? p.v.value : ''}
27
+ onChange={(e) => p.v.set(e.target.value)}
28
+ />
29
+ )
30
+ })
31
+
32
+ export const NumberControl = observer(function NumberControl(p: { v: VarSt }) {
33
+ const isInt = p.v.desc.kind === 'int'
34
+ const num = typeof p.v.value === 'number' ? p.v.value : 0
35
+ const min = p.v.desc.min
36
+ const max = p.v.desc.max
37
+ const apply = (raw: string): void => {
38
+ const n = isInt ? parseInt(raw, 10) : parseFloat(raw)
39
+ if (Number.isFinite(n)) p.v.set(n)
40
+ }
41
+ return (
42
+ <div className="row-inline">
43
+ <input
44
+ type="number"
45
+ value={num}
46
+ step={isInt ? 1 : 'any'}
47
+ min={min}
48
+ max={max}
49
+ onChange={(e) => apply(e.target.value)}
50
+ />
51
+ {min != null && max != null ? (
52
+ <input
53
+ type="range"
54
+ style={{ flex: 1, minWidth: 120 }}
55
+ value={num}
56
+ min={min}
57
+ max={max}
58
+ step={isInt ? 1 : (max - min) / 200}
59
+ onChange={(e) => apply(e.target.value)}
60
+ />
61
+ ) : null}
62
+ {min != null || max != null ? <span className="hint">{`${min ?? '-∞'} … ${max ?? '∞'}`}</span> : null}
63
+ </div>
64
+ )
65
+ })
66
+
67
+ export const ToggleControl = observer(function ToggleControl(p: { v: VarSt }) {
68
+ return (
69
+ <label className="row-inline" style={{ cursor: 'pointer' }}>
70
+ <input type="checkbox" checked={p.v.value === true} onChange={(e) => p.v.set(e.target.checked)} />
71
+ <span className="hint">{p.v.value === true ? 'on' : 'off'}</span>
72
+ </label>
73
+ )
74
+ })
75
+
76
+ export const ChoiceControl = observer(function ChoiceControl(p: { v: VarSt }) {
77
+ const choices = p.v.desc.choices ?? []
78
+ const value = typeof p.v.value === 'string' ? p.v.value : ''
79
+ return (
80
+ <select value={value} onChange={(e) => p.v.set(e.target.value)}>
81
+ {/* honest display for a value outside the current union (stale draft): the
82
+ browser would silently SHOW the first option while the state differs */}
83
+ {choices.includes(value) ? null : (
84
+ <option value={value} disabled>
85
+ {value === '' ? '(unset)' : `${value} (not on this host)`}
86
+ </option>
87
+ )}
88
+ {choices.map((c) => (
89
+ <option key={c} value={c}>
90
+ {c}
91
+ </option>
92
+ ))}
93
+ </select>
94
+ )
95
+ })
@@ -0,0 +1,71 @@
1
+ // image: a path/url input the api already accepts, plus a browser upload
2
+ // (POST /upload → local file under outputs/serve-inputs/) and a preview when
3
+ // the value is browser-reachable
4
+ import { observer } from 'mobx-react-lite'
5
+ import { useRef } from 'react'
6
+ import { uploadFile } from 'src/cli/serve/web/api.ts'
7
+ import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
8
+
9
+ export const ImageControl = observer(function ImageControl(p: { v: VarSt }) {
10
+ const fileInput = useRef<HTMLInputElement>(null)
11
+ const value = typeof p.v.value === 'string' ? p.v.value : ''
12
+ const previewUrl = /^https?:\/\//.test(value) ? value : p.v.uploadedUrl
13
+ const extensions = p.v.desc.extensions ?? []
14
+ const onFile = async (file: File | undefined): Promise<void> => {
15
+ if (file == null) return
16
+ try {
17
+ const reply = await uploadFile({ file })
18
+ p.v.set(reply.path)
19
+ p.v.setUploadedUrl(reply.url)
20
+ } catch (e) {
21
+ // loud both ways: the row hint cannot show async errors, alert can
22
+ alert(`upload failed: ${e instanceof Error ? e.message : String(e)}`)
23
+ }
24
+ }
25
+ return (
26
+ <div>
27
+ <div className="row-inline">
28
+ <input
29
+ type="text"
30
+ style={{ flex: 1 }}
31
+ placeholder="local path or http(s) url"
32
+ value={value}
33
+ onChange={(e) => {
34
+ p.v.set(e.target.value)
35
+ p.v.setUploadedUrl(null)
36
+ }}
37
+ />
38
+ <button type="button" onClick={() => fileInput.current?.click()}>
39
+ upload…
40
+ </button>
41
+ {value !== '' ? (
42
+ <button
43
+ type="button"
44
+ title="clear the image"
45
+ onClick={() => {
46
+ p.v.set('')
47
+ p.v.setUploadedUrl(null)
48
+ }}
49
+ >
50
+ ✕
51
+ </button>
52
+ ) : null}
53
+ <input
54
+ ref={fileInput}
55
+ type="file"
56
+ accept={extensions.map((ext) => `.${ext}`).join(',')}
57
+ style={{ display: 'none' }}
58
+ onChange={(e) => {
59
+ void onFile(e.target.files?.[0])
60
+ e.target.value = ''
61
+ }}
62
+ />
63
+ </div>
64
+ {previewUrl != null && previewUrl !== '' ? (
65
+ <div className="img-preview">
66
+ <img src={previewUrl} alt={value} />
67
+ </div>
68
+ ) : null}
69
+ </div>
70
+ )
71
+ })
@@ -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
+ })