comfy-ts 2.10.0 → 2.12.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 (110) hide show
  1. package/README.md +1 -0
  2. package/dist/{LogsSt-DFxzQfDc.js → LogsSt-U1H0mP1m.js} +35 -5
  3. package/dist/LogsSt-U1H0mP1m.js.map +1 -0
  4. package/dist/cli.js +4 -4
  5. package/dist/index.cjs +565 -62
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +210 -31
  8. package/dist/index.d.ts +210 -31
  9. package/dist/index.js +561 -63
  10. package/dist/index.js.map +1 -1
  11. package/dist/{run-serve-_nrvJYyt.js → run-serve-BeAznay5.js} +549 -43
  12. package/dist/run-serve-BeAznay5.js.map +1 -0
  13. package/dist/{run-tui-Atvf9vb3.js → run-tui-BTGjvnKk.js} +75 -18
  14. package/dist/run-tui-BTGjvnKk.js.map +1 -0
  15. package/dist/{DefinedWorkflow-BatWaZO1.js → schemaDrift-Cg39vs53.js} +644 -60
  16. package/dist/schemaDrift-Cg39vs53.js.map +1 -0
  17. package/dist/serve-web.js +523 -133
  18. package/dist/{state-6RFDIQwJ.js → state-C7REnHan.js} +18 -3
  19. package/dist/{state-6RFDIQwJ.js.map → state-C7REnHan.js.map} +1 -1
  20. package/dist/web.d.ts +210 -31
  21. package/dist/web.js +561 -63
  22. package/dist/web.js.map +1 -1
  23. package/examples/comfy-cloud/capybara-i2v.cflow.ts +2 -0
  24. package/examples/comfy-cloud/wan22-5b-t2v.cflow.ts +2 -0
  25. package/examples/comfy-cloud/wan22-i2v.cflow.ts +2 -0
  26. package/examples/comfy-cloud/wan22-t2v.cflow.ts +2 -0
  27. package/examples/rvion/06-qwen-image-edit.cflow.ts +3 -2
  28. package/examples/rvion/07-local-llm-text-gen.cflow.ts +2 -2
  29. package/examples/rvion/10-anima-t2i.cflow.ts +229 -0
  30. package/extra/README.md +4 -0
  31. package/extra/comfyui-fresh-model-lists/README.md +25 -0
  32. package/extra/comfyui-fresh-model-lists/__init__.py +36 -0
  33. package/extra/comfyui-fresh-model-lists/test_fresh_model_lists.py +97 -0
  34. package/package.json +17 -7
  35. package/src/cli/draftMeta.ts +39 -0
  36. package/src/cli/serve/ServeApp.ts +242 -12
  37. package/src/cli/serve/applyVarPayload.ts +50 -22
  38. package/src/cli/serve/describeVar.ts +49 -6
  39. package/src/cli/serve/favicon.ts +3 -0
  40. package/src/cli/serve/llmConfigShape.ts +51 -0
  41. package/src/cli/serve/llmConfigs.ts +52 -0
  42. package/src/cli/serve/tagList.ts +92 -0
  43. package/src/cli/serve/tagSource.ts +69 -0
  44. package/src/cli/serve/web/api.ts +60 -0
  45. package/src/cli/serve/web/components/App.tsx +336 -44
  46. package/src/cli/serve/web/components/Gallery.tsx +105 -28
  47. package/src/cli/serve/web/components/HistoryPicker.tsx +149 -0
  48. package/src/cli/serve/web/components/Icon.tsx +18 -2
  49. package/src/cli/serve/web/components/MenuButton.tsx +53 -0
  50. package/src/cli/serve/web/components/Omnibox.tsx +85 -0
  51. package/src/cli/serve/web/components/PromptEnhancer.tsx +476 -180
  52. package/src/cli/serve/web/components/TooltipLayer.tsx +45 -0
  53. package/src/cli/serve/web/components/VarIcon.tsx +24 -0
  54. package/src/cli/serve/web/components/VarsForm.tsx +341 -177
  55. package/src/cli/serve/web/components/controls/BasicControls.tsx +57 -32
  56. package/src/cli/serve/web/components/controls/LorasControl.tsx +708 -285
  57. package/src/cli/serve/web/components/controls/PresetPicker.tsx +1 -1
  58. package/src/cli/serve/web/components/controls/PromptControl.tsx +279 -0
  59. package/src/cli/serve/web/components/controls/PromptEditor.tsx +113 -0
  60. package/src/cli/serve/web/components/controls/SeedControl.tsx +17 -10
  61. package/src/cli/serve/web/components/controls/SizeControl.tsx +111 -18
  62. package/src/cli/serve/web/components/modKey.ts +2 -0
  63. package/src/cli/serve/web/llm.ts +23 -12
  64. package/src/cli/serve/web/promptEditor/promptExtensions.ts +281 -0
  65. package/src/cli/serve/web/state/EnhancerSt.ts +415 -100
  66. package/src/cli/serve/web/state/FormSt.ts +193 -29
  67. package/src/cli/serve/web/state/OmniboxSt.ts +57 -0
  68. package/src/cli/serve/web/state/WebSt.ts +281 -57
  69. package/src/cli/serve/web/state/choiceButtons.ts +61 -0
  70. package/src/cli/serve/web/state/generateButton.ts +16 -0
  71. package/src/cli/serve/web/state/history.ts +54 -0
  72. package/src/cli/serve/web/state/host.ts +5 -2
  73. package/src/cli/serve/web/state/keptLines.ts +53 -0
  74. package/src/cli/serve/web/state/latentMode.ts +20 -0
  75. package/src/cli/serve/web/state/loraSort.ts +57 -0
  76. package/src/cli/serve/web/state/moduleTree.ts +2 -2
  77. package/src/cli/serve/web/state/omnibox.ts +69 -0
  78. package/src/cli/serve/web/state/payload.ts +38 -58
  79. package/src/cli/serve/web/state/shortcuts.ts +54 -0
  80. package/src/cli/serve/web/state/sizeStars.ts +31 -0
  81. package/src/cli/serve/web/state/stableSlots.ts +21 -0
  82. package/src/cli/serve/web/state/varGroups.ts +24 -0
  83. package/src/cli/serve/web/styles.ts +472 -118
  84. package/src/cli/serve/webBundle.ts +54 -10
  85. package/src/cli/tui/components/Header.tsx +2 -0
  86. package/src/cli/tui/components/PickerOverlays.tsx +9 -2
  87. package/src/cli/tui/imagePicker/ImagePickerSt.ts +1 -1
  88. package/src/cli/tui/state/DraftsSt.ts +18 -2
  89. package/src/cli/tui/state/EditorSt.ts +1 -1
  90. package/src/cli/tui/state/HostSt.ts +34 -0
  91. package/src/cli/tui/state/LorasSt.ts +1 -1
  92. package/src/cli/tui/state/PickerSt.ts +25 -7
  93. package/src/cli/tui/state/SettingsSt.ts +1 -1
  94. package/src/cli/tui/state/TuiSt.ts +10 -0
  95. package/src/coreExports.ts +20 -0
  96. package/src/host/ComfyHost.ts +15 -0
  97. package/src/host/loraInfoCache.ts +70 -0
  98. package/src/host/loraManagerApi.ts +27 -0
  99. package/src/host/schemaDrift.ts +87 -0
  100. package/src/state.ts +5 -0
  101. package/src/vars/ComfyVars.ts +337 -67
  102. package/src/vars/DefinedWorkflow.ts +40 -19
  103. package/src/vars/lanes.ts +238 -0
  104. package/src/vars/loraEntry.ts +101 -0
  105. package/src/vars/promptSyntax.ts +382 -0
  106. package/dist/DefinedWorkflow-BatWaZO1.js.map +0 -1
  107. package/dist/LogsSt-DFxzQfDc.js.map +0 -1
  108. package/dist/run-serve-_nrvJYyt.js.map +0 -1
  109. package/dist/run-tui-Atvf9vb3.js.map +0 -1
  110. package/src/cli/serve/web/components/Sidebar.tsx +0 -66
