@iyulab/components 2.10.3 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/components/date-picker/UDatePicker.d.ts +8 -0
- package/dist/components/date-picker/UDatePicker.js +13 -1
- package/dist/components/date-range-picker/UDateRangePicker.d.ts +8 -0
- package/dist/components/date-range-picker/UDateRangePicker.js +13 -1
- package/dist/components/input/UInput.d.ts +2 -2
- package/dist/components/input/UInput.js +8 -7
- package/dist/components/select/USelect.d.ts +8 -0
- package/dist/components/select/USelect.js +12 -1
- package/dist/components/select/USelect.styles.js +7 -0
- package/dist/utilities/chars.d.ts +36 -0
- package/dist/utilities/chars.js +91 -0
- package/package.json +1 -1
- package/skills/iyulab-components/references/components/date-picker.md +1 -0
- package/skills/iyulab-components/references/components/date-range-picker.md +1 -0
- package/skills/iyulab-components/references/components/input.md +1 -1
- package/skills/iyulab-components/references/components/select.md +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.11.1] - 2026-10-07
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **A `chars` field holds N characters as they are drawn** (`u-input`, `u-select`, `u-date-picker`,
|
|
8
|
+
`u-date-range-picker`). The width was `N` CSS `ch`, which is one `0` without font features or letter spacing, so
|
|
9
|
+
with tabular figures (`font-variant-numeric: tabular-nums`, as the house theme sets) or letter spacing the last
|
|
10
|
+
digit was cut — six digits in Pretendard 14px overflowed by 2px. The field now draws N zeros in the text's own
|
|
11
|
+
computed font off-screen and uses that width; it re-measures when the font loads or the size changes.
|
|
12
|
+
|
|
13
|
+
## [2.11.0] - 2026-10-07
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- **`chars` on `u-select`, `u-date-picker` and `u-date-range-picker`** — the same declaration `u-input` has: an unsized
|
|
18
|
+
field draws at N characters + its suffix buttons + padding, and a sized one uses it as the text floor. These fields
|
|
19
|
+
had only the text floor (`--*-min-text`), so a consumer sized them by copying the clear, arrow and calendar button
|
|
20
|
+
boxes and the padding into a `calc()`. An unsized `u-select` also widened and narrowed with the chosen option; with
|
|
21
|
+
`chars` its width holds and a longer option ends in an ellipsis.
|
|
22
|
+
|
|
3
23
|
## [2.10.3] - 2026-10-07
|
|
4
24
|
|
|
5
25
|
### Fixed
|
|
@@ -64,6 +64,14 @@ export declare class UDatePicker extends UFormControlElement<string> {
|
|
|
64
64
|
static styles: import('lit').CSSResultGroup[];
|
|
65
65
|
/** 크기 — 다른 필드·버튼과 같은 세 단(`sm` 12px · `md` = `--u-density`(14px) · `lg` 16px). */
|
|
66
66
|
size: FieldSize;
|
|
67
|
+
/**
|
|
68
|
+
* 칸이 담을 글자 수 — 지정하면 폭을 정하지 않은 칸(기본 `inline-block`)이 «N자 + 지우기·달력 버튼 + 패딩» 폭으로 그려지고,
|
|
69
|
+
* 그보다 좁게 주면 넘친다(글자 영역 하한이 N자가 된다). 값의 표시 형식(`format`)이 정하는 길이를 주면 칸이 꼭 그만큼이다. `u-input` 의 `chars` 와 같은 축이다.
|
|
70
|
+
* 폭을 준 칸에서는 하한으로만 쓴다.
|
|
71
|
+
*/
|
|
72
|
+
chars?: number;
|
|
73
|
+
/** `chars` 의 폭 — 그려지는 N자를 잰다(`ch` 는 글꼴 기능·자간을 빼고 잰다). */
|
|
74
|
+
private readonly charsWidth;
|
|
67
75
|
/** `date` (default) selects a calendar day only. `datetime` also captures a time-of-day and
|
|
68
76
|
* the value becomes a complete ISO-8601 `DateTimeOffset` string. */
|
|
69
77
|
mode: DatePickerMode;
|
|
@@ -9,6 +9,7 @@ import { isDayUnavailable, parseISODate, toISODate } from "../calendar/dates.js"
|
|
|
9
9
|
import { UCalendar } from "../calendar/UCalendar.js";
|
|
10
10
|
import "../field/UField.js";
|
|
11
11
|
import { UPopover } from "../popover/UPopover.js";
|
|
12
|
+
import { CharsWidthController } from "../../utilities/chars.js";
|
|
12
13
|
import { DateTextController } from "../calendar/date-text-controller.js";
|
|
13
14
|
import { normalizeTime, splitDateTime, toDateTimeOffset } from "../calendar/datetime.js";
|
|
14
15
|
import { styles } from "../calendar/picker.styles.js";
|
|
@@ -38,6 +39,11 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
38
39
|
constructor(..._args) {
|
|
39
40
|
super(..._args);
|
|
40
41
|
this.size = "md";
|
|
42
|
+
this.charsWidth = new CharsWidthController(this, {
|
|
43
|
+
chars: () => this.chars,
|
|
44
|
+
text: () => this.renderRoot.querySelector(".text-input"),
|
|
45
|
+
box: () => this.renderRoot.querySelector(".container")
|
|
46
|
+
});
|
|
41
47
|
this.mode = "date";
|
|
42
48
|
this.seconds = false;
|
|
43
49
|
this.clearable = false;
|
|
@@ -171,6 +177,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
171
177
|
return (this.clearable && this.value ? 1 : 0) + 1;
|
|
172
178
|
}
|
|
173
179
|
render() {
|
|
180
|
+
const chars = this.charsWidth.width;
|
|
174
181
|
const datetime = this.mode === "datetime";
|
|
175
182
|
return html`
|
|
176
183
|
<u-field part="field"
|
|
@@ -182,8 +189,9 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
182
189
|
.validationMessage=${this.validationMessage}
|
|
183
190
|
>
|
|
184
191
|
<div class="container" part="container" @click=${this.textEntry.handleContainerClick}
|
|
185
|
-
style=${`--_icons: ${this.suffixButtonCount()}`}>
|
|
192
|
+
style=${`--_icons: ${this.suffixButtonCount()}${chars ? `; --date-picker-min-text: ${chars}` : ""}`}>
|
|
186
193
|
<input class="text-input" part="input"
|
|
194
|
+
style=${ifDefined(chars ? `inline-size: ${chars}` : void 0)}
|
|
187
195
|
type="text"
|
|
188
196
|
inputmode=${datetime ? "text" : "numeric"}
|
|
189
197
|
autocomplete="off"
|
|
@@ -390,6 +398,10 @@ __decorate([property({
|
|
|
390
398
|
type: String,
|
|
391
399
|
reflect: true
|
|
392
400
|
}), __decorateMetadata("design:type", Object)], UDatePicker.prototype, "size", void 0);
|
|
401
|
+
__decorate([property({
|
|
402
|
+
type: Number,
|
|
403
|
+
reflect: true
|
|
404
|
+
}), __decorateMetadata("design:type", Number)], UDatePicker.prototype, "chars", void 0);
|
|
393
405
|
__decorate([property({
|
|
394
406
|
type: String,
|
|
395
407
|
reflect: true
|
|
@@ -78,6 +78,14 @@ export declare class UDateRangePicker extends UFormControlElement<string> {
|
|
|
78
78
|
static styles: import('lit').CSSResultGroup[];
|
|
79
79
|
/** 크기 — 다른 필드·버튼과 같은 세 단(`sm` 12px · `md` = `--u-density`(14px) · `lg` 16px). */
|
|
80
80
|
size: FieldSize;
|
|
81
|
+
/**
|
|
82
|
+
* 칸이 담을 글자 수 — 지정하면 폭을 정하지 않은 칸(기본 `inline-block`)이 «N자 + 지우기·달력 버튼 + 패딩» 폭으로 그려지고,
|
|
83
|
+
* 그보다 좁게 주면 넘친다(글자 영역 하한이 N자가 된다). 두 날짜와 구분자(`a – b`)를 담을 길이를 준다. `u-input` 의 `chars` 와 같은 축이다.
|
|
84
|
+
* 폭을 준 칸에서는 하한으로만 쓴다.
|
|
85
|
+
*/
|
|
86
|
+
chars?: number;
|
|
87
|
+
/** `chars` 의 폭 — 그려지는 N자를 잰다(`ch` 는 글꼴 기능·자간을 빼고 잰다). */
|
|
88
|
+
private readonly charsWidth;
|
|
81
89
|
/** Earliest selectable day (ISO `YYYY-MM-DD`), inclusive. */
|
|
82
90
|
min?: string;
|
|
83
91
|
/** Latest selectable day (ISO `YYYY-MM-DD`), inclusive. */
|
|
@@ -10,6 +10,7 @@ import { parseISODate } from "../calendar/dates.js";
|
|
|
10
10
|
import { UCalendar } from "../calendar/UCalendar.js";
|
|
11
11
|
import "../field/UField.js";
|
|
12
12
|
import { UPopover } from "../popover/UPopover.js";
|
|
13
|
+
import { CharsWidthController } from "../../utilities/chars.js";
|
|
13
14
|
import { DateTextController } from "../calendar/date-text-controller.js";
|
|
14
15
|
import { normalizeTime, splitDateTime, toDateTimeOffset } from "../calendar/datetime.js";
|
|
15
16
|
import { styles } from "../calendar/picker.styles.js";
|
|
@@ -43,6 +44,11 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
|
|
|
43
44
|
constructor(..._args) {
|
|
44
45
|
super(..._args);
|
|
45
46
|
this.size = "md";
|
|
47
|
+
this.charsWidth = new CharsWidthController(this, {
|
|
48
|
+
chars: () => this.chars,
|
|
49
|
+
text: () => this.renderRoot.querySelector(".text-input"),
|
|
50
|
+
box: () => this.renderRoot.querySelector(".container")
|
|
51
|
+
});
|
|
46
52
|
this.clearable = false;
|
|
47
53
|
this.format = "iso";
|
|
48
54
|
this.presets = [];
|
|
@@ -206,6 +212,7 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
|
|
|
206
212
|
return (this.clearable && this.value ? 1 : 0) + 1;
|
|
207
213
|
}
|
|
208
214
|
render() {
|
|
215
|
+
const chars = this.charsWidth.width;
|
|
209
216
|
const pattern = this.mode === "datetime" ? `${dateTextPattern(this.format)} ${this.seconds ? "HH:mm:ss" : "HH:mm"}` : dateTextPattern(this.format);
|
|
210
217
|
return html`
|
|
211
218
|
<u-field part="field"
|
|
@@ -217,8 +224,9 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
|
|
|
217
224
|
.validationMessage=${this.validationMessage}
|
|
218
225
|
>
|
|
219
226
|
<div class="container" part="container" @click=${this.textEntry.handleContainerClick}
|
|
220
|
-
style=${`--_icons: ${this.suffixButtonCount()}`}>
|
|
227
|
+
style=${`--_icons: ${this.suffixButtonCount()}${chars ? `; --date-range-picker-min-text: ${chars}` : ""}`}>
|
|
221
228
|
<input class="text-input" part="input"
|
|
229
|
+
style=${ifDefined(chars ? `inline-size: ${chars}` : void 0)}
|
|
222
230
|
type="text"
|
|
223
231
|
autocomplete="off"
|
|
224
232
|
role="combobox"
|
|
@@ -462,6 +470,10 @@ __decorate([property({
|
|
|
462
470
|
type: String,
|
|
463
471
|
reflect: true
|
|
464
472
|
}), __decorateMetadata("design:type", Object)], UDateRangePicker.prototype, "size", void 0);
|
|
473
|
+
__decorate([property({
|
|
474
|
+
type: Number,
|
|
475
|
+
reflect: true
|
|
476
|
+
}), __decorateMetadata("design:type", Number)], UDateRangePicker.prototype, "chars", void 0);
|
|
465
477
|
__decorate([property({ type: String }), __decorateMetadata("design:type", String)], UDateRangePicker.prototype, "min", void 0);
|
|
466
478
|
__decorate([property({ type: String }), __decorateMetadata("design:type", String)], UDateRangePicker.prototype, "max", void 0);
|
|
467
479
|
__decorate([property({
|
|
@@ -96,6 +96,8 @@ export declare class UInput extends UFormControlElement<string> {
|
|
|
96
96
|
* `size` 는 이 컴포넌트에서 크기 단(sm·md·lg)이라 이름이 다르다. 폭을 준 칸(`width`·`block`)에서는 하한으로만 쓴다.
|
|
97
97
|
*/
|
|
98
98
|
chars?: number;
|
|
99
|
+
/** `chars` 의 폭 — 그려지는 N자를 잰다(`ch` 는 글꼴 기능·자간을 빼고 잰다). */
|
|
100
|
+
private readonly charsWidth;
|
|
99
101
|
placeholder?: string;
|
|
100
102
|
/** 유효성 검사 패턴 (정규식) */
|
|
101
103
|
pattern?: string;
|
|
@@ -121,8 +123,6 @@ export declare class UInput extends UFormControlElement<string> {
|
|
|
121
123
|
* `string`이라 `valueAsString` 같은 변환 없이 그대로 넘긴다. */
|
|
122
124
|
protected willUpdate(changedProperties: PropertyValues): void;
|
|
123
125
|
protected updated(changedProperties: PropertyValues): void;
|
|
124
|
-
/** `chars` 를 CSS 길이로 — 양의 정수일 때만(그 밖은 지정 없음과 같다). */
|
|
125
|
-
private get charsWidth();
|
|
126
126
|
/** The shown number uses the locale's decimal separator — re-show it in the new locale (unless the user is typing in it). */
|
|
127
127
|
protected localeChanged(): void;
|
|
128
128
|
/** Canonical `value` → the text shown: the locale's decimal separator, no grouping inserted. */
|
|
@@ -8,6 +8,7 @@ import "../icon/UIcon.js";
|
|
|
8
8
|
import { parseNumber } from "../../utilities/format.js";
|
|
9
9
|
import "../field/UField.js";
|
|
10
10
|
import "../popover/UPopover.js";
|
|
11
|
+
import { CharsWidthController } from "../../utilities/chars.js";
|
|
11
12
|
import { UOption } from "../option/UOption.js";
|
|
12
13
|
import { styles } from "./UInput.styles.js";
|
|
13
14
|
import { html } from "lit";
|
|
@@ -26,6 +27,11 @@ var UInput = class UInput extends UFormControlElement {
|
|
|
26
27
|
this.autocorrect = false;
|
|
27
28
|
this.autocapitalize = "off";
|
|
28
29
|
this.size = "md";
|
|
30
|
+
this.charsWidth = new CharsWidthController(this, {
|
|
31
|
+
chars: () => this.chars,
|
|
32
|
+
text: () => this.renderRoot.querySelector("input"),
|
|
33
|
+
box: () => this.renderRoot.querySelector(".container")
|
|
34
|
+
});
|
|
29
35
|
this.showPassword = false;
|
|
30
36
|
this.numberText = "";
|
|
31
37
|
this.syncingFromText = false;
|
|
@@ -194,12 +200,12 @@ var UInput = class UInput extends UFormControlElement {
|
|
|
194
200
|
.validationMessage=${this.validationMessage}
|
|
195
201
|
>
|
|
196
202
|
<div class="container" part="container"
|
|
197
|
-
style=${`--_icons: ${(showStepper ? 2 : 0) + (showClear ? 1 : 0) + (showToggle ? 1 : 0)}${this.charsWidth ? `; --input-min-text: ${this.charsWidth}` : ""}`}>
|
|
203
|
+
style=${`--_icons: ${(showStepper ? 2 : 0) + (showClear ? 1 : 0) + (showToggle ? 1 : 0)}${this.charsWidth.width ? `; --input-min-text: ${this.charsWidth.width}` : ""}`}>
|
|
198
204
|
|
|
199
205
|
<slot name="prefix"></slot>
|
|
200
206
|
|
|
201
207
|
<input part="input"
|
|
202
|
-
style=${ifDefined(this.charsWidth ? `inline-size: ${this.charsWidth}` : void 0)}
|
|
208
|
+
style=${ifDefined(this.charsWidth.width ? `inline-size: ${this.charsWidth.width}` : void 0)}
|
|
203
209
|
type=${isNumber || this.type === "password" && this.showPassword ? "text" : this.type}
|
|
204
210
|
aria-label=${ifDefined(this.resolvedAriaLabel)}
|
|
205
211
|
aria-description=${ifDefined(this.resolvedAriaDescription)}
|
|
@@ -306,11 +312,6 @@ var UInput = class UInput extends UFormControlElement {
|
|
|
306
312
|
super.updated(changedProperties);
|
|
307
313
|
if (changedProperties.has("value")) this.internals?.setFormValue(this.value ?? "");
|
|
308
314
|
}
|
|
309
|
-
/** `chars` 를 CSS 길이로 — 양의 정수일 때만(그 밖은 지정 없음과 같다). */
|
|
310
|
-
get charsWidth() {
|
|
311
|
-
const n = this.chars;
|
|
312
|
-
return n != null && Number.isFinite(n) && n > 0 ? `${Math.ceil(n)}ch` : void 0;
|
|
313
|
-
}
|
|
314
315
|
/** The shown number uses the locale's decimal separator — re-show it in the new locale (unless the user is typing in it). */
|
|
315
316
|
localeChanged() {
|
|
316
317
|
if (this.type === "number" && this.shadowRoot?.activeElement !== this.inputEl) this.numberText = this.displayNumber(this.value ?? "");
|
|
@@ -49,6 +49,14 @@ export declare class USelect extends UFormControlElement<string | string[]> {
|
|
|
49
49
|
* 한 줄에 서도록. 테마는 필드 상자 토큰(`--u-field-padding-block`)으로 단마다 높이를 다듬는다.
|
|
50
50
|
*/
|
|
51
51
|
size: FieldSize;
|
|
52
|
+
/**
|
|
53
|
+
* 칸이 담을 글자 수 — 지정하면 폭을 정하지 않은 칸(기본 `inline-block`)이 «N자 + 지우기·펼침 화살표 + 패딩» 폭으로 그려져
|
|
54
|
+
* 고른 값이 바뀌어도 폭이 흔들리지 않고(더 긴 값은 말줄임), 그보다 좁게 주면 넘친다(표시 글자 하한이 N자가 된다).
|
|
55
|
+
* `u-input` 의 `chars` 와 같은 축이다. 폭을 준 칸(`--u-select-width`·`block`)에서는 하한으로만 쓴다.
|
|
56
|
+
*/
|
|
57
|
+
chars?: number;
|
|
58
|
+
/** `chars` 의 폭 — 그려지는 N자를 잰다(`ch` 는 글꼴 기능·자간을 빼고 잰다). */
|
|
59
|
+
private readonly charsWidth;
|
|
52
60
|
/** 다중 선택 여부 */
|
|
53
61
|
multiple: boolean;
|
|
54
62
|
/** 검색 가능 여부 */
|
|
@@ -7,6 +7,7 @@ import "../icon/UIcon.js";
|
|
|
7
7
|
import "../chip/UChip.js";
|
|
8
8
|
import "../field/UField.js";
|
|
9
9
|
import "../popover/UPopover.js";
|
|
10
|
+
import { CharsWidthController } from "../../utilities/chars.js";
|
|
10
11
|
import { UOption } from "../option/UOption.js";
|
|
11
12
|
import { styles } from "./USelect.styles.js";
|
|
12
13
|
import { html } from "lit";
|
|
@@ -18,6 +19,11 @@ var USelect = class USelect extends UFormControlElement {
|
|
|
18
19
|
super(..._args);
|
|
19
20
|
this.appearance = "outlined";
|
|
20
21
|
this.size = "md";
|
|
22
|
+
this.charsWidth = new CharsWidthController(this, {
|
|
23
|
+
chars: () => this.chars,
|
|
24
|
+
text: () => this.renderRoot.querySelector(".text-content, .chips-content"),
|
|
25
|
+
box: () => this.renderRoot.querySelector(".container")
|
|
26
|
+
});
|
|
21
27
|
this.multiple = false;
|
|
22
28
|
this.searchable = false;
|
|
23
29
|
this.clearable = false;
|
|
@@ -165,6 +171,7 @@ var USelect = class USelect extends UFormControlElement {
|
|
|
165
171
|
if (changedProperties.has("open")) this.internals?.states[this.open ? "add" : "delete"]("open");
|
|
166
172
|
}
|
|
167
173
|
render() {
|
|
174
|
+
const chars = this.charsWidth.width;
|
|
168
175
|
return html`
|
|
169
176
|
<u-field part="field"
|
|
170
177
|
?required=${this.required}
|
|
@@ -179,7 +186,7 @@ var USelect = class USelect extends UFormControlElement {
|
|
|
179
186
|
</span>
|
|
180
187
|
|
|
181
188
|
<div class="container" part="container" tabindex=${this.effectivelyDisabled ? "-1" : "0"}
|
|
182
|
-
style=${`--_clear: ${this.clearable && this.hasValue && !this.effectivelyDisabled && !this.readonly ? 1 : 0}`}
|
|
189
|
+
style=${`--_clear: ${this.clearable && this.hasValue && !this.effectivelyDisabled && !this.readonly ? 1 : 0}${chars ? `; --select-min-text: ${chars}; --_chars: ${chars}` : ""}`}
|
|
183
190
|
role="combobox"
|
|
184
191
|
aria-disabled=${ifDefined(this.effectivelyDisabled ? "true" : void 0)}
|
|
185
192
|
aria-label=${ifDefined(this.resolvedAriaLabel)}
|
|
@@ -343,6 +350,10 @@ __decorate([property({
|
|
|
343
350
|
type: String,
|
|
344
351
|
reflect: true
|
|
345
352
|
}), __decorateMetadata("design:type", Object)], USelect.prototype, "size", void 0);
|
|
353
|
+
__decorate([property({
|
|
354
|
+
type: Number,
|
|
355
|
+
reflect: true
|
|
356
|
+
}), __decorateMetadata("design:type", Number)], USelect.prototype, "chars", void 0);
|
|
346
357
|
__decorate([property({
|
|
347
358
|
type: Boolean,
|
|
348
359
|
reflect: true
|
|
@@ -163,6 +163,13 @@ var styles = css`
|
|
|
163
163
|
color: var(--u-txt-color-weak, #616161);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
/* chars — 표시 글자 요소의 폭을 N자로(렌더가 --_chars 를 준다). 고유 폭 계산에서 고른 값의 길이 대신 이 값이 쓰여
|
|
167
|
+
칸이 값마다 흔들리지 않고, 폭을 받은 칸에서는 flex: 1 이 그대로 채운다. 없으면 종전 auto. */
|
|
168
|
+
.text-content,
|
|
169
|
+
.chips-content {
|
|
170
|
+
inline-size: var(--_chars, auto);
|
|
171
|
+
}
|
|
172
|
+
|
|
166
173
|
.chips-content {
|
|
167
174
|
flex: 1;
|
|
168
175
|
min-width: 0;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
/** `chars` 가 유효한 글자 수인가 — 양의 유한수일 때만(그 밖은 지정 없음과 같다). 소수는 올린다. */
|
|
3
|
+
export declare function charsCount(n: number | undefined | null): number | undefined;
|
|
4
|
+
/** 이 컨트롤러가 측정하는 컨트롤이 내주는 것. */
|
|
5
|
+
export interface CharsWidthOptions {
|
|
6
|
+
/** 칸이 담을 글자 수(`chars` 속성). */
|
|
7
|
+
chars(): number | undefined;
|
|
8
|
+
/** 글자를 그리는 요소 — 그 계산된 글꼴로 잰다. 없으면 `box` 의 글꼴로. */
|
|
9
|
+
text(): HTMLElement | null | undefined;
|
|
10
|
+
/** 측정용 요소를 붙일 자리(글자 영역을 담는 컨테이너). */
|
|
11
|
+
box(): HTMLElement | null | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* `chars` 의 폭 — «N자 칸» 을 **그려지는 N자** 로 잰다.
|
|
15
|
+
*
|
|
16
|
+
* CSS `ch` 는 글꼴 기능을 뺀 `0` 하나의 폭이다. 숫자를 고정폭(`font-variant-numeric: tabular-nums`)으로 그리거나
|
|
17
|
+
* 자간(`letter-spacing`)을 주면 N자가 `Nch` 를 넘어, «N자리 숫자 칸» 이 마지막 숫자를 잘랐다(Pretendard 14px 에서 자당
|
|
18
|
+
* 0.33px — 6자리면 2px). 그래서 글자 요소의 계산된 글꼴을 옮긴 보이지 않는 요소에 `0` N개를 실제로 그리고 그 폭을 쓴다.
|
|
19
|
+
* 크기는 `ResizeObserver` 로 따른다 — 웹 글꼴이 늦게 실리거나 크기 단(`size`)이 바뀌어 폭이 달라지면 다시 읽는다.
|
|
20
|
+
* 재기 전(첫 그림)에는 `Nch` 로 그린다.
|
|
21
|
+
*/
|
|
22
|
+
export declare class CharsWidthController implements ReactiveController {
|
|
23
|
+
private readonly host;
|
|
24
|
+
private readonly options;
|
|
25
|
+
private sizer?;
|
|
26
|
+
private observer?;
|
|
27
|
+
private measured?;
|
|
28
|
+
constructor(host: ReactiveControllerHost & HTMLElement, options: CharsWidthOptions);
|
|
29
|
+
/** 글자 영역의 CSS 길이 — 잰 폭(px), 재기 전에는 `Nch`, `chars` 가 없으면 `undefined`. */
|
|
30
|
+
get width(): string | undefined;
|
|
31
|
+
hostUpdated(): void;
|
|
32
|
+
hostDisconnected(): void;
|
|
33
|
+
private measure;
|
|
34
|
+
private read;
|
|
35
|
+
private release;
|
|
36
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
//#region src/utilities/chars.ts
|
|
2
|
+
/** `chars` 가 유효한 글자 수인가 — 양의 유한수일 때만(그 밖은 지정 없음과 같다). 소수는 올린다. */
|
|
3
|
+
function charsCount(n) {
|
|
4
|
+
return n != null && Number.isFinite(n) && n > 0 ? Math.ceil(n) : void 0;
|
|
5
|
+
}
|
|
6
|
+
/** 측정용 요소에 옮기는 글꼴 속성 — 그려지는 글자 폭을 바꾸는 것 전부. */
|
|
7
|
+
var FONT_PROPS = [
|
|
8
|
+
"font-family",
|
|
9
|
+
"font-size",
|
|
10
|
+
"font-weight",
|
|
11
|
+
"font-style",
|
|
12
|
+
"font-stretch",
|
|
13
|
+
"font-variant-numeric",
|
|
14
|
+
"font-feature-settings",
|
|
15
|
+
"font-variation-settings",
|
|
16
|
+
"font-kerning",
|
|
17
|
+
"letter-spacing"
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* `chars` 의 폭 — «N자 칸» 을 **그려지는 N자** 로 잰다.
|
|
21
|
+
*
|
|
22
|
+
* CSS `ch` 는 글꼴 기능을 뺀 `0` 하나의 폭이다. 숫자를 고정폭(`font-variant-numeric: tabular-nums`)으로 그리거나
|
|
23
|
+
* 자간(`letter-spacing`)을 주면 N자가 `Nch` 를 넘어, «N자리 숫자 칸» 이 마지막 숫자를 잘랐다(Pretendard 14px 에서 자당
|
|
24
|
+
* 0.33px — 6자리면 2px). 그래서 글자 요소의 계산된 글꼴을 옮긴 보이지 않는 요소에 `0` N개를 실제로 그리고 그 폭을 쓴다.
|
|
25
|
+
* 크기는 `ResizeObserver` 로 따른다 — 웹 글꼴이 늦게 실리거나 크기 단(`size`)이 바뀌어 폭이 달라지면 다시 읽는다.
|
|
26
|
+
* 재기 전(첫 그림)에는 `Nch` 로 그린다.
|
|
27
|
+
*/
|
|
28
|
+
var CharsWidthController = class {
|
|
29
|
+
constructor(host, options) {
|
|
30
|
+
this.host = host;
|
|
31
|
+
this.options = options;
|
|
32
|
+
host.addController(this);
|
|
33
|
+
}
|
|
34
|
+
/** 글자 영역의 CSS 길이 — 잰 폭(px), 재기 전에는 `Nch`, `chars` 가 없으면 `undefined`. */
|
|
35
|
+
get width() {
|
|
36
|
+
const n = charsCount(this.options.chars());
|
|
37
|
+
if (!n) return void 0;
|
|
38
|
+
return this.measured != null ? `${this.measured}px` : `${n}ch`;
|
|
39
|
+
}
|
|
40
|
+
hostUpdated() {
|
|
41
|
+
this.measure();
|
|
42
|
+
}
|
|
43
|
+
hostDisconnected() {
|
|
44
|
+
this.release();
|
|
45
|
+
}
|
|
46
|
+
measure() {
|
|
47
|
+
const n = charsCount(this.options.chars());
|
|
48
|
+
const box = this.options.box();
|
|
49
|
+
if (!n || !box) {
|
|
50
|
+
if (this.sizer) {
|
|
51
|
+
this.release();
|
|
52
|
+
this.host.requestUpdate();
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!this.sizer || this.sizer.parentNode?.parentNode !== box) {
|
|
57
|
+
this.release();
|
|
58
|
+
const frame = document.createElement("span");
|
|
59
|
+
frame.setAttribute("aria-hidden", "true");
|
|
60
|
+
frame.style.cssText = "position:absolute;inset-block-start:0;inset-inline-start:0;inline-size:0;block-size:0;overflow:hidden;visibility:hidden;pointer-events:none";
|
|
61
|
+
const sizer = document.createElement("span");
|
|
62
|
+
sizer.style.cssText = "display:inline-block;white-space:pre";
|
|
63
|
+
frame.appendChild(sizer);
|
|
64
|
+
box.appendChild(frame);
|
|
65
|
+
this.sizer = sizer;
|
|
66
|
+
this.observer = new ResizeObserver((entries) => this.read(entries[entries.length - 1].contentRect.width));
|
|
67
|
+
this.observer.observe(sizer);
|
|
68
|
+
}
|
|
69
|
+
const sizer = this.sizer;
|
|
70
|
+
const source = getComputedStyle(this.options.text() ?? box);
|
|
71
|
+
for (const prop of FONT_PROPS) sizer.style.setProperty(prop, source.getPropertyValue(prop));
|
|
72
|
+
const digits = "0".repeat(n);
|
|
73
|
+
if (sizer.textContent !== digits) sizer.textContent = digits;
|
|
74
|
+
}
|
|
75
|
+
read(width) {
|
|
76
|
+
if (!(width > 0)) return;
|
|
77
|
+
const rounded = Math.ceil(width);
|
|
78
|
+
if (rounded === this.measured) return;
|
|
79
|
+
this.measured = rounded;
|
|
80
|
+
this.host.requestUpdate();
|
|
81
|
+
}
|
|
82
|
+
release() {
|
|
83
|
+
this.observer?.disconnect();
|
|
84
|
+
this.observer = void 0;
|
|
85
|
+
this.sizer?.parentElement?.remove();
|
|
86
|
+
this.sizer = void 0;
|
|
87
|
+
this.measured = void 0;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
//#endregion
|
|
91
|
+
export { CharsWidthController, charsCount };
|
package/package.json
CHANGED
|
@@ -82,6 +82,7 @@ starts from the value. Typing in the text box still commits on Enter or leaving
|
|
|
82
82
|
| `min` | `string` | — | — | Minimum selectable date (ISO `YYYY-MM-DD`, date-only in both modes) |
|
|
83
83
|
| `max` | `string` | — | — | Maximum selectable date (ISO `YYYY-MM-DD`, date-only in both modes) |
|
|
84
84
|
| `size` | `'sm'\|'md'\|'lg'` | `'md'` | ✓ | Field size, like a button's: 12px · `--u-density` (14px) · 16px. A field and a button of the same size share a height |
|
|
85
|
+
| `chars` | `number` | — | ✓ | Characters the field holds. An unsized field draws at N characters + its clear and calendar buttons + padding; a sized one uses it as the text floor, so a narrower box overflows. Give the length of the `format` pattern for a box that fits it exactly. Same axis as `u-input`'s `chars`. N characters are measured as drawn — tabular figures and letter spacing count, which CSS `ch` leaves out |
|
|
85
86
|
| `clearable` | `boolean` | `false` | ✓ | Show clear button |
|
|
86
87
|
| `isDateDisabled` | `(date: string) => boolean` | — | — | App rule for days that cannot be chosen (ISO in, `true` = disabled). Property only; see «Disabled days» |
|
|
87
88
|
| `placeholder` | `string` | — | — | Placeholder text (defaults to the pattern to type, e.g. `YYYY-MM-DD` or `YYYY-MM-DD HH:mm`) |
|
|
@@ -138,6 +138,7 @@ picker.addEventListener('change', () => {
|
|
|
138
138
|
| `min` | `string` | — | — | Earliest selectable day (ISO `YYYY-MM-DD`), inclusive |
|
|
139
139
|
| `max` | `string` | — | — | Latest selectable day (ISO `YYYY-MM-DD`), inclusive |
|
|
140
140
|
| `size` | `'sm'\|'md'\|'lg'` | `'md'` | ✓ | Field size, like a button's: 12px · `--u-density` (14px) · 16px. A field and a button of the same size share a height |
|
|
141
|
+
| `chars` | `number` | — | ✓ | Characters the field holds — both dates and the separator (`a – b`). An unsized field draws at N characters + its clear and calendar buttons + padding; a sized one uses it as the text floor, so a narrower box overflows. Same axis as `u-input`'s `chars`. N characters are measured as drawn — tabular figures and letter spacing count, which CSS `ch` leaves out |
|
|
141
142
|
| `clearable` | `boolean` | `false` | ✓ | Show clear button |
|
|
142
143
|
| `isDateDisabled` | `(date: string) => boolean` | — | — | App rule for days that cannot start or end a range (ISO in, `true` = disabled). Property only; see «Disabled days» |
|
|
143
144
|
| `placeholder` | `string` | — | — | Placeholder text (defaults to the pattern to type) |
|
|
@@ -57,7 +57,7 @@ the library does not infer one from field meaning.
|
|
|
57
57
|
| `appearance` | `'outlined'\|'soft'\|'underlined'\|'plain'` | `'outlined'` | ✓ | How much chrome: `outlined` · `soft` tinted face · `underlined` bottom line only · `plain` no chrome |
|
|
58
58
|
| `size` | `'sm'\|'md'\|'lg'` | `'md'` | ✓ | Field size, like a button's: 12px · `--u-density` (14px) · 16px. A field and a button of the same size share a height |
|
|
59
59
|
| `type` | `'text'\|'password'\|'email'\|'tel'\|'url'\|'search'\|'number'\|'date'\|'time'`… | `'text'` | — | Input type |
|
|
60
|
-
| `chars` | `number` | — | ✓ | Characters the field holds. An unsized field draws at N characters + its suffix icons + padding; a sized one (`width`, `block`) uses it as the text floor, so a narrower box overflows. Not `size` — that is the sm/md/lg scale |
|
|
60
|
+
| `chars` | `number` | — | ✓ | Characters the field holds. An unsized field draws at N characters + its suffix icons + padding; a sized one (`width`, `block`) uses it as the text floor, so a narrower box overflows. Not `size` — that is the sm/md/lg scale. N characters are measured as drawn — tabular figures and letter spacing count, which CSS `ch` leaves out |
|
|
61
61
|
| `placeholder` | `string` | — | — | Placeholder text |
|
|
62
62
|
| `clearable` | `boolean` | `false` | ✓ | Show clear button |
|
|
63
63
|
| `minlength` | `number` | — | — | Minimum character count |
|
|
@@ -39,6 +39,7 @@ Dropdown select with single or multiple selection, search, and clear support. Fo
|
|
|
39
39
|
| `value` | `string \| string[]` | — | — | Selected value(s) |
|
|
40
40
|
| `appearance` | `'outlined'\|'soft'\|'underlined'\|'plain'` | `'outlined'` | ✓ | How much chrome: `outlined` · `soft` tinted face · `underlined` bottom line only · `plain` no chrome |
|
|
41
41
|
| `size` | `'sm'\|'md'\|'lg'` | `'md'` | ✓ | Field size, like a button's: 12px · `--u-density` (14px) · 16px. A field and a button of the same size share a height |
|
|
42
|
+
| `chars` | `number` | — | ✓ | Characters the field holds. An unsized field draws at N characters + its clear button and arrow + padding, so it no longer widens and narrows with the chosen option (a longer one ends in an ellipsis); a sized one (`--u-select-width`, `block`) uses it as the text floor, so a narrower box overflows. Same axis as `u-input`'s `chars`. N characters are measured as drawn — tabular figures and letter spacing count, which CSS `ch` leaves out |
|
|
42
43
|
| `multiple` | `boolean` | `false` | ✓ | Allow multiple selections |
|
|
43
44
|
| `searchable` | `boolean` | `false` | ✓ | Filter options by text |
|
|
44
45
|
| `clearable` | `boolean` | `false` | ✓ | Show clear button |
|