@marianmeres/stuic 3.180.0 → 3.182.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.
Files changed (59) hide show
  1. package/AGENTS.md +2 -2
  2. package/README.md +1 -1
  3. package/dist/components/ColorPicker/ColorPicker.svelte +457 -0
  4. package/dist/components/ColorPicker/ColorPicker.svelte.d.ts +75 -0
  5. package/dist/components/ColorPicker/README.md +220 -0
  6. package/dist/components/ColorPicker/color-value.d.ts +32 -0
  7. package/dist/components/ColorPicker/color-value.js +55 -0
  8. package/dist/components/ColorPicker/i18n-sk.d.ts +17 -0
  9. package/dist/components/ColorPicker/i18n-sk.js +48 -0
  10. package/dist/components/ColorPicker/i18n.d.ts +64 -0
  11. package/dist/components/ColorPicker/i18n.js +75 -0
  12. package/dist/components/ColorPicker/index.css +275 -0
  13. package/dist/components/ColorPicker/index.d.ts +4 -0
  14. package/dist/components/ColorPicker/index.js +4 -0
  15. package/dist/components/ColorPicker/palettes.d.ts +41 -0
  16. package/dist/components/ColorPicker/palettes.js +49 -0
  17. package/dist/components/FieldsBuilder/FieldsBuilder.svelte +101 -150
  18. package/dist/components/FieldsBuilder/FieldsBuilder.svelte.d.ts +10 -1
  19. package/dist/components/FieldsBuilder/README.md +85 -4
  20. package/dist/components/FieldsBuilder/_internal/ColumnsEditor.svelte +624 -0
  21. package/dist/components/FieldsBuilder/_internal/ColumnsEditor.svelte.d.ts +41 -0
  22. package/dist/components/FieldsBuilder/_internal/ExtrasEditor.svelte +174 -0
  23. package/dist/components/FieldsBuilder/_internal/ExtrasEditor.svelte.d.ts +20 -0
  24. package/dist/components/FieldsBuilder/_internal/column-meta.d.ts +27 -0
  25. package/dist/components/FieldsBuilder/_internal/column-meta.js +15 -0
  26. package/dist/components/FieldsBuilder/i18n-sk.js +17 -0
  27. package/dist/components/FieldsBuilder/i18n.d.ts +17 -0
  28. package/dist/components/FieldsBuilder/i18n.js +17 -0
  29. package/dist/components/FieldsBuilder/index.css +20 -0
  30. package/dist/components/FieldsBuilder/index.d.ts +2 -2
  31. package/dist/components/FieldsBuilder/types.d.ts +46 -2
  32. package/dist/components/FieldsBuilder/utils.d.ts +38 -2
  33. package/dist/components/FieldsBuilder/utils.js +184 -70
  34. package/dist/components/Input/FieldTable.svelte +907 -0
  35. package/dist/components/Input/FieldTable.svelte.d.ts +98 -0
  36. package/dist/components/Input/README.md +251 -0
  37. package/dist/components/Input/field-table-i18n-sk.d.ts +21 -0
  38. package/dist/components/Input/field-table-i18n-sk.js +41 -0
  39. package/dist/components/Input/field-table-i18n.d.ts +60 -0
  40. package/dist/components/Input/field-table-i18n.js +66 -0
  41. package/dist/components/Input/field-table-number.d.ts +48 -0
  42. package/dist/components/Input/field-table-number.js +86 -0
  43. package/dist/components/Input/index.css +597 -0
  44. package/dist/components/Input/index.d.ts +4 -0
  45. package/dist/components/Input/index.js +4 -0
  46. package/dist/components/Nav/Nav.svelte +7 -2
  47. package/dist/components/Nav/Nav.svelte.d.ts +7 -2
  48. package/dist/components/Nav/README.md +2 -2
  49. package/dist/components/TabbedMenu/README.md +14 -13
  50. package/dist/components/TabbedMenu/TabbedMenu.svelte +7 -2
  51. package/dist/components/TabbedMenu/TabbedMenu.svelte.d.ts +7 -2
  52. package/dist/index.css +1 -0
  53. package/dist/index.d.ts +1 -0
  54. package/dist/index.js +1 -0
  55. package/dist/utils/tr.d.ts +26 -14
  56. package/dist/utils/tr.js +43 -19
  57. package/docs/_archive/maybe-todo.md +9 -2
  58. package/docs/domains/components.md +82 -19
  59. package/package.json +1 -1
