@danielgindi/dom-utils 1.0.11 → 2.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.
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @param {Element} el
3
+ * @param {string[]} props
4
+ * @returns {Object<string, string>}
5
+ */
6
+ declare const getCssProps: (el: Element, props: string[]) => Record<string, string>;
7
+ /**
8
+ * @param {ElementCSSInlineStyle} el
9
+ * @param {Object<string, string>} props
10
+ */
11
+ declare const setCssProps: (el: ElementCSSInlineStyle, props: Record<string, unknown>) => void;
12
+ /**
13
+ * Gets the width of an element, with fractions
14
+ * @function getElementWidth
15
+ * @param {Element} el
16
+ * @param {boolean} [paddings=false] - include paddings
17
+ * @param {boolean} [borders=false] - include borders
18
+ * @param {boolean} [margins=false] - include margins
19
+ * @returns {number}
20
+ */
21
+ declare const getElementWidth: (el: Element | Document | Window, paddings?: boolean, borders?: boolean, margins?: boolean) => number;
22
+ /**
23
+ * Gets the width of an element, with fractions
24
+ * @function getElementHeight
25
+ * @param {Element} el
26
+ * @param {boolean} [paddings=false] - include paddings
27
+ * @param {boolean} [borders=false] - include borders
28
+ * @param {boolean} [margins=false] - include margins
29
+ * @returns {number}
30
+ */
31
+ declare const getElementHeight: (el: Element | Document | Window, paddings?: boolean, borders?: boolean, margins?: boolean) => number;
32
+ /**
33
+ * Gets the width of an element, with fractions
34
+ * @function getPseudoElementWidth
35
+ * @param {Element} el
36
+ * @param {string} pseudo
37
+ * @param {boolean} [paddings=false] - include paddings
38
+ * @param {boolean} [borders=false] - include borders
39
+ * @param {boolean} [margins=false] - include margins
40
+ * @returns {number}
41
+ */
42
+ declare const getPseudoElementWidth: (el: Element, pseudo: string, paddings?: boolean, borders?: boolean, margins?: boolean) => number;
43
+ /**
44
+ * Gets the width of an element, with fractions
45
+ * @function getPseudoElementHeight
46
+ * @param {Element} el
47
+ * @param {string} pseudo
48
+ * @param {boolean} [paddings=false] - include paddings
49
+ * @param {boolean} [borders=false] - include borders
50
+ * @param {boolean} [margins=false] - include margins
51
+ * @returns {number}
52
+ */
53
+ declare const getPseudoElementHeight: (el: Element, pseudo: string, paddings?: boolean, borders?: boolean, margins?: boolean) => number;
54
+ /**
55
+ * Sets the width of an element
56
+ * @function setElementWidth
57
+ * @param {Element} el
58
+ * @param {number} value
59
+ * @param {boolean} [paddings=false] - include paddings
60
+ * @param {boolean} [borders=false] - include borders
61
+ * @param {boolean} [margins=false] - include margins
62
+ */
63
+ declare const setElementWidth: (el: ElementCSSInlineStyle, value: number, paddings?: boolean, borders?: boolean, margins?: boolean) => void;
64
+ /**
65
+ * Sets the width of an element, with fractions
66
+ * @function setElementHeight
67
+ * @param {Element} el
68
+ * @param {number} value
69
+ * @param {boolean} [paddings=false] - include paddings
70
+ * @param {boolean} [borders=false] - include borders
71
+ * @param {boolean} [margins=false] - include margins
72
+ */
73
+ declare const setElementHeight: (el: ElementCSSInlineStyle, value: number, paddings?: boolean, borders?: boolean, margins?: boolean) => void;
74
+ /**
75
+ * Find offset of an element relative to the document, considering scroll offsets
76
+ * @param {Element} el
77
+ * @returns {{top: number, left: number}}
78
+ */
79
+ declare const getElementOffset: (el: Element) => {
80
+ top: number;
81
+ left: number;
82
+ };
83
+ /**
84
+ * Calculates the anchored position relative to this element. <br />
85
+ * The return value will include an `left`/`top` position on left/top axis, <br />
86
+ * an `right`/`bottom` position which is the exact opposite, <br />
87
+ * and the `xSpec`/`ySpec` after normalizing rtl based values (`'start'`/`'end'`).
88
+ * @param {Element} el? - the target element to base the calculations on. If `size` and `rtl` are specified - then this argument is optional.
89
+ * @param {'left'|'center'|'right'|'start'|'end'|string|number} xSpec - horizontal anchor specification (could be either `'left'|'center'|'right'|'start'|'end'` or a percentage `'50%'` or a fixed decimal `Number`)
90
+ * @param {'top'|'center'|'bottom'|string|number} ySpec - vertical anchor specification (could be either `'top'|'center'|'bottom'` or a percentage `'50%'` or a fixed decimal `Number`)
91
+ * @param {{width: number, height: number}?} size - can be specified if already known, to avoid extra dom calculations. This is the outer size of the element, including padding and borders.
92
+ * @param {boolean?} [rtl] - if not specified and values like `'start'`/`'end'` are use, then `rtl` is auto detected
93
+ * @returns {{left: number, top: number, right: number, bottom: number, xSpec: string|number, ySpec: string|number}}
94
+ */
95
+ declare const anchoredPosition: (el: Element | undefined, xSpec: string | number, ySpec: string | number, size?: {
96
+ width: number;
97
+ height: number;
98
+ }, rtl?: boolean | null) => {
99
+ left: number;
100
+ top: number;
101
+ right: number;
102
+ bottom: number;
103
+ xSpec: string | number;
104
+ ySpec: string | number;
105
+ };
106
+ declare const timeToMs: (value?: string) => number | undefined;
107
+ declare const isTimeString: (value: string) => boolean;
108
+ /**
109
+ *
110
+ * @param {string} transition
111
+ * @return {{duration: number, delay: number, name: string, timingFunction: string?}}
112
+ */
113
+ declare const parseSingleTransition: (transition: string) => {
114
+ duration?: number;
115
+ delay?: number;
116
+ name: string;
117
+ timingFunction?: string;
118
+ };
119
+ /**
120
+ *
121
+ * @param {string} transition
122
+ * @return {{duration: number, delay: number, name: string, timingFunction: string?}[]}
123
+ */
124
+ declare const parseTransition: (transition: string) => {
125
+ duration?: number;
126
+ delay?: number;
127
+ name: string;
128
+ timingFunction?: string;
129
+ }[];
130
+ export { getCssProps, setCssProps, getElementWidth, getElementHeight, setElementWidth, setElementHeight, getPseudoElementWidth, getPseudoElementHeight, getElementOffset, anchoredPosition, parseTransition, parseSingleTransition, isTimeString, timeToMs, };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @param {string} tag
3
+ * @param {Object<string, string>} [attrs]
4
+ * @param {Node|Node[]} [children]
5
+ * @returns {Element}
6
+ */
7
+ declare const createElement: (tag: string, attrs?: Record<string, unknown>, children?: Node | Node[]) => Element;
8
+ /**
9
+ * @param {Element} el
10
+ * @param {Object<string, string>} attrs
11
+ */
12
+ declare const setElementAttrs: (el: Element, attrs: Record<string, unknown>) => void;
13
+ /**
14
+ * @param {Element} el
15
+ * @param {string} selector
16
+ * @param {Node} [until]
17
+ * @returns {Node|null}
18
+ */
19
+ declare const closestUntil: (el: Element, selector: string, until?: Node) => Element | null;
20
+ /**
21
+ * @param {Element} el
22
+ * @param {string} selector
23
+ * @returns {Element|null}
24
+ */
25
+ declare const prev: (el: Element, selector: string) => Element | null;
26
+ /**
27
+ * @param {Element} el
28
+ * @param {string} selector
29
+ * @returns {null|Element}
30
+ */
31
+ declare const next: (el: Element, selector: string) => Element | null;
32
+ declare const unwrapChildren: (el: Element) => void;
33
+ export { createElement, setElementAttrs, closestUntil, prev, next, unwrapChildren, };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @param {Node} el
3
+ * @returns {Node|null}
4
+ */
5
+ declare const getRootNode: (el: Node) => Node | null;
6
+ /**
7
+ * @param {Node} el
8
+ * @param {string} selector
9
+ * @returns {Node|null}
10
+ */
11
+ declare const closest: (el: Element, selector: string) => Element | null;
12
+ /**
13
+ * @param {Element} el
14
+ */
15
+ declare const remove: (el: Element) => void;
16
+ /**
17
+ * @param {ChildNode} before
18
+ * @param {(Node|string)[]} nodes
19
+ */
20
+ declare const before: (before: ChildNode, ...nodes: (Node | string)[]) => void;
21
+ /**
22
+ * @param {ChildNode} after
23
+ * @param {(Node|string)[]} nodes
24
+ */
25
+ declare const after: (after: ChildNode, ...nodes: (Node | string)[]) => void;
26
+ /**
27
+ * @param {ParentNode|Element} parent
28
+ * @param {(Node|string)[]} nodes
29
+ */
30
+ declare const prepend: (parent: ParentNode, ...nodes: (Node | string)[]) => void;
31
+ /**
32
+ * @param {ParentNode|Element} parent
33
+ * @param {(Node|string)[]} nodes
34
+ */
35
+ declare const append: (parent: ParentNode, ...nodes: (Node | string)[]) => void;
36
+ /**
37
+ * @param {Element} el
38
+ * @param {string} selector
39
+ * @returns {Element|null}
40
+ */
41
+ declare const scopedSelector: (el: Element, selector: string) => Element | null;
42
+ /**
43
+ * @param {Element} el
44
+ * @param {string} selector
45
+ * @returns {NodeListOf<Element>}
46
+ */
47
+ declare const scopedSelectorAll: (el: Element, selector: string) => NodeListOf<Element>;
48
+ /**
49
+ * @param {Element} el
50
+ * @param {string} className
51
+ * @param {boolean?} [toggle]
52
+ * @returns {boolean} `true` if the class name is now present
53
+ */
54
+ declare const toggleClass: (el: Element, className: string, toggle?: boolean) => boolean;
55
+ export { getRootNode, closest, remove, before, after, prepend, append, scopedSelector, scopedSelectorAll, toggleClass, };
@@ -0,0 +1,20 @@
1
+ export default class DomEventsSink {
2
+ private _events;
3
+ constructor();
4
+ /**
5
+ * @param {EventTarget} el
6
+ * @param {string} eventName
7
+ * @param {EventListenerOrEventListenerObject} handler
8
+ * @param {boolean|AddEventListenerOptions} [optionsOrCapture=undefined]
9
+ * @returns {DomEventsSink}
10
+ */
11
+ add(el: EventTarget, eventName: string, handler: EventListenerOrEventListenerObject, optionsOrCapture?: boolean | AddEventListenerOptions): DomEventsSink;
12
+ /**
13
+ * @param {EventTarget} [el=undefined]
14
+ * @param {string} [eventName=undefined]
15
+ * @param {EventListenerOrEventListenerObject} [handler=undefined]
16
+ * @param {boolean|EventListenerOptions} [optionsOrCapture=undefined]
17
+ * @returns {DomEventsSink}
18
+ */
19
+ remove(el?: EventTarget, eventName?: string, handler?: EventListenerOrEventListenerObject, optionsOrCapture?: boolean | EventListenerOptions): DomEventsSink;
20
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @param {Element} el
3
+ * @param {number} left
4
+ * @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
5
+ * @returns {number}
6
+ */
7
+ declare function calculateNativeScrollLeftForLeft(el: Element, left: number, rtl?: boolean): number;
8
+ /**
9
+ * @param {Element} el
10
+ * @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
11
+ * @returns {number}
12
+ */
13
+ declare function getScrollLeft(el: Element, rtl?: boolean): number;
14
+ /**
15
+ * @param {Element} el
16
+ * @param {number} left
17
+ * @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
18
+ */
19
+ declare function setScrollLeft(el: Element, left: number, rtl?: boolean): void;
20
+ /**
21
+ * @param {Element} el
22
+ * @param {number} value
23
+ * @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
24
+ * @returns {number}
25
+ */
26
+ declare function calculateNativeScrollLeftForHorz(el: Element, value: number, rtl?: boolean): number;
27
+ /**
28
+ * @param {Element} el
29
+ * @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
30
+ * @returns {number}
31
+ */
32
+ declare function getScrollHorz(el: Element, rtl?: boolean): number;
33
+ /**
34
+ * @param {Element} el
35
+ * @param {number} horz
36
+ * @param {boolean|undefined} [rtl] if unspecified, then it's automatically detected.
37
+ */
38
+ declare function setScrollHorz(el: Element, horz: number, rtl?: boolean): void;
39
+ export { calculateNativeScrollLeftForLeft, getScrollLeft, setScrollLeft, calculateNativeScrollLeftForHorz, getScrollHorz, setScrollHorz, };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @param {Element} el
3
+ * @param {Object} [options]
4
+ * @param {number|undefined} [options.distance=9]
5
+ * @param {function(event: TouchEvent)} [options.handler]
6
+ * @returns {{ unbind: Function }}
7
+ */
8
+ declare const bindTouchTap: (el: Element, options: {
9
+ distance?: number | null;
10
+ handler?: (event: TouchEvent) => void;
11
+ }) => {
12
+ unbind: () => void;
13
+ };
14
+ export { bindTouchTap, };
@@ -0,0 +1,7 @@
1
+ import * as Css from './Css';
2
+ import * as Dom from './Dom';
3
+ import * as DomCompat from './DomCompat';
4
+ import * as DomEventsSink from './DomEventsSink';
5
+ import * as Touches from './Touches';
6
+ import * as ScrollHelper from './ScrollHelper';
7
+ export { Css, Dom, DomCompat, DomEventsSink, Touches, ScrollHelper, };
package/eslint.config.mjs CHANGED
@@ -1,136 +1,72 @@
1
- import globals from "globals";
2
- import path from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import js from "@eslint/js";
5
- import { FlatCompat } from "@eslint/eslintrc";
1
+ import eslint from '@eslint/js';
2
+ import globals from 'globals';
3
+ import tseslint from 'typescript-eslint';
6
4
 
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
- const compat = new FlatCompat({
10
- baseDirectory: __dirname,
11
- recommendedConfig: js.configs.recommended,
12
- allConfig: js.configs.all,
13
- });
14
-
15
- export default [
5
+ export default tseslint.config(
16
6
  {
17
- ignores: [
18
- "tests/**/*",
19
- "test/**/*",
20
- "!tests/**/*tests.js",
21
- "!test/**/*tests.js",
22
- "!tests/**/*_test.js",
23
- "!test/**/*_test.js",
24
- "!tests/**/*_helpers.js",
25
- "!test/**/*_helpers.js",
26
- "dist/**/*",
27
- "example/**/*",
28
- ],
7
+ ignores: ['dist/**', '.tsbuild/**', 'node_modules/**'],
29
8
  },
30
- ...compat.extends("eslint:recommended"),
9
+ eslint.configs.recommended,
10
+ ...tseslint.configs.recommended.map(config => ({
11
+ ...config,
12
+ files: ['lib/**/*.ts', 'scripts/**/*.ts', 'tests/**/*.ts'],
13
+ })),
31
14
  {
15
+ files: ['lib/**/*.ts'],
32
16
  languageOptions: {
33
- globals: {
34
- ...Object.fromEntries(Object.entries(globals.node).map(([key]) => [key, "off"])),
35
- ...globals.browser,
36
- },
37
-
38
- ecmaVersion: 2020,
39
- sourceType: "module",
17
+ globals: globals.browser,
40
18
  },
41
-
42
19
  rules: {
43
- semi: ["warn", "always"],
44
- "comma-dangle": ["warn", "always-multiline"],
45
- "comma-style": ["warn", "last"],
46
- "no-var": ["warn"],
47
-
48
- "arrow-spacing": ["warn", {
49
- before: true,
50
- after: true,
51
- }],
52
-
53
- "space-infix-ops": ["warn", {
54
- int32Hint: true,
20
+ '@typescript-eslint/no-explicit-any': 'warn',
21
+ '@typescript-eslint/no-unused-expressions': 'off',
22
+ 'prefer-const': 'off',
23
+ '@typescript-eslint/no-unused-vars': ['warn', {
24
+ argsIgnorePattern: '^_',
25
+ caughtErrorsIgnorePattern: '^ignore',
55
26
  }],
56
-
57
- "keyword-spacing": ["warn", {
58
- before: true,
59
- after: true,
60
- }],
61
-
62
- "space-unary-ops": ["warn", {
63
- words: true,
64
- nonwords: false,
65
- }],
66
-
67
- "comma-spacing": ["warn", {
68
- before: false,
69
- after: true,
70
- }],
71
-
72
- "object-curly-spacing": ["warn", "always"],
73
-
74
- "no-unused-vars": ["warn", {
75
- vars: "all",
76
- args: "after-used",
77
- varsIgnorePattern: "[iIgnored]|^_",
78
- ignoreRestSiblings: false,
79
- argsIgnorePattern: "^_",
80
- caughtErrors: "all",
81
- caughtErrorsIgnorePattern: "^ignore",
82
- }],
83
-
84
- "no-console": "warn",
85
- "no-extra-semi": "warn",
86
- "no-unreachable": "warn",
87
-
88
- "no-fallthrough": ["error", {
89
- commentPattern: "break[\\s\\w]*omitted|fallthrough",
90
- }],
91
-
92
- "no-useless-escape": "warn",
93
- "no-constant-condition": "warn",
94
- "no-return-await": "warn",
95
- "no-async-promise-executor": "warn",
96
27
  },
97
28
  },
98
29
  {
99
- files: [
100
- "tests/**/*tests.js",
101
- "test/**/*tests.js",
102
- "tests/**/*_test.js",
103
- "test/**/*_test.js",
104
- ],
105
-
106
- languageOptions: {
107
- globals: {
108
- ...Object.fromEntries(Object.entries(globals.browser).map(([key]) => [key, "off"])),
109
- ...globals.node,
110
- ...globals.mocha,
111
- ...globals.jest,
112
- },
113
- },
114
-
30
+ files: ['lib/Css.ts'],
115
31
  rules: {
116
- "no-console": "off",
32
+ '@typescript-eslint/no-explicit-any': 'off',
117
33
  },
118
34
  },
119
35
  {
120
- files: ["*db*/**/migrations/**/*.js"],
121
-
36
+ files: ['scripts/**/*.ts'],
37
+ languageOptions: {
38
+ globals: globals.node,
39
+ },
122
40
  rules: {
123
- "no-console": "off",
41
+ '@typescript-eslint/no-explicit-any': 'warn',
124
42
  },
125
43
  },
126
44
  {
127
- files: ["scripts/**/*.js", "**/eslint.config.mjs"],
128
-
45
+ files: ['tests/**/*.ts'],
129
46
  languageOptions: {
130
47
  globals: {
131
- ...Object.fromEntries(Object.entries(globals.browser).map(([key]) => [key, "off"])),
132
48
  ...globals.node,
49
+ ...globals.browser,
133
50
  },
134
51
  },
135
52
  },
136
- ];
53
+ {
54
+ files: ['scripts/**/*.js', 'eslint.config.mjs'],
55
+ languageOptions: {
56
+ globals: globals.node,
57
+ },
58
+ rules: {
59
+ 'no-unused-vars': ['warn', {
60
+ argsIgnorePattern: '^_',
61
+ }],
62
+ },
63
+ },
64
+ {
65
+ rules: {
66
+ semi: ['warn', 'always'],
67
+ 'comma-dangle': ['warn', 'always-multiline'],
68
+ 'no-fallthrough': 'error',
69
+ 'no-console': 'warn',
70
+ },
71
+ },
72
+ );