@@ -22,7 +22,7 @@ export const PresetPicker = observer(function PresetPicker(p: { v: VarSt }) {
22
22
  <div className="preset-box" onKeyDown={(e) => (e.key === 'Escape' ? setOpen(false) : undefined)}>
23
23
  <button
24
24
  type="button"
25
- className="preset-btn"
25
+ className="preset-btn mini"
26
26
  aria-expanded={open}
27
27
  data-tip="named starting texts — picking one replaces the field"
28
28
  onClick={() => setOpen(!open)}
@@ -0,0 +1,279 @@
1
+ // prompt: one box, or `{ lanes }` (src/vars/lanes.ts), one box per named lane merged in listed
2
+ // order. Above it, what the active loras add: one line per lora, a popover to leave words out
3
+ import { observer } from 'mobx-react-lite'
4
+ import { useState } from 'react'
5
+ import { MenuButton, MenuItem } from 'src/cli/serve/web/components/MenuButton.tsx'
6
+ import { PresetPicker } from 'src/cli/serve/web/components/controls/PresetPicker.tsx'
7
+ import { PromptEditor } from 'src/cli/serve/web/components/controls/PromptEditor.tsx'
8
+ import { PromptEnhancer } from 'src/cli/serve/web/components/PromptEnhancer.tsx'
9
+ import { HistoryButton } from 'src/cli/serve/web/components/HistoryPicker.tsx'
10
+ import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
11
+ import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
12
+ import {
13
+ isPromptLanes,
14
+ moveLane,
15
+ newLaneName,
16
+ patchLane,
17
+ promptFromLanes,
18
+ removeLane,
19
+ toPromptLanes,
20
+ type PromptLane,
21
+ } from 'src/vars/lanes.ts'
22
+
23
+ /** the words each active lora adds in front of the prompt. One line per lora, cut with an
24
+ * ellipsis; clicking opens the full list with a checkbox per word and all / none */
25
+ const KeywordGroups = observer(function KeywordGroups(p: { v: VarSt; st: WebSt }) {
26
+ const [open, setOpen] = useState<string | null>(null)
27
+ const form = p.st.form
28
+ const groups = form?.loraKeywordGroups(p.v) ?? []
29
+ if (form == null || groups.length === 0) return null
30
+ return (
31
+ <div className="kw-prefix">
32
+ {groups.map((g) => {
33
+ const kept = g.parts.filter((w) => w.on).length
34
+ return (
35
+ <div key={g.lora} className="preset-box kw-box">
36
+ <button
37
+ type="button"
38
+ className={g.running ? 'kw-line' : 'kw-line stopped'}
39
+ aria-expanded={open === g.lora}
40
+ data-tip={`${g.lora}\n${g.running ? 'added in front of your prompt at run time' : 'not running: paused, or its lane is off'}\nclick to choose the words`}
41
+ onClick={() => setOpen(open === g.lora ? null : g.lora)}
42
+ >
43
+ <span className="kw-lora">{g.label}</span>
44
+ <span className="kw-words">
45
+ {g.parts
46
+ .filter((w) => w.on)
47
+ .map((w) => w.text)
48
+ .join(', ') || 'no words'}
49
+ </span>
50
+ {g.parts.length - kept > 0 ? (
51
+ <span className="kw-off">+{g.parts.length - kept} disabled</span>
52
+ ) : null}
53
+ </button>
54
+ {open === g.lora ? (
55
+ <>
56
+ <div className="preset-backdrop" onClick={() => setOpen(null)} />
57
+ <div className="preset-menu kw-menu">
58
+ <div className="row-inline kw-menu-head">
59
+ <span className="kw-lora">{g.label}</span>
60
+ <button
61
+ type="button"
62
+ className="link"
63
+ onClick={() => form.setKeywordMute(p.v, g.lora, [])}
64
+ >
65
+ all
66
+ </button>
67
+ <button
68
+ type="button"
69
+ className="link"
70
+ onClick={() =>
71
+ form.setKeywordMute(
72
+ p.v,
73
+ g.lora,
74
+ g.parts.map((w) => w.text),
75
+ )
76
+ }
77
+ >
78
+ none
79
+ </button>
80
+ </div>
81
+ {g.parts.map((w) => (
82
+ <label key={w.text} className="kw-item">
83
+ <input
84
+ type="checkbox"
85
+ checked={w.on}
86
+ onChange={() => form.toggleKeywordPart(p.v, g.lora, w.text)}
87
+ />
88
+ <span>{w.text}</span>
89
+ </label>
90
+ ))}
91
+ </div>
92
+ </>
93
+ ) : null}
94
+ </div>
95
+ )
96
+ })}
97
+ </div>
98
+ )
99
+ })
100
+
101
+ const LANE_DRAG = 'application/x-comfy-lane'
102
+
103
+ /** one prompt lane: a name pill and its box. Click the pill to use or leave out the lane, drag
104
+ * it onto another lane to reorder, ⋯ to rename or remove. Nothing else on the bar */
105
+ const LaneBox = observer(function LaneBox(p: {
106
+ v: VarSt
107
+ st: WebSt
108
+ module: string
109
+ lanes: PromptLane[]
110
+ ix: number
111
+ /** ⌘E opens this lane's enhancer (lane 0 of the first prompt) */
112
+ shortcut: boolean
113
+ }) {
114
+ const [renaming, setRenaming] = useState(false)
115
+ const lane = p.lanes[p.ix]
116
+ if (lane == null) return null
117
+ const write = (lanes: PromptLane[]): void => {
118
+ p.v.set({ lanes })
119
+ }
120
+ return (
121
+ <div
122
+ className={lane.active ? 'lane-box' : 'lane-box off'}
123
+ onDragOver={(e) => {
124
+ if (e.dataTransfer.types.includes(LANE_DRAG)) e.preventDefault()
125
+ }}
126
+ onDrop={(e) => {
127
+ const from = Number(e.dataTransfer.getData(LANE_DRAG))
128
+ if (e.dataTransfer.getData(LANE_DRAG) === '' || !Number.isInteger(from) || from === p.ix) return
129
+ e.preventDefault()
130
+ write(moveLane(p.lanes, from, p.ix - from))
131
+ }}
132
+ >
133
+ <div className="lane-bar">
134
+ {renaming ? (
135
+ <input
136
+ type="text"
137
+ className="lane-name"
138
+ autoFocus
139
+ defaultValue={lane.name}
140
+ onFocus={(e) => e.currentTarget.select()}
141
+ onKeyDown={(e) => {
142
+ if (e.key === 'Enter') {
143
+ write(patchLane(p.lanes, p.ix, { name: e.currentTarget.value.trim() || lane.name }))
144
+ setRenaming(false)
145
+ }
146
+ if (e.key === 'Escape') setRenaming(false)
147
+ }}
148
+ onBlur={() => setRenaming(false)}
149
+ />
150
+ ) : (
151
+ <button
152
+ type="button"
153
+ className={lane.active ? 'lane-pill' : 'lane-pill off'}
154
+ draggable
155
+ data-tip={`${lane.active ? 'in the prompt' : 'left out'}: click to switch, drag to reorder, double-click to rename`}
156
+ onDragStart={(e) => {
157
+ e.dataTransfer.effectAllowed = 'move'
158
+ e.dataTransfer.setData(LANE_DRAG, String(p.ix))
159
+ }}
160
+ onClick={() => write(patchLane(p.lanes, p.ix, { active: !lane.active }))}
161
+ onDoubleClick={() => setRenaming(true)}
162
+ >
163
+ {lane.name}
164
+ </button>
165
+ )}
166
+ <span className="lane-tools">
167
+ <PromptEnhancer v={p.v} st={p.st} module={p.module} lane={p.ix} compact shortcut={p.shortcut} />
168
+ <MenuButton tip="lane actions">
169
+ {(close) => (
170
+ <>
171
+ <MenuItem
172
+ label="rename"
173
+ onClick={() => {
174
+ close()
175
+ setRenaming(true)
176
+ }}
177
+ />
178
+ <MenuItem
179
+ label="remove"
180
+ disabled={p.lanes.length === 1}
181
+ onClick={() => {
182
+ close()
183
+ write(removeLane(p.lanes, p.ix))
184
+ }}
185
+ />
186
+ </>
187
+ )}
188
+ </MenuButton>
189
+ </span>
190
+ </div>
191
+ <PromptEditor
192
+ v={p.v}
193
+ st={p.st}
194
+ module={p.module}
195
+ value={lane.prompt}
196
+ onChange={(text) => write(patchLane(p.lanes, p.ix, { prompt: text }))}
197
+ minLines={2}
198
+ />
199
+ </div>
200
+ )
201
+ })
202
+
203
+ export const PromptControl = observer(function PromptControl(p: {
204
+ v: VarSt
205
+ st: WebSt
206
+ module: string
207
+ /** the first prompt: ⌘P lands here and ⌘E opens its enhancer */
208
+ jumpTarget?: boolean
209
+ }) {
210
+ const value = p.v.value
211
+ if (isPromptLanes(value)) {
212
+ const single = promptFromLanes(value)
213
+ return (
214
+ <div>
215
+ <KeywordGroups v={p.v} st={p.st} />
216
+ <div className="lanes">
217
+ {value.lanes.map((lane, ix) => (
218
+ // index keys on purpose: a lane's name is editable and may repeat
219
+ <LaneBox
220
+ key={ix}
221
+ v={p.v}
222
+ st={p.st}
223
+ module={p.module}
224
+ lanes={value.lanes}
225
+ ix={ix}
226
+ shortcut={p.jumpTarget === true && ix === 0}
227
+ />
228
+ ))}
229
+ </div>
230
+ <div className="row-inline lane-foot">
231
+ <button
232
+ type="button"
233
+ className="link"
234
+ onClick={() =>
235
+ p.v.set({
236
+ lanes: [...value.lanes, { name: newLaneName(value.lanes), prompt: '', active: true }],
237
+ })
238
+ }
239
+ >
240
+ + lane
241
+ </button>
242
+ {single == null ? null : (
243
+ <button
244
+ type="button"
245
+ className="link"
246
+ data-tip="back to a single prompt box"
247
+ onClick={() => p.v.set(single)}
248
+ >
249
+ single box
250
+ </button>
251
+ )}
252
+ <HistoryButton entries={p.st.promptHistory} what="prompt" onPick={(e) => p.v.set(e.value)} />
253
+ <span className="hint">lanes merge top to bottom</span>
254
+ </div>
255
+ </div>
256
+ )
257
+ }
258
+ const text = typeof value === 'string' ? value : ''
259
+ return (
260
+ <div>
261
+ <KeywordGroups v={p.v} st={p.st} />
262
+ <PromptEditor v={p.v} st={p.st} module={p.module} value={text} onChange={(t) => p.v.set(t)} minLines={4} />
263
+ {/* three small separate actions under the box, the same size, none dressed as a link */}
264
+ <div className="row-inline prompt-actions">
265
+ <PresetPicker v={p.v} />
266
+ <PromptEnhancer v={p.v} st={p.st} module={p.module} shortcut={p.jumpTarget} />
267
+ <HistoryButton entries={p.st.promptHistory} what="prompt" onPick={(e) => p.v.set(e.value)} />
268
+ <button
269
+ type="button"
270
+ className="mini"
271
+ data-tip="split this prompt into named lanes, merged in the order they are listed"
272
+ onClick={() => p.v.set(toPromptLanes(text))}
273
+ >
274
+ lanes
275
+ </button>
276
+ </div>
277
+ </div>
278
+ )
279
+ })
@@ -0,0 +1,113 @@
1
+ // one prompt box: a CodeMirror editor over a plain string. The value stays controlled (a preset
2
+ // pick or a draft switch replaces the text), and the footer says what the editor cannot color
3
+ import { EditorState } from '@codemirror/state'
4
+ import { EditorView } from '@codemirror/view'
5
+ import { observer } from 'mobx-react-lite'
6
+ import { useEffect, useRef, useState } from 'react'
7
+ import { fetchTags } from 'src/cli/serve/web/api.ts'
8
+ import {
9
+ promptExtensions,
10
+ refreshMarks,
11
+ WEIGHT_STEP,
12
+ type PromptEditorCtx,
13
+ } from 'src/cli/serve/web/promptEditor/promptExtensions.ts'
14
+ import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
15
+ import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
16
+ import { estimateTokens } from 'src/vars/promptSyntax.ts'
17
+
18
+ const KEYS_TIP = [
19
+ `⌘↑ / ⌘↓ (or ⌃↑ / ⌃↓): weight of the selection or the tag under the cursor, ±${WEIGHT_STEP}`,
20
+ '⌘/ comment lines · ⌘⇧- negative lines · ⌥↑ / ⌥↓ move lines',
21
+ '"//" starts a comment · "- " line = negative prompt · ⌘⏎ generate',
22
+ ].join('\n')
23
+
24
+ export const PromptEditor = observer(function PromptEditor(p: {
25
+ v: VarSt
26
+ st: WebSt
27
+ module: string
28
+ value: string
29
+ onChange: (text: string) => void
30
+ minLines: number
31
+ }) {
32
+ const host = useRef<HTMLDivElement>(null)
33
+ const view = useRef<EditorView | null>(null)
34
+ const [tagError, setTagError] = useState<string | null>(null)
35
+ // the editor reads these through a getter, so it sees the latest without being rebuilt
36
+ const latest = useRef({ p, setTagError })
37
+ latest.current = { p, setTagError }
38
+ const form = p.st.form
39
+ const injectedKey = JSON.stringify(form?.injectedTagsFor(p.v) ?? [])
40
+
41
+ useEffect(() => {
42
+ const ctx = (): PromptEditorCtx => {
43
+ const cur = latest.current.p
44
+ const f = cur.st.form
45
+ return {
46
+ weights: cur.v.desc.weights !== false,
47
+ tags: cur.v.desc.tags ?? null,
48
+ searchTags: async (q, signal) =>
49
+ (await fetchTags({ module: cur.module, varName: cur.v.name, q, signal })).hits,
50
+ injected: () => f?.injectedTagsFor(cur.v) ?? [],
51
+ loraWords: () => f?.loraWordsFor(cur.v) ?? [],
52
+ onTagError: (m) => latest.current.setTagError(m),
53
+ }
54
+ }
55
+ if (host.current == null) return
56
+ const v = new EditorView({
57
+ parent: host.current,
58
+ state: EditorState.create({
59
+ doc: latest.current.p.value,
60
+ extensions: promptExtensions({
61
+ ctx,
62
+ onChange: (text) => latest.current.p.onChange(text),
63
+ minLines: latest.current.p.minLines,
64
+ }),
65
+ }),
66
+ })
67
+ view.current = v
68
+ return () => {
69
+ v.destroy()
70
+ view.current = null
71
+ }
72
+ }, [])
73
+
74
+ // controlled: a value that changed from outside (preset, draft, revert) replaces the text
75
+ useEffect(() => {
76
+ const v = view.current
77
+ if (v == null) return
78
+ const doc = v.state.doc.toString()
79
+ if (doc === p.value) return
80
+ const head = Math.min(v.state.selection.main.head, p.value.length)
81
+ v.dispatch({ changes: { from: 0, to: doc.length, insert: p.value }, selection: { anchor: head } })
82
+ }, [p.value])
83
+
84
+ // a lora switched on or off moves which tags count as already added
85
+ useEffect(() => {
86
+ view.current?.dispatch({ effects: refreshMarks.of(null) })
87
+ }, [injectedKey])
88
+
89
+ const tokens = estimateTokens(p.value)
90
+ return (
91
+ <div className="prompt-editor">
92
+ <div ref={host} />
93
+ {/* keys and the token count are reference, not something to watch: they float in the
94
+ corner and show only while the editor has focus. A tag error always shows */}
95
+ <div className={tagError == null ? 'pe-foot' : 'pe-foot has-error'}>
96
+ {tagError == null ? null : (
97
+ <span className="pe-error" data-tip={tagError}>
98
+ tags: {tagError}
99
+ </span>
100
+ )}
101
+ <span className="pe-keys" data-tip={KEYS_TIP}>
102
+ keys
103
+ </span>
104
+ <span
105
+ className="pe-tokens"
106
+ data-tip={'an estimate of the CLIP tokens the positive prompt uses\nCLIP models read it in chunks of 75'}
107
+ >
108
+ ≈ {tokens} tokens
109
+ </span>
110
+ </div>
111
+ </div>
112
+ )
113
+ })
@@ -1,25 +1,32 @@
1
1
  // seed: mode buttons + value + 🎲. Drafts are live, so the mode configures the
2
2
  // SERVER's per-draft seed policy (generate posts no seed key; step 4 applies
3
- // the draft's {mode, value}). The buttons are the SYMBOLS the mode actually is,
4
- // with the sentence in the tooltip: `fixed / +1 / -1 / random` spelled out was a
5
- // row of prose wider than the input it belongs to
3
+ // the draft's {mode, value}). The buttons are ONE short word each (fixed, inc,
4
+ // random), the sentence in the tooltip: the bare symbols `= + ?` were unclear,
5
+ // and full sentences a row of prose wider than the input
6
6
  import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
7
7
  import { observer } from 'mobx-react-lite'
8
8
  import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
9
9
  import { asSeedForm, randomSeed } from 'src/cli/serve/web/state/payload.ts'
10
10
 
11
- const MODES: { mode: string; hint: string }[] = [
12
- { mode: '=', hint: 'fixed: this exact seed, every run' },
13
- { mode: '+', hint: 'increments after each run' },
14
- { mode: '?', hint: 'a fresh random seed each run' },
11
+ /** the stored mode stays the symbol (drafts, the TUI, the api all speak it); the button says
12
+ * the word, a row of `=` `+` `?` read like punctuation */
13
+ const MODES: { mode: string; label: string; hint: string }[] = [
14
+ { mode: '=', label: 'fixed', hint: 'this exact seed, every run' },
15
+ { mode: '+', label: 'inc', hint: 'one more after each run' },
16
+ { mode: '?', label: 'random', hint: 'a fresh random seed each run' },
15
17
  ]
16
18
 
17
19
  /** `-` is a real mode a draft can hold (the TUI offers it), it is just not worth a permanent
18
20
  * button here. It appears only while it IS the mode, so the row never misreports the draft,
19
21
  * and it disappears once you pick another one */
20
- function visibleModes(current: string): { mode: string; hint: string }[] {
22
+ function visibleModes(current: string): { mode: string; label: string; hint: string }[] {
21
23
  if (MODES.some((m) => m.mode === current)) return MODES
22
- return [...MODES, { mode: current, hint: current === '-' ? 'decrements after each run' : `mode '${current}'` }]
24
+ return [
25
+ ...MODES,
26
+ current === '-'
27
+ ? { mode: '-', label: 'dec', hint: 'one less after each run' }
28
+ : { mode: current, label: current, hint: `mode '${current}'` },
29
+ ]
23
30
  }
24
31
 
25
32
  export const SeedControl = observer(function SeedControl(p: { v: VarSt }) {
@@ -42,7 +49,7 @@ export const SeedControl = observer(function SeedControl(p: { v: VarSt }) {
42
49
  data-tip={m.hint}
43
50
  onClick={() => p.v.set({ mode: m.mode, value: seed.value })}
44
51
  >
45
- {m.mode}
52
+ {m.label}
46
53
  </button>
47
54
  ))}
48
55
  </span>
@@ -1,13 +1,48 @@
1
- // size: preset select + free WxH inputs + ⇄ swap
1
+ // size: starred presets as one-click aspect icons, then the full list (each row starrable),
2
+ // then W × H fields that fit their numbers, then ⇄ swap
2
3
  import { Icon } from 'src/cli/serve/web/components/Icon.tsx'
3
4
  import { observer } from 'mobx-react-lite'
5
+ import { useState, type ReactNode } from 'react'
4
6
  import type { VarSt } from 'src/cli/serve/web/state/FormSt.ts'
5
7
  import { asSizeForm } from 'src/cli/serve/web/state/payload.ts'
8
+ import { aspectBox, starredPresets, toggleStar } from 'src/cli/serve/web/state/sizeStars.ts'
9
+ import type { WebSt } from 'src/cli/serve/web/state/WebSt.ts'
6
10
 
7
- export const SizeControl = observer(function SizeControl(p: { v: VarSt }) {
11
+ /** a tiny rectangle in the preset's own ratio, centred in a fixed square so a row lines up */
12
+ function AspectIcon(p: { width: number; height: number; box?: number }): ReactNode {
13
+ const box = p.box ?? 14
14
+ const r = aspectBox(p.width, p.height, box - 2)
15
+ return (
16
+ <svg className="aspect-icon" width={box} height={box} viewBox={`0 0 ${box} ${box}`} aria-hidden="true">
17
+ <rect
18
+ x={(box - r.w) / 2}
19
+ y={(box - r.h) / 2}
20
+ width={r.w}
21
+ height={r.h}
22
+ rx={1.5}
23
+ fill="none"
24
+ stroke="currentColor"
25
+ strokeWidth={1.4}
26
+ />
27
+ </svg>
28
+ )
29
+ }
30
+
31
+ /** a number field as wide as its number, so 512 and 1344 both read without dead space */
32
+ function fitWidth(n: number): string {
33
+ return `${String(n).length + 2.6}ch`
34
+ }
35
+
36
+ export const SizeControl = observer(function SizeControl(p: { v: VarSt; st: WebSt; module: string }) {
37
+ const [open, setOpen] = useState(false)
8
38
  const size = asSizeForm(p.v.value)
9
39
  const presets = p.v.desc.presets ?? []
40
+ const starKey = `${p.module}/${p.v.name}`
41
+ const defaults = p.v.desc.starredPresets ?? []
42
+ const mine = p.st.sizeStars[starKey]
43
+ const stars = starredPresets({ presets, defaults, mine })
10
44
  const current = presets.find((pr) => pr.width === size.width && pr.height === size.height)
45
+ const pick = (pr: { width: number; height: number }): void => p.v.set({ width: pr.width, height: pr.height })
11
46
  const setDim = (patch: { width?: number; height?: number }): void => {
12
47
  const width = patch.width ?? size.width
13
48
  const height = patch.height ?? size.height
@@ -15,26 +50,84 @@ export const SizeControl = observer(function SizeControl(p: { v: VarSt }) {
15
50
  p.v.set({ width: Math.floor(width), height: Math.floor(height) })
16
51
  }
17
52
  return (
18
- <div className="row-inline">
19
- <select
20
- value={current?.label ?? '__custom__'}
21
- onChange={(e) => {
22
- const preset = presets.find((pr) => pr.label === e.target.value)
23
- if (preset != null) p.v.set({ width: preset.width, height: preset.height })
24
- }}
25
- >
26
- {current == null ? <option value="__custom__">custom</option> : null}
27
- {presets.map((pr) => (
28
- <option key={pr.label} value={pr.label}>
29
- {pr.label} ({pr.width}×{pr.height})
30
- </option>
31
- ))}
32
- </select>
33
- <input type="number" min={1} value={size.width} onChange={(e) => setDim({ width: Number(e.target.value) })} />
53
+ <div className="row-inline size-row">
54
+ {stars.length > 0 ? (
55
+ <span className="btn-group">
56
+ {stars.map((pr) => (
57
+ <button
58
+ key={pr.label}
59
+ type="button"
60
+ className={pr === current ? 'sel' : ''}
61
+ data-tip={`${pr.label} · ${pr.width}×${pr.height}`}
62
+ onClick={() => pick(pr)}
63
+ >
64
+ <AspectIcon width={pr.width} height={pr.height} />
65
+ </button>
66
+ ))}
67
+ </span>
68
+ ) : null}
69
+ <div className="preset-box" onKeyDown={(e) => (e.key === 'Escape' ? setOpen(false) : undefined)}>
70
+ <button type="button" className="preset-btn size-pick" aria-expanded={open} onClick={() => setOpen(!open)}>
71
+ <AspectIcon width={size.width} height={size.height} /> {current?.label ?? 'custom'} ▾
72
+ </button>
73
+ {open ? (
74
+ <>
75
+ <div className="preset-backdrop" onClick={() => setOpen(false)} />
76
+ <div className="preset-menu size-menu">
77
+ {presets.map((pr) => {
78
+ const starred = stars.includes(pr)
79
+ return (
80
+ <div key={pr.label} className={pr === current ? 'size-item on' : 'size-item'}>
81
+ <button
82
+ type="button"
83
+ className="size-item-pick"
84
+ onClick={() => {
85
+ pick(pr)
86
+ setOpen(false)
87
+ }}
88
+ >
89
+ <AspectIcon width={pr.width} height={pr.height} />
90
+ <span className="size-item-label">{pr.label}</span>
91
+ <span className="hint">
92
+ {pr.width}×{pr.height}
93
+ </span>
94
+ </button>
95
+ {/* the star is its own button: starring never changes the size */}
96
+ <button
97
+ type="button"
98
+ className={starred ? 'size-star on' : 'size-star'}
99
+ // a NATIVE tooltip: the page's own tooltip is drawn inside this scrolling list, sticks
100
+ // out past its edge and scrolls it sideways over the last row
101
+ title={
102
+ starred ? 'unstar: remove from the quick buttons' : 'star: add to the quick buttons'
103
+ }
104
+ onClick={() =>
105
+ p.st.setSizeStars(starKey, toggleStar({ defaults, mine, label: pr.label }))
106
+ }
107
+ >
108
+ {starred ? '★' : '☆'}
109
+ </button>
110
+ </div>
111
+ )
112
+ })}
113
+ </div>
114
+ </>
115
+ ) : null}
116
+ </div>
117
+ <input
118
+ type="number"
119
+ min={1}
120
+ className="size-num"
121
+ style={{ width: fitWidth(size.width) }}
122
+ value={size.width}
123
+ onChange={(e) => setDim({ width: Number(e.target.value) })}
124
+ />
34
125
  ×
35
126
  <input
36
127
  type="number"
37
128
  min={1}
129
+ className="size-num"
130
+ style={{ width: fitWidth(size.height) }}
38
131
  value={size.height}
39
132
  onChange={(e) => setDim({ height: Number(e.target.value) })}
40
133
  />
@@ -0,0 +1,2 @@
1
+ /** the modifier the shortcuts use on THIS machine, as a key cap shows it */
2
+ export const MOD_KEY = /mac|iphone|ipad/i.test(navigator.userAgent) ? '⌘' : 'Ctrl+'