@chai-ui/vue 0.8.0 → 0.9.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/dist/style.css CHANGED
@@ -751,6 +751,99 @@
751
751
  flex-wrap: wrap;
752
752
  }
753
753
 
754
+ .chai-composer__controls-end {
755
+ display: flex;
756
+ align-items: center;
757
+ gap: var(--chai-space-2);
758
+ }
759
+
760
+ /* Voice input: the mic left of submit. While recording it becomes a stop
761
+ button (a filled square in a ringed circle) and a waveform replaces the
762
+ prompt; while transcribing, a spinner. */
763
+ .chai-composer__voice {
764
+ display: flex;
765
+ align-items: center;
766
+ }
767
+
768
+ .chai-composer__voice-button {
769
+ display: flex;
770
+ align-items: center;
771
+ justify-content: center;
772
+ width: 40px;
773
+ height: 40px;
774
+ padding: 0;
775
+ border: 2px solid transparent;
776
+ border-radius: var(--chai-radius-full);
777
+ background: transparent;
778
+ color: var(--chai-composer-text);
779
+ cursor: pointer;
780
+ transition: background-color var(--chai-motion-duration-fast) var(--chai-motion-easing-standard);
781
+ }
782
+
783
+ .chai-composer__voice-button:hover:not(:disabled) {
784
+ background: var(--chai-composer-hover);
785
+ }
786
+
787
+ .chai-composer__voice-button:disabled {
788
+ cursor: not-allowed;
789
+ opacity: 0.5;
790
+ }
791
+
792
+ .chai-composer__voice-button svg {
793
+ width: 24px;
794
+ height: 24px;
795
+ }
796
+
797
+ .chai-composer__voice[data-status="recording"] .chai-composer__voice-button {
798
+ border-color: var(--chai-composer-text);
799
+ background: var(--chai-composer-hover);
800
+ }
801
+
802
+ .chai-composer__voice[data-status="recording"] .chai-composer__voice-button svg {
803
+ width: 18px;
804
+ height: 18px;
805
+ }
806
+
807
+ /* Same row height as the prompt it stands in for. */
808
+ .chai-composer__waveform {
809
+ display: flex;
810
+ align-items: center;
811
+ gap: var(--chai-space-3);
812
+ min-height: var(--chai-type-leading-body-large);
813
+ }
814
+
815
+ .chai-composer__waveform-bars {
816
+ flex: 1;
817
+ display: flex;
818
+ align-items: center;
819
+ justify-content: space-between;
820
+ height: var(--chai-type-leading-body-large);
821
+ min-width: 0;
822
+ }
823
+
824
+ .chai-composer__waveform-bar {
825
+ width: 2px;
826
+ border-radius: var(--chai-radius-full);
827
+ background: var(--chai-composer-text);
828
+ }
829
+
830
+ .chai-composer__waveform-time {
831
+ color: var(--chai-composer-text);
832
+ font-family: var(--chai-type-family-material);
833
+ font-size: var(--chai-type-size-label-large);
834
+ font-weight: var(--chai-type-weight-material-medium);
835
+ font-variant-numeric: tabular-nums;
836
+ }
837
+
838
+ .chai-composer__voice-spinner {
839
+ width: 20px;
840
+ height: 20px;
841
+ border-radius: 50%;
842
+ border: 2px solid var(--chai-color-semantic-control-border-faint);
843
+ border-top-color: var(--chai-color-semantic-accent);
844
+ animation: chai-spin var(--chai-motion-duration-steep) linear infinite;
845
+ }
846
+
754
847
  /* Neutral trigger text, not `--md-sys-color-primary` green (account
755
848
  holder correction: "don't make dropdown select menu buttons green when
756
849
  they don't need to be"). */
