@magicx-eng/ai-autocomplete-vanilla 0.57.0 → 0.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/REFERENCE.md ADDED
@@ -0,0 +1,599 @@
1
+ # @magicx-eng/ai-autocomplete-vanilla reference
2
+
3
+ Longer guides that do not fit in the [README](https://unpkg.com/@magicx-eng/ai-autocomplete-vanilla/README.md) on the npm page. This file ships in the package, at `node_modules/@magicx-eng/ai-autocomplete-vanilla/REFERENCE.md`.
4
+
5
+ - [Product strip](#product-strip)
6
+ - [Datepicker](#datepicker)
7
+ - [Time picker](#time-picker)
8
+ - [Multiple selections](#multiple-selections)
9
+ - [Location search](#location-search)
10
+ - [CSS variables](#css-variables)
11
+
12
+ ## Product strip
13
+
14
+ The dropdown renders a horizontal row of product cards below the options grid
15
+ whenever it has products to show. By default those are the items the
16
+ `/suggest` response itself reports as matching the query. No configuration,
17
+ no extra request: the cards land in the same state write as the suggestions,
18
+ so what the strip shows and what the pills offer always describe the same
19
+ narrowing.
20
+
21
+ ```ts
22
+ import { AIAutocomplete } from "@magicx-eng/ai-autocomplete-vanilla";
23
+
24
+ new AIAutocomplete(container, {
25
+ apiConfig: { apiKey: "..." },
26
+ // Selection emits an event. The SDK never navigates.
27
+ onProductSelect: (product) => {
28
+ if (product.url) window.location.assign(product.url); // …or add to cart, or fill the input
29
+ },
30
+ });
31
+ ```
32
+
33
+ Each server item becomes a `Product` with `id` (the item's stable id), `title`,
34
+ `price` (the item's lowest price, verbatim as the catalog spells it; the
35
+ currency is yours to add), `compareAtPrice` (the price before a markdown, on a
36
+ discounted item only, struck through beside the price), `vendor`, `imageUrl`, and a `url`: the item's own
37
+ `item_url` when the uploaded catalog named one (absolute or root-relative;
38
+ anything else is ignored), else a **relative** `/products/{handle}` (the right
39
+ link for a Shopify widget running on the storefront itself), opened on the
40
+ variant the query chose (`?variant=…`, e.g. the blue one for "blue shoes") when
41
+ there is one, whose price and image the card then shows. `available` is carried
42
+ over when the server reports it. An item with
43
+ neither gets no `url`: its card is still activatable and still emits
44
+ `onProductSelect`, it just has nothing for cmd-click to open. `productFromMatchedItem` / `productsFromCustomFields` are
45
+ exported for a hand-rolled strip that wants the same mapping.
46
+
47
+ Set `showProducts: false` to render no strip at all. The catalog report
48
+ (below) stays readable either way.
49
+
50
+ `productsLayout: "list"` stacks the same cards as full-width rows (thumbnail
51
+ on the left, title, vendor and price on the right) for results that read as
52
+ a list (courses, listings, documents) rather than products on a shelf. The
53
+ column scrolls vertically inside `--aia-product-list-max-height` (320px by
54
+ default); `--aia-product-list-media-size` (44px) sizes the thumbnail and
55
+ `--aia-product-list-gap` (2px) the space between rows. `"row"`, the default,
56
+ is the horizontal strip. `update({ productsLayout })` re-lays the strip out at
57
+ once.
58
+
59
+ **Product image fallback.** A product's image takes priority when its
60
+ `imageUrl` loads successfully. A missing or blank URL, or an image load error,
61
+ uses `productImageFallback`: `"image"` (the default) shows the existing
62
+ placeholder pictogram; `"initial"` shows the first character of the trimmed,
63
+ uppercased title. This is a Unicode grapheme (so a combined character or emoji
64
+ stays together), with a Unicode code point fallback in older browsers. An
65
+ empty or whitespace-only title shows `?`. The fallback works in both row and
66
+ list layouts. Initial tiles are decorative (`aria-hidden="true"`); the card's
67
+ visible title supplies its text.
68
+
69
+ **Sold out.** A product with `available: false` shows a "Sold out" badge over
70
+ the top-left of its image (in the list layout, a smaller banner across the
71
+ bottom of the thumbnail) and its image is desaturated; the card stays
72
+ selectable and keeps its link. Absent or `true` shows no
73
+ badge, so leave `available` out when you don't know. The badge is part of the
74
+ card's text, so screen readers announce it. Theme it with
75
+ `--aia-product-badge-bg`, `--aia-product-badge-color`,
76
+ `--aia-product-badge-font-size` and `--aia-product-badge-inset`, and the list
77
+ banner with `--aia-product-badge-list-bg`, `--aia-product-badge-list-color` and
78
+ `--aia-product-badge-list-font-size`.
79
+
80
+ Set the option at construction or change it through `update()`. Both
81
+ rendered tiers (`"full"` and `"dropdown"`) apply it to the visible cards:
82
+
83
+ ```ts
84
+ const ac = new AIAutocomplete(container, {
85
+ apiConfig: { apiKey: "..." },
86
+ productImageFallback: "initial",
87
+ });
88
+
89
+ // Switch existing fallback tiles back to the placeholder pictogram.
90
+ ac.update({ productImageFallback: "image" });
91
+ ```
92
+
93
+ Style the initial tile itself with `[data-aia-product-initial]`. For
94
+ example, wrap the widget in an element with `id="catalog-search"` and add this
95
+ rule to your stylesheet. The existing `--aia-product-media-bg` variable sets
96
+ the background; `color`, `font-size` and `border-radius` style the initial
97
+ without additional SDK options.
98
+
99
+ ```css
100
+ #catalog-search [data-aia-product-initial] {
101
+ --aia-product-media-bg: #eef2ff;
102
+ color: #4338ca;
103
+ font-size: 22px;
104
+ border-radius: 12px;
105
+ }
106
+ ```
107
+
108
+ ### Add to cart
109
+
110
+ Pass `onProductAddToCart` and every card that isn't sold out gets a round
111
+ add-to-cart button in the bottom right corner of its image. Sold-out cards
112
+ (`available: false`) get none. Pressing it calls your handler, not
113
+ `onProductSelect`. The card doesn't open, and the panel stays open. The SDK
114
+ never touches a cart; your handler does the adding:
115
+
116
+ ```ts
117
+ new AIAutocomplete(container, {
118
+ apiConfig: { apiKey: "..." },
119
+ onProductAddToCart: async (product) => {
120
+ const res = await fetch("/cart/add", { method: "POST", body: JSON.stringify({ id: product.id }) });
121
+ if (!res.ok) throw new Error(`cart ${res.status}`);
122
+ },
123
+ });
124
+ ```
125
+
126
+ Return a promise to have the button show progress. It carries
127
+ `data-aia-cart-state="adding"` while the promise is pending, then `"added"`
128
+ (the cart glyph turns into a check) once it resolves. The check stays until the
129
+ card's product changes (a price-only change keeps it); pressing it again adds
130
+ another unit, going back through `"adding"` to `"added"`. A rejection returns
131
+ it to rest. Style it with
132
+ `--aia-product-cart-size` (28px), `--aia-product-cart-bg` and
133
+ `--aia-product-cart-color`, or `[data-aia-product-cart]`. In the list layout
134
+ the button sits at the row's right end. Headless consumers rendering
135
+ their own cards call `addProductToCart(product)`, which resolves or rejects
136
+ with the handler.
137
+
138
+ ### The catalog report (`customFields`)
139
+
140
+ Every response that read the catalog also says what it did with the query, and
141
+ the SDK exposes that as `customFields` on state (and as `custom_fields` on
142
+ `AutocompleteResult`, so `onResult` / `getResult()` carry it too):
143
+
144
+ ```ts
145
+ ac.subscribe((state) => {
146
+ const report = state.customFields;
147
+ if (!report) return; // no catalog was read for this response
148
+ count.textContent = `${report.items.total} results`;
149
+ if (report.dropped_filters.length > 0) {
150
+ // e.g. { parameter: "Color", value: "Chartreuse", op: "eq" }: the shopper asked
151
+ // for a colour no item carries, so the results ignore it. Say so.
152
+ note.textContent = `No match for ${report.dropped_filters.map((f) => f.value).join(", ")}`;
153
+ }
154
+ });
155
+ ```
156
+
157
+ - `applied_filters` / `dropped_filters`: the constraints the server read out
158
+ of the query as `{ parameter, value, op }` (`op` is one of `eq`, `ne`, `lt`,
159
+ `lte`, `gt`, `gte`), split into the ones the catalog answered and the ones it
160
+ could not (a parameter it does not have, a bound that is not a number, a
161
+ value no item carries). The items answer the applied set, so the dropped
162
+ list is what tells "87 black t-shirts" from "no black item, so here are
163
+ t-shirts". Both are always arrays.
164
+ - `items.total`: how many items the applied filters left standing. It also
165
+ moves with the query's own words, so it drops as a typed word starts
166
+ matching a title. `items.matched` is the list the strip renders, capped by
167
+ the server; it is empty (with a non-zero `total`) when nothing narrowed the
168
+ catalog, where listing arbitrary items as matches would mislead.
169
+ - `null` means the response carried no report: no catalog was read for it
170
+ (a product with no catalog, the starting state, a response with no
171
+ option-bearing parameter to offer). That is "no news", not an empty
172
+ catalog. The strip clears on such a response rather than keeping an older
173
+ query's items.
174
+
175
+ ### Change product cards before display
176
+
177
+ - `mapProducts(products, items)` synchronously returns the cards to show.
178
+ - The SDK calls it once per response with its default cards and their matched items in the same order.
179
+ - The returned array becomes the product state and the displayed strip.
180
+ - A thrown error or a non-array result keeps the default cards. A thrown error warns once per instance.
181
+ - `refreshProducts()` maps the current items again without a request. Call it when your own data arrives.
182
+ - Both APIs leave a custom `products` integration unchanged.
183
+
184
+ ```ts
185
+ const autocomplete = new AIAutocomplete(container, {
186
+ mapProducts: (products, items) =>
187
+ products.map((product, index) => ({
188
+ ...product,
189
+ price: shopperPrices[items[index].source_id] ?? "",
190
+ })),
191
+ });
192
+
193
+ // After updating shopperPrices:
194
+ autocomplete.refreshProducts();
195
+ ```
196
+
197
+ - `update({ mapProducts })` immediately maps the current items with the new mapper.
198
+ - Price changes add, update, or remove price text on the same cards. Selection reports the updated product.
199
+
200
+ ### Your own product search (`products`)
201
+
202
+ To source the cards from your own search instead (a platform with its own
203
+ endpoint and response shape), set `products`. The SDK owns the UI; you own
204
+ only the fetching and the mapping. The server's items are then not rendered
205
+ (they stay readable on `customFields`).
206
+
207
+ ```ts
208
+ import { AIAutocomplete, type Product } from "@magicx-eng/ai-autocomplete-vanilla";
209
+
210
+ new AIAutocomplete(container, {
211
+ apiConfig: { apiKey: "..." },
212
+
213
+ products: {
214
+ // You own the request entirely: auth headers, GraphQL body, locale
215
+ // prefixes, whatever the platform needs. Honour the signal: the SDK aborts
216
+ // it as soon as a newer query supersedes this one.
217
+ fetch: (query, signal) =>
218
+ fetch("/api/2024-10/graphql.json", {
219
+ method: "POST",
220
+ headers: { "X-Shopify-Storefront-Access-Token": token },
221
+ body: JSON.stringify({ query: SEARCH_QUERY, variables: { q: query } }),
222
+ signal,
223
+ }).then((r) => r.json()),
224
+
225
+ // Pure mapping, kept out of `fetch` so you can unit-test it without a
226
+ // network. Fold it into `fetch` and return the array if you prefer.
227
+ transform: (raw) =>
228
+ raw.data.products.nodes.map((node) => ({
229
+ id: node.id,
230
+ title: node.title,
231
+ url: node.onlineStoreUrl,
232
+ imageUrl: node.featuredImage?.url ?? null,
233
+ price: formatMoney(node.priceRange.minVariantPrice), // you know the currency
234
+ vendor: node.vendor,
235
+ })),
236
+
237
+ limit: 8, // applied by the SDK, after transform
238
+ },
239
+
240
+ onProductSelect: (product) => {
241
+ if (product.url) window.location.assign(product.url);
242
+ },
243
+ });
244
+ ```
245
+
246
+ `Product` is exactly seven fields; only `id` and `title` are required:
247
+
248
+ ```ts
249
+ type Product = {
250
+ id: string;
251
+ title: string;
252
+ url?: string; // absent = a card with no link (still activatable)
253
+ imageUrl?: string | null; // null uses the configured productImageFallback
254
+ price?: string; // pre-formatted by you
255
+ compareAtPrice?: string; // the price before a markdown; struck through beside price
256
+ vendor?: string;
257
+ available?: boolean; // false shows a "Sold out" badge
258
+ };
259
+ ```
260
+
261
+ **What the SDK guarantees**
262
+
263
+ - **One fetch cadence.** The product search rides the same debounce, the same
264
+ `AbortController` and the same version guard as `/suggest`, so there is no
265
+ second timer to drift out of step. A query that never triggers a suggestions
266
+ request (e.g. one still narrowing the current option list) doesn't trigger a
267
+ product search either.
268
+ - **Empty queries never reach you.** On mount and after `reset()` the strip
269
+ simply clears.
270
+ - **Out-of-order responses are dropped.** A slow response for an older query is
271
+ never rendered over a newer one.
272
+ - **Failure is silent.** A rejected `fetch` or a throwing `transform` clears the
273
+ strip, logs once, and leaves the suggestions half untouched: no `error`
274
+ state, no `onError`, no effect on `isLoading`.
275
+ - **The two halves are independent.** The panel opens if *either* has content,
276
+ so products keep it open when option filtering empties the list, and
277
+ suggestions render normally when there are no products. `dropdownTrigger`
278
+ (`manual` / `hidden`) still gates the panel as before; products don't
279
+ overrule an explicit opt-out of an auto-opening panel.
280
+
281
+ **Selection and links.** Cards are real `<a href>` elements, so cmd/ctrl-click,
282
+ middle-click and "copy link address" behave natively. A plain left click is
283
+ intercepted (`preventDefault`) and emits `onProductSelect` instead. The SDK
284
+ never navigates on your behalf.
285
+
286
+ `product.url` is used verbatim: the SDK trusts your `transform` output and
287
+ does not sanitise it, so validate the URL there if the platform response isn't
288
+ fully under your control. (Angular additionally runs its own `href`
289
+ sanitiser, so unrecognised schemes like `myapp://…` are rewritten to
290
+ `unsafe:…` in that package only.)
291
+
292
+ **Accessibility.** The strip is a `role="group"` labelled "Best match"; each card
293
+ is a `role="option"` in the tab order, activated with Enter or Space, with a
294
+ visible focus ring. Tabbing into the strip does not close the panel. The row
295
+ scrolls horizontally by trackpad, wheel, touch and keyboard; the page never
296
+ scrolls sideways and the scrollbar chrome is hidden in all engines.
297
+
298
+ `update({ products })` swaps the integration and clears the current cards; the
299
+ strip repopulates on the *next* `/suggest` request, since the product search
300
+ rides that one scheduler and changing the config doesn't itself change the
301
+ query. `update({ products: undefined })` hands the strip back to the server's
302
+ items at once, and `update({ showProducts })` empties or restores it at once.
303
+
304
+ ## Datepicker
305
+
306
+ When the next parameter is a date, the dropdown shows a calendar instead of a
307
+ list of options. Which parameters are dates is the server's call: one whose
308
+ `type` is `date` gets a calendar, and one without a date type keeps its option
309
+ list, however date-like its name or options look.
310
+
311
+ Nothing is required to switch it on: a date parameter renders this way
312
+ automatically, and every other parameter is unaffected. Tier 1 and Tier 2 render
313
+ the calendar for you; in Tier 3 the same data reaches your own renderer (see
314
+ [Tier 3](README.md#tier-3-headless)).
315
+
316
+ **What the user can do**
317
+
318
+ | Input | Result |
319
+ |---|---|
320
+ | Click a day | Commits that date |
321
+ | <kbd>↓</kbd> | Moves into the calendar, starting on today |
322
+ | <kbd>←</kbd> / <kbd>→</kbd> | Previous / next day, crossing week boundaries |
323
+ | <kbd>↑</kbd> / <kbd>↓</kbd> | Previous / next week. Past either end of the month, focus returns to the input |
324
+ | <kbd>Enter</kbd> | Commits the highlighted day |
325
+ | Month arrows | Page the calendar. Paging never commits anything |
326
+ | <kbd>→</kbd> at the end of the input | Skips the parameter, same as any other pill |
327
+
328
+ **The committed value** is written the way a person would write it, always in
329
+ English regardless of the visitor's locale, so the value you receive has one
330
+ vocabulary everywhere:
331
+
332
+ - a date inside the next week (today included) commits as its weekday name:
333
+ `Tuesday`. Like the sentence it sits in, that name is relative: read later,
334
+ it means the next such day;
335
+ - one further out in the current year as `MONTH DAY`: `March 23`;
336
+ - one in another year as `MONTH DAY YEAR`: `March 23 2027`.
337
+
338
+ It arrives as an ordinary completed parameter: bold in the input,
339
+ and present in `completed_params` on submit like any other answer.
340
+
341
+ **Re-editing** a committed date re-opens the calendar on the month the committed
342
+ text names, with that day marked, so changing an answer takes one click. For a
343
+ weekday name that reading is relative, so once the day it named has gone by,
344
+ re-editing marks the next such day rather than the one originally picked: the
345
+ calendar shows what the sentence says today, which is also what gets submitted.
346
+
347
+ **Reading the value back.** The date arrives as text, so if you need a `Date`
348
+ object, `parseDate` is exported for it:
349
+
350
+ ```ts
351
+ import { parseDate } from "@magicx-eng/ai-autocomplete-vanilla";
352
+
353
+ // Reads all three committed shapes: a weekday name is the one date it can
354
+ // mean in the next seven days, and a yearless month-day is the current year.
355
+ const due = parseDate("March 23"); // Date, or null if the text isn't one of ours
356
+ ```
357
+
358
+ `parseLooseDate` is exported too, for the looser shapes a person types into a
359
+ query: it reads `september 5th`, `5th September`, `Sept 5` and `2026-09-05`,
360
+ and answers `null` for anything ambiguous rather than guessing.
361
+
362
+ **Dates the user writes themselves.** When someone types a date into their query
363
+ ("fly to vegas on september 5th"), the parameter it answers is recognised in
364
+ place and the date becomes tappable. Tapping it opens the calendar on that
365
+ month with the day already marked, so confirming or changing it takes one tap,
366
+ and the picked date replaces their words with the canonical form.
367
+
368
+ The written date is read where it can be: `september 5th`, `5th September`,
369
+ `Sept 5`, `September 5, 2026` and `2026-09-05` all resolve, in any of those
370
+ orders and with or without the year (a date with no year means its next
371
+ occurrence). Two cases deliberately don't pre-select: a numeric date like
372
+ `09/05`, which is September 5th in the US and May 9th elsewhere with nothing to
373
+ say which, and phrases like `next friday`. Those still open the calendar, just
374
+ on the current month with nothing marked, so the user picks rather than being
375
+ shown a guess that might be wrong.
376
+
377
+ **Date ranges.** A parameter whose `type` is `date_range` is answered by the
378
+ same calendar in two clicks: the first sets the start, the second the end, and the pair
379
+ commits as one answer. The days between them band as the user moves across the
380
+ calendar, so the span being chosen is visible before it is committed. Paging the
381
+ month between the two clicks is expected (that is how a span crosses months),
382
+ and <kbd>Esc</kbd> drops the start and lets them begin again. Clicking the end
383
+ before the start is fine; the two are ordered on the way in.
384
+
385
+ It commits as one parameter, written as a span,
386
+ `September 11 - October 13`, with the year on whichever end needs it, and both
387
+ ends are also recorded on the completed parameter's `metadata` as `YYYY-MM-DD`,
388
+ under the `DATE_RANGE_META_START` / `DATE_RANGE_META_END` keys this package
389
+ exports (`aiaDateRangeStart` / `aiaDateRangeEnd`), so you never have to parse
390
+ the prose. Re-editing one re-opens the calendar with both ends marked.
391
+
392
+ **Typing** while the calendar is open does not filter it. The text is treated as
393
+ a new query, so suggestions refresh as the user types, which helps when someone
394
+ would rather describe what they want than pick a day.
395
+
396
+ ## Time picker
397
+
398
+ When the next parameter is a time, the dropdown shows a time wheel instead of a
399
+ list of options. As with dates, which parameters are times is the server's call:
400
+ one whose `type` is `time` gets the wheel, and one without it keeps its option
401
+ list, however time-like its options look.
402
+
403
+ Nothing is required to switch it on. The options the server still sends for a
404
+ time parameter are never shown, but they choose where the wheel opens: on the
405
+ middle of the times suggested (`6 PM`, `7 PM`, `8 PM` opens on 7:00 PM), or on
406
+ the next whole hour when there are none.
407
+
408
+ **What the user can do**
409
+
410
+ | Input | Result |
411
+ |---|---|
412
+ | Scroll or tap a wheel | Turns that wheel; the time on the top rows is the time. Commits nothing |
413
+ | <kbd>↓</kbd> / <kbd>↑</kbd> in the input | Moves the time 5 minutes later / earlier |
414
+ | <kbd>Enter</kbd> | Commits the time — once the wheel has been moved. Until then it is only a suggestion, and Enter submits as usual |
415
+ | Done | Commits the time |
416
+ | <kbd>Esc</kbd> | Puts a moved wheel back on its suggested time |
417
+ | <kbd>→</kbd> at the end of the input | Skips the parameter, same as any other pill |
418
+
419
+ **The committed value** is written the way a person would write it, always in
420
+ English: `7:30 PM`, `12:05 AM`. It arrives as an ordinary completed parameter
421
+ (bold in the input, in `completed_params` on submit) with the server's lead-in
422
+ before it when there is one (`at 7:30 PM`). The exact time is also recorded on
423
+ the parameter's `metadata` as 24-hour `HH:MM` under the `TIME_META_KEY` key
424
+ (`aiaTime`), so you never have to parse the prose:
425
+
426
+ ```ts
427
+ import { parseTime, TIME_META_KEY } from "@magicx-eng/ai-autocomplete-vanilla";
428
+
429
+ const time = param.metadata?.[TIME_META_KEY]; // "19:30"
430
+ const minutes = parseTime(param.text); // 1170 — minutes since midnight, or null
431
+ ```
432
+
433
+ **Re-editing** a committed time re-opens the wheel on it.
434
+
435
+ **Typing** while the wheel is open does not filter anything. As with the
436
+ calendar, the text is treated as a new query.
437
+
438
+ ## Multiple selections
439
+
440
+ - A suggestion with `type: { kind: "multi_select" }` shows checkbox options and a Done button.
441
+ - The option list shows three rows and scrolls the rest, on every screen size, so Done is always in view right under it.
442
+ - A click or tap on a row's checkbox (or just beside it) ticks the row and waits for Done. A click or tap anywhere else on the row (its text, or the space after it) answers right away with that option, together with anything already ticked. Space and Enter always tick. In code: `selectOption(option, { commit: true })`.
443
+ - Select rows to toggle values. Typing filters the options and keeps the current picks.
444
+ - Done joins the picks in selection order with the UI language's word for "and".
445
+ - Each value has its own `completed_params` entry. The input shows one chip for the group.
446
+ - Remove the group chip to change the answer. Group chips do not open for editing.
447
+ - Done without picks skips the question. Typing a phrase with no matching options closes the question and keeps that phrase.
448
+ - Space toggles the highlighted row when nothing is typed for the question. Enter commits the picks, or selects the highlighted row when no values are picked.
449
+ - Headless integrations can call `toggleMultiSelectOption(option)` and `commitMultiSelect()`.
450
+ - `multiSelectView.picked` contains the selected option texts. The view is null outside a multi_select question.
451
+
452
+ ## Location search
453
+
454
+ A location parameter is answered one of two ways, depending on whether the
455
+ server sends options for it. As with dates, which parameters are
456
+ locations is the server's call: it marks them `type: { kind: "location" }`.
457
+
458
+ - **With options** (a catalog with a `city` field, say), it is an ordinary
459
+ option list. Nothing changes.
460
+ - **Without options**, the dropdown shows a search field instead. Typing in it
461
+ searches places through the MagicX server, which proxies a location provider,
462
+ and lists what it finds; any city, address or landmark can be picked.
463
+
464
+ Nothing is required to switch it on. The field searches
465
+ `…/locations/autocomplete`, next to your `/suggest` endpoint
466
+ (`/api/suggest` → `/api/locations/autocomplete`). If `apiConfig.endpoint`
467
+ points at a proxy with its own path, set `apiConfig.locationEndpoint` too.
468
+ The SDK calls that route directly; `/suggest` doesn't need to say anything
469
+ about it. If the route answers 404 (a server without it), the field takes
470
+ typed text for the rest of the session. Any other failure (401, 429, a
471
+ timeout) only costs that one search: Enter commits the typed text, and the
472
+ next phrase tries again.
473
+
474
+ **Turning the search off.** Set `locationSearch: false` to keep the field but take typed text
475
+ only — nothing the user types is sent for a lookup.
476
+
477
+ **Your own places.** An `optionOverrides` entry for the parameter takes
478
+ priority over the search: the parameter is answered from your list like any
479
+ other option list (a store's branches, say), and the search never runs.
480
+
481
+ **What the user can do**
482
+
483
+ | Input | Result |
484
+ |---|---|
485
+ | The pill coming up while the user is typing | Focus moves into the search field, so the place is typed straight into it |
486
+ | Typing in the field | Searches after a short pause (2 characters or more) |
487
+ | <kbd>↓</kbd> / <kbd>↑</kbd> | Moves through the places found |
488
+ | <kbd>Enter</kbd> or a tap on a place | Commits it. With nothing found, Enter commits the typed text as written. So does Enter pressed before the search answers (within the 250ms pause): nothing is highlighted yet |
489
+ | <kbd>Esc</kbd>, or <kbd>Backspace</kbd> in an empty field | Back to the input, the pill left open |
490
+ | <kbd>Tab</kbd> / <kbd>Shift</kbd>+<kbd>Tab</kbd> | On to the next control / back to the input, as for any field |
491
+
492
+ **The committed value** reads as the place and its region (`Seattle, WA`), with
493
+ the server's lead-in before it when there is one (`in Seattle, WA`). A picked
494
+ place also records the provider's place ID on the parameter's `metadata` under
495
+ `LOCATION_META_KEY` (`aiaPlace`); typed text records none:
496
+
497
+ ```ts
498
+ import { LOCATION_META_KEY } from "@magicx-eng/ai-autocomplete-vanilla";
499
+
500
+ const place = param.metadata?.[LOCATION_META_KEY]; // { id: "ChIJ…" } | undefined
501
+ ```
502
+
503
+ **Re-editing** a committed place re-opens the field on it, selected, so typing
504
+ replaces it.
505
+
506
+ **In your own UI** (Tier 3, or a custom dropdown): for a location pill,
507
+ `state.activeFormatType` is `"location"`, `state.filteredOptions` is empty, and
508
+ `state.locationView` holds `{ query, places, status, highlighted }`. Call
509
+ `ac.setLocationQuery(text)` as the user types (the SDK debounces and cancels
510
+ the searches), `ac.moveLocationHighlight(±1)` for the arrow keys, and
511
+ `ac.commitLocation(index?)` to answer. If your field lives outside the input,
512
+ call `ac.setLocationFieldFocused(true)` *before* moving focus into it (and
513
+ `false` when it leaves), so the input's blur doesn't close the panel.
514
+
515
+ ---
516
+
517
+ ## CSS variables
518
+
519
+ Override these on the container element. The variables are declared with `:where()` (zero specificity), so a value you set on the container always wins without `!important`.
520
+
521
+ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-weight` on its container or an ancestor. Omit them to retain the default `10px` radius and `300` weight; changing `mode` does not reset these overrides. In dropdown-only integrations, style your own input directly.
522
+
523
+ ```css
524
+ .my-search {
525
+ --aia-input-radius: 0;
526
+ --aia-written-text-font-weight: 500;
527
+ }
528
+ ```
529
+
530
+ | Variable | Default (light) | Default (dark) | Description |
531
+ |---|---|---|---|
532
+ | `--aia-font-family` | `inherit` | `inherit` | Font used by the library. Defaults to `inherit` so the library picks up your page's font automatically. Set this to pin a specific font on the library without changing the surrounding page. |
533
+ | `--aia-pill-bg` | `#bdbdbd` | `#bdbdbd` | Pill background |
534
+ | `--aia-pill-color` | `#000000` | `#ffffff` | Pill text |
535
+ | `--aia-pill-font-size` | `19px` | `19px` | Pill font size |
536
+ | `--aia-option-bg` | `transparent` | `transparent` | Option background (highlighted) |
537
+ | `--aia-option-color` | `#000000` | `#ffffff` | Option text |
538
+ | `--aia-option-color-selected` | `#000000` | `#ffffff` | Highlighted option text |
539
+ | `--aia-option-font-size` | `19px` | `19px` | Option font size |
540
+ | `--aia-written-text-color` | `#000000` | `#ffffff` | Input text |
541
+ | `--aia-written-text-font-size` | `19px` | `19px` | Input text font size |
542
+ | `--aia-written-text-font-weight` | `300` | `300` | Written text weight in the full input. Completed chips keep their own typography. |
543
+ | `--aia-caret-color` | `--aia-written-text-color` | `--aia-written-text-color` | Editor caret color. Override independently of input text color. |
544
+ | `--aia-submit-bg` | `#000000` | `#ffffff` | Submit button background. Solid + full-opacity at rest, even when the input is empty/disabled. |
545
+ | `--aia-submit-color` | `#ffffff` | `#000000` | Submit button arrow color |
546
+ | `--aia-submit-bg-disabled` | `--aia-submit-bg` | `--aia-submit-bg` | Submit background when disabled (empty input). Defaults to the enabled background so themed colors aren't washed out. Set this for a faded rest state. |
547
+ | `--aia-submit-bg-ready` | `--aia-submit-bg` | `--aia-submit-bg` | Submit background once the request is complete (the button also lifts slightly). Defaults to the enabled background. |
548
+ | `--aia-submit-color-disabled` | `--aia-submit-color` | `--aia-submit-color` | Submit arrow color when disabled. Defaults to the enabled color. |
549
+ | `--aia-border` | `rgba(17, 24, 39, 0.14)` | `#505050` | Input container border color |
550
+ | `--aia-input-radius` | `10px` | `10px` | Full input corner radius. Set `0` for square corners. |
551
+ | `--aia-shadow` | `none` | `none` | Input container elevation (box-shadow). Flat by default; set it to add one |
552
+ | `--aia-dropdown-offset` | `13px` | `13px` | Gap between the input box and the dropdown (the dropdown's margin toward the input). |
553
+ | `--aia-content-inset-left` | `16px` | `16px` | Left inset of the SDK's content: the input wrapper's left padding, and the line the dropdown's content (parameter label, option text, product strip) starts on. Set it when you pad the field to clear a leading icon of your own, so the dropdown's content stays aligned under the typed text. Practical minimum is `10px` (the option text's own inset); both surfaces floor it there. |
554
+ | `--aia-footer-gap` | `12px` | `12px` | Breathing room above the dropdown footer (badge / keyboard hints), additive to the dropdown's 8px section gap. |
555
+ | `--aia-footer-chip-bg` | `--aia-surface` at 65% | `--aia-surface` at 65% | Fill behind the footer's keyboard hint and AI-Autocomplete badge. The option list scrolls under the footer, so this keeps both legible over the row passing behind them. `transparent` on the glass surface. |
556
+ | `--aia-dropdown-bg` | — | — | Optional bg color the dropdown's "glass" rim shadow tints toward. Set this to the page background behind the dropdown so the bottom-corner glow blends seamlessly. |
557
+ | `--aia-scrollbar-thumb` | `rgba(0, 0, 0, 0.3)` | `rgba(0, 0, 0, 0.3)` | No longer used: the option list hides its scrollbar in every browser. Kept so existing overrides don't break. |
558
+ | `--aia-streak-rgb` | `99, 102, 241` | `255, 255, 255` | Comma-separated RGB triplet tinting the datepicker's pressed cell, and its selected cell when `--aia-date-selected-bg` is unset. The today ring uses `--aia-date-today-ring`, not this. |
559
+ | `--aia-product-card-width` | `116px` | `116px` | Width of a product card in the strip. The media tile is square, so this also sets its height. |
560
+ | `--aia-product-gap` | `8px` | `8px` | Gap between product cards. |
561
+ | `--aia-product-bg` | `transparent` | `transparent` | Product card background. |
562
+ | `--aia-product-bg-active` | `--aia-option-bg` | `--aia-option-bg` | Product card background on hover. |
563
+ | `--aia-product-media-bg` | `--aia-skeleton-bg` | `--aia-skeleton-bg` | Placeholder fill of the product tile: shown until the photo loads, and behind both fallback tiles (placeholder pictogram or title initial) used when an image URL is missing, blank or fails to load. Once a photo loads the tile is transparent. |
564
+ | `--aia-scroll-arrow-color` | `--aia-option-color` | `--aia-option-color` | Chevron color of the arrow (`--aia-scroll-arrow-color-hover` on hover). |
565
+ | `--aia-placeholder-fade` | `120ms` | `120ms` | Fade-out of the outgoing placeholder phrase when the starting-state placeholder changes (the incoming one types itself in). |
566
+ | `--aia-product-image-radius` | `8px` | `8px` | Corner radius of a product photo narrower than its square tile (a tall one), which is scaled to fit rather than cropped. A photo that fills the tile takes the tile's own 8px corners. |
567
+ | `--aia-product-placeholder-image` | storefront pictogram | storefront pictogram | The pictogram used by `productImageFallback: "image"` (the default) when an image URL is missing, blank or fails to load. Defaults to a two-tone storefront inlined as a data URI. Set any `url(...)` to swap it; it is centered and contained over `--aia-product-media-bg`. Does not affect `"initial"` tiles. |
568
+ | `--aia-product-title-color` | `--aia-option-color-selected` | `--aia-option-color-selected` | Product title text. Follows the option colors by default, so theming the panel moves suggestions and products together. |
569
+ | `--aia-product-price-color` | `--aia-option-color-selected` | `--aia-option-color-selected` | Product price text. |
570
+ | `--aia-product-compare-at-color` | `currentColor` | `currentColor` | The struck price before a markdown. Defaults to the price's colour. |
571
+ | `--aia-product-compare-at-opacity` | `0.6` | `0.6` | How far the struck price is dimmed. |
572
+ | `--aia-product-vendor-color` | `--aia-option-color` | `--aia-option-color` | Product vendor line. |
573
+ | `--aia-product-focus-ring` | `--aia-option-color-selected` | `--aia-option-color-selected` | Focus ring drawn on a keyboard-focused card. |
574
+ | `--aia-products-label-color` | `--aia-option-color` | `--aia-option-color` | "Best match" section label. |
575
+ | `--aia-product-title-font-size` | `12px` | `12px` | Product title font size. |
576
+ | `--aia-product-price-font-size` | `11px` | `11px` | Product price font size. |
577
+ | `--aia-product-vendor-font-size` | `10px` | `10px` | Product vendor font size. |
578
+ | `--aia-products-label-font-size` | `11px` | `11px` | Section label font size. |
579
+ | `--aia-date-panel-width` | `312px` | `312px` | Max width of the whole dropdown panel while the calendar is up — the panel narrows to calendar size. |
580
+ | `--aia-date-cell-size` | `26px` | `26px` | Size of a day's square — the box that carries the highlight, the today ring and the selected fill. |
581
+ | `--aia-date-row-height` | `28px` | `28px` | Height of one week row. Lower it to fit a 6-week month in a shorter dropdown. |
582
+ | `--aia-date-row-min-height` | `20px` | `20px` | The shortest a week row may get when the dropdown is fitted to a short window and the weeks share what is left. Never applies above `--aia-date-row-height`. |
583
+ | `--aia-date-cell-font-size` | `13px` | `13px` | Day-number font size. |
584
+ | `--aia-date-month-font-size` | `14px` | `14px` | Font size of the "March 2026" header. |
585
+ | `--aia-date-weekday-font-size` | `11px` | `11px` | Font size of the S/M/T/W/T/F/S column letters. |
586
+ | `--aia-date-today-ring` | `--aia-option-color` | `--aia-option-color` | Outline drawn around today's date. |
587
+ | `--aia-date-selected-bg` | white at 12% | white at 12% | Fill behind the date a re-edited parameter already holds. |
588
+ | `--aia-date-range-bg` | white at 6% | white at 6% | Band across the days between the two ends of a picked date range. The ends themselves use `--aia-date-selected-bg`. |
589
+ | `--aia-time-panel-width` | `240px` | `240px` | Max width of the whole dropdown panel while the time wheel is up. |
590
+ | `--aia-time-font-size` | `15px` | `15px` | The time wheel's numbers and its `:` separator. |
591
+ | `--aia-time-band-bg` | white at 8% | white at 8% | The band behind the wheels' top rows — the chosen time. |
592
+ | `--aia-time-done-bg` | white at 10% | white at 10% | The time wheel's Done button. |
593
+ | `--aia-time-done-bg-hover` | white at 16% | white at 16% | The Done button on hover. |
594
+ | `--aia-time-done-color` | `--aia-option-color-selected` | `--aia-option-color-selected` | The Done button's text. |
595
+ | `--aia-location-field-bg` | `--aia-streak-rgb` at 6% (indigo) | `--aia-streak-rgb` at 6% (white) | The location search field. |
596
+ | `--aia-location-field-radius` | `10px` | `10px` | Corner radius of the location search field. |
597
+ | `--aia-location-font-size` | `15px` | `15px` | The location field's text and the place names. |
598
+ | `--aia-location-row-bg-highlighted` | `--aia-streak-rgb` at 8% (indigo) | `--aia-streak-rgb` at 8% (white) | The highlighted (or hovered) place. |
599
+ | `--aia-skeleton-bg` | `rgba(189, 189, 189, 0.083)` | `#1a1b1d` | Fill color for the loading skeleton bars and the masked text in cached pills/options, and of the option and chip image tiles while their picture loads (unless `--aia-option-image-bg` / `--aia-chip-image-bg` are set). |