@@ -0,0 +1,220 @@
1
+ # ColorPicker
2
+
3
+ A swatch palette plus a custom-color escape hatch — what `<input type="color">` alone
4
+ cannot do. The palette is a `role="radiogroup"` of swatch buttons (roving tabindex,
5
+ arrows / Home / End / Delete, an optional "no color" swatch), and the custom row is the
6
+ native `<input type="color">` next to a hex text field. A hidden input carries the value
7
+ into forms, with the stuic `validate` action and `required` enforced.
8
+
9
+ Swatch values are **never parsed** — they are handed to CSS as-is, so a palette may hold
10
+ `#3b82f6`, `oklch(...)`, `transparent`, or `var(--stuic-color-primary)`. The selected
11
+ swatch is marked by a ring drawn _outside_ it, which reads on any color without
12
+ measuring its luminance.
13
+
14
+ Mobile is the native picker's home turf: tapping the swatch button opens the platform's
15
+ own full-screen color UI, so there is no anchored popover to fight the on-screen
16
+ keyboard. Swatches grow to a ~44px hit target on a coarse pointer, and the hex field
17
+ carries the iOS zoom guard.
18
+
19
+ Adjacent but different: `Rating` (the same input-with-hidden-input shape),
20
+ `FieldSelect` (a labeled field wrapper), `ThemePreview` (theme token swatches).
21
+
22
+ ## Props
23
+
24
+ | Prop | Type | Default | Description |
25
+ | --------------------- | --------------------------------------- | ---------------------- | ---------------------------------------------------------------------------------------------------------------- |
26
+ | `value` | `string` | `""` | Current color (bindable). Any CSS color string, stored verbatim; `""` = no color |
27
+ | `palette` | `ColorPickerSwatch[]` | `COLOR_PICKER_PALETTE` | Swatches: color strings or `{ value, label }` objects. `[]` renders no palette |
28
+ | `columns` | `number` | — | Cap of N swatches per row (a narrower container wraps to fewer). Unset = as many as fit |
29
+ | `custom` | `"both" \| "native" \| "text" \| false` | `"both"` | Which custom-color controls to render under the palette |
30
+ | `allowClear` | `boolean` | `true` | A crossed-out "no color" swatch, Delete / Backspace, and an emptied hex field all set `""` |
31
+ | `disabled` | `boolean` | `false` | No interaction; the hidden input is disabled too (nothing submits) |
32
+ | `label` | `string` | `"Color"` | Accessible name of the swatch group (via `t("color")` by default) |
33
+ | `name` | `string` | — | Form field name of the hidden input |
34
+ | `required` | `boolean` | `false` | Require a non-empty value — enforced by the built-in validator (hidden inputs skip native constraint validation) |
35
+ | `t` | `TranslateFn` | English | i18n translate function (see below) |
36
+ | `onchange` | `(value: string) => void` | — | Fires on a user **commit** (see "Preview vs commit") |
37
+ | `validate` | `boolean \| ValidateOptions` | — | Validation (stuic `validate` action): omitted/`true` = on, `false` = off, object = options |
38
+ | `setValidationResult` | `(res: ValidationResult) => void` | — | Receives every validation result |
39
+ | `unstyled` | `boolean` | `false` | Skip all default styling (aria and `data-index` stay) |
40
+ | `class` | `string` | — | Additional CSS classes (merged via twMerge) |
41
+ | `classSwatch` | `string` | — | Class for every swatch button |
42
+ | `el` | `HTMLDivElement` | — | Root element reference (bindable) |
43
+ | `inputEl` | `HTMLInputElement` | — | Hidden input reference (bindable) |
44
+
45
+ Other attributes (`id`, `style`, `data-*`, …) are passed to the root `div`.
46
+
47
+ ### Imperative API (via `bind:this`)
48
+
49
+ | Method | Description |
50
+ | ------------------- | -------------------------------------------------------------------- |
51
+ | `validate()` | Trigger validation now; returns the `ValidationResult` |
52
+ | `clearValidation()` | Clear the stored result and the hidden input's custom validity |
53
+ | `getValidation()` | The last validation result (also reported via `setValidationResult`) |
54
+
55
+ ## Usage
56
+
57
+ ### Basic
58
+
59
+ ```svelte
60
+ <script lang="ts">
61
+ import { ColorPicker } from "@marianmeres/stuic";
62
+ let color = $state("#3b82f6");
63
+ </script>
64
+
65
+ <ColorPicker bind:value={color} />
66
+ ```
67
+
68
+ ### Palette only, capped rows
69
+
70
+ ```svelte
71
+ <ColorPicker
72
+ bind:value={color}
73
+ palette={["#ef4444", "#f97316", "#eab308", "#22c55e", "#3b82f6", "#a855f7"]}
74
+ columns={3}
75
+ custom={false}
76
+ allowClear={false}
77
+ />
78
+ ```
79
+
80
+ ### Theme-token swatches
81
+
82
+ ```svelte
83
+ <script lang="ts">
84
+ import { ColorPicker, COLOR_PICKER_PALETTE_THEME } from "@marianmeres/stuic";
85
+ let color = $state("var(--stuic-color-primary)");
86
+ </script>
87
+
88
+ <ColorPicker bind:value={color} palette={COLOR_PICKER_PALETTE_THEME} />
89
+ ```
90
+
91
+ The stored value is the `var(--stuic-color-*)` reference itself, so it keeps following
92
+ the theme wherever it is applied later. The native picker cannot display such a value
93
+ (it shows black until a hex is picked), and on the monochrome themes several of these
94
+ resolve to near-identical greys.
95
+
96
+ ### In a form
97
+
98
+ ```svelte
99
+ <script lang="ts">
100
+ import { ColorPicker, Button } from "@marianmeres/stuic";
101
+ let picker: ColorPicker | undefined = $state();
102
+ let color = $state("");
103
+
104
+ function onsubmit(e: SubmitEvent) {
105
+ e.preventDefault();
106
+ if (!picker?.validate()?.valid) return;
107
+ // ...
108
+ }
109
+ </script>
110
+
111
+ <form {onsubmit}>
112
+ <ColorPicker bind:this={picker} bind:value={color} name="brand_color" required />
113
+ <Button type="submit">Save</Button>
114
+ </form>
115
+ ```
116
+
117
+ ## Preview vs commit
118
+
119
+ `value` updates **live** while the native picker is being dragged and while a valid
120
+ color is being typed into the hex field, so `bind:value` can drive a live preview.
121
+ `onchange` (and the hidden input's `change`, which is what re-runs validation) fires
122
+ only on a **commit**:
123
+
124
+ | Action | `value` | `onchange` |
125
+ | ------------------------------------------------ | ------- | ---------------------------- |
126
+ | Swatch click / arrow key onto a different swatch | ✅ | ✅ |
127
+ | Arrow / Home / End onto the already-checked one | — | — (a radio does not re-fire) |
128
+ | Dragging inside the native OS picker | ✅ | — |
129
+ | The native picker's `change` (dialog committed) | ✅ | ✅ |
130
+ | Typing a valid color into the hex field | ✅ | — |
131
+ | Enter / blur in the hex field | ✅ | ✅ |
132
+ | Enter / blur with an unparseable hex field | — | — (the field snaps back) |
133
+
134
+ The hex field accepts hex in any spelling (`#0f0`, `3b82f6`) and normalizes it to
135
+ lowercase `#rrggbb` on commit; anything else the browser accepts as a CSS color
136
+ (`rebeccapurple`, `rgb(0 0 255)`, `#rrggbbaa`) is kept verbatim. Emptying it clears the
137
+ value when `allowClear` is on.
138
+
139
+ ## Accessibility
140
+
141
+ - The swatches are a `role="radiogroup"` of `role="radio"` buttons with a roving
142
+ tabindex: the checked swatch is the single tab stop (the first one when the current
143
+ color is off-palette), and arrows move + select. Left / Right wrap around the group;
144
+ Up / Down step by one **rendered** row (measured from the layout, so it stays right
145
+ when a narrow screen wraps to fewer per row) and stop at the edges.
146
+ `aria-required` / `aria-invalid` sit on the group.
147
+ - Every swatch is named: an entry's `label` (through `t`) or, without one, its color
148
+ string. The clear swatch is "No color".
149
+ - Selection is signalled by a ring drawn outside the swatch, not only by color.
150
+ - The native picker and hex field are outside the radiogroup and labeled
151
+ ("Custom color", "Hex value").
152
+
153
+ ## i18n
154
+
155
+ ```svelte
156
+ <script lang="ts">
157
+ import {
158
+ ColorPicker,
159
+ createColorPickerT,
160
+ COLOR_PICKER_MESSAGES_SK,
161
+ } from "@marianmeres/stuic";
162
+ const t = createColorPickerT(COLOR_PICKER_MESSAGES_SK);
163
+ </script>
164
+
165
+ <ColorPicker bind:value={color} {t} />
166
+ ```
167
+
168
+ Swatch labels are looked up with themselves as the fallback — `t(label, null, label)` —
169
+ so a consumer's own label ("Brand blue") renders verbatim while the bundled palettes'
170
+ short keys (`red`, `primary`, …) get translated by the catalog. English
171
+ (`COLOR_PICKER_MESSAGES_EN`) is the built-in default and the fallback for every partial
172
+ catalog.
173
+
174
+ ## CSS Variables
175
+
176
+ Prefix `--stuic-color-picker-*`. Override globally at `:root` or locally via `style`:
177
+
178
+ ```svelte
179
+ <ColorPicker style="--stuic-color-picker-swatch-size: 2.5rem;" />
180
+ ```
181
+
182
+ | Variable | Default | Description |
183
+ | -------------------------------- | ------------------------------------------- | ------------------------------------------ |
184
+ | `gap` | `0.375rem` | Gap between swatches |
185
+ | `custom-gap` | `0.5rem` | Gap between the palette and the custom row |
186
+ | `swatch-size` | `1.75rem` | Swatch (and native picker) size |
187
+ | `swatch-size-touch` | `2.75rem` | ...on a coarse pointer |
188
+ | `swatch-border` | `foreground 20%` | Hairline that keeps white swatches visible |
189
+ | `swatch-scale-hover` | `1.1` | Hover scale (fine pointers only) |
190
+ | `swatch-ring-width` / `-gap` | `2px` / `2px` | The selected ring and its gap |
191
+ | `swatch-ring-color` | `--stuic-color-foreground` | The selected ring color |
192
+ | `swatch-ring-gap-color` | `--stuic-color-background` | The gap color (match your surface) |
193
+ | `ring-width` / `ring-color` | `2px` / `--stuic-color-ring` | Focus ring |
194
+ | `clear-color` / `clear-bg` | `--stuic-color-destructive` / `transparent` | The "no color" slash and its background |
195
+ | `text-width` | `10ch` | Hex field width |
196
+ | `text-bg` / `-border` / `-color` | input tokens | Hex field colors |
197
+ | `text-font-family` / `-size` | `--font-mono` / `--text-sm` | Hex field type |
198
+ | `text-font-size-touch-min` | `16px` | iOS zoom guard floor (`0px` opts out) |
199
+ | `opacity-disabled` | `0.5` | Disabled opacity |
200
+
201
+ Radius and border width follow the shared tokens (`--stuic-radius`,
202
+ `--stuic-border-width`) unless `--stuic-color-picker-swatch-radius` /
203
+ `--stuic-color-picker-text-radius` / `--stuic-color-picker-*-border-width` are set.
204
+
205
+ ## Exports
206
+
207
+ | Export | Kind | Description |
208
+ | ---------------------------- | --------- | ------------------------------------------------ |
209
+ | `ColorPicker` | component | Main component |
210
+ | `ColorPickerProps` | type | Props type |
211
+ | `ColorPickerCustom` | type | `"both" \| "native" \| "text" \| false` |
212
+ | `ColorPickerSwatch` | type | `string \| ColorPickerSwatchObject` |
213
+ | `ColorPickerSwatchObject` | type | `{ value, label? }` |
214
+ | `COLOR_PICKER_PALETTE` | constant | The default palette (12 hues + white/grey/black) |
215
+ | `COLOR_PICKER_PALETTE_THEME` | constant | Opt-in design-token palette |
216
+ | `createColorPickerT` | function | Builds the `t` prop from a (partial) catalog |
217
+ | `COLOR_PICKER_MESSAGES_EN` | constant | Built-in English catalog (also the fallback) |
218
+ | `COLOR_PICKER_MESSAGES_SK` | constant | Bundled Slovak catalog (opt-in) |
219
+ | `ColorPickerMessageKey` | type | Message key union |
220
+ | `ColorPickerMessages` | type | One locale's catalog |
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Normalizes a hex color string to lowercase `#rrggbb`, or returns `null` if the
3
+ * input is not a 3- or 6-digit hex color. The leading `#` is optional on input.
4
+ *
5
+ * Alpha (`#rgba` / `#rrggbbaa`) is deliberately rejected here — `ColorPicker`'s
6
+ * native `<input type="color">` cannot represent it. Such values still pass
7
+ * {@link isCssColor} and are kept verbatim.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * normalizeHex("#F00"); // "#ff0000"
12
+ * normalizeHex("3b82f6"); // "#3b82f6"
13
+ * normalizeHex("red"); // null
14
+ * ```
15
+ */
16
+ export declare function normalizeHex(input: unknown): string | null;
17
+ /**
18
+ * True if the browser accepts `v` as a CSS `color` value — `red`, `oklch(...)`,
19
+ * `#rrggbbaa`, `var(--x)`, ... Used as the permissive fallback of the hex text
20
+ * field, so the field can hold anything the palette itself may hold.
21
+ *
22
+ * Returns `false` outside the browser (no `CSS.supports`), which is safe: the
23
+ * only caller is a DOM event handler.
24
+ */
25
+ export declare function isCssColor(v: unknown): boolean;
26
+ /**
27
+ * Loose equality of two color strings: identical strings, or two spellings of the
28
+ * same hex (`#FFF` === `#ffffff`). No color-space conversion — `red` and
29
+ * `#ff0000` are NOT considered equal, on purpose: swatch identity is the string
30
+ * the consumer wrote.
31
+ */
32
+ export declare function isSameColor(a: unknown, b: unknown): boolean;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Normalizes a hex color string to lowercase `#rrggbb`, or returns `null` if the
3
+ * input is not a 3- or 6-digit hex color. The leading `#` is optional on input.
4
+ *
5
+ * Alpha (`#rgba` / `#rrggbbaa`) is deliberately rejected here — `ColorPicker`'s
6
+ * native `<input type="color">` cannot represent it. Such values still pass
7
+ * {@link isCssColor} and are kept verbatim.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * normalizeHex("#F00"); // "#ff0000"
12
+ * normalizeHex("3b82f6"); // "#3b82f6"
13
+ * normalizeHex("red"); // null
14
+ * ```
15
+ */
16
+ export function normalizeHex(input) {
17
+ if (typeof input !== "string")
18
+ return null;
19
+ const v = input.trim().replace(/^#/, "").toLowerCase();
20
+ if (/^[0-9a-f]{3}$/.test(v)) {
21
+ return `#${v[0]}${v[0]}${v[1]}${v[1]}${v[2]}${v[2]}`;
22
+ }
23
+ if (/^[0-9a-f]{6}$/.test(v))
24
+ return `#${v}`;
25
+ return null;
26
+ }
27
+ /**
28
+ * True if the browser accepts `v` as a CSS `color` value — `red`, `oklch(...)`,
29
+ * `#rrggbbaa`, `var(--x)`, ... Used as the permissive fallback of the hex text
30
+ * field, so the field can hold anything the palette itself may hold.
31
+ *
32
+ * Returns `false` outside the browser (no `CSS.supports`), which is safe: the
33
+ * only caller is a DOM event handler.
34
+ */
35
+ export function isCssColor(v) {
36
+ if (typeof v !== "string" || !v.trim())
37
+ return false;
38
+ if (typeof CSS === "undefined" || typeof CSS.supports !== "function")
39
+ return false;
40
+ return CSS.supports("color", v.trim());
41
+ }
42
+ /**
43
+ * Loose equality of two color strings: identical strings, or two spellings of the
44
+ * same hex (`#FFF` === `#ffffff`). No color-space conversion — `red` and
45
+ * `#ff0000` are NOT considered equal, on purpose: swatch identity is the string
46
+ * the consumer wrote.
47
+ */
48
+ export function isSameColor(a, b) {
49
+ if (typeof a !== "string" || typeof b !== "string")
50
+ return false;
51
+ if (a === b)
52
+ return true;
53
+ const na = normalizeHex(a);
54
+ return !!na && na === normalizeHex(b);
55
+ }
@@ -0,0 +1,17 @@
1
+ import type { ColorPickerMessages } from "./i18n.js";
2
+ /**
3
+ * Slovak message catalog for `ColorPicker`. Opt-in — English stays the built-in
4
+ * default, and this module is only pulled into a bundle when it is actually
5
+ * imported (the component itself never references it).
6
+ *
7
+ * @example
8
+ * ```svelte
9
+ * <script>
10
+ * import { ColorPicker, createColorPickerT, COLOR_PICKER_MESSAGES_SK } from "@marianmeres/stuic";
11
+ * const t = createColorPickerT(COLOR_PICKER_MESSAGES_SK);
12
+ * </script>
13
+ *
14
+ * <ColorPicker bind:value {t} />
15
+ * ```
16
+ */
17
+ export declare const COLOR_PICKER_MESSAGES_SK: ColorPickerMessages;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Slovak message catalog for `ColorPicker`. Opt-in — English stays the built-in
3
+ * default, and this module is only pulled into a bundle when it is actually
4
+ * imported (the component itself never references it).
5
+ *
6
+ * @example
7
+ * ```svelte
8
+ * <script>
9
+ * import { ColorPicker, createColorPickerT, COLOR_PICKER_MESSAGES_SK } from "@marianmeres/stuic";
10
+ * const t = createColorPickerT(COLOR_PICKER_MESSAGES_SK);
11
+ * </script>
12
+ *
13
+ * <ColorPicker bind:value {t} />
14
+ * ```
15
+ */
16
+ export const COLOR_PICKER_MESSAGES_SK = {
17
+ color: "Farba",
18
+ custom_color: "Vlastná farba",
19
+ hex_value: "Hex hodnota",
20
+ // a format hint, not a word — the same in every locale
21
+ hex_placeholder: "#rrggbb",
22
+ no_color: "Žiadna farba",
23
+ required: "Prosím, vyberte farbu",
24
+ red: "Červená",
25
+ orange: "Oranžová",
26
+ amber: "Jantárová",
27
+ yellow: "Žltá",
28
+ lime: "Limetková",
29
+ green: "Zelená",
30
+ teal: "Modrozelená",
31
+ cyan: "Azúrová",
32
+ blue: "Modrá",
33
+ indigo: "Indigová",
34
+ violet: "Fialová",
35
+ pink: "Ružová",
36
+ white: "Biela",
37
+ gray: "Sivá",
38
+ black: "Čierna",
39
+ primary: "Primárna",
40
+ accent: "Akcentová",
41
+ success: "Úspešná",
42
+ warning: "Varovná",
43
+ destructive: "Deštruktívna",
44
+ foreground: "Popredie",
45
+ muted_foreground: "Tlmené popredie",
46
+ muted: "Tlmená",
47
+ background: "Pozadie",
48
+ };
@@ -0,0 +1,64 @@
1
+ import type { TranslateFn } from "../../types.js";
2
+ /**
3
+ * The built-in (English) message catalog of `ColorPicker`. Also the fallback of
4
+ * every other bundled locale, so a locale missing a key still renders text.
5
+ *
6
+ * The second half are the labels of the two bundled palettes. Swatch labels are
7
+ * looked up with themselves as the fallback (`t(label, null, label)`), which is
8
+ * why a consumer's own label — "Brand blue" — renders verbatim while the short
9
+ * keys below get translated.
10
+ */
11
+ export declare const COLOR_PICKER_MESSAGES_EN: {
12
+ color: string;
13
+ custom_color: string;
14
+ hex_value: string;
15
+ hex_placeholder: string;
16
+ no_color: string;
17
+ required: string;
18
+ red: string;
19
+ orange: string;
20
+ amber: string;
21
+ yellow: string;
22
+ lime: string;
23
+ green: string;
24
+ teal: string;
25
+ cyan: string;
26
+ blue: string;
27
+ indigo: string;
28
+ violet: string;
29
+ pink: string;
30
+ white: string;
31
+ gray: string;
32
+ black: string;
33
+ primary: string;
34
+ accent: string;
35
+ success: string;
36
+ warning: string;
37
+ destructive: string;
38
+ foreground: string;
39
+ muted_foreground: string;
40
+ muted: string;
41
+ background: string;
42
+ };
43
+ /** Every message key `ColorPicker` may look up. */
44
+ export type ColorPickerMessageKey = keyof typeof COLOR_PICKER_MESSAGES_EN;
45
+ /** A (possibly partial) catalog for one locale. */
46
+ export type ColorPickerMessages = Record<ColorPickerMessageKey, string>;
47
+ /**
48
+ * Builds the `t` prop of `ColorPicker` from a message catalog. Unknown or
49
+ * untranslated keys fall back to `fallbackMessages` (English by default), so a
50
+ * catalog may safely be partial and never renders a raw key.
51
+ *
52
+ * @example
53
+ * ```svelte
54
+ * <script>
55
+ * import { ColorPicker, createColorPickerT, COLOR_PICKER_MESSAGES_SK } from "@marianmeres/stuic";
56
+ * const t = createColorPickerT(COLOR_PICKER_MESSAGES_SK);
57
+ * </script>
58
+ *
59
+ * <ColorPicker bind:value {t} />
60
+ * ```
61
+ */
62
+ export declare function createColorPickerT(messages: Partial<ColorPickerMessages> | Record<string, string>, fallbackMessages?: Partial<ColorPickerMessages> | Record<string, string>): TranslateFn;
63
+ /** The component's built-in English `t`. */
64
+ export declare const t_default: TranslateFn;
@@ -0,0 +1,75 @@
1
+ import { isPlainObject } from "../../utils/is-plain-object.js";
2
+ import { replaceMap } from "../../utils/replace-map.js";
3
+ /**
4
+ * The built-in (English) message catalog of `ColorPicker`. Also the fallback of
5
+ * every other bundled locale, so a locale missing a key still renders text.
6
+ *
7
+ * The second half are the labels of the two bundled palettes. Swatch labels are
8
+ * looked up with themselves as the fallback (`t(label, null, label)`), which is
9
+ * why a consumer's own label — "Brand blue" — renders verbatim while the short
10
+ * keys below get translated.
11
+ */
12
+ export const COLOR_PICKER_MESSAGES_EN = {
13
+ // chrome
14
+ color: "Color",
15
+ custom_color: "Custom color",
16
+ hex_value: "Hex value",
17
+ hex_placeholder: "#rrggbb",
18
+ no_color: "No color",
19
+ required: "Please select a color",
20
+ // COLOR_PICKER_PALETTE
21
+ red: "Red",
22
+ orange: "Orange",
23
+ amber: "Amber",
24
+ yellow: "Yellow",
25
+ lime: "Lime",
26
+ green: "Green",
27
+ teal: "Teal",
28
+ cyan: "Cyan",
29
+ blue: "Blue",
30
+ indigo: "Indigo",
31
+ violet: "Violet",
32
+ pink: "Pink",
33
+ white: "White",
34
+ gray: "Gray",
35
+ black: "Black",
36
+ // COLOR_PICKER_PALETTE_THEME
37
+ primary: "Primary",
38
+ accent: "Accent",
39
+ success: "Success",
40
+ warning: "Warning",
41
+ destructive: "Destructive",
42
+ foreground: "Foreground",
43
+ muted_foreground: "Muted foreground",
44
+ muted: "Muted",
45
+ background: "Background",
46
+ };
47
+ /**
48
+ * Builds the `t` prop of `ColorPicker` from a message catalog. Unknown or
49
+ * untranslated keys fall back to `fallbackMessages` (English by default), so a
50
+ * catalog may safely be partial and never renders a raw key.
51
+ *
52
+ * @example
53
+ * ```svelte
54
+ * <script>
55
+ * import { ColorPicker, createColorPickerT, COLOR_PICKER_MESSAGES_SK } from "@marianmeres/stuic";
56
+ * const t = createColorPickerT(COLOR_PICKER_MESSAGES_SK);
57
+ * </script>
58
+ *
59
+ * <ColorPicker bind:value {t} />
60
+ * ```
61
+ */
62
+ export function createColorPickerT(messages, fallbackMessages = COLOR_PICKER_MESSAGES_EN) {
63
+ return (k, values = null, fallback = "") => {
64
+ const out = messages[k] ??
65
+ fallbackMessages[k] ??
66
+ (typeof fallback === "string" ? fallback : k);
67
+ return isPlainObject(values)
68
+ ? replaceMap(out, values, {
69
+ preSearchKeyTransform: (k) => `{${k}}`,
70
+ })
71
+ : out;
72
+ };
73
+ }
74
+ /** The component's built-in English `t`. */
75
+ export const t_default = createColorPickerT(COLOR_PICKER_MESSAGES_EN);