@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,72 @@
1
+ import { D as DateGranularity } from './index.d-B-hFBS-X.js';
2
+ import { N as NxFieldElement, F as FieldError } from './field-PQ7-S6JJ.js';
3
+
4
+ /** `day`, `month` or `year`: what `<nx-date-picker>` picks. */
5
+ type NxDateGranularity = DateGranularity;
6
+ /**
7
+ * `<nx-date-picker>`: a form-associated date field. A text field that accepts a typed date
8
+ * (normalised on blur or Enter) and a button that opens a dialog with a grid: days, months
9
+ * (`granularity="month"`) or years (`granularity="year"`); a bottom sheet below 48rem. The
10
+ * value is `YYYY-MM-DD`, `YYYY-MM` or `YYYY`, so it never shifts across time zones.
11
+ *
12
+ * Keyboard in the grid (as `@nexub/react`'s DatePicker): arrows move, Page Up/Down change the
13
+ * month (Shift: the year; in the month and year grids, the page), Home/End go to the start or
14
+ * end of the week (row), Enter or Space picks, Escape closes; focus returns to the field.
15
+ *
16
+ * Attributes (reflected as properties): `name`, `value` (the default), `min`, `max`,
17
+ * `granularity`, `required`, `disabled`, `readonly`, `locale` (defaults to the nearest `lang`),
18
+ * `size`. Event: `change` when the value changes.
19
+ *
20
+ * @alpha
21
+ */
22
+ declare class NxDatePicker extends NxFieldElement {
23
+ #private;
24
+ static get observedAttributes(): string[];
25
+ /** @internal */
26
+ protected readonly control: HTMLInputElement;
27
+ constructor();
28
+ get min(): string;
29
+ set min(v: string);
30
+ get max(): string;
31
+ set max(v: string);
32
+ /** `day` (default), `month` or `year`. */
33
+ get granularity(): NxDateGranularity;
34
+ set granularity(v: NxDateGranularity);
35
+ /** BCP 47 locale for month and weekday names and the typed format; `''` follows the nearest `lang`. */
36
+ get locale(): string;
37
+ set locale(v: string);
38
+ get value(): string;
39
+ set value(v: string);
40
+ /** `true` while the calendar is open. */
41
+ get open(): boolean;
42
+ /** Opens the calendar on the selected date (or today), focused. */
43
+ show(): void;
44
+ /** Closes the calendar; focus goes back to the field. */
45
+ close(): void;
46
+ attributeChangedCallback(name: string, old: string | null, next: string | null): void;
47
+ /** @internal Any of the three forms, cut to the granularity; a coarser one (`2026` for a day) is no value. */
48
+ protected sanitize(v: string): string;
49
+ /** @internal */
50
+ protected reset(): void;
51
+ /** @internal */
52
+ protected check(): FieldError;
53
+ /** @internal */
54
+ protected update(): void;
55
+ /** @internal */
56
+ protected nameControl(): void;
57
+ }
58
+
59
+ /**
60
+ * Registers `<nx-date-picker>` only (11.9): a page that uses one element loads just its code.
61
+ * `@nexub/elements/define` registers every element.
62
+ *
63
+ * @alpha
64
+ */
65
+
66
+ declare global {
67
+ interface HTMLElementTagNameMap {
68
+ 'nx-date-picker': NxDatePicker;
69
+ }
70
+ }
71
+
72
+ export { DateGranularity, FieldError, NxDatePicker, NxFieldElement };
@@ -0,0 +1,121 @@
1
+ var Z={pickDate:"Pick a date",pickMonth:"Pick a month",pickYear:"Pick a year",previousMonth:"Go to previous month",nextMonth:"Go to next month",previousYear:"Go to previous year",nextYear:"Go to next year",previousYears:"Go to previous years",nextYears:"Go to next years",todayDate:i=>`Today, ${i}`,selectedDate:i=>`${i}, selected`};var ae=/^(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?$/,be={year:0,month:1,day:2},V=(i,e=2)=>String(i).padStart(e,"0");function A(i,e){let r=new Date(0);return r.setUTCFullYear(i,e+1,0),r.getUTCDate()}function w(i){let e=i?ae.exec(i):null;if(!e)return;let r=e[3]?"day":e[2]?"month":"year";return c(i,r)?r:void 0}function c(i,e){let r=i?ae.exec(i):null;if(!r)return;let t=r[3]?"day":r[2]?"month":"year";if(e&&t!==e)return;let n=Number(r[1]),a=r[2]?Number(r[2])-1:0,o=r[3]?Number(r[3]):1;if(!(a<0||a>11||o<1||o>A(n,a)))return{year:n,month:a,day:o}}function v(i,e="day"){let r=V(i.year,4);return e==="year"?r:e==="month"?`${r}-${V(i.month+1)}`:`${r}-${V(i.month+1)}-${V(i.day)}`}function b(i,e,r="day"){let t=be[r];return i.year!==e.year?i.year-e.year:t>=1&&i.month!==e.month?i.month-e.month:t>=2&&i.day!==e.day?i.day-e.day:0}function L(i,e,r,t="day"){let n=c(e),a=c(r),o=(s,d)=>d==="year"?{year:s.year,month:11,day:31}:d==="month"?{...s,day:A(s.year,s.month)}:s;if(n&&b(i,n,t)<0)return"under";if(a&&b(i,o(a,w(r)),t)>0)return"over"}function R({year:i,month:e,day:r}){let t=new Date(0);return t.setUTCFullYear(i,e,r),t.getUTCDay()}function z({year:i,month:e,day:r},t){let n=new Date(0);return n.setUTCFullYear(i,e,r+t),{year:n.getUTCFullYear(),month:n.getUTCMonth(),day:n.getUTCDate()}}function x({year:i,month:e,day:r},t){let n=i*12+e+t,a=Math.floor(n/12),o=n-a*12;return{year:a,month:o,day:Math.min(r,A(a,o))}}function O(i=new Date){return{year:i.getFullYear(),month:i.getMonth(),day:i.getDate()}}var ve=new Set("AG AS BD BR BS BT BW BZ CA CN CO DM DO ET GT GU HK HN ID IL IN JM JP KE KH KR LA MH MM MO MT MX MZ NI NP PA PE PH PK PR PT PY SA SG SV TH TT TW UM US VE VI WS YE ZA ZW".split(" ")),xe=new Set("AE AF BH DJ DZ EG IQ IR JO KW LY OM QA SD SY".split(" "));function H(i){let e;try{e=new Intl.Locale(i??new Intl.DateTimeFormat().resolvedOptions().locale)}catch{return 1}try{let t=typeof e.getWeekInfo=="function"?e.getWeekInfo():e.weekInfo;if(t&&typeof t.firstDay=="number")return t.firstDay%7}catch{}let r=e.maximize().region??"";return ve.has(r)?0:xe.has(r)?6:1}var U="var(--motion-spring-effects-fast-duration) var(--motion-spring-effects-fast-easing)",se="outline: 0.1875rem solid var(--color-ring-default, var(--color-primary)); outline-offset: 0.125rem;",Y=`
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 ${U}, box-shadow ${U}; }
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
+ `,oe=new Map;function I(i){let e=oe.get(i);return e||(e=new CSSStyleSheet,e.replaceSync(i),oe.set(i,e)),e}var De=typeof HTMLElement>"u"?class{}:HTMLElement,K=class extends De{static formAssociated=!0;internals;root;box;#t="";#e=!1;#o=!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=[I(Y)],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.#e||(this.#t=this.sanitize(this.initial())),this.render(),queueMicrotask(()=>this.nameControl())}attributeChangedCallback(e,r,t){r!==t&&(e==="value"&&!this.#e&&(this.#t=this.sanitize(t??this.initial())),e==="aria-label"&&this.nameControl(),this.render())}get value(){return this.#t}set value(e){this.#e=!0,this.#t=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.#e=!1,this.#r=!1,this.reset(),this.#t=this.sanitize(this.initial()),this.render()}formDisabledCallback(e){this.#o=e,this.render()}formStateRestoreCallback(e){typeof e=="string"&&(this.value=e)}initial(){return this.getAttribute("value")??""}upgrade(...e){let r=this;for(let t of e){if(!Object.prototype.hasOwnProperty.call(this,t))continue;let n=r[t];delete r[t],r[t]=n}}reset(){}resanitize(){this.#t=this.sanitize(this.#e?this.#t:this.initial())}get isDisabled(){return this.disabled||this.#o}setValue(e){let r=this.sanitize(e),t=r!==this.#t;return this.#e=!0,this.#t=r,t}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.#t),e&&!this.readOnly&&!this.isDisabled?this.internals.setValidity({[e.kind]:!0},e.message,this.control):this.internals.setValidity({});let r=!!e&&this.#r&&!this.readOnly||this.invalid;this.box.toggleAttribute("data-invalid",r),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(r)),this.update()}nameControl(){let e=this.getAttribute("aria-label"),r=Array.from(this.internals.labels??[]);if(!r.length){let n=this.getRootNode(),a=this.id?Array.from(n.querySelectorAll("label[for]")).filter(s=>s.htmlFor===this.id):[],o=this.closest("label");r=o&&!a.includes(o)?[...a,o]:a}let t=e??r.map(n=>n.textContent?.trim()).filter(Boolean).join(" ");t?this.control.setAttribute("aria-label",t):this.control.removeAttribute("aria-label")}};function W(i,e,r,t){if(i!=="badInput"&&i!=="typeMismatch"&&typeof document<"u"){let n=document.createElement("input");if(i==="valueMissing"?n.required=!0:(n.type=e,n[i==="rangeUnderflow"?"min":"max"]=r,n.value=e==="number"?String(Number(r)+(i==="rangeUnderflow"?-1:1)):i==="rangeUnderflow"?"0001-01-01".slice(0,r.length):"9999-12-31".slice(0,r.length)),n.validationMessage)return n.validationMessage}return t}var le=`
48
+ :host([size='sm']) .field { padding-inline-end: 0.125rem; }
49
+ .field { padding-inline-end: 0.25rem; }
50
+ :host([size='lg']) .field { padding-inline-end: 0.375rem; }
51
+ button {
52
+ position: relative; isolation: isolate; display: inline-flex; align-items: center; justify-content: center;
53
+ margin: 0; padding: 0; border: 1px solid transparent; border-radius: var(--shape-control, 999rem);
54
+ background: transparent; color: inherit; font: inherit; cursor: pointer;
55
+ }
56
+ /* The state layer (themes' .nx-state-layer): the text colour at the --state-* opacity. */
57
+ button::before {
58
+ content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit;
59
+ background: currentColor; opacity: 0; pointer-events: none;
60
+ }
61
+ button:hover::before { opacity: var(--state-hover, 0.08); }
62
+ button:focus-visible::before { opacity: var(--state-focus, 0.1); }
63
+ button:active::before { opacity: var(--state-pressed, 0.1); }
64
+ button:disabled { cursor: default; pointer-events: none; color: var(--color-text-disabled); }
65
+ button:disabled::before { opacity: 0; }
66
+ button:focus-visible { ${se} }
67
+ svg { inline-size: 1rem; block-size: 1rem; flex: none; }
68
+ .open { flex: none; inline-size: 2rem; block-size: 2rem; border-radius: 999rem; }
69
+ :host([size='sm']) .open { inline-size: 1.75rem; block-size: 1.75rem; }
70
+ dialog {
71
+ position: fixed; margin: 0; inset: auto;
72
+ inset-block-start: var(--nx-top, 0); inset-inline-start: var(--nx-start, 0);
73
+ inline-size: max-content; max-inline-size: calc(100vw - 1rem); max-block-size: calc(100dvh - 1rem); overflow: auto;
74
+ padding: 0.75rem; border: 0; border-radius: var(--shape-container, 1rem);
75
+ background: var(--color-surface-elevated, var(--color-surface)); color: var(--color-on-surface);
76
+ box-shadow: var(--elevation-2); font-size: var(--type-body-sm-size, 0.875rem);
77
+ }
78
+ dialog::backdrop { background: transparent; }
79
+ .head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-block-end: 0.5rem; }
80
+ .title { font-size: var(--type-label-lg-size, 0.875rem); font-weight: var(--type-label-lg-weight, 600); }
81
+ .nav { inline-size: 1.75rem; block-size: 1.75rem; border-radius: 999rem; }
82
+ :host(:dir(rtl)) .nav svg { transform: scaleX(-1); }
83
+ table { border-collapse: collapse; margin-inline: auto; }
84
+ th { block-size: var(--day-cell, 2rem); padding: 0; font-weight: inherit; font-size: var(--type-label-sm-size, 0.75rem); color: var(--color-on-surface-muted); }
85
+ td { padding: 0; padding-block-start: 0.25rem; text-align: center; }
86
+ .day, .cell { font-variant-numeric: tabular-nums; border-radius: 999rem; }
87
+ .day { inline-size: var(--day-cell, 2rem); block-size: var(--day-cell, 2rem); }
88
+ .day[data-outside]:not([aria-pressed='true']):not(:disabled) { color: var(--color-on-surface-muted); }
89
+ .cells { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.25rem; inline-size: 16.5rem; max-inline-size: 100%; }
90
+ /* Long month names in some locales wrap to two lines rather than overflow. */
91
+ .cell { block-size: 2.5rem; padding-inline: 0.25rem; line-height: 1.125; overflow-wrap: anywhere; }
92
+ [aria-current='date'] { border-color: var(--color-primary); }
93
+ [aria-pressed='true'], [aria-selected='true'] > button { background: var(--color-primary); color: var(--color-on-primary); }
94
+ @media (max-width: 47.99rem) {
95
+ dialog {
96
+ inset-inline: 0; inset-block: auto 0; inline-size: 100%; max-inline-size: none; max-block-size: 85dvh;
97
+ border-start-start-radius: var(--shape-overlay, 1.5rem); border-start-end-radius: var(--shape-overlay, 1.5rem);
98
+ border-end-start-radius: 0; border-end-end-radius: 0;
99
+ padding-block-end: max(0.75rem, env(safe-area-inset-bottom));
100
+ }
101
+ dialog::before {
102
+ content: ''; display: block; inline-size: 2rem; block-size: 0.25rem; margin: 0 auto 0.5rem;
103
+ border-radius: var(--shape-overlay, 1.5rem); background: var(--color-outline-variant);
104
+ }
105
+ dialog::backdrop { background: color-mix(in srgb, var(--color-scrim, CanvasText) 40%, transparent); }
106
+ .cells { inline-size: 100%; }
107
+ .day { inline-size: 2.75rem; block-size: 2.75rem; }
108
+ }
109
+ @media (prefers-reduced-motion: no-preference) {
110
+ button::before { transition: opacity ${U}; }
111
+ dialog[open] { animation: nx-pop var(--motion-spring-effects-default-duration) var(--motion-spring-effects-default-easing); }
112
+ @keyframes nx-pop { from { opacity: 0; scale: 0.96; } }
113
+ }
114
+ @media (forced-colors: active) {
115
+ dialog { outline: 1px solid CanvasText; }
116
+ button:focus-visible { outline-color: Highlight; }
117
+ [aria-current='date'] { border-color: CanvasText; }
118
+ [aria-pressed='true'], [aria-selected='true'] > button { forced-color-adjust: none; background: Highlight; color: HighlightText; }
119
+ button:disabled { color: GrayText; }
120
+ }
121
+ `;var h=Z,de={year:0,month:1,day:2};function D({year:i,month:e,day:r}){let t=new Date(0);return t.setUTCFullYear(i,e,r),t}var T=(i,e)=>new Intl.DateTimeFormat(i,{timeZone:"UTC",...e}),Q={year:"numeric",month:"2-digit",day:"2-digit"};function $(i,e,r){return e==="year"?String(i.year):T(r,e==="month"?{year:"numeric",month:"long"}:Q).format(D(i))}function ke(i){return T(i,Q).formatToParts(D({year:2026,month:0,day:31})).map(e=>e.type).filter(e=>e==="year"||e==="month"||e==="day")}function X(i,e){if(i==="year")return"yyyy";let r={year:"yyyy",month:"mm",day:"dd"};return T(e,i==="month"?{year:"numeric",month:"2-digit"}:Q).formatToParts(D({year:2026,month:0,day:31})).map(n=>n.type==="year"||n.type==="month"||n.type==="day"?r[n.type]:n.type==="literal"?n.value:"").join("").trim()}function we(i,e){let r=new Intl.NumberFormat(e,{useGrouping:!1}),t=i;for(let n=0;n<=9;n++){let a=r.format(n);a!==String(n)&&(t=t.split(a).join(String(n)))}return t}function Ee(i,e){let r=t=>t.toLowerCase().replace(/\.$/,"");for(let t=0;t<12;t++){let n=D({year:2026,month:t,day:1});if([T(e,{month:"long"}).format(n),T(e,{month:"short"}).format(n),T(e,{day:"numeric",month:"long"}).formatToParts(n).find(o=>o.type==="month")?.value??""].map(r).some(o=>o===i||i.length>=3&&o.startsWith(i)))return t}}function ue(i,e,r){let t=we(i.trim(),r);if(!t)return;let n=c(t);if(n)return de[w(t)]>=de[e]?n:void 0;let a,o=[];for(let m of t.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean))if(/^\d+$/.test(m))o.push(m);else{let E=Ee(m,r);if(E===void 0||a!==void 0)return;a=E}let s=ke(r).filter(m=>m==="year"||m==="month"&&e!=="year"&&a===void 0||m==="day"&&e==="day");if(o.length!==s.length)return;let d=m=>o[s.indexOf(m)]??"",y=d("year"),P={year:y.length<=2?2e3+Number(y):Number(y),month:a??(e==="year"?0:Number(d("month"))-1),day:e==="day"?Number(d("day")):1};return c(v(P,e),e)}var ce="http://www.w3.org/2000/svg",B=i=>{let e=document.createElementNS(ce,"svg"),r={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"};for(let[t,n]of Object.entries(r))e.setAttribute(t,n);for(let[t,n]of i){let a=document.createElementNS(ce,t);for(let[o,s]of Object.entries(n))a.setAttribute(o,s);e.append(a)}return e},l=(i,e={})=>{let r=document.createElement(i);for(let[t,n]of Object.entries(e))n!==void 0&&r.setAttribute(t,n);return r};var he=i=>{let e=i.getAttribute("locale")||i.closest("[lang]")?.getAttribute("lang")||void 0;try{return e?Intl.getCanonicalLocales(e)[0]:void 0}catch{return}},me=i=>{try{return i.matches(":dir(rtl)")}catch{return i.closest("[dir]")?.getAttribute("dir")?.toLowerCase()==="rtl"}};var j={year:0,month:1,day:2},M=12,Se=[["rect",{x:"3",y:"4",width:"18",height:"18",rx:"2"}],["path",{d:"M16 2v4M8 2v4M3 10h18"}]],Ae=[["path",{d:"m15 18-6-6 6-6"}]],Me=[["path",{d:"m9 18 6-6-6-6"}]],Ce="(max-width: 47.99rem)",J=i=>i-(i%M+M)%M,q=class extends K{static get observedAttributes(){return[...super.observedAttributes,"min","max","granularity","locale"]}control=l("input",{type:"text",part:"input",autocomplete:"off",spellcheck:"false"});#t=l("button",{type:"button",part:"button",class:"open","aria-haspopup":"dialog","aria-expanded":"false"});#e=l("dialog",{part:"calendar",tabindex:"-1"});#o=l("span",{class:"title","aria-live":"polite"});#r=l("button",{type:"button",class:"nav"});#l=l("button",{type:"button",class:"nav"});#d=l("div");#i=null;#n;#s=O();constructor(){super(),this.root.adoptedStyleSheets=[I(Y),I(le)],this.#t.replaceChildren(B(Se)),this.#r.replaceChildren(B(Ae)),this.#l.replaceChildren(B(Me));let e=l("div",{class:"head"});e.append(this.#r,this.#o,this.#l),this.#e.append(e,this.#d),this.box.append(this.control,this.#t),this.root.append(this.#e);let r=this.control;r.addEventListener("input",t=>{t.stopPropagation(),this.#i=r.value}),r.addEventListener("blur",()=>this.#b()),r.addEventListener("keydown",t=>{t.key!=="Enter"||t.isComposing||(this.#b(),this.form?.requestSubmit())}),this.#t.addEventListener("click",()=>this.show()),this.#r.addEventListener("click",()=>this.#v(-1)),this.#l.addEventListener("click",()=>this.#v(1)),this.#d.addEventListener("click",t=>{let n=t.target.closest("button[data-value]");n&&!n.disabled&&this.#x(n.dataset.value)}),this.#d.addEventListener("keydown",this.#D),this.#e.addEventListener("close",()=>this.#p()),this.#e.addEventListener("keydown",t=>{t.key!=="Escape"||t.isComposing||(t.preventDefault(),this.close())}),this.#e.addEventListener("click",t=>{if(t.target!==this.#e)return;let n=this.#e.getBoundingClientRect();(t.clientX<n.left||t.clientX>n.right||t.clientY<n.top||t.clientY>n.bottom)&&this.close()})}get min(){return this.getAttribute("min")??""}set min(e){this.setAttribute("min",e)}get max(){return this.getAttribute("max")??""}set max(e){this.setAttribute("max",e)}get granularity(){let e=this.getAttribute("granularity");return e==="month"||e==="year"?e:"day"}set granularity(e){this.setAttribute("granularity",e)}get locale(){return this.getAttribute("locale")??""}set locale(e){this.setAttribute("locale",e)}get value(){return super.value}set value(e){this.#i=null,this.#n=void 0,super.value=e}get open(){return this.#e.open}show(){this.open||this.isDisabled||this.readOnly||(this.#s=this.#h(c(this.value)??O()),this.#c(),this.#e.showModal(),this.#t.setAttribute("aria-expanded","true"),this.#u(),window.addEventListener("resize",this.#u),window.addEventListener("scroll",this.#u,{capture:!0,passive:!0}),this.#m())}close(){this.open&&(this.#e.close(),this.#p())}#p(){this.open||this.#t.getAttribute("aria-expanded")==="false"||(this.#t.setAttribute("aria-expanded","false"),window.removeEventListener("resize",this.#u),window.removeEventListener("scroll",this.#u,!0),this.control.focus())}attributeChangedCallback(e,r,t){e==="granularity"&&r!==t&&this.resanitize(),super.attributeChangedCallback(e,r,t),this.open&&this.#c()}get#a(){return he(this)}get#f(){return me(this)}sanitize(e){let r=c(e.trim()),t=w(e.trim());return r&&t&&j[t]>=j[this.granularity]?v(r,this.granularity):""}reset(){this.#i=null,this.#n=void 0,this.close()}#y(e){let r=L(e,this.min,this.max,this.granularity);if(!r)return;let t=r==="under",n=c(t?this.min:this.max),a=this.granularity,o=$(n,a,this.#a),s=t?"rangeUnderflow":"rangeOverflow";return{kind:s,message:W(s,a==="day"?"date":a==="month"?"month":"number",v(n,a),`Value must be ${o} or ${t?"later":"earlier"}.`)}}check(){if(this.#n)return this.#n;let e=c(this.value);return e?this.#y(e):this.required?{kind:"valueMissing",message:W("valueMissing","date","","Fill out this field.")}:void 0}update(){let e=this.granularity,r=c(this.value),t=this.#i??(r?$(r,e,this.#a):"");this.control.value!==t&&(this.control.value=t),this.control.placeholder=X(e,this.#a),this.#t.disabled=this.isDisabled||this.readOnly,this.#g()}#g(){let e=this.granularity,r=e==="day"?h.pickDate:e==="month"?h.pickMonth:h.pickYear,t=this.control.getAttribute("aria-label");this.#t.setAttribute("aria-label",t?`${r}, ${t}`:r)}nameControl(){super.nameControl(),this.#g()}#b(){let e=this.#i;if(e===null)return;let r=!1,t=e.trim()?ue(e,this.granularity,this.#a):void 0;this.#n=!e.trim()||!t?e.trim()?{kind:"badInput",message:W("badInput","date","",`Enter a date as ${X(this.granularity,this.#a)}.`)}:void 0:this.#y(t),this.#n||(this.#i=null,r=this.setValue(t?v(t,this.granularity):"")),this.touch(),this.render(),r&&this.emit("change")}#x(e){this.#i=null,this.#n=void 0;let r=this.setValue(e);this.touch(),this.render(),this.close(),r&&this.emit("change")}#h(e){let r=this.granularity,t=L(e,this.min,this.max,r);if(!t)return e;let n=c(t==="under"?this.min:this.max);if(t==="under"||j[w(this.max)]>=j[r])return n;let a=w(this.max)==="year"?11:n.month;return{year:n.year,month:a,day:A(n.year,a)}}#v(e,r=!1){let t=this.granularity,n=this.#s;this.#s=this.#h(t==="day"?x(n,e):x(n,e*12*(t==="year"?M:1))),this.#c(),r&&this.#m()}#D=e=>{let r=this.granularity,t=this.#s,n=this.#f?-1:1,a=d=>r==="day"?z(t,d):x(t,d*(r==="year"?12:1)),o=()=>r==="day"?z(t,-((R(t)-H(this.#a)+7)%7)):r==="month"?{...t,month:0,day:1}:{year:J(t.year),month:0,day:1},s;switch(e.key){case"ArrowLeft":s=a(-n);break;case"ArrowRight":s=a(n);break;case"ArrowUp":s=a(r==="day"?-7:-3);break;case"ArrowDown":s=a(r==="day"?7:3);break;case"PageUp":case"PageDown":{let d=e.key==="PageUp"?-1:1;s=r==="day"?x(t,d*(e.shiftKey?12:1)):x(t,d*12*(r==="year"?M:1));break}case"Home":s=o();break;case"End":s=r==="day"?z(o(),6):r==="month"?{...t,month:11,day:1}:{year:J(t.year)+11,month:0,day:1};break;default:return}e.preventDefault(),this.#s=this.#h(s),this.#c(),this.#m()};#m(){this.#d.querySelector('[tabindex="0"]')?.focus()}#u=()=>{if(!this.open||window.matchMedia?.(Ce).matches)return;let e=this.box.getBoundingClientRect(),{offsetWidth:r,offsetHeight:t}=this.#e,n=document.documentElement.clientWidth||innerWidth,a=document.documentElement.clientHeight||innerHeight,o=4,s=e.bottom+o;s+t>a-o&&e.top-o-t>=o&&(s=e.top-o-t);let d=Math.max(o,Math.min(this.#f?n-e.right:e.left,n-r-o));this.#e.style.setProperty("--nx-top",`${Math.max(o,s)}px`),this.#e.style.setProperty("--nx-start",`${d}px`)};#c(){let e=this.granularity,r=this.#a,t=this.#s,n=c(this.value),a=O(),o=(u,g)=>L(u,this.min,this.max,g),s=u=>new Intl.DateTimeFormat(r,{timeZone:"UTC",...u}),d=new Intl.NumberFormat(r,{useGrouping:!1}),y,P,m,E,F;if(e==="day"){let u={year:t.year,month:t.month,day:1};y=s({month:"long",year:"numeric"}).format(D(u)),[P,m,E]=[x(u,-1),x(u,1),"month"];let g=H(r),S=(R(u)-g+7)%7,p=Math.ceil((S+A(t.year,t.month))/7)*7;F=l("table",{role:"grid","aria-label":y});let C=l("tr");for(let k=0;k<7;k++){let f=D({year:1970,month:0,day:4+(g+k)%7}),G=l("th",{scope:"col",abbr:s({weekday:"long"}).format(f)});G.textContent=s({weekday:"short"}).format(f),C.append(G)}let ee=l("thead");ee.append(C);let te=l("tbody");F.append(ee,te);let ge=s({dateStyle:"full"}),re;for(let k=0;k<p;k++){k%7===0&&te.append(re=l("tr"));let f=z(u,k-S),G=n!==void 0&&b(f,n)===0,ie=b(f,a)===0,N=ge.format(D(f));ie&&(N=h.todayDate(N)),G&&(N=h.selectedDate(N));let ne=l("td",{role:"gridcell","aria-selected":G?"true":void 0}),_=l("button",{type:"button",class:"day","data-value":v(f),tabindex:b(f,t)===0?"0":"-1","aria-label":N,"aria-current":ie?"date":void 0,"data-outside":f.month!==t.month?"":void 0});_.disabled=o(f,"day")!==void 0,_.textContent=d.format(f.day),ne.append(_),re.append(ne)}}else{let u=e==="month",g=u?t.year:J(t.year);y=u?String(t.year):`${g} \u2013 ${g+M-1}`,E="year",P={year:u?t.year-1:g-1,month:0,day:1},m={year:u?t.year+1:g+M,month:0,day:1},F=l("div",{role:"group",class:"cells","aria-label":y});for(let S=0;S<12;S++){let p=u?{year:t.year,month:S,day:1}:{year:g+S,month:0,day:1},C=l("button",{type:"button",class:"cell","data-value":v(p,e),tabindex:b(p,t,e)===0?"0":"-1","aria-pressed":String(n!==void 0&&b(p,n,e)===0),"aria-current":b(p,a,e)===0?"date":void 0,"aria-label":u?$(p,"month",r):String(p.year)});C.disabled=o(p,e)!==void 0,C.textContent=u?s({month:"long"}).format(D(p)):String(p.year),F.append(C)}}this.#r.disabled=o(P,E)==="under",this.#l.disabled=o(m,E)==="over";let[fe,ye]=e==="day"?[h.previousMonth,h.nextMonth]:e==="month"?[h.previousYear,h.nextYear]:[h.previousYears,h.nextYears];this.#r.setAttribute("aria-label",fe),this.#l.setAttribute("aria-label",ye),this.#o.textContent!==y&&(this.#o.textContent=y),this.#e.setAttribute("aria-label",e==="day"?h.pickDate:e==="month"?h.pickMonth:h.pickYear),this.#d.replaceChildren(F)}};function pe(i,e){typeof customElements<"u"&&!customElements.get(i)&&customElements.define(i,e)}pe("nx-date-picker",q);export{q as NxDatePicker};
@@ -0,0 +1,102 @@
1
+ type ValidityKind = 'valueMissing' | 'rangeUnderflow' | 'rangeOverflow' | 'badInput' | 'typeMismatch';
2
+
3
+ /** `HTMLElement`, or a stand-in where there is none (a server importing the classes), so the import doesn't throw. */
4
+ declare const Base: typeof HTMLElement;
5
+ /** Control sizes, as `@nexub/react`'s `size`. */
6
+ type NxFieldSize = 'sm' | 'md' | 'lg';
7
+ /** What a field's current value fails, with the message; `undefined` when valid. */
8
+ type FieldError = {
9
+ kind: ValidityKind;
10
+ message: string;
11
+ } | undefined;
12
+ /**
13
+ * The form plumbing both elements share: form association through `ElementInternals`
14
+ * (form value, validity, reset, disabled from a fieldset, state restore), the attributes every
15
+ * field has, and naming the inner control from the host's `<label>`.
16
+ *
17
+ * `value` behaves as on a native input: the `value` attribute is the default (`defaultValue`),
18
+ * the `value` property is the current value; `form.reset()` goes back to the attribute.
19
+ *
20
+ * @alpha
21
+ */
22
+ declare abstract class NxFieldElement extends Base {
23
+ #private;
24
+ static formAssociated: boolean;
25
+ /** @internal */
26
+ protected readonly internals: ElementInternals;
27
+ /** @internal */
28
+ protected readonly root: ShadowRoot;
29
+ /** @internal The focusable control: the validation anchor, named from the label. */
30
+ protected abstract readonly control: HTMLInputElement | HTMLButtonElement;
31
+ /** @internal The bordered box around the control. */
32
+ protected readonly box: HTMLDivElement;
33
+ static get observedAttributes(): string[];
34
+ constructor();
35
+ /** @internal Turns any string into a valid value for this field (or `''`). */
36
+ protected abstract sanitize(value: string): string;
37
+ /** @internal What the current value fails, if anything. */
38
+ protected abstract check(): FieldError;
39
+ /** @internal Updates the shadow DOM from the state. */
40
+ protected abstract update(): void;
41
+ connectedCallback(): void;
42
+ attributeChangedCallback(name: string, old: string | null, next: string | null): void;
43
+ /** The current value: a string, `''` for none. Setting it doesn't fire events. */
44
+ get value(): string;
45
+ set value(v: string);
46
+ /** The `value` attribute: the value the field starts with and goes back to on `form.reset()`. */
47
+ get defaultValue(): string;
48
+ set defaultValue(v: string);
49
+ get name(): string;
50
+ set name(v: string);
51
+ get required(): boolean;
52
+ set required(v: boolean);
53
+ get disabled(): boolean;
54
+ set disabled(v: boolean);
55
+ get readOnly(): boolean;
56
+ set readOnly(v: boolean);
57
+ /** Shows the field as invalid (`aria-invalid`, the error border) whatever its validity, as `@nexub/react`'s `invalid`. */
58
+ get invalid(): boolean;
59
+ set invalid(v: boolean);
60
+ /** `sm`, `md` (default) or `lg`. */
61
+ get size(): NxFieldSize;
62
+ set size(v: NxFieldSize);
63
+ get form(): HTMLFormElement | null;
64
+ get labels(): NodeList;
65
+ get validity(): ValidityState;
66
+ get validationMessage(): string;
67
+ get willValidate(): boolean;
68
+ checkValidity(): boolean;
69
+ reportValidity(): boolean;
70
+ /** Focuses the inner field (a `<label for>` click does the same through `delegatesFocus`). */
71
+ focus(options?: FocusOptions): void;
72
+ blur(): void;
73
+ formResetCallback(): void;
74
+ formDisabledCallback(disabled: boolean): void;
75
+ formStateRestoreCallback(state: File | string | FormData | null): void;
76
+ /** @internal The value the field starts with and resets to: the `value` attribute. */
77
+ protected initial(): string;
78
+ /** @internal A property set on the element before its class was defined goes through the setter. */
79
+ protected upgrade(...names: string[]): void;
80
+ /** @internal Clears typing state on reset. */
81
+ protected reset(): void;
82
+ /** @internal Runs `sanitize` again after an attribute it reads changed (the default when untouched). */
83
+ protected resanitize(): void;
84
+ /** @internal Disabled by its own attribute or by a disabled fieldset. */
85
+ protected get isDisabled(): boolean;
86
+ /** @internal Sets the value from the user; `true` when it changed. Doesn't render. */
87
+ protected setValue(v: string): boolean;
88
+ /** @internal Marks the field as edited, so an invalid value shows. */
89
+ protected touch(): void;
90
+ /** @internal Fires `input` / `change` as a native field does (`input` crosses shadow roots). */
91
+ protected emit(type: 'input' | 'change'): void;
92
+ /** @internal Form value, validity and the shadow DOM, from the state. */
93
+ protected render(): void;
94
+ /**
95
+ * @internal The label can't reach into the shadow root, so its text becomes the control's
96
+ * accessible name: the host's `aria-label`, else its `<label>`s.
97
+ */
98
+ protected nameControl(): void;
99
+ }
100
+
101
+ export { NxFieldElement as N };
102
+ export type { FieldError as F };
@@ -0,0 +1,14 @@
1
+ /** ISO 3166-1 alpha-2 code, upper case ("IN"). */
2
+ type CountryCode = string;
3
+
4
+ /**
5
+ * Date values as strings, shared by `@nexub/react`'s DatePicker (`granularity="month" | "year"`)
6
+ * and `@nexub/elements`' `<nx-date-picker>`. A value is `YYYY-MM-DD` (day), `YYYY-MM` (month) or
7
+ * `YYYY` (year): no time and no time zone, so a date never shifts by a day across zones. These
8
+ * are calendar-independent helpers (Gregorian calendar, plain arithmetic); the calendar grid
9
+ * itself is not shared (the React day picker uses react-day-picker).
10
+ */
11
+ /** How fine a date value is. */
12
+ type DateGranularity = 'day' | 'month' | 'year';
13
+
14
+ export type { CountryCode as C, DateGranularity as D };
@@ -0,0 +1,60 @@
1
+ import { N as NxFieldElement, F as FieldError } from './field-PQ7-S6JJ.js';
2
+
3
+ /**
4
+ * `<nx-number-input>`: a form-associated number field with the `@nexub/react` `NumberInput`
5
+ * rules (from `@nexub/core`). It can be empty (`value` is `''`), a half-typed `2.` or `-` stays
6
+ * as typed while focused, and `min` / `max` apply when it loses focus or on a step, never while
7
+ * typing. Arrow Up/Down step, Page Up/Down step ten times, Home/End go to `min`/`max`.
8
+ *
9
+ * Attributes (reflected as properties): `name`, `value` (the default), `min`, `max`, `step`
10
+ * (a number or `any`), `required`, `disabled`, `readonly`, `placeholder`, `size`.
11
+ *
12
+ * Events: `input` on every edit and step, `change` when the value was committed (blur, a step,
13
+ * Enter); `value` is a string, `''` when cleared.
14
+ *
15
+ * @alpha
16
+ */
17
+ declare class NxNumberInput extends NxFieldElement {
18
+ #private;
19
+ static get observedAttributes(): string[];
20
+ /** @internal */
21
+ protected readonly control: HTMLInputElement;
22
+ constructor();
23
+ /** Smallest value, applied on blur and steps (a number as a string, `''` for none). */
24
+ get min(): string;
25
+ set min(v: string);
26
+ /** Largest value, applied on blur and steps. */
27
+ get max(): string;
28
+ set max(v: string);
29
+ /** The step for keys: a positive number, or `any` (any decimal; keys move by 1). Default 1. */
30
+ get step(): string;
31
+ set step(v: string);
32
+ get placeholder(): string;
33
+ set placeholder(v: string);
34
+ /** The value as a number, `NaN` when empty. */
35
+ get valueAsNumber(): number;
36
+ set valueAsNumber(n: number);
37
+ /** @internal */
38
+ protected sanitize(v: string): string;
39
+ /** @internal */
40
+ protected reset(): void;
41
+ /** @internal */
42
+ protected check(): FieldError;
43
+ /** @internal */
44
+ protected update(): void;
45
+ }
46
+
47
+ /**
48
+ * Registers `<nx-number-input>` only (11.9): a page that uses one element loads just its code.
49
+ * `@nexub/elements/define` registers every element.
50
+ *
51
+ * @alpha
52
+ */
53
+
54
+ declare global {
55
+ interface HTMLElementTagNameMap {
56
+ 'nx-number-input': NxNumberInput;
57
+ }
58
+ }
59
+
60
+ export { FieldError, NxFieldElement, NxNumberInput };
@@ -0,0 +1,47 @@
1
+ var w=/^[-+]?\d*(?:[.,]\d*)?$/;function f(i){return w.test(i)}function u(i){let e=Number(i.trim().replace(",","."));return i.trim()!==""&&Number.isFinite(e)&&/\d/.test(i)?e:void 0}function l(i,e,t){let r=i;return e!==void 0&&r<e&&(r=e),t!==void 0&&r>t&&(r=t),r}function g(i=1){return i==="any"?1:i}function d(i,e,t,r){return l(i===null?l(0,t,r):i+e,t,r)}function b(i,e,{min:t,max:r,step:n}={}){let s=g(n);switch(i){case"ArrowUp":return d(e,s,t,r);case"ArrowDown":return d(e,-s,t,r);case"PageUp":return d(e,s*10,t,r);case"PageDown":return d(e,-s*10,t,r);case"Home":return t===void 0?void 0:l(t,t,r);case"End":return r===void 0?void 0:l(r,t,r);default:return}}var v="var(--motion-spring-effects-fast-duration) var(--motion-spring-effects-fast-easing)";var x=`
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 ${v}, box-shadow ${v}; }
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
+ `,y=new Map;function A(i){let e=y.get(i);return e||(e=new CSSStyleSheet,e.replaceSync(i),y.set(i,e)),e}var N=typeof HTMLElement>"u"?class{}:HTMLElement,c=class extends N{static formAssociated=!0;internals;root;box;#e="";#t=!1;#r=!1;#i=!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=[A(x)],this.box=document.createElement("div"),this.box.className="field",this.box.setAttribute("part","field"),this.root.append(this.box),this.addEventListener("invalid",()=>{this.#i=!0,this.render()})}connectedCallback(){this.#t||(this.#e=this.sanitize(this.initial())),this.render(),queueMicrotask(()=>this.nameControl())}attributeChangedCallback(e,t,r){t!==r&&(e==="value"&&!this.#t&&(this.#e=this.sanitize(r??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.#i=!1,this.reset(),this.#e=this.sanitize(this.initial()),this.render()}formDisabledCallback(e){this.#r=e,this.render()}formStateRestoreCallback(e){typeof e=="string"&&(this.value=e)}initial(){return this.getAttribute("value")??""}upgrade(...e){let t=this;for(let r of e){if(!Object.prototype.hasOwnProperty.call(this,r))continue;let n=t[r];delete t[r],t[r]=n}}reset(){}resanitize(){this.#e=this.sanitize(this.#t?this.#e:this.initial())}get isDisabled(){return this.disabled||this.#r}setValue(e){let t=this.sanitize(e),r=t!==this.#e;return this.#t=!0,this.#e=t,r}touch(){this.#i=!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.#i&&!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 n=this.getRootNode(),s=this.id?Array.from(n.querySelectorAll("label[for]")).filter(a=>a.htmlFor===this.id):[],o=this.closest("label");t=o&&!s.includes(o)?[...s,o]:s}let r=e??t.map(n=>n.textContent?.trim()).filter(Boolean).join(" ");r?this.control.setAttribute("aria-label",r):this.control.removeAttribute("aria-label")}};function h(i,e,t,r){if(i!=="badInput"&&i!=="typeMismatch"&&typeof document<"u"){let n=document.createElement("input");if(i==="valueMissing"?n.required=!0:(n.type=e,n[i==="rangeUnderflow"?"min":"max"]=t,n.value=e==="number"?String(Number(t)+(i==="rangeUnderflow"?-1:1)):i==="rangeUnderflow"?"0001-01-01".slice(0,t.length):"9999-12-31".slice(0,t.length)),n.validationMessage)return n.validationMessage}return r}var p=i=>{if(i===null||i.trim()==="")return;let e=Number(i);return Number.isFinite(e)?e:void 0},m=class extends c{static get observedAttributes(){return[...super.observedAttributes,"min","max","step","placeholder"]}control=document.createElement("input");#e=null;#t="";constructor(){super();let e=this.control;e.type="text",e.inputMode="decimal",e.autocomplete="off",e.setAttribute("role","spinbutton"),e.setAttribute("part","input"),this.box.append(e),e.addEventListener("focus",()=>{this.#e=this.value,this.#t=this.value}),e.addEventListener("input",this.#i),e.addEventListener("blur",this.#s),e.addEventListener("keydown",this.#o)}get min(){return this.getAttribute("min")??""}set min(e){this.setAttribute("min",e)}get max(){return this.getAttribute("max")??""}set max(e){this.setAttribute("max",e)}get step(){return this.getAttribute("step")??""}set step(e){this.setAttribute("step",e)}get placeholder(){return this.getAttribute("placeholder")??""}set placeholder(e){this.setAttribute("placeholder",e)}get valueAsNumber(){return this.value===""?NaN:Number(this.value)}set valueAsNumber(e){this.value=Number.isFinite(e)?String(e):""}get#r(){let e=this.getAttribute("step"),t=p(e),r=e?.trim().toLowerCase()==="any"?"any":t!==void 0&&t>0?t:1;return{min:p(this.getAttribute("min")),max:p(this.getAttribute("max")),step:r}}sanitize(e){let t=u(e);return t===void 0?"":String(t)}reset(){this.#e=null,this.#t=this.sanitize(this.getAttribute("value")??"")}check(){let{min:e,max:t}=this.#r,r=this.#e;if(r!==null&&r.trim()!==""&&u(r)===void 0)return{kind:"badInput",message:h("badInput","number","","Enter a number.")};if(this.value==="")return this.required?{kind:"valueMissing",message:h("valueMissing","number","","Fill out this field.")}:void 0;let n=Number(this.value);if(e!==void 0&&n<e)return{kind:"rangeUnderflow",message:h("rangeUnderflow","number",String(e),`Value must be ${e} or more.`)};if(t!==void 0&&n>t)return{kind:"rangeOverflow",message:h("rangeOverflow","number",String(t),`Value must be ${t} or less.`)}}update(){let e=this.control,{min:t,max:r}=this.#r,n=this.#e??this.value;e.value!==n&&(e.value=n),e.placeholder=this.placeholder;let s=(o,a)=>a===void 0?e.removeAttribute(o):e.setAttribute(o,String(a));s("aria-valuenow",this.value===""?void 0:Number(this.value)),s("aria-valuemin",t),s("aria-valuemax",r)}#i=e=>{e.stopPropagation();let t=this.control,r=t.value;if(!f(r)){let o=this.#e??this.value,a=Math.max(0,(t.selectionStart??o.length)-(r.length-o.length));t.value=o,t.setSelectionRange?.(a,a);return}this.#e=r;let n=u(r),s=n!==void 0?this.setValue(String(n)):r.trim()===""?this.setValue(""):!1;this.render(),s&&this.emit("input")};#n(){this.#e=null;let{min:e,max:t}=this.#r,r=!1;this.value!==""&&!this.readOnly&&(r=this.setValue(String(l(Number(this.value),e,t)))),this.value!==this.#t&&this.touch(),this.render(),r&&this.emit("input"),this.value!==this.#t&&(this.#t=this.value,this.emit("change"))}#s=()=>this.#n();#o=e=>{if(e.key==="Enter"&&!e.isComposing){this.#n(),this.#e=this.value,this.form?.requestSubmit();return}if(this.readOnly){(e.key==="ArrowUp"||e.key==="ArrowDown")&&e.preventDefault();return}if(this.isDisabled)return;let t=this.value===""?null:Number(this.value),r=b(e.key,t,this.#r);if(r===void 0)return;e.preventDefault();let n=this.setValue(String(r));this.#e!==null&&(this.#e=this.value),this.touch(),this.render(),n&&(this.emit("input"),this.#t=this.value,this.emit("change"))}};function S(i,e){typeof customElements<"u"&&!customElements.get(i)&&customElements.define(i,e)}S("nx-number-input",m);export{m as NxNumberInput};
@@ -0,0 +1,71 @@
1
+ import { C as CountryCode } from './index.d-B-hFBS-X.js';
2
+ import { N as NxFieldElement, F as FieldError } from './field-PQ7-S6JJ.js';
3
+
4
+ /**
5
+ * `<nx-phone-input>`: a form-associated phone field, the `@nexub/react` `PhoneInput`: a country
6
+ * picker (a select-only combobox listing every country, or the `countries` given) and the
7
+ * national number, grouped as you type, with the `@nexub/core` phone rules. A full
8
+ * international number (`+44 20…`, `0044…`) typed or pasted picks its country.
9
+ *
10
+ * The value (what the form posts) is E.164 (`+919847012345`), `''` when empty. A number with
11
+ * the wrong length for its country is `typeMismatch`; an international prefix left unfinished
12
+ * (`+4`) is `badInput`. Formatting and length checks only: confirm the number on the server.
13
+ *
14
+ * Attributes (reflected as properties): `name`, `value` (the default, E.164), `country` (the
15
+ * picked country; set it to change it), `default-country` (else the region of the nearest
16
+ * `lang`, else `US`), `countries` (a list, in this order; one shows as text), `locale` (country
17
+ * names), `placeholder`, `required`, `disabled`, `readonly`, `invalid`, `size`. Events: `input`
18
+ * on every change of the value, `change` when it was committed (blur, Enter, a country pick),
19
+ * and `countrychange` when the user changes the country.
20
+ *
21
+ * @alpha
22
+ */
23
+ declare class NxPhoneInput extends NxFieldElement {
24
+ #private;
25
+ static get observedAttributes(): string[];
26
+ /** @internal */
27
+ protected readonly control: HTMLInputElement;
28
+ constructor();
29
+ /** The country the number is in (ISO 3166-1 alpha-2). Setting it keeps the national digits. */
30
+ get country(): CountryCode;
31
+ set country(v: CountryCode);
32
+ /** The country an empty field starts on, and goes back to on `form.reset()`. */
33
+ get defaultCountry(): string;
34
+ set defaultCountry(v: string);
35
+ /** The countries to pick from, in order (`"IN AE US"`); empty for every country. */
36
+ get countries(): string;
37
+ set countries(v: string);
38
+ get locale(): string;
39
+ set locale(v: string);
40
+ get placeholder(): string;
41
+ set placeholder(v: string);
42
+ /** `true` while the country list is open. */
43
+ get open(): boolean;
44
+ /** Closes the country list. */
45
+ close(): void;
46
+ disconnectedCallback(): void;
47
+ attributeChangedCallback(name: string, old: string | null, next: string | null): void;
48
+ /** @internal Any typed form to E.164 (a number from a country the field doesn't allow is no value); its country becomes the field's. */
49
+ protected sanitize(v: string): string;
50
+ /** @internal */
51
+ protected reset(): void;
52
+ /** @internal */
53
+ protected check(): FieldError;
54
+ /** @internal */
55
+ protected update(): void;
56
+ }
57
+
58
+ /**
59
+ * Registers `<nx-phone-input>` only (11.9): a page that uses one element loads just its code.
60
+ * `@nexub/elements/define` registers every element.
61
+ *
62
+ * @alpha
63
+ */
64
+
65
+ declare global {
66
+ interface HTMLElementTagNameMap {
67
+ 'nx-phone-input': NxPhoneInput;
68
+ }
69
+ }
70
+
71
+ export { CountryCode, FieldError, NxFieldElement, NxPhoneInput };