@@ -12,7 +12,7 @@ export declare function useComposer(options?: MaybeRefOrGetter<UseComposerOption
12
12
  submit: (payload: import("@chai-ui/core").ComposerSubmitPayload) => void;
13
13
  cancel: () => void;
14
14
  /** `undefined` without reasoning, so the Composer hides its Enhance button. */
15
- enhance: import("vue").ComputedRef<((value: string, field?: import("@chai-ui/core").ComposerPromptField) => Promise<string>) | undefined>;
15
+ enhance: import("vue").ComputedRef<((value: string, field?: import("@chai-ui/core").ComposerPromptField, mode?: import("@chai-ui/core").GenerationUseCase) => Promise<string>) | undefined>;
16
16
  enhancing: import("vue").ComputedRef<boolean>;
17
17
  routing: import("vue").ComputedRef<boolean>;
18
18
  /** Props for an `EditCard`, and `regions` for `Composer`. `null` when there's no `editImage`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chai-ui/vue",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "CHAI UI Vue components — smart, drop-in UI for AI apps: Composer, Media Analyzer, Result Card, Edit Card, and the useComposer composable.",
5
5
  "license": "MIT",
6
6
  "author": "kazarazat",
@@ -46,8 +46,8 @@
46
46
  "dependencies": {
47
47
  "@fontsource/roboto": "^5.3.0",
48
48
  "@material/web": "^2.5.0",
49
- "@chai-ui/core": "0.8.0",
50
- "@chai-ui/tokens": "0.8.0"
49
+ "@chai-ui/core": "0.9.0",
50
+ "@chai-ui/tokens": "0.9.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@vitejs/plugin-vue": "^6.0.9",
package/src/Composer.vue CHANGED
@@ -9,20 +9,22 @@
9
9
  * Some controls show only with somewhere for them to go, so these listeners
10
10
  * are props, checked for: `@update:attachments` (add and remove media),
11
11
  * `@update:model-id` / `@update:model-ids` (the Model menu),
12
- * `@update:aspect-ratio`, `@update:character` and `@update:frame-rate` (a
12
+ * `voiceInput` (the mic), `@update:aspect-ratio`, `@update:character` and `@update:frame-rate` (a
13
13
  * world's fields), `@update:use-cases` and `@clear-use-case` (chip
14
14
  * remove), `@update:regions`, `@enhance` (the Enhance button), `@abort` (stop
15
15
  * while submitting) and `@attach-menu-select` (the + menu's use cases).
16
16
  */
17
17
  import "@material/web/fab/fab.js";
18
- import { computed, ref, watch } from "vue";
18
+ import { computed, onScopeDispose, ref, shallowRef, watch } from "vue";
19
19
  import {
20
20
  composerAttachmentsFromFiles,
21
21
  composerAttachMenuItems,
22
22
  composerView,
23
+ createVoiceInput,
23
24
  type ComposerAttachment,
24
25
  type ComposerAttachMenuAction,
25
26
  type ComposerPromptField,
27
+ type GenerationUseCase,
26
28
  type ComposerSubmitPayload,
27
29
  type ComposerUseCase,
28
30
  type EditRegion,
@@ -30,10 +32,13 @@ import {
30
32
  type ModelOption,
31
33
  type OutputKind,
32
34
  type ParameterOption,
35
+ type VoiceInputConfig,
33
36
  } from "@chai-ui/core";
34
37
  import AttachMenu from "./composer/AttachMenu.vue";
35
38
  import Chip from "./composer/Chip.vue";
36
39
  import PromptField from "./composer/PromptField.vue";
40
+ import VoiceButton from "./composer/VoiceButton.vue";
41
+ import VoiceWaveform from "./composer/VoiceWaveform.vue";
37
42
  import { ArrowForwardIcon, CloseSymbolIcon, ErrorIcon, ImageIcon, MusicNoteIcon, RetryIcon, StopIcon, VideocamIcon } from "./icons.js";
38
43
  import SearchMenu from "./primitives/SearchMenu.vue";
39
44
 
@@ -75,8 +80,8 @@ const props = withDefaults(
75
80
  aspectRatios?: ParameterOption<string>[];
76
81
  aspectRatio?: string | null;
77
82
  "onUpdate:aspectRatio"?: (value: string) => void;
78
- /** Shows the Enhance button; your handler runs the rewrite and updates the prompt. Gets the current text, and with a world which field it's for. */
79
- onEnhance?: (value: string, field: ComposerPromptField) => void;
83
+ /** Shows the Enhance button; your handler runs the rewrite and updates the prompt. Gets the current text, which field, and the use case on screen (`mode`). */
84
+ onEnhance?: (value: string, field: ComposerPromptField, mode?: GenerationUseCase) => void;
80
85
  /** True while your Enhance handler is running. */
81
86
  enhancing?: boolean;
82
87
  /** A world's character field (Create world), beside the environment (`v-model`). Shows with `v-model:character`. */
@@ -98,6 +103,13 @@ const props = withDefaults(
98
103
  /** An edit's regions (from `useComposer`'s `edit`), shown as colored chips while editing. */
99
104
  regions?: EditRegion[];
100
105
  "onUpdate:regions"?: (next: EditRegion[]) => void;
106
+ /**
107
+ * The mic, left of submit: the transcript is added to the prompt, never
108
+ * submitted. `{ model: "fal-ai/wizper" }` goes through your
109
+ * `/api/chai/fal` route; `{ transcribe }` uses any provider. Off by
110
+ * default, with no default model.
111
+ */
112
+ voiceInput?: VoiceInputConfig;
101
113
  disabled?: boolean;
102
114
  }>(),
103
115
  {
@@ -175,9 +187,24 @@ const enhanceField = (field: ComposerPromptField) =>
175
187
  props.onEnhance &&
176
188
  ((current: string) => {
177
189
  enhancingField.value = field;
178
- props.onEnhance?.(current, field);
190
+ props.onEnhance?.(current, field, view.value.enhanceMode);
179
191
  });
180
192
 
193
+ // Voice input: a transcript is added to the prompt, never submitted.
194
+ const voice = createVoiceInput(
195
+ () => props.voiceInput ?? { transcribe: async () => "" },
196
+ (text) => {
197
+ const current = props.modelValue;
198
+ emit("update:modelValue", current.trim() ? `${current.trimEnd()} ${text}` : text);
199
+ }
200
+ );
201
+ const voiceState = shallowRef(voice.getState());
202
+ const stopVoice = voice.subscribe(() => (voiceState.value = voice.getState()));
203
+ onScopeDispose(() => {
204
+ stopVoice();
205
+ voice.dispose();
206
+ });
207
+
181
208
  async function onFiles(files: FileList | null) {
182
209
  const onAttachments = props["onUpdate:attachments"];
183
210
  if (!files || files.length === 0 || !onAttachments) return;
@@ -228,7 +255,8 @@ function onSubmitClick() {
228
255
  </li>
229
256
  </ul>
230
257
 
231
- <div v-if="view.world" class="chai-composer__world-fields">
258
+ <VoiceWaveform v-if="voiceInput && voiceState.status === 'recording'" :levels="voiceState.levels" :elapsed-ms="voiceState.elapsedMs" />
259
+ <div v-else-if="view.world" class="chai-composer__world-fields">
232
260
  <PromptField
233
261
  :value="modelValue"
234
262
  :placeholder="view.placeholder"
@@ -264,6 +292,7 @@ function onSubmitClick() {
264
292
  />
265
293
 
266
294
  <p v-if="submitError" class="chai-composer__error" role="alert"><ErrorIcon />{{ submitError }}</p>
295
+ <p v-if="voiceInput && voiceState.status === 'error'" class="chai-composer__error" role="alert"><ErrorIcon />{{ voiceState.error }}</p>
267
296
 
268
297
  <div class="chai-composer__controls">
269
298
  <div class="chai-composer__controls-start">
@@ -330,8 +359,12 @@ function onSubmitClick() {
330
359
  />
331
360
  </div>
332
361
 
333
- <!-- MD3's md-fab has no disabled state of its own; Chai's unfilled-until-ready look comes from `data-ready` in style.css. `label=""` keeps it a plain icon FAB. -->
362
+ <div class="chai-composer__controls-end">
363
+ <VoiceButton v-if="voiceInput" :voice="voice" :state="voiceState" :disabled="disabled" />
364
+ <!-- MD3's md-fab has no disabled state of its own; Chai's unfilled-until-ready look comes from `data-ready` in style.css. `label=""` keeps it a plain icon FAB.
365
+ Hidden while a recording is made or transcribed: the transcript is sent once it's in the prompt to check. -->
334
366
  <md-fab
367
+ v-if="!(voiceInput && (voiceState.status === 'recording' || voiceState.status === 'transcribing'))"
335
368
  class="chai-composer__submit"
336
369
  size="small"
337
370
  variant="secondary"
@@ -345,6 +378,7 @@ function onSubmitClick() {
345
378
  >
346
379
  <span slot="icon"><StopIcon v-if="view.showStop" /><RetryIcon v-else-if="submitError" /><ArrowForwardIcon v-else /></span>
347
380
  </md-fab>
381
+ </div>
348
382
  </div>
349
383
  </div>
350
384
  </template>
@@ -0,0 +1,50 @@
1
+ <script setup lang="ts">
2
+ /** The mic: click to record; while recording, a stop button that transcribes; while transcribing, a spinner that cancels. */
3
+ import { computed } from "vue";
4
+ import type { VoiceInput, VoiceInputState } from "@chai-ui/core";
5
+ import { MicIcon, StopIcon } from "../icons.js";
6
+
7
+ const props = defineProps<{ voice: VoiceInput; state: VoiceInputState; disabled?: boolean }>();
8
+
9
+ const label = computed(() =>
10
+ props.state.status === "recording"
11
+ ? "Stop recording and transcribe"
12
+ : props.state.status === "transcribing"
13
+ ? "Cancel transcription"
14
+ : "Start voice input"
15
+ );
16
+
17
+ function onClick() {
18
+ const { status } = props.state;
19
+ if (status === "recording") props.voice.stop();
20
+ else if (status === "transcribing") props.voice.cancel();
21
+ else {
22
+ props.voice.dismiss();
23
+ void props.voice.start();
24
+ }
25
+ }
26
+
27
+ function onKeydown(e: KeyboardEvent) {
28
+ if (e.key === "Escape" && props.state.status === "recording") props.voice.cancel();
29
+ }
30
+ </script>
31
+
32
+ <template>
33
+ <div class="chai-composer__voice" :data-status="state.status">
34
+ <button
35
+ type="button"
36
+ class="chai-composer__voice-button"
37
+ :disabled="disabled"
38
+ :aria-label="label"
39
+ :title="label"
40
+ @click="onClick"
41
+ @keydown="onKeydown"
42
+ >
43
+ <span v-if="state.status === 'transcribing'" class="chai-composer__voice-spinner" aria-hidden="true" /><StopIcon
44
+ v-else-if="state.status === 'recording'"
45
+ /><MicIcon v-else />
46
+ </button>
47
+ <!-- Announces each change of state once, not every tick of the timer. -->
48
+ <span class="chai-visually-hidden" role="status">{{ state.status === "recording" ? "Recording" : state.status === "transcribing" ? "Transcribing" : "" }}</span>
49
+ </div>
50
+ </template>
@@ -0,0 +1,17 @@
1
+ <script setup lang="ts">
2
+ /** What replaces the prompt while recording: recent mic loudness as bars, newest on the right, and the time. Decorative. */
3
+ import { computed } from "vue";
4
+ import { formatVoiceElapsed, VOICE_LEVEL_COUNT } from "@chai-ui/core";
5
+
6
+ const props = defineProps<{ levels: number[]; elapsedMs: number }>();
7
+ const bars = computed(() => [...Array<number>(Math.max(0, VOICE_LEVEL_COUNT - props.levels.length)).fill(0), ...props.levels]);
8
+ </script>
9
+
10
+ <template>
11
+ <div class="chai-composer__waveform" aria-hidden="true">
12
+ <div class="chai-composer__waveform-bars">
13
+ <span v-for="(level, i) in bars" :key="i" class="chai-composer__waveform-bar" :style="{ height: `${Math.max(20, level * 100)}%` }" />
14
+ </div>
15
+ <span class="chai-composer__waveform-time">{{ formatVoiceElapsed(elapsedMs) }}</span>
16
+ </div>
17
+ </template>
package/src/icons.ts CHANGED
@@ -28,6 +28,8 @@ export const VisibilityIcon = icon("0 -960 960 960", [{ "d": "M600.5-379.5Q650-4
28
28
  export const VisibilityOffIcon = icon("0 -960 960 960", [{ "d": "m629-419-44-44q26-71-27-118t-115-24l-44-44q17-11 38-16t43-5q71 0 120.5 49.5T650-500q0 22-5.5 43.5T629-419Zm129 129-40-40q49-36 85.5-80.5T857-500q-50-111-150-175.5T490-740q-42 0-86 8t-69 19l-46-47q35-16 89.5-28T485-800q143 0 261.5 81.5T920-500q-26 64-67 117t-95 93Zm58 226L648-229q-35 14-79 21.5t-89 7.5q-146 0-265-81.5T40-500q20-52 55.5-101.5T182-696L56-822l42-43 757 757-39 44ZM223-654q-37 27-71.5 71T102-500q51 111 153.5 175.5T488-260q33 0 65-4t48-12l-64-64q-11 5-27 7.5t-30 2.5q-70 0-120-49t-50-121q0-15 2.5-30t7.5-27l-97-97Zm305 142Zm-116 58Z", "fill": "currentColor" }]);
29
29
  export const CheckSymbolIcon = icon("0 -960 960 960", [{ "d": "M378-246 154-470l43-43 181 181 384-384 43 43-427 427Z", "fill": "currentColor" }]);
30
30
  export const CloseSymbolIcon = icon("0 -960 960 960", [{ "d": "m249-207-42-42 231-231-231-231 42-42 231 231 231-231 42 42-231 231 231 231-42 42-231-231-231 231Z", "fill": "currentColor" }]);
31
+ /** Material Symbols "mic" — voice input. */
32
+ export const MicIcon = icon("0 -960 960 960", [{ "d": "M408-453.92q-29-30.91-29-75.08v-251q0-41.67 29.44-70.83Q437.88-880 479.94-880t71.56 29.17Q581-821.67 581-780v251q0 44.17-29 75.08Q523-423 480-423t-72-30.92ZM480-651Zm-30 531v-136q-106-11-178-89t-72-184h60q0 91 64.29 153t155.5 62q91.21 0 155.71-62Q700-438 700-529h60q0 106-72 184t-178 89v136h-60Zm59.5-376.5Q521-510 521-529v-251q0-17-11.79-28.5T480-820q-17.42 0-29.21 11.5T439-780v251q0 19 11.5 32.5T480-483q18 0 29.5-13.5Z", "fill": "currentColor" }]);
31
33
  export const StopIcon = icon("0 -960 960 960", [{ "d": "M240-240v-480h480v480H240Z", "fill": "currentColor" }]);
32
34
  export const ThumbUpIcon = icon("0 0 18 18", [{ "d": "M5.25039 15.7502V6.00019L10.5004 0.750193L11.8879 2.13769L10.9129 6.00019H17.2504V9.30019L14.5129 15.7502H5.25039ZM6.75039 14.2502H13.5004L15.7504 9.00019V7.50019H9.00039L10.0129 3.37519L6.75039 6.63769V14.2502ZM1.50039 15.7502V6.00019H5.25039V7.50019H3.00039V14.2502H5.25039V15.7502H1.50039Z", "fill": "currentColor" }], true);
33
35
  export const ThumbDownIcon = icon("0 0 18 18", [{ "d": "M2.24961 12C1.84961 12 1.49961 11.85 1.19961 11.55C0.899615 11.25 0.749615 10.9 0.749615 10.5V9C0.749615 8.9125 0.762115 8.81875 0.787115 8.71875C0.812115 8.61875 0.837115 8.525 0.862115 8.4375L3.11211 3.15C3.22461 2.9 3.41211 2.6875 3.67461 2.5125C3.93711 2.3375 4.21211 2.25 4.49961 2.25H12.7496V12L8.24961 16.4625C8.06211 16.65 7.84024 16.7594 7.58399 16.7906C7.32774 16.8219 7.08086 16.775 6.84336 16.65C6.60586 16.525 6.43086 16.35 6.31836 16.125C6.20586 15.9 6.18086 15.6688 6.24336 15.4313L7.08711 12H2.24961ZM11.2496 11.3625V3.75H4.49961L2.24961 9V10.5H8.99961L7.98711 14.625L11.2496 11.3625ZM14.9996 2.25C15.4121 2.25 15.7652 2.39688 16.059 2.69063C16.3527 2.98438 16.4996 3.3375 16.4996 3.75V10.5C16.4996 10.9125 16.3527 11.2656 16.059 11.5594C15.7652 11.8531 15.4121 12 14.9996 12H12.7496V10.5H14.9996V3.75H12.7496V2.25H14.9996Z", "fill": "currentColor" }], true);
package/src/index.ts CHANGED
@@ -16,6 +16,7 @@ export * from "./useMediaAnalyzer.js";
16
16
  // to import from @chai-ui/vue.
17
17
  export {
18
18
  createFalEngine,
19
+ createFalTranscriber,
19
20
  createOpenRouterEngine,
20
21
  createMockEngine,
21
22
  mockEngine,
@@ -64,6 +65,9 @@ export type {
64
65
  MediaKind,
65
66
  ModelOption,
66
67
  OutputKind,
68
+ Transcribe,
69
+ VoiceClip,
70
+ VoiceInputConfig,
67
71
  ParameterOption,
68
72
  Reasoning,
69
73
  RegionBox,