@human-kit/ui 1.0.0-beta.9 → 1.0.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 (98) hide show
  1. package/README.md +27 -60
  2. package/dist/FOCUS_STATE_CONTRACT.md +1 -0
  3. package/dist/color-picker/README.md +78 -0
  4. package/dist/color-picker/area/color-picker-area.svelte +195 -0
  5. package/dist/color-picker/area/color-picker-area.svelte.d.ts +4 -0
  6. package/dist/color-picker/area-thumb/color-picker-area-thumb.svelte +231 -0
  7. package/dist/color-picker/area-thumb/color-picker-area-thumb.svelte.d.ts +4 -0
  8. package/dist/color-picker/channel-field/color-picker-channel-field.svelte +95 -0
  9. package/dist/color-picker/channel-field/color-picker-channel-field.svelte.d.ts +4 -0
  10. package/dist/color-picker/eye-dropper/color-picker-eye-dropper.svelte +79 -0
  11. package/dist/color-picker/eye-dropper/color-picker-eye-dropper.svelte.d.ts +4 -0
  12. package/dist/color-picker/hex-field/color-picker-hex-field.svelte +105 -0
  13. package/dist/color-picker/hex-field/color-picker-hex-field.svelte.d.ts +4 -0
  14. package/dist/color-picker/index.d.ts +16 -0
  15. package/dist/color-picker/index.js +15 -0
  16. package/dist/color-picker/index.parts.d.ts +12 -0
  17. package/dist/color-picker/index.parts.js +12 -0
  18. package/dist/color-picker/label/color-picker-label.svelte +34 -0
  19. package/dist/color-picker/label/color-picker-label.svelte.d.ts +4 -0
  20. package/dist/color-picker/preview/color-picker-preview.svelte +43 -0
  21. package/dist/color-picker/preview/color-picker-preview.svelte.d.ts +4 -0
  22. package/dist/color-picker/root/color-picker-root.svelte +365 -0
  23. package/dist/color-picker/root/color-picker-root.svelte.d.ts +4 -0
  24. package/dist/color-picker/root/color.d.ts +68 -0
  25. package/dist/color-picker/root/color.js +266 -0
  26. package/dist/color-picker/root/context.d.ts +127 -0
  27. package/dist/color-picker/root/context.js +44 -0
  28. package/dist/color-picker/slider/color-picker-slider.svelte +188 -0
  29. package/dist/color-picker/slider/color-picker-slider.svelte.d.ts +4 -0
  30. package/dist/color-picker/slider-thumb/color-picker-slider-thumb.svelte +208 -0
  31. package/dist/color-picker/slider-thumb/color-picker-slider-thumb.svelte.d.ts +4 -0
  32. package/dist/color-picker/swatch/color-picker-swatch.svelte +149 -0
  33. package/dist/color-picker/swatch/color-picker-swatch.svelte.d.ts +4 -0
  34. package/dist/color-picker/swatch-list/color-picker-swatch-list.svelte +133 -0
  35. package/dist/color-picker/swatch-list/color-picker-swatch-list.svelte.d.ts +4 -0
  36. package/dist/color-picker/types.d.ts +176 -0
  37. package/dist/color-picker/types.js +1 -0
  38. package/dist/index.d.ts +8 -0
  39. package/dist/index.js +8 -0
  40. package/dist/internal/localized-strings.d.ts +152 -0
  41. package/dist/internal/localized-strings.js +152 -0
  42. package/dist/pin-input/README.md +55 -0
  43. package/dist/pin-input/cell/pin-input-cell.svelte +210 -0
  44. package/dist/pin-input/cell/pin-input-cell.svelte.d.ts +4 -0
  45. package/dist/pin-input/index.d.ts +6 -0
  46. package/dist/pin-input/index.js +5 -0
  47. package/dist/pin-input/index.parts.d.ts +3 -0
  48. package/dist/pin-input/index.parts.js +3 -0
  49. package/dist/pin-input/label/pin-input-label.svelte +43 -0
  50. package/dist/pin-input/label/pin-input-label.svelte.d.ts +4 -0
  51. package/dist/pin-input/root/context.d.ts +70 -0
  52. package/dist/pin-input/root/context.js +15 -0
  53. package/dist/pin-input/root/pin-input-root.svelte +337 -0
  54. package/dist/pin-input/root/pin-input-root.svelte.d.ts +4 -0
  55. package/dist/pin-input/root/pin-input-utils.d.ts +18 -0
  56. package/dist/pin-input/root/pin-input-utils.js +44 -0
  57. package/dist/pin-input/types.d.ts +84 -0
  58. package/dist/pin-input/types.js +1 -0
  59. package/dist/rating/README.md +58 -0
  60. package/dist/rating/index.d.ts +7 -0
  61. package/dist/rating/index.js +6 -0
  62. package/dist/rating/index.parts.d.ts +4 -0
  63. package/dist/rating/index.parts.js +4 -0
  64. package/dist/rating/item/rating-item.svelte +177 -0
  65. package/dist/rating/item/rating-item.svelte.d.ts +4 -0
  66. package/dist/rating/label/rating-label.svelte +42 -0
  67. package/dist/rating/label/rating-label.svelte.d.ts +4 -0
  68. package/dist/rating/output/rating-output.svelte +38 -0
  69. package/dist/rating/output/rating-output.svelte.d.ts +4 -0
  70. package/dist/rating/root/context.d.ts +87 -0
  71. package/dist/rating/root/context.js +15 -0
  72. package/dist/rating/root/rating-root.svelte +521 -0
  73. package/dist/rating/root/rating-root.svelte.d.ts +4 -0
  74. package/dist/rating/root/rating-utils.d.ts +28 -0
  75. package/dist/rating/root/rating-utils.js +53 -0
  76. package/dist/rating/types.d.ts +124 -0
  77. package/dist/rating/types.js +1 -0
  78. package/dist/search-field/README.md +29 -0
  79. package/dist/search-field/clear/README.md +5 -0
  80. package/dist/search-field/clear/search-field-clear.svelte +99 -0
  81. package/dist/search-field/clear/search-field-clear.svelte.d.ts +10 -0
  82. package/dist/search-field/index.d.ts +15 -0
  83. package/dist/search-field/index.js +6 -0
  84. package/dist/search-field/index.parts.d.ts +4 -0
  85. package/dist/search-field/index.parts.js +4 -0
  86. package/dist/search-field/input/README.md +5 -0
  87. package/dist/search-field/input/search-field-input.svelte +158 -0
  88. package/dist/search-field/input/search-field-input.svelte.d.ts +14 -0
  89. package/dist/search-field/label/README.md +3 -0
  90. package/dist/search-field/label/search-field-label.svelte +27 -0
  91. package/dist/search-field/label/search-field-label.svelte.d.ts +7 -0
  92. package/dist/search-field/root/README.md +5 -0
  93. package/dist/search-field/root/context.d.ts +28 -0
  94. package/dist/search-field/root/context.js +15 -0
  95. package/dist/search-field/root/search-field-root.svelte +230 -0
  96. package/dist/search-field/root/search-field-root.svelte.d.ts +33 -0
  97. package/dist/tooltip/root/tooltip-root.svelte +16 -11
  98. package/package.json +21 -1
