@oscarpalmer/toretto 0.39.0 → 0.39.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.
Files changed (2) hide show
  1. package/package.json +4 -3
  2. package/types/index.d.ts +428 -11
package/package.json CHANGED
@@ -10,6 +10,7 @@
10
10
  "devDependencies": {
11
11
  "@types/node": "^25.4",
12
12
  "@vitest/coverage-istanbul": "^4",
13
+ "dts-bundle-generator": "^9.5",
13
14
  "jsdom": "^28.1",
14
15
  "oxfmt": "^0.39",
15
16
  "oxlint": "^1.54",
@@ -23,7 +24,7 @@
23
24
  "./package.json": "./package.json",
24
25
  ".": {
25
26
  "types": "./types/index.d.ts",
26
- "default": "./dist/index.js"
27
+ "default": "./dist/toretto.full.js"
27
28
  },
28
29
  "./attribute": {
29
30
  "types": "./types/attribute/index.d.ts",
@@ -84,7 +85,7 @@
84
85
  "url": "git+https://github.com/oscarpalmer/toretto.git"
85
86
  },
86
87
  "scripts": {
87
- "build": "npm run clean && npx vite build && npm run rolldown:build && npx tsc",
88
+ "build": "npm run clean && npx vite build && npm run rolldown:build && npx tsc && npx dts-bundle-generator --config ./dts.config.ts --silent",
88
89
  "clean": "rm -rf ./dist && rm -rf ./types && rm -f ./tsconfig.tsbuildinfo",
89
90
  "rolldown:build": "npx rolldown -c",
90
91
  "rolldown:watch": "npx rolldown -c ./rolldown.config.js --watch",
@@ -93,5 +94,5 @@
93
94
  },
94
95
  "type": "module",
95
96
  "types": "types/index.d.ts",
96
- "version": "0.39.0"
97
+ "version": "0.39.1"
97
98
  }
