@humanspeak/svelte-headless-table 6.0.2 → 6.0.3

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 (76) hide show
  1. package/README.md +2 -2
  2. package/dist/bodyCells.d.ts +116 -0
  3. package/dist/bodyCells.js +80 -0
  4. package/dist/bodyRows.d.ts +92 -0
  5. package/dist/bodyRows.js +55 -0
  6. package/dist/columns.d.ts +204 -0
  7. package/dist/columns.js +120 -0
  8. package/dist/constants.d.ts +4 -0
  9. package/dist/constants.js +4 -0
  10. package/dist/createTable.d.ts +107 -0
  11. package/dist/createTable.js +92 -0
  12. package/dist/createViewModel.d.ts +105 -2
  13. package/dist/createViewModel.js +55 -1
  14. package/dist/headerCells.d.ts +210 -0
  15. package/dist/headerCells.js +151 -0
  16. package/dist/headerRows.d.ts +72 -0
  17. package/dist/headerRows.js +60 -0
  18. package/dist/plugins/addColumnFilters.d.ts +101 -0
  19. package/dist/plugins/addColumnFilters.js +55 -0
  20. package/dist/plugins/addColumnOrder.d.ts +30 -0
  21. package/dist/plugins/addColumnOrder.js +21 -0
  22. package/dist/plugins/addDataExport.d.ts +51 -0
  23. package/dist/plugins/addDataExport.js +30 -0
  24. package/dist/plugins/addExpandedRows.d.ts +41 -2
  25. package/dist/plugins/addExpandedRows.js +24 -0
  26. package/dist/plugins/addFlatten.d.ts +48 -3
  27. package/dist/plugins/addFlatten.js +28 -0
  28. package/dist/plugins/addGridLayout.d.ts +13 -0
  29. package/dist/plugins/addGridLayout.js +13 -0
  30. package/dist/plugins/addGroupBy.d.ts +80 -4
  31. package/dist/plugins/addGroupBy.js +48 -4
  32. package/dist/plugins/addHiddenColumns.d.ts +27 -0
  33. package/dist/plugins/addHiddenColumns.js +19 -0
  34. package/dist/plugins/addPagination.d.ts +54 -0
  35. package/dist/plugins/addPagination.js +29 -0
  36. package/dist/plugins/addResizedColumns.d.ts +58 -4
  37. package/dist/plugins/addResizedColumns.js +33 -0
  38. package/dist/plugins/addSelectedRows.d.ts +58 -2
  39. package/dist/plugins/addSelectedRows.js +42 -0
  40. package/dist/plugins/addSortBy.d.ts +83 -6
  41. package/dist/plugins/addSortBy.js +65 -24
  42. package/dist/plugins/addSubRows.d.ts +39 -1
  43. package/dist/plugins/addSubRows.js +25 -0
  44. package/dist/plugins/addTableFilter.d.ts +87 -3
  45. package/dist/plugins/addTableFilter.js +90 -40
  46. package/dist/tableComponent.d.ts +41 -0
  47. package/dist/tableComponent.js +37 -0
  48. package/dist/types/Action.d.ts +16 -2
  49. package/dist/types/Entries.d.ts +6 -0
  50. package/dist/types/KeyPath.d.ts +20 -0
  51. package/dist/types/Label.d.ts +26 -3
  52. package/dist/types/Matrix.d.ts +6 -0
  53. package/dist/types/TablePlugin.d.ts +140 -10
  54. package/dist/utils/array.d.ts +24 -0
  55. package/dist/utils/array.js +24 -0
  56. package/dist/utils/attributes.d.ts +31 -0
  57. package/dist/utils/attributes.js +31 -0
  58. package/dist/utils/clone.d.ts +19 -0
  59. package/dist/utils/clone.js +13 -0
  60. package/dist/utils/compare.d.ts +29 -0
  61. package/dist/utils/compare.js +29 -0
  62. package/dist/utils/counter.d.ts +12 -0
  63. package/dist/utils/counter.js +12 -0
  64. package/dist/utils/css.d.ts +11 -0
  65. package/dist/utils/css.js +11 -0
  66. package/dist/utils/event.d.ts +14 -0
  67. package/dist/utils/event.js +14 -0
  68. package/dist/utils/filter.d.ts +47 -0
  69. package/dist/utils/filter.js +47 -0
  70. package/dist/utils/math.d.ts +22 -0
  71. package/dist/utils/math.js +22 -0
  72. package/dist/utils/matrix.d.ts +24 -0
  73. package/dist/utils/matrix.js +24 -0
  74. package/dist/utils/store.d.ts +116 -9
  75. package/dist/utils/store.js +63 -0
  76. package/package.json +22 -22
