fhdp-extenders 4.10.6-SNAPSHOT-1696606565019 → 4.10.6

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.
@@ -1,71 +1,71 @@
1
- const rules = [];
2
- const exclusion = [];
3
-
4
- (window as any).getRules = () => rules;
5
- (window as any).getExclustions = () => exclusion;
6
-
7
- const callback = async (mutationsList, observer) => {
8
- for (const rule of rules) {
9
- for(const mutation of mutationsList) {
10
- try {
11
- const exclustions = await Promise.all(exclusion.map(async ex => await ex.condition(mutation)));
12
- const excluded = exclustions.indexOf(true) > -1;
13
- if (!excluded) {
14
- if ((mutation.type === 'childList' || mutation.type === 'attributes') && await rule.condition(mutation)) {
15
- await rule.mutator(mutation);
16
- }
17
- }
18
- } catch (e) {
19
- console.error(e.message, `\n on rule: `, rule, '\n on mutator: ', mutation);
20
- }
21
- }
22
- }
23
- };
24
-
25
- export const dynamicRelocator = (elQuery: string) => {
26
- if (!document.querySelector(elQuery)) {
27
- return;
28
- }
29
- const config = { attributes: true, childList: true, subtree: true };
30
- const targetNode = document.querySelector(elQuery);
31
- const observer = new MutationObserver(callback);
32
- observer.observe(targetNode, config);
33
-
34
- window.onresize = async () => {
35
- const f = async () => {
36
- for (const rule of rules) {
37
- const mutation = {target: document.querySelector(rule.selector)}
38
- try {
39
- if (!!mutation.target) {
40
- const excluded = exclusion.map(ex => ex.condition(mutation)).indexOf(true) > -1;
41
- if (!excluded) {
42
- if (await rule.condition(mutation)) {
43
- await rule.mutator(mutation);
44
- }
45
- }
46
- }
47
- } catch (e) {
48
- console.error(e.message, `\n on rule: `, rule, '\n on mutator: ', mutation);
49
- }
50
- clearTimeout((window as any).resizeTimer);
51
- (window as any).resizeTimer = undefined;
52
- }
53
- }
54
- if ((window as any).resizeTimer) {
55
- clearTimeout((window as any).resizeTimer);
56
- (window as any).resizeTimer = undefined;
57
- }
58
- (window as any).resizeTimer = setTimeout(f, 200);
59
- };
60
- return observer;
61
- }
62
-
63
- export const addRule = (selector: string, condition: (mutation) => Promise<boolean>, mutator: (mutation) => Promise<void>) => {
64
- const executor = dynamicRelocator(selector);
65
- rules.push({selector, condition, mutator, executor});
66
- }
67
-
68
- export const excludeRule = (selector: string, condition: (mutation) => Promise<boolean>) => {
69
- exclusion.push({selector, condition});
70
- }
71
-
1
+ const rules = [];
2
+ const exclusion = [];
3
+
4
+ (window as any).getRules = () => rules;
5
+ (window as any).getExclustions = () => exclusion;
6
+
7
+ const callback = async (mutationsList, observer) => {
8
+ for (const rule of rules) {
9
+ for(const mutation of mutationsList) {
10
+ try {
11
+ const exclustions = await Promise.all(exclusion.map(async ex => await ex.condition(mutation)));
12
+ const excluded = exclustions.indexOf(true) > -1;
13
+ if (!excluded) {
14
+ if ((mutation.type === 'childList' || mutation.type === 'attributes') && await rule.condition(mutation)) {
15
+ await rule.mutator(mutation);
16
+ }
17
+ }
18
+ } catch (e) {
19
+ console.error(e.message, `\n on rule: `, rule, '\n on mutator: ', mutation);
20
+ }
21
+ }
22
+ }
23
+ };
24
+
25
+ export const dynamicRelocator = (elQuery: string) => {
26
+ if (!document.querySelector(elQuery)) {
27
+ return;
28
+ }
29
+ const config = { attributes: true, childList: true, subtree: true };
30
+ const targetNode = document.querySelector(elQuery);
31
+ const observer = new MutationObserver(callback);
32
+ observer.observe(targetNode, config);
33
+
34
+ window.onresize = async () => {
35
+ const f = async () => {
36
+ for (const rule of rules) {
37
+ const mutation = {target: document.querySelector(rule.selector)}
38
+ try {
39
+ if (!!mutation.target) {
40
+ const excluded = exclusion.map(ex => ex.condition(mutation)).indexOf(true) > -1;
41
+ if (!excluded) {
42
+ if (await rule.condition(mutation)) {
43
+ await rule.mutator(mutation);
44
+ }
45
+ }
46
+ }
47
+ } catch (e) {
48
+ console.error(e.message, `\n on rule: `, rule, '\n on mutator: ', mutation);
49
+ }
50
+ clearTimeout((window as any).resizeTimer);
51
+ (window as any).resizeTimer = undefined;
52
+ }
53
+ }
54
+ if ((window as any).resizeTimer) {
55
+ clearTimeout((window as any).resizeTimer);
56
+ (window as any).resizeTimer = undefined;
57
+ }
58
+ (window as any).resizeTimer = setTimeout(f, 200);
59
+ };
60
+ return observer;
61
+ }
62
+
63
+ export const addRule = (selector: string, condition: (mutation) => Promise<boolean>, mutator: (mutation) => Promise<void>) => {
64
+ const executor = dynamicRelocator(selector);
65
+ rules.push({selector, condition, mutator, executor});
66
+ }
67
+
68
+ export const excludeRule = (selector: string, condition: (mutation) => Promise<boolean>) => {
69
+ exclusion.push({selector, condition});
70
+ }
71
+