package/types/index.d.ts CHANGED
@@ -1,11 +1,428 @@
1
- import supportsTouch from './touch';
2
- export { isBadAttribute, isBooleanAttribute, isEmptyNonBooleanAttribute, isInvalidBooleanAttribute, } from './attribute/index';
3
- export * from './data';
4
- export * from './event/index';
5
- export * from './find/index';
6
- export * from './focusable';
7
- export * from './html/index';
8
- export * from './is';
9
- export * from './models';
10
- export * from './style';
11
- export { supportsTouch };
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export type SupporsTouch = {
4
+ /**
5
+ * Are touch events supported?
6
+ */
7
+ readonly value: boolean;
8
+ /**
9
+ * Are touch events supported?
10
+ */
11
+ get(): boolean;
12
+ /**
13
+ * Re-evaluate if touch events are supported
14
+ */
15
+ update(): boolean;
16
+ };
17
+ /**
18
+ * Does the device support touch events?
19
+ */
20
+ export declare const supportsTouch: SupporsTouch;
21
+ /**
22
+ * Attribute for an element
23
+ */
24
+ export type Attribute = {
25
+ name: string;
26
+ value: unknown;
27
+ };
28
+ /**
29
+ * Event listener for custom events
30
+ */
31
+ export type CustomEventListener = (event: CustomEvent) => void;
32
+ /**
33
+ * The position of an event
34
+ */
35
+ export type EventPosition = {
36
+ x: number;
37
+ y: number;
38
+ };
39
+ /**
40
+ * Event listener that can be removed
41
+ */
42
+ export type RemovableEventListener = () => void;
43
+ /**
44
+ * Selector that be searched for
45
+ */
46
+ export type Selector = string | Node | Node[] | NodeList;
47
+ /**
48
+ * Text direction for an element
49
+ */
50
+ export type TextDirection = "ltr" | "rtl";
51
+ /**
52
+ * Is the attribute considered bad and potentially harmful?
53
+ * @param attribute Attribute to check
54
+ * @returns `true` if attribute is considered bad
55
+ */
56
+ export declare function isBadAttribute(attribute: Attr | Attribute): boolean;
57
+ /**
58
+ * Is the attribute considered bad and potentially harmful?
59
+ * @param name Attribute name
60
+ * @param value Attribute value
61
+ * @returns `true` if attribute is considered bad
62
+ */
63
+ export declare function isBadAttribute(name: string, value: string): boolean;
64
+ /**
65
+ * Is the attribute a boolean attribute?
66
+ * @param name Attribute to check
67
+ * @returns `true` if attribute is a boolean attribute
68
+ */
69
+ export declare function isBooleanAttribute(attribute: Attr | Attribute): boolean;
70
+ /**
71
+ * Is the attribute a boolean attribute?
72
+ * @param name Attribute name
73
+ * @returns `true` if attribute is a boolean attribute
74
+ */
75
+ export declare function isBooleanAttribute(name: string): boolean;
76
+ /**
77
+ * Is the attribute empty and not a boolean attribute?
78
+ * @param attribute Attribute to check
79
+ * @returns `true` if attribute is empty and not a boolean attribute
80
+ */
81
+ export declare function isEmptyNonBooleanAttribute(attribute: Attr | Attribute): boolean;
82
+ /**
83
+ * Is the attribute empty and not a boolean attribute?
84
+ * @param name Attribute name
85
+ * @param value Attribute value
86
+ * @returns `true` if attribute is empty and not a boolean attribute
87
+ */
88
+ export declare function isEmptyNonBooleanAttribute(name: string, value: string): boolean;
89
+ /**
90
+ * Is the attribute an invalid boolean attribute?
91
+ *
92
+ * _(I.e., its value is not empty or the same as its name)_
93
+ * @param attribute Attribute to check
94
+ * @returns `true` if attribute is an invalid boolean attribute
95
+ */
96
+ export declare function isInvalidBooleanAttribute(attribute: Attr | Attribute): boolean;
97
+ /**
98
+ * Is the attribute an invalid boolean attribute?
99
+ *
100
+ * _(I.e., its value is not empty or the same as its name)_
101
+ * @param name Attribute name
102
+ * @param value Attribute value
103
+ * @returns `true` if attribute is an invalid boolean attribute
104
+ */
105
+ export declare function isInvalidBooleanAttribute(name: string, value: string): boolean;
106
+ /**
107
+ * A generic object
108
+ */
109
+ export type PlainObject = Record<PropertyKey, unknown>;
110
+ /**
111
+ * Get a keyed data value from an element
112
+ * @param element Element to get data from
113
+ * @param key Data key
114
+ * @param parse Parse values? _(defaults to `true`)_
115
+ * @returns Data value
116
+ */
117
+ export declare function getData(element: Element, key: string, parse?: boolean): unknown;
118
+ /**
119
+ * Get keyed data values from an element
120
+ * @param element Element to get data from
121
+ * @param keys Keys of the data values to get
122
+ * @param parse Parse values? _(defaults to `true`)_
123
+ * @returns Keyed data values
124
+ */
125
+ export declare function getData<Key extends string>(element: Element, keys: Key[], parse?: boolean): Record<Key, unknown>;
126
+ /**
127
+ * Set data values on an element
128
+ * @param element Element to set data on
129
+ * @param data Data to set
130
+ */
131
+ export declare function setData(element: Element, data: PlainObject): void;
132
+ /**
133
+ * Set a data value on an element
134
+ * @param element Element to set data on
135
+ * @param key Data key
136
+ * @param value Data value
137
+ */
138
+ export declare function setData(element: Element, key: string, value: unknown): void;
139
+ /**
140
+ * Dispatch an event for a target
141
+ * @param target Event target
142
+ * @param type Type of event
143
+ * @param options Options for event _(bubbles and is cancelable by default)_
144
+ */
145
+ export declare function dispatch<Type extends keyof HTMLElementEventMap>(target: EventTarget, type: Type, options?: CustomEventInit): void;
146
+ /**
147
+ * Dispatch an event for a target
148
+ * @param target Event target
149
+ * @param type Type of event
150
+ * @param options Options for event _(bubbles and is cancelable by default)_
151
+ */
152
+ export declare function dispatch(target: EventTarget, type: string, options?: CustomEventInit): void;
153
+ /**
154
+ * Get the X- and Y-coordinates from a pointer event
155
+ * @param event Pointer event
156
+ * @returns X- and Y-coordinates
157
+ */
158
+ export declare function getPosition(event: MouseEvent | TouchEvent): EventPosition | undefined;
159
+ /**
160
+ * Remove an event listener
161
+ * @param target Event target
162
+ * @param type Type of event
163
+ * @param listener Event listener
164
+ * @param options Options for event
165
+ */
166
+ export declare function off(target: EventTarget, type: keyof HTMLElementEventMap, listener: EventListener | CustomEventListener, options?: EventListenerOptions): void;
167
+ /**
168
+ * Remove an event listener
169
+ * @param target Event target
170
+ * @param type Type of event
171
+ * @param listener Event listener
172
+ * @param options Options for event
173
+ */
174
+ export declare function off(target: EventTarget, type: string, listener: EventListener | CustomEventListener, options?: EventListenerOptions): void;
175
+ /**
176
+ * Add an event listener
177
+ * @param target Event target
178
+ * @param type Type of event
179
+ * @param listener Event listener
180
+ * @param options Options for event _(passive by default)_
181
+ */
182
+ export declare function on<Type extends keyof HTMLElementEventMap>(target: EventTarget, type: Type, listener: (event: HTMLElementEventMap[Type]) => void, options?: AddEventListenerOptions): RemovableEventListener;
183
+ /**
184
+ * Add an event listener
185
+ * @param target Event target
186
+ * @param type Type of event
187
+ * @param listener Event listener
188
+ * @param options Options for event _(passive by default)_
189
+ */
190
+ export declare function on(target: EventTarget, type: string, listener: EventListener | CustomEventListener, options?: AddEventListenerOptions): RemovableEventListener;
191
+ /**
192
+ * Find the closest ancestor element that matches the tag name
193
+ *
194
+ * - If no match is found, `null` is returned
195
+ * - _(If you want to search upwards, downwards, and sideways, use {@link findRelatives})_
196
+ * @param origin Origin to start from
197
+ * @param tagName Tag name to match
198
+ * @returns Found ancestor or `null`
199
+ */
200
+ export declare function findAncestor<TagName extends keyof HTMLElementTagNameMap>(origin: Element | Event | EventTarget, tagName: TagName): HTMLElementTagNameMap[TagName] | null;
201
+ /**
202
+ * Find the closest ancestor element that matches the selector _(string or callback)_
203
+ *
204
+ * - If no match is found, `null` is returned
205
+ * - _(If you want to search upwards, downwards, and sideways, use {@link findRelatives})_
206
+ * @param origin Origin to start from
207
+ * @param selector Selector to match
208
+ * @returns Found ancestor or `null`
209
+ */
210
+ export declare function findAncestor(origin: Element | Event | EventTarget, selector: string | ((element: Element) => boolean)): Element | null;
211
+ /**
212
+ * Finds the closest elements to the origin element that matches the tag name
213
+ *
214
+ * Traverses up, down, and sideways in the _DOM_-tree. _(If you only want to traverse up, use {@link findAncestor})_
215
+ * @param origin Element to start from
216
+ * @param tagName Tag name to match
217
+ * @param context Context to search within
218
+ * @returns Found elements
219
+ */
220
+ export declare function findRelatives<TagName extends keyof HTMLElementTagNameMap>(origin: Element, tagName: TagName, context?: Document | Element): HTMLElementTagNameMap[TagName][];
221
+ /**
222
+ * Finds the closest elements to the origin element that matches the selector
223
+ *
224
+ * Traverses up, down, and sideways in the _DOM_-tree. _(If you only want to traverse up, use {@link findAncestor})_
225
+ * @param origin Element to start from
226
+ * @param selector Selector to match
227
+ * @param context Context to search within
228
+ * @returns Found elements
229
+ */
230
+ export declare function findRelatives(origin: Element, selector: string, context?: Document | Element): Element[];
231
+ /**
232
+ * Get the distance between two elements _(i.e., the amount of nodes of between them)_
233
+ * @param origin Origin element
234
+ * @param target Target element
235
+ * @returns Distance between elements, or `-1` if distance cannot be calculated
236
+ */
237
+ export declare function getDistance(origin: Element, target: Element): number;
238
+ /**
239
+ * Find the first element that matches the tag name
240
+ * @param tagName Tag name of element to find
241
+ * @param context Context to search within _(defaults to `document`)_
242
+ * @returns Found element or `null`
243
+ */
244
+ export declare function findElement<TagName extends keyof HTMLElementTagNameMap>(tagName: TagName, context?: Selector | null): HTMLElementTagNameMap[TagName] | null;
245
+ /**
246
+ * Find the first element that matches the selector
247
+ * @param selector Selector to find element for
248
+ * @param context Context to search within _(defaults to `document`)_
249
+ * @returns Found element or `null`
250
+ */
251
+ export declare function findElement(selector: string, context?: Selector | null): Element | null;
252
+ /**
253
+ * Find elements that match the selector
254
+ * @param tagName tagName to find elements for
255
+ * @param context Context to search within _(defaults to `document`)_
256
+ * @returns Found elements
257
+ */
258
+ export declare function findElements(tagName: keyof HTMLElementTagNameMap, context?: Selector | null): HTMLElementTagNameMap[typeof tagName][];
259
+ /**
260
+ * Find elements that match the selector
261
+ * @param selector Selector to find elements for
262
+ * @param context Context to search within _(defaults to `document`)_
263
+ * @returns Found elements
264
+ */
265
+ export declare function findElements(selector: Selector, context?: Selector | null): Element[];
266
+ /**
267
+ * Get the most specific element under the pointer
268
+ *
269
+ * - Ignores elements with `pointer-events: none` and `visibility: hidden`
270
+ * - _(If `skipIgnore` is `true`, no elements are ignored)_
271
+ * @param skipIgnore Skip ignored elements?
272
+ * @returns Found element or `null`
273
+ */
274
+ export declare function getElementUnderPointer(skipIgnore?: boolean): Element | null;
275
+ /**
276
+ * Get a list of focusable elements within a parent element
277
+ * @param parent Parent element
278
+ * @returns Focusable elements
279
+ */
280
+ export declare function getFocusable(parent: Element): Element[];
281
+ /**
282
+ * Get a list of tabbable elements within a parent element
283
+ * @param parent Parent element
284
+ * @returns Tabbable elements
285
+ */
286
+ export declare function getTabbable(parent: Element): Element[];
287
+ /**
288
+ * Is the element focusable?
289
+ * @param element Element to check
290
+ * @returns `true` if focusable, otherwise `false`
291
+ */
292
+ export declare function isFocusable(element: Element): boolean;
293
+ /**
294
+ * Is the element tabbable?
295
+ * @param element Element to check
296
+ * @returns `true` if tabbable, otherwise `false`
297
+ */
298
+ export declare function isTabbable(element: Element): boolean;
299
+ export type Html = {
300
+ /**
301
+ * Create nodes from an HTML string or a template element
302
+ * @param value HTML string or id for a template element
303
+ * @param options Options for creating nodes
304
+ * @returns Created nodes
305
+ */
306
+ (value: string, options?: HtmlOptions): Node[];
307
+ /**
308
+ * Create nodes from a template element
309
+ * @param template Template element
310
+ * @param options Options for creating nodes
311
+ * @returns Created nodes
312
+ */
313
+ (template: HTMLTemplateElement, options?: HtmlOptions): Node[];
314
+ /**
315
+ * Clear cache of template elements
316
+ */
317
+ clear(): void;
318
+ /**
319
+ * Remove cached template element for an HTML string or id
320
+ * @param template HTML string or id for a template element
321
+ */
322
+ remove(template: string): void;
323
+ };
324
+ export type HtmlOptions = {
325
+ /**
326
+ * Cache template element for the HTML string? _(defaults to `true`)_
327
+ */
328
+ cache?: boolean;
329
+ };
330
+ export declare const html: Html;
331
+ /**
332
+ * Sanitize one or more nodes, recursively
333
+ * @param value Node or nodes to sanitize
334
+ * @param options Sanitization options
335
+ * @returns Sanitized nodes
336
+ */
337
+ export declare function sanitize(value: Node | Node[]): Node[];
338
+ /**
339
+ * Is the value an event target?
340
+ * @param value Value to check
341
+ * @returns `true` if it's an event target, otherwise `false`
342
+ */
343
+ export declare function isEventTarget(value: unknown): value is EventTarget;
344
+ /**
345
+ * Is the value an HTML or SVG element?
346
+ * @param value Value to check
347
+ * @returns `true` if it's an HTML or SVG element, otherwise `false`
348
+ */
349
+ export declare function isHTMLOrSVGElement(value: unknown): value is HTMLElement | SVGElement;
350
+ /**
351
+ * Is the value a child node?
352
+ * @param value Value to check
353
+ * @returns `true` if it's a child node, otherwise `false`
354
+ */
355
+ export declare function isChildNode(value: unknown): value is ChildNode;
356
+ /**
357
+ * Is the node inside a document?
358
+ * @param node Node to check
359
+ * @returns `true` if it's inside a document, otherwise `false`
360
+ */
361
+ export declare function isInDocument(node: Node): boolean;
362
+ /**
363
+ * Is the node inside a specific document?
364
+ * @param node Node to check
365
+ * @param document Document to check within
366
+ * @returns `true` if it's inside the document, otherwise `false`
367
+ */
368
+ export declare function isInDocument(node: Node, document: Document): boolean;
369
+ export type StyleToggler = {
370
+ /**
371
+ * Set the provided styles on the element
372
+ */
373
+ set(): void;
374
+ /**
375
+ * Remove the provided styles from the element _(and sets any previous styles)_
376
+ */
377
+ remove(): void;
378
+ };
379
+ /**
380
+ * Get a style from an element
381
+ * @param element Element to get the style from
382
+ * @param property Style name
383
+ * @param computed Get the computed style? _(defaults to `false`)_
384
+ * @returns Style value
385
+ */
386
+ export declare function getStyle(element: Element, property: keyof CSSStyleDeclaration, computed?: boolean): string | undefined;
387
+ /**
388
+ * Get styles from an element
389
+ * @param element Element to get the styles from
390
+ * @param properties Styles to get
391
+ * @param computed Get the computed styles? _(defaults to `false`)_
392
+ * @returns Style values
393
+ */
394
+ export declare function getStyles<Property extends keyof CSSStyleDeclaration>(element: Element, properties: Property[], computed?: boolean): Record<Property, string | undefined>;
395
+ /**
396
+ * Get the text direction of an element
397
+ * @param element Element to get the text direction from
398
+ * @param computed Get the computed text direction? _(defaults to `false`)_
399
+ * @returns Text direction
400
+ */
401
+ export declare function getTextDirection(element: Element, computed?: boolean): TextDirection;
402
+ /**
403
+ * Set a style on an element
404
+ * @param element Element to set the style on
405
+ * @param property Style name
406
+ * @param value Style value
407
+ */
408
+ export declare function setStyle(element: Element, property: keyof CSSStyleDeclaration, value?: string): void;
409
+ /**
410
+ * Set styles on an element
411
+ * @param element Element to set the styles on
412
+ * @param styles Styles to set
413
+ */
414
+ export declare function setStyles(element: Element, styles: Partial<CSSStyleDeclaration>): void;
415
+ /**
416
+ * Toggle styles for an element
417
+ * @param element Element to style
418
+ * @param styles Styles to be set or removed
419
+ * @returns Style toggler
420
+ */
421
+ export declare function toggleStyles(element: Element, styles: Partial<CSSStyleDeclaration>): StyleToggler;
422
+
423
+ export {
424
+ findElement as $,
425
+ findElements as $$,
426
+ };
427
+
428
+ export {};