accented 0.0.0-20250124142030 → 0.0.0-20250223121749

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 (124) hide show
  1. package/README.md +55 -3
  2. package/dist/accented.d.ts +3 -1
  3. package/dist/accented.d.ts.map +1 -1
  4. package/dist/accented.js +69 -50
  5. package/dist/accented.js.map +1 -1
  6. package/dist/constants.d.ts +3 -0
  7. package/dist/constants.d.ts.map +1 -0
  8. package/dist/constants.js +3 -0
  9. package/dist/constants.js.map +1 -0
  10. package/dist/dom-updater.d.ts +1 -1
  11. package/dist/dom-updater.d.ts.map +1 -1
  12. package/dist/dom-updater.js +26 -19
  13. package/dist/dom-updater.js.map +1 -1
  14. package/dist/elements/{accented-container.d.ts → accented-dialog.d.ts} +10 -4
  15. package/dist/elements/accented-dialog.d.ts.map +1 -0
  16. package/dist/elements/accented-dialog.js +361 -0
  17. package/dist/elements/accented-dialog.js.map +1 -0
  18. package/dist/elements/accented-trigger.d.ts +359 -0
  19. package/dist/elements/accented-trigger.d.ts.map +1 -0
  20. package/dist/elements/accented-trigger.js +159 -0
  21. package/dist/elements/accented-trigger.js.map +1 -0
  22. package/dist/intersection-observer.d.ts +5 -0
  23. package/dist/intersection-observer.d.ts.map +1 -0
  24. package/dist/intersection-observer.js +28 -0
  25. package/dist/intersection-observer.js.map +1 -0
  26. package/dist/log-and-rethrow.d.ts +2 -0
  27. package/dist/log-and-rethrow.d.ts.map +1 -0
  28. package/dist/log-and-rethrow.js +7 -0
  29. package/dist/log-and-rethrow.js.map +1 -0
  30. package/dist/logger.d.ts.map +1 -1
  31. package/dist/logger.js +10 -5
  32. package/dist/logger.js.map +1 -1
  33. package/dist/register-elements.d.ts +2 -0
  34. package/dist/register-elements.d.ts.map +1 -0
  35. package/dist/register-elements.js +21 -0
  36. package/dist/register-elements.js.map +1 -0
  37. package/dist/resize-listener.d.ts +2 -0
  38. package/dist/resize-listener.d.ts.map +1 -0
  39. package/dist/resize-listener.js +18 -0
  40. package/dist/resize-listener.js.map +1 -0
  41. package/dist/scanner.d.ts +2 -2
  42. package/dist/scanner.d.ts.map +1 -1
  43. package/dist/scanner.js +97 -33
  44. package/dist/scanner.js.map +1 -1
  45. package/dist/scroll-listeners.d.ts +2 -0
  46. package/dist/scroll-listeners.d.ts.map +1 -0
  47. package/dist/scroll-listeners.js +38 -0
  48. package/dist/scroll-listeners.js.map +1 -0
  49. package/dist/state.d.ts +1 -0
  50. package/dist/state.d.ts.map +1 -1
  51. package/dist/state.js +6 -0
  52. package/dist/state.js.map +1 -1
  53. package/dist/types.d.ts +70 -18
  54. package/dist/types.d.ts.map +1 -1
  55. package/dist/types.js +1 -0
  56. package/dist/types.js.map +1 -1
  57. package/dist/utils/deep-merge.js +1 -1
  58. package/dist/utils/deep-merge.js.map +1 -1
  59. package/dist/utils/get-element-html.d.ts +2 -0
  60. package/dist/utils/get-element-html.d.ts.map +1 -0
  61. package/dist/utils/get-element-html.js +14 -0
  62. package/dist/utils/get-element-html.js.map +1 -0
  63. package/dist/utils/get-element-position.d.ts +3 -0
  64. package/dist/utils/get-element-position.d.ts.map +1 -0
  65. package/dist/utils/get-element-position.js +22 -0
  66. package/dist/utils/get-element-position.js.map +1 -0
  67. package/dist/utils/get-scrollable-ancestors.d.ts +2 -0
  68. package/dist/utils/get-scrollable-ancestors.d.ts.map +1 -0
  69. package/dist/utils/get-scrollable-ancestors.js +15 -0
  70. package/dist/utils/get-scrollable-ancestors.js.map +1 -0
  71. package/dist/utils/recalculate-positions.d.ts +2 -0
  72. package/dist/utils/recalculate-positions.d.ts.map +1 -0
  73. package/dist/utils/recalculate-positions.js +27 -0
  74. package/dist/utils/recalculate-positions.js.map +1 -0
  75. package/dist/utils/recalculate-scrollable-ancestors.d.ts +2 -0
  76. package/dist/utils/recalculate-scrollable-ancestors.d.ts.map +1 -0
  77. package/dist/utils/recalculate-scrollable-ancestors.js +13 -0
  78. package/dist/utils/recalculate-scrollable-ancestors.js.map +1 -0
  79. package/dist/utils/supports-anchor-positioning.d.ts +6 -0
  80. package/dist/utils/supports-anchor-positioning.d.ts.map +1 -0
  81. package/dist/utils/supports-anchor-positioning.js +4 -0
  82. package/dist/utils/supports-anchor-positioning.js.map +1 -0
  83. package/dist/utils/transform-violations.d.ts.map +1 -1
  84. package/dist/utils/transform-violations.js +9 -0
  85. package/dist/utils/transform-violations.js.map +1 -1
  86. package/dist/utils/update-elements-with-issues.d.ts +3 -1
  87. package/dist/utils/update-elements-with-issues.d.ts.map +1 -1
  88. package/dist/utils/update-elements-with-issues.js +25 -7
  89. package/dist/utils/update-elements-with-issues.js.map +1 -1
  90. package/dist/validate-options.d.ts +3 -0
  91. package/dist/validate-options.d.ts.map +1 -0
  92. package/dist/validate-options.js +42 -0
  93. package/dist/validate-options.js.map +1 -0
  94. package/package.json +2 -1
  95. package/src/accented.ts +78 -58
  96. package/src/constants.ts +2 -0
  97. package/src/dom-updater.ts +26 -18
  98. package/src/elements/accented-dialog.ts +384 -0
  99. package/src/elements/accented-trigger.ts +179 -0
  100. package/src/intersection-observer.ts +28 -0
  101. package/src/log-and-rethrow.ts +9 -0
  102. package/src/logger.ts +11 -6
  103. package/src/register-elements.ts +21 -0
  104. package/src/resize-listener.ts +17 -0
  105. package/src/scanner.ts +108 -37
  106. package/src/scroll-listeners.ts +37 -0
  107. package/src/state.ts +12 -0
  108. package/src/types.ts +77 -19
  109. package/src/utils/deep-merge.test.ts +7 -0
  110. package/src/utils/deep-merge.ts +1 -1
  111. package/src/utils/get-element-html.ts +13 -0
  112. package/src/utils/get-element-position.ts +21 -0
  113. package/src/utils/get-scrollable-ancestors.ts +14 -0
  114. package/src/utils/recalculate-positions.ts +27 -0
  115. package/src/utils/recalculate-scrollable-ancestors.ts +13 -0
  116. package/src/utils/supports-anchor-positioning.ts +7 -0
  117. package/src/utils/transform-violations.ts +12 -1
  118. package/src/utils/update-elements-with-issues.test.ts +90 -16
  119. package/src/utils/update-elements-with-issues.ts +40 -20
  120. package/src/validate-options.ts +44 -0
  121. package/dist/elements/accented-container.d.ts.map +0 -1
  122. package/dist/elements/accented-container.js +0 -131
  123. package/dist/elements/accented-container.js.map +0 -1
  124. package/src/elements/accented-container.ts +0 -147
