typetify 2.2.0 → 4.0.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 +102 -0
- package/README.md +123 -1
- package/dist/chunk-2YRFWQ6M.mjs +1 -0
- package/dist/chunk-35CB7HNN.js +1 -0
- package/dist/chunk-6WGRWYAD.js +1 -0
- package/dist/chunk-7UMXGQE4.mjs +1 -0
- package/dist/chunk-7XHBEA63.js +1 -0
- package/dist/chunk-BLUG7TSP.js +1 -0
- package/dist/chunk-C5X2N4X4.js +2 -0
- package/dist/chunk-CX7GJR55.js +1 -0
- package/dist/chunk-F76ECQKE.js +1 -0
- package/dist/chunk-FHCBXSNA.js +1 -0
- package/dist/chunk-GQIJLGEZ.mjs +1 -0
- package/dist/chunk-H7MLD632.mjs +2 -0
- package/dist/chunk-MB77QAOC.mjs +1 -0
- package/dist/chunk-MCQFAXUX.mjs +1 -0
- package/dist/chunk-RCSO5S56.js +2 -0
- package/dist/chunk-U6XM3X5N.mjs +2 -0
- package/dist/chunk-U7MK5AR5.mjs +1 -0
- package/dist/chunk-WWU7P2L2.mjs +1 -0
- package/dist/chunk-X6JSYVIW.mjs +1 -0
- package/dist/chunk-XKTDG6LH.js +1 -0
- package/dist/collection/index.d.mts +125 -1
- package/dist/collection/index.d.ts +125 -1
- package/dist/collection/index.js +1 -1
- package/dist/collection/index.mjs +1 -1
- package/dist/color/index.d.mts +274 -0
- package/dist/color/index.d.ts +274 -0
- package/dist/color/index.js +1 -0
- package/dist/color/index.mjs +1 -0
- package/dist/datetime/index.d.mts +320 -0
- package/dist/datetime/index.d.ts +320 -0
- package/dist/datetime/index.js +1 -0
- package/dist/datetime/index.mjs +1 -0
- package/dist/dom/index.d.mts +353 -0
- package/dist/dom/index.d.ts +353 -0
- package/dist/dom/index.js +1 -0
- package/dist/dom/index.mjs +1 -0
- package/dist/encrypt/index.d.mts +208 -0
- package/dist/encrypt/index.d.ts +208 -0
- package/dist/encrypt/index.js +1 -0
- package/dist/encrypt/index.mjs +1 -0
- package/dist/http/index.d.mts +301 -0
- package/dist/http/index.d.ts +301 -0
- package/dist/http/index.js +1 -0
- package/dist/http/index.mjs +1 -0
- package/dist/index.d.mts +591 -413
- package/dist/index.d.ts +591 -413
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/object/index.d.mts +137 -1
- package/dist/object/index.d.ts +137 -1
- package/dist/object/index.js +1 -1
- package/dist/object/index.mjs +1 -1
- package/dist/path/index.d.mts +178 -0
- package/dist/path/index.d.ts +178 -0
- package/dist/path/index.js +1 -0
- package/dist/path/index.mjs +1 -0
- package/dist/storage/index.d.mts +197 -0
- package/dist/storage/index.d.ts +197 -0
- package/dist/storage/index.js +1 -0
- package/dist/storage/index.mjs +1 -0
- package/dist/string/index.d.mts +201 -1
- package/dist/string/index.d.ts +201 -1
- package/dist/string/index.js +1 -1
- package/dist/string/index.mjs +1 -1
- package/package.json +36 -1
- package/dist/chunk-4HQERWI6.mjs +0 -1
- package/dist/chunk-5LWNMYHB.js +0 -1
- package/dist/chunk-7V3EDYJD.mjs +0 -1
- package/dist/chunk-FYQNKDT3.mjs +0 -1
- package/dist/chunk-MSOFO6QN.js +0 -1
- package/dist/chunk-WQPSXQT5.js +0 -1
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-safe querySelector that returns the correct element type.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* // Get a button with proper typing
|
|
6
|
+
* const button = querySelector<HTMLButtonElement>('#submit');
|
|
7
|
+
* if (button) {
|
|
8
|
+
* button.disabled = true;
|
|
9
|
+
* }
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Get an input element
|
|
13
|
+
* const input = querySelector<HTMLInputElement>('input[name="email"]');
|
|
14
|
+
* if (input) {
|
|
15
|
+
* console.log(input.value);
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Returns null if not found
|
|
20
|
+
* const missing = querySelector('#nonexistent');
|
|
21
|
+
* // => null
|
|
22
|
+
*/
|
|
23
|
+
declare function querySelector<T extends Element = Element>(selector: string, parent?: Document | Element): T | null;
|
|
24
|
+
/**
|
|
25
|
+
* Type-safe querySelectorAll that returns an array of elements.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Get all buttons
|
|
29
|
+
* const buttons = querySelectorAll<HTMLButtonElement>('button');
|
|
30
|
+
* buttons.forEach(btn => btn.disabled = true);
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Get all list items
|
|
34
|
+
* const items = querySelectorAll<HTMLLIElement>('ul > li');
|
|
35
|
+
* console.log(items.length);
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Search within a specific element
|
|
39
|
+
* const container = querySelector('#container');
|
|
40
|
+
* if (container) {
|
|
41
|
+
* const links = querySelectorAll<HTMLAnchorElement>('a', container);
|
|
42
|
+
* }
|
|
43
|
+
*/
|
|
44
|
+
declare function querySelectorAll<T extends Element = Element>(selector: string, parent?: Document | Element): T[];
|
|
45
|
+
|
|
46
|
+
type ClassValue = string | number | boolean | undefined | null | ClassValue[] | Record<string, boolean | undefined | null>;
|
|
47
|
+
/**
|
|
48
|
+
* Combines class names conditionally (like clsx/classnames).
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // Simple strings
|
|
52
|
+
* classNames('btn', 'btn-primary');
|
|
53
|
+
* // => 'btn btn-primary'
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* // Conditional classes
|
|
57
|
+
* classNames('btn', { 'btn-primary': isPrimary, 'btn-disabled': disabled });
|
|
58
|
+
* // => 'btn btn-primary' (if isPrimary=true, disabled=false)
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* // Mixed with arrays
|
|
62
|
+
* classNames('btn', ['btn-lg', disabled && 'btn-disabled']);
|
|
63
|
+
* // => 'btn btn-lg btn-disabled' (if disabled=true)
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* // Real-world React example
|
|
67
|
+
* function Button({ variant, disabled, className }: ButtonProps) {
|
|
68
|
+
* return (
|
|
69
|
+
* <button
|
|
70
|
+
* className={classNames(
|
|
71
|
+
* 'btn',
|
|
72
|
+
* `btn-${variant}`,
|
|
73
|
+
* { 'btn-disabled': disabled },
|
|
74
|
+
* className
|
|
75
|
+
* )}
|
|
76
|
+
* />
|
|
77
|
+
* );
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* // Falsy values are ignored
|
|
82
|
+
* classNames('btn', null, undefined, false, '', 'active');
|
|
83
|
+
* // => 'btn active'
|
|
84
|
+
*/
|
|
85
|
+
declare function classNames(...classes: ClassValue[]): string;
|
|
86
|
+
/**
|
|
87
|
+
* Adds a class to an element.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* const button = querySelector('#submit');
|
|
91
|
+
* addClass(button, 'active');
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* // Add multiple classes
|
|
95
|
+
* addClass(element, 'btn', 'btn-primary', 'btn-lg');
|
|
96
|
+
*/
|
|
97
|
+
declare function addClass(element: Element | null, ...classes: string[]): void;
|
|
98
|
+
/**
|
|
99
|
+
* Removes a class from an element.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* removeClass(button, 'active');
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* // Remove multiple classes
|
|
106
|
+
* removeClass(element, 'btn-primary', 'btn-lg');
|
|
107
|
+
*/
|
|
108
|
+
declare function removeClass(element: Element | null, ...classes: string[]): void;
|
|
109
|
+
/**
|
|
110
|
+
* Toggles a class on an element.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* // Toggle a class
|
|
114
|
+
* toggleClass(button, 'active');
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* // Force add or remove
|
|
118
|
+
* toggleClass(button, 'active', true); // Always add
|
|
119
|
+
* toggleClass(button, 'active', false); // Always remove
|
|
120
|
+
*/
|
|
121
|
+
declare function toggleClass(element: Element | null, className: string, force?: boolean): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Checks if an element has a class.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* if (hasClass(button, 'active')) {
|
|
127
|
+
* console.log('Button is active');
|
|
128
|
+
* }
|
|
129
|
+
*/
|
|
130
|
+
declare function hasClass(element: Element | null, className: string): boolean;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Adds an event listener with automatic cleanup.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* // Basic usage
|
|
137
|
+
* const cleanup = addEventListener(button, 'click', () => {
|
|
138
|
+
* console.log('Clicked!');
|
|
139
|
+
* });
|
|
140
|
+
* // Later: cleanup();
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* // With options
|
|
144
|
+
* addEventListener(window, 'scroll', handleScroll, { passive: true });
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* // Multiple events
|
|
148
|
+
* const cleanups = [
|
|
149
|
+
* addEventListener(input, 'focus', handleFocus),
|
|
150
|
+
* addEventListener(input, 'blur', handleBlur)
|
|
151
|
+
* ];
|
|
152
|
+
* // Cleanup all: cleanups.forEach(fn => fn());
|
|
153
|
+
*/
|
|
154
|
+
declare function addEventListener<K extends keyof HTMLElementEventMap>(element: HTMLElement | Window | Document | null, event: K, handler: (event: HTMLElementEventMap[K]) => void, options?: AddEventListenerOptions): () => void;
|
|
155
|
+
/**
|
|
156
|
+
* Adds an event listener that fires only once.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* // Listen for one click
|
|
160
|
+
* once(button, 'click', () => {
|
|
161
|
+
* console.log('Clicked once!');
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* // Wait for image load
|
|
166
|
+
* once(image, 'load', () => {
|
|
167
|
+
* console.log('Image loaded');
|
|
168
|
+
* });
|
|
169
|
+
*/
|
|
170
|
+
declare function once<K extends keyof HTMLElementEventMap>(element: HTMLElement | Window | Document | null, event: K, handler: (event: HTMLElementEventMap[K]) => void): () => void;
|
|
171
|
+
/**
|
|
172
|
+
* Event delegation - attach handler to parent that fires for matching children.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* // Handle clicks on any button inside container
|
|
176
|
+
* delegate(container, 'button', 'click', (event, target) => {
|
|
177
|
+
* console.log('Button clicked:', target);
|
|
178
|
+
* });
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* // Handle dynamic list items
|
|
182
|
+
* delegate(list, '.item', 'click', (event, item) => {
|
|
183
|
+
* item.classList.toggle('selected');
|
|
184
|
+
* });
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* // Works with dynamically added elements
|
|
188
|
+
* const cleanup = delegate(document.body, '[data-action]', 'click', (e, el) => {
|
|
189
|
+
* const action = el.getAttribute('data-action');
|
|
190
|
+
* handleAction(action);
|
|
191
|
+
* });
|
|
192
|
+
*/
|
|
193
|
+
declare function delegate<T extends HTMLElement = HTMLElement>(parent: HTMLElement | Document, selector: string, event: string, handler: (event: Event, target: T) => void): () => void;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Checks if an element is visible in the viewport.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* // Check if element is visible
|
|
200
|
+
* if (isInViewport(element)) {
|
|
201
|
+
* lazyLoadImage(element);
|
|
202
|
+
* }
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* // Partial visibility
|
|
206
|
+
* if (isInViewport(element, 0.5)) {
|
|
207
|
+
* // At least 50% visible
|
|
208
|
+
* triggerAnimation(element);
|
|
209
|
+
* }
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* // Lazy loading images
|
|
213
|
+
* const images = querySelectorAll<HTMLImageElement>('img[data-src]');
|
|
214
|
+
* images.forEach(img => {
|
|
215
|
+
* if (isInViewport(img)) {
|
|
216
|
+
* img.src = img.dataset.src!;
|
|
217
|
+
* }
|
|
218
|
+
* });
|
|
219
|
+
*/
|
|
220
|
+
declare function isInViewport(element: Element | null, threshold?: number): boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Gets the bounding rectangle of an element.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* const rect = getRect(element);
|
|
226
|
+
* console.log(rect.top, rect.left, rect.width, rect.height);
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* // Position tooltip relative to button
|
|
230
|
+
* const buttonRect = getRect(button);
|
|
231
|
+
* tooltip.style.top = `${buttonRect.bottom + 10}px`;
|
|
232
|
+
* tooltip.style.left = `${buttonRect.left}px`;
|
|
233
|
+
*/
|
|
234
|
+
declare function getRect(element: Element | null): DOMRect | null;
|
|
235
|
+
/**
|
|
236
|
+
* Scrolls an element into view smoothly.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* // Scroll to element
|
|
240
|
+
* scrollIntoView(element);
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* // Scroll to top of page
|
|
244
|
+
* scrollIntoView(document.body, 'start');
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* // Scroll element to center
|
|
248
|
+
* scrollIntoView(element, 'center');
|
|
249
|
+
*/
|
|
250
|
+
declare function scrollIntoView(element: Element | null, block?: ScrollLogicalPosition, behavior?: ScrollBehavior): void;
|
|
251
|
+
/**
|
|
252
|
+
* Scrolls to a specific position.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* // Scroll to top
|
|
256
|
+
* scrollTo(0, 0);
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* // Scroll down 500px
|
|
260
|
+
* scrollTo(0, 500, 'smooth');
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* // Scroll to bottom
|
|
264
|
+
* scrollTo(0, document.body.scrollHeight);
|
|
265
|
+
*/
|
|
266
|
+
declare function scrollTo(x: number, y: number, behavior?: ScrollBehavior): void;
|
|
267
|
+
/**
|
|
268
|
+
* Gets the scroll position of the window.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* const { x, y } = getScrollPosition();
|
|
272
|
+
* console.log(`Scrolled ${y}px from top`);
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* // Save scroll position
|
|
276
|
+
* const position = getScrollPosition();
|
|
277
|
+
* // Later: scrollTo(position.x, position.y);
|
|
278
|
+
*/
|
|
279
|
+
declare function getScrollPosition(): {
|
|
280
|
+
x: number;
|
|
281
|
+
y: number;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Sets inline styles on an element.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* // Set single style
|
|
289
|
+
* setStyle(element, 'color', 'red');
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* // Set multiple styles
|
|
293
|
+
* setStyles(element, {
|
|
294
|
+
* color: 'red',
|
|
295
|
+
* fontSize: '16px',
|
|
296
|
+
* display: 'flex'
|
|
297
|
+
* });
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* // Conditional styles
|
|
301
|
+
* setStyles(button, {
|
|
302
|
+
* opacity: disabled ? '0.5' : '1',
|
|
303
|
+
* cursor: disabled ? 'not-allowed' : 'pointer'
|
|
304
|
+
* });
|
|
305
|
+
*/
|
|
306
|
+
declare function setStyle(element: HTMLElement | null, property: string, value: string): void;
|
|
307
|
+
declare function setStyles(element: HTMLElement | null, styles: Partial<CSSStyleDeclaration> | Record<string, string>): void;
|
|
308
|
+
/**
|
|
309
|
+
* Gets computed style of an element.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* const color = getComputedStyle(element, 'color');
|
|
313
|
+
* console.log(color); // => 'rgb(255, 0, 0)'
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* // Get multiple properties
|
|
317
|
+
* const styles = getComputedStyles(element, ['width', 'height']);
|
|
318
|
+
* console.log(styles); // => { width: '100px', height: '50px' }
|
|
319
|
+
*/
|
|
320
|
+
declare function getComputedStyleValue(element: Element | null, property: string): string;
|
|
321
|
+
declare function getComputedStyles(element: Element | null, properties: string[]): Record<string, string>;
|
|
322
|
+
/**
|
|
323
|
+
* Shows an element by removing display: none.
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* show(modal);
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* // Show with specific display value
|
|
330
|
+
* show(element, 'flex');
|
|
331
|
+
*/
|
|
332
|
+
declare function show(element: HTMLElement | null, display?: string): void;
|
|
333
|
+
/**
|
|
334
|
+
* Hides an element by setting display: none.
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* hide(modal);
|
|
338
|
+
*/
|
|
339
|
+
declare function hide(element: HTMLElement | null): void;
|
|
340
|
+
/**
|
|
341
|
+
* Toggles element visibility.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* toggle(dropdown);
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* // Force show/hide
|
|
348
|
+
* toggle(element, true); // Always show
|
|
349
|
+
* toggle(element, false); // Always hide
|
|
350
|
+
*/
|
|
351
|
+
declare function toggle(element: HTMLElement | null, force?: boolean): void;
|
|
352
|
+
|
|
353
|
+
export { addClass, addEventListener, classNames, delegate, getComputedStyleValue, getComputedStyles, getRect, getScrollPosition, hasClass, hide, isInViewport, once, querySelector, querySelectorAll, removeClass, scrollIntoView, scrollTo, setStyle, setStyles, show, toggle, toggleClass };
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-safe querySelector that returns the correct element type.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* // Get a button with proper typing
|
|
6
|
+
* const button = querySelector<HTMLButtonElement>('#submit');
|
|
7
|
+
* if (button) {
|
|
8
|
+
* button.disabled = true;
|
|
9
|
+
* }
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Get an input element
|
|
13
|
+
* const input = querySelector<HTMLInputElement>('input[name="email"]');
|
|
14
|
+
* if (input) {
|
|
15
|
+
* console.log(input.value);
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Returns null if not found
|
|
20
|
+
* const missing = querySelector('#nonexistent');
|
|
21
|
+
* // => null
|
|
22
|
+
*/
|
|
23
|
+
declare function querySelector<T extends Element = Element>(selector: string, parent?: Document | Element): T | null;
|
|
24
|
+
/**
|
|
25
|
+
* Type-safe querySelectorAll that returns an array of elements.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Get all buttons
|
|
29
|
+
* const buttons = querySelectorAll<HTMLButtonElement>('button');
|
|
30
|
+
* buttons.forEach(btn => btn.disabled = true);
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Get all list items
|
|
34
|
+
* const items = querySelectorAll<HTMLLIElement>('ul > li');
|
|
35
|
+
* console.log(items.length);
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Search within a specific element
|
|
39
|
+
* const container = querySelector('#container');
|
|
40
|
+
* if (container) {
|
|
41
|
+
* const links = querySelectorAll<HTMLAnchorElement>('a', container);
|
|
42
|
+
* }
|
|
43
|
+
*/
|
|
44
|
+
declare function querySelectorAll<T extends Element = Element>(selector: string, parent?: Document | Element): T[];
|
|
45
|
+
|
|
46
|
+
type ClassValue = string | number | boolean | undefined | null | ClassValue[] | Record<string, boolean | undefined | null>;
|
|
47
|
+
/**
|
|
48
|
+
* Combines class names conditionally (like clsx/classnames).
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // Simple strings
|
|
52
|
+
* classNames('btn', 'btn-primary');
|
|
53
|
+
* // => 'btn btn-primary'
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* // Conditional classes
|
|
57
|
+
* classNames('btn', { 'btn-primary': isPrimary, 'btn-disabled': disabled });
|
|
58
|
+
* // => 'btn btn-primary' (if isPrimary=true, disabled=false)
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* // Mixed with arrays
|
|
62
|
+
* classNames('btn', ['btn-lg', disabled && 'btn-disabled']);
|
|
63
|
+
* // => 'btn btn-lg btn-disabled' (if disabled=true)
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* // Real-world React example
|
|
67
|
+
* function Button({ variant, disabled, className }: ButtonProps) {
|
|
68
|
+
* return (
|
|
69
|
+
* <button
|
|
70
|
+
* className={classNames(
|
|
71
|
+
* 'btn',
|
|
72
|
+
* `btn-${variant}`,
|
|
73
|
+
* { 'btn-disabled': disabled },
|
|
74
|
+
* className
|
|
75
|
+
* )}
|
|
76
|
+
* />
|
|
77
|
+
* );
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* // Falsy values are ignored
|
|
82
|
+
* classNames('btn', null, undefined, false, '', 'active');
|
|
83
|
+
* // => 'btn active'
|
|
84
|
+
*/
|
|
85
|
+
declare function classNames(...classes: ClassValue[]): string;
|
|
86
|
+
/**
|
|
87
|
+
* Adds a class to an element.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* const button = querySelector('#submit');
|
|
91
|
+
* addClass(button, 'active');
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* // Add multiple classes
|
|
95
|
+
* addClass(element, 'btn', 'btn-primary', 'btn-lg');
|
|
96
|
+
*/
|
|
97
|
+
declare function addClass(element: Element | null, ...classes: string[]): void;
|
|
98
|
+
/**
|
|
99
|
+
* Removes a class from an element.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* removeClass(button, 'active');
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* // Remove multiple classes
|
|
106
|
+
* removeClass(element, 'btn-primary', 'btn-lg');
|
|
107
|
+
*/
|
|
108
|
+
declare function removeClass(element: Element | null, ...classes: string[]): void;
|
|
109
|
+
/**
|
|
110
|
+
* Toggles a class on an element.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* // Toggle a class
|
|
114
|
+
* toggleClass(button, 'active');
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* // Force add or remove
|
|
118
|
+
* toggleClass(button, 'active', true); // Always add
|
|
119
|
+
* toggleClass(button, 'active', false); // Always remove
|
|
120
|
+
*/
|
|
121
|
+
declare function toggleClass(element: Element | null, className: string, force?: boolean): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Checks if an element has a class.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* if (hasClass(button, 'active')) {
|
|
127
|
+
* console.log('Button is active');
|
|
128
|
+
* }
|
|
129
|
+
*/
|
|
130
|
+
declare function hasClass(element: Element | null, className: string): boolean;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Adds an event listener with automatic cleanup.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* // Basic usage
|
|
137
|
+
* const cleanup = addEventListener(button, 'click', () => {
|
|
138
|
+
* console.log('Clicked!');
|
|
139
|
+
* });
|
|
140
|
+
* // Later: cleanup();
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* // With options
|
|
144
|
+
* addEventListener(window, 'scroll', handleScroll, { passive: true });
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* // Multiple events
|
|
148
|
+
* const cleanups = [
|
|
149
|
+
* addEventListener(input, 'focus', handleFocus),
|
|
150
|
+
* addEventListener(input, 'blur', handleBlur)
|
|
151
|
+
* ];
|
|
152
|
+
* // Cleanup all: cleanups.forEach(fn => fn());
|
|
153
|
+
*/
|
|
154
|
+
declare function addEventListener<K extends keyof HTMLElementEventMap>(element: HTMLElement | Window | Document | null, event: K, handler: (event: HTMLElementEventMap[K]) => void, options?: AddEventListenerOptions): () => void;
|
|
155
|
+
/**
|
|
156
|
+
* Adds an event listener that fires only once.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* // Listen for one click
|
|
160
|
+
* once(button, 'click', () => {
|
|
161
|
+
* console.log('Clicked once!');
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* // Wait for image load
|
|
166
|
+
* once(image, 'load', () => {
|
|
167
|
+
* console.log('Image loaded');
|
|
168
|
+
* });
|
|
169
|
+
*/
|
|
170
|
+
declare function once<K extends keyof HTMLElementEventMap>(element: HTMLElement | Window | Document | null, event: K, handler: (event: HTMLElementEventMap[K]) => void): () => void;
|
|
171
|
+
/**
|
|
172
|
+
* Event delegation - attach handler to parent that fires for matching children.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* // Handle clicks on any button inside container
|
|
176
|
+
* delegate(container, 'button', 'click', (event, target) => {
|
|
177
|
+
* console.log('Button clicked:', target);
|
|
178
|
+
* });
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* // Handle dynamic list items
|
|
182
|
+
* delegate(list, '.item', 'click', (event, item) => {
|
|
183
|
+
* item.classList.toggle('selected');
|
|
184
|
+
* });
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* // Works with dynamically added elements
|
|
188
|
+
* const cleanup = delegate(document.body, '[data-action]', 'click', (e, el) => {
|
|
189
|
+
* const action = el.getAttribute('data-action');
|
|
190
|
+
* handleAction(action);
|
|
191
|
+
* });
|
|
192
|
+
*/
|
|
193
|
+
declare function delegate<T extends HTMLElement = HTMLElement>(parent: HTMLElement | Document, selector: string, event: string, handler: (event: Event, target: T) => void): () => void;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Checks if an element is visible in the viewport.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* // Check if element is visible
|
|
200
|
+
* if (isInViewport(element)) {
|
|
201
|
+
* lazyLoadImage(element);
|
|
202
|
+
* }
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* // Partial visibility
|
|
206
|
+
* if (isInViewport(element, 0.5)) {
|
|
207
|
+
* // At least 50% visible
|
|
208
|
+
* triggerAnimation(element);
|
|
209
|
+
* }
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* // Lazy loading images
|
|
213
|
+
* const images = querySelectorAll<HTMLImageElement>('img[data-src]');
|
|
214
|
+
* images.forEach(img => {
|
|
215
|
+
* if (isInViewport(img)) {
|
|
216
|
+
* img.src = img.dataset.src!;
|
|
217
|
+
* }
|
|
218
|
+
* });
|
|
219
|
+
*/
|
|
220
|
+
declare function isInViewport(element: Element | null, threshold?: number): boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Gets the bounding rectangle of an element.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* const rect = getRect(element);
|
|
226
|
+
* console.log(rect.top, rect.left, rect.width, rect.height);
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* // Position tooltip relative to button
|
|
230
|
+
* const buttonRect = getRect(button);
|
|
231
|
+
* tooltip.style.top = `${buttonRect.bottom + 10}px`;
|
|
232
|
+
* tooltip.style.left = `${buttonRect.left}px`;
|
|
233
|
+
*/
|
|
234
|
+
declare function getRect(element: Element | null): DOMRect | null;
|
|
235
|
+
/**
|
|
236
|
+
* Scrolls an element into view smoothly.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* // Scroll to element
|
|
240
|
+
* scrollIntoView(element);
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* // Scroll to top of page
|
|
244
|
+
* scrollIntoView(document.body, 'start');
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* // Scroll element to center
|
|
248
|
+
* scrollIntoView(element, 'center');
|
|
249
|
+
*/
|
|
250
|
+
declare function scrollIntoView(element: Element | null, block?: ScrollLogicalPosition, behavior?: ScrollBehavior): void;
|
|
251
|
+
/**
|
|
252
|
+
* Scrolls to a specific position.
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* // Scroll to top
|
|
256
|
+
* scrollTo(0, 0);
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* // Scroll down 500px
|
|
260
|
+
* scrollTo(0, 500, 'smooth');
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* // Scroll to bottom
|
|
264
|
+
* scrollTo(0, document.body.scrollHeight);
|
|
265
|
+
*/
|
|
266
|
+
declare function scrollTo(x: number, y: number, behavior?: ScrollBehavior): void;
|
|
267
|
+
/**
|
|
268
|
+
* Gets the scroll position of the window.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* const { x, y } = getScrollPosition();
|
|
272
|
+
* console.log(`Scrolled ${y}px from top`);
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* // Save scroll position
|
|
276
|
+
* const position = getScrollPosition();
|
|
277
|
+
* // Later: scrollTo(position.x, position.y);
|
|
278
|
+
*/
|
|
279
|
+
declare function getScrollPosition(): {
|
|
280
|
+
x: number;
|
|
281
|
+
y: number;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Sets inline styles on an element.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* // Set single style
|
|
289
|
+
* setStyle(element, 'color', 'red');
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* // Set multiple styles
|
|
293
|
+
* setStyles(element, {
|
|
294
|
+
* color: 'red',
|
|
295
|
+
* fontSize: '16px',
|
|
296
|
+
* display: 'flex'
|
|
297
|
+
* });
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* // Conditional styles
|
|
301
|
+
* setStyles(button, {
|
|
302
|
+
* opacity: disabled ? '0.5' : '1',
|
|
303
|
+
* cursor: disabled ? 'not-allowed' : 'pointer'
|
|
304
|
+
* });
|
|
305
|
+
*/
|
|
306
|
+
declare function setStyle(element: HTMLElement | null, property: string, value: string): void;
|
|
307
|
+
declare function setStyles(element: HTMLElement | null, styles: Partial<CSSStyleDeclaration> | Record<string, string>): void;
|
|
308
|
+
/**
|
|
309
|
+
* Gets computed style of an element.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* const color = getComputedStyle(element, 'color');
|
|
313
|
+
* console.log(color); // => 'rgb(255, 0, 0)'
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* // Get multiple properties
|
|
317
|
+
* const styles = getComputedStyles(element, ['width', 'height']);
|
|
318
|
+
* console.log(styles); // => { width: '100px', height: '50px' }
|
|
319
|
+
*/
|
|
320
|
+
declare function getComputedStyleValue(element: Element | null, property: string): string;
|
|
321
|
+
declare function getComputedStyles(element: Element | null, properties: string[]): Record<string, string>;
|
|
322
|
+
/**
|
|
323
|
+
* Shows an element by removing display: none.
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* show(modal);
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* // Show with specific display value
|
|
330
|
+
* show(element, 'flex');
|
|
331
|
+
*/
|
|
332
|
+
declare function show(element: HTMLElement | null, display?: string): void;
|
|
333
|
+
/**
|
|
334
|
+
* Hides an element by setting display: none.
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* hide(modal);
|
|
338
|
+
*/
|
|
339
|
+
declare function hide(element: HTMLElement | null): void;
|
|
340
|
+
/**
|
|
341
|
+
* Toggles element visibility.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* toggle(dropdown);
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* // Force show/hide
|
|
348
|
+
* toggle(element, true); // Always show
|
|
349
|
+
* toggle(element, false); // Always hide
|
|
350
|
+
*/
|
|
351
|
+
declare function toggle(element: HTMLElement | null, force?: boolean): void;
|
|
352
|
+
|
|
353
|
+
export { addClass, addEventListener, classNames, delegate, getComputedStyleValue, getComputedStyles, getRect, getScrollPosition, hasClass, hide, isInViewport, once, querySelector, querySelectorAll, removeClass, scrollIntoView, scrollTo, setStyle, setStyles, show, toggle, toggleClass };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunk35CB7HNN_js=require('../chunk-35CB7HNN.js');require('../chunk-WOT6VMZA.js');Object.defineProperty(exports,"addClass",{enumerable:true,get:function(){return chunk35CB7HNN_js.d}});Object.defineProperty(exports,"addEventListener",{enumerable:true,get:function(){return chunk35CB7HNN_js.h}});Object.defineProperty(exports,"classNames",{enumerable:true,get:function(){return chunk35CB7HNN_js.c}});Object.defineProperty(exports,"delegate",{enumerable:true,get:function(){return chunk35CB7HNN_js.j}});Object.defineProperty(exports,"getComputedStyleValue",{enumerable:true,get:function(){return chunk35CB7HNN_js.r}});Object.defineProperty(exports,"getComputedStyles",{enumerable:true,get:function(){return chunk35CB7HNN_js.s}});Object.defineProperty(exports,"getRect",{enumerable:true,get:function(){return chunk35CB7HNN_js.l}});Object.defineProperty(exports,"getScrollPosition",{enumerable:true,get:function(){return chunk35CB7HNN_js.o}});Object.defineProperty(exports,"hasClass",{enumerable:true,get:function(){return chunk35CB7HNN_js.g}});Object.defineProperty(exports,"hide",{enumerable:true,get:function(){return chunk35CB7HNN_js.u}});Object.defineProperty(exports,"isInViewport",{enumerable:true,get:function(){return chunk35CB7HNN_js.k}});Object.defineProperty(exports,"once",{enumerable:true,get:function(){return chunk35CB7HNN_js.i}});Object.defineProperty(exports,"querySelector",{enumerable:true,get:function(){return chunk35CB7HNN_js.a}});Object.defineProperty(exports,"querySelectorAll",{enumerable:true,get:function(){return chunk35CB7HNN_js.b}});Object.defineProperty(exports,"removeClass",{enumerable:true,get:function(){return chunk35CB7HNN_js.e}});Object.defineProperty(exports,"scrollIntoView",{enumerable:true,get:function(){return chunk35CB7HNN_js.m}});Object.defineProperty(exports,"scrollTo",{enumerable:true,get:function(){return chunk35CB7HNN_js.n}});Object.defineProperty(exports,"setStyle",{enumerable:true,get:function(){return chunk35CB7HNN_js.p}});Object.defineProperty(exports,"setStyles",{enumerable:true,get:function(){return chunk35CB7HNN_js.q}});Object.defineProperty(exports,"show",{enumerable:true,get:function(){return chunk35CB7HNN_js.t}});Object.defineProperty(exports,"toggle",{enumerable:true,get:function(){return chunk35CB7HNN_js.v}});Object.defineProperty(exports,"toggleClass",{enumerable:true,get:function(){return chunk35CB7HNN_js.f}});
|