@magicx-eng/ai-autocomplete-react 0.1.24 → 0.1.26

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var xe=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var Ue=Object.prototype.hasOwnProperty;var Qe=(o,e)=>{for(var t in e)xe(o,t,{get:e[t],enumerable:!0})},We=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ve(e))!Ue.call(o,r)&&r!==t&&xe(o,r,{get:()=>e[r],enumerable:!(i=qe(e,r))||i.enumerable});return o};var je=o=>We(xe({},"__esModule",{value:!0}),o);var gt={};Qe(gt,{AIAutocomplete:()=>$e,AIAutocompleteDropdown:()=>te,useAIAutocomplete:()=>ce});module.exports=je(gt);var P=require("react");if(typeof document<"u"&&!document.getElementById("ac-style-cc65f4cc")){let o=document.createElement("style");o.id="ac-style-cc65f4cc",o.textContent=`.AIAutocomplete-module_container_KKjFU {
1
+ "use strict";var be=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var Ue=Object.prototype.hasOwnProperty;var Qe=(o,e)=>{for(var t in e)be(o,t,{get:e[t],enumerable:!0})},We=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ve(e))!Ue.call(o,r)&&r!==t&&be(o,r,{get:()=>e[r],enumerable:!(i=qe(e,r))||i.enumerable});return o};var je=o=>We(be({},"__esModule",{value:!0}),o);var gt={};Qe(gt,{AIAutocomplete:()=>$e,AIAutocompleteDropdown:()=>ee,useAIAutocomplete:()=>pe});module.exports=je(gt);var C=require("react");if(typeof document<"u"&&!document.getElementById("ac-style-cc65f4cc")){let o=document.createElement("style");o.id="ac-style-cc65f4cc",o.textContent=`.AIAutocomplete-module_container_KKjFU {
2
2
  position: relative;
3
3
  font-family: "IBM Plex Sans", sans-serif;
4
4
  container-type: inline-size;
@@ -47,7 +47,7 @@
47
47
 
48
48
  .AIAutocomplete-module_placeholderText_K3ayy {
49
49
  color: var(--aia-color-text-muted, #c1c4cb);
50
- opacity: 0.7;
50
+ opacity: 0.4;
51
51
  }
52
52
 
53
53
  .AIAutocomplete-module_textarea_eyn6A {
@@ -60,7 +60,10 @@
60
60
  border: none;
61
61
  background: transparent;
62
62
  color: var(--aia-written-text-color, var(--aia-color-text-default, #fff));
63
- caret-color: var(--aia-written-text-color, var(--aia-color-text-default, #fff));
63
+ caret-color: var(
64
+ --aia-caret-color,
65
+ var(--aia-written-text-color, var(--aia-color-text-default, #fff))
66
+ );
64
67
  font-family: inherit;
65
68
  font-size: var(--aia-written-text-font-size, 19px);
66
69
  line-height: 38px;
@@ -81,8 +84,8 @@
81
84
  height: 36px;
82
85
  border-radius: 50%;
83
86
  border: none;
84
- background: var(--aia-color-text-default, #fff);
85
- color: var(--aia-color-bg-default, #000);
87
+ background: var(--aia-submit-bg, var(--aia-color-text-default, #fff));
88
+ color: var(--aia-submit-color, var(--aia-color-bg-default, #000));
86
89
  cursor: pointer;
87
90
  display: flex;
88
91
  align-items: center;
@@ -139,7 +142,7 @@
139
142
  .AIAutocomplete-module_shimmerHidden_45-Pf {
140
143
  color: transparent !important;
141
144
  }
142
- `,document.head.appendChild(o)}var k={container:"AIAutocomplete-module_container_KKjFU",inputWrapper:"AIAutocomplete-module_inputWrapper_FLq1b",editorArea:"AIAutocomplete-module_editorArea_7rBWq",sizerContent:"AIAutocomplete-module_sizerContent_DQgmV",sizerText:"AIAutocomplete-module_sizerText_iZIMK",sizerTextVisible:"AIAutocomplete-module_sizerTextVisible_HR-5h",textareaHidden:"AIAutocomplete-module_textareaHidden_UayJt",placeholderText:"AIAutocomplete-module_placeholderText_K3ayy",textarea:"AIAutocomplete-module_textarea_eyn6A",submitButton:"AIAutocomplete-module_submitButton_sl1Mi",shimmer:"AIAutocomplete-module_shimmer_13AnY",shimmerRevealed:"AIAutocomplete-module_shimmerRevealed_RR8dp",shimmerSweep:"AIAutocomplete-module_shimmerSweep_ARCon",textShimmer:"AIAutocomplete-module_textShimmer_eCLdq",shimmerHidden:"AIAutocomplete-module_shimmerHidden_45-Pf"};if(typeof document<"u"&&!document.getElementById("ac-style-2eef895d")){let o=document.createElement("style");o.id="ac-style-2eef895d",o.textContent=`.AIAutocompleteDropdown-module_dropdown_yz2KC {
145
+ `,document.head.appendChild(o)}var A={container:"AIAutocomplete-module_container_KKjFU",inputWrapper:"AIAutocomplete-module_inputWrapper_FLq1b",editorArea:"AIAutocomplete-module_editorArea_7rBWq",sizerContent:"AIAutocomplete-module_sizerContent_DQgmV",sizerText:"AIAutocomplete-module_sizerText_iZIMK",sizerTextVisible:"AIAutocomplete-module_sizerTextVisible_HR-5h",textareaHidden:"AIAutocomplete-module_textareaHidden_UayJt",placeholderText:"AIAutocomplete-module_placeholderText_K3ayy",textarea:"AIAutocomplete-module_textarea_eyn6A",submitButton:"AIAutocomplete-module_submitButton_sl1Mi",shimmer:"AIAutocomplete-module_shimmer_13AnY",shimmerRevealed:"AIAutocomplete-module_shimmerRevealed_RR8dp",shimmerSweep:"AIAutocomplete-module_shimmerSweep_ARCon",textShimmer:"AIAutocomplete-module_textShimmer_eCLdq",shimmerHidden:"AIAutocomplete-module_shimmerHidden_45-Pf"};if(typeof document<"u"&&!document.getElementById("ac-style-2eef895d")){let o=document.createElement("style");o.id="ac-style-2eef895d",o.textContent=`.AIAutocompleteDropdown-module_dropdown_yz2KC {
143
146
  position: absolute;
144
147
  left: 0;
145
148
  top: 100%;
@@ -175,7 +178,7 @@
175
178
  .AIAutocompleteDropdown-module_pillBar_pwTXe {
176
179
  padding: 27px 27px 0px 27px;
177
180
  }
178
- `,document.head.appendChild(o)}var Y={dropdown:"AIAutocompleteDropdown-module_dropdown_yz2KC",visible:"AIAutocompleteDropdown-module_visible_QCoXj",pillBar:"AIAutocompleteDropdown-module_pillBar_pwTXe"};if(typeof document<"u"&&!document.getElementById("ac-style-b745b4fb")){let o=document.createElement("style");o.id="ac-style-b745b4fb",o.textContent=`.PillList-module_list_qvLqO {
181
+ `,document.head.appendChild(o)}var J={dropdown:"AIAutocompleteDropdown-module_dropdown_yz2KC",visible:"AIAutocompleteDropdown-module_visible_QCoXj",pillBar:"AIAutocompleteDropdown-module_pillBar_pwTXe"};if(typeof document<"u"&&!document.getElementById("ac-style-b745b4fb")){let o=document.createElement("style");o.id="ac-style-b745b4fb",o.textContent=`.PillList-module_list_qvLqO {
179
182
  position: relative;
180
183
  z-index: 1;
181
184
  pointer-events: auto;
@@ -207,6 +210,18 @@
207
210
  cursor: pointer;
208
211
  white-space: nowrap;
209
212
  animation: PillList-module_fadeIn_Aezob 400ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
213
+ box-shadow:
214
+ hsla(0, 0%, 100%, 1) -3.2px -3.2px 3.2px -3.2px inset,
215
+ hsla(0, 0%, 100%, 1) 6.4px 6.4px 1.6px -8px inset,
216
+ var(--aia-dropdown-bg, transparent) -6.4px 6.4px 1.6px -8px inset,
217
+ var(--aia-dropdown-bg, transparent) 6.4px -6.4px 1.6px -8px inset,
218
+ hsla(0, 0%, 100%, 0.15) -1.6px 0px 0px -1.6px inset,
219
+ hsla(0, 0%, 100%, 0.15) 0px -1.6px 0px -1.6px inset,
220
+ hsla(0, 0%, 100%, 0.3) 0px 1.6px 0px 0px inset,
221
+ hsla(0, 0%, 100%, 0.3) 1.6px 0px 0px 0px inset,
222
+ inset 0 0 30px 5px hsla(0, 0%, 0%, 0.05),
223
+ hsla(0, 0%, 0%, 0.08) 0px 0px 30px 2px;
224
+ backdrop-filter: blur(30px);
210
225
  }
211
226
 
212
227
  .PillList-module_rounded_WvXy4 {
@@ -226,7 +241,7 @@
226
241
  opacity: 0;
227
242
  }
228
243
  }
229
- `,document.head.appendChild(o)}var Q={list:"PillList-module_list_qvLqO",pill:"PillList-module_pill_osSyz",fadeIn:"PillList-module_fadeIn_Aezob",rounded:"PillList-module_rounded_WvXy4",active:"PillList-module_active_Oll--"};var be=require("react/jsx-runtime");function Ge(o){return o===0?.4:o===1?.3:.15}function Z({pills:o,activePillIndex:e,onSelectPill:t,rounded:i}){return(0,be.jsx)("span",{className:Q.list,children:o.map((r,n)=>(0,be.jsx)("button",{type:"button",className:`${Q.pill} ${i?Q.rounded:""} ${n===e?Q.active:""}`,style:{opacity:Ge(n)},onClick:()=>t(n),children:r.text},`${r.type}-${r.text}`))})}var L=require("react");if(typeof document<"u"&&!document.getElementById("ac-style-d91f2b06")){let o=document.createElement("style");o.id="ac-style-d91f2b06",o.textContent=`.SuggestionGrid-module_scrollWrapper_MOqfw {
244
+ `,document.head.appendChild(o)}var U={list:"PillList-module_list_qvLqO",pill:"PillList-module_pill_osSyz",fadeIn:"PillList-module_fadeIn_Aezob",rounded:"PillList-module_rounded_WvXy4",active:"PillList-module_active_Oll--"};var ve=require("react/jsx-runtime");function Ge(o){return o===0?.4:o===1?.3:.15}function Y({pills:o,activePillIndex:e,onSelectPill:t,rounded:i}){return(0,ve.jsx)("span",{className:U.list,children:o.map((r,n)=>(0,ve.jsx)("button",{type:"button","data-aia-pill":"",className:`${U.pill} ${i?U.rounded:""} ${n===e?U.active:""}`,style:{opacity:Ge(n)},onClick:()=>t(n),children:r.text},`${r.type}-${r.text}`))})}var D=require("react");if(typeof document<"u"&&!document.getElementById("ac-style-d91f2b06")){let o=document.createElement("style");o.id="ac-style-d91f2b06",o.textContent=`.SuggestionGrid-module_scrollWrapper_MOqfw {
230
245
  position: relative;
231
246
  }
232
247
 
@@ -252,7 +267,7 @@
252
267
  display: grid;
253
268
  grid-template-columns: minmax(0, 1fr);
254
269
  max-width: 100cqi;
255
- padding: 13px 13px;
270
+ padding: 8px 8px;
256
271
  max-height: 200px;
257
272
  overflow-y: auto;
258
273
  scrollbar-width: thin;
@@ -261,7 +276,7 @@
261
276
 
262
277
  @container (min-width: 650px) {
263
278
  .SuggestionGrid-module_grid_jvaPb {
264
- grid-template-columns: repeat(2, minmax(0, 300px));
279
+ grid-template-columns: repeat(2, minmax(0, 250px));
265
280
  justify-content: start;
266
281
  }
267
282
  }
@@ -278,7 +293,7 @@
278
293
  background: var(--aia-scrollbar-thumb, rgba(0, 0, 0, 0.3));
279
294
  border-radius: 3px;
280
295
  }
281
- `,document.head.appendChild(o)}var ve={scrollWrapper:"SuggestionGrid-module_scrollWrapper_MOqfw",grid:"SuggestionGrid-module_grid_jvaPb"};var N=require("react");if(typeof document<"u"&&!document.getElementById("ac-style-f6bdc634")){let o=document.createElement("style");o.id="ac-style-f6bdc634",o.textContent=`.SuggestionItem-module_item_d4vpD {
296
+ `,document.head.appendChild(o)}var ye={scrollWrapper:"SuggestionGrid-module_scrollWrapper_MOqfw",grid:"SuggestionGrid-module_grid_jvaPb"};var N=require("react");if(typeof document<"u"&&!document.getElementById("ac-style-f6bdc634")){let o=document.createElement("style");o.id="ac-style-f6bdc634",o.textContent=`.SuggestionItem-module_item_d4vpD {
282
297
  position: relative;
283
298
  overflow: visible;
284
299
  display: flex;
@@ -334,7 +349,7 @@
334
349
  .SuggestionItem-module_pressed_98o-r {
335
350
  opacity: 0.8;
336
351
  color: var(--aia-color-text-default, #fff);
337
- background: rgba(255, 255, 255, 0.06);
352
+ background: rgba(var(--aia-streak-rgb, 255, 255, 255), 0.06);
338
353
  animation:
339
354
  SuggestionItem-module_glassFade_oyiSj 500ms ease forwards,
340
355
  SuggestionItem-module_tapDown_G3WGz 500ms ease forwards;
@@ -354,7 +369,7 @@
354
369
 
355
370
  @keyframes SuggestionItem-module_glassFade_oyiSj {
356
371
  0% {
357
- background: rgba(255, 255, 255, 0.1);
372
+ background: var(--aia-streak-glass-bg, rgba(255, 255, 255, 0.1));
358
373
  }
359
374
  100% {
360
375
  background: transparent;
@@ -383,11 +398,11 @@
383
398
  opacity: 0;
384
399
  background: radial-gradient(
385
400
  ellipse at center,
386
- rgba(255, 255, 255, 0.5) 0%,
387
- rgba(255, 255, 255, 0.2) 40%,
401
+ rgba(var(--aia-streak-rgb, 255, 255, 255), 0.5) 0%,
402
+ rgba(var(--aia-streak-rgb, 255, 255, 255), 0.2) 40%,
388
403
  transparent 70%
389
404
  );
390
- box-shadow: 0 0 12px 4px rgba(255, 255, 255, 0.2);
405
+ box-shadow: 0 0 12px 4px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.2);
391
406
  filter: blur(1px);
392
407
  border-radius: 50%;
393
408
  }
@@ -403,11 +418,11 @@
403
418
  opacity: 0;
404
419
  background: radial-gradient(
405
420
  ellipse at center,
406
- rgba(255, 255, 255, 0.5) 0%,
407
- rgba(255, 255, 255, 0.2) 40%,
421
+ rgba(var(--aia-streak-rgb, 255, 255, 255), 0.5) 0%,
422
+ rgba(var(--aia-streak-rgb, 255, 255, 255), 0.2) 40%,
408
423
  transparent 70%
409
424
  );
410
- box-shadow: 0 0 12px 4px rgba(255, 255, 255, 0.2);
425
+ box-shadow: 0 0 12px 4px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.2);
411
426
  filter: blur(1px);
412
427
  border-radius: 50%;
413
428
  }
@@ -434,11 +449,11 @@
434
449
  opacity: 0;
435
450
  background: radial-gradient(
436
451
  ellipse at center,
437
- rgba(255, 255, 255, 0.4) 0%,
438
- rgba(255, 255, 255, 0.15) 40%,
452
+ rgba(var(--aia-streak-rgb, 255, 255, 255), 0.4) 0%,
453
+ rgba(var(--aia-streak-rgb, 255, 255, 255), 0.15) 40%,
439
454
  transparent 70%
440
455
  );
441
- box-shadow: 0 0 12px 4px rgba(255, 255, 255, 0.15);
456
+ box-shadow: 0 0 12px 4px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.15);
442
457
  filter: blur(1px);
443
458
  border-radius: 50%;
444
459
  }
@@ -454,11 +469,11 @@
454
469
  opacity: 0;
455
470
  background: radial-gradient(
456
471
  ellipse at center,
457
- rgba(255, 255, 255, 0.4) 0%,
458
- rgba(255, 255, 255, 0.15) 40%,
472
+ rgba(var(--aia-streak-rgb, 255, 255, 255), 0.4) 0%,
473
+ rgba(var(--aia-streak-rgb, 255, 255, 255), 0.15) 40%,
459
474
  transparent 70%
460
475
  );
461
- box-shadow: 0 0 12px 4px rgba(255, 255, 255, 0.15);
476
+ box-shadow: 0 0 12px 4px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.15);
462
477
  filter: blur(1px);
463
478
  border-radius: 50%;
464
479
  }
@@ -486,27 +501,27 @@
486
501
  height: 4px;
487
502
  opacity: 0;
488
503
  filter: blur(1px);
489
- box-shadow: 0 0 8px 3px rgba(255, 255, 255, 0.3);
504
+ box-shadow: 0 0 8px 3px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.3);
490
505
  }
491
506
  15% {
492
507
  height: 4px;
493
508
  opacity: 1;
494
509
  filter: blur(1px);
495
- box-shadow: 0 0 10px 4px rgba(255, 255, 255, 0.3);
510
+ box-shadow: 0 0 10px 4px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.3);
496
511
  }
497
512
  80% {
498
513
  width: 50%;
499
514
  height: 10px;
500
515
  opacity: 0.8;
501
516
  filter: blur(3px);
502
- box-shadow: 0 0 16px 6px rgba(255, 255, 255, 0.1);
517
+ box-shadow: 0 0 16px 6px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.1);
503
518
  }
504
519
  100% {
505
520
  width: 50%;
506
521
  height: 12px;
507
522
  opacity: 0;
508
523
  filter: blur(5px);
509
- box-shadow: 0 0 20px 8px rgba(255, 255, 255, 0.03);
524
+ box-shadow: 0 0 20px 8px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.03);
510
525
  }
511
526
  }
512
527
 
@@ -517,27 +532,27 @@
517
532
  height: 4px;
518
533
  opacity: 0;
519
534
  filter: blur(1px);
520
- box-shadow: 0 0 8px 3px rgba(255, 255, 255, 0.3);
535
+ box-shadow: 0 0 8px 3px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.3);
521
536
  }
522
537
  15% {
523
538
  height: 4px;
524
539
  opacity: 1;
525
540
  filter: blur(1px);
526
- box-shadow: 0 0 10px 4px rgba(255, 255, 255, 0.3);
541
+ box-shadow: 0 0 10px 4px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.3);
527
542
  }
528
543
  80% {
529
544
  width: 50%;
530
545
  height: 10px;
531
546
  opacity: 0.8;
532
547
  filter: blur(3px);
533
- box-shadow: 0 0 16px 6px rgba(255, 255, 255, 0.1);
548
+ box-shadow: 0 0 16px 6px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.1);
534
549
  }
535
550
  100% {
536
551
  width: 50%;
537
552
  height: 12px;
538
553
  opacity: 0;
539
554
  filter: blur(5px);
540
- box-shadow: 0 0 20px 8px rgba(255, 255, 255, 0.03);
555
+ box-shadow: 0 0 20px 8px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.03);
541
556
  }
542
557
  }
543
558
 
@@ -548,21 +563,21 @@
548
563
  width: 6px;
549
564
  opacity: 0.9;
550
565
  filter: blur(1.8px);
551
- box-shadow: 0 0 12px 5px rgba(255, 255, 255, 0.25);
566
+ box-shadow: 0 0 12px 5px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.25);
552
567
  }
553
568
  75% {
554
569
  height: 100%;
555
570
  width: 10px;
556
571
  opacity: 0.4;
557
572
  filter: blur(3px);
558
- box-shadow: 0 0 18px 8px rgba(255, 255, 255, 0.06);
573
+ box-shadow: 0 0 18px 8px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.06);
559
574
  }
560
575
  100% {
561
576
  height: 100%;
562
577
  width: 14px;
563
578
  opacity: 0;
564
579
  filter: blur(5px);
565
- box-shadow: 0 0 24px 10px rgba(255, 255, 255, 0.02);
580
+ box-shadow: 0 0 24px 10px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.02);
566
581
  }
