@zag-js/focus-visible 0.1.0 → 0.1.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Chakra UI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # @zag-js/focus-visible
2
2
 
3
-
4
-
5
3
  ## Installation
6
4
 
7
5
  ```sh
@@ -12,11 +10,8 @@ npm i @zag-js/focus-visible
12
10
 
13
11
  ## Contribution
14
12
 
15
- Yes please! See the
16
- [contributing guidelines](https://github.com/chakra-ui/zag/blob/main/CONTRIBUTING.md)
17
- for details.
13
+ Yes please! See the [contributing guidelines](https://github.com/chakra-ui/zag/blob/main/CONTRIBUTING.md) for details.
18
14
 
19
15
  ## Licence
20
16
 
21
- This project is licensed under the terms of the
22
- [MIT license](https://github.com/chakra-ui/zag/blob/main/LICENSE).
17
+ This project is licensed under the terms of the [MIT license](https://github.com/chakra-ui/zag/blob/main/LICENSE).
package/dist/index.d.ts CHANGED
@@ -1,4 +1,8 @@
1
+ declare type Modality = "keyboard" | "pointer" | "virtual";
1
2
  declare type FocusVisibleCallback = (isFocusVisible: boolean) => void;
2
- export declare function trackFocusVisible(fn: FocusVisibleCallback): () => void;
3
- export {};
4
- //# sourceMappingURL=index.d.ts.map
3
+ declare function trackFocusVisible(fn: FocusVisibleCallback): () => void;
4
+ declare function trackInteractionModality(fn: (value: Modality | null) => void): () => void;
5
+ declare function setInteractionModality(value: Modality): void;
6
+ declare function getInteractionModality(): Modality | null;
7
+
8
+ export { getInteractionModality, setInteractionModality, trackFocusVisible, trackInteractionModality };
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -19,20 +20,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
20
  // src/index.ts
20
21
  var src_exports = {};
21
22
  __export(src_exports, {
22
- trackFocusVisible: () => trackFocusVisible
23
+ getInteractionModality: () => getInteractionModality,
24
+ setInteractionModality: () => setInteractionModality,
25
+ trackFocusVisible: () => trackFocusVisible,
26
+ trackInteractionModality: () => trackInteractionModality
23
27
  });
24
28
  module.exports = __toCommonJS(src_exports);
25
29
  var hasSetup = false;
26
30
  var modality = null;
27
31
  var hasEventBeforeFocus = false;
32
+ var hasBlurredWindowRecently = false;
28
33
  var handlers = /* @__PURE__ */ new Set();
29
- var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
30
- function isValidKey(event) {
31
- return !(event.metaKey || !isMac && event.altKey || event.ctrlKey);
32
- }
33
34
  function trigger(modality2, event) {
34
35
  handlers.forEach((handler) => handler(modality2, event));
35
36
  }
37
+ var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
38
+ function isValidKey(e) {
39
+ return !(e.metaKey || !isMac && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
40
+ }
36
41
  function onKeyboardEvent(event) {
37
42
  hasEventBeforeFocus = true;
38
43
  if (isValidKey(event)) {
@@ -44,21 +49,37 @@ function onPointerEvent(event) {
44
49
  modality = "pointer";
45
50
  if (event.type === "mousedown" || event.type === "pointerdown") {
46
51
  hasEventBeforeFocus = true;
52
+ const target = event.composedPath ? event.composedPath()[0] : event.target;
53
+ if (target.matches(":focus-visible"))
54
+ return;
47
55
  trigger("pointer", event);
48
56
  }
49
57
  }
58
+ function isVirtualClick(event) {
59
+ if (event.mozInputSource === 0 && event.isTrusted)
60
+ return true;
61
+ return event.detail === 0 && !event.pointerType;
62
+ }
63
+ function onClickEvent(e) {
64
+ if (isVirtualClick(e)) {
65
+ hasEventBeforeFocus = true;
66
+ modality = "virtual";
67
+ }
68
+ }
50
69
  function onWindowFocus(event) {
51
70
  if (event.target === window || event.target === document) {
52
71
  return;
53
72
  }
54
- if (!hasEventBeforeFocus) {
55
- modality = "keyboard";
56
- trigger("keyboard", event);
73
+ if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {
74
+ modality = "virtual";
75
+ trigger("virtual", event);
57
76
  }
58
77
  hasEventBeforeFocus = false;
78
+ hasBlurredWindowRecently = false;
59
79
  }
60
80
  function onWindowBlur() {
61
81
  hasEventBeforeFocus = false;
82
+ hasBlurredWindowRecently = true;
62
83
  }
63
84
  function isFocusVisible() {
64
85
  return modality !== "pointer";
@@ -74,6 +95,7 @@ function setupGlobalFocusEvents() {
74
95
  };
75
96
  document.addEventListener("keydown", onKeyboardEvent, true);
76
97
  document.addEventListener("keyup", onKeyboardEvent, true);
98
+ document.addEventListener("click", onClickEvent, true);
77
99
  window.addEventListener("focus", onWindowFocus, true);
78
100
  window.addEventListener("blur", onWindowBlur, false);
79
101
  if (typeof PointerEvent !== "undefined") {
@@ -96,4 +118,26 @@ function trackFocusVisible(fn) {
96
118
  handlers.delete(handler);
97
119
  };
98
120
  }
99
- //# sourceMappingURL=index.js.map
121
+ function trackInteractionModality(fn) {
122
+ setupGlobalFocusEvents();
123
+ fn(modality);
124
+ const handler = () => fn(modality);
125
+ handlers.add(handler);
126
+ return () => {
127
+ handlers.delete(handler);
128
+ };
129
+ }
130
+ function setInteractionModality(value) {
131
+ modality = value;
132
+ trigger(value, null);
133
+ }
134
+ function getInteractionModality() {
135
+ return modality;
136
+ }
137
+ // Annotate the CommonJS export names for ESM import in node:
138
+ 0 && (module.exports = {
139
+ getInteractionModality,
140
+ setInteractionModality,
141
+ trackFocusVisible,
142
+ trackInteractionModality
143
+ });
package/dist/index.mjs CHANGED
@@ -2,14 +2,15 @@
2
2
  var hasSetup = false;
3
3
  var modality = null;
4
4
  var hasEventBeforeFocus = false;
5
+ var hasBlurredWindowRecently = false;
5
6
  var handlers = /* @__PURE__ */ new Set();
6
- var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
7
- function isValidKey(event) {
8
- return !(event.metaKey || !isMac && event.altKey || event.ctrlKey);
9
- }
10
7
  function trigger(modality2, event) {
11
8
  handlers.forEach((handler) => handler(modality2, event));
12
9
  }
10
+ var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
11
+ function isValidKey(e) {
12
+ return !(e.metaKey || !isMac && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
13
+ }
13
14
  function onKeyboardEvent(event) {
14
15
  hasEventBeforeFocus = true;
15
16
  if (isValidKey(event)) {
@@ -21,21 +22,37 @@ function onPointerEvent(event) {
21
22
  modality = "pointer";
22
23
  if (event.type === "mousedown" || event.type === "pointerdown") {
23
24
  hasEventBeforeFocus = true;
25
+ const target = event.composedPath ? event.composedPath()[0] : event.target;
26
+ if (target.matches(":focus-visible"))
27
+ return;
24
28
  trigger("pointer", event);
25
29
  }
26
30
  }
31
+ function isVirtualClick(event) {
32
+ if (event.mozInputSource === 0 && event.isTrusted)
33
+ return true;
34
+ return event.detail === 0 && !event.pointerType;
35
+ }
36
+ function onClickEvent(e) {
37
+ if (isVirtualClick(e)) {
38
+ hasEventBeforeFocus = true;
39
+ modality = "virtual";
40
+ }
41
+ }
27
42
  function onWindowFocus(event) {
28
43
  if (event.target === window || event.target === document) {
29
44
  return;
30
45
  }
31
- if (!hasEventBeforeFocus) {
32
- modality = "keyboard";
33
- trigger("keyboard", event);
46
+ if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {
47
+ modality = "virtual";
48
+ trigger("virtual", event);
34
49
  }
35
50
  hasEventBeforeFocus = false;
51
+ hasBlurredWindowRecently = false;
36
52
  }
37
53
  function onWindowBlur() {
38
54
  hasEventBeforeFocus = false;
55
+ hasBlurredWindowRecently = true;
39
56
  }
40
57
  function isFocusVisible() {
41
58
  return modality !== "pointer";
@@ -51,6 +68,7 @@ function setupGlobalFocusEvents() {
51
68
  };
52
69
  document.addEventListener("keydown", onKeyboardEvent, true);
53
70
  document.addEventListener("keyup", onKeyboardEvent, true);
71
+ document.addEventListener("click", onClickEvent, true);
54
72
  window.addEventListener("focus", onWindowFocus, true);
55
73
  window.addEventListener("blur", onWindowBlur, false);
56
74
  if (typeof PointerEvent !== "undefined") {
@@ -73,7 +91,25 @@ function trackFocusVisible(fn) {
73
91
  handlers.delete(handler);
74
92
  };
75
93
  }
94
+ function trackInteractionModality(fn) {
95
+ setupGlobalFocusEvents();
96
+ fn(modality);
97
+ const handler = () => fn(modality);
98
+ handlers.add(handler);
99
+ return () => {
100
+ handlers.delete(handler);
101
+ };
102
+ }
103
+ function setInteractionModality(value) {
104
+ modality = value;
105
+ trigger(value, null);
106
+ }
107
+ function getInteractionModality() {
108
+ return modality;
109
+ }
76
110
  export {
77
- trackFocusVisible
111
+ getInteractionModality,
112
+ setInteractionModality,
113
+ trackFocusVisible,
114
+ trackInteractionModality
78
115
  };
79
- //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/focus-visible",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Focus visible polyfill utility based on WICG",
5
5
  "keywords": [
6
6
  "js",
@@ -19,19 +19,19 @@
19
19
  "files": [
20
20
  "dist/**/*"
21
21
  ],
22
- "scripts": {
23
- "build:fast": "yarn zag build",
24
- "start": "yarn zag build --watch",
25
- "build": "yarn zag build --prod",
26
- "test": "jest --config ../../../jest.config.js --rootDir tests",
27
- "lint": "eslint src --ext .ts,.tsx",
28
- "test:ci": "yarn test --ci --runInBand --updateSnapshot",
29
- "test:watch": "yarn test --watchAll"
30
- },
31
22
  "publishConfig": {
32
23
  "access": "public"
33
24
  },
34
25
  "bugs": {
35
26
  "url": "https://github.com/chakra-ui/zag/issues"
27
+ },
28
+ "scripts": {
29
+ "build-fast": "tsup src/index.ts --format=esm,cjs",
30
+ "start": "pnpm build --watch",
31
+ "build": "tsup src/index.ts --format=esm,cjs --dts",
32
+ "test": "jest --config ../../../jest.config.js --rootDir tests",
33
+ "lint": "eslint src --ext .ts,.tsx",
34
+ "test-ci": "pnpm test --ci --runInBand -u",
35
+ "test-watch": "pnpm test --watchAll"
36
36
  }
37
- }
37
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,aAAK,oBAAoB,GAAG,CAAC,cAAc,EAAE,OAAO,KAAK,IAAI,CAAA;AAkG7D,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,oBAAoB,cAUzD"}
package/dist/index.js.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/index.ts"],
4
- "sourcesContent": ["type Modality = \"keyboard\" | \"pointer\"\ntype HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent\ntype Handler = (modality: Modality, e: HandlerEvent) => void\ntype FocusVisibleCallback = (isFocusVisible: boolean) => void\n\nlet hasSetup = false\nlet modality: Modality | null = null\nlet hasEventBeforeFocus = false\n\nconst handlers = new Set<Handler>()\n\nconst isMac = typeof window !== \"undefined\" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false\n\nfunction isValidKey(event: KeyboardEvent) {\n return !(event.metaKey || (!isMac && event.altKey) || event.ctrlKey)\n}\n\nfunction trigger(modality: Modality, event: HandlerEvent) {\n handlers.forEach((handler) => handler(modality, event))\n}\n\nfunction onKeyboardEvent(event: KeyboardEvent) {\n hasEventBeforeFocus = true\n if (isValidKey(event)) {\n modality = \"keyboard\"\n trigger(\"keyboard\", event)\n }\n}\n\nfunction onPointerEvent(event: PointerEvent | MouseEvent) {\n modality = \"pointer\"\n if (event.type === \"mousedown\" || event.type === \"pointerdown\") {\n hasEventBeforeFocus = true\n trigger(\"pointer\", event)\n }\n}\n\nfunction onWindowFocus(event: FocusEvent) {\n // Firefox fires two extra focus events when the user first clicks into an iframe:\n // first on the window, then on the document. We ignore these events so they don't\n // cause keyboard focus rings to appear.\n if (event.target === window || event.target === document) {\n return\n }\n\n // If a focus event occurs without a preceding keyboard or pointer event, switch to keyboard modality.\n // This occurs, for example, when navigating a form with the next/previous buttons on iOS.\n if (!hasEventBeforeFocus) {\n modality = \"keyboard\"\n trigger(\"keyboard\", event)\n }\n\n hasEventBeforeFocus = false\n}\n\nfunction onWindowBlur() {\n // When the window is blurred, reset state. This is necessary when tabbing out of the window,\n // for example, since a subsequent focus event won't be fired.\n hasEventBeforeFocus = false\n}\n\nfunction isFocusVisible() {\n return modality !== \"pointer\"\n}\n\nfunction setupGlobalFocusEvents() {\n if (typeof window === \"undefined\" || hasSetup) {\n return\n }\n\n // Programmatic focus() calls shouldn't affect the current input modality.\n // However, we need to detect other cases when a focus event occurs without\n // a preceding user event (e.g. screen reader focus). Overriding the focus\n // method on HTMLElement.prototype is a bit hacky, but works.\n const { focus } = HTMLElement.prototype\n HTMLElement.prototype.focus = function focusElement(...args) {\n hasEventBeforeFocus = true\n focus.apply(this, args)\n }\n\n document.addEventListener(\"keydown\", onKeyboardEvent, true)\n document.addEventListener(\"keyup\", onKeyboardEvent, true)\n\n // Register focus events on the window so they are sure to happen\n // before React's event listeners (registered on the document).\n window.addEventListener(\"focus\", onWindowFocus, true)\n window.addEventListener(\"blur\", onWindowBlur, false)\n\n if (typeof PointerEvent !== \"undefined\") {\n document.addEventListener(\"pointerdown\", onPointerEvent, true)\n document.addEventListener(\"pointermove\", onPointerEvent, true)\n document.addEventListener(\"pointerup\", onPointerEvent, true)\n } else {\n document.addEventListener(\"mousedown\", onPointerEvent, true)\n document.addEventListener(\"mousemove\", onPointerEvent, true)\n document.addEventListener(\"mouseup\", onPointerEvent, true)\n }\n\n hasSetup = true\n}\n\nexport function trackFocusVisible(fn: FocusVisibleCallback) {\n setupGlobalFocusEvents()\n\n fn(isFocusVisible())\n const handler = () => fn(isFocusVisible())\n\n handlers.add(handler)\n return () => {\n handlers.delete(handler)\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,IAAI,WAAW;AACf,IAAI,WAA4B;AAChC,IAAI,sBAAsB;AAE1B,IAAM,WAAW,oBAAI,IAAa;AAElC,IAAM,QAAQ,OAAO,WAAW,eAAe,OAAO,aAAa,OAAO,OAAO,KAAK,OAAO,UAAU,QAAQ,IAAI;AAEnH,oBAAoB,OAAsB;AACxC,SAAO,CAAE,OAAM,WAAY,CAAC,SAAS,MAAM,UAAW,MAAM;AAC9D;AAEA,iBAAiB,WAAoB,OAAqB;AACxD,WAAS,QAAQ,CAAC,YAAY,QAAQ,WAAU,KAAK,CAAC;AACxD;AAEA,yBAAyB,OAAsB;AAC7C,wBAAsB;AACtB,MAAI,WAAW,KAAK,GAAG;AACrB,eAAW;AACX,YAAQ,YAAY,KAAK;AAAA,EAC3B;AACF;AAEA,wBAAwB,O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,OAAO,OAAO;AAAA,EACzB;AACF;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/index.ts"],
4
- "sourcesContent": ["type Modality = \"keyboard\" | \"pointer\"\ntype HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent\ntype Handler = (modality: Modality, e: HandlerEvent) => void\ntype FocusVisibleCallback = (isFocusVisible: boolean) => void\n\nlet hasSetup = false\nlet modality: Modality | null = null\nlet hasEventBeforeFocus = false\n\nconst handlers = new Set<Handler>()\n\nconst isMac = typeof window !== \"undefined\" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false\n\nfunction isValidKey(event: KeyboardEvent) {\n return !(event.metaKey || (!isMac && event.altKey) || event.ctrlKey)\n}\n\nfunction trigger(modality: Modality, event: HandlerEvent) {\n handlers.forEach((handler) => handler(modality, event))\n}\n\nfunction onKeyboardEvent(event: KeyboardEvent) {\n hasEventBeforeFocus = true\n if (isValidKey(event)) {\n modality = \"keyboard\"\n trigger(\"keyboard\", event)\n }\n}\n\nfunction onPointerEvent(event: PointerEvent | MouseEvent) {\n modality = \"pointer\"\n if (event.type === \"mousedown\" || event.type === \"pointerdown\") {\n hasEventBeforeFocus = true\n trigger(\"pointer\", event)\n }\n}\n\nfunction onWindowFocus(event: FocusEvent) {\n // Firefox fires two extra focus events when the user first clicks into an iframe:\n // first on the window, then on the document. We ignore these events so they don't\n // cause keyboard focus rings to appear.\n if (event.target === window || event.target === document) {\n return\n }\n\n // If a focus event occurs without a preceding keyboard or pointer event, switch to keyboard modality.\n // This occurs, for example, when navigating a form with the next/previous buttons on iOS.\n if (!hasEventBeforeFocus) {\n modality = \"keyboard\"\n trigger(\"keyboard\", event)\n }\n\n hasEventBeforeFocus = false\n}\n\nfunction onWindowBlur() {\n // When the window is blurred, reset state. This is necessary when tabbing out of the window,\n // for example, since a subsequent focus event won't be fired.\n hasEventBeforeFocus = false\n}\n\nfunction isFocusVisible() {\n return modality !== \"pointer\"\n}\n\nfunction setupGlobalFocusEvents() {\n if (typeof window === \"undefined\" || hasSetup) {\n return\n }\n\n // Programmatic focus() calls shouldn't affect the current input modality.\n // However, we need to detect other cases when a focus event occurs without\n // a preceding user event (e.g. screen reader focus). Overriding the focus\n // method on HTMLElement.prototype is a bit hacky, but works.\n const { focus } = HTMLElement.prototype\n HTMLElement.prototype.focus = function focusElement(...args) {\n hasEventBeforeFocus = true\n focus.apply(this, args)\n }\n\n document.addEventListener(\"keydown\", onKeyboardEvent, true)\n document.addEventListener(\"keyup\", onKeyboardEvent, true)\n\n // Register focus events on the window so they are sure to happen\n // before React's event listeners (registered on the document).\n window.addEventListener(\"focus\", onWindowFocus, true)\n window.addEventListener(\"blur\", onWindowBlur, false)\n\n if (typeof PointerEvent !== \"undefined\") {\n document.addEventListener(\"pointerdown\", onPointerEvent, true)\n document.addEventListener(\"pointermove\", onPointerEvent, true)\n document.addEventListener(\"pointerup\", onPointerEvent, true)\n } else {\n document.addEventListener(\"mousedown\", onPointerEvent, true)\n document.addEventListener(\"mousemove\", onPointerEvent, true)\n document.addEventListener(\"mouseup\", onPointerEvent, true)\n }\n\n hasSetup = true\n}\n\nexport function trackFocusVisible(fn: FocusVisibleCallback) {\n setupGlobalFocusEvents()\n\n fn(isFocusVisible())\n const handler = () => fn(isFocusVisible())\n\n handlers.add(handler)\n return () => {\n handlers.delete(handler)\n }\n}\n"],
5
- "mappings": ";AAKA,IAAI,WAAW;AACf,IAAI,WAA4B;AAChC,IAAI,sBAAsB;AAE1B,IAAM,WAAW,oBAAI,IAAa;AAElC,IAAM,QAAQ,OAAO,WAAW,eAAe,OAAO,aAAa,OAAO,OAAO,KAAK,OAAO,UAAU,QAAQ,IAAI;AAEnH,oBAAoB,OAAsB;AACxC,SAAO,CAAE,OAAM,WAAY,CAAC,SAAS,MAAM,UAAW,MAAM;AAC9D;AAEA,iBAAiB,WAAoB,OAAqB;AACxD,WAAS,QAAQ,CAAC,YAAY,QAAQ,WAAU,KA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