@eldrajs/ui 0.0.0-stage → 0.1.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 +1724 -0
- package/LICENSE +21 -0
- package/README.md +3177 -2
- package/dist/VariantPicker-CKw8hmxt.js +9009 -0
- package/dist/componentNames.d.ts +19 -0
- package/dist/components/accordion/Accordion.vue.d.ts +18 -0
- package/dist/components/accordion/AccordionItem.vue.d.ts +26 -0
- package/dist/components/accordion/context.d.ts +20 -0
- package/dist/components/accordion/detailsExclusivity.d.ts +3 -0
- package/dist/components/accordion/heightTransition.d.ts +59 -0
- package/dist/components/accordion/types.d.ts +40 -0
- package/dist/components/avatar/Avatar.vue.d.ts +10 -0
- package/dist/components/avatar/AvatarGroup.vue.d.ts +7 -0
- package/dist/components/avatar/types.d.ts +61 -0
- package/dist/components/badge/Badge.vue.d.ts +24 -0
- package/dist/components/badge/StockBadge.vue.d.ts +10 -0
- package/dist/components/badge/types.d.ts +79 -0
- package/dist/components/breadcrumb/Breadcrumb.vue.d.ts +10 -0
- package/dist/components/breadcrumb/types.d.ts +53 -0
- package/dist/components/button/Button.vue.d.ts +37 -0
- package/dist/components/button/ButtonGroup.vue.d.ts +17 -0
- package/dist/components/button/types.d.ts +68 -0
- package/dist/components/card/ContentCard.vue.d.ts +36 -0
- package/dist/components/card/FeatureCard.vue.d.ts +27 -0
- package/dist/components/card/cueArrow.d.ts +10 -0
- package/dist/components/card/stretchedLink.d.ts +45 -0
- package/dist/components/card/types.d.ts +92 -0
- package/dist/components/carousel/Carousel.vue.d.ts +39 -0
- package/dist/components/carousel/types.d.ts +75 -0
- package/dist/components/carousel/useCarousel.d.ts +152 -0
- package/dist/components/checkbox/Checkbox.vue.d.ts +36 -0
- package/dist/components/checkbox/CheckboxGroup.vue.d.ts +16 -0
- package/dist/components/checkbox/types.d.ts +78 -0
- package/dist/components/chip/Chip.vue.d.ts +37 -0
- package/dist/components/chip/ChipGroup.vue.d.ts +21 -0
- package/dist/components/chip/context.d.ts +22 -0
- package/dist/components/chip/types.d.ts +84 -0
- package/dist/components/container/Container.vue.d.ts +18 -0
- package/dist/components/container/types.d.ts +17 -0
- package/dist/components/currency-input/CurrencyInput.vue.d.ts +17 -0
- package/dist/components/currency-input/types.d.ts +8 -0
- package/dist/components/dialog/Dialog.vue.d.ts +34 -0
- package/dist/components/dialog/types.d.ts +25 -0
- package/dist/components/drawer/Drawer.vue.d.ts +36 -0
- package/dist/components/drawer/types.d.ts +30 -0
- package/dist/components/empty-state/EditorPlaceholder.vue.d.ts +9 -0
- package/dist/components/empty-state/EmptyState.vue.d.ts +28 -0
- package/dist/components/empty-state/types.d.ts +59 -0
- package/dist/components/field-wrapper/FieldError.vue.d.ts +37 -0
- package/dist/components/field-wrapper/FieldWrapper.vue.d.ts +30 -0
- package/dist/components/field-wrapper/context.d.ts +44 -0
- package/dist/components/field-wrapper/types.d.ts +38 -0
- package/dist/components/filter-panel/FilterGroup.vue.d.ts +48 -0
- package/dist/components/filter-panel/FilterPanel.vue.d.ts +77 -0
- package/dist/components/filter-panel/Histogram.vue.d.ts +15 -0
- package/dist/components/filter-panel/facets/ColourFacet.vue.d.ts +12 -0
- package/dist/components/filter-panel/facets/ListFacet.vue.d.ts +12 -0
- package/dist/components/filter-panel/facets/RangeFacet.vue.d.ts +20 -0
- package/dist/components/filter-panel/facets/SizeFacet.vue.d.ts +12 -0
- package/dist/components/filter-panel/facets/ToggleFacet.vue.d.ts +12 -0
- package/dist/components/filter-panel/facets/shared.d.ts +39 -0
- package/dist/components/filter-panel/northwind.d.ts +32 -0
- package/dist/components/filter-panel/swatchInk.d.ts +50 -0
- package/dist/components/filter-panel/types.d.ts +183 -0
- package/dist/components/filter-panel/useFilterPanel.d.ts +230 -0
- package/dist/components/form-layout/FormLayout.vue.d.ts +36 -0
- package/dist/components/form-layout/context.d.ts +33 -0
- package/dist/components/form-layout/focusInvalid.d.ts +18 -0
- package/dist/components/form-layout/types.d.ts +52 -0
- package/dist/components/icon/Icon.vue.d.ts +8 -0
- package/dist/components/icon/types.d.ts +29 -0
- package/dist/components/image/Image.vue.d.ts +21 -0
- package/dist/components/image/types.d.ts +81 -0
- package/dist/components/input/Input.vue.d.ts +47 -0
- package/dist/components/input/classes.d.ts +110 -0
- package/dist/components/input/types.d.ts +55 -0
- package/dist/components/internal/ValueText.vue.d.ts +7 -0
- package/dist/components/lightbox/Lightbox.vue.d.ts +19 -0
- package/dist/components/lightbox/types.d.ts +47 -0
- package/dist/components/link/Link.vue.d.ts +23 -0
- package/dist/components/link/types.d.ts +40 -0
- package/dist/components/load-more/LoadMore.vue.d.ts +12 -0
- package/dist/components/load-more/types.d.ts +21 -0
- package/dist/components/logo-item/LogoItem.vue.d.ts +10 -0
- package/dist/components/logo-item/types.d.ts +37 -0
- package/dist/components/pagination/Pagination.vue.d.ts +15 -0
- package/dist/components/pagination/types.d.ts +51 -0
- package/dist/components/popover/Popover.vue.d.ts +31 -0
- package/dist/components/popover/types.d.ts +53 -0
- package/dist/components/price/Price.vue.d.ts +25 -0
- package/dist/components/price/types.d.ts +104 -0
- package/dist/components/product-card/ProductCard.vue.d.ts +22 -0
- package/dist/components/product-card/types.d.ts +123 -0
- package/dist/components/quantity-stepper/QuantityStepper.vue.d.ts +26 -0
- package/dist/components/quantity-stepper/types.d.ts +35 -0
- package/dist/components/radio/RadioGroup.vue.d.ts +38 -0
- package/dist/components/radio/types.d.ts +39 -0
- package/dist/components/range-slider/RangeSlider.vue.d.ts +70 -0
- package/dist/components/range-slider/types.d.ts +151 -0
- package/dist/components/range-slider/useRangeSlider.d.ts +106 -0
- package/dist/components/rating/Rating.vue.d.ts +22 -0
- package/dist/components/rating/RatingStars.vue.d.ts +16 -0
- package/dist/components/rating/types.d.ts +45 -0
- package/dist/components/search-bar/SearchBar.vue.d.ts +47 -0
- package/dist/components/search-bar/SearchResultsPanel.vue.d.ts +93 -0
- package/dist/components/search-bar/shortcutOwner.d.ts +39 -0
- package/dist/components/search-bar/types.d.ts +122 -0
- package/dist/components/search-modal/SearchModal.vue.d.ts +53 -0
- package/dist/components/search-modal/types.d.ts +59 -0
- package/dist/components/section/Section.vue.d.ts +21 -0
- package/dist/components/section/context.d.ts +23 -0
- package/dist/components/section/types.d.ts +34 -0
- package/dist/components/select/MultiSelect.vue.d.ts +62 -0
- package/dist/components/select/Select.vue.d.ts +57 -0
- package/dist/components/select/SelectPanel.vue.d.ts +97 -0
- package/dist/components/select/openRegistry.d.ts +11 -0
- package/dist/components/select/panelParts.d.ts +91 -0
- package/dist/components/select/types.d.ts +129 -0
- package/dist/components/select/useListbox.d.ts +106 -0
- package/dist/components/select/useOptionList.d.ts +61 -0
- package/dist/components/select/usePopover.d.ts +147 -0
- package/dist/components/skeleton/Skeleton.vue.d.ts +12 -0
- package/dist/components/skeleton/types.d.ts +38 -0
- package/dist/components/spinner/Spinner.vue.d.ts +3 -0
- package/dist/components/switch/Switch.vue.d.ts +30 -0
- package/dist/components/switch/types.d.ts +20 -0
- package/dist/components/tabs/Tab.vue.d.ts +17 -0
- package/dist/components/tabs/TabPanel.vue.d.ts +16 -0
- package/dist/components/tabs/Tabs.vue.d.ts +28 -0
- package/dist/components/tabs/context.d.ts +48 -0
- package/dist/components/tabs/types.d.ts +63 -0
- package/dist/components/textarea/Textarea.vue.d.ts +27 -0
- package/dist/components/textarea/supportsFieldSizing.d.ts +10 -0
- package/dist/components/textarea/types.d.ts +32 -0
- package/dist/components/toast/Toast.vue.d.ts +16 -0
- package/dist/components/toast/Toaster.vue.d.ts +13 -0
- package/dist/components/toast/types.d.ts +44 -0
- package/dist/components/tooltip/Tooltip.vue.d.ts +9 -0
- package/dist/components/tooltip/supportsFocusVisible.d.ts +17 -0
- package/dist/components/tooltip/types.d.ts +46 -0
- package/dist/components/unit-input/UnitInput.vue.d.ts +55 -0
- package/dist/components/unit-input/types.d.ts +68 -0
- package/dist/components/unit-input/undo-redo.d.ts +6 -0
- package/dist/components/variant-picker/VariantPicker.vue.d.ts +15 -0
- package/dist/components/variant-picker/types.d.ts +49 -0
- package/dist/components/visually-hidden/VisuallyHidden.vue.d.ts +18 -0
- package/dist/components/visually-hidden/types.d.ts +14 -0
- package/dist/composables/dialogStack.d.ts +52 -0
- package/dist/composables/teleportTarget.d.ts +79 -0
- package/dist/composables/useControllableModel.d.ts +16 -0
- package/dist/composables/useDialog.d.ts +84 -0
- package/dist/composables/useFloating.d.ts +82 -0
- package/dist/composables/useHeadingTag.d.ts +24 -0
- package/dist/composables/useLocale.d.ts +81 -0
- package/dist/composables/useMessages.d.ts +30 -0
- package/dist/composables/useOverlay.d.ts +88 -0
- package/dist/composables/useSlotPresence.d.ts +29 -0
- package/dist/composables/useToast.d.ts +53 -0
- package/dist/icons/paths.d.ts +10 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.js +12586 -0
- package/dist/listFormat-1UrH38f2.js +39 -0
- package/dist/messages/en-US.d.ts +485 -0
- package/dist/messages/index.d.ts +2 -0
- package/dist/messages/is-IS.d.ts +16 -0
- package/dist/messages/is-IS.js +169 -0
- package/dist/resolver.d.ts +43 -0
- package/dist/resolver.js +121 -0
- package/dist/style.css +5251 -0
- package/dist/tailwind.css +2057 -0
- package/dist/tokens.css +134 -0
- package/dist/utils/avatar.d.ts +15 -0
- package/dist/utils/color.d.ts +11 -0
- package/dist/utils/cssTiming.d.ts +40 -0
- package/dist/utils/cx.d.ts +31 -0
- package/dist/utils/date.d.ts +45 -0
- package/dist/utils/id.d.ts +36 -0
- package/dist/utils/listFormat.d.ts +22 -0
- package/dist/utils/mask.d.ts +48 -0
- package/dist/utils/number-format.d.ts +250 -0
- package/dist/utils/numeric-input.d.ts +42 -0
- package/dist/utils/rating.d.ts +26 -0
- package/dist/utils/ratio.d.ts +18 -0
- package/dist/utils/tagRecipe.d.ts +24 -0
- package/dist/utils/valueFade.d.ts +42 -0
- package/dist/vee-validate/FieldCheckbox.vue.d.ts +14 -0
- package/dist/vee-validate/FieldCheckboxGroup.vue.d.ts +14 -0
- package/dist/vee-validate/FieldCurrencyInput.vue.d.ts +14 -0
- package/dist/vee-validate/FieldInput.vue.d.ts +14 -0
- package/dist/vee-validate/FieldMultiSelect.vue.d.ts +14 -0
- package/dist/vee-validate/FieldQuantityStepper.vue.d.ts +14 -0
- package/dist/vee-validate/FieldRadioGroup.vue.d.ts +14 -0
- package/dist/vee-validate/FieldSearchBar.vue.d.ts +14 -0
- package/dist/vee-validate/FieldSelect.vue.d.ts +14 -0
- package/dist/vee-validate/FieldSwitch.vue.d.ts +14 -0
- package/dist/vee-validate/FieldTextarea.vue.d.ts +14 -0
- package/dist/vee-validate/FieldUnitInput.vue.d.ts +14 -0
- package/dist/vee-validate/FieldVariantPicker.vue.d.ts +14 -0
- package/dist/vee-validate/Form.vue.d.ts +27 -0
- package/dist/vee-validate/context.d.ts +48 -0
- package/dist/vee-validate/index.d.ts +27 -0
- package/dist/vee-validate/types.d.ts +115 -0
- package/dist/vee-validate/useFieldControl.d.ts +67 -0
- package/dist/vee-validate.js +1154 -0
- package/package.json +105 -3
package/dist/tokens.css
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/* Generated by scripts/build-tokens.mjs from eldra-starter-spec/tokens.json — do not edit. */
|
|
2
|
+
:root {
|
|
3
|
+
--eldra-color-background: #fcfbf8;
|
|
4
|
+
--eldra-color-surface: #f4f1eb;
|
|
5
|
+
--eldra-color-surface-strong: #e9e4da;
|
|
6
|
+
--eldra-color-border: #ddd6ca;
|
|
7
|
+
--eldra-color-border-strong: #7d7466;
|
|
8
|
+
--eldra-color-text: #1c1917;
|
|
9
|
+
--eldra-color-muted: #595249;
|
|
10
|
+
--eldra-color-primary: #24201c;
|
|
11
|
+
--eldra-color-primary-contrast: #fcfbf8;
|
|
12
|
+
--eldra-color-accent: #9c3f24;
|
|
13
|
+
--eldra-color-accent-contrast: #ffffff;
|
|
14
|
+
--eldra-color-success: #0e6b62;
|
|
15
|
+
--eldra-color-warning: #8a5300;
|
|
16
|
+
--eldra-color-danger: #b0261c;
|
|
17
|
+
--eldra-color-focus: #1c1917;
|
|
18
|
+
--eldra-color-focus-inner: #ffffff;
|
|
19
|
+
--eldra-color-overlay: rgba(28, 25, 23, 0.7);
|
|
20
|
+
--eldra-font-heading: "Bricolage Grotesque", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
21
|
+
--eldra-font-body: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
22
|
+
--eldra-font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
23
|
+
--eldra-text-display-family: var(--eldra-font-heading);
|
|
24
|
+
--eldra-text-display-size: 3.5rem;
|
|
25
|
+
--eldra-text-display-line: 1.05;
|
|
26
|
+
--eldra-text-display-weight: 700;
|
|
27
|
+
--eldra-text-display-tracking: -0.02em;
|
|
28
|
+
--eldra-text-h1-family: var(--eldra-font-heading);
|
|
29
|
+
--eldra-text-h1-size: 2.75rem;
|
|
30
|
+
--eldra-text-h1-line: 1.1;
|
|
31
|
+
--eldra-text-h1-weight: 700;
|
|
32
|
+
--eldra-text-h1-tracking: -0.02em;
|
|
33
|
+
--eldra-text-h2-family: var(--eldra-font-heading);
|
|
34
|
+
--eldra-text-h2-size: 2rem;
|
|
35
|
+
--eldra-text-h2-line: 1.15;
|
|
36
|
+
--eldra-text-h2-weight: 700;
|
|
37
|
+
--eldra-text-h2-tracking: -0.015em;
|
|
38
|
+
--eldra-text-h3-family: var(--eldra-font-heading);
|
|
39
|
+
--eldra-text-h3-size: 1.5rem;
|
|
40
|
+
--eldra-text-h3-line: 1.25;
|
|
41
|
+
--eldra-text-h3-weight: 600;
|
|
42
|
+
--eldra-text-h3-tracking: -0.01em;
|
|
43
|
+
--eldra-text-h4-family: var(--eldra-font-heading);
|
|
44
|
+
--eldra-text-h4-size: 1.125rem;
|
|
45
|
+
--eldra-text-h4-line: 1.35;
|
|
46
|
+
--eldra-text-h4-weight: 600;
|
|
47
|
+
--eldra-text-h4-tracking: 0;
|
|
48
|
+
--eldra-text-body-lg-family: var(--eldra-font-body);
|
|
49
|
+
--eldra-text-body-lg-size: 1.125rem;
|
|
50
|
+
--eldra-text-body-lg-line: 1.6;
|
|
51
|
+
--eldra-text-body-lg-weight: 400;
|
|
52
|
+
--eldra-text-body-lg-tracking: 0;
|
|
53
|
+
--eldra-text-body-family: var(--eldra-font-body);
|
|
54
|
+
--eldra-text-body-size: 1rem;
|
|
55
|
+
--eldra-text-body-line: 1.6;
|
|
56
|
+
--eldra-text-body-weight: 400;
|
|
57
|
+
--eldra-text-body-tracking: 0;
|
|
58
|
+
--eldra-text-body-sm-family: var(--eldra-font-body);
|
|
59
|
+
--eldra-text-body-sm-size: 0.875rem;
|
|
60
|
+
--eldra-text-body-sm-line: 1.5;
|
|
61
|
+
--eldra-text-body-sm-weight: 400;
|
|
62
|
+
--eldra-text-body-sm-tracking: 0;
|
|
63
|
+
--eldra-text-caption-family: var(--eldra-font-body);
|
|
64
|
+
--eldra-text-caption-size: 0.8125rem;
|
|
65
|
+
--eldra-text-caption-line: 1.4;
|
|
66
|
+
--eldra-text-caption-weight: 400;
|
|
67
|
+
--eldra-text-caption-tracking: 0.01em;
|
|
68
|
+
--eldra-text-overline-family: var(--eldra-font-body);
|
|
69
|
+
--eldra-text-overline-size: 0.75rem;
|
|
70
|
+
--eldra-text-overline-line: 1.3;
|
|
71
|
+
--eldra-text-overline-weight: 600;
|
|
72
|
+
--eldra-text-overline-tracking: 0.12em;
|
|
73
|
+
--eldra-text-label-family: var(--eldra-font-body);
|
|
74
|
+
--eldra-text-label-size: 0.875rem;
|
|
75
|
+
--eldra-text-label-line: 1.4;
|
|
76
|
+
--eldra-text-label-weight: 600;
|
|
77
|
+
--eldra-text-label-tracking: 0;
|
|
78
|
+
--eldra-text-code-family: var(--eldra-font-mono);
|
|
79
|
+
--eldra-text-code-size: 0.875rem;
|
|
80
|
+
--eldra-text-code-line: 1.6;
|
|
81
|
+
--eldra-text-code-weight: 400;
|
|
82
|
+
--eldra-text-code-tracking: 0;
|
|
83
|
+
--eldra-space-1: 0.25rem;
|
|
84
|
+
--eldra-space-2: 0.5rem;
|
|
85
|
+
--eldra-space-3: 0.75rem;
|
|
86
|
+
--eldra-space-4: 1rem;
|
|
87
|
+
--eldra-space-5: 1.25rem;
|
|
88
|
+
--eldra-space-6: 1.5rem;
|
|
89
|
+
--eldra-space-8: 2rem;
|
|
90
|
+
--eldra-space-12: 3rem;
|
|
91
|
+
--eldra-space-16: 4rem;
|
|
92
|
+
--eldra-radius-sm: 0.375rem;
|
|
93
|
+
--eldra-radius-md: 0.5rem;
|
|
94
|
+
--eldra-radius-lg: 0.75rem;
|
|
95
|
+
--eldra-radius-xl: 1rem;
|
|
96
|
+
--eldra-radius-full: 9999px;
|
|
97
|
+
--eldra-shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.06), 0 1px 3px rgba(28, 25, 23, 0.08);
|
|
98
|
+
--eldra-shadow-md: 0 12px 32px -8px rgba(28, 25, 23, 0.18), 0 2px 6px rgba(28, 25, 23, 0.06);
|
|
99
|
+
--eldra-shadow-float: 0 8px 24px -6px rgba(28, 25, 23, 0.10), 0 1px 2px rgba(28, 25, 23, 0.04);
|
|
100
|
+
--eldra-container-narrow: 40rem;
|
|
101
|
+
--eldra-container-content: 64rem;
|
|
102
|
+
--eldra-container-wide: 80rem;
|
|
103
|
+
--eldra-container-full: 100%;
|
|
104
|
+
--eldra-gutter-mobile: 1rem;
|
|
105
|
+
--eldra-gutter-tablet: 1.5rem;
|
|
106
|
+
--eldra-gutter-desktop: 2rem;
|
|
107
|
+
--eldra-section-sm: clamp(2rem, 1.5rem + 2vw, 3rem);
|
|
108
|
+
--eldra-section-md: clamp(3rem, 2rem + 4vw, 6rem);
|
|
109
|
+
--eldra-section-lg: clamp(4rem, 2.5rem + 6vw, 8rem);
|
|
110
|
+
--eldra-target-min: 1.5rem;
|
|
111
|
+
--eldra-target-touch: 2.75rem;
|
|
112
|
+
--eldra-control-height: 2.5rem;
|
|
113
|
+
--eldra-control-height-sm: 2rem;
|
|
114
|
+
--eldra-control-height-lg: 3rem;
|
|
115
|
+
--eldra-focus-width: 2px;
|
|
116
|
+
--eldra-focus-offset: 2px;
|
|
117
|
+
--eldra-revalidating-opacity: 0.75;
|
|
118
|
+
--eldra-duration-fast: 150ms;
|
|
119
|
+
--eldra-duration-base: 200ms;
|
|
120
|
+
--eldra-duration-slow: 250ms;
|
|
121
|
+
--eldra-ease-out: cubic-bezier(0.2, 0, 0, 1);
|
|
122
|
+
--eldra-ease-in: cubic-bezier(0.4, 0, 1, 1);
|
|
123
|
+
--eldra-z-sticky: 20;
|
|
124
|
+
--eldra-z-drawer: 40;
|
|
125
|
+
--eldra-z-dialog: 50;
|
|
126
|
+
--eldra-z-toast: 60;
|
|
127
|
+
}
|
|
128
|
+
@media (prefers-reduced-motion: reduce) {
|
|
129
|
+
:root {
|
|
130
|
+
--eldra-duration-fast: 0ms;
|
|
131
|
+
--eldra-duration-base: 0ms;
|
|
132
|
+
--eldra-duration-slow: 0ms;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Avatar`'s own initials logic (spec "Avatar" → Properties, `name` row: "first letter of given
|
|
3
|
+
* and family name, uppercase"; Do/Don't: "keep initials to two letters"), pulled out of the
|
|
4
|
+
* component the same way `roundRatingToHalf` is pulled out of `Rating` — a unit test can hit the
|
|
5
|
+
* boundary case with nothing else in the render path to obscure a broken mutant.
|
|
6
|
+
*
|
|
7
|
+
* A name with two or more words takes the first letter of the first word and the first letter of
|
|
8
|
+
* the last one — the spec's own two examples, "Maya Okafor" → "MO" and "Jonas Lindqvist" → "JL",
|
|
9
|
+
* both come out of this rule directly. A single-word name (a mononym, a store handle) takes that
|
|
10
|
+
* word's own first two letters, uppercase, so the avatar is never left with a lone letter when a
|
|
11
|
+
* second one is sitting right there to show. An empty or all-whitespace name has no letters to
|
|
12
|
+
* take, and returns `''` — `Avatar.vue` treats that the same as no name at all, falling on to the
|
|
13
|
+
* icon.
|
|
14
|
+
*/
|
|
15
|
+
export declare function initialsFromName(name: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A CSS `color-mix()` of `color` shifted `percent` toward `toward`, in the
|
|
3
|
+
* perceptual oklab space.
|
|
4
|
+
*
|
|
5
|
+
* States that the design spec describes as "darker"/"lighter" than a token
|
|
6
|
+
* (hover and active fills, subtle separators) are expressed this way rather
|
|
7
|
+
* than as new colour tokens: a store restyles by setting one variable and
|
|
8
|
+
* every derived state follows. Components use the result inside an arbitrary
|
|
9
|
+
* Tailwind value, e.g. `bg-[color-mix(...)]`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function mixToward(color: string, toward: string, percent: number): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading the package's motion tokens off a real element, for the two places that animate in
|
|
3
|
+
* JavaScript rather than in CSS (`AccordionItem`'s panel height, a refreshed value's fade-in).
|
|
4
|
+
*
|
|
5
|
+
* Both need the same three things — "may I animate at all", "how long", "with what easing" — and
|
|
6
|
+
* both must read them from the element's own computed style rather than from a literal, so a
|
|
7
|
+
* consumer who overrides `--eldra-duration-base` or `--eldra-ease-out` changes the JavaScript
|
|
8
|
+
* animation exactly as it changes every CSS one. These lived in
|
|
9
|
+
* `src/components/accordion/heightTransition.ts` first; they moved here when the second caller
|
|
10
|
+
* arrived rather than being copied into it.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* `true` under `prefers-reduced-motion: reduce`. The one JavaScript check `motion-reduce:` CSS
|
|
14
|
+
* cannot make on its own: whether an animation may *start*, as opposed to how it looks once it
|
|
15
|
+
* has. `useCarousel` reads it to keep autoplay from ever starting, `Carousel.vue` to scroll
|
|
16
|
+
* instantly instead of smoothly, `Lightbox` for its own `←`/`→` stepping, and the two JavaScript
|
|
17
|
+
* animations above to skip themselves entirely. It is re-exported from
|
|
18
|
+
* `src/components/carousel/useCarousel.ts`, which is where the package's public entry has always
|
|
19
|
+
* taken it from.
|
|
20
|
+
*
|
|
21
|
+
* `window.matchMedia` is guarded rather than assumed: a node-environment caller (there are none
|
|
22
|
+
* today, but nothing here should throw if one shows up) gets `false` — the same "motion is fine"
|
|
23
|
+
* default an engine with no media query support would produce.
|
|
24
|
+
*/
|
|
25
|
+
export declare function prefersReducedMotion(): boolean;
|
|
26
|
+
/** One custom property's computed value on `el`, or `''` where there is no style engine at all
|
|
27
|
+
* (a unit test with no CSS pipeline, most likely — a real consumer of this package always ships
|
|
28
|
+
* `tokens.css`). */
|
|
29
|
+
export declare function readCssVar(el: Element, name: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Parses a CSS `<time>` (`200ms` / `0.2s`) into milliseconds, or `null` when it isn't a positive
|
|
32
|
+
* one — the custom property is unset, empty, zeroed (reduced motion already zeroes every
|
|
33
|
+
* `--eldra-duration-*` in `tokens.css`, which this treats the same as "cannot animate" rather than
|
|
34
|
+
* animating a 0ms step), or not a time at all.
|
|
35
|
+
*
|
|
36
|
+
* That `null` is the second half of the reduced-motion answer, and the half that keeps working
|
|
37
|
+
* when a consumer ships their own token file: `prefersReducedMotion()` above asks the visitor's
|
|
38
|
+
* setting, this asks the stylesheet that setting is supposed to have changed.
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseCssDurationMs(raw: string): number | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anything `cx` accepts: a class string, a falsy placeholder for a branch that
|
|
3
|
+
* did not apply, or an object whose truthy keys are class names.
|
|
4
|
+
*
|
|
5
|
+
* An **array is deliberately not in this union**, and neither is it in a
|
|
6
|
+
* `classes` prop's own `Partial<Record<Part, string>>` type: this package's
|
|
7
|
+
* `classes` contract is one string per part, so a TypeScript consumer writing
|
|
8
|
+
* `classes: { root: ['a', 'b'] }` gets a type error where it belongs — at the
|
|
9
|
+
* call. `cx` still *flattens* one at runtime (see `flattenClassValue` below),
|
|
10
|
+
* and `partClass` warns about it in dev, because the type cannot help a
|
|
11
|
+
* JavaScript consumer, a `v-bind` of an untyped object, or a value that arrived
|
|
12
|
+
* from JSON.
|
|
13
|
+
*/
|
|
14
|
+
export type ClassValue = string | false | null | undefined | Record<string, boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Join class values, then resolve Tailwind conflicts so the last one wins.
|
|
17
|
+
*
|
|
18
|
+
* Every component builds its classes with this, which is what makes the
|
|
19
|
+
* `classes` prop work without `!important`: a consumer's `px-6` replaces the
|
|
20
|
+
* component's `px-4` instead of landing beside it and losing to source order.
|
|
21
|
+
*/
|
|
22
|
+
export declare function cx(...inputs: ClassValue[]): string;
|
|
23
|
+
/**
|
|
24
|
+
* The classes for one named part of a component: the part's own classes with
|
|
25
|
+
* the consumer's override for that part merged over them.
|
|
26
|
+
*
|
|
27
|
+
* `Part` is the union of the part names in the component's spec anatomy, so a
|
|
28
|
+
* typo in a `classes` key is a type error rather than a silently ignored
|
|
29
|
+
* override.
|
|
30
|
+
*/
|
|
31
|
+
export declare function partClass<P extends string>(base: string, classes: Partial<Record<P, string>> | undefined, part: P): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format an ISO date as `<time datetime>` text (spec "Content card" → Properties, `date` row:
|
|
3
|
+
* `'Rendered as "12 Sep 2026" in a <time datetime>'`), in whatever style `Intl.DateTimeFormat`
|
|
4
|
+
* gives the locale — `en-US` reads "Sep 12, 2026", `is-IS` reads "12. sep. 2026"; the spec's own
|
|
5
|
+
* "12 Sep 2026" is one locale's rendering, not a format this function reproduces literally.
|
|
6
|
+
*
|
|
7
|
+
* `iso` is parsed by its calendar components (`YYYY-MM-DD`, an optional `T…` time/offset
|
|
8
|
+
* discarded) and built and formatted in UTC, so the calendar date never shifts with the visitor's
|
|
9
|
+
* time zone and the server and the browser print the same text (`@eldrajs/sdk/format/date`).
|
|
10
|
+
*
|
|
11
|
+
* Never throws. `iso` is content — often round-tripped through a CMS field a caller does not fully
|
|
12
|
+
* control — so a malformed, empty or out-of-range value (`''`, `'not-a-date'`, `'2026-02-30'`,
|
|
13
|
+
* which `Date` would otherwise silently roll over to 2 March) returns `null` instead of an Invalid
|
|
14
|
+
* Date or a thrown `RangeError` from `Intl.DateTimeFormat`. `ContentCard` renders no `<time>`
|
|
15
|
+
* element at all when this returns `null` — never a fabricated date like "Jan 1, 1900" (the result
|
|
16
|
+
* of `Number('')` defaulting every component to `0`/`NaN` and formatting anyway). Warns once per
|
|
17
|
+
* distinct bad value in dev, the same "never throw from a computed" rule `Price.vue` documents for
|
|
18
|
+
* an invalid currency code.
|
|
19
|
+
*
|
|
20
|
+
* `options` (added 2026-09-27) widens the *style* without widening the contract: a caller that
|
|
21
|
+
* needs a spelled-out month ("12 September 2026" beside a `Section`'s wide layout, the short form
|
|
22
|
+
* in a narrow one — the starter's `article` block renders both and picks one with a container
|
|
23
|
+
* query) passes `{ month: 'long' }` rather than reaching for `Intl.DateTimeFormat` itself and
|
|
24
|
+
* losing every guarantee above. Only the four date parts are exposed, deliberately: this is a
|
|
25
|
+
* *date* formatter, the `<time datetime>` attribute it pairs with carries a date-only value, and
|
|
26
|
+
* there is no time in the parsed input to format.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* The `Intl.DateTimeFormatOptions` subset `formatDate` accepts. Each key defaults to what the
|
|
30
|
+
* spec's own "12 Sep 2026" needs (`day: 'numeric'`, `month: 'short'`, `year: 'numeric'`), and
|
|
31
|
+
* `weekday` is off unless asked for — omitting a key keeps its default rather than dropping that
|
|
32
|
+
* part from the output, so `{ month: 'long' }` is a one-key change to the long form and nothing
|
|
33
|
+
* else moves.
|
|
34
|
+
*/
|
|
35
|
+
export interface FormatDateOptions {
|
|
36
|
+
/** `'numeric'` (default) → "12"; `'2-digit'` → "05" for May's 5th. */
|
|
37
|
+
day?: 'numeric' | '2-digit';
|
|
38
|
+
/** `'short'` (default) → "Sep"; `'long'` → "September"; `'numeric'`/`'2-digit'`/`'narrow'` too. */
|
|
39
|
+
month?: 'numeric' | '2-digit' | 'short' | 'long' | 'narrow';
|
|
40
|
+
/** `'numeric'` (default) → "2026"; `'2-digit'` → "26". */
|
|
41
|
+
year?: 'numeric' | '2-digit';
|
|
42
|
+
/** Off by default. `'long'` → "Saturday", `'short'` → "Sat", `'narrow'` → "S". */
|
|
43
|
+
weekday?: 'long' | 'short' | 'narrow';
|
|
44
|
+
}
|
|
45
|
+
export declare function formatDate(iso: string, locale?: string, options?: FormatDateOptions): string | null;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ComputedRef, MaybeRefOrGetter } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* A stable, SSR-safe id for a component part, or the caller's own id when it
|
|
4
|
+
* gave one.
|
|
5
|
+
*
|
|
6
|
+
* Built on Vue's `useId()` (Vue 3.5+), so the server and the client produce the
|
|
7
|
+
* same value and `aria-describedby`/`for` wiring does not break on hydration.
|
|
8
|
+
* Must be called during `setup()`, like every other Vue composable.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useUiId(prefix: string, explicit?: MaybeRefOrGetter<string | undefined>): ComputedRef<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Compose an `aria-describedby` (or `aria-labelledby`) value from ids that may
|
|
13
|
+
* be absent.
|
|
14
|
+
*
|
|
15
|
+
* One rule, everywhere in this package: **a control's own ids come first, then
|
|
16
|
+
* whatever the field context adds.** `aria-describedby` is read in document
|
|
17
|
+
* order of the listed ids, so the control's own error, counter or description is
|
|
18
|
+
* what a screen reader hears first, and the wrapper's help text follows. Nothing
|
|
19
|
+
* ever *replaces* the context — a `describedBy` prop adds to it, so
|
|
20
|
+
* `<FieldWrapper error="…"><Input described-by="x"/></FieldWrapper>` still
|
|
21
|
+
* describes the error.
|
|
22
|
+
*
|
|
23
|
+
* Duplicates are dropped (the same id listed twice is announced twice), and an
|
|
24
|
+
* empty result is `undefined` rather than `""`, so the attribute is omitted
|
|
25
|
+
* instead of rendered empty.
|
|
26
|
+
*
|
|
27
|
+
* **Deduplication is per id, not per argument.** Every argument here is itself an
|
|
28
|
+
* `aria-describedby` value, so it may already hold several space-separated ids —
|
|
29
|
+
* a `FieldWrapper`'s context contributes its error, help and counter ids as one
|
|
30
|
+
* string, and a consumer's `describedBy` prop may do the same. Comparing whole
|
|
31
|
+
* arguments would only have caught the case where two of them were byte-identical,
|
|
32
|
+
* and `joinIds('a b', 'b c')` would have announced `b` twice. Each argument is
|
|
33
|
+
* split on whitespace and the ids are deduplicated individually, first occurrence
|
|
34
|
+
* winning, so the order the rule promises is preserved.
|
|
35
|
+
*/
|
|
36
|
+
export declare function joinIds(...ids: Array<string | false | null | undefined>): string | undefined;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Joins a list of strings the way a short list naturally reads: comma-separated, with the last
|
|
3
|
+
* item introduced by the locale's own conjunction word and no comma before it —
|
|
4
|
+
* `AvatarGroup`'s accessible sentence is the one caller (spec "Avatar" → Accessibility:
|
|
5
|
+
* `aria-label="Makers: Ingrid, Tomas, Maya and 4 more"`, no Oxford comma before "and"; the API contract:
|
|
6
|
+
* "Icelandic list joining: use `Intl.ListFormat` with the message locale where available").
|
|
7
|
+
*
|
|
8
|
+
* `Intl.ListFormat` is the right primitive for this locale by locale, but its English "long
|
|
9
|
+
* conjunction" CLDR pattern inserts a comma before "and" once there are three or more items
|
|
10
|
+
* ("a, b, and c"), which the spec's own example does not have — Icelandic's own pattern has no
|
|
11
|
+
* such comma, so verbatim output already matches there. Rather than hand-roll the whole join and
|
|
12
|
+
* lose every locale's own conjunction word, word order and pluralisation, this keeps
|
|
13
|
+
* `Intl.ListFormat`'s output and removes only that one separator: `formatToParts` exposes the
|
|
14
|
+
* literal immediately before the final element, and stripping a leading `", "` from it turns
|
|
15
|
+
* "a, b, and c" into "a, b and c" while leaving a locale that never had the comma (Icelandic
|
|
16
|
+
* among them) untouched.
|
|
17
|
+
*
|
|
18
|
+
* Falls back to a hand-written join — `", "` between every item but the last, `" and "`/`" og "`
|
|
19
|
+
* before it, picked from the locale tag — when `Intl.ListFormat` is not available in the runtime
|
|
20
|
+
* at all (some minimal JS engines ship `Intl` without every constructor).
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatConjunctionList(items: string[], locale: string): string;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The format masks the design spec's Input asks for ("Like BS1 4XE", `(###) ###-####`).
|
|
3
|
+
*
|
|
4
|
+
* A *format* is a template string in which some characters are **placeholder slots** and
|
|
5
|
+
* everything else is a **separator**. `applyMask` fills the slots from the raw value in order and
|
|
6
|
+
* writes the separators between them; `stripMask` takes a formatted string back to the raw value.
|
|
7
|
+
* The two are inverse for any raw value `applyMask` accepted, which is what lets a component keep
|
|
8
|
+
* the raw value in its model and only ever show the formatted one.
|
|
9
|
+
*
|
|
10
|
+
* A format with **no placeholder slots at all** (`'--'`, `'()- '`) therefore formats every value to
|
|
11
|
+
* the empty string and strips every value to the empty string: separators are only ever written
|
|
12
|
+
* behind a slot that filled, and there is no slot. A field masked that way shows nothing, whatever
|
|
13
|
+
* is typed into it. That is the consistent answer rather than a special case, but it is worth
|
|
14
|
+
* knowing before a format is built from anything but a literal.
|
|
15
|
+
*
|
|
16
|
+
* Deliberately tiny and stateless: no caret model, no incremental diffing, no DOM. The component
|
|
17
|
+
* owns the caret; this owns the string.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The placeholder characters every format understands unless the caller passes its own map:
|
|
21
|
+
* `#` a digit, `A` a letter, `*` either. Any character that is not a key here is a separator, so
|
|
22
|
+
* `(`, `)`, `-` and a space in `(###) ###-####` are literal text.
|
|
23
|
+
*/
|
|
24
|
+
export declare const defaultCharacterMeaning: Readonly<Record<string, RegExp>>;
|
|
25
|
+
/**
|
|
26
|
+
* Formats `raw` into `format`.
|
|
27
|
+
*
|
|
28
|
+
* - Raw characters fill the placeholder slots in order; a character that does not satisfy the slot
|
|
29
|
+
* it reaches is dropped and the next one is tried, so pasting `(555) 123-4567` into a
|
|
30
|
+
* `(###) ###-####` field yields the same string back.
|
|
31
|
+
* - Separators are written only once there is a value after them, so a partially typed value never
|
|
32
|
+
* grows a dangling `)` or `-` the customer then has to delete.
|
|
33
|
+
* - The result never exceeds the format: input past the last slot is ignored.
|
|
34
|
+
*
|
|
35
|
+
* An empty `format` means "no mask" and returns `raw` unchanged. A non-empty format with no
|
|
36
|
+
* placeholder slots in it returns `''` — see the module comment.
|
|
37
|
+
*/
|
|
38
|
+
export declare function applyMask(raw: string, format: string, characterMeaning?: Readonly<Record<string, RegExp>>): string;
|
|
39
|
+
/**
|
|
40
|
+
* The inverse of {@link applyMask}: the raw value behind a formatted string.
|
|
41
|
+
*
|
|
42
|
+
* It tolerates a string that is not exactly what `applyMask` would have produced — a value the
|
|
43
|
+
* customer pasted without separators, or one mid-edit with a separator deleted — by matching
|
|
44
|
+
* characters against the slot rules rather than by position. Anything that fits no slot is
|
|
45
|
+
* dropped. An empty `format` returns the value unchanged, and one with no placeholder slots in
|
|
46
|
+
* it returns `''`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function stripMask(formatted: string, format: string, characterMeaning?: Readonly<Record<string, RegExp>>): string;
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale-aware number formatting and parsing, ported from the private library's own `unit-utils.ts`.
|
|
3
|
+
* Deliberately tiny and no DOM: just `Intl.NumberFormat` wrapped for the three shapes this package
|
|
4
|
+
* needs (a plain decimal, a currency amount, a unit) and the inverse — turning what a person typed
|
|
5
|
+
* in their own locale back into a `number`.
|
|
6
|
+
*
|
|
7
|
+
* **Stateless but for one memo.** `formatUnit` keeps the formatters it builds in a module-level
|
|
8
|
+
* `Map`, because it takes a value and returns a string — a caller formatting a grid of prices has no
|
|
9
|
+
* formatter of its own to hold, and construction costs some 40× a `format()` call. The memo is keyed
|
|
10
|
+
* on every input that reaches `Intl` and holds nothing but `Intl.NumberFormat` instances, so the
|
|
11
|
+
* function stays pure and there is no cross-request state on a server; see `unitFormatters`' own
|
|
12
|
+
* note. Every formatter comes from `@eldrajs/sdk/format`, which writes Icelandic the same on every
|
|
13
|
+
* runtime (Chrome and Cloudflare Workers ship without it) and shares one instance per locale and options.
|
|
14
|
+
*/
|
|
15
|
+
/** What a formatted number needs: the locale plus the handful of `Intl.NumberFormat` options this
|
|
16
|
+
* package's components actually use. */
|
|
17
|
+
export interface NumberFormatOptions {
|
|
18
|
+
/** A BCP 47 locale tag, e.g. `"en-US"` or `"is-IS"`. */
|
|
19
|
+
locale: string;
|
|
20
|
+
/** `"decimal"` (the default), `"currency"` or `"unit"`. */
|
|
21
|
+
style?: 'decimal' | 'currency' | 'unit';
|
|
22
|
+
/** Required with `style: "currency"`, e.g. `"ISK"`, `"USD"`. */
|
|
23
|
+
currency?: string;
|
|
24
|
+
/** Required with `style: "unit"`, e.g. `"kilogram"`. */
|
|
25
|
+
unit?: string;
|
|
26
|
+
/** `Intl.NumberFormat`'s `maximumFractionDigits`. */
|
|
27
|
+
maxFraction?: number;
|
|
28
|
+
/** `Intl.NumberFormat`'s `minimumFractionDigits`. */
|
|
29
|
+
minFraction?: number;
|
|
30
|
+
/**
|
|
31
|
+
* The narrow display: `currencyDisplay: "narrowSymbol"` for a currency ("$" rather than "US$"
|
|
32
|
+
* where the two differ), `unitDisplay: "narrow"` for a unit. No effect on a plain decimal.
|
|
33
|
+
*/
|
|
34
|
+
narrow?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* `Intl.NumberFormat`'s own `currencyDisplay`, for the two values `narrow` cannot express
|
|
37
|
+
* (`"code"` → "USD 12.00", `"name"` → "12.00 US dollars"). Set, it wins over `narrow`.
|
|
38
|
+
*/
|
|
39
|
+
currencyDisplay?: Intl.NumberFormatOptions['currencyDisplay'];
|
|
40
|
+
/** `Intl.NumberFormat`'s own `unitDisplay` (`"short"`, `"narrow"`, `"long"`). Wins over `narrow`. */
|
|
41
|
+
unitDisplay?: Intl.NumberFormatOptions['unitDisplay'];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Builds the `Intl.NumberFormat` a `NumberFormatOptions` describes, so a caller that needs to
|
|
45
|
+
* format many values (a list of prices) builds it once rather than paying `formatNumber`'s own
|
|
46
|
+
* construction cost per value.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createNumberFormat(options: NumberFormatOptions): Intl.NumberFormat;
|
|
49
|
+
/** Formats one value. For formatting many values under the same options, use `createNumberFormat`
|
|
50
|
+
* once and call `.format()` on the result instead — this constructs a fresh formatter every call. */
|
|
51
|
+
export declare function formatNumber(value: number, options: NumberFormatOptions): string;
|
|
52
|
+
/**
|
|
53
|
+
* The group and decimal separators a locale's `Intl.NumberFormat` actually uses, read from the
|
|
54
|
+
* runtime's own ICU data rather than a hand-maintained table — `is-IS` groups with `.` and takes
|
|
55
|
+
* `,` as the decimal point, `en-US` the reverse, and other locales use other characters entirely
|
|
56
|
+
* (a non-breaking space, an apostrophe, …). `12345.6` is large enough to force a `group` part in
|
|
57
|
+
* every locale that groups at all, and has a fractional part so `decimal` always appears too.
|
|
58
|
+
*
|
|
59
|
+
* Exported because a control that lets a person *type* a number needs exactly the two characters
|
|
60
|
+
* the formatter would print: `QuantityStepper` strips the group separator out of its editing text
|
|
61
|
+
* and accepts both through the `beforeinput` filter in `src/utils/numeric-input.ts`. A locale that does
|
|
62
|
+
* not group at all returns `""` for `group`, which a caller must read as "there is no group
|
|
63
|
+
* separator" rather than as a separator that happens to be empty.
|
|
64
|
+
*/
|
|
65
|
+
export declare function localeSeparators(locale: string): {
|
|
66
|
+
group: string;
|
|
67
|
+
decimal: string;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Parses text a person typed in their own locale back into a plain `number` — the inverse of
|
|
71
|
+
* `formatNumber` with `style: "decimal"`. Handles `is-IS`'s `"1.234,56"` (`.` groups, `,` is the
|
|
72
|
+
* decimal point) and `en-US`'s `"1,234.56"` (the reverse) by deriving both separators from the
|
|
73
|
+
* locale itself (`localeSeparators`, above) rather than assuming either arrangement.
|
|
74
|
+
*
|
|
75
|
+
* Returns `null` for anything that is not a valid number once separators are stripped — empty
|
|
76
|
+
* text, a bare `-` or `.`, stray letters — so a caller never has to check for `NaN` itself. A
|
|
77
|
+
* **trailing** separator is not one of those: `"12."` is `12`, and so is `"12,"` under `is-IS`,
|
|
78
|
+
* because a fraction that has not been typed yet is not a reason to throw the number away.
|
|
79
|
+
*/
|
|
80
|
+
export declare function parseLocaleNumber(text: string, locale: string): number | null;
|
|
81
|
+
/**
|
|
82
|
+
* How many fraction digits a currency actually has — 2 for `USD` and `EUR`, **0** for `ISK` and
|
|
83
|
+
* `JPY`, 3 for `KWD` — read from the runtime's own ICU data rather than a hand-maintained table,
|
|
84
|
+
* the same way `localeSeparators` reads the separators.
|
|
85
|
+
*
|
|
86
|
+
* A public helper, also used by `Price` (`toMajor`, converting a minor-unit integer to the major
|
|
87
|
+
* unit `Intl.NumberFormat` expects). `UnitInput` and `CurrencyInput` keep the private library's own
|
|
88
|
+
* rule instead — `maxFraction` is `2` whatever the currency, so a field shows what was typed rather
|
|
89
|
+
* than what the currency's minor unit allows. It is exported for a consumer who wants the other
|
|
90
|
+
* rule too: rounding an Icelandic price to two decimals and then displaying it with none silently
|
|
91
|
+
* drops what the customer typed, and hard-coding 2 is exactly the assumption that breaks in
|
|
92
|
+
* `is-IS`.
|
|
93
|
+
*
|
|
94
|
+
* The locale only picks which ICU data is consulted; the digit count is the currency's, so
|
|
95
|
+
* `ISK` is 0 under `en-US` too.
|
|
96
|
+
*/
|
|
97
|
+
export declare function currencyFractionDigits(currency: string, locale?: string): number;
|
|
98
|
+
/**
|
|
99
|
+
* The options the private library's `formatUnit` takes, mirrored name for name (its own
|
|
100
|
+
* `UnitFormatProps`) so that library can alias this module's function in place of its copy.
|
|
101
|
+
* `locale` and `maxFraction` are the two it declares as required; every value is defaulted here
|
|
102
|
+
* exactly as it defaults them, so an omitted one behaves identically either way.
|
|
103
|
+
*/
|
|
104
|
+
export interface UnitFormatOptions {
|
|
105
|
+
/** A BCP 47 locale tag. Defaults to `"en-US"`. */
|
|
106
|
+
locale?: string;
|
|
107
|
+
/** An `Intl` unit identifier, read only when `isCurrency` is false. Defaults to `"meter"`. */
|
|
108
|
+
unit?: string;
|
|
109
|
+
/** `maximumFractionDigits`. Defaults to `2`. */
|
|
110
|
+
maxFraction?: number;
|
|
111
|
+
/** Format as a currency rather than a unit. Defaults to `false`. */
|
|
112
|
+
isCurrency?: boolean;
|
|
113
|
+
/** ISO 4217, read only when `isCurrency`. Defaults to `"USD"`. */
|
|
114
|
+
currency?: string;
|
|
115
|
+
/**
|
|
116
|
+
* The **narrow** currency sign (`currencyDisplay: "narrowSymbol"`) rather than the wide one.
|
|
117
|
+
* Defaults to `false`. Deliberately has no effect on a unit — the private helper sets no
|
|
118
|
+
* `unitDisplay` at all, so a unit is always `Intl`'s own `"short"`. (`NumberFormatOptions.narrow`,
|
|
119
|
+
* this module's own option, *does* narrow a unit; that is the one place the two vocabularies
|
|
120
|
+
* differ, and the reason this function does not simply forward `narrow`.)
|
|
121
|
+
*/
|
|
122
|
+
narrow?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* `minimumFractionDigits`. **Display-only; omit it to match input formatting.**
|
|
125
|
+
*
|
|
126
|
+
* The one option here the private library's own `UnitFormatProps` does not have, and the reason
|
|
127
|
+
* it is optional with no default: omitted, this is the private helper's unconditional
|
|
128
|
+
* `minimumFractionDigits: 0` — the rule a *field* wants, where `28` must read `"$28"` because
|
|
129
|
+
* that is what the person typed. A **displayed** amount wants the opposite: a price list in which
|
|
130
|
+
* one row reads `$96` and the next `$96.50` is ragged, so `Price` (and a theme formatting money
|
|
131
|
+
* into a sentence) passes `currencyFractionDigits(currency, locale)` here and gets `"$96.00"`.
|
|
132
|
+
* A zero-decimal currency is unaffected either way: its own count is `0`.
|
|
133
|
+
*
|
|
134
|
+
* So the private library can alias these functions unchanged — it never passes this — while the
|
|
135
|
+
* kit's own display path gets padded amounts out of the same formatter.
|
|
136
|
+
*
|
|
137
|
+
* **It must not exceed `maxFraction`, which defaults to `2` whatever the currency.** So a
|
|
138
|
+
* three-decimal currency needs both passed, and passing only `minFraction: 3` is refused with a
|
|
139
|
+
* `RangeError` naming both — `Intl`'s own message for that pair blames
|
|
140
|
+
* `maximumFractionDigits`, a value the caller never set.
|
|
141
|
+
*/
|
|
142
|
+
minFraction?: number;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The `Intl.NumberFormat` a `UnitFormatOptions` describes: the port of the private library's own
|
|
146
|
+
* `defaultUnitFormat`, argument for argument — the options object, the optional second
|
|
147
|
+
* `Intl.NumberFormatOptions` bag, and the fact that the bag is applied **last** so it can override
|
|
148
|
+
* anything the rule above it decided.
|
|
149
|
+
*
|
|
150
|
+
* **The third canonical copy, and the one that actually holds the rule.** `formatUnit` and
|
|
151
|
+
* `formatCurrency` are wrappers over this, exactly as the private library's own two are, which is
|
|
152
|
+
* what lets that library import all three from `@eldrajs/ui` and delete its `unit-utils.ts`
|
|
153
|
+
* outright — deleting only the wrappers would leave the sign and digit rule still defined privately,
|
|
154
|
+
* which is the duplication this port exists to end. The rule, in full: `style` is `"currency"` or
|
|
155
|
+
* `"unit"`; a unit carries `unit` and no `unitDisplay`, so `Intl`'s own `"short"` applies; a currency
|
|
156
|
+
* carries `currency` and `currencyDisplay: narrow ? "narrowSymbol" : "symbol"`;
|
|
157
|
+
* `minimumFractionDigits` is `minFraction` (`0` when omitted, as there) and `maximumFractionDigits`
|
|
158
|
+
* is `maxFraction`. Change none of it here without changing it there; the defaults live in
|
|
159
|
+
* `UNIT_FORMAT_DEFAULTS`.
|
|
160
|
+
*
|
|
161
|
+
* `extraOptions` is what the private library's `UnitInput` passes `{ minimumFractionDigits: 2 }`
|
|
162
|
+
* through for its placeholder and its part measurement, and it keeps that meaning: a plain
|
|
163
|
+
* `Intl.NumberFormatOptions` spread over the resolved options, so a caller can override even
|
|
164
|
+
* `style`. Nothing in this package calls it — `formatUnit` does not forward one, because the
|
|
165
|
+
* formatter it memoises must be a function of its key alone — but the signature is the private
|
|
166
|
+
* one's, so an aliasing consumer needs no change.
|
|
167
|
+
*
|
|
168
|
+
* Returns the formatter rather than a string, so a caller that formats many values builds it once;
|
|
169
|
+
* that is also why nothing memoises it. Throws `RangeError` for a currency code, unit identifier or
|
|
170
|
+
* locale `Intl` does not recognise, and for an explicit `minFraction` above `maxFraction`.
|
|
171
|
+
*/
|
|
172
|
+
export declare function defaultUnitFormat(options?: UnitFormatOptions, extraOptions?: Intl.NumberFormatOptions): Intl.NumberFormat;
|
|
173
|
+
/**
|
|
174
|
+
* A number with a unit or a currency attached, in a locale: the port of the private library's own
|
|
175
|
+
* `formatUnit`, option names and all — `defaultUnitFormat(options).format(value)`, exactly as the
|
|
176
|
+
* private one is, with the formatter memoised (see `unitFormatters`).
|
|
177
|
+
*
|
|
178
|
+
* **Canonical, with `defaultUnitFormat` and `formatCurrency`.** The private library is expected to
|
|
179
|
+
* import all three from `@eldrajs/ui` and delete its own, so with the arguments that library passes
|
|
180
|
+
* the output must agree character for character; the rule itself is written out on
|
|
181
|
+
* `defaultUnitFormat`. `minFraction` is the one option beyond that library's own, additive and
|
|
182
|
+
* optional: omitted — which is how it calls — the behaviour is exactly the private one's. See
|
|
183
|
+
* `UnitFormatOptions.minFraction`.
|
|
184
|
+
*
|
|
185
|
+
* Throws what `Intl.NumberFormat` throws — a `RangeError` for a currency code, unit identifier or
|
|
186
|
+
* locale it does not recognise — because the private helper does, and a public copy that swallowed
|
|
187
|
+
* an error its original raises is not the same function; plus the one `defaultUnitFormat` adds for
|
|
188
|
+
* an explicit `minFraction` above `maxFraction`. A caller inside a `computed` must guard it (`Price`
|
|
189
|
+
* does, falling back to a plain decimal plus the raw code).
|
|
190
|
+
*/
|
|
191
|
+
export declare function formatUnit(value: number, options: UnitFormatOptions): string;
|
|
192
|
+
/**
|
|
193
|
+
* One currency amount as text, in the narrow sign by default: `"kr 2,800"` (`en-US`/`ISK`),
|
|
194
|
+
* `"2.800 kr."` (`is-IS`/`ISK`), `"$28"` (`en-US`/`USD`).
|
|
195
|
+
*
|
|
196
|
+
* The port of the private library's own `formatCurrency` — **positional arguments and the same
|
|
197
|
+
* defaults on purpose**, where the rest of this package would take an options object, so that this
|
|
198
|
+
* can be the canonical copy that library imports in place of its own. In its first five parameters
|
|
199
|
+
* it is `formatUnit(value, { locale, isCurrency: true, currency, maxFraction, narrow: narrowSymbol })`
|
|
200
|
+
* and nothing else, exactly as the private one is.
|
|
201
|
+
*
|
|
202
|
+
* This is the one public entry point for formatting money, and the reason it exists: a hand-built
|
|
203
|
+
* `Intl.NumberFormat({ style: 'currency' })` renders the **wide** sign (`"ISK 2,800"`), which is
|
|
204
|
+
* not the shape this kit's prices and currency fields are in — a storefront formatting its own
|
|
205
|
+
* amounts that way showed `"ISK 2,800"` in a button label beside a `<Price>` reading `"kr 2,800"`
|
|
206
|
+
* for the same money.
|
|
207
|
+
*
|
|
208
|
+
* Three things to know before calling it:
|
|
209
|
+
*
|
|
210
|
+
* - **`minimumFractionDigits` is `0` unless `minFraction` says otherwise.** Called the private
|
|
211
|
+
* library's way — five arguments or fewer — `28` is `"$28"` and `28.5` is `"$28.5"`: the rule a
|
|
212
|
+
* currency *field* wants, where the field shows what a person typed rather than what the minor
|
|
213
|
+
* unit allows.
|
|
214
|
+
* - **`minFraction` is the display rule**, the sixth parameter and the one addition to the ported
|
|
215
|
+
* signature. A price list in which one row reads `$96` and the next `$96.50` is ragged, so a
|
|
216
|
+
* *displayed* amount passes `currencyFractionDigits(currency, locale)` and gets `"$96.00"`. That
|
|
217
|
+
* is what `Price` and the starter's own money helpers do; a zero-decimal currency is unaffected
|
|
218
|
+
* (`"kr 2,800"` either way, its own count being `0`). **It must not exceed `maxFraction`**, which
|
|
219
|
+
* is the next bullet's trap: `formatCurrency(v, 'en-US', 'BHD', true, 2, 3)` is refused with a
|
|
220
|
+
* `RangeError` naming both, rather than `Intl`'s own message blaming a `maximumFractionDigits`
|
|
221
|
+
* the caller never set.
|
|
222
|
+
* - **`maxFraction` defaults to `2` whatever the currency.** A zero-decimal currency is unaffected
|
|
223
|
+
* (`ISK` has no fraction to print), but a three-decimal one is rounded to two unless the caller
|
|
224
|
+
* says otherwise. Pass `currencyFractionDigits(currency, locale)` for the currency's own count,
|
|
225
|
+
* which — being the same answer as for `minFraction` — is what a displayed amount passes for
|
|
226
|
+
* both; passing only the sixth argument for such a currency is the refusal above.
|
|
227
|
+
*
|
|
228
|
+
* Throws for an unrecognised currency code or locale, the same as `formatUnit` and the same as the
|
|
229
|
+
* private helper; see that function's note.
|
|
230
|
+
*/
|
|
231
|
+
export declare function formatCurrency(value: number, locale?: string, currency?: string, narrowSymbol?: boolean, maxFraction?: number, minFraction?: number): string;
|
|
232
|
+
/**
|
|
233
|
+
* The sign a currency is written with in a locale, on its own: `"kr"` (`ISK` under `en-US`,
|
|
234
|
+
* narrow), `"kr."` (`ISK` under `is-IS`), `"$"` (`USD` under `en-US`). For a place that names a
|
|
235
|
+
* currency rather than formatting an amount in it — a currency selector, a label beside a store's
|
|
236
|
+
* code.
|
|
237
|
+
*
|
|
238
|
+
* This package's own addition rather than a port: the private library has no equivalent. Read out
|
|
239
|
+
* of `formatToParts` rather than a hand-maintained code → symbol table, so it is whatever the
|
|
240
|
+
* runtime's own ICU data says, and `narrow` (the default) picks the same sign `formatCurrency`
|
|
241
|
+
* prints. Some locales have no sign for a currency distinct from its code — `ISK` under `en-US` is
|
|
242
|
+
* `"ISK"` with `narrow: false`, `CHF` is `"CHF"` either way — in which case that is what comes
|
|
243
|
+
* back; a caller pairing the code with the symbol should compare the two and print the code alone
|
|
244
|
+
* when they match, rather than `"ISK ISK"`.
|
|
245
|
+
*
|
|
246
|
+
* Unlike `formatCurrency` this one never throws: it has no original to be faithful to, and an
|
|
247
|
+
* unrecognised code returns the code itself, which is also what `Intl` answers for a code it knows
|
|
248
|
+
* but has no sign for.
|
|
249
|
+
*/
|
|
250
|
+
export declare function currencySymbol(currency: string, locale?: string, narrow?: boolean): string;
|