567
582
  }
568
583
 
@@ -572,22 +587,101 @@
572
587
  width: 6px;
573
588
  opacity: 0.9;
574
589
  filter: blur(1.8px);
575
- box-shadow: 0 0 12px 5px rgba(255, 255, 255, 0.25);
590
+ box-shadow: 0 0 12px 5px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.25);
576
591
  }
577
592
  75% {
578
593
  height: 100%;
579
594
  width: 10px;
580
595
  opacity: 0.4;
581
596
  filter: blur(3px);
582
- box-shadow: 0 0 18px 8px rgba(255, 255, 255, 0.06);
597
+ box-shadow: 0 0 18px 8px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.06);
583
598
  }
584
599
  100% {
585
600
  height: 100%;
586
601
  width: 14px;
587
602
  opacity: 0;
588
603
  filter: blur(5px);
589
- box-shadow: 0 0 24px 10px rgba(255, 255, 255, 0.02);
604
+ box-shadow: 0 0 24px 10px rgba(var(--aia-streak-rgb, 255, 255, 255), 0.02);
590
605
  }
591
606
  }
592
- `,document.head.appendChild(o)}var O={item:"SuggestionItem-module_item_d4vpD",fadeIn:"SuggestionItem-module_fadeIn_I8u35",content:"SuggestionItem-module_content_T-Qba",tappable:"SuggestionItem-module_tappable_70KcX",nonTappable:"SuggestionItem-module_nonTappable_xSZM-",highlighted:"SuggestionItem-module_highlighted_Hb0SU",tag:"SuggestionItem-module_tag_e3Fwe",pressed:"SuggestionItem-module_pressed_98o-r",glassFade:"SuggestionItem-module_glassFade_oyiSj",tapDown:"SuggestionItem-module_tapDown_G3WGz",streaks:"SuggestionItem-module_streaks_d9PEB",streaksVert:"SuggestionItem-module_streaksVert_ERlV1",streakHorizRight:"SuggestionItem-module_streakHorizRight_aboGz",streakHorizLeft:"SuggestionItem-module_streakHorizLeft_BreWJ",streakVertUp:"SuggestionItem-module_streakVertUp_to1GD",streakVertDown:"SuggestionItem-module_streakVertDown_OrcLh"};var H=require("react/jsx-runtime");function _e({option:o,isHighlighted:e,onSelect:t,onHighlight:i,id:r}){let[n,a]=(0,N.useState)(!1),d=(0,N.useRef)(void 0);(0,N.useEffect)(()=>()=>clearTimeout(d.current),[]);let s=()=>{!o.is_tappable||n||(a(!0),t(o),clearTimeout(d.current),d.current=setTimeout(()=>a(!1),400))},l=[O.item,e?O.highlighted:"",o.is_tappable?O.tappable:O.nonTappable,n?O.pressed:""].filter(Boolean).join(" ");return(0,H.jsxs)("div",{id:r,role:"option","aria-selected":e,className:l,tabIndex:o.is_tappable?0:-1,onClick:s,onKeyDown:p=>{o.is_tappable&&(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),s())},onMouseEnter:i,children:[(0,H.jsx)("div",{className:O.streaks}),(0,H.jsx)("div",{className:O.streaksVert}),(0,H.jsxs)("span",{className:O.content,children:[o.icon?`${o.icon} ${o.text}`:o.text,o.tag&&(0,H.jsx)("span",{className:O.tag,children:o.tag})]})]})}var ee=require("react/jsx-runtime");function Pe({options:o,activeIndex:e,onSelect:t,onHighlight:i,listboxId:r}){let n=(0,L.useRef)(null),[a,d]=(0,L.useState)(!1);return(0,L.useEffect)(()=>{let s=n.current;if(!s)return;let l=()=>{d(s.scrollHeight-s.scrollTop-s.clientHeight>1)};s.addEventListener("scroll",l,{passive:!0});let p=new ResizeObserver(l);return p.observe(s),()=>{s.removeEventListener("scroll",l),p.disconnect()}},[]),(0,L.useLayoutEffect)(()=>{let s=n.current;s&&d(s.scrollHeight-s.scrollTop-s.clientHeight>1)},[o]),(0,ee.jsx)("div",{className:ve.scrollWrapper,"data-fade":a?"":void 0,children:(0,ee.jsx)("div",{ref:n,className:ve.grid,children:o.map((s,l)=>(0,ee.jsx)(_e,{option:s,isHighlighted:l===e,onSelect:t,onHighlight:()=>i(l),id:`${r}-option-${l}`},s.text))})})}var K=require("react/jsx-runtime");function te({suggestions:o,activeIndex:e,onSelect:t,onHighlight:i,isOpen:r,id:n,className:a,pills:d,onPillClick:s,showPills:l=!0}){let c=o[0]?.options??[],u=l&&d&&d.length>0&&s,m=r&&c.length>0||r&&u;return(0,K.jsxs)("div",{id:n,role:"listbox","data-aia-dropdown":"",className:`${Y.dropdown} ${m?Y.visible:""} ${a??""}`,onMouseDown:S=>S.preventDefault(),children:[u&&(0,K.jsx)("div",{className:Y.pillBar,"data-aia-pillbar":"",children:(0,K.jsx)(Z,{pills:d,activePillIndex:0,onSelectPill:s,rounded:!0})}),c.length>0&&(0,K.jsx)(Pe,{options:c,activeIndex:e,onSelect:t,onHighlight:i,listboxId:n})]})}var b=require("react");function W(o,e,t){let i=o.slice(e);if(t||e===0||o[e-1]===" ")return i;let r=i.indexOf(" ");return r===-1?"":i.slice(r+1)}function Ce(o,e){let t=o.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let i=t.split(" "),r=e.toLowerCase();for(let n=0;n<i.length;n++){let a=i.slice(n).join(" ");if(r.startsWith(a.toLowerCase())){let d=t.length-a.length;return o.length-d}}return 0}function oe(o,e){if(!o)return[];let t=e.trimStart();if(!t)return o;let i=t.toLowerCase();return o.filter(r=>!r.is_tappable||r.text.toLowerCase().includes(i))}function ye(o,e){if(!o)return null;let t=e.trim();if(!t)return null;let i=t.toLowerCase();return o.find(r=>r.is_tappable&&r.text.toLowerCase()===i)??null}var $=class{constructor(e,t="auto"){this.container=e;this.mode=t;this.mediaQuery=null;this.onSystemChange=e=>{this.container.dataset.mode=e.matches?"dark":"light"};this.apply()}setMode(e){this.detachListener(),this.mode=e,this.apply()}destroy(){this.detachListener()}apply(){this.mode==="auto"?(this.mediaQuery??(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)")),this.mediaQuery.addEventListener("change",this.onSystemChange),this.container.dataset.mode=this.mediaQuery.matches?"dark":"light"):this.container.dataset.mode=this.mode}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function Ae(o,e){let t=[],i=0;for(let n of e){let a=o.indexOf(n.text,i);a!==-1&&(a>i&&t.push({type:"text",value:o.slice(i,a)}),t.push({type:"completed",value:n.text,param:n}),i=a+n.text.length)}let r=o.slice(i);return r&&t.push({type:"text",value:r}),t}function ke(o,e){let t=[],i=[],r=0;for(let n of e){let a=o.indexOf(n.text,r);a===-1?i.push(n):(t.push(n),r=a+n.text.length)}return{valid:t,invalid:i}}var ie=class{constructor(e){this.config=e;this.current=null;this.expiresAt=null;this.inFlightRefresh=null;e.accessToken&&(this.current=e.accessToken)}async getToken(e=!1){if(!e&&this.current&&!this.isExpired())return this.current;if(!e&&this.inFlightRefresh)return this.inFlightRefresh;this.inFlightRefresh=this.refresh();try{return await this.inFlightRefresh}finally{this.inFlightRefresh=null}}async refresh(){let e=await this.config.getAccessToken();return this.current=e.accessToken,this.expiresAt=e.expiresAt??null,this.current}isExpired(){return this.expiresAt==null?!1:Date.now()>=this.expiresAt-3e4}};var Xe="0.1.24",Te=!1;function Je(){return crypto.randomUUID()}function Ye(o,e){return{placeholder:o.placeholder,type:o.type,...e&&{text:o.text},kind:o.kind}}function Ee(o){return o?.type==="accessToken"}function Ze(o){if(!(!o||Ee(o)))return o}var Oe=new WeakMap;function et(o){let e=Oe.get(o.getAccessToken);return e||(e=new ie(o),Oe.set(o.getAccessToken,e)),e}function tt(o,e,t){let i=e.find(n=>n.type==="contact"&&n.metadata?.contact_account_count)?.metadata?.contact_account_count,r=typeof i=="number"?i:void 0;return{data:{raw_query:o,completed_params:e.map(n=>Ye(n,t)),...r!=null&&{contact_account_count:r}},meta:{request_id:Je(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:Xe}}}function ot(o){return{"Content-Type":"application/json",...o?.appIdentifier&&{"X-App-Identifier":o.appIdentifier},...o?.headers}}async function De(o,e,t,i,r){return fetch(o,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:i,signal:r})}async function Le(o,e,t){let i=t?.apiConfig,r=!t?.maskCompletedText,n=tt(o,e,r),a=ot(i),d=i?.endpoint??"/ac/suggest",s=JSON.stringify(n);if(Ee(i)){let u=et(i),h=await u.getToken(),m=await De(d,a,h,s,t?.signal);if(m.status===401){let S=await u.getToken(!0);m=await De(d,a,S,s,t?.signal)}if(!m.ok)throw new Error(`API error: ${m.status} ${m.statusText}`);return m.json()}let l=Ze(i),p=l?.apiKey??"";if(!p&&!Te&&(Te=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),p){let u=l?.authScheme??"Bearer";a.Authorization=u==="Basic"?`Basic ${btoa(p)}`:`Bearer ${p}`}let c=await fetch(d,{method:"POST",headers:a,body:s,signal:t?.signal});if(!c.ok)throw new Error(`API error: ${c.status} ${c.statusText}`);return c.json()}function R(o,e){let t=o,i={},r=[];for(let n of e){let a=(i[n.type]??0)+1;i[n.type]=a;let s=`{{${n.type.toUpperCase().replace(/\s+/g,"_")}_${a}}}`,l=t.indexOf(n.text);l!==-1&&(t=t.slice(0,l)+s+t.slice(l+n.text.length)),r.push({...n,placeholder:s})}return{rawQuery:t,completedParams:r}}function Re(o,e){return e?o.map(t=>{let i=e[t.type];if(!i)return t;let r=i("");if(r.length===0)return t;let n=new Set(r.map(d=>d.text)),a=(t.options??[]).filter(d=>!n.has(d.text));return{...t,options:[...r,...a]}}):o}var it=100,nt=300,rt=2,ne=class{constructor(e,t,i,r,n){this.store=e;this.getApiConfig=t;this.getOptionOverrides=i;this.getMaskCompletedText=r;this.getOnError=n;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,t=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(i=>{(i.text!==e||i.completedParams!==t)&&(e=i.text,t=i.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let i=new AbortController;this.abortController=i;let r=++this.fetchVersion,n=this.store.get(),a=n.text.length;n.suggestions.some(s=>s.type!=="placeholder")||this.store.set({isLoading:!0}),this.store.set({error:null});try{let s=await Le(e,t,{maskCompletedText:this.getMaskCompletedText(),signal:i.signal,apiConfig:this.getApiConfig()});if(r!==this.fetchVersion)return;let l=Re(s.data.suggestions??[],this.getOptionOverrides()),p=s.data.input??[],c=p[p.length-1],u=this.store.get().text,h,m;if(c?.state==="in_progress"){m=!0;let C=u.toLowerCase().lastIndexOf(c.text.toLowerCase());h=C!==-1?C:a}else m=!1,h=a;let x=l.filter(C=>C.type!=="placeholder")[0],v=null;if(x){let C=W(u,h,m),g=ye(x.options,C);g&&(v={id:crypto.randomUUID(),placeholder:"",type:x.type,text:g.text,kind:g.kind,suggestionType:x.type,suggestionPlaceholder:x.text,options:x.options??[],metadata:g.metadata},l=l.filter(I=>I!==x))}this.store.set(C=>({suggestions:l,isLoading:!1,isReady:s.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:h,filterInProgress:m,...v?{completedParams:[...C.completedParams,v]}:{}}))}catch(s){if(r===this.fetchVersion){let l=s instanceof Error?s:new Error(String(s));this.store.set({error:l,isLoading:!1}),this.getOnError()?.(l)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=i=>{let r=this.store.get();if(!r.text&&r.completedParams.length===0)return this.doFetch("",[]),!0;let n=W(r.text,r.filterBase,r.filterInProgress),d=r.suggestions.filter(x=>x.type!=="placeholder")[0],l=(d?oe(d.options,n):[]).filter(x=>x.is_tappable),p=d?ye(d.options,n)!==null:!1,c=n.trim().length>0;if(l.length>0&&!p&&c)return!1;if(r.completedParams.length===0&&r.text.length>0){let x=r.suggestions.filter(v=>v.type==="placeholder").map(v=>v.text).join(" ");if(x.length>0&&x.toLowerCase().startsWith(r.text.toLowerCase()))return!1}let{rawQuery:u,completedParams:h}=R(r.text,r.completedParams),m=u.length<r.lastRawQuery.length,S=Math.abs(u.length-r.lastRawQuery.length);return m||S>=i?(this.doFetch(u,h),!0):!1};this.debounceTimer=setTimeout(()=>{t(rt)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},it),this.slowDebounceTimer=setTimeout(()=>t(1),nt)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var re=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{columns:i,listboxId:r,getOnSubmit:n}=this.ctx,a=n(),d=this.getTappableIndices();switch(e.key){case"ArrowDown":{let s=e.target;if(!(s.selectionStart!=null&&s.selectionStart===s.value.length)&&t.activeDropdownIndex<0)break;if(e.preventDefault(),!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:d[0]??0});break}if(d.length===0)return;let p=d.indexOf(t.activeDropdownIndex),c=p<d.length-1?p+1:0;this.store.set({activeDropdownIndex:d[c]});break}case"ArrowUp":{if(d.length===0||t.activeDropdownIndex<0)break;if(e.preventDefault(),t.activeDropdownIndex<i){this.store.set({activeDropdownIndex:-1});break}let s=d.indexOf(t.activeDropdownIndex),l=s>0?s-1:d.length-1;this.store.set({activeDropdownIndex:d[l]});break}case"ArrowRight":{if(t.activeDropdownIndex<0){let l=e.target;l.selectionStart!=null&&l.selectionStart===l.value.length&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}if(t.activeDropdownIndex%i<i-1){let l=t.activeDropdownIndex+1;l<t.filteredOptions.length&&t.filteredOptions[l]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:l}))}break}case"ArrowLeft":{if(t.activeDropdownIndex<0)break;if(t.activeDropdownIndex%i>0){let s=t.activeDropdownIndex-1;s>=0&&t.filteredOptions[s]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:s}))}break}case"Enter":{if(e.preventDefault(),t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,r);else if(a){let{rawQuery:s,completedParams:l}=R(t.text,t.completedParams);a({query:t.text.trim(),raw_query:s,completed_params:l})}break}case"Tab":{if(t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,r);else if(t.isDropdownOpen){let s=t.filteredOptions.findIndex(l=>l.is_tappable);s>=0&&(e.preventDefault(),this.clickOrSelect(s,t.filteredOptions,r))}else if(!t.text&&t.placeholderText){e.preventDefault();let s=t.suggestions.find(l=>l.type==="placeholder");s?this.store.set(l=>({text:t.placeholderText,filterBase:t.placeholderText.length,completedParams:[...l.completedParams,{id:crypto.randomUUID(),placeholder:"",type:s.type,text:t.placeholderText,kind:null,suggestionType:s.type,suggestionPlaceholder:s.text,options:s.options??[]}],suggestions:l.suggestions.filter(p=>p!==s)})):this.store.set({text:t.placeholderText,filterBase:t.placeholderText.length})}break}case"Escape":this.store.set({activeDropdownIndex:-1});break}}getTappableIndices(){let e=this.store.get(),{columns:t}=this.ctx,i=e.filteredOptions.map((n,a)=>n.is_tappable?a:-1).filter(n=>n!==-1),r=Array.from({length:t},()=>[]);for(let n of i)r[n%t].push(n);return r.flat()}clickOrSelect(e,t,i){let r=document.getElementById(`${i}-option-${e}`);r?r.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),i=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],n=i.filter((d,s)=>s!==e),a=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...a,r,...n],pillTapped:!0,activeDropdownIndex:-1})}};var se=class{constructor(e){this.store=e}setActivePill(e){let t=this.store.get(),i=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],n=i.filter((d,s)=>s!==e),a=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...a,r,...n],pillTapped:!0,activeDropdownIndex:-1})}removeLastParam(){let e=this.store.get();if(e.completedParams.length===0)return;let t=e.completedParams[e.completedParams.length-1],i={type:t.suggestionType,text:t.suggestionPlaceholder,required:!0,options:t.options};this.store.set(r=>({completedParams:r.completedParams.slice(0,-1),suggestions:[i,...r.suggestions],activeDropdownIndex:-1}))}};function st(o){return o===0?.4:o===1?.3:.15}function ae(o,e,t,i,r=!1){let n=o.querySelector(".magicx-aia-pill-list");n||(n=document.createElement("span"),n.className="magicx-aia-pill-list",o.appendChild(n));let a=new Map;for(let s of n.querySelectorAll(".magicx-aia-pill"))a.set(s.dataset.pillKey??"",s);let d=new Set;for(let s=0;s<e.length;s++){let l=e[s],p=`${l.type}-${l.text}`;d.add(p);let c=a.get(p);c||(c=document.createElement("button"),c.type="button",c.dataset.pillKey=p,c.textContent=l.text),c.className=`magicx-aia-pill${r?" magicx-aia-pill--rounded":""}${s===t?" magicx-aia-pill--active":""}`,c.style.opacity=String(st(s)),c.onclick=()=>i(s),n.children[s]!==c&&n.insertBefore(c,n.children[s]??null)}for(let[s,l]of a)d.has(s)||l.remove()}function le(o){let e=document.createElement("div");return e.id=o,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function de(o,e){let{filteredOptions:t,activeIndex:i,isOpen:r,pills:n,showPills:a,onSelect:d,onHighlight:s,onPillClick:l}=e,p=a&&n.length>0;r&&t.length>0||r&&p?o.classList.add("magicx-aia-dropdown--visible"):o.classList.remove("magicx-aia-dropdown--visible");let h=o.querySelector(".magicx-aia-pill-bar");p?(h||(h=document.createElement("div"),h.className="magicx-aia-pill-bar",o.insertBefore(h,o.firstChild)),ae(h,n,0,l,!0)):h&&h.remove();let m=o.querySelector(".magicx-aia-grid");t.length>0?(m||(m=document.createElement("div"),m.className="magicx-aia-grid",o.appendChild(m)),at(m,t,i,d,s,e.listboxId)):m&&(m.innerHTML="")}function at(o,e,t,i,r,n){let a=e.map(l=>l.text).join("\0"),d=o.dataset.optionsKey??"",s=a!==d;if(o.dataset.optionsKey=a,s){let l=document.createDocumentFragment();for(let p=0;p<e.length;p++){let c=e[p],u=lt(c,p,t,i,r,n);l.appendChild(u)}o.innerHTML="",o.appendChild(l)}else{let l=o.querySelectorAll(".magicx-aia-option");for(let p=0;p<l.length;p++){let c=l[p],u=p===t;c.setAttribute("aria-selected",String(u)),u?c.classList.add("magicx-aia-option--highlighted"):c.classList.remove("magicx-aia-option--highlighted")}}}function lt(o,e,t,i,r,n){let a=document.createElement("div");a.id=`${n}-option-${e}`,a.setAttribute("role","option"),a.setAttribute("aria-selected",String(e===t)),a.tabIndex=o.is_tappable?0:-1;let d=["magicx-aia-option"];e===t&&d.push("magicx-aia-option--highlighted"),o.is_tappable?d.push("magicx-aia-option--tappable"):d.push("magicx-aia-option--non-tappable"),a.className=d.join(" ");let s=document.createElement("div");s.className="magicx-aia-streaks",a.appendChild(s);let l=document.createElement("div");l.className="magicx-aia-streaks-vert",a.appendChild(l);let p=document.createElement("span");if(p.className="magicx-aia-option-content",p.textContent=o.icon?`${o.icon} ${o.text}`:o.text,o.tag){let c=document.createElement("span");c.className="magicx-aia-option-tag",c.textContent=o.tag,p.appendChild(c)}return a.appendChild(p),o.is_tappable&&a.addEventListener("click",()=>{a.classList.add("magicx-aia-option--pressed"),i(o),setTimeout(()=>a.classList.remove("magicx-aia-option--pressed"),400)}),a.addEventListener("mouseenter",()=>r(e)),a}function Me(o,e){let t=le(e.listboxId);return o.appendChild(t),{dropdown:t}}function we(o,e,t){de(o.dropdown,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:!0,onSelect:t.selectOption,onHighlight:i=>t.store.set({activeDropdownIndex:i}),onPillClick:t.setActivePill})}function He(o,e,t,i,r){let n=o.querySelector(".magicx-aia-sizer-text"),a=o.querySelector(".magicx-aia-placeholder");if(i&&r){n&&(n.style.display="none"),a||(a=document.createElement("span"),a.className="magicx-aia-placeholder",o.insertBefore(a,o.firstChild)),a.style.display="",a.textContent=`${r} `,o.dataset.segmentKey="";return}a&&(a.style.display="none"),n||(n=document.createElement("span"),n.className="magicx-aia-sizer-text",o.insertBefore(n,o.firstChild)),n.style.display="",n.className=`magicx-aia-sizer-text${t?" magicx-aia-sizer-text--visible":""}`;let d=e.map(p=>`${p.type}:${p.value}`).join("\0"),s=o.dataset.segmentKey??"",l=o.dataset.newParamId??"";if(!(d===s&&(t??"")===l)){o.dataset.segmentKey=d,o.dataset.newParamId=t??"",n.innerHTML="";for(let p of e){let c=document.createElement("span");p.type==="completed"&&(p.param.id===t?c.className="magicx-aia-shimmer-revealed magicx-aia-shimmer-sweep":c.className="magicx-aia-segment magicx-aia-segment--completed"),c.textContent=p.value,n.appendChild(c)}e.length===0&&(n.textContent="\xA0")}}var dt='<svg width="18" height="18" viewBox="0 0 18 18" fill="none" role="img" aria-label="Submit"><path d="M9 14V4M9 4L4 9M9 4L14 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function ze(o,e){let{listboxId:t}=e,i=le(t);o.appendChild(i);let r=document.createElement("div");r.className="magicx-aia-input-wrapper",o.appendChild(r);let n=document.createElement("div");n.className="magicx-aia-editor",r.appendChild(n);let a=document.createElement("div");a.className="magicx-aia-sizer",a.setAttribute("aria-hidden","true"),n.appendChild(a);let d=document.createElement("span");a.appendChild(document.createTextNode(" ")),a.appendChild(d);let s=document.createElement("textarea");s.className="magicx-aia-textarea",s.rows=1,s.setAttribute("role","combobox"),s.setAttribute("aria-autocomplete","list"),s.setAttribute("aria-controls",t),n.appendChild(s);let l=document.createElement("button");return l.type="button",l.className="magicx-aia-submit",l.setAttribute("aria-label","Submit"),l.innerHTML=dt,r.appendChild(l),r.addEventListener("click",()=>s.focus()),s.addEventListener("input",()=>{let p=s.value,u=p.length>0&&p[0]!==p[0].toUpperCase()?p[0].toUpperCase()+p.slice(1):p;e.handleChange(u)}),s.addEventListener("keydown",p=>e.handleKeyDown(p)),l.addEventListener("click",p=>{p.stopPropagation();let c=e.store.get();if(!(!!c.text||c.completedParams.length>0)||!e.onSubmit)return;let{rawQuery:h,completedParams:m}=R(c.text,c.completedParams);e.onSubmit({query:c.text.trim(),raw_query:h,completed_params:m})}),s.focus(),{textarea:s,dropdown:i,sizer:a,submitButton:l,inlinePillContainer:d}}function Se(o,e,t){let{textarea:i,dropdown:r,sizer:n,submitButton:a,inlinePillContainer:d}=o,{pillPlacement:s,setActivePill:l,selectOption:p,store:c}=t;i.value!==e.text&&(i.value=e.text),e.placeholderText?i.placeholder=e.placeholderText:i.removeAttribute("placeholder"),i.setAttribute("aria-expanded",String(e.isDropdownOpen));let u=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";u?i.setAttribute("aria-activedescendant",u):i.removeAttribute("aria-activedescendant"),e.newParamId?i.classList.add("magicx-aia-textarea--hidden"):i.classList.remove("magicx-aia-textarea--hidden");let h=!!e.text||e.completedParams.length>0;a.disabled=!h,He(n,e.segments,e.newParamId,!e.text,e.placeholderText),s==="inline"?ae(d,e.actionableSuggestions,0,l):d.innerHTML="",de(r,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:s==="dropdown",onSelect:p,onHighlight:m=>c.set({activeDropdownIndex:m}),onPillClick:l})}function Be(o){let e=o,t=new Set;return{get:()=>e,set:i=>{let r=typeof i=="function"?i(e):i,n={...e,...r},a=e;e=n;for(let d of t)d(n,a)},subscribe:i=>(t.add(i),()=>{t.delete(i)})}}var Ie=!1;function Ne(){if(Ie||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){Ie=!0;return}Ie=!0;let o=document.createElement("style");o.setAttribute("data-magicx-aia",""),o.textContent=pt,document.head.appendChild(o)}var pt="";var ct=0;function ut(){return`:ac-${++ct}:`}function Ke(){return{text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],placeholderText:"",isDropdownOpen:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:""}}var pe=class{constructor(e,t={}){this.store=Be(Ke());this._listboxId=ut();this.modeController=null;this.unsubscribers=[];this.derivedInProgress=!1;this.domRefs=null;this.dropdownRefs=null;this.externalListeners=new Set;this.container=e,this.opts=t,this.renderMode=t.renderMode??"full",t.value!==void 0&&this.store.set({text:t.value}),t.completedParams!==void 0&&this.store.set({completedParams:t.completedParams}),this.pillsController=new se(this.store),this.fetchController=new ne(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.opts.onError),this.keyboardController=new re(this.store,{columns:t.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.opts.onSubmit,selectOption:i=>this.selectOption(i)}),this.unsubscribers.push(this.store.subscribe((i,r)=>{this.recomputeDerived(i,r)})),this.unsubscribers.push(this.store.subscribe((i,r)=>{i.text!==r.text&&this.opts.onChange?.(i.text),i.completedParams!==r.completedParams&&this.opts.onParamsChange?.(i.completedParams),this.opts.onStateChange?.(i)})),this.renderMode!=="headless"&&(Ne(),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.fetchController.start()}focus(){this.domRefs?.textarea.focus()}reset(){this.store.set({...Ke()}),this.fetchController.doFetch("",[])}destroy(){this.fetchController.dispose(),this.modeController?.destroy(),this.newParamTimer&&clearTimeout(this.newParamTimer),this.suggestionRemovalTimer&&clearTimeout(this.suggestionRemovalTimer),this.externalListeners.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}setValue(e){this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e)}removeLastParam(){this.pillsController.removeLastParam()}clearNewParamId(){this.store.set({newParamId:null})}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}handleTextChange(e){this.handleChange(e)}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}subscribe(e){return this.externalListeners.add(e),()=>{this.externalListeners.delete(e)}}getState(){return this.store.get()}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,t){switch(e){case"submit":return this.opts.onSubmit=t,()=>{this.opts.onSubmit=void 0};case"error":return this.opts.onError=t,()=>{this.opts.onError=void 0};case"change":return this.opts.onChange=t,()=>{this.opts.onChange=void 0};case"paramsChange":return this.opts.onParamsChange=t,()=>{this.opts.onParamsChange=void 0};case"stateChange":return this.opts.onStateChange=t,()=>{this.opts.onStateChange=void 0};default:return()=>{}}}update(e){Object.assign(this.opts,e),e.mode!==void 0&&this.modeController?.setMode(e.mode),e.optionsPosition!==void 0&&(this.container.dataset.optionsPosition=e.optionsPosition),e.animations!==void 0&&(this.container.dataset.animations=e.animations?"on":"off"),e.pillPlacement!==void 0&&(this.container.dataset.pillPlacement=e.pillPlacement,this.store.set({})),e.dropdownTrigger!==void 0&&this.store.set({}),e.value!==void 0&&this.store.set({text:e.value}),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let t=this.store.get(),i=t.actionableSuggestions[0];if(!i)return;let r=t.filterBase,n=t.text.slice(0,r),a=n.length===0&&t.text.length===0,d=n.length===0&&t.text.length>0&&t.placeholderText.length>0&&t.placeholderText.toLowerCase().startsWith(t.text.toLowerCase());(a||d)&&t.placeholderText&&(n=`${t.placeholderText} `);let s=Ce(n,e.text);s>0&&(n=n.slice(0,n.length-s));let l=n.length>0&&n[n.length-1]!==" ",p=`${n}${l?" ":""}${e.text} `,c=(a||d)&&p.length>0?p[0].toUpperCase()+p.slice(1):p,u=c.toLowerCase().lastIndexOf(e.text.toLowerCase()),h=u>=0?c.slice(u,u+e.text.length):e.text,m={id:crypto.randomUUID(),placeholder:"",type:i.type,text:h,kind:e.kind,suggestionType:i.type,suggestionPlaceholder:i.text,options:i.options??[],metadata:e.metadata},S=t.actionableSuggestions.length-1;this.store.set(x=>({text:c,filterBase:c.length,completedParams:[...x.completedParams,m],newParamId:m.id,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:S>0})),this.suggestionRemovalTimer=window.setTimeout(()=>{this.store.set(x=>({suggestions:x.suggestions.filter(v=>v!==i)}))},400)}recomputeDerived(e,t){if(this.derivedInProgress)return;this.derivedInProgress=!0;let i=Ae(e.text,e.completedParams),r=e.suggestions.filter(v=>v.type!=="placeholder"),n=r[0],a=n?this.opts.optionOverrides?.[n.type]:void 0,d=Math.min(e.filterBase,e.text.length),l=e.lastRawQuery!==""||d>0?W(e.text,d,e.filterInProgress):"",p=n?a?a(l.trim()):n.options??[]:[],c=oe(p,l),u=e.suggestions.filter(v=>v.type==="placeholder").map(v=>v.text).join(" ")||this.opts.placeholder||"",h=u.length>0,m=this.opts.dropdownTrigger??"auto",S=!1;m==="auto"?S=!e.isLoading&&c.length>0&&(!!e.text||e.pillTapped||!h):m==="manual"&&(S=!e.isLoading&&c.length>0&&e.pillTapped),this.store.set({segments:i,actionableSuggestions:r,filteredOptions:c,placeholderText:u,isDropdownOpen:S}),this.derivedInProgress=!1;let x=this.store.get();for(let v of this.externalListeners)v(x)}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"inline",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new $(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,t={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"inline"},get onSubmit(){return e.opts.onSubmit},selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i)};this.domRefs=ze(this.container,t),this.subscribeBatchedRender(()=>{this.domRefs&&Se(this.domRefs,this.store.get(),t)}),Se(this.domRefs,this.store.get(),t),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e={store:this.store,listboxId:this.listboxId,selectOption:t=>this.selectOption(t),setActivePill:t=>this.pillsController.setActivePill(t)};this.dropdownRefs=Me(this.container,e),this.subscribeBatchedRender(()=>{this.dropdownRefs&&we(this.dropdownRefs,this.store.get(),e)}),we(this.dropdownRefs,this.store.get(),e),this.subscribeNewParamTimer()}subscribeBatchedRender(e){let t=!1;this.unsubscribers.push(this.store.subscribe(()=>{t||(t=!0,queueMicrotask(()=>{t=!1,e()}))}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,t)=>{e.newParamId&&e.newParamId!==t.newParamId&&(this.newParamTimer&&clearTimeout(this.newParamTimer),this.newParamTimer=window.setTimeout(()=>{this.store.set({newParamId:null})},650))}))}handleChange(e){let t=this.store.get();this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:r}=ke(e,t.completedParams);r.length>0&&this.store.set(n=>({completedParams:i,suggestions:[...r.map(a=>({type:a.suggestionType,text:a.suggestionPlaceholder,required:!0,options:a.options})),...n.suggestions]}))}};function ce({onSubmit:o,onError:e,optionOverrides:t,maskCompletedText:i,placeholder:r,apiConfig:n,columns:a=2,dropdownTrigger:d,value:s,completedParams:l,onChange:p,onParamsChange:c}){let u=(0,b.useRef)(null),[h,m]=(0,b.useState)(null),S=(0,b.useRef)(o);S.current=o;let x=(0,b.useRef)(e);x.current=e;let v=(0,b.useRef)(p);v.current=p;let C=(0,b.useRef)(c);C.current=c,(0,b.useEffect)(()=>{if(typeof document>"u")return;let y=new pe(document.createElement("div"),{renderMode:"headless",apiConfig:n,optionOverrides:t,maskCompletedText:i,placeholder:r,columns:a,dropdownTrigger:d,value:s,completedParams:l,onSubmit:(...f)=>S.current?.(...f),onError:(...f)=>x.current?.(...f),onChange:(...f)=>v.current?.(...f),onParamsChange:(...f)=>C.current?.(...f)});u.current=y,m(y.getState());let A=y.subscribe(f=>m(f));return()=>{A(),y.destroy(),u.current===y&&(u.current=null)}},[]);let g=u.current,I=(0,b.useCallback)(()=>{},[]);(0,b.useEffect)(()=>{s!==void 0&&g?.setValue(s)},[s,g]),(0,b.useEffect)(()=>{l!==void 0&&g?.setCompletedParams(l)},[l,g]);let j=JSON.stringify(n??null),T=(0,b.useRef)(t),z=(0,b.useRef)(0);if(t!==T.current){let y=T.current,A=t,f=Object.keys(y??{}),D=Object.keys(A??{});(f.length!==D.length||D.some(J=>!y?.[J]||A[J]!==y[J]))&&z.current++,T.current=t}(0,b.useEffect)(()=>{g?.update({apiConfig:n,optionOverrides:t,dropdownTrigger:d})},[j,z.current,d,g]);let ue=(0,b.useCallback)(y=>{if(!g)return;let A=y.target.value,D=A.length>0&&!y.nativeEvent?.isComposing&&A[0]!==A[0].toUpperCase()?A[0].toUpperCase()+A.slice(1):A;g.handleTextChange(D)},[g]),me=(0,b.useCallback)(y=>{g?.handleKeyDown(y.nativeEvent)},[g]),F=(0,b.useCallback)(y=>g?.setActivePill(y),[g]),M=(0,b.useCallback)(()=>g?.removeLastParam(),[g]),G=(0,b.useCallback)(()=>g?.clearNewParamId(),[g]),E=(0,b.useCallback)(()=>g?.reset(),[g]),ge=(0,b.useCallback)(y=>g?.selectOption(y),[g]),B=(0,b.useCallback)(y=>g?.setActiveDropdownIndex(y),[g]);if(!g)return{completedParams:l??[],suggestionPills:[],setActivePill:I,removeLastParam:I,segments:[],newParamId:null,clearNewParamId:I,suggestions:[],activeIndex:-1,isReady:!1,isLoading:!0,error:null,inputProps:{value:s??"",placeholder:r,onChange:I,onKeyDown:I,role:"combobox","aria-expanded":!1,"aria-activedescendant":void 0,"aria-autocomplete":"list","aria-controls":""},reset:I,dropdownProps:{suggestions:[],activeIndex:-1,onSelect:I,onHighlight:I,isOpen:!1,id:"",pills:[],onPillClick:I}};let w=h??g.getState(),q=s!==void 0?s:w.text,X=l!==void 0?l:w.completedParams,V=w.actionableSuggestions,U=V[0],fe=w.filteredOptions,he=w.activeDropdownIndex>=0?`${g.listboxId}-option-${w.activeDropdownIndex}`:void 0;return{completedParams:X,suggestionPills:V,setActivePill:F,removeLastParam:M,segments:w.segments,newParamId:w.newParamId,clearNewParamId:G,suggestions:w.suggestions,activeIndex:w.activeDropdownIndex,isReady:w.isReady,isLoading:w.isLoading,error:w.error,inputProps:{value:q,placeholder:w.placeholderText||void 0,onChange:ue,onKeyDown:me,role:"combobox","aria-expanded":w.isDropdownOpen,"aria-activedescendant":he,"aria-autocomplete":"list","aria-controls":g.listboxId},reset:E,dropdownProps:{suggestions:U?[{...U,options:fe}]:[],activeIndex:w.activeDropdownIndex,onSelect:ge,onHighlight:B,isOpen:w.isDropdownOpen,id:g.listboxId,pills:V,onPillClick:F}}}var _=require("react/jsx-runtime");function mt(o){return o!=="auto"?o:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var $e=(0,P.forwardRef)(function({onSubmit:e,onError:t,optionOverrides:i,maskCompletedText:r,placeholder:n,className:a,apiConfig:d,columns:s,pillPlacement:l="inline",mode:p="auto",optionsPosition:c="below",animations:u=!0,dropdownTrigger:h,value:m,completedParams:S,onChange:x,onParamsChange:v},C){let g=(0,P.useRef)(null),I=(0,P.useRef)(null),j=(0,P.useRef)(()=>{}),T=(0,P.useRef)(null);(0,P.useEffect)(()=>{I.current?.focus()},[]),(0,P.useEffect)(()=>{let f=g.current;if(f)return T.current?T.current.setMode(p):T.current=new $(f,p),()=>{T.current?.destroy(),T.current=null}},[p]);let{completedParams:z,suggestionPills:ue,setActivePill:me,segments:F,newParamId:M,clearNewParamId:G,inputProps:E,dropdownProps:ge,reset:B}=ce({onSubmit:f=>j.current(f),onError:t,optionOverrides:i,maskCompletedText:r,placeholder:n,apiConfig:d,columns:s,dropdownTrigger:h,value:m,completedParams:S,onChange:x,onParamsChange:v});(0,P.useEffect)(()=>{if(!M)return;let f=window.setTimeout(()=>G(),650);return()=>window.clearTimeout(f)},[M,G]),(0,P.useImperativeHandle)(C,()=>({focus:()=>I.current?.focus(),reset:B,setMode:f=>T.current?.setMode(f)}),[B]);let w=()=>{I.current?.focus()},q=!!E.value||z.length>0,X=(0,P.useCallback)(()=>{if(!q)return;let{rawQuery:f,completedParams:D}=R(E.value,z);e({query:E.value.trim(),raw_query:f,completed_params:D}),B()},[q,E.value,z,e,B]);j.current=X;let{onChange:V,placeholder:U,...fe}=E,he=!E.value,y=l==="inline",A=l==="dropdown";return(0,_.jsxs)("div",{ref:g,className:`magicx-aia ${k.container} ${a??""}`,"data-pill-placement":l,"data-options-position":c,"data-animations":u?"on":"off","data-mode":mt(p),children:[(0,_.jsx)(te,{...ge,showPills:A}),(0,_.jsxs)("div",{className:k.inputWrapper,onClick:w,children:[(0,_.jsxs)("div",{className:k.editorArea,children:[(0,_.jsxs)("div",{className:k.sizerContent,"aria-hidden":"true",children:[he&&U?(0,_.jsxs)("span",{className:k.placeholderText,children:[U," "]}):(0,_.jsxs)("span",{className:`${k.sizerText} ${M?k.sizerTextVisible:""}`,children:[F.map((f,D)=>{if(f.type==="completed"&&f.param.id===M){let Fe=`${k.shimmerRevealed} ${k.shimmerSweep}`;return(0,_.jsx)("span",{className:Fe,children:f.value},`${D}-${f.type}`)}return(0,_.jsx)("span",{children:f.value},`${D}-${f.type}`)}),F.length===0&&"\xA0"]})," ",y&&(0,_.jsx)(Z,{pills:ue,activePillIndex:0,onSelectPill:me})]}),(0,_.jsx)("textarea",{ref:I,className:`${k.textarea} ${M?k.textareaHidden:""}`,rows:1,onChange:V,...fe})]}),(0,_.jsx)("button",{type:"button",className:k.submitButton,disabled:!q,onClick:f=>{f.stopPropagation(),X()},"aria-label":"Submit",children:(0,_.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:(0,_.jsx)("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})});0&&(module.exports={AIAutocomplete,AIAutocompleteDropdown,useAIAutocomplete});
607
+ `,document.head.appendChild(o)}var T={item:"SuggestionItem-module_item_d4vpD",fadeIn:"SuggestionItem-module_fadeIn_I8u35",content:"SuggestionItem-module_content_T-Qba",tappable:"SuggestionItem-module_tappable_70KcX",nonTappable:"SuggestionItem-module_nonTappable_xSZM-",highlighted:"SuggestionItem-module_highlighted_Hb0SU",tag:"SuggestionItem-module_tag_e3Fwe",pressed:"SuggestionItem-module_pressed_98o-r",glassFade:"SuggestionItem-module_glassFade_oyiSj",tapDown:"SuggestionItem-module_tapDown_G3WGz",streaks:"SuggestionItem-module_streaks_d9PEB",streaksVert:"SuggestionItem-module_streaksVert_ERlV1",streakHorizRight:"SuggestionItem-module_streakHorizRight_aboGz",streakHorizLeft:"SuggestionItem-module_streakHorizLeft_BreWJ",streakVertUp:"SuggestionItem-module_streakVertUp_to1GD",streakVertDown:"SuggestionItem-module_streakVertDown_OrcLh"};var R=require("react/jsx-runtime");function Ce({option:o,isHighlighted:e,onSelect:t,onHighlight:i,id:r}){let[n,a]=(0,N.useState)(!1),d=(0,N.useRef)(void 0);(0,N.useEffect)(()=>()=>clearTimeout(d.current),[]);let s=()=>{!o.is_tappable||n||(a(!0),t(o),clearTimeout(d.current),d.current=setTimeout(()=>a(!1),400))},l=[T.item,e?T.highlighted:"",o.is_tappable?T.tappable:T.nonTappable,n?T.pressed:""].filter(Boolean).join(" ");return(0,R.jsxs)("div",{id:r,role:"option","data-aia-option":"","aria-selected":e,className:l,tabIndex:o.is_tappable?0:-1,onClick:s,onKeyDown:p=>{o.is_tappable&&(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),s())},onMouseEnter:o.is_tappable?i:void 0,children:[(0,R.jsx)("div",{className:T.streaks}),(0,R.jsx)("div",{className:T.streaksVert}),(0,R.jsxs)("span",{className:T.content,children:[o.icon?`${o.icon} ${o.text}`:o.text,o.tag&&(0,R.jsx)("span",{className:T.tag,children:o.tag})]})]})}var Z=require("react/jsx-runtime");function Pe({options:o,activeIndex:e,onSelect:t,onHighlight:i,listboxId:r}){let n=(0,D.useRef)(null),[a,d]=(0,D.useState)(!1);return(0,D.useEffect)(()=>{let s=n.current;if(!s)return;let l=()=>{d(s.scrollHeight-s.scrollTop-s.clientHeight>1)};s.addEventListener("scroll",l,{passive:!0});let p=new ResizeObserver(l);return p.observe(s),()=>{s.removeEventListener("scroll",l),p.disconnect()}},[]),(0,D.useLayoutEffect)(()=>{let s=n.current;s&&d(s.scrollHeight-s.scrollTop-s.clientHeight>1)},[o]),(0,Z.jsx)("div",{className:ye.scrollWrapper,"data-fade":a?"":void 0,children:(0,Z.jsx)("div",{ref:n,className:ye.grid,children:o.map((s,l)=>(0,Z.jsx)(Ce,{option:s,isHighlighted:l===e,onSelect:t,onHighlight:()=>i(l),id:`${r}-option-${l}`},s.text))})})}var K=require("react/jsx-runtime");function ee({suggestions:o,activeIndex:e,onSelect:t,onHighlight:i,isOpen:r,id:n,className:a,pills:d,onPillClick:s,showPills:l=!0}){let c=o[0]?.options??[],m=l&&d&&d.length>0&&s,g=r&&c.length>0||r&&m;return(0,K.jsxs)("div",{id:n,role:"listbox","data-aia-dropdown":"",className:`${J.dropdown} ${g?J.visible:""} ${a??""}`,onMouseDown:_=>_.preventDefault(),children:[m&&(0,K.jsx)("div",{className:J.pillBar,"data-aia-pillbar":"",children:(0,K.jsx)(Y,{pills:d,activePillIndex:0,onSelectPill:s,rounded:!0})}),c.length>0&&(0,K.jsx)(Pe,{options:c,activeIndex:e,onSelect:t,onHighlight:i,listboxId:n})]})}if(typeof document<"u"&&!document.getElementById("ac-style-dc8da745")){let o=document.createElement("style");o.id="ac-style-dc8da745",o.textContent=`/*
608
+ * Built-in appearance defaults \u2014 zero specificity via :where().
609
+ * Consumer CSS always wins without !important.
610
+ *
611
+ * Resolution priority (highest wins):
612
+ * 1. Consumer CSS targeting new vars (--aia-pill-bg, etc.)
613
+ * 2. Consumer CSS targeting legacy vars (--aia-color-*, via fallback chain)
614
+ * 3. These built-in defaults
615
+ */
616
+
617
+ /* Light mode defaults (base) */
618
+ :where(.magicx-aia),
619
+ :where(.magicx-aia[data-mode="light"]) {
620
+ --aia-pill-bg: #bdbdbd;
621
+ --aia-pill-color: #000000;
622
+ --aia-pill-font-size: 19px;
623
+
624
+ --aia-option-bg: transparent;
625
+ --aia-option-color: #000000;
626
+ --aia-option-color-selected: #000000;
627
+ --aia-option-font-size: 19px;
628
+
629
+ --aia-written-text-color: #000000;
630
+ --aia-written-text-font-size: 19px;
631
+ --aia-caret-color: var(--aia-written-text-color, #000000);
632
+
633
+ --aia-submit-bg: #000000;
634
+ --aia-submit-color: #ffffff;
635
+
636
+ --aia-color-text-muted: #6b7280;
637
+
638
+ --aia-streak-rgb: 99, 102, 241;
639
+ --aia-streak-glass-bg: rgba(99, 102, 241, 0.1);
640
+ }
641
+
642
+ /* Dark mode defaults */
643
+ :where(.magicx-aia[data-mode="dark"]) {
644
+ --aia-pill-bg: #bdbdbd;
645
+ --aia-pill-color: #ffffff;
646
+ --aia-pill-font-size: 19px;
647
+
648
+ --aia-option-bg: transparent;
649
+ --aia-option-color: #ffffff;
650
+ --aia-option-color-selected: #ffffff;
651
+ --aia-option-font-size: 19px;
652
+
653
+ --aia-written-text-color: #ffffff;
654
+ --aia-written-text-font-size: 19px;
655
+ --aia-caret-color: var(--aia-written-text-color, #ffffff);
656
+
657
+ --aia-submit-bg: #ffffff;
658
+ --aia-submit-color: #000000;
659
+
660
+ --aia-color-text-muted: #c1c4cb;
661
+
662
+ --aia-streak-rgb: 255, 255, 255;
663
+ --aia-streak-glass-bg: rgba(255, 255, 255, 0.1);
664
+ }
665
+
666
+ /* optionsPosition: dropdown above the input */
667
+ :where(.magicx-aia[data-options-position="above"]) [data-aia-dropdown] {
668
+ top: auto;
669
+ bottom: 100%;
670
+ margin-top: 0;
671
+ margin-bottom: 6px;
672
+ flex-direction: column-reverse;
673
+ }
674
+
675
+ :where(.magicx-aia[data-options-position="above"]) [data-aia-pillbar] {
676
+ padding: 0 27px 27px 27px;
677
+ }
678
+
679
+ /* Disable all animations when data-animations="off" */
680
+ :where(.magicx-aia[data-animations="off"]) *,
681
+ :where(.magicx-aia[data-animations="off"]) *::before,
682
+ :where(.magicx-aia[data-animations="off"]) *::after {
683
+ animation-duration: 0s !important;
684
+ transition-duration: 0s !important;
685
+ }
686
+ `,document.head.appendChild(o)}var b=require("react");function Q(o,e,t){let i=o.slice(e);if(t||e===0||o[e-1]===" ")return i;let r=i.indexOf(" ");return r===-1?"":i.slice(r+1)}function Ae(o,e){let t=o.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let i=t.split(" "),r=e.toLowerCase();for(let n=0;n<i.length;n++){let a=i.slice(n).join(" ");if(r.startsWith(a.toLowerCase())){let d=t.length-a.length;return o.length-d}}return 0}function te(o,e){if(!o)return[];let t=e.trimStart();if(!t)return o;let i=t.toLowerCase();return o.filter(r=>!r.is_tappable||r.text.toLowerCase().includes(i))}function we(o,e){if(!o)return null;let t=e.trim();if(!t)return null;let i=t.toLowerCase();return o.find(r=>r.is_tappable&&r.text.toLowerCase()===i)??null}var F=class{constructor(e,t="auto"){this.container=e;this.mode=t;this.mediaQuery=null;this.onSystemChange=e=>{this.container.dataset.mode=e.matches?"dark":"light"};this.apply()}setMode(e){this.detachListener(),this.mode=e,this.apply()}destroy(){this.detachListener()}apply(){this.mode==="auto"?(this.mediaQuery??(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)")),this.mediaQuery.addEventListener("change",this.onSystemChange),this.container.dataset.mode=this.mediaQuery.matches?"dark":"light"):this.container.dataset.mode=this.mode}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function ke(o,e){let t=[],i=0;for(let n of e){let a=o.indexOf(n.text,i);a!==-1&&(a>i&&t.push({type:"text",value:o.slice(i,a)}),t.push({type:"completed",value:n.text,param:n}),i=a+n.text.length)}let r=o.slice(i);return r&&t.push({type:"text",value:r}),t}function Te(o,e){let t=[],i=[],r=0;for(let n of e){let a=o.indexOf(n.text,r);a===-1?i.push(n):(t.push(n),r=a+n.text.length)}return{valid:t,invalid:i}}var oe=class{constructor(e){this.config=e;this.current=null;this.expiresAt=null;this.inFlightRefresh=null;e.accessToken&&(this.current=e.accessToken)}async getToken(e=!1){if(!e&&this.current&&!this.isExpired())return this.current;if(!e&&this.inFlightRefresh)return this.inFlightRefresh;this.inFlightRefresh=this.refresh();try{return await this.inFlightRefresh}finally{this.inFlightRefresh=null}}async refresh(){let e=await this.config.getAccessToken();return this.current=e.accessToken,this.expiresAt=e.expiresAt??null,this.current}isExpired(){return this.expiresAt==null?!1:Date.now()>=this.expiresAt-3e4}};var Xe="0.1.26",Oe=!1;function Je(){return crypto.randomUUID()}function Ye(o,e){return{placeholder:o.placeholder,type:o.type,...e&&{text:o.text},kind:o.kind}}function Le(o){return o?.type==="accessToken"}function Ze(o){if(!(!o||Le(o)))return o}var De=new WeakMap;function et(o){let e=De.get(o.getAccessToken);return e||(e=new oe(o),De.set(o.getAccessToken,e)),e}function tt(o,e,t){let i=e.find(n=>n.type==="contact"&&n.metadata?.contact_account_count)?.metadata?.contact_account_count,r=typeof i=="number"?i:void 0;return{data:{raw_query:o,completed_params:e.map(n=>Ye(n,t)),...r!=null&&{contact_account_count:r}},meta:{request_id:Je(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:Xe}}}function ot(o){return{"Content-Type":"application/json",...o?.appIdentifier&&{"X-App-Identifier":o.appIdentifier},...o?.headers}}async function Ee(o,e,t,i,r){return fetch(o,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:i,signal:r})}async function Re(o,e,t){let i=t?.apiConfig,r=!t?.maskCompletedText,n=tt(o,e,r),a=ot(i),d=i?.endpoint??"/ac/suggest",s=JSON.stringify(n);if(Le(i)){let m=et(i),h=await m.getToken(),g=await Ee(d,a,h,s,t?.signal);if(g.status===401){let _=await m.getToken(!0);g=await Ee(d,a,_,s,t?.signal)}if(!g.ok)throw new Error(`API error: ${g.status} ${g.statusText}`);return g.json()}let l=Ze(i),p=l?.apiKey??"";if(!p&&!Oe&&(Oe=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),p){let m=l?.authScheme??"Bearer";a.Authorization=m==="Basic"?`Basic ${btoa(p)}`:`Bearer ${p}`}let c=await fetch(d,{method:"POST",headers:a,body:s,signal:t?.signal});if(!c.ok)throw new Error(`API error: ${c.status} ${c.statusText}`);return c.json()}function E(o,e){let t=o,i={},r=[];for(let n of e){let a=(i[n.type]??0)+1;i[n.type]=a;let s=`{{${n.type.toUpperCase().replace(/\s+/g,"_")}_${a}}}`,l=t.indexOf(n.text);l!==-1&&(t=t.slice(0,l)+s+t.slice(l+n.text.length)),r.push({...n,placeholder:s})}return{rawQuery:t,completedParams:r}}function Me(o,e){return e?o.map(t=>{let i=e[t.type];if(!i)return t;let r=i("");if(r.length===0)return t;let n=new Set(r.map(d=>d.text)),a=(t.options??[]).filter(d=>!n.has(d.text));return{...t,options:[...r,...a]}}):o}var it=100,nt=300,rt=2,ie=class{constructor(e,t,i,r,n){this.store=e;this.getApiConfig=t;this.getOptionOverrides=i;this.getMaskCompletedText=r;this.getOnError=n;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,t=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(i=>{(i.text!==e||i.completedParams!==t)&&(e=i.text,t=i.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let i=new AbortController;this.abortController=i;let r=++this.fetchVersion,n=this.store.get(),a=n.text.length;n.suggestions.some(s=>s.type!=="placeholder")||this.store.set({isLoading:!0}),this.store.set({error:null});try{let s=await Re(e,t,{maskCompletedText:this.getMaskCompletedText(),signal:i.signal,apiConfig:this.getApiConfig()});if(r!==this.fetchVersion)return;let l=Me(s.data.suggestions??[],this.getOptionOverrides()),p=s.data.input??[],c=p[p.length-1],m=this.store.get().text,h,g;if(c?.state==="in_progress"){g=!0;let u=m.toLowerCase().lastIndexOf(c.text.toLowerCase());h=u!==-1?u:a}else g=!1,h=a;let x=l.filter(u=>u.type!=="placeholder")[0],P=null;if(x){let u=Q(m,h,g),y=we(x.options,u);y&&(P={id:crypto.randomUUID(),placeholder:"",type:x.type,text:y.text,kind:y.kind,suggestionType:x.type,suggestionPlaceholder:x.text,options:x.options??[],metadata:y.metadata},l=l.filter(M=>M!==x))}this.store.set(u=>({suggestions:l,isLoading:!1,isReady:s.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:h,filterInProgress:g,...P?{completedParams:[...u.completedParams,P]}:{}}))}catch(s){if(r===this.fetchVersion){let l=s instanceof Error?s:new Error(String(s));this.store.set({error:l,isLoading:!1}),this.getOnError()?.(l)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=i=>{let r=this.store.get();if(!r.text&&r.completedParams.length===0)return this.doFetch("",[]),!0;let n=Q(r.text,r.filterBase,r.filterInProgress),d=r.suggestions.filter(x=>x.type!=="placeholder")[0],l=(d?te(d.options,n):[]).filter(x=>x.is_tappable),p=d?we(d.options,n)!==null:!1,c=n.trim().length>0;if(l.length>0&&!p&&c)return!1;if(r.completedParams.length===0&&r.text.length>0){let x=r.suggestions.filter(P=>P.type==="placeholder").map(P=>P.text).join(" ");if(x.length>0&&x.toLowerCase().startsWith(r.text.toLowerCase()))return!1}let{rawQuery:m,completedParams:h}=E(r.text,r.completedParams),g=m.length<r.lastRawQuery.length,_=Math.abs(m.length-r.lastRawQuery.length);return g||_>=i?(this.doFetch(m,h),!0):!1};this.debounceTimer=setTimeout(()=>{t(rt)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},it),this.slowDebounceTimer=setTimeout(()=>t(1),nt)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var ne=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{listboxId:i,getOnSubmit:r}=this.ctx,n=this.getEffectiveColumns(),a=r(),d=this.getTappableIndices(n);switch(e.key){case"ArrowDown":{let s=e.target;if(!(s.selectionStart!=null&&s.selectionStart===s.value.length)&&t.activeDropdownIndex<0)break;if(e.preventDefault(),!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:d[0]??0});break}if(d.length===0)return;let p=d.indexOf(t.activeDropdownIndex),c=p<d.length-1?p+1:0;this.store.set({activeDropdownIndex:d[c]});break}case"ArrowUp":{if(d.length===0||t.activeDropdownIndex<0)break;if(e.preventDefault(),t.activeDropdownIndex<n){this.store.set({activeDropdownIndex:-1});break}let s=d.indexOf(t.activeDropdownIndex),l=s>0?s-1:d.length-1;this.store.set({activeDropdownIndex:d[l]});break}case"ArrowRight":{if(t.activeDropdownIndex<0){let l=e.target;l.selectionStart!=null&&l.selectionStart===l.value.length&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}if(t.activeDropdownIndex%n<n-1){let l=t.activeDropdownIndex+1;l<t.filteredOptions.length&&t.filteredOptions[l]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:l}))}break}case"ArrowLeft":{if(t.activeDropdownIndex<0)break;if(t.activeDropdownIndex%n>0){let s=t.activeDropdownIndex-1;s>=0&&t.filteredOptions[s]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:s}))}break}case"Enter":{if(e.preventDefault(),t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,i);else if(a){let{rawQuery:s,completedParams:l}=E(t.text,t.completedParams);a({query:t.text.trim(),raw_query:s,completed_params:l})}break}case"Tab":{let s=!t.text&&!!t.placeholderText,l=t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable;if(s&&!l){e.preventDefault();let p=t.suggestions.find(c=>c.type==="placeholder");p?this.store.set(c=>({text:t.placeholderText,filterBase:t.placeholderText.length,completedParams:[...c.completedParams,{id:crypto.randomUUID(),placeholder:"",type:p.type,text:t.placeholderText,kind:null,suggestionType:p.type,suggestionPlaceholder:p.text,options:p.options??[]}],suggestions:c.suggestions.filter(m=>m!==p)})):this.store.set({text:t.placeholderText,filterBase:t.placeholderText.length})}else if(l)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,i);else if(t.isDropdownOpen){let p=t.filteredOptions.findIndex(c=>c.is_tappable);p>=0&&(e.preventDefault(),this.clickOrSelect(p,t.filteredOptions,i))}break}case"Escape":this.store.set({activeDropdownIndex:-1});break}}getTappableIndices(e){let i=this.store.get().filteredOptions.map((n,a)=>n.is_tappable?a:-1).filter(n=>n!==-1),r=Array.from({length:e},()=>[]);for(let n of i)r[n%e].push(n);return r.flat()}getEffectiveColumns(){let t=document.getElementById(`${this.ctx.listboxId}-option-0`)?.parentElement;if(!t)return this.ctx.columns;let i=getComputedStyle(t).gridTemplateColumns.split(" ").filter(Boolean).length;return i>0?i:this.ctx.columns}clickOrSelect(e,t,i){let r=document.getElementById(`${i}-option-${e}`);r?r.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),i=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],n=i.filter((d,s)=>s!==e),a=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...a,r,...n],pillTapped:!0,activeDropdownIndex:-1})}};var re=class{constructor(e){this.store=e}setActivePill(e){let t=this.store.get(),i=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],n=i.filter((d,s)=>s!==e),a=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...a,r,...n],pillTapped:!0,activeDropdownIndex:-1})}removeLastParam(){let e=this.store.get();if(e.completedParams.length===0)return;let t=e.completedParams[e.completedParams.length-1],i={type:t.suggestionType,text:t.suggestionPlaceholder,required:!0,options:t.options};this.store.set(r=>({completedParams:r.completedParams.slice(0,-1),suggestions:[i,...r.suggestions],activeDropdownIndex:-1}))}};function st(o){return o===0?.4:o===1?.3:.15}function se(o,e,t,i,r=!1){let n=o.querySelector(".magicx-aia-pill-list");n||(n=document.createElement("span"),n.className="magicx-aia-pill-list",o.appendChild(n));let a=new Map;for(let s of n.querySelectorAll(".magicx-aia-pill"))a.set(s.dataset.pillKey??"",s);let d=new Set;for(let s=0;s<e.length;s++){let l=e[s],p=`${l.type}-${l.text}`;d.add(p);let c=a.get(p);c||(c=document.createElement("button"),c.type="button",c.dataset.pillKey=p,c.setAttribute("data-aia-pill",""),c.textContent=l.text),c.className=`magicx-aia-pill${r?" magicx-aia-pill--rounded":""}${s===t?" magicx-aia-pill--active":""}`,c.style.opacity=String(st(s)),c.onclick=()=>i(s),n.children[s]!==c&&n.insertBefore(c,n.children[s]??null)}for(let[s,l]of a)d.has(s)||l.remove()}function ae(o){let e=document.createElement("div");return e.id=o,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function le(o,e){let{filteredOptions:t,activeIndex:i,isOpen:r,pills:n,showPills:a,onSelect:d,onHighlight:s,onPillClick:l}=e,p=a&&n.length>0;r&&t.length>0||r&&p?o.classList.add("magicx-aia-dropdown--visible"):o.classList.remove("magicx-aia-dropdown--visible");let h=o.querySelector(".magicx-aia-pill-bar");p?(h||(h=document.createElement("div"),h.className="magicx-aia-pill-bar",h.setAttribute("data-aia-pillbar",""),o.insertBefore(h,o.firstChild)),se(h,n,0,l,!0)):h&&h.remove();let g=o.querySelector(".magicx-aia-grid");t.length>0?(g||(g=document.createElement("div"),g.className="magicx-aia-grid",o.appendChild(g)),at(g,t,i,d,s,e.listboxId)):g&&(g.innerHTML="")}function at(o,e,t,i,r,n){let a=e.map(l=>l.text).join("\0"),d=o.dataset.optionsKey??"",s=a!==d;if(o.dataset.optionsKey=a,s){let l=document.createDocumentFragment();for(let p=0;p<e.length;p++){let c=e[p],m=lt(c,p,t,i,r,n);l.appendChild(m)}o.innerHTML="",o.appendChild(l)}else{let l=o.querySelectorAll(".magicx-aia-option");for(let p=0;p<l.length;p++){let c=l[p],m=p===t;c.setAttribute("aria-selected",String(m)),m?c.classList.add("magicx-aia-option--highlighted"):c.classList.remove("magicx-aia-option--highlighted")}}}function lt(o,e,t,i,r,n){let a=document.createElement("div");a.id=`${n}-option-${e}`,a.setAttribute("role","option"),a.setAttribute("data-aia-option",""),a.setAttribute("aria-selected",String(e===t)),a.tabIndex=o.is_tappable?0:-1;let d=["magicx-aia-option"];e===t&&d.push("magicx-aia-option--highlighted"),o.is_tappable?d.push("magicx-aia-option--tappable"):d.push("magicx-aia-option--non-tappable"),a.className=d.join(" ");let s=document.createElement("div");s.className="magicx-aia-streaks",a.appendChild(s);let l=document.createElement("div");l.className="magicx-aia-streaks-vert",a.appendChild(l);let p=document.createElement("span");if(p.className="magicx-aia-option-content",p.textContent=o.icon?`${o.icon} ${o.text}`:o.text,o.tag){let c=document.createElement("span");c.className="magicx-aia-option-tag",c.textContent=o.tag,p.appendChild(c)}return a.appendChild(p),o.is_tappable&&(a.addEventListener("click",()=>{a.classList.add("magicx-aia-option--pressed"),i(o),setTimeout(()=>a.classList.remove("magicx-aia-option--pressed"),400)}),a.addEventListener("mouseenter",()=>r(e))),a}function He(o,e){let t=ae(e.listboxId);return o.appendChild(t),{dropdown:t}}function Se(o,e,t){le(o.dropdown,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:!0,onSelect:t.selectOption,onHighlight:i=>t.store.set({activeDropdownIndex:i}),onPillClick:t.setActivePill})}function ze(o,e,t,i,r){let n=o.querySelector(".magicx-aia-sizer-text"),a=o.querySelector(".magicx-aia-placeholder");if(i&&r){n&&(n.style.display="none"),a||(a=document.createElement("span"),a.className="magicx-aia-placeholder",o.insertBefore(a,o.firstChild)),a.style.display="",a.textContent=`${r} `,o.dataset.segmentKey="";return}a&&(a.style.display="none"),n||(n=document.createElement("span"),n.className="magicx-aia-sizer-text",o.insertBefore(n,o.firstChild)),n.style.display="",n.className=`magicx-aia-sizer-text${t?" magicx-aia-sizer-text--visible":""}`;let d=e.map(p=>`${p.type}:${p.value}`).join("\0"),s=o.dataset.segmentKey??"",l=o.dataset.newParamId??"";if(!(d===s&&(t??"")===l)){o.dataset.segmentKey=d,o.dataset.newParamId=t??"",n.innerHTML="";for(let p of e){let c=document.createElement("span");p.type==="completed"&&(p.param.id===t?c.className="magicx-aia-shimmer-revealed magicx-aia-shimmer-sweep":c.className="magicx-aia-segment magicx-aia-segment--completed"),c.textContent=p.value,n.appendChild(c)}e.length===0&&(n.textContent="\xA0")}}var dt='<svg width="18" height="18" viewBox="0 0 18 18" fill="none" role="img" aria-label="Submit"><path d="M9 14V4M9 4L4 9M9 4L14 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function Be(o,e){let{listboxId:t}=e,i=ae(t);o.appendChild(i);let r=document.createElement("div");r.className="magicx-aia-input-wrapper",o.appendChild(r);let n=document.createElement("div");n.className="magicx-aia-editor",n.setAttribute("data-aia-editor",""),r.appendChild(n);let a=document.createElement("div");a.className="magicx-aia-sizer",a.setAttribute("aria-hidden","true"),n.appendChild(a);let d=document.createElement("span");a.appendChild(document.createTextNode(" ")),a.appendChild(d);let s=document.createElement("textarea");s.className="magicx-aia-textarea",s.rows=1,s.setAttribute("role","combobox"),s.setAttribute("aria-autocomplete","list"),s.setAttribute("aria-controls",t),s.setAttribute("data-aia-textarea",""),n.appendChild(s);let l=document.createElement("button");return l.type="button",l.className="magicx-aia-submit",l.setAttribute("aria-label","Submit"),l.setAttribute("data-aia-submit",""),l.innerHTML=dt,r.appendChild(l),r.addEventListener("click",()=>s.focus()),s.addEventListener("input",()=>{let p=s.value,m=p.length>0&&p[0]!==p[0].toUpperCase()?p[0].toUpperCase()+p.slice(1):p;e.handleChange(m)}),s.addEventListener("keydown",p=>e.handleKeyDown(p)),s.addEventListener("focus",()=>e.store.set({isFocused:!0})),s.addEventListener("blur",()=>e.store.set({isFocused:!1})),l.addEventListener("click",p=>{p.stopPropagation();let c=e.store.get();if(!(!!c.text||c.completedParams.length>0)||!e.onSubmit)return;let{rawQuery:h,completedParams:g}=E(c.text,c.completedParams);e.onSubmit({query:c.text.trim(),raw_query:h,completed_params:g})}),s.focus(),{textarea:s,dropdown:i,sizer:a,submitButton:l,inlinePillContainer:d}}function Ie(o,e,t){let{textarea:i,dropdown:r,sizer:n,submitButton:a,inlinePillContainer:d}=o,{pillPlacement:s,setActivePill:l,selectOption:p,store:c}=t;i.value!==e.text&&(i.value=e.text),e.placeholderText?i.placeholder=e.placeholderText:i.removeAttribute("placeholder"),i.setAttribute("aria-expanded",String(e.isDropdownOpen));let m=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";m?i.setAttribute("aria-activedescendant",m):i.removeAttribute("aria-activedescendant"),e.newParamId?i.classList.add("magicx-aia-textarea--hidden"):i.classList.remove("magicx-aia-textarea--hidden");let h=!!e.text||e.completedParams.length>0;a.disabled=!h,ze(n,e.segments,e.newParamId,!e.text,e.placeholderText),s==="inline"?se(d,e.actionableSuggestions,0,l):d.innerHTML="",le(r,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:s==="dropdown",onSelect:p,onHighlight:g=>c.set({activeDropdownIndex:g}),onPillClick:l})}function Ne(o){let e=o,t=new Set;return{get:()=>e,set:i=>{let r=typeof i=="function"?i(e):i,n={...e,...r},a=e;e=n;for(let d of t)d(n,a)},subscribe:i=>(t.add(i),()=>{t.delete(i)})}}var _e=!1;function Ke(){if(_e||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){_e=!0;return}_e=!0;let o=document.createElement("style");o.setAttribute("data-magicx-aia",""),o.textContent=pt,document.head.appendChild(o)}var pt="";var ct=0;function ut(){return`:ac-${++ct}:`}function Fe(){return{text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],placeholderText:"",isDropdownOpen:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1}}var de=class{constructor(e,t={}){this.store=Ne(Fe());this._listboxId=ut();this.modeController=null;this.unsubscribers=[];this.derivedInProgress=!1;this.domRefs=null;this.dropdownRefs=null;this.externalListeners=new Set;this.container=e,this.opts=t,this.renderMode=t.renderMode??"full",t.value!==void 0&&this.store.set({text:t.value}),t.completedParams!==void 0&&this.store.set({completedParams:t.completedParams}),this.pillsController=new re(this.store),this.fetchController=new ie(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.opts.onError),this.keyboardController=new ne(this.store,{columns:t.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.opts.onSubmit,selectOption:i=>this.selectOption(i)}),this.unsubscribers.push(this.store.subscribe((i,r)=>{this.recomputeDerived(i,r)})),this.unsubscribers.push(this.store.subscribe((i,r)=>{i.text!==r.text&&this.opts.onChange?.(i.text),i.completedParams!==r.completedParams&&this.opts.onParamsChange?.(i.completedParams),this.opts.onStateChange?.(i)})),this.renderMode!=="headless"&&(Ke(),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.fetchController.start()}focus(){this.domRefs?.textarea.focus()}reset(){this.store.set({...Fe()}),this.fetchController.doFetch("",[])}destroy(){this.fetchController.dispose(),this.modeController?.destroy(),this.newParamTimer&&clearTimeout(this.newParamTimer),this.suggestionRemovalTimer&&clearTimeout(this.suggestionRemovalTimer),this.externalListeners.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}setValue(e){this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e)}removeLastParam(){this.pillsController.removeLastParam()}clearNewParamId(){this.store.set({newParamId:null})}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}handleTextChange(e){this.handleChange(e)}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}setFocused(e){this.store.get().isFocused!==e&&this.store.set({isFocused:e})}subscribe(e){return this.externalListeners.add(e),()=>{this.externalListeners.delete(e)}}getState(){return this.store.get()}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,t){switch(e){case"submit":return this.opts.onSubmit=t,()=>{this.opts.onSubmit=void 0};case"error":return this.opts.onError=t,()=>{this.opts.onError=void 0};case"change":return this.opts.onChange=t,()=>{this.opts.onChange=void 0};case"paramsChange":return this.opts.onParamsChange=t,()=>{this.opts.onParamsChange=void 0};case"stateChange":return this.opts.onStateChange=t,()=>{this.opts.onStateChange=void 0};default:return()=>{}}}update(e){Object.assign(this.opts,e),e.mode!==void 0&&this.modeController?.setMode(e.mode),e.optionsPosition!==void 0&&(this.container.dataset.optionsPosition=e.optionsPosition),e.animations!==void 0&&(this.container.dataset.animations=e.animations?"on":"off"),e.pillPlacement!==void 0&&(this.container.dataset.pillPlacement=e.pillPlacement,this.store.set({})),e.dropdownTrigger!==void 0&&this.store.set({}),e.value!==void 0&&this.store.set({text:e.value}),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let t=this.store.get(),i=t.actionableSuggestions[0];if(!i)return;let r=t.filterBase,n=t.text.slice(0,r),a=n.length===0&&t.text.length===0,d=n.length===0&&t.text.length>0&&t.placeholderText.length>0&&t.placeholderText.toLowerCase().startsWith(t.text.toLowerCase());(a||d)&&t.placeholderText&&(n=`${t.placeholderText} `);let s=Ae(n,e.text);s>0&&(n=n.slice(0,n.length-s));let l=n.length>0&&n[n.length-1]!==" ",p=`${n}${l?" ":""}${e.text} `,c=(a||d)&&p.length>0?p[0].toUpperCase()+p.slice(1):p,m=c.toLowerCase().lastIndexOf(e.text.toLowerCase()),h=m>=0?c.slice(m,m+e.text.length):e.text,g={id:crypto.randomUUID(),placeholder:"",type:i.type,text:h,kind:e.kind,suggestionType:i.type,suggestionPlaceholder:i.text,options:i.options??[],metadata:e.metadata},_=t.actionableSuggestions.length-1;this.store.set(x=>({text:c,filterBase:c.length,completedParams:[...x.completedParams,g],newParamId:g.id,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:_>0})),this.suggestionRemovalTimer=window.setTimeout(()=>{this.store.set(x=>({suggestions:x.suggestions.filter(P=>P!==i)}))},400)}recomputeDerived(e,t){if(this.derivedInProgress)return;this.derivedInProgress=!0;let i=ke(e.text,e.completedParams),r=e.suggestions.filter(x=>x.type!=="placeholder"),n=r[0],a=n?this.opts.optionOverrides?.[n.type]:void 0,d=Math.min(e.filterBase,e.text.length),l=e.lastRawQuery!==""||d>0?Q(e.text,d,e.filterInProgress):"",p=n?a?a(l.trim()):n.options??[]:[],c=te(p,l),m=e.suggestions.filter(x=>x.type==="placeholder").map(x=>x.text).join(" "),h=this.opts.dropdownTrigger??"auto",g=!1;h==="auto"?g=!e.isLoading&&c.length>0&&e.isFocused:h==="manual"&&(g=!e.isLoading&&c.length>0&&e.pillTapped),this.store.set({segments:i,actionableSuggestions:r,filteredOptions:c,placeholderText:m,isDropdownOpen:g}),this.derivedInProgress=!1;let _=this.store.get();for(let x of this.externalListeners)x(_)}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"inline",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new F(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,t={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"inline"},get onSubmit(){return e.opts.onSubmit},selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i)};this.domRefs=Be(this.container,t),this.subscribeBatchedRender(()=>{this.domRefs&&Ie(this.domRefs,this.store.get(),t)}),Ie(this.domRefs,this.store.get(),t),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e={store:this.store,listboxId:this.listboxId,selectOption:t=>this.selectOption(t),setActivePill:t=>this.pillsController.setActivePill(t)};this.dropdownRefs=He(this.container,e),this.subscribeBatchedRender(()=>{this.dropdownRefs&&Se(this.dropdownRefs,this.store.get(),e)}),Se(this.dropdownRefs,this.store.get(),e),this.subscribeNewParamTimer()}subscribeBatchedRender(e){let t=!1;this.unsubscribers.push(this.store.subscribe(()=>{t||(t=!0,queueMicrotask(()=>{t=!1,e()}))}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,t)=>{e.newParamId&&e.newParamId!==t.newParamId&&(this.newParamTimer&&clearTimeout(this.newParamTimer),this.newParamTimer=window.setTimeout(()=>{this.store.set({newParamId:null})},650))}))}handleChange(e){let t=this.store.get();this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:r}=Te(e,t.completedParams);r.length>0&&this.store.set(n=>({completedParams:i,suggestions:[...r.map(a=>({type:a.suggestionType,text:a.suggestionPlaceholder,required:!0,options:a.options})),...n.suggestions]}))}};function pe({onSubmit:o,onError:e,optionOverrides:t,maskCompletedText:i,apiConfig:r,columns:n=2,dropdownTrigger:a,value:d,completedParams:s,onChange:l,onParamsChange:p}){let c=(0,b.useRef)(null),[m,h]=(0,b.useState)(null),g=(0,b.useRef)(o);g.current=o;let _=(0,b.useRef)(e);_.current=e;let x=(0,b.useRef)(l);x.current=l;let P=(0,b.useRef)(p);P.current=p,(0,b.useEffect)(()=>{if(typeof document>"u")return;let v=new de(document.createElement("div"),{renderMode:"headless",apiConfig:r,optionOverrides:t,maskCompletedText:i,columns:n,dropdownTrigger:a,value:d,completedParams:s,onSubmit:(...S)=>g.current?.(...S),onError:(...S)=>_.current?.(...S),onChange:(...S)=>x.current?.(...S),onParamsChange:(...S)=>P.current?.(...S)});c.current=v,h(v.getState());let f=v.subscribe(S=>h(S));return()=>{f(),v.destroy(),c.current===v&&(c.current=null)}},[]);let u=c.current,y=(0,b.useCallback)(()=>{},[]);(0,b.useEffect)(()=>{d!==void 0&&u?.setValue(d)},[d,u]),(0,b.useEffect)(()=>{s!==void 0&&u?.setCompletedParams(s)},[s,u]);let M=JSON.stringify(r??null),k=(0,b.useRef)(t),H=(0,b.useRef)(0);if(t!==k.current){let v=k.current,f=t,S=Object.keys(v??{}),q=Object.keys(f??{});(S.length!==q.length||q.some(V=>!v?.[V]||f[V]!==v[V]))&&H.current++,k.current=t}(0,b.useEffect)(()=>{u?.update({apiConfig:r,optionOverrides:t,dropdownTrigger:a})},[M,H.current,a,u]);let ce=(0,b.useCallback)(v=>{if(!u)return;let f=v.target.value,q=f.length>0&&!v.nativeEvent?.isComposing&&f[0]!==f[0].toUpperCase()?f[0].toUpperCase()+f.slice(1):f;u.handleTextChange(q)},[u]),ue=(0,b.useCallback)(v=>{u?.handleKeyDown(v.nativeEvent)},[u]),W=(0,b.useCallback)(()=>u?.setFocused(!0),[u]),L=(0,b.useCallback)(()=>u?.setFocused(!1),[u]),$=(0,b.useCallback)(v=>u?.setActivePill(v),[u]),O=(0,b.useCallback)(()=>u?.removeLastParam(),[u]),me=(0,b.useCallback)(()=>u?.clearNewParamId(),[u]),z=(0,b.useCallback)(()=>u?.reset(),[u]),j=(0,b.useCallback)(v=>u?.selectOption(v),[u]),ge=(0,b.useCallback)(v=>u?.setActiveDropdownIndex(v),[u]);if(!u)return{completedParams:s??[],suggestionPills:[],setActivePill:y,removeLastParam:y,segments:[],newParamId:null,clearNewParamId:y,suggestions:[],activeIndex:-1,isReady:!1,isLoading:!0,error:null,inputProps:{value:d??"",placeholder:void 0,onChange:y,onKeyDown:y,onFocus:y,onBlur:y,role:"combobox","aria-expanded":!1,"aria-activedescendant":void 0,"aria-autocomplete":"list","aria-controls":""},reset:y,dropdownProps:{suggestions:[],activeIndex:-1,onSelect:y,onHighlight:y,isOpen:!1,id:"",pills:[],onPillClick:y}};let w=m??u.getState(),G=d!==void 0?d:w.text,fe=s!==void 0?s:w.completedParams,B=w.actionableSuggestions,X=B[0],he=w.filteredOptions,xe=w.activeDropdownIndex>=0?`${u.listboxId}-option-${w.activeDropdownIndex}`:void 0;return{completedParams:fe,suggestionPills:B,setActivePill:$,removeLastParam:O,segments:w.segments,newParamId:w.newParamId,clearNewParamId:me,suggestions:w.suggestions,activeIndex:w.activeDropdownIndex,isReady:w.isReady,isLoading:w.isLoading,error:w.error,inputProps:{value:G,placeholder:w.placeholderText||void 0,onChange:ce,onKeyDown:ue,onFocus:W,onBlur:L,role:"combobox","aria-expanded":w.isDropdownOpen,"aria-activedescendant":xe,"aria-autocomplete":"list","aria-controls":u.listboxId},reset:z,dropdownProps:{suggestions:X?[{...X,options:he}]:[],activeIndex:w.activeDropdownIndex,onSelect:j,onHighlight:ge,isOpen:w.isDropdownOpen,id:u.listboxId,pills:B,onPillClick:$}}}var I=require("react/jsx-runtime");function mt(o){return o!=="auto"?o:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var $e=(0,C.forwardRef)(function({onSubmit:e,onError:t,optionOverrides:i,maskCompletedText:r,className:n,apiConfig:a,columns:d,pillPlacement:s="inline",mode:l="auto",optionsPosition:p="below",animations:c=!0,dropdownTrigger:m,value:h,completedParams:g,onChange:_,onParamsChange:x},P){let u=(0,C.useRef)(null),y=(0,C.useRef)(null),M=(0,C.useRef)(()=>{}),k=(0,C.useRef)(null);(0,C.useEffect)(()=>{let f=u.current;if(f)return k.current?k.current.setMode(l):k.current=new F(f,l),()=>{k.current?.destroy(),k.current=null}},[l]);let{completedParams:H,suggestionPills:ce,setActivePill:ue,segments:W,newParamId:L,clearNewParamId:$,inputProps:O,dropdownProps:me,reset:z}=pe({onSubmit:f=>M.current(f),onError:t,optionOverrides:i,maskCompletedText:r,apiConfig:a,columns:d,dropdownTrigger:m,value:h,completedParams:g,onChange:_,onParamsChange:x}),j=O.onFocus;(0,C.useEffect)(()=>{let f=y.current;f&&(document.activeElement===f?j():f.focus())},[j]),(0,C.useEffect)(()=>{if(!L)return;let f=window.setTimeout(()=>$(),650);return()=>window.clearTimeout(f)},[L,$]),(0,C.useImperativeHandle)(P,()=>({focus:()=>y.current?.focus(),reset:z,setMode:f=>k.current?.setMode(f)}),[z]);let ge=()=>{y.current?.focus()},w=!!O.value||H.length>0,G=(0,C.useCallback)(()=>{if(!w)return;let{rawQuery:f,completedParams:S}=E(O.value,H);e({query:O.value.trim(),raw_query:f,completed_params:S}),z()},[w,O.value,H,e,z]);M.current=G;let{onChange:fe,placeholder:B,...X}=O,he=!O.value,xe=s==="inline",v=s==="dropdown";return(0,I.jsxs)("div",{ref:u,className:`magicx-aia ${A.container} ${n??""}`,"data-pill-placement":s,"data-options-position":p,"data-animations":c?"on":"off","data-mode":mt(l),children:[(0,I.jsx)(ee,{...me,showPills:v}),(0,I.jsxs)("div",{className:A.inputWrapper,onClick:ge,children:[(0,I.jsxs)("div",{className:A.editorArea,"data-aia-editor":"",children:[(0,I.jsxs)("div",{className:A.sizerContent,"aria-hidden":"true",children:[he&&B?(0,I.jsxs)("span",{className:A.placeholderText,children:[B," "]}):(0,I.jsxs)("span",{className:`${A.sizerText} ${L?A.sizerTextVisible:""}`,children:[W.map((f,S)=>{if(f.type==="completed"&&f.param.id===L){let V=`${A.shimmerRevealed} ${A.shimmerSweep}`;return(0,I.jsx)("span",{className:V,children:f.value},`${S}-${f.type}`)}return(0,I.jsx)("span",{children:f.value},`${S}-${f.type}`)}),W.length===0&&"\xA0"]})," ",xe&&(0,I.jsx)(Y,{pills:ce,activePillIndex:0,onSelectPill:ue})]}),(0,I.jsx)("textarea",{ref:y,"data-aia-textarea":"",className:`${A.textarea} ${L?A.textareaHidden:""}`,rows:1,onChange:fe,...X})]}),(0,I.jsx)("button",{type:"button","data-aia-submit":"",className:A.submitButton,disabled:!w,onClick:f=>{f.stopPropagation(),G()},"aria-label":"Submit",children:(0,I.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:(0,I.jsx)("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})});0&&(module.exports={AIAutocomplete,AIAutocompleteDropdown,useAIAutocomplete});
593
687
  //# sourceMappingURL=index.js.map