@lynn123411/dsh-model-submenu 0.3.5 → 0.3.11

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.
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Geometry of the discrete effort slider.
3
+ *
4
+ * The track is a capsule and the knob a slightly larger circle riding on it, so
5
+ * the knob overhangs the track instead of merging with its rounded end. The
6
+ * knob's centre travels between two points inset by the knob's radius, so the
7
+ * knob never runs past either end. A pointer position becomes a position along
8
+ * that travel; a position becomes the detent nearest it, or the CSS lengths that
9
+ * put the knob and the fill there.
10
+ */
11
+
12
+ /**
13
+ * Track height in CSS pixels; the stylesheet keeps the same value. Half of it is
14
+ * the radius of the track's ends and of the fill's cap.
15
+ */
16
+ export const TRACK_HEIGHT = 16;
17
+
18
+ /**
19
+ * Knob diameter in CSS pixels. It is larger than the track, so the knob reads as
20
+ * a knob riding on the track rather than as the track's own end cap.
21
+ */
22
+ export const KNOB_SIZE = 20;
23
+
24
+ /** The knob's centre keeps its own radius away from either end of the track. */
25
+ const KNOB_RADIUS = KNOB_SIZE / 2;
26
+
27
+ /**
28
+ * @param index - detent index.
29
+ * @param count - number of detents.
30
+ * @returns the knob centre as a fraction of the track, 0 at the first detent and 1 at the last.
31
+ */
32
+ export function offsetOf(index: number, count: number): number {
33
+ if (count <= 1) return 0;
34
+ const clamped = Math.min(Math.max(index, 0), count - 1);
35
+ return clamped / (count - 1);
36
+ }
37
+
38
+ /**
39
+ * Where a pointer sits along the knob's travel. The drag reads this rather than a
40
+ * detent, so the knob follows the pointer instead of jumping a level at a time.
41
+ * @param clientX - pointer position in viewport coordinates.
42
+ * @param left - the track's left edge in viewport coordinates.
43
+ * @param width - the track's width in pixels.
44
+ * @returns the position as a fraction of the travel, clamped to 0 and 1.
45
+ */
46
+ export function fractionAt(clientX: number, left: number, width: number): number {
47
+ const usable = width - KNOB_SIZE;
48
+ if (usable <= 0) return 0;
49
+ const fraction = (clientX - left - KNOB_RADIUS) / usable;
50
+ return Math.min(Math.max(fraction, 0), 1);
51
+ }
52
+
53
+ /**
54
+ * @param fraction - a knob position between 0 and 1.
55
+ * @param count - number of detents.
56
+ * @returns the detent nearest that position.
57
+ */
58
+ export function detentAt(fraction: number, count: number): number {
59
+ if (count <= 1) return 0;
60
+ const clamped = Math.min(Math.max(fraction, 0), 1);
61
+ return Math.round(clamped * (count - 1));
62
+ }
63
+
64
+ /**
65
+ * @param clientX - pointer position in viewport coordinates.
66
+ * @param left - the track's left edge in viewport coordinates.
67
+ * @param width - the track's width in pixels.
68
+ * @param count - number of detents.
69
+ * @returns the detent nearest the pointer, clamped to the two ends.
70
+ */
71
+ export function stepAt(clientX: number, left: number, width: number, count: number): number {
72
+ if (count <= 1) return 0;
73
+ return detentAt(fractionAt(clientX, left, width), count);
74
+ }
75
+
76
+ /**
77
+ * @param fraction - a knob position between 0 and 1.
78
+ * @returns the CSS length that puts the knob centre there, inset at both ends.
79
+ */
80
+ export function knobOffset(fraction: number): string {
81
+ const clamped = Math.min(Math.max(fraction, 0), 1);
82
+ return `calc(${KNOB_RADIUS}px + ${clamped} * (100% - ${KNOB_SIZE}px))`;
83
+ }
84
+
85
+ /**
86
+ * Width of the colored fill for a knob position.
87
+ *
88
+ * The fill is the track's own shape cut at the knob: its right cap carries the
89
+ * track's radius and ends under the knob, so the color runs into the knob
90
+ * instead of stopping at a straight edge, and the last detent reaches the track's
91
+ * end rather than the knob's centre.
92
+ * @param fraction - a knob position between 0 and 1.
93
+ * @returns the CSS width of the fill.
94
+ */
95
+ export function fillWidth(fraction: number): string {
96
+ const clamped = Math.min(Math.max(fraction, 0), 1);
97
+ return `calc(${TRACK_HEIGHT}px + ${clamped} * (100% - ${TRACK_HEIGHT}px))`;
98
+ }
@@ -1,509 +0,0 @@
1
- /*
2
- * The composer model seat and the picker it opens. The menu surface renders
3
- * through the primitives' MenuSurface and the dialog through Modal, so neither
4
- * this file paints a floating fill — it only places content on the surfaces
5
- * those two own.
6
- */
7
-
8
- .root {
9
- min-width: 0;
10
- position: relative;
11
- display: flex;
12
- }
13
-
14
- /* The Models glyph replaces the text when the composer row cannot fit it; the
15
- * row owns both variables, so this plugin follows the same compact contract as
16
- * the built-in occupant. */
17
- .trigger {
18
- min-width: 0;
19
- max-width: min(360px, 45cqw);
20
- height: 28px;
21
- color: var(--dsw-alias-label-secondary);
22
- cursor: pointer;
23
- background: 0 0;
24
- border: none;
25
- border-radius: 24px;
26
- outline: none;
27
- align-items: center;
28
- gap: 4px;
29
- padding: 0 4px 0 8px;
30
- font-size: 13px;
31
- font-weight: 500;
32
- line-height: 20px;
33
- display: flex;
34
- }
35
-
36
- .trigger:hover:not(:disabled) {
37
- background: var(--dsw-alias-interactive-bg-hover);
38
- }
39
-
40
- .trigger:focus-visible {
41
- box-shadow: 0 0 0 2px var(--dsw-alias-border-l3);
42
- }
43
-
44
- .trigger:disabled {
45
- color: var(--dsw-alias-label-dimmed);
46
- cursor: default;
47
- }
48
-
49
- .triggerLabel {
50
- text-overflow: ellipsis;
51
- white-space: nowrap;
52
- min-width: 0;
53
- overflow: hidden;
54
- display: var(--dsh-composer-model-text-display, block);
55
- }
56
-
57
- /* The effort caption is the accent the reference UI uses to say "this is the
58
- * thinking level in force"; it carries no extra meaning of its own. */
59
- .triggerEffort {
60
- text-overflow: ellipsis;
61
- white-space: nowrap;
62
- min-width: 0;
63
- color: var(--dsw-alias-state-business-primary);
64
- flex-shrink: 1000;
65
- overflow: hidden;
66
- display: var(--dsh-composer-model-text-display, block);
67
- }
68
-
69
- .triggerIcon {
70
- flex: 0 0 auto;
71
- display: var(--dsh-composer-model-icon-display, none);
72
- }
73
-
74
- .triggerBadge {
75
- flex: none;
76
- margin-inline-end: 4px;
77
- }
78
-
79
- .rowBadge {
80
- flex: none;
81
- margin-inline-start: 6px;
82
- }
83
-
84
- .chevron {
85
- color: var(--dsw-alias-label-caption);
86
- flex: none;
87
- transition: transform .12s;
88
- }
89
-
90
- .chevronOpen {
91
- transform: rotate(180deg);
92
- }
93
-
94
- .menu {
95
- z-index: 1100;
96
- --dsw-elevation-stroke-color: var(--dsw-alias-border-l1);
97
- /* A fixed width keeps the card independent of the trigger's text length, so
98
- * opening the menu never reflows the composer. */
99
- box-sizing: border-box;
100
- width: min(252px, calc(100vw - 24px));
101
- max-height: var(--dsh-anchored-max-height, min(70vh, calc(100vh - 96px)));
102
- box-shadow: var(--dsw-elevation-prominent);
103
- color: var(--dsw-alias-label-primary);
104
- --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2);
105
- --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2);
106
- border: 0;
107
- flex-direction: column;
108
- padding: 4px;
109
- display: flex;
110
- position: fixed;
111
- overflow: hidden;
112
- }
113
-
114
- /* The provider name is a heading, not a control: it says which provider's
115
- * models the list below belongs to. */
116
- .providerName {
117
- text-overflow: ellipsis;
118
- white-space: nowrap;
119
- min-height: 24px;
120
- color: var(--dsw-alias-label-tertiary);
121
- align-items: center;
122
- padding: 3px 8px;
123
- font-size: 12px;
124
- font-weight: 500;
125
- line-height: 18px;
126
- overflow: hidden;
127
- display: flex;
128
- }
129
-
130
- .groups {
131
- min-height: 0;
132
- overflow-y: auto;
133
- }
134
-
135
- .row {
136
- align-items: center;
137
- gap: 2px;
138
- display: flex;
139
- }
140
-
141
- .rowPick {
142
- box-sizing: border-box;
143
- /* A slightly tighter side padding buys the name a few more characters, which
144
- * is what keeps a long provider suffix readable inside a narrow card. */
145
- padding-inline: 6px;
146
- /* The scroll list is a block container, so a flex item's `flex: 1` does
147
- * nothing here: the row must claim the full width or a long model name pushes
148
- * the favorite mark and the check past the card's edge, where overflow clips
149
- * them. */
150
- width: 100%;
151
- flex: 1;
152
- min-width: 0;
153
- min-height: 34px;
154
- color: inherit;
155
- text-align: left;
156
- cursor: pointer;
157
- background: 0 0;
158
- border: none;
159
- border-radius: 10px;
160
- outline: none;
161
- align-items: center;
162
- gap: 4px;
163
- padding: 5px 7px;
164
- display: flex;
165
- }
166
-
167
- .rowPick:hover:not(:disabled),
168
- .rowPick:focus-visible {
169
- background: var(--dsw-alias-interactive-bg-hover);
170
- }
171
-
172
- .rowPick:disabled {
173
- color: var(--dsw-alias-label-dimmed);
174
- cursor: default;
175
- }
176
-
177
- .rowCopy {
178
- flex-direction: column;
179
- flex: 1;
180
- min-width: 0;
181
- display: flex;
182
- }
183
-
184
- .rowName {
185
- color: inherit;
186
- text-overflow: ellipsis;
187
- white-space: nowrap;
188
- font-size: 11.5px;
189
- font-weight: 400;
190
- line-height: 17px;
191
- overflow: hidden;
192
- }
193
-
194
- /* The menu's names carry the weight: at this size a regular face reads thin
195
- * against the card. The picker's rows keep theirs regular — there the metadata
196
- * line already separates the rows. */
197
- .menu .rowName {
198
- font-weight: 600;
199
- }
200
-
201
- .rowMeta {
202
- color: var(--dsw-alias-label-tertiary);
203
- text-overflow: ellipsis;
204
- white-space: nowrap;
205
- font-size: 12px;
206
- line-height: 18px;
207
- overflow: hidden;
208
- }
209
-
210
- .check {
211
- color: var(--dsw-alias-label-primary);
212
- flex: 0 0 15px;
213
- place-items: center;
214
- display: grid;
215
- }
216
-
217
- /* The menu's favorite mark: it lives inside the row button, so hovering it
218
- * highlights the row and clicking it picks the model — no separate hit area. */
219
- .starStatic {
220
- color: var(--dsw-alias-state-warn-primary);
221
- flex: none;
222
- place-items: center;
223
- width: 14px;
224
- display: grid;
225
- }
226
-
227
- /* The picker's star is a real control: outline until hover or focus, solid and
228
- * gold once favorited, and visible without hover on touch screens. */
229
- .starButton {
230
- color: var(--dsw-alias-label-tertiary);
231
- cursor: pointer;
232
- background: 0 0;
233
- border: none;
234
- border-radius: 8px;
235
- outline: none;
236
- flex: none;
237
- place-items: center;
238
- width: 26px;
239
- height: 26px;
240
- display: grid;
241
- opacity: 0;
242
- }
243
-
244
- .starButton:focus-visible {
245
- outline: 2px solid var(--dsw-alias-border-l3);
246
- }
247
-
248
- .row:hover .starButton,
249
- .row:focus-within .starButton {
250
- opacity: 1;
251
- }
252
-
253
- .starButton[aria-pressed='true'] {
254
- color: var(--dsw-alias-state-warn-primary);
255
- opacity: 1;
256
- }
257
-
258
- @media (hover: none) {
259
- .starButton {
260
- opacity: 1;
261
- }
262
- }
263
-
264
- .star {
265
- flex: none;
266
- }
267
-
268
- .divider {
269
- height: .5px;
270
- background: var(--dsw-alias-border-l2);
271
- flex: none;
272
- margin: 3px 2px;
273
- }
274
-
275
- .effortRow {
276
- align-items: center;
277
- gap: 6px;
278
- padding: 3px 6px;
279
- display: flex;
280
- }
281
-
282
- .effortHeading {
283
- color: var(--dsw-alias-label-primary);
284
- flex: none;
285
- font-size: 12px;
286
- line-height: 18px;
287
- }
288
-
289
- /* The segments scroll sideways rather than wrap, so the row keeps one height
290
- * however many levels a model advertises. */
291
- .effortTrack {
292
- background: var(--dsw-alias-interactive-bg-hover);
293
- border-radius: 999px;
294
- align-items: center;
295
- gap: 1px;
296
- min-width: 0;
297
- margin-left: auto;
298
- padding: 2px;
299
- display: flex;
300
- overflow-x: auto;
301
- scrollbar-width: none;
302
- }
303
-
304
- .effortTrack::-webkit-scrollbar {
305
- display: none;
306
- }
307
-
308
- .effortSegment {
309
- color: var(--dsw-alias-label-secondary);
310
- cursor: pointer;
311
- background: 0 0;
312
- border: none;
313
- border-radius: 999px;
314
- outline: none;
315
- flex: none;
316
- padding: 2px 7px;
317
- font-size: 11px;
318
- line-height: 16px;
319
- }
320
-
321
- .effortSegment:hover:not(:disabled) {
322
- color: var(--dsw-alias-label-primary);
323
- }
324
-
325
- .effortSegment[aria-checked='true'] {
326
- color: var(--dsw-alias-label-primary);
327
- background: var(--dsw-alias-bg-layer-1);
328
- box-shadow: var(--dsw-elevation-soft);
329
- font-weight: 600;
330
- }
331
-
332
- .effortSegment:disabled {
333
- color: var(--dsw-alias-label-dimmed);
334
- cursor: default;
335
- }
336
-
337
- .effortSegment:focus-visible {
338
- outline: 2px solid var(--dsw-alias-border-l3);
339
- outline-offset: -2px;
340
- }
341
-
342
- .hint {
343
- color: var(--dsw-alias-label-tertiary);
344
- margin: 0;
345
- padding: 6px 8px;
346
- font-size: 11px;
347
- line-height: 16px;
348
- }
349
-
350
- .moreRow {
351
- color: var(--dsw-alias-label-secondary);
352
- cursor: pointer;
353
- background: 0 0;
354
- border: none;
355
- border-radius: 10px;
356
- outline: none;
357
- align-items: center;
358
- gap: 6px;
359
- min-height: 32px;
360
- padding: 5px 8px;
361
- font-size: 12px;
362
- line-height: 18px;
363
- display: flex;
364
- }
365
-
366
- .moreRow:hover,
367
- .moreRow:focus-visible {
368
- color: var(--dsw-alias-label-primary);
369
- background: var(--dsw-alias-interactive-bg-hover);
370
- }
371
-
372
- .moreIcon {
373
- color: var(--dsw-alias-label-tertiary);
374
- flex: none;
375
- }
376
-
377
- .notice {
378
- color: var(--dsw-alias-label-tertiary);
379
- justify-content: space-between;
380
- align-items: flex-start;
381
- gap: 8px;
382
- padding: 6px 10px;
383
- font-size: 12px;
384
- line-height: 18px;
385
- display: flex;
386
- }
387
-
388
- .retry {
389
- color: inherit;
390
- font: inherit;
391
- cursor: pointer;
392
- background: 0 0;
393
- border: none;
394
- flex: none;
395
- padding: 0;
396
- font-weight: 600;
397
- text-decoration: underline;
398
- }
399
-
400
- /* ── the picker dialog ───────────────────────────────────────────────────── */
401
-
402
- .pickerDialog {
403
- width: min(680px, 100%);
404
- height: min(640px, 80vh);
405
- gap: 0;
406
- padding: 0;
407
- }
408
-
409
- .pickerContent {
410
- min-height: 0;
411
- flex: 1;
412
- display: flex;
413
- flex-direction: column;
414
- }
415
-
416
- /* Modal wraps children in a body row of its own; that row — the content
417
- * region's last child — is what has to carry the column and give the list its
418
- * remaining height, so the footer stays put while the list scrolls. */
419
- .pickerContent > :last-child {
420
- min-height: 0;
421
- flex: 1;
422
- display: flex;
423
- flex-direction: column;
424
- }
425
-
426
- .pickerSearch {
427
- padding: 0 20px 12px;
428
- }
429
-
430
- .pickerSearchInput {
431
- width: 100%;
432
- }
433
-
434
- /* The tabs scroll sideways rather than wrap: the dialog keeps one row of
435
- * providers however many the catalog has, so the list below starts at the same
436
- * height every time. The bar keeps its hairline and hides its scrollbar the way
437
- * the effort track does. */
438
- .pickerTabs {
439
- border-bottom: .5px solid var(--dsw-alias-border-l2);
440
- gap: 2px;
441
- padding: 0 16px;
442
- display: flex;
443
- flex-wrap: nowrap;
444
- overflow-x: auto;
445
- overscroll-behavior-x: contain;
446
- scrollbar-width: none;
447
- }
448
-
449
- .pickerTabs::-webkit-scrollbar {
450
- display: none;
451
- }
452
-
453
- .pickerTab {
454
- color: var(--dsw-alias-label-secondary);
455
- cursor: pointer;
456
- background: 0 0;
457
- border: none;
458
- border-radius: 8px;
459
- outline: none;
460
- flex: none;
461
- padding: 6px 10px;
462
- font-size: 13px;
463
- line-height: 18px;
464
- white-space: nowrap;
465
- }
466
-
467
- .pickerTab:hover {
468
- color: var(--dsw-alias-label-primary);
469
- background: var(--dsw-alias-interactive-bg-hover);
470
- }
471
-
472
- .pickerTab[aria-selected='true'] {
473
- color: var(--dsw-alias-label-primary);
474
- background: var(--dsw-alias-interactive-bg-hover);
475
- font-weight: 600;
476
- }
477
-
478
- .pickerTab:focus-visible {
479
- outline: 2px solid var(--dsw-alias-border-l3);
480
- }
481
-
482
- .pickerList {
483
- min-height: 0;
484
- flex: 1;
485
- padding: 8px 12px;
486
- overflow-y: auto;
487
- }
488
-
489
- .pickerFooter {
490
- border-top: .5px solid var(--dsw-alias-border-l2);
491
- color: var(--dsw-alias-label-tertiary);
492
- align-items: center;
493
- gap: 6px;
494
- padding: 10px 20px;
495
- font-size: 12px;
496
- line-height: 18px;
497
- display: flex;
498
- }
499
-
500
- .footerHint {
501
- align-items: center;
502
- gap: 6px;
503
- display: flex;
504
- flex-wrap: wrap;
505
- }
506
-
507
- .footerDot {
508
- color: var(--dsw-alias-label-dimmed);
509
- }