@@ -1,12 +1,31 @@
1
1
  import { finalizeAttributes, mergeAttributes } from './utils/attributes.js';
2
2
  import { derivedKeys } from '@humanspeak/svelte-subscribe';
3
3
  import { derived } from 'svelte/store';
4
+ /**
5
+ * Abstract base class for all table components (rows, cells, etc.).
6
+ * Provides common functionality for state injection, hook application, and attribute merging.
7
+ *
8
+ * @template Item - The type of data items in the table.
9
+ * @template Plugins - The plugins used by the table.
10
+ * @template Key - The component key type (e.g., 'tbody.tr', 'tbody.tr.td').
11
+ */
4
12
  export class TableComponent {
13
+ /** Unique identifier for the component. */
5
14
  id;
15
+ /**
16
+ * Creates a new TableComponent.
17
+ *
18
+ * @param init - Initialization options.
19
+ */
6
20
  constructor({ id }) {
7
21
  this.id = id;
8
22
  }
9
23
  attrsForName = {};
24
+ /**
25
+ * Gets the merged HTML attributes from all applied plugins.
26
+ *
27
+ * @returns A readable store of merged attributes.
28
+ */
10
29
  attrs() {
11
30
  return derived(Object.values(this.attrsForName), ($attrsArray) => {
12
31
  let $mergedAttrs = {};
@@ -17,13 +36,31 @@ export class TableComponent {
17
36
  });
18
37
  }
19
38
  propsForName = {};
39
+ /**
40
+ * Gets the merged props from all applied plugins.
41
+ *
42
+ * @returns A readable store of plugin props keyed by plugin name.
43
+ */
20
44
  props() {
21
45
  return derivedKeys(this.propsForName);
22
46
  }
47
+ /** Reference to the table state, injected after creation. */
23
48
  state;
49
+ /**
50
+ * Injects the table state reference into this component.
51
+ *
52
+ * @param state - The table state to inject.
53
+ */
24
54
  injectState(state) {
25
55
  this.state = state;
26
56
  }
57
+ /**
58
+ * Applies a plugin hook to this component.
59
+ * Hooks can provide both props and attributes.
60
+ *
61
+ * @param pluginName - The name of the plugin.
62
+ * @param hook - The element hook containing props and/or attrs.
63
+ */
27
64
  applyHook(pluginName, hook) {
28
65
  if (hook.props !== undefined) {
29
66
  this.propsForName[pluginName] = hook.props;
@@ -1,5 +1,19 @@
1
+ /**
2
+ * Return type for Svelte actions.
3
+ * Contains optional lifecycle methods for updating and destroying the action.
4
+ *
5
+ * @template Props - The type of props passed to the action.
6
+ */
1
7
  export type ActionReturnType<Props = any> = {
2
- update?: (newProps: Props) => void;
8
+ /** Called when props change. */
9
+ update?: (_newProps: Props) => void;
10
+ /** Called when the element is removed from the DOM. */
3
11
  destroy?: () => void;
4
12
  };
5
- export type Action<Props> = (node: Element, props?: Props) => ActionReturnType<Props> | void;
13
+ /**
14
+ * A Svelte action function that can be applied to DOM elements.
15
+ * Actions receive an element and optional props, returning lifecycle methods.
16
+ *
17
+ * @template Props - The type of props passed to the action.
18
+ */
19
+ export type Action<Props> = (_node: Element, _props?: Props) => ActionReturnType<Props> | void;
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Converts an object type to its entries type (array of [key, value] tuples).
3
+ * Similar to the return type of Object.entries() but with stronger typing.
4
+ *
5
+ * @template Obj - The object type to convert.
6
+ */
1
7
  export type Entries<Obj> = NonNullable<{
2
8
  [K in keyof Obj]: [K, NonNullable<Obj[K]>];
3
9
  }[keyof Obj]>[];
@@ -1,6 +1,26 @@
1
+ /**
2
+ * Generates a union of all valid dot-notation key paths for an object type.
3
+ * Useful for type-safe property access with nested objects.
4
+ *
5
+ * @template T - The object type to extract paths from.
6
+ * @template D - Maximum depth to traverse (default 3 to avoid infinite recursion).
7
+ * @example
8
+ * ```typescript
9
+ * type Person = { name: string; address: { city: string } }
10
+ * type Paths = KeyPath<Person> // 'name' | 'address' | 'address.city'
11
+ * ```
12
+ */
1
13
  export type KeyPath<T, D extends number = 3> = KeyPath_<T, D, []>;
14
+ /**
15
+ * Internal recursive helper for KeyPath.
16
+ * @internal
17
+ */
2
18
  type KeyPath_<T, D extends number, S extends unknown[]> = D extends S['length'] ? never : T extends object ? {
3
19
  [K in keyof T]-?: K extends string ? `${K}` | Join<K, KeyPath_<T[K], D, [never, ...S]>> : K extends number ? `[${K}]` | Join<`[${K}]`, KeyPath_<T[K], D, [never, ...S]>> : never;
4
20
  }[keyof T] : '';
21
+ /**
22
+ * Internal helper for joining path segments with dots.
23
+ * @internal
24
+ */
5
25
  type Join<K, P> = K extends string | number ? P extends string | number ? P extends `[${string}` ? `${K}${P}` : `${K}${'' extends P ? '' : '.'}${P}` : never : never;
6
26
  export {};
@@ -3,6 +3,29 @@ import type { DataBodyCell, DisplayBodyCell } from '../bodyCells.js';
3
3
  import type { TableState } from '../createViewModel.js';
4
4
  import type { HeaderCell } from '../headerCells.js';
5
5
  import type { AnyPlugins } from './TablePlugin.js';
6
- export type DataLabel<Item, Plugins extends AnyPlugins = AnyPlugins, Value = any> = (cell: DataBodyCell<Item, AnyPlugins, Value>, state: TableState<Item, Plugins>) => RenderConfig;
7
- export type DisplayLabel<Item, Plugins extends AnyPlugins = AnyPlugins> = (cell: DisplayBodyCell<Item>, state: TableState<Item, Plugins>) => RenderConfig;
8
- export type HeaderLabel<Item, Plugins extends AnyPlugins = AnyPlugins> = RenderConfig | ((cell: HeaderCell<Item, Plugins>, state: TableState<Item, Plugins>) => RenderConfig);
6
+ /**
7
+ * A render function for data body cells.
8
+ * Receives the cell and table state, returns content to render.
9
+ *
10
+ * @template Item - The type of data items in the table.
11
+ * @template Plugins - The plugins used by the table.
12
+ * @template Value - The type of the cell value.
13
+ */
14
+ export type DataLabel<Item, Plugins extends AnyPlugins = AnyPlugins, Value = any> = (_cell: DataBodyCell<Item, AnyPlugins, Value>, _state: TableState<Item, Plugins>) => RenderConfig;
15
+ /**
16
+ * A render function for display body cells.
17
+ * Receives the cell and table state, returns content to render.
18
+ *
19
+ * @template Item - The type of data items in the table.
20
+ * @template Plugins - The plugins used by the table.
21
+ */
22
+ export type DisplayLabel<Item, Plugins extends AnyPlugins = AnyPlugins> = (_cell: DisplayBodyCell<Item>, _state: TableState<Item, Plugins>) => RenderConfig;
23
+ /**
24
+ * A label for header cells. Can be static content or a render function.
25
+ * If the function type is removed from the union, generics will not be
26
+ * inferred for subtypes.
27
+ *
28
+ * @template Item - The type of data items in the table.
29
+ * @template Plugins - The plugins used by the table.
30
+ */
31
+ export type HeaderLabel<Item, Plugins extends AnyPlugins = AnyPlugins> = RenderConfig | ((_cell: HeaderCell<Item, Plugins>, _state: TableState<Item, Plugins>) => RenderConfig);
@@ -1 +1,7 @@
1
+ /**
2
+ * A two-dimensional array (matrix) type.
3
+ * Used for header row/column matrices and other grid-like structures.
4
+ *
5
+ * @template T - The type of elements in the matrix.
6
+ */
1
7
  export type Matrix<T> = T[][];
@@ -5,12 +5,41 @@ import type { DataColumn, FlatColumn } from '../columns.js';
5
5
  import type { PluginInitTableState, TableAttributes, TableBodyAttributes, TableHeadAttributes } from '../createViewModel.js';
6
6
  import type { HeaderCell, HeaderCellAttributes } from '../headerCells.js';
7
7
  import type { HeaderRow, HeaderRowAttributes } from '../headerRows.js';
8
- export type TablePlugin<Item, PluginState, ColumnOptions, TablePropSet extends AnyTablePropSet = AnyTablePropSet, TableAttributeSet extends AnyTableAttributeSet = AnyTableAttributeSet> = (init: TablePluginInit<Item, ColumnOptions>) => TablePluginInstance<Item, PluginState, ColumnOptions, TablePropSet, TableAttributeSet>;
8
+ /**
9
+ * A table plugin factory function.
10
+ * Receives initialization options and returns a plugin instance.
11
+ *
12
+ * @template Item - The type of data items in the table.
13
+ * @template PluginState - The state exposed by the plugin.
14
+ * @template ColumnOptions - Per-column configuration options.
15
+ * @template TablePropSet - Props added to table components.
16
+ * @template TableAttributeSet - Attributes added to table components.
17
+ */
18
+ export type TablePlugin<Item, PluginState, ColumnOptions, TablePropSet extends AnyTablePropSet = AnyTablePropSet, TableAttributeSet extends AnyTableAttributeSet = AnyTableAttributeSet> = (_init: TablePluginInit<Item, ColumnOptions>) => TablePluginInstance<Item, PluginState, ColumnOptions, TablePropSet, TableAttributeSet>;
19
+ /**
20
+ * Initialization options passed to a table plugin.
21
+ *
22
+ * @template Item - The type of data items in the table.
23
+ * @template ColumnOptions - Per-column configuration options.
24
+ */
9
25
  export type TablePluginInit<Item, ColumnOptions> = {
26
+ /** The name/key of this plugin in the plugins object. */
10
27
  pluginName: string;
28
+ /** The table state during plugin initialization. */
11
29
  tableState: PluginInitTableState<Item>;
30
+ /** Column options keyed by column ID. */
12
31
  columnOptions: Record<string, ColumnOptions>;
13
32
  };
33
+ /**
34
+ * A plugin instance returned by a TablePlugin factory.
35
+ * Contains state, transformation functions, and component hooks.
36
+ *
37
+ * @template Item - The type of data items in the table.
38
+ * @template PluginState - The state exposed by the plugin.
39
+ * @template ColumnOptions - Per-column configuration options.
40
+ * @template TablePropSet - Props added to table components.
41
+ * @template TableAttributeSet - Attributes added to table components.
42
+ */
14
43
  export type TablePluginInstance<Item, PluginState, ColumnOptions, TablePropSet extends AnyTablePropSet = AnyTablePropSet, TableAttributeSet extends AnyTableAttributeSet = AnyTableAttributeSet> = {
15
44
  pluginState: PluginState;
16
45
  transformFlatColumnsFn?: Readable<TransformFlatColumnsFn<Item>>;
@@ -23,65 +52,166 @@ export type TablePluginInstance<Item, PluginState, ColumnOptions, TablePropSet e
23
52
  columnOptions?: ColumnOptions;
24
53
  hooks?: TableHooks<Item, TablePropSet, TableAttributeSet>;
25
54
  };
55
+ /**
56
+ * A record of table plugins, keyed by plugin name.
57
+ * Used as a type constraint for the plugins parameter.
58
+ */
26
59
  export type AnyPlugins = Record<any, TablePlugin<any, any, any, any, any>>;
60
+ /**
61
+ * A record of plugin instances, keyed by plugin name.
62
+ * Used internally after plugins are initialized.
63
+ */
27
64
  export type AnyPluginInstances = Record<any, TablePluginInstance<any, any, any, any, any>>;
28
- export type TransformFlatColumnsFn<Item> = (flatColumns: DataColumn<Item>[]) => DataColumn<Item>[];
29
- export type DeriveFlatColumnsFn<Item> = <Col extends FlatColumn<Item>>(flatColumns: Readable<Col[]>) => Readable<Col[]>;
30
- export type DeriveRowsFn<Item> = <Row extends BodyRow<Item>>(rows: Readable<Row[]>) => Readable<Row[]>;
31
- export type DeriveFn<T> = (obj: Readable<T>) => Readable<T>;
65
+ /**
66
+ * A synchronous function that transforms flat columns.
67
+ *
68
+ * @template Item - The type of data items in the table.
69
+ */
70
+ export type TransformFlatColumnsFn<Item> = (_flatColumns: DataColumn<Item>[]) => DataColumn<Item>[];
71
+ /**
72
+ * A reactive function that derives flat columns from a store.
73
+ *
74
+ * @template Item - The type of data items in the table.
75
+ */
76
+ export type DeriveFlatColumnsFn<Item> = <Col extends FlatColumn<Item>>(_flatColumns: Readable<Col[]>) => Readable<Col[]>;
77
+ /**
78
+ * A reactive function that derives rows from a store.
79
+ *
80
+ * @template Item - The type of data items in the table.
81
+ */
82
+ export type DeriveRowsFn<Item> = <Row extends BodyRow<Item>>(_rows: Readable<Row[]>) => Readable<Row[]>;
83
+ /**
84
+ * A generic reactive derivation function.
85
+ *
86
+ * @template T - The type being derived.
87
+ */
88
+ export type DeriveFn<T> = (_obj: Readable<T>) => Readable<T>;
89
+ /**
90
+ * Maps component keys to their corresponding component types.
91
+ *
92
+ * @template Item - The type of data items in the table.
93
+ * @template Plugins - The plugins used by the table.
94
+ */
32
95
  export type Components<Item, Plugins extends AnyPlugins = AnyPlugins> = {
33
96
  'thead.tr': HeaderRow<Item, Plugins>;
34
97
  'thead.tr.th': HeaderCell<Item, Plugins>;
35
98
  'tbody.tr': BodyRow<Item, Plugins>;
36
99
  'tbody.tr.td': BodyCell<Item, Plugins>;
37
100
  };
101
+ /**
102
+ * Maps component keys to their corresponding attribute types.
103
+ *
104
+ * @template Item - The type of data items in the table.
105
+ * @template Plugins - The plugins used by the table.
106
+ */
38
107
  export type AttributesForKey<Item, Plugins extends AnyPlugins = AnyPlugins> = {
39
108
  'thead.tr': HeaderRowAttributes<Item, Plugins>;
40
109
  'thead.tr.th': HeaderCellAttributes<Item, Plugins>;
41
110
  'tbody.tr': BodyRowAttributes<Item, Plugins>;
42
111
  'tbody.tr.td': BodyCellAttributes<Item, Plugins>;
43
112
  };
113
+ /**
114
+ * Valid keys for table components: header rows, header cells, body rows, body cells.
115
+ */
44
116
  export type ComponentKeys = keyof Components<unknown>;
45
117
  type TablePropSet<PropSet extends {
46
- [K in ComponentKeys]?: unknown;
118
+ [_K in ComponentKeys]?: unknown;
47
119
  }> = {
48
120
  [K in ComponentKeys]: PropSet[K];
49
121
  };
122
+ /**
123
+ * Creates a new table prop set type, filtering out undefined component props.
124
+ *
125
+ * @template PropSet - The prop set definition.
126
+ */
50
127
  export type NewTablePropSet<PropSet extends {
51
- [K in ComponentKeys]?: unknown;
128
+ [_K in ComponentKeys]?: unknown;
52
129
  }> = {
53
130
  [K in ComponentKeys]: unknown extends PropSet[K] ? never : PropSet[K];
54
131
  };
132
+ /**
133
+ * A table prop set with any types. Used as a type constraint.
134
+ */
55
135
  export type AnyTablePropSet = TablePropSet<any>;
136
+ /**
137
+ * Internal type for mapping component keys to attribute sets.
138
+ * @internal
139
+ */
56
140
  type TableAttributeSet<AttributeSet extends {
57
- [K in ComponentKeys]?: unknown;
141
+ [_K in ComponentKeys]?: unknown;
58
142
  }> = {
59
143
  [K in ComponentKeys]: AttributeSet[K];
60
144
  };
145
+ /**
146
+ * Creates a new table attribute set type, filtering out undefined component attributes.
147
+ *
148
+ * @template AttributeSet - The attribute set definition.
149
+ */
61
150
  export type NewTableAttributeSet<AttributeSet extends {
62
- [K in ComponentKeys]?: unknown;
151
+ [_K in ComponentKeys]?: unknown;
63
152
  }> = {
64
153
  [K in ComponentKeys]: unknown extends AttributeSet[K] ? never : AttributeSet[K];
65
154
  };
155
+ /**
156
+ * A table attribute set with any types. Used as a type constraint.
157
+ */
66
158
  export type AnyTableAttributeSet = TableAttributeSet<any>;
159
+ /**
160
+ * Hooks for attaching props and attributes to table components.
161
+ * Each hook receives a component and returns props/attrs stores.
162
+ *
163
+ * @template Item - The type of data items in the table.
164
+ * @template PropSet - The prop set type.
165
+ * @template AttributeSet - The attribute set type.
166
+ */
67
167
  export type TableHooks<Item, PropSet extends AnyTablePropSet = AnyTablePropSet, AttributeSet extends AnyTableAttributeSet = AnyTableAttributeSet> = {
68
- [ComponentKey in keyof Components<Item>]?: (component: Components<Item>[ComponentKey]) => ElementHook<PropSet[ComponentKey], AttributeSet[ComponentKey]>;
168
+ [ComponentKey in keyof Components<Item>]?: (_component: Components<Item>[ComponentKey]) => ElementHook<PropSet[ComponentKey], AttributeSet[ComponentKey]>;
69
169
  };
170
+ /**
171
+ * Return type for component hooks.
172
+ * Contains optional readable stores for props and attributes.
173
+ *
174
+ * @template Props - The props type.
175
+ * @template Attributes - The attributes type.
176
+ */
70
177
  export type ElementHook<Props, Attributes> = {
178
+ /** Reactive props store. */
71
179
  props?: Readable<Props>;
180
+ /** Reactive attributes store. */
72
181
  attrs?: Readable<Attributes>;
73
182
  };
183
+ /**
184
+ * Extracts the plugin state types from a plugins record.
185
+ *
186
+ * @template Plugins - The plugins record type.
187
+ */
74
188
  export type PluginStates<Plugins extends AnyPlugins> = {
75
189
  [K in keyof Plugins]: ReturnType<Plugins[K]>['pluginState'];
76
190
  };
191
+ /**
192
+ * Internal type for extracting prop sets from plugins.
193
+ * @internal
194
+ */
77
195
  type TablePropSetForPluginKey<Plugins extends AnyPlugins> = {
78
196
  [K in keyof Plugins]: Plugins[K] extends TablePlugin<any, any, any, infer TablePropSet> ? TablePropSet : never;
79
197
  };
198
+ /**
199
+ * Combines prop sets from all plugins into a single type.
200
+ * Props are grouped by component key, then by plugin key.
201
+ *
202
+ * @template Plugins - The plugins record type.
203
+ */
80
204
  export type PluginTablePropSet<Plugins extends AnyPlugins> = {
81
205
  [ComponentKey in ComponentKeys]: {
82
206
  [PluginKey in keyof Plugins]: TablePropSetForPluginKey<Plugins>[PluginKey][ComponentKey];
83
207
  };
84
208
  };
209
+ /**
210
+ * Extracts column configuration types from all plugins.
211
+ * Used to type the `plugins` option in column definitions.
212
+ *
213
+ * @template Plugins - The plugins record type.
214
+ */
85
215
  export type PluginColumnConfigs<Plugins extends AnyPlugins> = Partial<{
86
216
  [K in keyof Plugins]: ReturnType<Plugins[K]>['columnOptions'];
87
217
  }>;
@@ -1,2 +1,26 @@
1
+ /**
2
+ * Returns an array containing only the distinct elements from the input array.
3
+ * Preserves the order of first occurrence.
4
+ *
5
+ * @template T - The type of elements in the array.
6
+ * @param items - The input array potentially containing duplicates.
7
+ * @returns A new array with duplicate elements removed.
8
+ * @example
9
+ * ```typescript
10
+ * getDistinct([1, 2, 2, 3, 1]) // Returns [1, 2, 3]
11
+ * ```
12
+ */
1
13
  export declare const getDistinct: <T>(items: T[]) => T[];
14
+ /**
15
+ * Returns an array containing only the elements that appear more than once
16
+ * in the input array.
17
+ *
18
+ * @template T - The type of elements in the array.
19
+ * @param items - The input array to check for duplicates.
20
+ * @returns A new array containing only duplicate elements.
21
+ * @example
22
+ * ```typescript
23
+ * getDuplicates([1, 2, 2, 3, 1]) // Returns [1, 2]
24
+ * ```
25
+ */
2
26
  export declare const getDuplicates: <T>(items: T[]) => T[];
@@ -1,7 +1,31 @@
1
1
  import { getCounter } from './counter.js';
2
+ /**
3
+ * Returns an array containing only the distinct elements from the input array.
4
+ * Preserves the order of first occurrence.
5
+ *
6
+ * @template T - The type of elements in the array.
7
+ * @param items - The input array potentially containing duplicates.
8
+ * @returns A new array with duplicate elements removed.
9
+ * @example
10
+ * ```typescript
11
+ * getDistinct([1, 2, 2, 3, 1]) // Returns [1, 2, 3]
12
+ * ```
13
+ */
2
14
  export const getDistinct = (items) => {
3
15
  return Array.from(getCounter(items).keys());
4
16
  };
17
+ /**
18
+ * Returns an array containing only the elements that appear more than once
19
+ * in the input array.
20
+ *
21
+ * @template T - The type of elements in the array.
22
+ * @param items - The input array to check for duplicates.
23
+ * @returns A new array containing only duplicate elements.
24
+ * @example
25
+ * ```typescript
26
+ * getDuplicates([1, 2, 2, 3, 1]) // Returns [1, 2]
27
+ * ```
28
+ */
5
29
  export const getDuplicates = (items) => {
6
30
  return Array.from(getCounter(items).entries())
7
31
  .filter(([, count]) => count !== 1)
@@ -1,2 +1,33 @@
1
+ /**
2
+ * Merges two attribute objects, with special handling for style properties.
3
+ * Style objects are deeply merged rather than overwritten.
4
+ *
5
+ * @template T - The type of the first attributes object.
6
+ * @template U - The type of the second attributes object.
7
+ * @param a - The first attributes object.
8
+ * @param b - The second attributes object (takes precedence for non-style properties).
9
+ * @returns A merged attributes object with combined styles.
10
+ * @example
11
+ * ```typescript
12
+ * mergeAttributes(
13
+ * { class: 'foo', style: { color: 'red' } },
14
+ * { class: 'bar', style: { fontSize: '14px' } }
15
+ * )
16
+ * // Returns { class: 'bar', style: { color: 'red', fontSize: '14px' } }
17
+ * ```
18
+ */
1
19
  export declare const mergeAttributes: <T extends Record<string, unknown>, U extends Record<string, unknown>>(a: T, b: U) => T & U;
20
+ /**
21
+ * Converts an attributes object's style property from an object to a CSS string.
22
+ * This prepares attributes for use in DOM elements.
23
+ *
24
+ * @template T - The type of the attributes object.
25
+ * @param attrs - The attributes object with a potential style object.
26
+ * @returns A new attributes object with the style converted to a string.
27
+ * @example
28
+ * ```typescript
29
+ * finalizeAttributes({ class: 'foo', style: { color: 'red' } })
30
+ * // Returns { class: 'foo', style: 'color:red' }
31
+ * ```
32
+ */
2
33
  export declare const finalizeAttributes: <T extends Record<string, unknown>>(attrs: T) => Record<string, unknown>;
@@ -1,4 +1,22 @@
1
1
  import { stringifyCss } from './css.js';
2
+ /**
3
+ * Merges two attribute objects, with special handling for style properties.
4
+ * Style objects are deeply merged rather than overwritten.
5
+ *
6
+ * @template T - The type of the first attributes object.
7
+ * @template U - The type of the second attributes object.
8
+ * @param a - The first attributes object.
9
+ * @param b - The second attributes object (takes precedence for non-style properties).
10
+ * @returns A merged attributes object with combined styles.
11
+ * @example
12
+ * ```typescript
13
+ * mergeAttributes(
14
+ * { class: 'foo', style: { color: 'red' } },
15
+ * { class: 'bar', style: { fontSize: '14px' } }
16
+ * )
17
+ * // Returns { class: 'bar', style: { color: 'red', fontSize: '14px' } }
18
+ * ```
19
+ */
2
20
  export const mergeAttributes = (a, b) => {
3
21
  if (a.style === undefined && b.style === undefined) {
4
22
  return { ...a, ...b };
@@ -12,6 +30,19 @@ export const mergeAttributes = (a, b) => {
12
30
  }
13
31
  };
14
32
  };
33
+ /**
34
+ * Converts an attributes object's style property from an object to a CSS string.
35
+ * This prepares attributes for use in DOM elements.
36
+ *
37
+ * @template T - The type of the attributes object.
38
+ * @param attrs - The attributes object with a potential style object.
39
+ * @returns A new attributes object with the style converted to a string.
40
+ * @example
41
+ * ```typescript
42
+ * finalizeAttributes({ class: 'foo', style: { color: 'red' } })
43
+ * // Returns { class: 'foo', style: 'color:red' }
44
+ * ```
45
+ */
15
46
  export const finalizeAttributes = (attrs) => {
16
47
  if (attrs.style === undefined || typeof attrs.style !== 'object') {
17
48
  return attrs;
@@ -1,6 +1,25 @@
1
+ /**
2
+ * Interface for objects that can create a copy of themselves.
3
+ *
4
+ * @template T - The type of the cloned object.
5
+ */
1
6
  export interface Clonable<T> {
7
+ /** Creates and returns a copy of the object. */
2
8
  clone(): T;
3
9
  }
10
+ /**
11
+ * Type guard that checks if an object implements the Clonable interface.
12
+ *
13
+ * @template T - The expected type of the cloned object.
14
+ * @param obj - The object to check.
15
+ * @returns True if the object has a clone method.
16
+ * @example
17
+ * ```typescript
18
+ * if (isClonable(obj)) {
19
+ * const copy = obj.clone()
20
+ * }
21
+ * ```
22
+ */
4
23
  export declare const isClonable: <T>(obj: unknown) => obj is Clonable<T>;
5
24
  /**
6
25
  * Create a new instance of a class instance with all properties shallow
@@ -1,3 +1,16 @@
1
+ /**
2
+ * Type guard that checks if an object implements the Clonable interface.
3
+ *
4
+ * @template T - The expected type of the cloned object.
5
+ * @param obj - The object to check.
6
+ * @returns True if the object has a clone method.
7
+ * @example
8
+ * ```typescript
9
+ * if (isClonable(obj)) {
10
+ * const copy = obj.clone()
11
+ * }
12
+ * ```
13
+ */
1
14
  export const isClonable = (obj) => {
2
15
  return typeof obj.clone === 'function';
3
16
  };
@@ -1,2 +1,31 @@
1
+ /**
2
+ * Compares two values or arrays for sorting purposes.
3
+ * Returns a negative number if a < b, positive if a > b, and 0 if equal.
4
+ *
5
+ * @template T - The type of elements being compared (string or number).
6
+ * @param a - The first value or array to compare.
7
+ * @param b - The second value or array to compare.
8
+ * @returns A number indicating the sort order.
9
+ * @example
10
+ * ```typescript
11
+ * compare(1, 2) // Returns -1
12
+ * compare('b', 'a') // Returns 1
13
+ * compare([1, 2], [1, 3]) // Returns -1
14
+ * ```
15
+ */
1
16
  export declare const compare: <T extends string | number>(a: T | T[], b: T | T[]) => number;
17
+ /**
18
+ * Compares two arrays element by element for sorting purposes.
19
+ * Comparison stops at the first non-equal element.
20
+ *
21
+ * @template T - The type of elements in the arrays (string or number).
22
+ * @param a - The first array to compare.
23
+ * @param b - The second array to compare.
24
+ * @returns A number indicating the sort order based on the first differing element.
25
+ * @example
26
+ * ```typescript
27
+ * compareArray([1, 2, 3], [1, 2, 4]) // Returns -1
28
+ * compareArray(['a', 'b'], ['a', 'a']) // Returns 1
29
+ * ```
30
+ */
2
31
  export declare const compareArray: <T extends string | number>(a: T[], b: T[]) => number;
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Compares two values or arrays for sorting purposes.
3
+ * Returns a negative number if a < b, positive if a > b, and 0 if equal.
4
+ *
5
+ * @template T - The type of elements being compared (string or number).
6
+ * @param a - The first value or array to compare.
7
+ * @param b - The second value or array to compare.
8
+ * @returns A number indicating the sort order.
9
+ * @example
10
+ * ```typescript
11
+ * compare(1, 2) // Returns -1
12
+ * compare('b', 'a') // Returns 1
13
+ * compare([1, 2], [1, 3]) // Returns -1
14
+ * ```
15
+ */
1
16
  export const compare = (a, b) => {
2
17
  if (Array.isArray(a) && Array.isArray(b)) {
3
18
  return compareArray(a, b);
@@ -6,6 +21,20 @@ export const compare = (a, b) => {
6
21
  return a - b;
7
22
  return a < b ? -1 : a > b ? 1 : 0;
8
23
  };
24
+ /**
25
+ * Compares two arrays element by element for sorting purposes.
26
+ * Comparison stops at the first non-equal element.
27
+ *
28
+ * @template T - The type of elements in the arrays (string or number).
29
+ * @param a - The first array to compare.
30
+ * @param b - The second array to compare.
31
+ * @returns A number indicating the sort order based on the first differing element.
32
+ * @example
33
+ * ```typescript
34
+ * compareArray([1, 2, 3], [1, 2, 4]) // Returns -1
35
+ * compareArray(['a', 'b'], ['a', 'a']) // Returns 1
36
+ * ```
37
+ */
9
38
  export const compareArray = (a, b) => {
10
39
  const minLength = Math.min(a.length, b.length);
11
40
  for (let i = 0; i < minLength; i++) {
@@ -1 +1,13 @@
1
+ /**
2
+ * Creates a Map that counts the occurrences of each element in an array.
3
+ *
4
+ * @template T - The type of elements in the array.
5
+ * @param items - The array of items to count.
6
+ * @returns A Map where keys are unique items and values are their occurrence counts.
7
+ * @example
8
+ * ```typescript
9
+ * getCounter(['a', 'b', 'a', 'c', 'a'])
10
+ * // Returns Map { 'a' => 3, 'b' => 1, 'c' => 1 }
11
+ * ```
12
+ */
1
13
  export declare const getCounter: <T>(items: T[]) => Map<T, number>;
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Creates a Map that counts the occurrences of each element in an array.
3
+ *
4
+ * @template T - The type of elements in the array.
5
+ * @param items - The array of items to count.
6
+ * @returns A Map where keys are unique items and values are their occurrence counts.
7
+ * @example
8
+ * ```typescript
9
+ * getCounter(['a', 'b', 'a', 'c', 'a'])
10
+ * // Returns Map { 'a' => 3, 'b' => 1, 'c' => 1 }
11
+ * ```
12
+ */
1
13
  export const getCounter = (items) => {
2
14
  const result = new Map();
3
15
  items.forEach((item) => {