@@ -0,0 +1,21 @@
1
+ import getAccentedTrigger from './elements/accented-trigger.js';
2
+ import getAccentedDialog from './elements/accented-dialog.js';
3
+ export default function registerElements(name) {
4
+ const elements = [
5
+ {
6
+ elementName: `${name}-trigger`,
7
+ Component: getAccentedTrigger(name)
8
+ },
9
+ {
10
+ elementName: `${name}-dialog`,
11
+ Component: getAccentedDialog()
12
+ }
13
+ ];
14
+ for (const { elementName, Component } of elements) {
15
+ if (!customElements.get(elementName)) {
16
+ customElements.define(elementName, Component);
17
+ }
18
+ }
19
+ }
20
+ ;
21
+ //# sourceMappingURL=register-elements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-elements.js","sourceRoot":"","sources":["../src/register-elements.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,gCAAgC,CAAC;AAChE,OAAO,iBAAiB,MAAM,+BAA+B,CAAC;AAE9D,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,IAAY;IACnD,MAAM,QAAQ,GAAG;QACf;YACE,WAAW,EAAE,GAAG,IAAI,UAAU;YAC9B,SAAS,EAAE,kBAAkB,CAAC,IAAI,CAAC;SACpC;QACD;YACE,WAAW,EAAE,GAAG,IAAI,SAAS;YAC7B,SAAS,EAAE,iBAAiB,EAAE;SAC/B;KACF,CAAC;IAEF,KAAK,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,QAAQ,EAAE,CAAC;QAClD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YACrC,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;AACH,CAAC;AAAA,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function setupResizeListener(): () => void;
2
+ //# sourceMappingURL=resize-listener.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resize-listener.d.ts","sourceRoot":"","sources":["../src/resize-listener.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,mBAAmB,eAa1C"}
@@ -0,0 +1,18 @@
1
+ import logAndRethrow from './log-and-rethrow.js';
2
+ import recalculatePositions from './utils/recalculate-positions.js';
3
+ export default function setupResizeListener() {
4
+ const abortController = new AbortController();
5
+ window.addEventListener('resize', () => {
6
+ try {
7
+ recalculatePositions();
8
+ }
9
+ catch (error) {
10
+ logAndRethrow(error);
11
+ }
12
+ }, { signal: abortController.signal });
13
+ return () => {
14
+ abortController.abort();
15
+ };
16
+ }
17
+ ;
18
+ //# sourceMappingURL=resize-listener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resize-listener.js","sourceRoot":"","sources":["../src/resize-listener.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,sBAAsB,CAAC;AACjD,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAEpE,MAAM,CAAC,OAAO,UAAU,mBAAmB;IACzC,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;IAC9C,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE;QACrC,IAAI,CAAC;YACH,oBAAoB,EAAE,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,aAAa,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,EAAE,EAAE,MAAM,EAAE,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC;IAEvC,OAAO,GAAG,EAAE;QACV,eAAe,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC,CAAC;AACJ,CAAC;AAAA,CAAC"}
package/dist/scanner.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { Throttle, Callback } from './types';
2
- export default function createScanner(name: string, throttle: Required<Throttle>, callback: Callback): () => void;
1
+ import type { AxeOptions, Throttle, Callback, AxeContext } from './types';
2
+ export default function createScanner(name: string, axeContext: AxeContext, axeOptions: AxeOptions, throttle: Required<Throttle>, callback: Callback): () => void;
3
3
  //# sourceMappingURL=scanner.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGlD,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,cA6DnG"}