@@ -0,0 +1,230 @@
1
+ <script lang="ts">
2
+ import { readable } from 'svelte/store';
3
+ import { untrack, type Snippet } from 'svelte';
4
+ import type { HTMLAttributes } from 'svelte/elements';
5
+ import { resolveLocalizedString } from '../../internal/localized-strings';
6
+ import { useLocaleContextOptional } from '../../locale-provider/context';
7
+ import { isAriaInvalidValue } from '../../utils/aria-invalid';
8
+ import { composeEventHandlers } from '../../utils/compose-event-handlers';
9
+ import {
10
+ setSearchFieldContext,
11
+ type SearchFieldChangeReason,
12
+ type SearchFieldContext
13
+ } from './context';
14
+
15
+ type SearchFieldRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'id'> & {
16
+ children?: Snippet;
17
+ class?: string;
18
+ /** The id of the root element. If you give none, the component makes one. */
19
+ id?: string;
20
+ /** The search text. You can bind it with `bind:value`. */
21
+ value?: string;
22
+ /** The search text at the start, for when you give no `value`. A form reset goes back to it. */
23
+ defaultValue?: string;
24
+ /** The component calls it when the search text changes. */
25
+ onChange?: (value: string) => void;
26
+ /** The component calls it with the search text when the user presses `Enter` in the input. */
27
+ onSubmit?: (value: string) => void;
28
+ /** The component calls it after the `Escape` key or the clear button empties the input. */
29
+ onClear?: () => void;
30
+ /** Disables the input and the clear button. */
31
+ disabled?: boolean;
32
+ /** The user cannot change the text. The `Escape` key and the clear button do nothing. */
33
+ readonly?: boolean;
34
+ /** Tells a form that it must have a value. The input gets the native `required`. */
35
+ required?: boolean;
36
+ /** Marks the value as invalid. The input gets `aria-invalid`. */
37
+ invalid?: boolean;
38
+ /** Marks the value as invalid, the same as `invalid`. */
39
+ 'aria-invalid'?: HTMLAttributes<HTMLDivElement>['aria-invalid'];
40
+ /** The name of the input in a form. The form submits the search text with this name. */
41
+ name?: string;
42
+ };
43
+
44
+ const generatedId = $props.id();
45
+ const localeContext = useLocaleContextOptional();
46
+ const emptyLocaleStore = readable<string | undefined>(undefined);
47
+ const localeStore = localeContext?.locale ?? emptyLocaleStore;
48
+
49
+ let {
50
+ children,
51
+ class: className,
52
+ id,
53
+ value = $bindable<string | undefined>(undefined),
54
+ defaultValue = '',
55
+ onChange,
56
+ onSubmit,
57
+ onClear,
58
+ disabled = false,
59
+ readonly = false,
60
+ required = false,
61
+ invalid = false,
62
+ 'aria-invalid': ariaInvalid,
63
+ name,
64
+ onfocusin: onFocusInExternal,
65
+ onfocusout: onFocusOutExternal,
66
+ ...restProps
67
+ }: SearchFieldRootProps = $props();
68
+
69
+ const rootId = untrack(() => id) ?? generatedId;
70
+ const inputId = `${rootId}-input`;
71
+ const initialDefaultValue = untrack(() => defaultValue) ?? '';
72
+
73
+ const initialValue = untrack(() => value) ?? initialDefaultValue;
74
+
75
+ let currentValue = $state(initialValue);
76
+ let focused = $state(false);
77
+ let focusVisible = $state(false);
78
+ let focusWithin = $state(false);
79
+ let inputRef: HTMLInputElement | null = $state(null);
80
+
81
+ if (untrack(() => value) === undefined) {
82
+ value = initialValue;
83
+ }
84
+
85
+ // A new value from the parent replaces the text. The text that the user types goes to the
86
+ // parent through `setValue`, thus the two stay equal and this does nothing for it.
87
+ $effect(() => {
88
+ const next = value ?? '';
89
+ untrack(() => {
90
+ if (next !== currentValue) currentValue = next;
91
+ });
92
+ });
93
+
94
+ const isEmpty = $derived(currentValue === '');
95
+ const resolvedInvalid = $derived(Boolean(invalid || isAriaInvalidValue(ariaInvalid)));
96
+ const clearAriaLabel = $derived(resolveLocalizedString($localeStore, 'searchField.clear'));
97
+
98
+ $effect(() => {
99
+ if (!disabled) return;
100
+ focused = false;
101
+ focusVisible = false;
102
+ focusWithin = false;
103
+ });
104
+
105
+ $effect(() => {
106
+ const form = inputRef?.form;
107
+ if (!form) return;
108
+
109
+ // The browser puts `defaultValue` back in the input, but it sends no `input` event.
110
+ const handleFormReset = () => setValue(initialDefaultValue, 'form-reset');
111
+
112
+ form.addEventListener('reset', handleFormReset);
113
+ return () => form.removeEventListener('reset', handleFormReset);
114
+ });
115
+
116
+ function setValue(next: string, reason: SearchFieldChangeReason) {
117
+ if (reason !== 'form-reset' && (disabled || readonly)) return;
118
+ if (next === currentValue) return;
119
+
120
+ currentValue = next;
121
+ value = next;
122
+ onChange?.(next);
123
+ }
124
+
125
+ function clear(reason: 'escape-key' | 'clear-press'): boolean {
126
+ if (disabled || readonly) return false;
127
+ // The text can be in the input and not in the state, when a script wrote `input.value`.
128
+ if (currentValue === '' && (!inputRef || inputRef.value === '')) return false;
129
+
130
+ setValue('', reason);
131
+ if (inputRef && inputRef.value !== '') inputRef.value = '';
132
+ onClear?.();
133
+ return true;
134
+ }
135
+
136
+ function submit() {
137
+ if (disabled || readonly) return;
138
+ onSubmit?.(currentValue);
139
+ }
140
+
141
+ function handleFocusIn() {
142
+ if (disabled) return;
143
+ focusWithin = true;
144
+ }
145
+
146
+ function handleFocusOut(event: FocusEvent) {
147
+ const root = event.currentTarget as HTMLElement;
148
+ const next = event.relatedTarget as Node | null;
149
+ if (next && root.contains(next)) return;
150
+ focusWithin = false;
151
+ }
152
+
153
+ const context: SearchFieldContext = {
154
+ get id() {
155
+ return rootId;
156
+ },
157
+ get inputId() {
158
+ return inputId;
159
+ },
160
+ get value() {
161
+ return currentValue;
162
+ },
163
+ get defaultValue() {
164
+ return initialDefaultValue;
165
+ },
166
+ get name() {
167
+ return name;
168
+ },
169
+ get isEmpty() {
170
+ return isEmpty;
171
+ },
172
+ get isDisabled() {
173
+ return disabled;
174
+ },
175
+ get isReadOnly() {
176
+ return readonly;
177
+ },
178
+ get isRequired() {
179
+ return required;
180
+ },
181
+ get isInvalid() {
182
+ return resolvedInvalid;
183
+ },
184
+ get clearAriaLabel() {
185
+ return clearAriaLabel;
186
+ },
187
+ get focused() {
188
+ return focused;
189
+ },
190
+ get focusVisible() {
191
+ return focusVisible;
192
+ },
193
+ get inputRef() {
194
+ return inputRef;
195
+ },
196
+ setInputRef(element) {
197
+ inputRef = element;
198
+ },
199
+ setFocused(next) {
200
+ focused = next;
201
+ if (!next) focusVisible = false;
202
+ },
203
+ setFocusVisible(next) {
204
+ focusVisible = next;
205
+ },
206
+ setValue,
207
+ clear,
208
+ submit
209
+ };
210
+
211
+ setSearchFieldContext(context);
212
+ </script>
213
+
214
+ <div
215
+ {...restProps}
216
+ id={rootId}
217
+ class={className}
218
+ data-search-field-root="true"
219
+ data-empty={isEmpty || undefined}
220
+ data-disabled={disabled || undefined}
221
+ data-readonly={readonly || undefined}
222
+ data-required={required || undefined}
223
+ data-invalid={resolvedInvalid || undefined}
224
+ data-focus-within={focusWithin || undefined}
225
+ data-focus-visible={(focusWithin && focusVisible) || undefined}
226
+ onfocusin={composeEventHandlers(handleFocusIn, onFocusInExternal ?? undefined)}
227
+ onfocusout={composeEventHandlers(handleFocusOut, onFocusOutExternal ?? undefined)}
228
+ >
229
+ {@render children?.()}
230
+ </div>
@@ -0,0 +1,33 @@
1
+ import { type Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ type SearchFieldRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'id'> & {
4
+ children?: Snippet;
5
+ class?: string;
6
+ /** The id of the root element. If you give none, the component makes one. */
7
+ id?: string;
8
+ /** The search text. You can bind it with `bind:value`. */
9
+ value?: string;
10
+ /** The search text at the start, for when you give no `value`. A form reset goes back to it. */
11
+ defaultValue?: string;
12
+ /** The component calls it when the search text changes. */
13
+ onChange?: (value: string) => void;
14
+ /** The component calls it with the search text when the user presses `Enter` in the input. */
15
+ onSubmit?: (value: string) => void;
16
+ /** The component calls it after the `Escape` key or the clear button empties the input. */
17
+ onClear?: () => void;
18
+ /** Disables the input and the clear button. */
19
+ disabled?: boolean;
20
+ /** The user cannot change the text. The `Escape` key and the clear button do nothing. */
21
+ readonly?: boolean;
22
+ /** Tells a form that it must have a value. The input gets the native `required`. */
23
+ required?: boolean;
24
+ /** Marks the value as invalid. The input gets `aria-invalid`. */
25
+ invalid?: boolean;
26
+ /** Marks the value as invalid, the same as `invalid`. */
27
+ 'aria-invalid'?: HTMLAttributes<HTMLDivElement>['aria-invalid'];
28
+ /** The name of the input in a form. The form submits the search text with this name. */
29
+ name?: string;
30
+ };
31
+ declare const SearchFieldRoot: import("svelte").Component<SearchFieldRootProps, {}, "value">;
32
+ type SearchFieldRoot = ReturnType<typeof SearchFieldRoot>;
33
+ export default SearchFieldRoot;
@@ -21,13 +21,7 @@
21
21
  shouldSkipDelay,
22
22
  unregisterOpenTooltip
23
23
  } from './tooltip-group';
