@iyulab/components 2.35.0 → 2.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/dist/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.156.0}/helpers/esm/decorate.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.155.0 → _@oxc-project_runtime@0.156.0}/helpers/esm/decorateMetadata.js +1 -1
- package/dist/components/UFloatingElement.js +3 -3
- package/dist/components/UFormControlElement.js +2 -2
- package/dist/components/UOverlayElement.js +3 -3
- package/dist/components/alert/UAlert.js +6 -6
- package/dist/components/auto-scroll/UAutoScroll.js +2 -2
- package/dist/components/avatar/UAvatar.js +2 -2
- package/dist/components/badge/UBadge.js +4 -4
- package/dist/components/breadcrumb/UBreadcrumb.js +3 -3
- package/dist/components/breadcrumb-item/UBreadcrumbItem.js +3 -3
- package/dist/components/button/UButton.js +3 -3
- package/dist/components/button/UButton.styles.js +6 -2
- package/dist/components/button-group/UButtonGroup.js +2 -2
- package/dist/components/calendar/UCalendar.js +4 -4
- package/dist/components/calendar/datetime.js +1 -1
- package/dist/components/card/UCard.js +2 -2
- package/dist/components/carousel/UCarousel.js +5 -5
- package/dist/components/carousel/UCarousel.styles.js +4 -0
- package/dist/components/checkbox/UCheckbox.js +4 -4
- package/dist/components/chip/UChip.js +6 -6
- package/dist/components/command-palette/UCommandPalette.js +6 -6
- package/dist/components/copy-button/UCopyButton.js +5 -5
- package/dist/components/date-picker/UDatePicker.js +8 -8
- package/dist/components/date-range-picker/UDateRangePicker.d.ts +8 -0
- package/dist/components/date-range-picker/UDateRangePicker.js +31 -13
- package/dist/components/dialog/UDialog.js +4 -4
- package/dist/components/divider/UDivider.js +2 -2
- package/dist/components/drawer/UDrawer.js +4 -4
- package/dist/components/drawer/UDrawer.styles.js +16 -0
- package/dist/components/expander/UExpander.js +3 -3
- package/dist/components/field/UField.js +4 -4
- package/dist/components/file-input/UFileInput.js +5 -5
- package/dist/components/form/UForm.js +3 -3
- package/dist/components/icon/UIcon.js +2 -2
- package/dist/components/icon-button/UIconButton.js +4 -4
- package/dist/components/input/UInput.js +9 -9
- package/dist/components/menu/UMenu.js +3 -3
- package/dist/components/menu-item/UMenuItem.js +5 -5
- package/dist/components/option/UOption.js +4 -4
- package/dist/components/option-group/UOptionGroup.js +2 -2
- package/dist/components/pagination/UPagination.js +5 -5
- package/dist/components/panel/UPanel.js +2 -2
- package/dist/components/popover/UPopover.js +3 -3
- package/dist/components/progress-bar/UProgressBar.js +2 -2
- package/dist/components/progress-ring/UProgressRing.js +2 -2
- package/dist/components/radio/URadio.js +4 -4
- package/dist/components/rating/URating.js +5 -5
- package/dist/components/select/USelect.js +10 -10
- package/dist/components/skeleton/USkeleton.js +2 -2
- package/dist/components/slider/USlider.js +5 -5
- package/dist/components/spinner/USpinner.js +4 -4
- package/dist/components/split-panel/USplitPanel.js +4 -4
- package/dist/components/steps/USteps.d.ts +14 -0
- package/dist/components/steps/USteps.js +38 -3
- package/dist/components/steps/USteps.styles.js +16 -0
- package/dist/components/switch/USwitch.js +3 -3
- package/dist/components/tab/UTab.js +6 -6
- package/dist/components/tab-nav/UTabNav.js +2 -2
- package/dist/components/tab-panel/UTabPanel.js +4 -4
- package/dist/components/tag/UTag.js +3 -3
- package/dist/components/text/UText.js +2 -2
- package/dist/components/textarea/UTextarea.js +4 -4
- package/dist/components/tooltip/UTooltip.js +3 -3
- package/dist/components/tree/UTree.js +3 -3
- package/dist/components/tree-item/UTreeItem.js +6 -6
- package/dist/index.d.ts +1 -0
- package/dist/index.js +26 -25
- package/dist/utilities/Dialog.js +2 -2
- package/dist/utilities/Theme.js +1 -1
- package/dist/utilities/Toast.js +1 -1
- package/dist/utilities/chars.d.ts +2 -0
- package/dist/utilities/chars.js +1 -1
- package/dist/utilities/numberFormat.d.ts +23 -0
- package/dist/utilities/numberFormat.js +260 -0
- package/package.json +1 -1
- package/skills/iyulab-components/SKILL.md +1 -0
- package/skills/iyulab-components/references/components/steps.md +4 -0
- package/skills/iyulab-components/references/utilities/format.md +2 -0
- package/skills/iyulab-components/references/utilities/number-format.md +55 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import "../icon/UIcon.js";
|
|
2
|
+
import "../spinner/USpinner.js";
|
|
1
3
|
import { UElement } from "../UElement.js";
|
|
2
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorateMetadata.js";
|
|
3
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.155.0/helpers/esm/decorate.js";
|
|
4
4
|
import { HostAria } from "../../utilities/hostAria.js";
|
|
5
|
-
import "../spinner/USpinner.js";
|
|
6
|
-
import { SlotPresence } from "../../utilities/slotPresence.js";
|
|
7
|
-
import "../icon/UIcon.js";
|
|
8
|
-
import { isFromNestedControl } from "../../utilities/nestedControl.js";
|
|
9
5
|
import { styles } from "./UTreeItem.styles.js";
|
|
6
|
+
import { isFromNestedControl } from "../../utilities/nestedControl.js";
|
|
7
|
+
import { SlotPresence } from "../../utilities/slotPresence.js";
|
|
8
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/decorateMetadata.js";
|
|
9
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/decorate.js";
|
|
10
10
|
import { html } from "lit";
|
|
11
11
|
import { customElement, property, state } from "lit/decorators.js";
|
|
12
12
|
// src/components/tree-item/UTreeItem.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export * from './utilities/devWarning.js';
|
|
|
72
72
|
export * from './utilities/Dialog.js';
|
|
73
73
|
export * from './utilities/elements.js';
|
|
74
74
|
export * from './utilities/format.js';
|
|
75
|
+
export * from './utilities/numberFormat.js';
|
|
75
76
|
export * from './utilities/icons.js';
|
|
76
77
|
export * from './utilities/keyboard.js';
|
|
77
78
|
export * from './utilities/composition.js';
|
package/dist/index.js
CHANGED
|
@@ -1,75 +1,76 @@
|
|
|
1
|
-
import { defaultSearchMatch, foldForSearch, hangulKeystrokes, initialsOf, isHangul } from "./utilities/search.js";
|
|
2
|
-
import { Locale } from "./utilities/Locale.js";
|
|
3
1
|
import { UElement } from "./components/UElement.js";
|
|
4
|
-
import { getParentElement, isCoarsePointer, isFocusCandidate, isFromControl, querySelectorAllWithin, querySelectorDeep, querySelectorWithin } from "./utilities/elements.js";
|
|
5
2
|
import { UFloatingElement } from "./components/UFloatingElement.js";
|
|
6
3
|
import { UFormControlElement } from "./components/UFormControlElement.js";
|
|
7
|
-
import { isImeComposing } from "./utilities/keyboard.js";
|
|
8
|
-
import { OverlayManager } from "./utilities/OverlayManager.js";
|
|
9
|
-
import { arrayAttrConverter, booleanAttrConverter, dateAttrConverter, jsonAttrConverter, urlAttrConverter } from "./utilities/converters.js";
|
|
10
4
|
import { UOverlayElement } from "./components/UOverlayElement.js";
|
|
11
|
-
import { USpinner } from "./components/spinner/USpinner.js";
|
|
12
|
-
import { UButton } from "./components/button/UButton.js";
|
|
13
|
-
import { IconCache, IconRegistry, getDefaultBaseUrl, setDefaultBaseUrl } from "./utilities/icons.js";
|
|
14
|
-
import { createDevWarner, devWarnOnce, resetDevWarnings } from "./utilities/devWarning.js";
|
|
15
|
-
import { UIcon } from "./components/icon/UIcon.js";
|
|
16
5
|
import { ALERT_STATUSES, UAlert } from "./components/alert/UAlert.js";
|
|
17
6
|
import { UAvatar } from "./components/avatar/UAvatar.js";
|
|
18
7
|
import { UBadge } from "./components/badge/UBadge.js";
|
|
19
8
|
import { UBreadcrumb } from "./components/breadcrumb/UBreadcrumb.js";
|
|
20
9
|
import { UBreadcrumbItem } from "./components/breadcrumb-item/UBreadcrumbItem.js";
|
|
21
|
-
import {
|
|
22
|
-
import { UIconButton } from "./components/icon-button/UIconButton.js";
|
|
10
|
+
import { UButton } from "./components/button/UButton.js";
|
|
23
11
|
import { UButtonGroup } from "./components/button-group/UButtonGroup.js";
|
|
24
12
|
import { UCard } from "./components/card/UCard.js";
|
|
25
13
|
import { UAutoScroll } from "./components/auto-scroll/UAutoScroll.js";
|
|
26
14
|
import { UCarousel } from "./components/carousel/UCarousel.js";
|
|
27
15
|
import { UCommandPalette, filterCommands } from "./components/command-palette/UCommandPalette.js";
|
|
28
16
|
import { UCheckbox } from "./components/checkbox/UCheckbox.js";
|
|
29
|
-
import { UTag } from "./components/tag/UTag.js";
|
|
30
17
|
import { UChip } from "./components/chip/UChip.js";
|
|
31
18
|
import { UCopyButton } from "./components/copy-button/UCopyButton.js";
|
|
32
|
-
import { localOffset, readDateValue, writeInstant, writePlainDate, writePlainDateTime } from "./utilities/dateValue.js";
|
|
33
|
-
import { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeRangeText, formatDateTimeText, formatNumber, parseDate, parseDateRange, parseDateTime, parseDateTimeRange, parseNumber } from "./utilities/format.js";
|
|
34
|
-
import { UField } from "./components/field/UField.js";
|
|
35
|
-
import { UPopover } from "./components/popover/UPopover.js";
|
|
36
19
|
import { UDatePicker } from "./components/date-picker/UDatePicker.js";
|
|
37
20
|
import { UDateRangePicker } from "./components/date-range-picker/UDateRangePicker.js";
|
|
38
21
|
import { UDialog } from "./components/dialog/UDialog.js";
|
|
39
22
|
import { UDivider } from "./components/divider/UDivider.js";
|
|
40
23
|
import { UDrawer } from "./components/drawer/UDrawer.js";
|
|
41
24
|
import { UExpander } from "./components/expander/UExpander.js";
|
|
25
|
+
import { UField } from "./components/field/UField.js";
|
|
42
26
|
import { UFileInput } from "./components/file-input/UFileInput.js";
|
|
43
27
|
import { UForm } from "./components/form/UForm.js";
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
28
|
+
import { UIcon } from "./components/icon/UIcon.js";
|
|
29
|
+
import { UIconButton } from "./components/icon-button/UIconButton.js";
|
|
46
30
|
import { UInput } from "./components/input/UInput.js";
|
|
47
|
-
import { UMenuItem } from "./components/menu-item/UMenuItem.js";
|
|
48
31
|
import { UMenu } from "./components/menu/UMenu.js";
|
|
49
|
-
import {
|
|
50
|
-
import {
|
|
32
|
+
import { UMenuItem } from "./components/menu-item/UMenuItem.js";
|
|
33
|
+
import { UOption } from "./components/option/UOption.js";
|
|
34
|
+
import { UOptionGroup, collectOptions } from "./components/option-group/UOptionGroup.js";
|
|
51
35
|
import { UPagination } from "./components/pagination/UPagination.js";
|
|
52
36
|
import { UPanel } from "./components/panel/UPanel.js";
|
|
37
|
+
import { UPopover } from "./components/popover/UPopover.js";
|
|
53
38
|
import { UProgressBar } from "./components/progress-bar/UProgressBar.js";
|
|
54
39
|
import { UProgressRing } from "./components/progress-ring/UProgressRing.js";
|
|
55
40
|
import { URadio } from "./components/radio/URadio.js";
|
|
56
41
|
import { URating } from "./components/rating/URating.js";
|
|
42
|
+
import { USelect } from "./components/select/USelect.js";
|
|
57
43
|
import { USkeleton } from "./components/skeleton/USkeleton.js";
|
|
58
44
|
import { USlider } from "./components/slider/USlider.js";
|
|
45
|
+
import { USpinner } from "./components/spinner/USpinner.js";
|
|
59
46
|
import { USplitPanel } from "./components/split-panel/USplitPanel.js";
|
|
60
47
|
import { USteps } from "./components/steps/USteps.js";
|
|
61
48
|
import { USwitch } from "./components/switch/USwitch.js";
|
|
62
49
|
import { UTab } from "./components/tab/UTab.js";
|
|
63
50
|
import { UTabPanel } from "./components/tab-panel/UTabPanel.js";
|
|
64
51
|
import { UTabNav } from "./components/tab-nav/UTabNav.js";
|
|
52
|
+
import { UTag } from "./components/tag/UTag.js";
|
|
65
53
|
import { UText } from "./components/text/UText.js";
|
|
66
54
|
import { UTextarea } from "./components/textarea/UTextarea.js";
|
|
67
|
-
import {
|
|
55
|
+
import { UTooltip } from "./components/tooltip/UTooltip.js";
|
|
68
56
|
import { UTree } from "./components/tree/UTree.js";
|
|
57
|
+
import { UTreeItem } from "./components/tree-item/UTreeItem.js";
|
|
69
58
|
import { BrowserStorage } from "./utilities/BrowserStorage.js";
|
|
70
59
|
import { copyFromKey, isTextEntry, pasteFromKey } from "./utilities/clipboard.js";
|
|
60
|
+
import { arrayAttrConverter, booleanAttrConverter, dateAttrConverter, jsonAttrConverter, urlAttrConverter } from "./utilities/converters.js";
|
|
61
|
+
import { localOffset, readDateValue, writeInstant, writePlainDate, writePlainDateTime } from "./utilities/dateValue.js";
|
|
62
|
+
import { createDevWarner, devWarnOnce, resetDevWarnings } from "./utilities/devWarning.js";
|
|
71
63
|
import { Dialog } from "./utilities/Dialog.js";
|
|
64
|
+
import { getParentElement, isCoarsePointer, isFocusCandidate, isFromControl, querySelectorAllWithin, querySelectorDeep, querySelectorWithin } from "./utilities/elements.js";
|
|
65
|
+
import { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeRangeText, formatDateTimeText, formatNumber, parseDate, parseDateRange, parseDateTime, parseDateTimeRange, parseNumber } from "./utilities/format.js";
|
|
66
|
+
import { applyNumberFormat } from "./utilities/numberFormat.js";
|
|
67
|
+
import { IconCache, IconRegistry, getDefaultBaseUrl, setDefaultBaseUrl } from "./utilities/icons.js";
|
|
68
|
+
import { isImeComposing } from "./utilities/keyboard.js";
|
|
69
|
+
import { CompositionTracker, replayInput } from "./utilities/composition.js";
|
|
70
|
+
import { defaultSearchMatch, foldForSearch, hangulKeystrokes, initialsOf, isHangul } from "./utilities/search.js";
|
|
71
|
+
import { Locale } from "./utilities/Locale.js";
|
|
72
|
+
import { OverlayManager } from "./utilities/OverlayManager.js";
|
|
72
73
|
import { Theme } from "./utilities/Theme.js";
|
|
73
74
|
import { Toast } from "./utilities/Toast.js";
|
|
74
75
|
import { decodeDelimited, decodeTsv, encodeTsv } from "./utilities/tsv.js";
|
|
75
|
-
export { ALERT_STATUSES, BrowserStorage, CompositionTracker, Dialog, IconCache, IconRegistry, Locale, OverlayManager, Theme, Toast, UAlert, UAutoScroll, UAvatar, UBadge, UBreadcrumb, UBreadcrumbItem, UButton, UButtonGroup, UCard, UCarousel, UCheckbox, UChip, UCommandPalette, UCopyButton, UDatePicker, UDateRangePicker, UDialog, UDivider, UDrawer, UElement, UExpander, UField, UFileInput, UFloatingElement, UForm, UFormControlElement, UIcon, UIconButton, UInput, UMenu, UMenuItem, UOption, UOptionGroup, UOverlayElement, UPagination, UPanel, UPopover, UProgressBar, UProgressRing, URadio, URating, USelect, USkeleton, USlider, USpinner, USplitPanel, USteps, USwitch, UTab, UTabNav, UTabPanel, UTag, UText, UTextarea, UTooltip, UTree, UTreeItem, arrayAttrConverter, booleanAttrConverter, collectOptions, copyFromKey, createDevWarner, dateAttrConverter, dateTextPattern, decodeDelimited, decodeTsv, defaultSearchMatch, devWarnOnce, encodeTsv, filterCommands, foldForSearch, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeRangeText, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, hangulKeystrokes, initialsOf, isCoarsePointer, isFocusCandidate, isFromControl, isHangul, isImeComposing, isTextEntry, jsonAttrConverter, localOffset, parseDate, parseDateRange, parseDateTime, parseDateTimeRange, parseNumber, pasteFromKey, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, readDateValue, replayInput, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter, writeInstant, writePlainDate, writePlainDateTime };
|
|
76
|
+
export { ALERT_STATUSES, BrowserStorage, CompositionTracker, Dialog, IconCache, IconRegistry, Locale, OverlayManager, Theme, Toast, UAlert, UAutoScroll, UAvatar, UBadge, UBreadcrumb, UBreadcrumbItem, UButton, UButtonGroup, UCard, UCarousel, UCheckbox, UChip, UCommandPalette, UCopyButton, UDatePicker, UDateRangePicker, UDialog, UDivider, UDrawer, UElement, UExpander, UField, UFileInput, UFloatingElement, UForm, UFormControlElement, UIcon, UIconButton, UInput, UMenu, UMenuItem, UOption, UOptionGroup, UOverlayElement, UPagination, UPanel, UPopover, UProgressBar, UProgressRing, URadio, URating, USelect, USkeleton, USlider, USpinner, USplitPanel, USteps, USwitch, UTab, UTabNav, UTabPanel, UTag, UText, UTextarea, UTooltip, UTree, UTreeItem, applyNumberFormat, arrayAttrConverter, booleanAttrConverter, collectOptions, copyFromKey, createDevWarner, dateAttrConverter, dateTextPattern, decodeDelimited, decodeTsv, defaultSearchMatch, devWarnOnce, encodeTsv, filterCommands, foldForSearch, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeRangeText, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, hangulKeystrokes, initialsOf, isCoarsePointer, isFocusCandidate, isFromControl, isHangul, isImeComposing, isTextEntry, jsonAttrConverter, localOffset, parseDate, parseDateRange, parseDateTime, parseDateTimeRange, parseNumber, pasteFromKey, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, readDateValue, replayInput, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter, writeInstant, writePlainDate, writePlainDateTime };
|
package/dist/utilities/Dialog.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Locale } from "./Locale.js";
|
|
2
|
-
import { isImeComposing } from "./keyboard.js";
|
|
3
1
|
import "../components/button/UButton.js";
|
|
4
2
|
import { UDialog } from "../components/dialog/UDialog.js";
|
|
3
|
+
import { Locale } from "./Locale.js";
|
|
4
|
+
import { isImeComposing } from "./keyboard.js";
|
|
5
5
|
import { html, nothing, render } from "lit";
|
|
6
6
|
import { ifDefined } from "lit/directives/if-defined.js";
|
|
7
7
|
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
package/dist/utilities/Theme.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BrowserStorage } from "./BrowserStorage.js";
|
|
2
1
|
import dark_css_default from "../_virtual/_glob-assets_raw/dark.css.e8ac080d.js";
|
|
3
2
|
import light_css_default from "../_virtual/_glob-assets_raw/light.css.637cb2f8.js";
|
|
3
|
+
import { BrowserStorage } from "./BrowserStorage.js";
|
|
4
4
|
import { accentCustomProperties, deriveAccentRamp } from "./accent.js";
|
|
5
5
|
// src/utilities/Theme.ts
|
|
6
6
|
/** 프로퍼티 «이름»만 필요할 때 쓰는 더미 — 값은 쓰지 않는다. */
|
package/dist/utilities/Toast.js
CHANGED
|
@@ -9,6 +9,8 @@ export interface CharsWidthOptions {
|
|
|
9
9
|
text(): HTMLElement | null | undefined;
|
|
10
10
|
/** 측정용 요소를 붙일 자리(글자 영역을 담는 컨테이너). */
|
|
11
11
|
box(): HTMLElement | null | undefined;
|
|
12
|
+
/** 잴 글 — 주면 `0` N개 대신 이 글을 그려 잰다(자리표시처럼 글자가 정해진 칸). `chars()` 가 없으면 재지 않는다. */
|
|
13
|
+
sample?(): string | undefined;
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
16
|
* `chars` 의 폭 — «N자 칸» 을 **그려지는 N자** 로 잰다.
|
package/dist/utilities/chars.js
CHANGED
|
@@ -85,7 +85,7 @@ var CharsWidthController = class {
|
|
|
85
85
|
const sizer = this.sizer;
|
|
86
86
|
const source = getComputedStyle(this.options.text() ?? box);
|
|
87
87
|
for (const prop of FONT_PROPS) sizer.style.setProperty(prop, source.getPropertyValue(prop));
|
|
88
|
-
const digits = "0".repeat(n);
|
|
88
|
+
const digits = this.options.sample?.() || "0".repeat(n);
|
|
89
89
|
if (sizer.textContent !== digits) sizer.textContent = digits;
|
|
90
90
|
if (this.watch && this.watch.textContent !== digits) this.watch.textContent = digits;
|
|
91
91
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LocaleTag } from './Locale.js';
|
|
2
|
+
/** The status tone a section color maps to — colors come from the theme, not from the format. */
|
|
3
|
+
export type FormatTone = 'danger' | 'success' | 'info' | 'warning';
|
|
4
|
+
export interface FormattedNumber {
|
|
5
|
+
text: string;
|
|
6
|
+
tone?: FormatTone;
|
|
7
|
+
}
|
|
8
|
+
/** A number format: a spreadsheet format code (`#,##0.00`, `0.0%`, `[Red]-#,##0`) or `Intl.NumberFormat` options. */
|
|
9
|
+
export type NumberFormat = string | Intl.NumberFormatOptions;
|
|
10
|
+
/**
|
|
11
|
+
* Formats `value` with a {@link NumberFormat} — the one number-format vocabulary the table, sheet and
|
|
12
|
+
* widget packages share. A format code keeps its section color as a theme {@link FormatTone}.
|
|
13
|
+
*
|
|
14
|
+
* - `null` / `undefined` → empty text.
|
|
15
|
+
* - A number or numeric text is formatted; other text goes through a code's text section, or is shown as is.
|
|
16
|
+
* - Neither path writes a signed zero: a negative that rounds to zero reads `0`, as in Excel. For options,
|
|
17
|
+
* that is `signDisplay: 'negative'` unless the options set `signDisplay` themselves.
|
|
18
|
+
* - Returns `null` when a format code uses syntax this engine does not support (conditions `[>100]`,
|
|
19
|
+
* `[Color N]`, scientific `E+`, fractions) — the caller decides how to show the value then.
|
|
20
|
+
*
|
|
21
|
+
* Separators follow `locale`, or the app locale (`Locale.get()`) when omitted.
|
|
22
|
+
*/
|
|
23
|
+
export declare function applyNumberFormat(value: unknown, format: NumberFormat, locale?: LocaleTag): FormattedNumber | null;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { Locale } from "./Locale.js";
|
|
2
|
+
// src/utilities/numberFormat.ts
|
|
3
|
+
/**
|
|
4
|
+
* Number formats shared by the table, sheet and widget packages: spreadsheet format codes (the subset of
|
|
5
|
+
* ECMA-376 §18.8.31 a list needs) and `Intl.NumberFormat` options — see {@link applyNumberFormat}.
|
|
6
|
+
*
|
|
7
|
+
* Format codes:
|
|
8
|
+
*
|
|
9
|
+
* Supported: up to four `;` sections (positive;negative;zero;text) · digit placeholders `0` `#` `?`
|
|
10
|
+
* with `.` and grouping `,` · trailing `,` scaling (÷1000 each) · `%` · quoted literals `"…"` ·
|
|
11
|
+
* escaped literals `\x` · alignment space `_x` · fill `*x` (ignored) · colors `[Red]` `[Green]`
|
|
12
|
+
* `[Blue]` `[Yellow]` `[Black]` · currency `[$₩-412]` · `@` in the text section · any other
|
|
13
|
+
* character as a literal (so `#,##0원` keeps its unit).
|
|
14
|
+
*
|
|
15
|
+
* Not supported (the caller shows the value unformatted): conditions `[>100]`, `[Color N]`,
|
|
16
|
+
* scientific `E+`, fractions `# ?/?`.
|
|
17
|
+
*/
|
|
18
|
+
var COLOR_TONES = {
|
|
19
|
+
red: "danger",
|
|
20
|
+
green: "success",
|
|
21
|
+
blue: "info",
|
|
22
|
+
yellow: "warning",
|
|
23
|
+
black: null
|
|
24
|
+
};
|
|
25
|
+
var cache = /* @__PURE__ */ new Map();
|
|
26
|
+
/** Split on `;` outside quotes, brackets and escapes. */
|
|
27
|
+
function splitSections(code) {
|
|
28
|
+
const out = [];
|
|
29
|
+
let cur = "";
|
|
30
|
+
let quoted = false;
|
|
31
|
+
let bracket = false;
|
|
32
|
+
for (let i = 0; i < code.length; i++) {
|
|
33
|
+
const ch = code[i];
|
|
34
|
+
if (quoted) {
|
|
35
|
+
cur += ch;
|
|
36
|
+
if (ch === "\"") quoted = false;
|
|
37
|
+
} else if (bracket) {
|
|
38
|
+
cur += ch;
|
|
39
|
+
if (ch === "]") bracket = false;
|
|
40
|
+
} else if (ch === "\\" || ch === "_" || ch === "*") {
|
|
41
|
+
cur += ch + (code[i + 1] ?? "");
|
|
42
|
+
i++;
|
|
43
|
+
} else if (ch === "\"") {
|
|
44
|
+
quoted = true;
|
|
45
|
+
cur += ch;
|
|
46
|
+
} else if (ch === "[") {
|
|
47
|
+
bracket = true;
|
|
48
|
+
cur += ch;
|
|
49
|
+
} else if (ch === ";") {
|
|
50
|
+
out.push(cur);
|
|
51
|
+
cur = "";
|
|
52
|
+
} else cur += ch;
|
|
53
|
+
}
|
|
54
|
+
out.push(cur);
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
function parseSection(src) {
|
|
58
|
+
const tokens = [];
|
|
59
|
+
let literal = "";
|
|
60
|
+
let tone;
|
|
61
|
+
let intZeros = 0;
|
|
62
|
+
let minFraction = 0;
|
|
63
|
+
let maxFraction = 0;
|
|
64
|
+
let grouping = false;
|
|
65
|
+
let scale = 0;
|
|
66
|
+
let percent = false;
|
|
67
|
+
let numberSeen = false;
|
|
68
|
+
let inFraction = false;
|
|
69
|
+
let numberClosed = false;
|
|
70
|
+
let pendingCommas = 0;
|
|
71
|
+
const flushLiteral = () => {
|
|
72
|
+
if (literal) tokens.push({
|
|
73
|
+
kind: "literal",
|
|
74
|
+
text: literal
|
|
75
|
+
});
|
|
76
|
+
literal = "";
|
|
77
|
+
};
|
|
78
|
+
const closeNumber = () => {
|
|
79
|
+
if (numberSeen && !numberClosed) {
|
|
80
|
+
scale += pendingCommas;
|
|
81
|
+
pendingCommas = 0;
|
|
82
|
+
numberClosed = true;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
for (let i = 0; i < src.length; i++) {
|
|
86
|
+
const ch = src[i];
|
|
87
|
+
if (ch === "\"") {
|
|
88
|
+
closeNumber();
|
|
89
|
+
const end = src.indexOf("\"", i + 1);
|
|
90
|
+
literal += src.slice(i + 1, end === -1 ? src.length : end);
|
|
91
|
+
i = end === -1 ? src.length : end;
|
|
92
|
+
} else if (ch === "\\") {
|
|
93
|
+
closeNumber();
|
|
94
|
+
literal += src[i + 1] ?? "";
|
|
95
|
+
i++;
|
|
96
|
+
} else if (ch === "_") {
|
|
97
|
+
closeNumber();
|
|
98
|
+
literal += " ";
|
|
99
|
+
i++;
|
|
100
|
+
} else if (ch === "*") i++;
|
|
101
|
+
else if (ch === "[") {
|
|
102
|
+
const end = src.indexOf("]", i);
|
|
103
|
+
if (end === -1) return null;
|
|
104
|
+
const inner = src.slice(i + 1, end);
|
|
105
|
+
i = end;
|
|
106
|
+
if (inner.startsWith("$")) {
|
|
107
|
+
closeNumber();
|
|
108
|
+
const dash = inner.indexOf("-");
|
|
109
|
+
literal += inner.slice(1, dash === -1 ? void 0 : dash);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const key = inner.toLowerCase();
|
|
113
|
+
if (key in COLOR_TONES) {
|
|
114
|
+
tone = COLOR_TONES[key] ?? void 0;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
} else if (ch === "0" || ch === "#" || ch === "?") {
|
|
119
|
+
if (numberClosed) return null;
|
|
120
|
+
if (!numberSeen) {
|
|
121
|
+
flushLiteral();
|
|
122
|
+
tokens.push({ kind: "number" });
|
|
123
|
+
numberSeen = true;
|
|
124
|
+
}
|
|
125
|
+
if (pendingCommas) {
|
|
126
|
+
grouping = true;
|
|
127
|
+
pendingCommas = 0;
|
|
128
|
+
}
|
|
129
|
+
if (inFraction) {
|
|
130
|
+
maxFraction++;
|
|
131
|
+
if (ch === "0") minFraction++;
|
|
132
|
+
} else if (ch === "0") intZeros++;
|
|
133
|
+
} else if (ch === "." && numberSeen && !numberClosed && !inFraction) inFraction = true;
|
|
134
|
+
else if (ch === "." && !numberSeen && /[0#?]/.test(src[i + 1] ?? "")) {
|
|
135
|
+
flushLiteral();
|
|
136
|
+
tokens.push({ kind: "number" });
|
|
137
|
+
numberSeen = true;
|
|
138
|
+
inFraction = true;
|
|
139
|
+
} else if (ch === "," && numberSeen && !numberClosed) pendingCommas++;
|
|
140
|
+
else if (ch === "%") {
|
|
141
|
+
closeNumber();
|
|
142
|
+
percent = true;
|
|
143
|
+
literal += "%";
|
|
144
|
+
} else if ((ch === "E" || ch === "e") && /[+-]/.test(src[i + 1] ?? "")) return null;
|
|
145
|
+
else if (ch === "/" && numberSeen) return null;
|
|
146
|
+
else if (ch === "@") {
|
|
147
|
+
closeNumber();
|
|
148
|
+
flushLiteral();
|
|
149
|
+
tokens.push({ kind: "text" });
|
|
150
|
+
} else {
|
|
151
|
+
closeNumber();
|
|
152
|
+
literal += ch;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
closeNumber();
|
|
156
|
+
flushLiteral();
|
|
157
|
+
return {
|
|
158
|
+
tokens,
|
|
159
|
+
tone,
|
|
160
|
+
intZeros,
|
|
161
|
+
minFraction,
|
|
162
|
+
maxFraction,
|
|
163
|
+
grouping,
|
|
164
|
+
scale,
|
|
165
|
+
percent,
|
|
166
|
+
hasNumber: numberSeen
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function parseFormat(code) {
|
|
170
|
+
if (cache.has(code)) return cache.get(code);
|
|
171
|
+
const parts = splitSections(code);
|
|
172
|
+
let parsed = null;
|
|
173
|
+
if (parts.length <= 4) {
|
|
174
|
+
const sections = [];
|
|
175
|
+
for (const p of parts) {
|
|
176
|
+
const s = parseSection(p);
|
|
177
|
+
if (!s) {
|
|
178
|
+
sections.length = 0;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
sections.push(s);
|
|
182
|
+
}
|
|
183
|
+
if (sections.length === parts.length) parsed = { sections };
|
|
184
|
+
}
|
|
185
|
+
cache.set(code, parsed);
|
|
186
|
+
return parsed;
|
|
187
|
+
}
|
|
188
|
+
function renderDigits(abs, s, locale) {
|
|
189
|
+
let n = abs;
|
|
190
|
+
if (s.percent) n *= 100;
|
|
191
|
+
if (s.scale) n /= 1e3 ** s.scale;
|
|
192
|
+
const text = new Intl.NumberFormat(locale, {
|
|
193
|
+
minimumIntegerDigits: Math.max(1, s.intZeros),
|
|
194
|
+
minimumFractionDigits: s.minFraction,
|
|
195
|
+
maximumFractionDigits: s.maxFraction,
|
|
196
|
+
useGrouping: s.grouping
|
|
197
|
+
}).format(n);
|
|
198
|
+
if (s.intZeros === 0 && /^0(?=\D)/.test(text)) return text.slice(1);
|
|
199
|
+
if (s.intZeros === 0 && text === "0") return "";
|
|
200
|
+
return text;
|
|
201
|
+
}
|
|
202
|
+
function renderSection(s, abs, text, locale) {
|
|
203
|
+
let out = "";
|
|
204
|
+
for (const t of s.tokens) if (t.kind === "literal") out += t.text;
|
|
205
|
+
else if (t.kind === "number") out += renderDigits(abs, s, locale);
|
|
206
|
+
else out += text;
|
|
207
|
+
return out;
|
|
208
|
+
}
|
|
209
|
+
function formatCode(value, code, locale) {
|
|
210
|
+
const parsed = parseFormat(code);
|
|
211
|
+
if (!parsed) return null;
|
|
212
|
+
const { sections } = parsed;
|
|
213
|
+
const num = toNumber(value);
|
|
214
|
+
if (Number.isNaN(num)) {
|
|
215
|
+
const textSection = sections[3];
|
|
216
|
+
if (!textSection) return { text: String(value) };
|
|
217
|
+
return {
|
|
218
|
+
text: renderSection(textSection, 0, String(value), locale),
|
|
219
|
+
tone: textSection.tone
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
let section = sections[0];
|
|
223
|
+
let sign = "";
|
|
224
|
+
if (num < 0 && sections.length >= 2) section = sections[1];
|
|
225
|
+
else if (num === 0 && sections.length >= 3) section = sections[2];
|
|
226
|
+
else if (num < 0) sign = "-";
|
|
227
|
+
const body = renderSection(section, Math.abs(num), String(value), locale);
|
|
228
|
+
return {
|
|
229
|
+
text: (sign && section.hasNumber && !/[1-9]/.test(renderDigits(Math.abs(num), section, locale)) ? "" : sign) + body,
|
|
230
|
+
tone: section.tone
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function toNumber(value) {
|
|
234
|
+
return typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? Number(value) : NaN;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Formats `value` with a {@link NumberFormat} — the one number-format vocabulary the table, sheet and
|
|
238
|
+
* widget packages share. A format code keeps its section color as a theme {@link FormatTone}.
|
|
239
|
+
*
|
|
240
|
+
* - `null` / `undefined` → empty text.
|
|
241
|
+
* - A number or numeric text is formatted; other text goes through a code's text section, or is shown as is.
|
|
242
|
+
* - Neither path writes a signed zero: a negative that rounds to zero reads `0`, as in Excel. For options,
|
|
243
|
+
* that is `signDisplay: 'negative'` unless the options set `signDisplay` themselves.
|
|
244
|
+
* - Returns `null` when a format code uses syntax this engine does not support (conditions `[>100]`,
|
|
245
|
+
* `[Color N]`, scientific `E+`, fractions) — the caller decides how to show the value then.
|
|
246
|
+
*
|
|
247
|
+
* Separators follow `locale`, or the app locale (`Locale.get()`) when omitted.
|
|
248
|
+
*/
|
|
249
|
+
function applyNumberFormat(value, format, locale) {
|
|
250
|
+
if (value == null) return { text: "" };
|
|
251
|
+
const loc = locale ?? Locale.get();
|
|
252
|
+
if (typeof format === "string") return formatCode(value, format, loc);
|
|
253
|
+
const num = toNumber(value);
|
|
254
|
+
if (Number.isNaN(num)) return { text: String(value) };
|
|
255
|
+
return { text: new Intl.NumberFormat(loc, {
|
|
256
|
+
signDisplay: "negative",
|
|
257
|
+
...format
|
|
258
|
+
}).format(num) };
|
|
259
|
+
}
|
|
260
|
+
export { applyNumberFormat };
|
package/package.json
CHANGED
|
@@ -149,6 +149,7 @@ set on the host yourself always wins and is never overwritten.
|
|
|
149
149
|
- [`Locale`](./references/utilities/locale.md) — Validation-message locale registry and lookup utility · search matching (`matchesSearch` — Hangul jamo and initials)
|
|
150
150
|
- [`elements`](./references/utilities/elements.md) — Shadow-DOM-aware DOM query helpers
|
|
151
151
|
- [`format`](./references/utilities/format.md) — Locale-aware number, currency and date formatting
|
|
152
|
+
- [`number-format`](./references/utilities/number-format.md) — One number format for tables, sheets and widgets: spreadsheet codes or `Intl` options
|
|
152
153
|
- [`clipboard`](./references/utilities/clipboard.md) — `copyFromKey` / `pasteFromKey` / `isTextEntry`, Ctrl/Cmd + C · X · V for a grid or list selection in every browser (Safari fires no copy event without a text selection)
|
|
153
154
|
- [`keyboard`](./references/utilities/keyboard.md) — `isImeComposing` for Enter handlers that must not fire mid-composition (Korean/Japanese/Chinese input) · `CompositionTracker` / `replayInput` for inputs that filter as you type
|
|
154
155
|
- [`tsv`](./references/utilities/tsv.md) — `encodeTsv` / `decodeTsv`, the spreadsheet clipboard format with RFC 4180 quoting
|
|
@@ -31,6 +31,10 @@ hold = warning tint, upcoming = empty ring, skipped = dashed ring. Assistive tec
|
|
|
31
31
|
`stepOnHold`, `stepSkipped` locale keys). `skipped` is a step this record's route does not have — an order with no
|
|
32
32
|
proof still shows «Proof», passed over.
|
|
33
33
|
|
|
34
|
+
When the steps do not fit the element's width, `line` folds to one step per row (connectors run down from the
|
|
35
|
+
markers) and goes back to one row when the width returns — nothing past the edge is cut off. In a fixed narrow place
|
|
36
|
+
(a table cell, a card header) `compact` is still the better shape.
|
|
37
|
+
|
|
34
38
|
### Bars — `appearance="bars"`
|
|
35
39
|
|
|
36
40
|
Each step takes an equal column: a bar on top, the step's name and its description (a date) under it. The travelled
|
|
@@ -12,6 +12,8 @@ They add no formatting rules of their own — everything `Intl` accepts is passe
|
|
|
12
12
|
through. Reach for them instead of calling `Intl` directly when you want the active locale
|
|
13
13
|
applied without threading it through every call site.
|
|
14
14
|
|
|
15
|
+
For spreadsheet-style format codes (`#,##0;[Red](#,##0)`), see [`number-format`](./number-format.md).
|
|
16
|
+
|
|
15
17
|
## Functions
|
|
16
18
|
|
|
17
19
|
### `formatNumber(value, options?, locale?)`
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# number-format
|
|
2
|
+
|
|
3
|
+
```ts
|
|
4
|
+
import { applyNumberFormat, type NumberFormat } from '@iyulab/components';
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
Without the barrel's component registrations:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { applyNumberFormat } from '@iyulab/components/dist/utilities/numberFormat.js';
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
One number-format vocabulary for tables, sheets and widgets. A `NumberFormat` is either a
|
|
14
|
+
**spreadsheet format code** (the subset of Excel's number formats a list needs) or
|
|
15
|
+
**`Intl.NumberFormat` options** — the same two shapes a user brings from a spreadsheet or
|
|
16
|
+
from code.
|
|
17
|
+
|
|
18
|
+
## `applyNumberFormat(value, format, locale?)`
|
|
19
|
+
|
|
20
|
+
Returns `{ text, tone? }`, or `null` when a format code uses syntax the engine does not
|
|
21
|
+
support.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
applyNumberFormat(1234.5, '#,##0.00'); // { text: '1,234.50' } in an en locale
|
|
25
|
+
applyNumberFormat(-1234, '#,##0;[Red](#,##0)'); // { text: '(1,234)', tone: 'danger' }
|
|
26
|
+
applyNumberFormat(1234, '#,##0원'); // { text: '1,234원' }
|
|
27
|
+
applyNumberFormat(0.256, { style: 'percent', maximumFractionDigits: 1 }); // { text: '25.6%' }
|
|
28
|
+
applyNumberFormat(0.00007729, { maximumSignificantDigits: 4 }); // { text: '0.00007729' }
|
|
29
|
+
applyNumberFormat(5, '0.00E+00'); // null — scientific is not supported
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- `value`: a number or numeric text is formatted. Other text goes through a code's text
|
|
33
|
+
section (the fourth), or is returned as is. `null` / `undefined` give `''`.
|
|
34
|
+
- `locale`: overrides the active locale (`Locale.get()`) for this call — separators follow it.
|
|
35
|
+
- **No signed zero.** A negative that rounds to zero reads `0` on both paths (as Excel does).
|
|
36
|
+
With options that is `signDisplay: 'negative'`, unless the options set `signDisplay`.
|
|
37
|
+
- `tone`: a section color (`[Red]` `[Green]` `[Blue]` `[Yellow]`) becomes a status tone —
|
|
38
|
+
`'danger' | 'success' | 'info' | 'warning'` — so the caller paints it with theme colors,
|
|
39
|
+
not the literal color. `[Black]` is the default text color (no tone).
|
|
40
|
+
|
|
41
|
+
### Format codes
|
|
42
|
+
|
|
43
|
+
| Supported | Example |
|
|
44
|
+
|---|---|
|
|
45
|
+
| Up to four `;` sections — positive;negative;zero;text | `#,##0;(#,##0);"-"` |
|
|
46
|
+
| Digit placeholders `0` `#` `?`, decimal `.`, grouping `,` | `#,##0.00` · `000` · `#.##` |
|
|
47
|
+
| Trailing `,` divides by 1000 each | `#,##0,,"M"` |
|
|
48
|
+
| `%` multiplies by 100 | `0.0%` |
|
|
49
|
+
| Literals: `"…"`, `\x`, any other character | `#,##0" 원"` · `#,##0원` |
|
|
50
|
+
| `_x` alignment space · `*x` fill (ignored) | `#,##0_)` |
|
|
51
|
+
| Section colors | `[Red]-#,##0` |
|
|
52
|
+
| Currency `[$sym-locale]` (the symbol is used) | `[$₩-412]#,##0` |
|
|
53
|
+
| `@` in the text section | `0;-0;0;"["@"]"` |
|
|
54
|
+
|
|
55
|
+
Not supported (returns `null`): conditions `[>100]`, `[Color N]`, scientific `E+`, fractions `# ?/?`.
|