1
+ {"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAQ1E,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,cA+HnJ"}
package/dist/scanner.js CHANGED
@@ -2,47 +2,111 @@ import axe from 'axe-core';
2
2
  import TaskQueue from './task-queue.js';
3
3
  import { elementsWithIssues, enabled, extendedElementsWithIssues } from './state.js';
4
4
  import updateElementsWithIssues from './utils/update-elements-with-issues.js';
5
- export default function createScanner(name, throttle, callback) {
5
+ import recalculatePositions from './utils/recalculate-positions.js';
6
+ import recalculateScrollableAncestors from './utils/recalculate-scrollable-ancestors.js';
7
+ import supportsAnchorPositioning from './utils/supports-anchor-positioning.js';
8
+ import { issuesUrl } from './constants.js';
9
+ import logAndRethrow from './log-and-rethrow.js';
10
+ export default function createScanner(name, axeContext, axeOptions, throttle, callback) {
11
+ const axeRunningWindowProp = `__${name}_axe_running__`;
12
+ const win = window;
6
13
  const taskQueue = new TaskQueue(async () => {
7
- performance.mark('axe-start');
8
- const result = await axe.run({
9
- elementRef: true,
10
- // Although axe-core can perform iframe scanning, I haven't succeeded in it,
11
- // and the docs suggest that the axe-core script should be explicitly included
12
- // in each of the iframed documents anyway.
13
- // It seems preferable to disallow iframe scanning and not report issues in elements within iframes
14
- // in the case that such issues are for some reason reported by axe-core.
15
- // A consumer of Accented can instead scan the iframed document by calling Accented initialization from that document.
16
- iframes: false
17
- });
18
- const axeMeasure = performance.measure('axe', 'axe-start');
19
- if (!enabled.value) {
14
+ // We may see errors coming from axe-core when Accented is toggled off and on in qiuck succession,
15
+ // which I've seen happen with hot reloading of a React application.
16
+ // This window property serves as a circuit breaker for that particular case.
17
+ if (win[axeRunningWindowProp]) {
20
18
  return;
21
19
  }
22
- updateElementsWithIssues(extendedElementsWithIssues, result.violations, window, name);
23
- callback({
24
- elementsWithIssues: elementsWithIssues.value,
25
- scanDuration: Math.round(axeMeasure.duration)
26
- });
20
+ try {
21
+ performance.mark('axe-start');
22
+ win[axeRunningWindowProp] = true;
23
+ let result;
24
+ try {
25
+ // TODO (https://github.com/pomerantsev/accented/issues/102):
26
+ // only run Axe on what's changed, not on the whole axeContext
27
+ result = await axe.run(axeContext, {
28
+ elementRef: true,
29
+ // Although axe-core can perform iframe scanning, I haven't succeeded in it,
30
+ // and the docs suggest that the axe-core script should be explicitly included
31
+ // in each of the iframed documents anyway.
32
+ // It seems preferable to disallow iframe scanning and not report issues in elements within iframes
33
+ // in the case that such issues are for some reason reported by axe-core.
34
+ // A consumer of Accented can instead scan the iframed document by calling Accented initialization from that document.
35
+ iframes: false,
36
+ resultTypes: ['violations'],
37
+ ...axeOptions
38
+ });
39
+ }
40
+ catch (error) {
41
+ console.error('Accented: axe-core (the accessibility testing engine) threw an error. ' +
42
+ 'Check the `axeOptions` property that you’re passing to Accented. ' +
43
+ `If you still think it’s a bug in Accented, file an issue at ${issuesUrl}.\n`, error);
44
+ result = { violations: [] };
45
+ }
46
+ win[axeRunningWindowProp] = false;
47
+ const axeMeasure = performance.measure('axe', 'axe-start');
48
+ if (!enabled.value) {
49
+ return;
50
+ }
51
+ updateElementsWithIssues(extendedElementsWithIssues, result.violations, window, name);
52
+ callback({
53
+ elementsWithIssues: elementsWithIssues.value,
54
+ scanDuration: Math.round(axeMeasure.duration)
55
+ });
56
+ }
57
+ catch (error) {
58
+ win[axeRunningWindowProp] = false;
59
+ logAndRethrow(error);
60
+ }
27
61
  }, throttle);
62
+ // TODO (https://github.com/pomerantsev/accented/issues/102):
63
+ // limit to what's in axeContext,
64
+ // if that's an element or array of elements (not a selector).
28
65
  taskQueue.add(document);
66
+ const accentedElementNames = [`${name}-trigger`, `${name}-dialog`];
29
67
  const mutationObserver = new MutationObserver(mutationList => {
30
- const listWithoutAccentedContainers = mutationList.filter(mutationRecord => {
31
- return !(mutationRecord.type === 'childList' &&
32
- [...mutationRecord.addedNodes].every(node => node.nodeName === `${name}-container`.toUpperCase()) &&
33
- [...mutationRecord.removedNodes].every(node => node.nodeName === `${name}-container`.toUpperCase()));
34
- });
35
- const elementsWithAccentedAttributeChanges = listWithoutAccentedContainers.reduce((nodes, mutationRecord) => {
36
- if (mutationRecord.type === 'attributes' && mutationRecord.attributeName === `data-${name}`) {
37
- nodes.add(mutationRecord.target);
68
+ try {
69
+ // We're not interested in mutations that are caused exclusively by the custom elements
70
+ // introduced by Accented.
71
+ const listWithoutAccentedElements = mutationList.filter(mutationRecord => {
72
+ const onlyAccentedElementsAddedOrRemoved = mutationRecord.type === 'childList' &&
73
+ [...mutationRecord.addedNodes].every(node => accentedElementNames.includes(node.nodeName.toLowerCase())) &&
74
+ [...mutationRecord.removedNodes].every(node => accentedElementNames.includes(node.nodeName.toLowerCase()));
75
+ const accentedElementChanged = mutationRecord.type === 'attributes' &&
76
+ accentedElementNames.includes(mutationRecord.target.nodeName.toLowerCase());
77
+ return !(onlyAccentedElementsAddedOrRemoved || accentedElementChanged);
78
+ });
79
+ if (listWithoutAccentedElements.length !== 0 && !supportsAnchorPositioning(window)) {
80
+ // Something has changed in the DOM, so we need to realign all triggers with respective elements.
81
+ recalculatePositions();
82
+ // Elements' scrollable ancestors only change when styles change
83
+ // (specifically when the `display` prop on one of the ancestors changes),
84
+ // so a good place to recalculate the scrollable ancestors for elements is here.
85
+ // In future, we could further optimize this by only recalculating scrollable ancestors for elements that have changed.
86
+ recalculateScrollableAncestors();
38
87
  }
39
- return nodes;
40
- }, new Set());
41
- const filteredMutationList = listWithoutAccentedContainers.filter(mutationRecord => {
42
- return !elementsWithAccentedAttributeChanges.has(mutationRecord.target);
43
- });
44
- taskQueue.addMultiple(filteredMutationList.map(mutationRecord => mutationRecord.target));
88
+ // Exclude all mutations on elements that got the accented attribute added or removed.
89
+ // If we simply exclude all mutations where attributeName = `data-${name}`,
90
+ // we may miss other mutations on those same elements caused by Accented,
91
+ // leading to extra runs of the mutation observer.
92
+ const elementsWithAccentedAttributeChanges = listWithoutAccentedElements.reduce((nodes, mutationRecord) => {
93
+ if (mutationRecord.type === 'attributes' && mutationRecord.attributeName === `data-${name}`) {
94
+ nodes.add(mutationRecord.target);
95
+ }
96
+ return nodes;
97
+ }, new Set());
98
+ const filteredMutationList = listWithoutAccentedElements.filter(mutationRecord => {
99
+ return !elementsWithAccentedAttributeChanges.has(mutationRecord.target);
100
+ });
101
+ taskQueue.addMultiple(filteredMutationList.map(mutationRecord => mutationRecord.target));
102
+ }
103
+ catch (error) {
104
+ logAndRethrow(error);
105
+ }
45
106
  });
107
+ // TODO (https://github.com/pomerantsev/accented/issues/102):
108
+ // possibly limit the observer to what's in axeContext,
109
+ // if that's an element or array of elements (not a selector).
46
110
  mutationObserver.observe(document, {
47
111
  subtree: true,
48
112
  childList: true,
@@ -1 +1 @@
1
- {"version":3,"file":"scanner.js","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC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C;gBACnC,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC,EAAE,IAAI,GAAG,EAAQ,CAAC,CAAC;YAEpB,MAAM,oBAAoB,GAAG,2BAA2B,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;gBAC/E,OAAO,CAAC,oCAAoC,CAAC,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YAC1E,CAAC,CAAC,CAAC;YAEH,SAAS,CAAC,WAAW,CAAC,oBAAoB,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;QAC3F,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,aAAa,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,6DAA6D;IAC7D,uDAAuD;IACvD,8DAA8D;IAC9D,gBAAgB,CAAC,OAAO,CAAC,QAAQ,EAAE;QACjC,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,UAAU,EAAE,IAAI;QAChB,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,OAAO,GAAG,EAAE;QACV,gBAAgB,CAAC,UAAU,EAAE,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function setupScrollListeners(): () => void;
2
+ //# sourceMappingURL=scroll-listeners.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll-listeners.d.ts","sourceRoot":"","sources":["../src/scroll-listeners.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,OAAO,UAAU,oBAAoB,eA+B3C"}
@@ -0,0 +1,38 @@
1
+ import { effect } from '@preact/signals-core';
2
+ import recalculatePositions from './utils/recalculate-positions.js';
3
+ import { scrollableAncestors } from './state.js';
4
+ import logAndRethrow from './log-and-rethrow.js';
5
+ export default function setupScrollListeners() {
6
+ const documentAbortController = new AbortController();
7
+ document.addEventListener('scroll', () => {
8
+ try {
9
+ recalculatePositions();
10
+ }
11
+ catch (error) {
12
+ logAndRethrow(error);
13
+ }
14
+ }, { signal: documentAbortController.signal });
15
+ const disposeOfEffect = effect(() => {
16
+ // TODO: optimize performance, issue #81
17
+ const elementAbortController = new AbortController();
18
+ for (const scrollableAncestor of scrollableAncestors.value) {
19
+ scrollableAncestor.addEventListener('scroll', () => {
20
+ try {
21
+ recalculatePositions();
22
+ }
23
+ catch (error) {
24
+ logAndRethrow(error);
25
+ }
26
+ }, { signal: elementAbortController.signal });
27
+ }
28
+ return () => {
29
+ elementAbortController.abort();
30
+ };
31
+ });
32
+ return () => {
33
+ documentAbortController.abort();
34
+ disposeOfEffect();
35
+ };
36
+ }
37
+ ;
38
+ //# sourceMappingURL=scroll-listeners.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll-listeners.js","sourceRoot":"","sources":["../src/scroll-listeners.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,aAAa,MAAM,sBAAsB,CAAC;AAEjD,MAAM,CAAC,OAAO,UAAU,oBAAoB;IAC1C,MAAM,uBAAuB,GAAG,IAAI,eAAe,EAAE,CAAC;IACtD,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE;QACvC,IAAI,CAAC;YACH,oBAAoB,EAAE,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,aAAa,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,EAAE,EAAE,MAAM,EAAE,uBAAuB,CAAC,MAAM,EAAE,CAAC,CAAC;IAE/C,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,EAAE;QAClC,wCAAwC;QACxC,MAAM,sBAAsB,GAAG,IAAI,eAAe,EAAE,CAAC;QACrD,KAAK,MAAM,kBAAkB,IAAI,mBAAmB,CAAC,KAAK,EAAE,CAAC;YAC3D,kBAAkB,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE;gBACjD,IAAI,CAAC;oBACH,oBAAoB,EAAE,CAAC;gBACzB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,aAAa,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC;YACH,CAAC,EAAE,EAAE,MAAM,EAAE,sBAAsB,CAAC,MAAM,EAAE,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,GAAG,EAAE;YACV,sBAAsB,CAAC,KAAK,EAAE,CAAC;QACjC,CAAC,CAAA;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,EAAE;QACV,uBAAuB,CAAC,KAAK,EAAE,CAAC;QAChC,eAAe,EAAE,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AAAA,CAAC"}
package/dist/state.d.ts CHANGED
@@ -2,4 +2,5 @@ import type { ElementWithIssues, ExtendedElementWithIssues } from './types';
2
2
  export declare const enabled: import("@preact/signals-core").Signal<boolean>;
3
3
  export declare const extendedElementsWithIssues: import("@preact/signals-core").Signal<ExtendedElementWithIssues[]>;
4
4
  export declare const elementsWithIssues: import("@preact/signals-core").ReadonlySignal<ElementWithIssues[]>;
5
+ export declare const scrollableAncestors: import("@preact/signals-core").ReadonlySignal<Set<HTMLElement>>;
5
6
  //# sourceMappingURL=state.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAE5E,eAAO,MAAM,OAAO,gDAAgB,CAAC;AAErC,eAAO,MAAM,0BAA0B,oEAA+C,CAAC;AAEvF,eAAO,MAAM,kBAAkB,oEAG3B,CAAC"}
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAE5E,eAAO,MAAM,OAAO,gDAAgB,CAAC;AAErC,eAAO,MAAM,0BAA0B,oEAA+C,CAAC;AAEvF,eAAO,MAAM,kBAAkB,oEAG3B,CAAC;AAEL,eAAO,MAAM,mBAAmB,iEAU/B,CAAC"}
package/dist/state.js CHANGED
@@ -5,4 +5,10 @@ export const elementsWithIssues = computed(() => extendedElementsWithIssues.valu
5
5
  element: extendedElementWithIssues.element,
6
6
  issues: extendedElementWithIssues.issues.value
7
7
  })));
8
+ export const scrollableAncestors = computed(() => extendedElementsWithIssues.value.reduce((scrollableAncestors, extendedElementWithIssues) => {
9
+ for (const scrollableAncestor of extendedElementWithIssues.scrollableAncestors.value) {
10
+ scrollableAncestors.add(scrollableAncestor);
11
+ }
12
+ return scrollableAncestors;
13
+ }, new Set()));
8
14
  //# sourceMappingURL=state.js.map
package/dist/state.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIxD,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAErC,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAmC,EAAE,CAAC,CAAC;AAEvF,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAA2B,GAAG,EAAE,CAAC,0BAA0B,CAAC,KAAK,CAAC,GAAG,CAAC,yBAAyB,CAAC,EAAE,CAAC,CAAC;IAC5I,OAAO,EAAE,yBAAyB,CAAC,OAAO;IAC1C,MAAM,EAAE,yBAAyB,CAAC,MAAM,CAAC,KAAK;CAC/C,CAAC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIxD,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAErC,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAmC,EAAE,CAAC,CAAC;AAEvF,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAA2B,GAAG,EAAE,CAAC,0BAA0B,CAAC,KAAK,CAAC,GAAG,CAAC,yBAAyB,CAAC,EAAE,CAAC,CAAC;IAC5I,OAAO,EAAE,yBAAyB,CAAC,OAAO;IAC1C,MAAM,EAAE,yBAAyB,CAAC,MAAM,CAAC,KAAK;CAC/C,CAAC,CAAC,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,mBAAmB,GAAG,QAAQ,CAAmB,GAAG,EAAE,CACjE,0BAA0B,CAAC,KAAK,CAAC,MAAM,CACrC,CAAC,mBAAmB,EAAE,yBAAyB,EAAE,EAAE;IACjD,KAAK,MAAM,kBAAkB,IAAI,yBAAyB,CAAC,mBAAmB,CAAC,KAAK,EAAE,CAAC;QACrF,mBAAmB,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,mBAAmB,CAAC;AAC7B,CAAC,EACD,IAAI,GAAG,EAAe,CACvB,CACF,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,25 +1,33 @@
1
1
  import type axe from 'axe-core';
2
2
  import type { Signal } from '@preact/signals-core';
3
- import type { AccentedContainer } from './elements/accented-container';
4
- export type DeepRequired<T> = T extends object ? {
5
- [P in keyof T]-?: DeepRequired<T[P]>;
6
- } : T;
3
+ import type { AccentedTrigger } from './elements/accented-trigger';
7
4
  export type Throttle = {
8
5
  /**
9
6
  * The minimal time between scans.
10
7
  *
11
- * Default: 1000.
8
+ * Default: `1000`.
12
9
  * */
13
10
  wait?: number;
14
11
  /**
15
12
  * When to run the scan on Accented initialization or on a mutation.
16
13
  *
17
- * If true, the scan will run immediately. If false, the scan will run after the first throttle delay.
14
+ * If `true`, the scan will run immediately. If `false`, the scan will run after the first throttle delay.
18
15
  *
19
- * Default: true.
16
+ * Default: `true`.
20
17
  * */
21
18
  leading?: boolean;
22
19
  };
20
+ export type Output = {
21
+ /**
22
+ * Whether to output the issues to the console.
23
+ *
24
+ * Default: `true`.
25
+ * */
26
+ console?: boolean;
27
+ };
28
+ export type AxeContext = axe.ElementContext;
29
+ export declare const allowedAxeOptions: readonly ["rules", "runOnly"];
30
+ export type AxeOptions = Pick<axe.RunOptions, typeof allowedAxeOptions[number]>;
23
31
  type CallbackParams = {
24
32
  /**
25
33
  * The most current array of elements with issues.
@@ -32,22 +40,58 @@ type CallbackParams = {
32
40
  };
33
41
  export type Callback = (params: CallbackParams) => void;
34
42
  export type AccentedOptions = {
43
+ /**
44
+ * The `context` parameter for `axe.run()`.
45
+ *
46
+ * Determines what element(s) to scan for accessibility issues.
47
+ *
48
+ * Accepts a variety of shapes:
49
+ * * an element reference;
50
+ * * a selector;
51
+ * * a `NodeList`;
52
+ * * an include / exclude object;
53
+ * * and more.
54
+ *
55
+ * See documentation: https://www.deque.com/axe/core-documentation/api-documentation/#context-parameter
56
+ *
57
+ * Default: `document`.
58
+ */
59
+ axeContext?: AxeContext;
60
+ /**
61
+ * The `options` parameter for `axe.run()`.
62
+ *
63
+ * Accented only supports two keys of the `options` object:
64
+ * * `rules`;
65
+ * * `runOnly`.
66
+ *
67
+ * Both properties are optional, and both control
68
+ * which accessibility rules your page is tested against.
69
+ *
70
+ * See documentation: https://www.deque.com/axe/core-documentation/api-documentation/#options-parameter
71
+ *
72
+ * Default: `{}`.
73
+ */
74
+ axeOptions?: AxeOptions;
35
75
  /**
36
76
  * The character sequence that’s used in various elements, attributes and stylesheets that Accented adds to the page.
37
- * * The data attribute that’s added to elements with issues (default: "data-accented").
38
- * * The custom element that encapsulates the button and dialog attached to each element with issues (default: "accented-container").
39
- * * The CSS cascade layer containing page-wide Accented-specific styles (default: "accented").
40
- * * The prefix for some of the CSS custom properties used by Accented (default: "--accented-").
77
+ * * The data attribute that’s added to elements with issues (default: `data-accented`).
78
+ * * The custom elements for the button and the dialog that get created for each element with issues
79
+ * (default: `accented-trigger`, `accented-dialog`).
80
+ * * The CSS cascade layer containing page-wide Accented-specific styles (default: `accented`).
81
+ * * The prefix for some of the CSS custom properties used by Accented (default: `--accented-`).
82
+ * * The window property that’s used to prevent multiple axe-core scans from running simultaneously
83
+ * (default: `__accented_axe_running__`).
84
+ *
85
+ * Only lowercase alphanumeric characters and dashes (-) are allowed in the name,
86
+ * and it must start with a lowercase letter.
41
87
  *
42
- * Default: "accented".
88
+ * Default: `accented`.
43
89
  */
44
90
  name?: string;
45
91
  /**
46
- * Whether to output the issues to the console.
47
- *
48
- * Default: true.
92
+ * Output options object.
49
93
  * */
50
- outputToConsole?: boolean;
94
+ output?: Output;
51
95
  /**
52
96
  * Scan throttling options object.
53
97
  * */
@@ -55,7 +99,7 @@ export type AccentedOptions = {
55
99
  /**
56
100
  * A callback that will be called after each scan.
57
101
  *
58
- * Default: () => {}.
102
+ * Default: `() => {}`.
59
103
  * */
60
104
  callback?: Callback;
61
105
  };
@@ -64,6 +108,11 @@ export type AccentedOptions = {
64
108
  * stopping the scanning and removing all highlights from the page.
65
109
  */
66
110
  export type DisableAccented = () => void;
111
+ export type Position = {
112
+ inlineEndLeft: number;
113
+ blockStartTop: number;
114
+ direction: 'ltr' | 'rtl';
115
+ };
67
116
  export type Issue = {
68
117
  id: string;
69
118
  title: string;
@@ -77,7 +126,10 @@ export type ElementWithIssues = {
77
126
  };
78
127
  export type ExtendedElementWithIssues = Omit<ElementWithIssues, 'issues'> & {
79
128
  issues: Signal<ElementWithIssues['issues']>;
80
- accentedContainer: AccentedContainer;
129
+ visible: Signal<boolean>;
130
+ trigger: AccentedTrigger;
131
+ position: Signal<Position>;
132
+ scrollableAncestors: Signal<Set<HTMLElement>>;
81
133
  id: number;
82
134
  };
83
135
  export {};
@@ -1 +1 @@
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AC,QAAQ,CAAC,CAAC;IAC3B,mBAAmB,EAAE,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAA;IAC7C,EAAE,EAAE,MAAM,CAAA;CACX,CAAC"}
package/dist/types.js CHANGED
@@ -1 +1,2 @@
1
+ export const allowedAxeOptions = ['rules', 'runOnly'];
1
2
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAiCA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,SAAS,CAAU,CAAC"}
@@ -1,7 +1,7 @@
1
1
  export default function deepMerge(target, source) {
2
2
  const output = { ...target };
3
3
  for (const key of Object.keys(source)) {
4
- if (typeof source[key] === 'object' && source[key] !== null) {
4
+ if (typeof source[key] === 'object' && source[key] !== null && !Array.isArray(source[key])) {
5
5
  if (!(key in target)) {
6
6
  output[key] = source[key];
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"deep-merge.js","sourceRoot":"","sources":["../../src/utils/deep-merge.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,MAAiB,EAAE,MAAiB;IACpE,MAAM,MAAM,GAAG,EAAC,GAAG,MAAM,EAAC,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;YAC5D,IAAI,CAAC,CAAC,GAAG,IAAI,MAAM,CAAC,EAAE,CAAC;gBACrB,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;aACI,CAAC;YACJ,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"deep-merge.js","sourceRoot":"","sources":["../../src/utils/deep-merge.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,MAAiB,EAAE,MAAiB;IACpE,MAAM,MAAM,GAAG,EAAC,GAAG,MAAM,EAAC,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAC3F,IAAI,CAAC,CAAC,GAAG,IAAI,MAAM,CAAC,EAAE,CAAC;gBACrB,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;aACI,CAAC;YACJ,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function getElementHtml(element: Element): string;
2
+ //# sourceMappingURL=get-element-html.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-element-html.d.ts","sourceRoot":"","sources":["../../src/utils/get-element-html.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,OAAO,EAAE,OAAO,UAYtD"}
@@ -0,0 +1,14 @@
1
+ export default function getElementHtml(element) {
2
+ const outerHtml = element.outerHTML;
3
+ const innerHtml = element.innerHTML;
4
+ if (!innerHtml) {
5
+ return outerHtml;
6
+ }
7
+ const index = outerHtml.indexOf(innerHtml);
8
+ if (index === -1) {
9
+ // This shouldn't be happening, but if it does, we can just return the outer HTML.
10
+ return outerHtml;
11
+ }
12
+ return outerHtml.slice(0, index) + '…' + outerHtml.slice(index + innerHtml.length);
13
+ }
14
+ //# sourceMappingURL=get-element-html.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-element-html.js","sourceRoot":"","sources":["../../src/utils/get-element-html.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,OAAgB;IACrD,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IACpC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IACpC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3C,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QACjB,kFAAkF;QAClF,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AACrF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Position } from '../types';
2
+ export default function getElementPosition(element: Element, win: Window): Position;
3
+ //# sourceMappingURL=get-element-position.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-element-position.d.ts","sourceRoot":"","sources":["../../src/utils/get-element-position.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,QAAQ,CAkBlF"}
@@ -0,0 +1,22 @@
1
+ export default function getElementPosition(element, win) {
2
+ const rect = element.getBoundingClientRect();
3
+ const direction = win.getComputedStyle(element).direction;
4
+ if (direction === 'ltr') {
5
+ return {
6
+ inlineEndLeft: rect.right,
7
+ blockStartTop: rect.top,
8
+ direction
9
+ };
10
+ }
11
+ else if (direction === 'rtl') {
12
+ return {
13
+ inlineEndLeft: rect.left,
14
+ blockStartTop: rect.top,
15
+ direction
16
+ };
17
+ }
18
+ else {
19
+ throw new Error(`The element ${element} has a direction "${direction}", which is not supported.`);
20
+ }
21
+ }
22
+ //# sourceMappingURL=get-element-position.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-element-position.js","sourceRoot":"","sources":["../../src/utils/get-element-position.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,OAAgB,EAAE,GAAW;IACtE,MAAM,IAAI,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAC7C,MAAM,SAAS,GAAG,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC;IAC1D,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;QACxB,OAAO;YACL,aAAa,EAAE,IAAI,CAAC,KAAK;YACzB,aAAa,EAAE,IAAI,CAAC,GAAG;YACvB,SAAS;SACV,CAAC;IACJ,CAAC;SAAM,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;QAC/B,OAAO;YACL,aAAa,EAAE,IAAI,CAAC,IAAI;YACxB,aAAa,EAAE,IAAI,CAAC,GAAG;YACvB,SAAS;SACV,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,eAAe,OAAO,qBAAqB,SAAS,4BAA4B,CAAC,CAAC;IACpG,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function getScrollableAncestors(element: HTMLElement, win: Window): Set<HTMLElement>;
2
+ //# sourceMappingURL=get-scrollable-ancestors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-scrollable-ancestors.d.ts","sourceRoot":"","sources":["../../src/utils/get-scrollable-ancestors.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,oBAWhF"}
@@ -0,0 +1,15 @@
1
+ const scrollableOverflowValues = new Set(['auto', 'scroll', 'hidden']);
2
+ export default function getScrollableAncestors(element, win) {
3
+ let currentElement = element;
4
+ let scrollableAncestors = new Set();
5
+ while (currentElement.parentElement) {
6
+ currentElement = currentElement.parentElement;
7
+ const computedStyle = win.getComputedStyle(currentElement);
8
+ if (scrollableOverflowValues.has(computedStyle.overflowX) || scrollableOverflowValues.has(computedStyle.overflowY)) {
9
+ scrollableAncestors.add(currentElement);
10
+ }
11
+ }
12
+ return scrollableAncestors;
13
+ }
14
+ ;
15
+ //# sourceMappingURL=get-scrollable-ancestors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-scrollable-ancestors.js","sourceRoot":"","sources":["../../src/utils/get-scrollable-ancestors.ts"],"names":[],"mappings":"AAAA,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEvE,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAE,OAAoB,EAAE,GAAW;IAC/E,IAAI,cAAc,GAAG,OAAO,CAAC;IAC7B,IAAI,mBAAmB,GAAG,IAAI,GAAG,EAAe,CAAC;IACjD,OAAO,cAAc,CAAC,aAAa,EAAE,CAAC;QACpC,cAAc,GAAG,cAAc,CAAC,aAAa,CAAC;QAC9C,MAAM,aAAa,GAAG,GAAG,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC;QAC3D,IAAI,wBAAwB,CAAC,GAAG,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,wBAAwB,CAAC,GAAG,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC;YACnH,mBAAmB,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IACD,OAAO,mBAAmB,CAAC;AAC7B,CAAC;AAAA,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function recalculatePositions(): void;
2
+ //# sourceMappingURL=recalculate-positions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recalculate-positions.d.ts","sourceRoot":"","sources":["../../src/utils/recalculate-positions.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,OAAO,UAAU,oBAAoB,SAmB3C"}