24
- import {
25
- buildSafePolygon,
26
- isPointInPolygon,
27
- isPointInRect,
28
- type Point,
29
- type Side
30
- } from './safe-polygon';
24
+ import { buildSafePolygon, isPointInPolygon, type Point, type Side } from './safe-polygon';
31
25
 
32
26
  /**
33
27
  * Tooltip.Root — the open state, the delays, and the interaction with the trigger.
@@ -164,7 +158,11 @@
164
158
  $effect(() => {
165
159
  if (!isOpen) return;
166
160
  registerOpenTooltip(groupEntry);
167
- return () => unregisterOpenTooltip(groupEntry);
161
+ return () => {
162
+ unregisterOpenTooltip(groupEntry);
163
+ // The panel may go with the pointer still on it, and no `pointerleave` follows.
164
+ pointerOnContent = false;
165
+ };
168
166
  });
169
167
 
170
168
  $effect(() => {
@@ -252,8 +250,12 @@
252
250
  function handleGapPointerMove(event: PointerEvent) {
253
251
  if (!gapPolygon) return;
254
252
  const point = { x: event.clientX, y: event.clientY };
255
- const onContent = contentRef ? isPointInRect(point, contentRef.getBoundingClientRect()) : false;
256
- const onTrigger = triggerRef ? isPointInRect(point, triggerRef.getBoundingClientRect()) : false;
253
+ // What the pointer is on, as the browser hit-tests it, not the bounding box: the corner of a
254
+ // rounded panel is inside its box but not on it, and no `pointerenter` comes from there to
255
+ // take over — tracking stopped on it left the tooltip open for good.
256
+ const target = event.target instanceof Node ? event.target : null;
257
+ const onContent = target !== null && (contentRef?.contains(target) ?? false);
258
+ const onTrigger = target !== null && (triggerRef?.contains(target) ?? false);
257
259
  if (onContent || onTrigger) {
258
260
  // The `pointerenter` of the content or the trigger takes over from here.
259
261
  stopGapTracking();
@@ -326,7 +328,10 @@
326
328
  }
327
329
 
328
330
  function handleContentPointerEnter(event: PointerEvent) {
329
- if (event.pointerType === 'touch') return;
331
+ // A closed panel is still in the DOM through its exit animation, and a pointer that lands
332
+ // on it then is not reading it: counted, it would hold the next open forever, because the
333
+ // panel leaves the DOM under the pointer and its `pointerleave` never comes.
334
+ if (event.pointerType === 'touch' || !isOpen) return;
330
335
  pointerOnContent = true;
331
336
  stopGapTracking();
332
337
  if (closeTimer !== null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@human-kit/ui",
3
- "version": "1.0.0-beta.9",
3
+ "version": "1.0.0",
4
4
  "description": "Accessible, typed UI components for Svelte 5 — shipped as native ESM with per-component subpath exports so bundlers only include what you import.",
5
5
  "license": "MIT",
6
6
  "author": "Agustin Delgado <agustindariodelgado@gmail.com>",
@@ -178,6 +178,26 @@
178
178
  "svelte": "./dist/radio-group/index.js",
179
179
  "default": "./dist/radio-group/index.js"
180
180
  },
181
+ "./rating": {
182
+ "types": "./dist/rating/index.d.ts",
183
+ "svelte": "./dist/rating/index.js",
184
+ "default": "./dist/rating/index.js"
185
+ },
186
+ "./pin-input": {
187
+ "types": "./dist/pin-input/index.d.ts",
188
+ "svelte": "./dist/pin-input/index.js",
189
+ "default": "./dist/pin-input/index.js"
190
+ },
191
+ "./color-picker": {
192
+ "types": "./dist/color-picker/index.d.ts",
193
+ "svelte": "./dist/color-picker/index.js",
194
+ "default": "./dist/color-picker/index.js"
195
+ },
196
+ "./search-field": {
197
+ "types": "./dist/search-field/index.d.ts",
198
+ "svelte": "./dist/search-field/index.js",
199
+ "default": "./dist/search-field/index.js"
200
+ },
181
201
  "./select": {
182
202
  "types": "./dist/select/index.d.ts",
183
203
  "svelte": "./dist/select/index.js",