@nexub/elements 11.7.0 → 11.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,107 @@
1
+ var k={selectPlaceholder:"Select\u2026",noResults:"No results found.",searching:"Searching\u2026",searchFailed:"Search failed. Try again.",countryCode:(n,t)=>`Country code, ${n} +${t}`,invalidPhone:"Enter a valid phone number."};var U="US1GB44RU7AU61IT39NO47FI358MA212RE262GP590CW599AF93AL355DZ213AS1AD376AO244AI1AG1AR54AM374AW297AT43AZ994BS1BH973BD880BB1BY375BE32BZ501BJ229BM1BT975BO591BA387BW267BR55IO246VG1BN673BG359BF226BI257KH855CM237CA1CV238BQ599KY1CF236TD235CL56CN86CX61CC61CO57KM269CG242CD243CK682CR506CI225HR385CU53CY357CZ420DK45DJ253DM1DO1EC593EG20SV503GQ240ER291EE372SZ268ET251FK500FO298FJ679FR33GF594PF689GA241GM220GE995DE49GH233GI350GR30GL299GD1GU1GT502GG44GN224GW245GY592HT509HN504HK852HU36IS354IN91ID62IR98IQ964IE353IM44IL972JM1JP81JE44JO962KZ7KE254KI686XK383KW965KG996LA856LV371LB961LS266LR231LY218LI423LT370LU352MO853MG261MW265MY60MV960ML223MT356MH692MQ596MR222MU230YT262MX52FM691MD373MC377MN976ME382MS1MZ258MM95NA264NR674NP977NL31NC687NZ64NI505NE227NG234NU683NF672KP850MK389MP1OM968PK92PW680PS970PA507PG675PY595PE51PH63PL48PT351PR1QA974RO40RW250BL590SH290KN1LC1MF590PM508VC1WS685SM378ST239SA966SN221RS381SC248SL232SG65SX1SK421SI386SB677SO252ZA27KR82SS211ES34LK94SD249SR597SJ47SE46CH41SY963TW886TJ992TZ255TH66TL670TG228TK690TO676TT1TN216TR90TM993TC1TV688UG256UA380AE971UY598UZ998VU678VA39VE58VN84VI1WF681EH212YE967ZM260ZW263AX358",u=Object.fromEntries(Array.from(U.matchAll(/([A-Z]{2})(\d+)/g),n=>[n[1],n[2]])),D={IN:[10,10,"5 5"],AE:[8,9,"2 3 4"],SA:[9,9,"2 3 4"],QA:[8,8,"4 4"],KW:[8,8,"4 4"],BH:[8,8,"4 4"],OM:[8,8,"4 4"],US:[10,10,"3 3 4"],CA:[10,10,"3 3 4"],GB:[9,10,"4 6"],SG:[8,8,"4 4"],MY:[8,10,"2 4 4"],AU:[9,9,"3 3 3"],DE:[6,11,"3 4 4"],FR:[9,9,"1 2 2 2 2"],ID:[8,12,"3 4 4"],PH:[10,10,"3 3 4"],LK:[9,9,"2 3 4"],BD:[10,10,"4 6"],NP:[8,10,"3 3 4"],PK:[10,10,"3 7"]},O=n=>n.replace(/\D/g,"");function f(n){return u[n.toUpperCase()]??""}function N(n,t){let e=O(n),i=D[t.toUpperCase()]?.[2].split(" ").map(Number),r=[];if(i)for(let o=0;o<i.length&&e;o++){let s=o===i.length-1?e.length:i[o];r.push(e.slice(0,s)),e=e.slice(s)}else{for(;e.length>4;e=e.slice(3))r.push(e.slice(0,3));e&&r.push(e)}return r.join(" ")}function x(n,t){let e=f(t),i=O(n);return e&&i?`+${e}${i}`:""}var $=(n,t)=>{let e=f(t),[i,r]=D[t]??[4,14];return!!e&&n.length>=i&&n.length<=r&&e.length+n.length<=15};function m(n,t="US"){let e=t.toUpperCase(),i=n.trim(),r=O(i);if(/^(\+|00)/.test(i)){i[0]!=="+"&&(r=r.slice(2));let s=f(e);if(s&&r.startsWith(s))r=r.slice(s.length);else for(let a=3;a>0;a--){let c=Object.keys(u).find(l=>u[l]===r.slice(0,a));if(c){e=c,r=r.slice(a);break}}}e!=="IT"&&e!=="VA"&&(r=r.replace(/^0/,"")),r=r.slice(0,15-(f(e).length||1));let o=f(e);return{country:e,national:r,e164:x(r,e),valid:$(r,e),dialCode:o?`+${o}`:""}}function L(n,t="US"){try{let e=n?new Intl.Locale(n).maximize().region:void 0;if(e&&u[e])return e}catch{}return t}var b="var(--motion-spring-effects-fast-duration) var(--motion-spring-effects-fast-easing)";var C=`
2
+ :host { display: block; font-family: var(--font-family-sans, inherit); color: var(--color-on-surface); }
3
+ :host([hidden]) { display: none; }
4
+ /* The field draws focus itself; no second ring on the host. */
5
+ :host(:focus-within) { outline: none !important; }
6
+ * { box-sizing: border-box; }
7
+ .field {
8
+ display: flex; align-items: center; gap: 0.5rem; inline-size: 100%;
9
+ block-size: var(--size-control-md, 2.5rem); padding-inline: 0.875rem;
10
+ border: 1px solid var(--field-border, var(--color-outline));
11
+ border-radius: var(--field-radius, var(--shape-field));
12
+ background: var(--field-bg, var(--color-surface-container-lowest));
13
+ color: var(--field-fg, var(--color-on-surface));
14
+ font-size: var(--type-body-md-size, 1rem); line-height: var(--type-body-md-lineHeight, 1.5rem);
15
+ }
16
+ :host([size='sm']) .field {
17
+ block-size: var(--size-control-sm, 2rem); padding-inline: 0.75rem; gap: 0.375rem;
18
+ font-size: var(--type-body-sm-size, 0.875rem); line-height: var(--type-body-sm-lineHeight, 1.25rem);
19
+ }
20
+ :host([size='lg']) .field { block-size: var(--size-control-lg, 3rem); padding-inline: 1rem; }
21
+ .field:hover { border-color: var(--color-on-surface-variant); }
22
+ .field:focus-within, .field:focus-within:hover { border-color: var(--color-primary); box-shadow: inset 0 0 0 1px var(--color-primary); }
23
+ .field[data-invalid], .field[data-invalid]:hover { border-color: var(--color-error); }
24
+ .field[data-invalid]:focus-within { border-color: var(--color-error); box-shadow: inset 0 0 0 1px var(--color-error); }
25
+ .field[data-readonly], .field[data-readonly]:hover { border-color: var(--color-outline-variant); background: var(--color-surface-container-low); }
26
+ .field[data-disabled], .field[data-disabled]:hover {
27
+ cursor: not-allowed; border-color: var(--color-outline-variant);
28
+ background: var(--color-surface-container-low); color: var(--color-text-disabled);
29
+ }
30
+ /* 11.9: inline-size 100% (not the input's own ~20ch width) so the field's narrowest size is its
31
+ padding and button: at a 20rem viewport (WCAG 1.4.10 reflow) a grid or flex parent no longer overflows. */
32
+ input {
33
+ flex: 1; min-inline-size: 0; inline-size: 100%; block-size: 100%; margin: 0; padding: 0; border: 0; outline: none;
34
+ background: transparent; color: inherit; font: inherit; font-variant-numeric: tabular-nums;
35
+ }
36
+ input::placeholder { color: var(--color-on-surface-muted); opacity: 1; }
37
+ input:disabled { cursor: not-allowed; color: var(--color-text-disabled); }
38
+ @media (prefers-reduced-motion: no-preference) {
39
+ .field { transition: border-color ${b}, box-shadow ${b}; }
40
+ }
41
+ @media (forced-colors: active) {
42
+ .field { border-color: FieldText; }
43
+ .field:focus-within { outline: 0.125rem solid Highlight; outline-offset: 0; }
44
+ .field[data-invalid] { border-style: dashed; }
45
+ .field[data-disabled] { border-color: GrayText; color: GrayText; }
46
+ }
47
+ `,z=new Map;function v(n){let t=z.get(n);return t||(t=new CSSStyleSheet,t.replaceSync(n),z.set(n,t)),t}var j=typeof HTMLElement>"u"?class{}:HTMLElement,E=class extends j{static formAssociated=!0;internals;root;box;#t="";#i=!1;#r=!1;#e=!1;static get observedAttributes(){return["value","required","disabled","readonly","size","aria-label","invalid"]}constructor(){super(),this.internals=this.attachInternals(),this.root=this.attachShadow({mode:"open",delegatesFocus:!0}),this.root.adoptedStyleSheets=[v(C)],this.box=document.createElement("div"),this.box.className="field",this.box.setAttribute("part","field"),this.root.append(this.box),this.addEventListener("invalid",()=>{this.#e=!0,this.render()})}connectedCallback(){this.#i||(this.#t=this.sanitize(this.initial())),this.render(),queueMicrotask(()=>this.nameControl())}attributeChangedCallback(t,e,i){e!==i&&(t==="value"&&!this.#i&&(this.#t=this.sanitize(i??this.initial())),t==="aria-label"&&this.nameControl(),this.render())}get value(){return this.#t}set value(t){this.#i=!0,this.#t=this.sanitize(String(t??"")),this.render()}get defaultValue(){return this.getAttribute("value")??""}set defaultValue(t){this.setAttribute("value",t)}get name(){return this.getAttribute("name")??""}set name(t){this.setAttribute("name",t)}get required(){return this.hasAttribute("required")}set required(t){this.toggleAttribute("required",!!t)}get disabled(){return this.hasAttribute("disabled")}set disabled(t){this.toggleAttribute("disabled",!!t)}get readOnly(){return this.hasAttribute("readonly")}set readOnly(t){this.toggleAttribute("readonly",!!t)}get invalid(){return this.hasAttribute("invalid")}set invalid(t){this.toggleAttribute("invalid",!!t)}get size(){let t=this.getAttribute("size");return t==="sm"||t==="lg"?t:"md"}set size(t){this.setAttribute("size",t)}get form(){return this.internals.form}get labels(){return this.internals.labels}get validity(){return this.internals.validity}get validationMessage(){return this.internals.validationMessage}get willValidate(){return this.internals.willValidate}checkValidity(){return this.internals.checkValidity()}reportValidity(){return this.internals.reportValidity()}focus(t){this.control.focus(t)}blur(){this.control.blur()}formResetCallback(){this.#i=!1,this.#e=!1,this.reset(),this.#t=this.sanitize(this.initial()),this.render()}formDisabledCallback(t){this.#r=t,this.render()}formStateRestoreCallback(t){typeof t=="string"&&(this.value=t)}initial(){return this.getAttribute("value")??""}upgrade(...t){let e=this;for(let i of t){if(!Object.prototype.hasOwnProperty.call(this,i))continue;let r=e[i];delete e[i],e[i]=r}}reset(){}resanitize(){this.#t=this.sanitize(this.#i?this.#t:this.initial())}get isDisabled(){return this.disabled||this.#r}setValue(t){let e=this.sanitize(t),i=e!==this.#t;return this.#i=!0,this.#t=e,i}touch(){this.#e=!0}emit(t){this.dispatchEvent(new Event(t,{bubbles:!0,composed:t==="input"}))}render(){let t=this.check();this.internals.setFormValue(this.#t),t&&!this.readOnly&&!this.isDisabled?this.internals.setValidity({[t.kind]:!0},t.message,this.control):this.internals.setValidity({});let e=!!t&&this.#e&&!this.readOnly||this.invalid;this.box.toggleAttribute("data-invalid",e),this.box.toggleAttribute("data-disabled",this.isDisabled),this.box.toggleAttribute("data-readonly",this.readOnly),this.control.disabled=this.isDisabled,"readOnly"in this.control?this.control.readOnly=this.readOnly:this.control.setAttribute("aria-readonly",String(this.readOnly)),this.control.setAttribute("aria-required",String(this.required)),this.control.setAttribute("aria-invalid",String(e)),this.update()}nameControl(){let t=this.getAttribute("aria-label"),e=Array.from(this.internals.labels??[]);if(!e.length){let r=this.getRootNode(),o=this.id?Array.from(r.querySelectorAll("label[for]")).filter(a=>a.htmlFor===this.id):[],s=this.closest("label");e=s&&!o.includes(s)?[...o,s]:o}let i=t??e.map(r=>r.textContent?.trim()).filter(Boolean).join(" ");i?this.control.setAttribute("aria-label",i):this.control.removeAttribute("aria-label")}};var P="http://www.w3.org/2000/svg",A=n=>{let t=document.createElementNS(P,"svg"),e={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"};for(let[i,r]of Object.entries(e))t.setAttribute(i,r);for(let[i,r]of n){let o=document.createElementNS(P,i);for(let[s,a]of Object.entries(r))o.setAttribute(s,a);t.append(o)}return t},d=(n,t={})=>{let e=document.createElement(n);for(let[i,r]of Object.entries(t))r!==void 0&&e.setAttribute(i,r);return e},F=[["path",{d:"m6 9 6 6 6-6"}]],H=[["path",{d:"M20 6 9 17l-5-5"}]],y=n=>{let t=n.getAttribute("locale")||n.closest("[lang]")?.getAttribute("lang")||void 0;try{return t?Intl.getCanonicalLocales(t)[0]:void 0}catch{return}},R=n=>{try{return n.matches(":dir(rtl)")}catch{return n.closest("[dir]")?.getAttribute("dir")?.toLowerCase()==="rtl"}};var S=k,W="(max-width: 47.99rem)",V=500,G=n=>n.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase();var q=0,w=class{constructor(t,e,i,r,o){this.host=t;this.anchor=e;this.control=i;this.pick=r;this.refresh=o;this.list=d("div",{role:"listbox",id:this.#i,part:"listbox"}),this.popup.append(this.status,this.list),"popover"in this.popup&&(this.popup.popover="manual"),i.setAttribute("aria-controls",this.#i),i.setAttribute("aria-expanded","false"),this.popup.addEventListener("mousedown",s=>s.preventDefault()),this.list.addEventListener("click",s=>{let a=this.options[this.#n(s)];a&&!a.disabled&&this.pick(a)}),this.list.addEventListener("mousemove",s=>{let a=this.#n(s);a>=0&&a!==this.active&&!this.options[a].disabled&&this.setActive(a,!1)})}host;anchor;control;pick;refresh;popup=d("div",{class:"popup",part:"popup",hidden:""});status=d("div",{role:"status",class:"status"});list;options=[];active=-1;#t="";#i=`nx-list-${++q}`;#r="";#e=0;#n(t){let e=t.target.closest('[role="option"]');return e?Number(e.dataset.index):-1}get open(){return!this.popup.hidden}render(t,e,i){this.options=t,this.#t=e,i?this.list.setAttribute("aria-label",i):this.list.removeAttribute("aria-label");let r=[],o,s;t.forEach((a,c)=>{if(a.group!==s&&(s=a.group,o=void 0,s)){let h=`${this.#i}-g${c}`;o=d("div",{role:"group","aria-labelledby":h});let T=d("div",{role:"presentation",id:h,class:"heading"});T.textContent=s,o.append(T),r.push(o)}let l=`${this.#i}-${c}`,g=d("div",{role:"option",id:l,class:"option",part:"option","data-index":String(c),"aria-selected":String(a.value===e),"aria-disabled":a.disabled?"true":void 0,"aria-describedby":a.description?`${l}-d`:void 0}),p=d("span",{class:"label"});if(p.textContent=a.label,g.append(A(H),p),a.description){let h=d("span",{id:`${l}-d`,class:"description"});h.textContent=a.description,p.append(h)}o?o.append(g):r.push(g)}),this.list.replaceChildren(...r),this.active>=t.length&&(this.active=-1),this.setActive(this.active,!1)}setActive(t,e=!0){this.active=t;let i;for(let r of this.list.querySelectorAll('[role="option"]')){let o=Number(r.dataset.index)===t;r.toggleAttribute("data-active",o),o&&(i=r)}i&&this.open?(this.control.setAttribute("aria-activedescendant",i.id),e&&i.scrollIntoView?.({block:"nearest"})):this.control.removeAttribute("aria-activedescendant")}step(t,e,i=1){let r=t;for(let o=t+e;o>=0&&o<this.options.length&&i>0;o+=e)this.options[o].disabled||(r=o,i--);return r}first(){return this.step(-1,1)}last(){return this.step(this.options.length,-1)}indexOf(t){return this.options.findIndex(e=>e.value===t)}show(){if(!this.open){this.refresh(),this.popup.hidden=!1;try{this.popup.showPopover?.()}catch{}this.control.setAttribute("aria-expanded","true"),this.place(),window.addEventListener("resize",this.place),window.addEventListener("scroll",this.place,{capture:!0,passive:!0}),document.addEventListener("mousedown",this.#o,!0)}}hide(){if(this.open){try{this.popup.hidePopover?.()}catch{}this.popup.hidden=!0,this.active=-1,this.control.setAttribute("aria-expanded","false"),this.control.removeAttribute("aria-activedescendant"),window.removeEventListener("resize",this.place),window.removeEventListener("scroll",this.place,!0),document.removeEventListener("mousedown",this.#o,!0)}}#o=t=>{t.composedPath().includes(this.host)||this.hide()};place=()=>{if(!this.open||window.matchMedia?.(W).matches)return;let t=this.anchor.getBoundingClientRect(),e=this.popup.offsetHeight,i=document.documentElement.clientWidth||innerWidth,r=document.documentElement.clientHeight||innerHeight,o=4,s=t.bottom+o;s+e>r-o&&t.top-o-e>=o&&(s=t.top-o-e);let a=this.popup.style;a.setProperty("--nx-top",`${Math.max(o,s)}px`),a.setProperty("--nx-start",`${Math.max(0,R(this.host)?i-t.right:t.left)}px`),a.setProperty("--nx-width",`${t.right-t.left}px`)};get typing(){return this.#r!==""&&Date.now()-this.#e<=V}typeahead(t){let e=Date.now();this.#r=e-this.#e>V?t:this.#r+t,this.#e=e;let i=G(this.#r),r=[...i].every(l=>l===i[0]),o=r?i[0]:i,s=this.active>=0?this.active:this.indexOf(this.#t),a=s<0?0:s+(r?1:0),c=this.options.length;for(let l=0;l<c;l++){let g=(a+l)%c,p=this.options[g];if(!p.disabled&&[p.label,...p.keywords??[]].some(h=>G(h).startsWith(o)))return g}return-1}selectKey(t){let{key:e}=t,i=e.length===1&&!t.ctrlKey&&!t.metaKey&&!t.altKey,r=i&&(e!==" "||this.typing);if(!this.open){if(r){t.preventDefault(),this.refresh();let s=this.options[this.typeahead(e)];s&&this.pick(s)}else if(["ArrowDown","ArrowUp","Enter"," ","Home","End"].includes(e)){t.preventDefault(),this.show();let s=this.indexOf(this.#t);this.setActive(e==="Home"?this.first():e==="End"?this.last():s>=0&&!this.options[s].disabled?s:this.first())}return}let o;switch(e){case"ArrowDown":o=this.step(this.active,1);break;case"ArrowUp":if(t.altKey)return this.#s(t);o=this.active<0?this.last():this.step(this.active,-1);break;case"Home":o=this.first();break;case"End":o=this.last();break;case"PageDown":o=this.step(this.active,1,10);break;case"PageUp":o=this.step(this.active,-1,10);break;case"Enter":return this.#s(t);case"Tab":return this.#s();case"Escape":return t.preventDefault(),t.stopPropagation(),this.hide();default:if(!i)return;if(!r)return this.#s(t);if(o=this.typeahead(e),o<0)return t.preventDefault()}t.preventDefault(),this.setActive(o)}#s(t){t?.preventDefault();let e=this.options[this.active];e?this.pick(e):this.hide()}};function Y(n,t,e,i){if(n!=="badInput"&&n!=="typeMismatch"&&typeof document<"u"){let r=document.createElement("input");if(n==="valueMissing"?r.required=!0:(r.type=t,r[n==="rangeUnderflow"?"min":"max"]=e,r.value=t==="number"?String(Number(e)+(n==="rangeUnderflow"?-1:1)):n==="rangeUnderflow"?"0001-01-01".slice(0,e.length):"9999-12-31".slice(0,e.length)),r.validationMessage)return r.validationMessage}return i}var I=()=>Y("valueMissing","number","","Fill out this field.");var K=`
48
+ button { margin: 0; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; }
49
+ button:disabled { cursor: not-allowed; color: var(--color-text-disabled); }
50
+ button svg, .option svg { inline-size: 1rem; block-size: 1rem; flex: none; }
51
+ .trigger { flex: 1; align-self: stretch; display: flex; align-items: center; gap: 0.5rem; min-inline-size: 0; outline: none; text-align: start; }
52
+ /* One line, as the React trigger's line-clamp-1. */
53
+ .text { flex: 1; min-inline-size: 0; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; line-clamp: 1; overflow-wrap: anywhere; }
54
+ .trigger[data-placeholder] .text { color: var(--color-on-surface-muted); }
55
+ .trigger svg, .toggle svg, .country svg { color: var(--color-on-surface-variant); }
56
+ .toggle { flex: none; display: inline-flex; align-items: center; justify-content: center; inline-size: 1.75rem; block-size: 1.75rem; margin-inline-end: -0.5rem; border-radius: 999rem; }
57
+ .country {
58
+ flex: none; display: inline-flex; align-items: center; gap: 0.25rem; align-self: stretch;
59
+ margin-block: 0.25rem; margin-inline-start: -0.5rem; padding-inline: 0.5rem;
60
+ border-radius: var(--shape-control, 999rem); font-variant-numeric: tabular-nums; outline: none;
61
+ }
62
+ span.country { color: var(--color-on-surface-variant); }
63
+ .country[hidden] { display: none; }
64
+ button.country:hover { background: color-mix(in srgb, var(--color-on-surface) 8%, transparent); }
65
+ button.country:focus-visible { background: color-mix(in srgb, var(--color-on-surface) 12%, transparent); }
66
+ button.country:disabled { background: transparent; }
67
+ .popup {
68
+ position: fixed; z-index: var(--z-popover); margin: 0; inset: auto;
69
+ inset-block-start: var(--nx-top, 0); inset-inline-start: var(--nx-start, 0);
70
+ inline-size: max(var(--nx-width, 12rem), 12rem); max-inline-size: calc(100vw - 1rem); max-block-size: min(24rem, calc(100dvh - 1rem));
71
+ display: flex; flex-direction: column; overflow: auto; padding: 0.375rem; border: 0;
72
+ border-radius: var(--shape-container, 1rem); background: var(--color-surface-elevated, var(--color-surface));
73
+ color: var(--color-on-surface); box-shadow: var(--elevation-2);
74
+ font-size: var(--type-body-sm-size, 0.875rem); line-height: var(--type-body-sm-lineHeight, 1.25rem);
75
+ }
76
+ .popup[hidden] { display: none; }
77
+ .status { padding: 0.5rem 0.75rem; color: var(--color-on-surface-muted); }
78
+ .status:empty { display: none; }
79
+ .heading { padding: 0.5rem 0.5rem 0.25rem; font-size: var(--type-label-sm-size, 0.75rem); font-weight: var(--type-label-lg-weight, 600); color: var(--color-on-surface-muted); }
80
+ .option { display: flex; align-items: center; gap: 0.5rem; min-block-size: 2.25rem; padding: 0.375rem 0.5rem; border-radius: 0.625rem; cursor: default; }
81
+ .option svg { visibility: hidden; }
82
+ .option[aria-selected='true'] svg { visibility: visible; }
83
+ .option[data-active] { background: color-mix(in srgb, var(--color-on-surface) 8%, transparent); }
84
+ .option[aria-disabled='true'] { color: var(--color-text-disabled); }
85
+ .description { display: block; font-size: var(--type-label-sm-size, 0.75rem); color: var(--color-on-surface-muted); }
86
+ @media (max-width: 47.99rem) {
87
+ .popup {
88
+ inset-inline: 0; inset-block: auto 0; inline-size: 100%; max-inline-size: none; max-block-size: 50dvh;
89
+ border-start-start-radius: var(--shape-overlay, 1.5rem); border-start-end-radius: var(--shape-overlay, 1.5rem);
90
+ border-end-start-radius: 0; border-end-end-radius: 0;
91
+ padding-block-end: max(0.375rem, env(safe-area-inset-bottom));
92
+ }
93
+ .option { min-block-size: 2.75rem; }
94
+ }
95
+ @media (prefers-reduced-motion: no-preference) {
96
+ .popup:not([hidden]) { animation: nx-fade var(--motion-spring-effects-default-duration) var(--motion-spring-effects-default-easing); }
97
+ @keyframes nx-fade { from { opacity: 0; } }
98
+ .trigger svg, button.country { transition: rotate ${b}, background-color ${b}; }
99
+ }
100
+ [aria-expanded='true'] > svg { rotate: 180deg; }
101
+ @media (forced-colors: active) {
102
+ .popup { outline: 1px solid CanvasText; }
103
+ .option[data-active] { forced-color-adjust: none; background: Highlight; color: HighlightText; }
104
+ .option[aria-disabled='true'], button:disabled { color: GrayText; }
105
+ button.country:focus-visible { outline: 0.125rem solid Highlight; }
106
+ }
107
+ `;var Z=(n,t)=>{let e=0;for(let i=0;i<t&&e<n.length;e++)/\d/.test(n[e])&&i++;return e},M=class extends E{static get observedAttributes(){return[...super.observedAttributes,"country","default-country","countries","locale","placeholder"]}control=d("input",{type:"tel",inputmode:"tel",autocomplete:"tel-national",part:"input"});#t=d("button",{type:"button",role:"combobox",class:"country",part:"country","aria-haspopup":"listbox"});#i=d("span");#r=d("span",{class:"country",role:"img",hidden:""});#e;#n=null;#o=null;#s="";#l;#c;constructor(){super(),this.root.adoptedStyleSheets=[v(C),v(K)],this.#t.append(this.#i,A(F)),this.box.append(this.#t,this.#r,this.control),this.#e=new w(this,this.box,this.#t,e=>this.#m(e.value),()=>this.#p()),this.root.append(this.#e.popup),this.#t.addEventListener("click",()=>this.#e.open?this.#e.hide():this.#g()),this.#t.addEventListener("keydown",e=>this.#e.selectKey(e)),this.#t.addEventListener("keyup",e=>e.key===" "&&e.preventDefault()),this.#t.addEventListener("blur",()=>this.#e.hide());let t=this.control;t.addEventListener("focus",()=>this.#s=this.value),t.addEventListener("input",this.#b),t.addEventListener("blur",()=>this.#f()),t.addEventListener("keydown",e=>{e.key!=="Enter"||e.isComposing||(this.#f(),this.form?.requestSubmit())}),this.upgrade("value","country")}get country(){return this.#n??this.#a(this.getAttribute("country"))??this.#a(this.getAttribute("default-country"))??this.#a(L(y(this)))??this.#d?.[0]??"US"}set country(t){this.setAttribute("country",t)}get defaultCountry(){return this.getAttribute("default-country")??""}set defaultCountry(t){this.setAttribute("default-country",t)}get countries(){return this.getAttribute("countries")??""}set countries(t){this.setAttribute("countries",t)}get locale(){return this.getAttribute("locale")??""}set locale(t){this.setAttribute("locale",t)}get placeholder(){return this.getAttribute("placeholder")??""}set placeholder(t){this.setAttribute("placeholder",t)}get open(){return this.#e.open}close(){this.#e.hide()}disconnectedCallback(){this.close()}get#d(){let t=this.countries.split(/[\s,]+/).map(e=>e.toUpperCase()).filter(e=>u[e]);return t.length?t:void 0}#a(t){let e=t?.trim().toUpperCase(),i=this.#d;return e&&u[e]&&(!i||i.includes(e))?e:void 0}#h(t){let e=y(this);if(!this.#l||this.#l[0]!==e){let i;try{i=new Intl.DisplayNames(e?[e]:void 0,{type:"region"})}catch{i=void 0}this.#l=[e,i]}return this.#l[1]?.of(t)??t}attributeChangedCallback(t,e,i){if(e!==i)if(t==="country"){let r=this.#a(i);r&&this.#u(r)}else t==="countries"&&this.#n&&!this.#a(this.#n)&&this.#u(null);super.attributeChangedCallback(t,e,i)}#u(t){let{national:e}=m(this.value,this.country);this.#n=t,this.#o=null,e?this.setValue(x(e,this.country)):this.resanitize()}sanitize(t){if(!t.trim())return"";let e=m(t,this.country);return this.#a(e.country)?(this.#n=e.country,e.e164):""}reset(){this.#n=null,this.#o=null,this.#e.hide()}check(){return this.#o?{kind:"badInput",message:S.invalidPhone}:this.value?m(this.value,this.country).valid?void 0:{kind:"typeMismatch",message:S.invalidPhone}:this.required?{kind:"valueMissing",message:I()}:void 0}update(){let t=this.country,e=this.#o??N(m(this.value,t).national,t);this.control.value!==e&&(this.control.value=e),this.control.placeholder=this.placeholder;let i=f(t),r=S.countryCode(this.#h(t),i),o=this.#d?.length===1;this.#i.textContent=`+${i}`,this.#r.textContent=`+${i}`,this.#t.setAttribute("aria-label",r),this.#r.setAttribute("aria-label",r),this.#t.hidden=o,this.#r.hidden=!o,this.#t.disabled=this.isDisabled||this.readOnly,this.#e.open&&this.#p()}#p(){let t=this.#d,e=`${y(this)}|${this.countries}`;if(this.#c?.[0]!==e){let i=(t??Object.keys(u)).map(r=>({value:r,label:`${this.#h(r)} +${u[r]}`,keywords:[`+${u[r]}`]}));t||i.sort((r,o)=>r.label.localeCompare(o.label,y(this))),this.#c=[e,i]}this.#e.render(this.#c[1],this.country,this.#t.getAttribute("aria-label")??"")}#g(){this.#e.show(),this.#e.setActive(this.#e.indexOf(this.country))}#m(t){this.#e.hide();let e=this.country,i=this.value;this.#u(t),this.touch(),this.render(),this.country!==e&&this.dispatchEvent(new Event("countrychange",{bubbles:!0})),this.value!==i&&(this.emit("input"),this.#s=this.value,this.emit("change"))}#b=t=>{t.stopPropagation();let e=this.control,i=e.value,r=this.country,o=/^\s*(\+|00)/.test(i),s=m(i,r);this.#a(s.country)||(s=m(i.replace(/^[\s+0]+/,""),r),o=!1);let a=i.replace(/\D/g,"").slice(/^\s*0/.test(i)?2:0),c=f(s.country);this.#o=o&&!(a.startsWith(c)&&a.length>c.length)?i.replace(/[^\d+\s]/g,""):null;let l=i.slice(0,e.selectionStart??i.length).replace(/\D/g,""),g=l.startsWith("0")&&!s.national.startsWith("0")?1:0;this.#o||(this.#n=s.country);let p=this.setValue(this.#o?"":s.e164);if(this.render(),!this.#o){let h=Z(e.value,o?s.national.length:Math.max(0,l.length-g));e.setSelectionRange(h,h)}this.country!==r&&this.dispatchEvent(new Event("countrychange",{bubbles:!0})),p&&this.emit("input")};#f(){this.touch(),this.render(),this.value!==this.#s&&(this.#s=this.value,this.emit("change"))}};function B(n,t){typeof customElements<"u"&&!customElements.get(n)&&customElements.define(n,t)}B("nx-phone-input",M);export{M as NxPhoneInput};
@@ -0,0 +1,56 @@
1
+ import { F as FieldError } from './field-PQ7-S6JJ.js';
2
+ export { N as NxFieldElement } from './field-PQ7-S6JJ.js';
3
+ import { N as NxChoiceElement, L as ListPopup, a as NxOption } from './choice-jYQxGH_T.js';
4
+
5
+ /**
6
+ * `<nx-select>`: a form-associated single choice, the `@nexub/react` `Select`: a field-styled
7
+ * button (`role="combobox"`) that opens a listbox, the WAI-ARIA select-only combobox pattern.
8
+ * Options come from child `<option>` / `<optgroup>` elements (as in a native `<select>`) or the
9
+ * `options` property (`{ value, label, description?, disabled?, group? }[]`).
10
+ *
11
+ * Keyboard: closed, Arrow Down / Up, Enter, Space, Home and End open the list, and typing picks
12
+ * the option it starts (type-ahead, as a native select); open, arrows, Home / End and Page Up /
13
+ * Down move, typing jumps, Enter / Space pick, Escape closes, Tab picks and moves on.
14
+ *
15
+ * Attributes (reflected as properties): `name`, `value` (the default; else the child
16
+ * `<option selected>`), `placeholder`, `required`, `disabled`, `readonly`, `invalid`, `size`.
17
+ * A value that is none of the options is no value. Events: `input` and `change` when the user
18
+ * picks another option.
19
+ *
20
+ * @alpha
21
+ */
22
+ declare class NxSelect extends NxChoiceElement {
23
+ #private;
24
+ /** @internal */
25
+ protected readonly control: HTMLButtonElement;
26
+ /** @internal */
27
+ protected readonly list: ListPopup;
28
+ constructor();
29
+ /** The picked option, if any. */
30
+ get selectedOption(): NxOption | undefined;
31
+ /** Opens the list on the picked option (or the first). */
32
+ show(): void;
33
+ /** @internal Any of the option values; anything else is no value (kept while there are no options yet). */
34
+ protected sanitize(v: string): string;
35
+ /** @internal */
36
+ protected check(): FieldError;
37
+ /** @internal */
38
+ protected reset(): void;
39
+ /** @internal */
40
+ protected update(): void;
41
+ }
42
+
43
+ /**
44
+ * Registers `<nx-select>` only (11.9): a page that uses one element loads just its code.
45
+ * `@nexub/elements/define` registers every element.
46
+ *
47
+ * @alpha
48
+ */
49
+
50
+ declare global {
51
+ interface HTMLElementTagNameMap {
52
+ 'nx-select': NxSelect;
53
+ }
54
+ }
55
+
56
+ export { FieldError, ListPopup, NxChoiceElement, NxOption, NxSelect };
@@ -0,0 +1,107 @@
1
+ var E={selectPlaceholder:"Select\u2026",noResults:"No results found.",searching:"Searching\u2026",searchFailed:"Search failed. Try again.",countryCode:(s,e)=>`Country code, ${s} +${e}`,invalidPhone:"Enter a valid phone number."};var m="var(--motion-spring-effects-fast-duration) var(--motion-spring-effects-fast-easing)";var b=`
2
+ :host { display: block; font-family: var(--font-family-sans, inherit); color: var(--color-on-surface); }
3
+ :host([hidden]) { display: none; }
4
+ /* The field draws focus itself; no second ring on the host. */
5
+ :host(:focus-within) { outline: none !important; }
6
+ * { box-sizing: border-box; }
7
+ .field {
8
+ display: flex; align-items: center; gap: 0.5rem; inline-size: 100%;
9
+ block-size: var(--size-control-md, 2.5rem); padding-inline: 0.875rem;
10
+ border: 1px solid var(--field-border, var(--color-outline));
11
+ border-radius: var(--field-radius, var(--shape-field));
12
+ background: var(--field-bg, var(--color-surface-container-lowest));
13
+ color: var(--field-fg, var(--color-on-surface));
14
+ font-size: var(--type-body-md-size, 1rem); line-height: var(--type-body-md-lineHeight, 1.5rem);
15
+ }
16
+ :host([size='sm']) .field {
17
+ block-size: var(--size-control-sm, 2rem); padding-inline: 0.75rem; gap: 0.375rem;
18
+ font-size: var(--type-body-sm-size, 0.875rem); line-height: var(--type-body-sm-lineHeight, 1.25rem);
19
+ }
20
+ :host([size='lg']) .field { block-size: var(--size-control-lg, 3rem); padding-inline: 1rem; }
21
+ .field:hover { border-color: var(--color-on-surface-variant); }
22
+ .field:focus-within, .field:focus-within:hover { border-color: var(--color-primary); box-shadow: inset 0 0 0 1px var(--color-primary); }
23
+ .field[data-invalid], .field[data-invalid]:hover { border-color: var(--color-error); }
24
+ .field[data-invalid]:focus-within { border-color: var(--color-error); box-shadow: inset 0 0 0 1px var(--color-error); }
25
+ .field[data-readonly], .field[data-readonly]:hover { border-color: var(--color-outline-variant); background: var(--color-surface-container-low); }
26
+ .field[data-disabled], .field[data-disabled]:hover {
27
+ cursor: not-allowed; border-color: var(--color-outline-variant);
28
+ background: var(--color-surface-container-low); color: var(--color-text-disabled);
29
+ }
30
+ /* 11.9: inline-size 100% (not the input's own ~20ch width) so the field's narrowest size is its
31
+ padding and button: at a 20rem viewport (WCAG 1.4.10 reflow) a grid or flex parent no longer overflows. */
32
+ input {
33
+ flex: 1; min-inline-size: 0; inline-size: 100%; block-size: 100%; margin: 0; padding: 0; border: 0; outline: none;
34
+ background: transparent; color: inherit; font: inherit; font-variant-numeric: tabular-nums;
35
+ }
36
+ input::placeholder { color: var(--color-on-surface-muted); opacity: 1; }
37
+ input:disabled { cursor: not-allowed; color: var(--color-text-disabled); }
38
+ @media (prefers-reduced-motion: no-preference) {
39
+ .field { transition: border-color ${m}, box-shadow ${m}; }
40
+ }
41
+ @media (forced-colors: active) {
42
+ .field { border-color: FieldText; }
43
+ .field:focus-within { outline: 0.125rem solid Highlight; outline-offset: 0; }
44
+ .field[data-invalid] { border-style: dashed; }
45
+ .field[data-disabled] { border-color: GrayText; color: GrayText; }
46
+ }
47
+ `,A=new Map;function f(s){let e=A.get(s);return e||(e=new CSSStyleSheet,e.replaceSync(s),A.set(s,e)),e}var V=typeof HTMLElement>"u"?class{}:HTMLElement,g=class extends V{static formAssociated=!0;internals;root;box;#e="";#t=!1;#i=!1;#r=!1;static get observedAttributes(){return["value","required","disabled","readonly","size","aria-label","invalid"]}constructor(){super(),this.internals=this.attachInternals(),this.root=this.attachShadow({mode:"open",delegatesFocus:!0}),this.root.adoptedStyleSheets=[f(b)],this.box=document.createElement("div"),this.box.className="field",this.box.setAttribute("part","field"),this.root.append(this.box),this.addEventListener("invalid",()=>{this.#r=!0,this.render()})}connectedCallback(){this.#t||(this.#e=this.sanitize(this.initial())),this.render(),queueMicrotask(()=>this.nameControl())}attributeChangedCallback(e,t,i){t!==i&&(e==="value"&&!this.#t&&(this.#e=this.sanitize(i??this.initial())),e==="aria-label"&&this.nameControl(),this.render())}get value(){return this.#e}set value(e){this.#t=!0,this.#e=this.sanitize(String(e??"")),this.render()}get defaultValue(){return this.getAttribute("value")??""}set defaultValue(e){this.setAttribute("value",e)}get name(){return this.getAttribute("name")??""}set name(e){this.setAttribute("name",e)}get required(){return this.hasAttribute("required")}set required(e){this.toggleAttribute("required",!!e)}get disabled(){return this.hasAttribute("disabled")}set disabled(e){this.toggleAttribute("disabled",!!e)}get readOnly(){return this.hasAttribute("readonly")}set readOnly(e){this.toggleAttribute("readonly",!!e)}get invalid(){return this.hasAttribute("invalid")}set invalid(e){this.toggleAttribute("invalid",!!e)}get size(){let e=this.getAttribute("size");return e==="sm"||e==="lg"?e:"md"}set size(e){this.setAttribute("size",e)}get form(){return this.internals.form}get labels(){return this.internals.labels}get validity(){return this.internals.validity}get validationMessage(){return this.internals.validationMessage}get willValidate(){return this.internals.willValidate}checkValidity(){return this.internals.checkValidity()}reportValidity(){return this.internals.reportValidity()}focus(e){this.control.focus(e)}blur(){this.control.blur()}formResetCallback(){this.#t=!1,this.#r=!1,this.reset(),this.#e=this.sanitize(this.initial()),this.render()}formDisabledCallback(e){this.#i=e,this.render()}formStateRestoreCallback(e){typeof e=="string"&&(this.value=e)}initial(){return this.getAttribute("value")??""}upgrade(...e){let t=this;for(let i of e){if(!Object.prototype.hasOwnProperty.call(this,i))continue;let o=t[i];delete t[i],t[i]=o}}reset(){}resanitize(){this.#e=this.sanitize(this.#t?this.#e:this.initial())}get isDisabled(){return this.disabled||this.#i}setValue(e){let t=this.sanitize(e),i=t!==this.#e;return this.#t=!0,this.#e=t,i}touch(){this.#r=!0}emit(e){this.dispatchEvent(new Event(e,{bubbles:!0,composed:e==="input"}))}render(){let e=this.check();this.internals.setFormValue(this.#e),e&&!this.readOnly&&!this.isDisabled?this.internals.setValidity({[e.kind]:!0},e.message,this.control):this.internals.setValidity({});let t=!!e&&this.#r&&!this.readOnly||this.invalid;this.box.toggleAttribute("data-invalid",t),this.box.toggleAttribute("data-disabled",this.isDisabled),this.box.toggleAttribute("data-readonly",this.readOnly),this.control.disabled=this.isDisabled,"readOnly"in this.control?this.control.readOnly=this.readOnly:this.control.setAttribute("aria-readonly",String(this.readOnly)),this.control.setAttribute("aria-required",String(this.required)),this.control.setAttribute("aria-invalid",String(t)),this.update()}nameControl(){let e=this.getAttribute("aria-label"),t=Array.from(this.internals.labels??[]);if(!t.length){let o=this.getRootNode(),r=this.id?Array.from(o.querySelectorAll("label[for]")).filter(a=>a.htmlFor===this.id):[],n=this.closest("label");t=n&&!r.includes(n)?[...r,n]:r}let i=e??t.map(o=>o.textContent?.trim()).filter(Boolean).join(" ");i?this.control.setAttribute("aria-label",i):this.control.removeAttribute("aria-label")}};var S="http://www.w3.org/2000/svg",v=s=>{let e=document.createElementNS(S,"svg"),t={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"};for(let[i,o]of Object.entries(t))e.setAttribute(i,o);for(let[i,o]of s){let r=document.createElementNS(S,i);for(let[n,a]of Object.entries(o))r.setAttribute(n,a);e.append(r)}return e},l=(s,e={})=>{let t=document.createElement(s);for(let[i,o]of Object.entries(e))o!==void 0&&t.setAttribute(i,o);return t},z=[["path",{d:"m6 9 6 6 6-6"}]],O=[["path",{d:"M20 6 9 17l-5-5"}]];var M=s=>{try{return s.matches(":dir(rtl)")}catch{return s.closest("[dir]")?.getAttribute("dir")?.toLowerCase()==="rtl"}};var D=E,P="(max-width: 47.99rem)",C=500,N=s=>s.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase();function L(s){return Array.from(s.querySelectorAll("option"),e=>{let t=e.parentElement?.localName==="optgroup"?e.parentElement:void 0;return{value:e.value,label:e.label,disabled:e.disabled||!!t?.disabled,group:t?.label||void 0}})}var R=0,y=class{constructor(e,t,i,o,r){this.host=e;this.anchor=t;this.control=i;this.pick=o;this.refresh=r;this.list=l("div",{role:"listbox",id:this.#t,part:"listbox"}),this.popup.append(this.status,this.list),"popover"in this.popup&&(this.popup.popover="manual"),i.setAttribute("aria-controls",this.#t),i.setAttribute("aria-expanded","false"),this.popup.addEventListener("mousedown",n=>n.preventDefault()),this.list.addEventListener("click",n=>{let a=this.options[this.#s(n)];a&&!a.disabled&&this.pick(a)}),this.list.addEventListener("mousemove",n=>{let a=this.#s(n);a>=0&&a!==this.active&&!this.options[a].disabled&&this.setActive(a,!1)})}host;anchor;control;pick;refresh;popup=l("div",{class:"popup",part:"popup",hidden:""});status=l("div",{role:"status",class:"status"});list;options=[];active=-1;#e="";#t=`nx-list-${++R}`;#i="";#r=0;#s(e){let t=e.target.closest('[role="option"]');return t?Number(t.dataset.index):-1}get open(){return!this.popup.hidden}render(e,t,i){this.options=e,this.#e=t,i?this.list.setAttribute("aria-label",i):this.list.removeAttribute("aria-label");let o=[],r,n;e.forEach((a,p)=>{if(a.group!==n&&(n=a.group,r=void 0,n)){let h=`${this.#t}-g${p}`;r=l("div",{role:"group","aria-labelledby":h});let k=l("div",{role:"presentation",id:h,class:"heading"});k.textContent=n,r.append(k),o.push(r)}let d=`${this.#t}-${p}`,u=l("div",{role:"option",id:d,class:"option",part:"option","data-index":String(p),"aria-selected":String(a.value===t),"aria-disabled":a.disabled?"true":void 0,"aria-describedby":a.description?`${d}-d`:void 0}),c=l("span",{class:"label"});if(c.textContent=a.label,u.append(v(O),c),a.description){let h=l("span",{id:`${d}-d`,class:"description"});h.textContent=a.description,c.append(h)}r?r.append(u):o.push(u)}),this.list.replaceChildren(...o),this.active>=e.length&&(this.active=-1),this.setActive(this.active,!1)}setActive(e,t=!0){this.active=e;let i;for(let o of this.list.querySelectorAll('[role="option"]')){let r=Number(o.dataset.index)===e;o.toggleAttribute("data-active",r),r&&(i=o)}i&&this.open?(this.control.setAttribute("aria-activedescendant",i.id),t&&i.scrollIntoView?.({block:"nearest"})):this.control.removeAttribute("aria-activedescendant")}step(e,t,i=1){let o=e;for(let r=e+t;r>=0&&r<this.options.length&&i>0;r+=t)this.options[r].disabled||(o=r,i--);return o}first(){return this.step(-1,1)}last(){return this.step(this.options.length,-1)}indexOf(e){return this.options.findIndex(t=>t.value===e)}show(){if(!this.open){this.refresh(),this.popup.hidden=!1;try{this.popup.showPopover?.()}catch{}this.control.setAttribute("aria-expanded","true"),this.place(),window.addEventListener("resize",this.place),window.addEventListener("scroll",this.place,{capture:!0,passive:!0}),document.addEventListener("mousedown",this.#n,!0)}}hide(){if(this.open){try{this.popup.hidePopover?.()}catch{}this.popup.hidden=!0,this.active=-1,this.control.setAttribute("aria-expanded","false"),this.control.removeAttribute("aria-activedescendant"),window.removeEventListener("resize",this.place),window.removeEventListener("scroll",this.place,!0),document.removeEventListener("mousedown",this.#n,!0)}}#n=e=>{e.composedPath().includes(this.host)||this.hide()};place=()=>{if(!this.open||window.matchMedia?.(P).matches)return;let e=this.anchor.getBoundingClientRect(),t=this.popup.offsetHeight,i=document.documentElement.clientWidth||innerWidth,o=document.documentElement.clientHeight||innerHeight,r=4,n=e.bottom+r;n+t>o-r&&e.top-r-t>=r&&(n=e.top-r-t);let a=this.popup.style;a.setProperty("--nx-top",`${Math.max(r,n)}px`),a.setProperty("--nx-start",`${Math.max(0,M(this.host)?i-e.right:e.left)}px`),a.setProperty("--nx-width",`${e.right-e.left}px`)};get typing(){return this.#i!==""&&Date.now()-this.#r<=C}typeahead(e){let t=Date.now();this.#i=t-this.#r>C?e:this.#i+e,this.#r=t;let i=N(this.#i),o=[...i].every(d=>d===i[0]),r=o?i[0]:i,n=this.active>=0?this.active:this.indexOf(this.#e),a=n<0?0:n+(o?1:0),p=this.options.length;for(let d=0;d<p;d++){let u=(a+d)%p,c=this.options[u];if(!c.disabled&&[c.label,...c.keywords??[]].some(h=>N(h).startsWith(r)))return u}return-1}selectKey(e){let{key:t}=e,i=t.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey,o=i&&(t!==" "||this.typing);if(!this.open){if(o){e.preventDefault(),this.refresh();let n=this.options[this.typeahead(t)];n&&this.pick(n)}else if(["ArrowDown","ArrowUp","Enter"," ","Home","End"].includes(t)){e.preventDefault(),this.show();let n=this.indexOf(this.#e);this.setActive(t==="Home"?this.first():t==="End"?this.last():n>=0&&!this.options[n].disabled?n:this.first())}return}let r;switch(t){case"ArrowDown":r=this.step(this.active,1);break;case"ArrowUp":if(e.altKey)return this.#o(e);r=this.active<0?this.last():this.step(this.active,-1);break;case"Home":r=this.first();break;case"End":r=this.last();break;case"PageDown":r=this.step(this.active,1,10);break;case"PageUp":r=this.step(this.active,-1,10);break;case"Enter":return this.#o(e);case"Tab":return this.#o();case"Escape":return e.preventDefault(),e.stopPropagation(),this.hide();default:if(!i)return;if(!o)return this.#o(e);if(r=this.typeahead(t),r<0)return e.preventDefault()}e.preventDefault(),this.setActive(r)}#o(e){e?.preventDefault();let t=this.options[this.active];t?this.pick(t):this.hide()}},x=class extends g{static get observedAttributes(){return[...super.observedAttributes,"placeholder"]}#e=null;#t=[];#i;get options(){return this.#e??this.#t}set options(e){this.#e=e?e.map(t=>({...t,value:String(t.value),label:String(t.label??t.value)})):null,this.optionsChanged()}get placeholder(){return this.getAttribute("placeholder")??""}set placeholder(e){this.setAttribute("placeholder",e)}get open(){return this.list.open}close(){this.list.hide()}connectedCallback(){this.#t=L(this),this.#i??=new MutationObserver(()=>{this.#t=L(this),this.#e||this.optionsChanged()}),this.#i.observe(this,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["value","label","disabled","selected"]}),super.connectedCallback()}disconnectedCallback(){this.#i?.disconnect(),this.list.hide()}initial(){return this.getAttribute("value")??this.querySelector("option[selected]")?.value??""}optionsChanged(){this.resanitize(),this.render()}get locked(){return this.isDisabled||this.readOnly}get listLabel(){return this.control.getAttribute("aria-label")??""}};function K(s,e,t,i){if(s!=="badInput"&&s!=="typeMismatch"&&typeof document<"u"){let o=document.createElement("input");if(s==="valueMissing"?o.required=!0:(o.type=e,o[s==="rangeUnderflow"?"min":"max"]=t,o.value=e==="number"?String(Number(t)+(s==="rangeUnderflow"?-1:1)):s==="rangeUnderflow"?"0001-01-01".slice(0,t.length):"9999-12-31".slice(0,t.length)),o.validationMessage)return o.validationMessage}return i}var T=()=>K("valueMissing","number","","Fill out this field.");var F=`
48
+ button { margin: 0; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; }
49
+ button:disabled { cursor: not-allowed; color: var(--color-text-disabled); }
50
+ button svg, .option svg { inline-size: 1rem; block-size: 1rem; flex: none; }
51
+ .trigger { flex: 1; align-self: stretch; display: flex; align-items: center; gap: 0.5rem; min-inline-size: 0; outline: none; text-align: start; }
52
+ /* One line, as the React trigger's line-clamp-1. */
53
+ .text { flex: 1; min-inline-size: 0; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; line-clamp: 1; overflow-wrap: anywhere; }
54
+ .trigger[data-placeholder] .text { color: var(--color-on-surface-muted); }
55
+ .trigger svg, .toggle svg, .country svg { color: var(--color-on-surface-variant); }
56
+ .toggle { flex: none; display: inline-flex; align-items: center; justify-content: center; inline-size: 1.75rem; block-size: 1.75rem; margin-inline-end: -0.5rem; border-radius: 999rem; }
57
+ .country {
58
+ flex: none; display: inline-flex; align-items: center; gap: 0.25rem; align-self: stretch;
59
+ margin-block: 0.25rem; margin-inline-start: -0.5rem; padding-inline: 0.5rem;
60
+ border-radius: var(--shape-control, 999rem); font-variant-numeric: tabular-nums; outline: none;
61
+ }
62
+ span.country { color: var(--color-on-surface-variant); }
63
+ .country[hidden] { display: none; }
64
+ button.country:hover { background: color-mix(in srgb, var(--color-on-surface) 8%, transparent); }
65
+ button.country:focus-visible { background: color-mix(in srgb, var(--color-on-surface) 12%, transparent); }
66
+ button.country:disabled { background: transparent; }
67
+ .popup {
68
+ position: fixed; z-index: var(--z-popover); margin: 0; inset: auto;
69
+ inset-block-start: var(--nx-top, 0); inset-inline-start: var(--nx-start, 0);
70
+ inline-size: max(var(--nx-width, 12rem), 12rem); max-inline-size: calc(100vw - 1rem); max-block-size: min(24rem, calc(100dvh - 1rem));
71
+ display: flex; flex-direction: column; overflow: auto; padding: 0.375rem; border: 0;
72
+ border-radius: var(--shape-container, 1rem); background: var(--color-surface-elevated, var(--color-surface));
73
+ color: var(--color-on-surface); box-shadow: var(--elevation-2);
74
+ font-size: var(--type-body-sm-size, 0.875rem); line-height: var(--type-body-sm-lineHeight, 1.25rem);
75
+ }
76
+ .popup[hidden] { display: none; }
77
+ .status { padding: 0.5rem 0.75rem; color: var(--color-on-surface-muted); }
78
+ .status:empty { display: none; }
79
+ .heading { padding: 0.5rem 0.5rem 0.25rem; font-size: var(--type-label-sm-size, 0.75rem); font-weight: var(--type-label-lg-weight, 600); color: var(--color-on-surface-muted); }
80
+ .option { display: flex; align-items: center; gap: 0.5rem; min-block-size: 2.25rem; padding: 0.375rem 0.5rem; border-radius: 0.625rem; cursor: default; }
81
+ .option svg { visibility: hidden; }
82
+ .option[aria-selected='true'] svg { visibility: visible; }
83
+ .option[data-active] { background: color-mix(in srgb, var(--color-on-surface) 8%, transparent); }
84
+ .option[aria-disabled='true'] { color: var(--color-text-disabled); }
85
+ .description { display: block; font-size: var(--type-label-sm-size, 0.75rem); color: var(--color-on-surface-muted); }
86
+ @media (max-width: 47.99rem) {
87
+ .popup {
88
+ inset-inline: 0; inset-block: auto 0; inline-size: 100%; max-inline-size: none; max-block-size: 50dvh;
89
+ border-start-start-radius: var(--shape-overlay, 1.5rem); border-start-end-radius: var(--shape-overlay, 1.5rem);
90
+ border-end-start-radius: 0; border-end-end-radius: 0;
91
+ padding-block-end: max(0.375rem, env(safe-area-inset-bottom));
92
+ }
93
+ .option { min-block-size: 2.75rem; }
94
+ }
95
+ @media (prefers-reduced-motion: no-preference) {
96
+ .popup:not([hidden]) { animation: nx-fade var(--motion-spring-effects-default-duration) var(--motion-spring-effects-default-easing); }
97
+ @keyframes nx-fade { from { opacity: 0; } }
98
+ .trigger svg, button.country { transition: rotate ${m}, background-color ${m}; }
99
+ }
100
+ [aria-expanded='true'] > svg { rotate: 180deg; }
101
+ @media (forced-colors: active) {
102
+ .popup { outline: 1px solid CanvasText; }
103
+ .option[data-active] { forced-color-adjust: none; background: Highlight; color: HighlightText; }
104
+ .option[aria-disabled='true'], button:disabled { color: GrayText; }
105
+ button.country:focus-visible { outline: 0.125rem solid Highlight; }
106
+ }
107
+ `;var w=class extends x{control=l("button",{type:"button",role:"combobox",class:"trigger",part:"trigger","aria-haspopup":"listbox"});#e=l("span",{class:"text",part:"value"});list;constructor(){super(),this.root.adoptedStyleSheets=[f(b),f(F)],this.control.append(this.#e,v(z)),this.box.append(this.control),this.list=new y(this,this.box,this.control,e=>this.#t(e),()=>this.list.render(this.options,this.value,this.listLabel)),this.root.append(this.list.popup),this.control.addEventListener("click",()=>this.open?this.close():this.show()),this.control.addEventListener("keydown",e=>{if(this.locked){e.key!=="Tab"&&e.preventDefault();return}this.list.selectKey(e)}),this.control.addEventListener("keyup",e=>e.key===" "&&e.preventDefault()),this.control.addEventListener("blur",()=>this.close()),this.upgrade("options","value")}get selectedOption(){return this.options.find(e=>e.value===this.value)}show(){if(this.locked||this.open)return;this.list.show();let e=this.list.indexOf(this.value);this.list.setActive(e>=0&&!this.options[e].disabled?e:this.list.first())}sanitize(e){return!this.options.length||this.options.some(t=>t.value===e)?e:""}check(){return this.required&&!this.value?{kind:"valueMissing",message:T()}:void 0}reset(){this.close()}update(){let e=this.selectedOption;this.#e.textContent=e?e.label:this.placeholder||D.selectPlaceholder,this.control.toggleAttribute("data-placeholder",!e),this.open&&this.list.refresh()}#t(e){this.close();let t=this.setValue(e.value);this.touch(),this.render(),t&&(this.emit("input"),this.emit("change"))}};function H(s,e){typeof customElements<"u"&&!customElements.get(s)&&customElements.define(s,e)}H("nx-select",w);export{w as NxSelect};
package/dist/define.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { NxNumberInput, NxDatePicker } from './index.js';
1
+ import { NxNumberInput, NxDatePicker, NxSelect, NxCombobox, NxPhoneInput } from './index.js';
2
2
 
3
3
  /**
4
- * Registers `<nx-number-input>` and `<nx-date-picker>` (skipped for a tag that is already
5
- * defined, so loading this twice is safe).
4
+ * Registers `<nx-number-input>` only (11.9): a page that uses one element loads just its code.
5
+ * `@nexub/elements/define` registers every element.
6
6
  *
7
7
  * @alpha
8
8
  */
@@ -10,8 +10,59 @@ import { NxNumberInput, NxDatePicker } from './index.js';
10
10
  declare global {
11
11
  interface HTMLElementTagNameMap {
12
12
  'nx-number-input': NxNumberInput;
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Registers `<nx-date-picker>` only (11.9): a page that uses one element loads just its code.
18
+ * `@nexub/elements/define` registers every element.
19
+ *
20
+ * @alpha
21
+ */
22
+
23
+ declare global {
24
+ interface HTMLElementTagNameMap {
13
25
  'nx-date-picker': NxDatePicker;
14
26
  }
15
27
  }
16
28
 
17
- export { NxDatePicker, NxNumberInput };
29
+ /**
30
+ * Registers `<nx-select>` only (11.9): a page that uses one element loads just its code.
31
+ * `@nexub/elements/define` registers every element.
32
+ *
33
+ * @alpha
34
+ */
35
+
36
+ declare global {
37
+ interface HTMLElementTagNameMap {
38
+ 'nx-select': NxSelect;
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Registers `<nx-combobox>` only (11.9): a page that uses one element loads just its code.
44
+ * `@nexub/elements/define` registers every element.
45
+ *
46
+ * @alpha
47
+ */
48
+
49
+ declare global {
50
+ interface HTMLElementTagNameMap {
51
+ 'nx-combobox': NxCombobox;
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Registers `<nx-phone-input>` only (11.9): a page that uses one element loads just its code.
57
+ * `@nexub/elements/define` registers every element.
58
+ *
59
+ * @alpha
60
+ */
61
+
62
+ declare global {
63
+ interface HTMLElementTagNameMap {
64
+ 'nx-phone-input': NxPhoneInput;
65
+ }
66
+ }
67
+
68
+ export { NxCombobox, NxDatePicker, NxNumberInput, NxPhoneInput, NxSelect };
package/dist/define.js CHANGED
@@ -1 +1 @@
1
- import{b as t,c as n}from"./chunk-N4ME7GWE.js";var m=[["nx-number-input",t],["nx-date-picker",n]];if(typeof customElements<"u")for(let[e,r]of m)customElements.get(e)||customElements.define(e,r);export{n as NxDatePicker,t as NxNumberInput};
1
+ import{b as r,c as o,e as t,f as m,g as p}from"./chunk-NG5UPH5U.js";function e(x,n){typeof customElements<"u"&&!customElements.get(x)&&customElements.define(x,n)}e("nx-number-input",r);e("nx-date-picker",o);e("nx-select",t);e("nx-combobox",m);e("nx-phone-input",p);export{m as NxCombobox,o as NxDatePicker,r as NxNumberInput,p as NxPhoneInput,t as NxSelect};