@spectrum-web-components/shared 0.14.4 → 0.14.5-devmode.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.
Files changed (53) hide show
  1. package/package.json +52 -6
  2. package/src/first-focusable-in.dev.js +6 -0
  3. package/src/first-focusable-in.dev.js.map +7 -0
  4. package/src/first-focusable-in.js +3 -14
  5. package/src/first-focusable-in.js.map +7 -1
  6. package/src/focus-visible.dev.js +68 -0
  7. package/src/focus-visible.dev.js.map +7 -0
  8. package/src/focus-visible.js +59 -105
  9. package/src/focus-visible.js.map +7 -1
  10. package/src/focusable.dev.js +190 -0
  11. package/src/focusable.dev.js.map +7 -0
  12. package/src/focusable.js +185 -244
  13. package/src/focusable.js.map +7 -1
  14. package/src/get-active-element.dev.js +4 -0
  15. package/src/get-active-element.dev.js.map +7 -0
  16. package/src/get-active-element.js +2 -14
  17. package/src/get-active-element.js.map +7 -1
  18. package/src/get-deep-element-from-point.dev.js +12 -0
  19. package/src/get-deep-element-from-point.dev.js.map +7 -0
  20. package/src/get-deep-element-from-point.js +9 -20
  21. package/src/get-deep-element-from-point.js.map +7 -1
  22. package/src/index.dev.js +10 -0
  23. package/src/index.dev.js.map +7 -0
  24. package/src/index.js +10 -21
  25. package/src/index.js.map +7 -1
  26. package/src/like-anchor.dev.js +58 -0
  27. package/src/like-anchor.dev.js.map +7 -0
  28. package/src/like-anchor.js +45 -40
  29. package/src/like-anchor.js.map +7 -1
  30. package/src/observe-slot-presence.dev.js +52 -0
  31. package/src/observe-slot-presence.dev.js.map +7 -0
  32. package/src/observe-slot-presence.js +47 -55
  33. package/src/observe-slot-presence.js.map +7 -1
  34. package/src/observe-slot-text.dev.js +79 -0
  35. package/src/observe-slot-text.dev.js.map +7 -0
  36. package/src/observe-slot-text.js +73 -64
  37. package/src/observe-slot-text.js.map +7 -1
  38. package/src/platform.dev.js +31 -0
  39. package/src/platform.dev.js.map +7 -0
  40. package/src/platform.js +11 -32
  41. package/src/platform.js.map +7 -1
  42. package/src/reparent-children.dev.js +50 -0
  43. package/src/reparent-children.dev.js.map +7 -0
  44. package/src/reparent-children.js +44 -52
  45. package/src/reparent-children.js.map +7 -1
  46. package/test/focusable.test.js +19 -31
  47. package/test/focusable.test.js.map +7 -1
  48. package/test/observe-slot-presence.test.js +17 -27
  49. package/test/observe-slot-presence.test.js.map +7 -1
  50. package/test/observe-slot-text.test.js +17 -28
  51. package/test/observe-slot-text.test.js.map +7 -1
  52. package/test/reparent-children.test.js +151 -162
  53. package/test/reparent-children.test.js.map +7 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/shared",
3
- "version": "0.14.4",
3
+ "version": "0.14.5-devmode.0+07474d44f",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -20,9 +20,55 @@
20
20
  "module": "./src/index.js",
21
21
  "type": "module",
22
22
  "exports": {
23
- ".": "./src/index.js",
24
- "./src/*": "./src/*",
25
- "./package.json": "./package.json"
23
+ ".": {
24
+ "development": "./src/index.dev.js",
25
+ "default": "./src/index.js"
26
+ },
27
+ "./package.json": "./package.json",
28
+ "./src/first-focusable-in.js": {
29
+ "development": "./src/first-focusable-in.dev.js",
30
+ "default": "./src/first-focusable-in.js"
31
+ },
32
+ "./src/focus-visible.js": {
33
+ "development": "./src/focus-visible.dev.js",
34
+ "default": "./src/focus-visible.js"
35
+ },
36
+ "./src/focusable.js": {
37
+ "development": "./src/focusable.dev.js",
38
+ "default": "./src/focusable.js"
39
+ },
40
+ "./src/get-active-element.js": {
41
+ "development": "./src/get-active-element.dev.js",
42
+ "default": "./src/get-active-element.js"
43
+ },
44
+ "./src/get-deep-element-from-point.js": {
45
+ "development": "./src/get-deep-element-from-point.dev.js",
46
+ "default": "./src/get-deep-element-from-point.js"
47
+ },
48
+ "./src/index.js": {
49
+ "development": "./src/index.dev.js",
50
+ "default": "./src/index.js"
51
+ },
52
+ "./src/like-anchor.js": {
53
+ "development": "./src/like-anchor.dev.js",
54
+ "default": "./src/like-anchor.js"
55
+ },
56
+ "./src/observe-slot-presence.js": {
57
+ "development": "./src/observe-slot-presence.dev.js",
58
+ "default": "./src/observe-slot-presence.js"
59
+ },
60
+ "./src/observe-slot-text.js": {
61
+ "development": "./src/observe-slot-text.dev.js",
62
+ "default": "./src/observe-slot-text.js"
63
+ },
64
+ "./src/platform.js": {
65
+ "development": "./src/platform.dev.js",
66
+ "default": "./src/platform.js"
67
+ },
68
+ "./src/reparent-children.js": {
69
+ "development": "./src/reparent-children.dev.js",
70
+ "default": "./src/reparent-children.js"
71
+ }
26
72
  },
27
73
  "scripts": {
28
74
  "test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
@@ -43,12 +89,12 @@
43
89
  ],
44
90
  "dependencies": {
45
91
  "@lit-labs/observers": "^1.0.1",
46
- "@spectrum-web-components/base": "^0.5.8",
92
+ "@spectrum-web-components/base": "^0.5.9-devmode.24+07474d44f",
47
93
  "focus-visible": "^5.1.0",
48
94
  "tslib": "^2.0.0"
49
95
  },
50
96
  "types": "./src/index.d.ts",
51
97
  "customElements": "custom-elements.json",
52
98
  "sideEffects": false,
53
- "gitHead": "3be62133721efba844cd7032566a2c49ed6d9875"
99
+ "gitHead": "07474d44f6cee1db241b9ccf3dc812514ffbe7fa"
54
100
  }
@@ -0,0 +1,6 @@
1
+ const firstFocusableSelector = 'button:not([tabindex="-1"]), [href]:not([tabindex="-1"]), input:not([tabindex="-1"]), select:not([tabindex="-1"]), textarea:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), [focusable]:not([tabindex="-1"])';
2
+ export const firstFocusableIn = (root) => {
3
+ const firstFocusable = root.querySelector(firstFocusableSelector);
4
+ return firstFocusable;
5
+ };
6
+ //# sourceMappingURL=first-focusable-in.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["first-focusable-in.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { SpectrumElement } from '@spectrum-web-components/base';\n\nconst firstFocusableSelector =\n 'button:not([tabindex=\"-1\"]), [href]:not([tabindex=\"-1\"]), input:not([tabindex=\"-1\"]), select:not([tabindex=\"-1\"]), textarea:not([tabindex=\"-1\"]), [tabindex]:not([tabindex=\"-1\"]), [focusable]:not([tabindex=\"-1\"])';\n\nexport const firstFocusableIn = (\n root: HTMLElement | ShadowRoot\n): SpectrumElement | null => {\n const firstFocusable = root.querySelector(\n firstFocusableSelector\n ) as SpectrumElement;\n return firstFocusable;\n};\n"],
5
+ "mappings": "AAcA,MAAM,yBACF;AAEG,aAAM,mBAAmB,CAC5B,SACyB;AACzB,QAAM,iBAAiB,KAAK,cACxB,sBACJ;AACA,SAAO;AACX;",
6
+ "names": []
7
+ }
@@ -1,17 +1,6 @@
1
- /*
2
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
1
  const firstFocusableSelector = 'button:not([tabindex="-1"]), [href]:not([tabindex="-1"]), input:not([tabindex="-1"]), select:not([tabindex="-1"]), textarea:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), [focusable]:not([tabindex="-1"])';
13
2
  export const firstFocusableIn = (root) => {
14
- const firstFocusable = root.querySelector(firstFocusableSelector);
15
- return firstFocusable;
3
+ const firstFocusable = root.querySelector(firstFocusableSelector);
4
+ return firstFocusable;
16
5
  };
17
- //# sourceMappingURL=first-focusable-in.js.map
6
+ //# sourceMappingURL=first-focusable-in.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"first-focusable-in.js","sourceRoot":"","sources":["first-focusable-in.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAIF,MAAM,sBAAsB,GACxB,qNAAqN,CAAC;AAE1N,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC5B,IAA8B,EACR,EAAE;IACxB,MAAM,cAAc,GAAG,IAAI,CAAC,aAAa,CACrC,sBAAsB,CACN,CAAC;IACrB,OAAO,cAAc,CAAC;AAC1B,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { SpectrumElement } from '@spectrum-web-components/base';\n\nconst firstFocusableSelector =\n 'button:not([tabindex=\"-1\"]), [href]:not([tabindex=\"-1\"]), input:not([tabindex=\"-1\"]), select:not([tabindex=\"-1\"]), textarea:not([tabindex=\"-1\"]), [tabindex]:not([tabindex=\"-1\"]), [focusable]:not([tabindex=\"-1\"])';\n\nexport const firstFocusableIn = (\n root: HTMLElement | ShadowRoot\n): SpectrumElement | null => {\n const firstFocusable = root.querySelector(\n firstFocusableSelector\n ) as SpectrumElement;\n return firstFocusable;\n};\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["first-focusable-in.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { SpectrumElement } from '@spectrum-web-components/base';\n\nconst firstFocusableSelector =\n 'button:not([tabindex=\"-1\"]), [href]:not([tabindex=\"-1\"]), input:not([tabindex=\"-1\"]), select:not([tabindex=\"-1\"]), textarea:not([tabindex=\"-1\"]), [tabindex]:not([tabindex=\"-1\"]), [focusable]:not([tabindex=\"-1\"])';\n\nexport const firstFocusableIn = (\n root: HTMLElement | ShadowRoot\n): SpectrumElement | null => {\n const firstFocusable = root.querySelector(\n firstFocusableSelector\n ) as SpectrumElement;\n return firstFocusable;\n};\n"],
5
+ "mappings": "AAcA,MAAM,yBACF;AAEG,aAAM,mBAAmB,CAC5B,SACyB;AACzB,QAAM,iBAAiB,KAAK,cACxB,sBACJ;AACA,SAAO;AACX;",
6
+ "names": []
7
+ }
@@ -0,0 +1,68 @@
1
+ let hasFocusVisible = true;
2
+ try {
3
+ document.body.querySelector(":focus-visible");
4
+ } catch (error) {
5
+ hasFocusVisible = false;
6
+ import("focus-visible");
7
+ }
8
+ export const FocusVisiblePolyfillMixin = (SuperClass) => {
9
+ var _a;
10
+ const coordinateWithPolyfill = (instance) => {
11
+ if (instance.shadowRoot == null || instance.hasAttribute("data-js-focus-visible")) {
12
+ return () => {
13
+ };
14
+ }
15
+ if (self.applyFocusVisiblePolyfill) {
16
+ self.applyFocusVisiblePolyfill(instance.shadowRoot);
17
+ if (instance.manageAutoFocus) {
18
+ instance.manageAutoFocus();
19
+ }
20
+ } else {
21
+ const coordinationHandler = () => {
22
+ if (self.applyFocusVisiblePolyfill && instance.shadowRoot) {
23
+ self.applyFocusVisiblePolyfill(instance.shadowRoot);
24
+ }
25
+ if (instance.manageAutoFocus) {
26
+ instance.manageAutoFocus();
27
+ }
28
+ };
29
+ self.addEventListener("focus-visible-polyfill-ready", coordinationHandler, { once: true });
30
+ return () => {
31
+ self.removeEventListener("focus-visible-polyfill-ready", coordinationHandler);
32
+ };
33
+ }
34
+ return () => {
35
+ };
36
+ };
37
+ const $endPolyfillCoordination = Symbol("endPolyfillCoordination");
38
+ class FocusVisibleCoordinator extends SuperClass {
39
+ constructor() {
40
+ super(...arguments);
41
+ this[_a] = null;
42
+ }
43
+ connectedCallback() {
44
+ super.connectedCallback && super.connectedCallback();
45
+ if (!hasFocusVisible) {
46
+ requestAnimationFrame(() => {
47
+ if (this[$endPolyfillCoordination] == null) {
48
+ this[$endPolyfillCoordination] = coordinateWithPolyfill(this);
49
+ }
50
+ });
51
+ }
52
+ }
53
+ disconnectedCallback() {
54
+ super.disconnectedCallback && super.disconnectedCallback();
55
+ if (!hasFocusVisible) {
56
+ requestAnimationFrame(() => {
57
+ if (this[$endPolyfillCoordination] != null) {
58
+ this[$endPolyfillCoordination]();
59
+ this[$endPolyfillCoordination] = null;
60
+ }
61
+ });
62
+ }
63
+ }
64
+ }
65
+ _a = $endPolyfillCoordination;
66
+ return FocusVisibleCoordinator;
67
+ };
68
+ //# sourceMappingURL=focus-visible.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["focus-visible.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\ndeclare global {\n interface Window {\n applyFocusVisiblePolyfill?: (scope: Document | ShadowRoot) => void;\n }\n}\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\ninterface OptionalLifecycleCallbacks {\n connectedCallback?(): void;\n disconnectedCallback?(): void;\n manageAutoFocus?(): void;\n}\n\ntype MixableBaseClass = HTMLElement & OptionalLifecycleCallbacks;\n\ntype EndPolyfillCoordinationCallback = () => void;\n\nlet hasFocusVisible = true;\n\ntry {\n document.body.querySelector(':focus-visible');\n} catch (error) {\n hasFocusVisible = false;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n import('focus-visible');\n}\n\n/**\n * This mixin function is designed to be applied to a class that inherits\n * from HTMLElement. It makes it easy for a custom element to coordinate with\n * the :focus-visible polyfill.\n *\n * NOTE(cdata): The code here was adapted from an example proposed with the\n * introduction of ShadowDOM support in the :focus-visible polyfill.\n *\n * @see https://github.com/WICG/focus-visible/pull/196\n * @param {Function} SuperClass The base class implementation to decorate with\n * implementation that coordinates with the :focus-visible polyfill\n */\nexport const FocusVisiblePolyfillMixin = <\n T extends Constructor<MixableBaseClass>\n>(\n SuperClass: T\n): T => {\n const coordinateWithPolyfill = (\n instance: MixableBaseClass\n ): EndPolyfillCoordinationCallback => {\n // If there is no shadow root, there is no need to coordinate with\n // the polyfill. If we already coordinated with the polyfill, we can\n // skip subsequent invokcations:\n if (\n instance.shadowRoot == null ||\n instance.hasAttribute('data-js-focus-visible')\n ) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n }\n\n // The polyfill might already be loaded. If so, we can apply it to\n // the shadow root immediately:\n if (self.applyFocusVisiblePolyfill) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n } else {\n const coordinationHandler = (): void => {\n if (self.applyFocusVisiblePolyfill && instance.shadowRoot) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n }\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n };\n // Otherwise, wait for the polyfill to be loaded lazily. It might\n // never be loaded, but if it is then we can apply it to the\n // shadow root at the appropriate time by waiting for the ready\n // event:\n self.addEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler,\n { once: true }\n );\n\n return () => {\n self.removeEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler\n );\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n };\n\n const $endPolyfillCoordination = Symbol('endPolyfillCoordination');\n\n // IE11 doesn't natively support custom elements or JavaScript class\n // syntax The mixin implementation assumes that the user will take the\n // appropriate steps to support both:\n class FocusVisibleCoordinator extends SuperClass {\n private [$endPolyfillCoordination]: EndPolyfillCoordinationCallback | null =\n null;\n\n // Attempt to coordinate with the polyfill when connected to the\n // document:\n override connectedCallback(): void {\n super.connectedCallback && super.connectedCallback();\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] == null) {\n this[$endPolyfillCoordination] =\n coordinateWithPolyfill(this);\n }\n });\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback && super.disconnectedCallback();\n // It's important to remove the polyfill event listener when we\n // disconnect, otherwise we will leak the whole element via window:\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] != null) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this[$endPolyfillCoordination]!();\n this[$endPolyfillCoordination] = null;\n }\n });\n }\n }\n }\n\n return FocusVisibleCoordinator;\n};\n"],
5
+ "mappings": "AAkCA,IAAI,kBAAkB;AAEtB,IAAI;AACA,WAAS,KAAK,cAAc,gBAAgB;AAChD,SAAS,OAAP;AACE,oBAAkB;AAGlB,SAAO;AACX;AAcO,aAAM,4BAA4B,CAGrC,eACI;AA7DR;AA8DI,QAAM,yBAAyB,CAC3B,aACkC;AAIlC,QACI,SAAS,cAAc,QACvB,SAAS,aAAa,uBAAuB,GAC/C;AAEE,aAAO,MAAM;AAAA,MAAC;AAAA,IAClB;AAIA,QAAI,KAAK,2BAA2B;AAChC,WAAK,0BAA0B,SAAS,UAAU;AAElD,UAAI,SAAS,iBAAiB;AAC1B,iBAAS,gBAAgB;AAAA,MAC7B;AAAA,IACJ,OAAO;AACH,YAAM,sBAAsB,MAAY;AACpC,YAAI,KAAK,6BAA6B,SAAS,YAAY;AACvD,eAAK,0BAA0B,SAAS,UAAU;AAAA,QACtD;AAEA,YAAI,SAAS,iBAAiB;AAC1B,mBAAS,gBAAgB;AAAA,QAC7B;AAAA,MACJ;AAKA,WAAK,iBACD,gCACA,qBACA,EAAE,MAAM,KAAK,CACjB;AAEA,aAAO,MAAM;AACT,aAAK,oBACD,gCACA,mBACJ;AAAA,MACJ;AAAA,IACJ;AAGA,WAAO,MAAM;AAAA,IAAC;AAAA,EAClB;AAEA,QAAM,2BAA2B,OAAO,yBAAyB;AAKjE,QAAM,gCAAgC,WAAW;AAAA,IAAjD;AAAA;AACa,iBACL;AAAA;AAAA,IAIK,oBAA0B;AAC/B,YAAM,qBAAqB,MAAM,kBAAkB;AACnD,UAAI,CAAC,iBAAiB;AAClB,8BAAsB,MAAM;AACxB,cAAI,KAAK,6BAA6B,MAAM;AACxC,iBAAK,4BACD,uBAAuB,IAAI;AAAA,UACnC;AAAA,QACJ,CAAC;AAAA,MACL;AAAA,IACJ;AAAA,IAES,uBAA6B;AAClC,YAAM,wBAAwB,MAAM,qBAAqB;AAGzD,UAAI,CAAC,iBAAiB;AAClB,8BAAsB,MAAM;AACxB,cAAI,KAAK,6BAA6B,MAAM;AAExC,iBAAK,0BAA2B;AAChC,iBAAK,4BAA4B;AAAA,UACrC;AAAA,QACJ,CAAC;AAAA,MACL;AAAA,IACJ;AAAA,EACJ;AAzJJ,EA0HiB;AAiCb,SAAO;AACX;",
6
+ "names": []
7
+ }
@@ -1,114 +1,68 @@
1
- /*
2
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
1
  let hasFocusVisible = true;
13
2
  try {
14
- document.body.querySelector(':focus-visible');
3
+ document.body.querySelector(":focus-visible");
4
+ } catch (error) {
5
+ hasFocusVisible = false;
6
+ import("focus-visible");
15
7
  }
16
- catch (error) {
17
- hasFocusVisible = false;
18
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
19
- // @ts-ignore
20
- import('focus-visible');
21
- }
22
- /**
23
- * This mixin function is designed to be applied to a class that inherits
24
- * from HTMLElement. It makes it easy for a custom element to coordinate with
25
- * the :focus-visible polyfill.
26
- *
27
- * NOTE(cdata): The code here was adapted from an example proposed with the
28
- * introduction of ShadowDOM support in the :focus-visible polyfill.
29
- *
30
- * @see https://github.com/WICG/focus-visible/pull/196
31
- * @param {Function} SuperClass The base class implementation to decorate with
32
- * implementation that coordinates with the :focus-visible polyfill
33
- */
34
8
  export const FocusVisiblePolyfillMixin = (SuperClass) => {
35
- var _a;
36
- const coordinateWithPolyfill = (instance) => {
37
- // If there is no shadow root, there is no need to coordinate with
38
- // the polyfill. If we already coordinated with the polyfill, we can
39
- // skip subsequent invokcations:
40
- if (instance.shadowRoot == null ||
41
- instance.hasAttribute('data-js-focus-visible')) {
42
- // eslint-disable-next-line @typescript-eslint/no-empty-function
43
- return () => { };
44
- }
45
- // The polyfill might already be loaded. If so, we can apply it to
46
- // the shadow root immediately:
47
- if (self.applyFocusVisiblePolyfill) {
48
- self.applyFocusVisiblePolyfill(instance.shadowRoot);
49
- if (instance.manageAutoFocus) {
50
- instance.manageAutoFocus();
51
- }
9
+ var _a;
10
+ const coordinateWithPolyfill = (instance) => {
11
+ if (instance.shadowRoot == null || instance.hasAttribute("data-js-focus-visible")) {
12
+ return () => {
13
+ };
14
+ }
15
+ if (self.applyFocusVisiblePolyfill) {
16
+ self.applyFocusVisiblePolyfill(instance.shadowRoot);
17
+ if (instance.manageAutoFocus) {
18
+ instance.manageAutoFocus();
19
+ }
20
+ } else {
21
+ const coordinationHandler = () => {
22
+ if (self.applyFocusVisiblePolyfill && instance.shadowRoot) {
23
+ self.applyFocusVisiblePolyfill(instance.shadowRoot);
52
24
  }
53
- else {
54
- const coordinationHandler = () => {
55
- if (self.applyFocusVisiblePolyfill && instance.shadowRoot) {
56
- self.applyFocusVisiblePolyfill(instance.shadowRoot);
57
- }
58
- if (instance.manageAutoFocus) {
59
- instance.manageAutoFocus();
60
- }
61
- };
62
- // Otherwise, wait for the polyfill to be loaded lazily. It might
63
- // never be loaded, but if it is then we can apply it to the
64
- // shadow root at the appropriate time by waiting for the ready
65
- // event:
66
- self.addEventListener('focus-visible-polyfill-ready', coordinationHandler, { once: true });
67
- return () => {
68
- self.removeEventListener('focus-visible-polyfill-ready', coordinationHandler);
69
- };
25
+ if (instance.manageAutoFocus) {
26
+ instance.manageAutoFocus();
70
27
  }
71
- // eslint-disable-next-line @typescript-eslint/no-empty-function
72
- return () => { };
28
+ };
29
+ self.addEventListener("focus-visible-polyfill-ready", coordinationHandler, { once: true });
30
+ return () => {
31
+ self.removeEventListener("focus-visible-polyfill-ready", coordinationHandler);
32
+ };
33
+ }
34
+ return () => {
73
35
  };
74
- const $endPolyfillCoordination = Symbol('endPolyfillCoordination');
75
- // IE11 doesn't natively support custom elements or JavaScript class
76
- // syntax The mixin implementation assumes that the user will take the
77
- // appropriate steps to support both:
78
- class FocusVisibleCoordinator extends SuperClass {
79
- constructor() {
80
- super(...arguments);
81
- this[_a] = null;
82
- }
83
- // Attempt to coordinate with the polyfill when connected to the
84
- // document:
85
- connectedCallback() {
86
- super.connectedCallback && super.connectedCallback();
87
- if (!hasFocusVisible) {
88
- requestAnimationFrame(() => {
89
- if (this[$endPolyfillCoordination] == null) {
90
- this[$endPolyfillCoordination] =
91
- coordinateWithPolyfill(this);
92
- }
93
- });
94
- }
95
- }
96
- disconnectedCallback() {
97
- super.disconnectedCallback && super.disconnectedCallback();
98
- // It's important to remove the polyfill event listener when we
99
- // disconnect, otherwise we will leak the whole element via window:
100
- if (!hasFocusVisible) {
101
- requestAnimationFrame(() => {
102
- if (this[$endPolyfillCoordination] != null) {
103
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
104
- this[$endPolyfillCoordination]();
105
- this[$endPolyfillCoordination] = null;
106
- }
107
- });
108
- }
109
- }
36
+ };
37
+ const $endPolyfillCoordination = Symbol("endPolyfillCoordination");
38
+ class FocusVisibleCoordinator extends SuperClass {
39
+ constructor() {
40
+ super(...arguments);
41
+ this[_a] = null;
42
+ }
43
+ connectedCallback() {
44
+ super.connectedCallback && super.connectedCallback();
45
+ if (!hasFocusVisible) {
46
+ requestAnimationFrame(() => {
47
+ if (this[$endPolyfillCoordination] == null) {
48
+ this[$endPolyfillCoordination] = coordinateWithPolyfill(this);
49
+ }
50
+ });
51
+ }
52
+ }
53
+ disconnectedCallback() {
54
+ super.disconnectedCallback && super.disconnectedCallback();
55
+ if (!hasFocusVisible) {
56
+ requestAnimationFrame(() => {
57
+ if (this[$endPolyfillCoordination] != null) {
58
+ this[$endPolyfillCoordination]();
59
+ this[$endPolyfillCoordination] = null;
60
+ }
61
+ });
62
+ }
110
63
  }
111
- _a = $endPolyfillCoordination;
112
- return FocusVisibleCoordinator;
64
+ }
65
+ _a = $endPolyfillCoordination;
66
+ return FocusVisibleCoordinator;
113
67
  };
114
- //# sourceMappingURL=focus-visible.js.map
68
+ //# sourceMappingURL=focus-visible.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"focus-visible.js","sourceRoot":"","sources":["focus-visible.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAwBF,IAAI,eAAe,GAAG,IAAI,CAAC;AAE3B,IAAI;IACA,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;CACjD;AAAC,OAAO,KAAK,EAAE;IACZ,eAAe,GAAG,KAAK,CAAC;IACxB,6DAA6D;IAC7D,aAAa;IACb,MAAM,CAAC,eAAe,CAAC,CAAC;CAC3B;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAGrC,UAAa,EACZ,EAAE;;IACH,MAAM,sBAAsB,GAAG,CAC3B,QAA0B,EACK,EAAE;QACjC,kEAAkE;QAClE,oEAAoE;QACpE,gCAAgC;QAChC,IACI,QAAQ,CAAC,UAAU,IAAI,IAAI;YAC3B,QAAQ,CAAC,YAAY,CAAC,uBAAuB,CAAC,EAChD;YACE,gEAAgE;YAChE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;SACnB;QAED,kEAAkE;QAClE,+BAA+B;QAC/B,IAAI,IAAI,CAAC,yBAAyB,EAAE;YAChC,IAAI,CAAC,yBAAyB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YAEpD,IAAI,QAAQ,CAAC,eAAe,EAAE;gBAC1B,QAAQ,CAAC,eAAe,EAAE,CAAC;aAC9B;SACJ;aAAM;YACH,MAAM,mBAAmB,GAAG,GAAS,EAAE;gBACnC,IAAI,IAAI,CAAC,yBAAyB,IAAI,QAAQ,CAAC,UAAU,EAAE;oBACvD,IAAI,CAAC,yBAAyB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;iBACvD;gBAED,IAAI,QAAQ,CAAC,eAAe,EAAE;oBAC1B,QAAQ,CAAC,eAAe,EAAE,CAAC;iBAC9B;YACL,CAAC,CAAC;YACF,iEAAiE;YACjE,4DAA4D;YAC5D,+DAA+D;YAC/D,SAAS;YACT,IAAI,CAAC,gBAAgB,CACjB,8BAA8B,EAC9B,mBAAmB,EACnB,EAAE,IAAI,EAAE,IAAI,EAAE,CACjB,CAAC;YAEF,OAAO,GAAG,EAAE;gBACR,IAAI,CAAC,mBAAmB,CACpB,8BAA8B,EAC9B,mBAAmB,CACtB,CAAC;YACN,CAAC,CAAC;SACL;QAED,gEAAgE;QAChE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;IACpB,CAAC,CAAC;IAEF,MAAM,wBAAwB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;IAEnE,oEAAoE;IACpE,sEAAsE;IACtE,qCAAqC;IACrC,MAAM,uBAAwB,SAAQ,UAAU;QAAhD;;YACY,QAA0B,GAC9B,IAAI,CAAC;QA8Bb,CAAC;QA5BG,gEAAgE;QAChE,YAAY;QACH,iBAAiB;YACtB,KAAK,CAAC,iBAAiB,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YACrD,IAAI,CAAC,eAAe,EAAE;gBAClB,qBAAqB,CAAC,GAAG,EAAE;oBACvB,IAAI,IAAI,CAAC,wBAAwB,CAAC,IAAI,IAAI,EAAE;wBACxC,IAAI,CAAC,wBAAwB,CAAC;4BAC1B,sBAAsB,CAAC,IAAI,CAAC,CAAC;qBACpC;gBACL,CAAC,CAAC,CAAC;aACN;QACL,CAAC;QAEQ,oBAAoB;YACzB,KAAK,CAAC,oBAAoB,IAAI,KAAK,CAAC,oBAAoB,EAAE,CAAC;YAC3D,+DAA+D;YAC/D,mEAAmE;YACnE,IAAI,CAAC,eAAe,EAAE;gBAClB,qBAAqB,CAAC,GAAG,EAAE;oBACvB,IAAI,IAAI,CAAC,wBAAwB,CAAC,IAAI,IAAI,EAAE;wBACxC,oEAAoE;wBACpE,IAAI,CAAC,wBAAwB,CAAE,EAAE,CAAC;wBAClC,IAAI,CAAC,wBAAwB,CAAC,GAAG,IAAI,CAAC;qBACzC;gBACL,CAAC,CAAC,CAAC;aACN;QACL,CAAC;KACJ;SA/BY,wBAAwB;IAiCrC,OAAO,uBAAuB,CAAC;AACnC,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\ndeclare global {\n interface Window {\n applyFocusVisiblePolyfill?: (scope: Document | ShadowRoot) => void;\n }\n}\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\ninterface OptionalLifecycleCallbacks {\n connectedCallback?(): void;\n disconnectedCallback?(): void;\n manageAutoFocus?(): void;\n}\n\ntype MixableBaseClass = HTMLElement & OptionalLifecycleCallbacks;\n\ntype EndPolyfillCoordinationCallback = () => void;\n\nlet hasFocusVisible = true;\n\ntry {\n document.body.querySelector(':focus-visible');\n} catch (error) {\n hasFocusVisible = false;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n import('focus-visible');\n}\n\n/**\n * This mixin function is designed to be applied to a class that inherits\n * from HTMLElement. It makes it easy for a custom element to coordinate with\n * the :focus-visible polyfill.\n *\n * NOTE(cdata): The code here was adapted from an example proposed with the\n * introduction of ShadowDOM support in the :focus-visible polyfill.\n *\n * @see https://github.com/WICG/focus-visible/pull/196\n * @param {Function} SuperClass The base class implementation to decorate with\n * implementation that coordinates with the :focus-visible polyfill\n */\nexport const FocusVisiblePolyfillMixin = <\n T extends Constructor<MixableBaseClass>\n>(\n SuperClass: T\n): T => {\n const coordinateWithPolyfill = (\n instance: MixableBaseClass\n ): EndPolyfillCoordinationCallback => {\n // If there is no shadow root, there is no need to coordinate with\n // the polyfill. If we already coordinated with the polyfill, we can\n // skip subsequent invokcations:\n if (\n instance.shadowRoot == null ||\n instance.hasAttribute('data-js-focus-visible')\n ) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n }\n\n // The polyfill might already be loaded. If so, we can apply it to\n // the shadow root immediately:\n if (self.applyFocusVisiblePolyfill) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n } else {\n const coordinationHandler = (): void => {\n if (self.applyFocusVisiblePolyfill && instance.shadowRoot) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n }\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n };\n // Otherwise, wait for the polyfill to be loaded lazily. It might\n // never be loaded, but if it is then we can apply it to the\n // shadow root at the appropriate time by waiting for the ready\n // event:\n self.addEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler,\n { once: true }\n );\n\n return () => {\n self.removeEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler\n );\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n };\n\n const $endPolyfillCoordination = Symbol('endPolyfillCoordination');\n\n // IE11 doesn't natively support custom elements or JavaScript class\n // syntax The mixin implementation assumes that the user will take the\n // appropriate steps to support both:\n class FocusVisibleCoordinator extends SuperClass {\n private [$endPolyfillCoordination]: EndPolyfillCoordinationCallback | null =\n null;\n\n // Attempt to coordinate with the polyfill when connected to the\n // document:\n override connectedCallback(): void {\n super.connectedCallback && super.connectedCallback();\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] == null) {\n this[$endPolyfillCoordination] =\n coordinateWithPolyfill(this);\n }\n });\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback && super.disconnectedCallback();\n // It's important to remove the polyfill event listener when we\n // disconnect, otherwise we will leak the whole element via window:\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] != null) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this[$endPolyfillCoordination]!();\n this[$endPolyfillCoordination] = null;\n }\n });\n }\n }\n }\n\n return FocusVisibleCoordinator;\n};\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["focus-visible.ts"],
4
+ "sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\ndeclare global {\n interface Window {\n applyFocusVisiblePolyfill?: (scope: Document | ShadowRoot) => void;\n }\n}\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\ninterface OptionalLifecycleCallbacks {\n connectedCallback?(): void;\n disconnectedCallback?(): void;\n manageAutoFocus?(): void;\n}\n\ntype MixableBaseClass = HTMLElement & OptionalLifecycleCallbacks;\n\ntype EndPolyfillCoordinationCallback = () => void;\n\nlet hasFocusVisible = true;\n\ntry {\n document.body.querySelector(':focus-visible');\n} catch (error) {\n hasFocusVisible = false;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n import('focus-visible');\n}\n\n/**\n * This mixin function is designed to be applied to a class that inherits\n * from HTMLElement. It makes it easy for a custom element to coordinate with\n * the :focus-visible polyfill.\n *\n * NOTE(cdata): The code here was adapted from an example proposed with the\n * introduction of ShadowDOM support in the :focus-visible polyfill.\n *\n * @see https://github.com/WICG/focus-visible/pull/196\n * @param {Function} SuperClass The base class implementation to decorate with\n * implementation that coordinates with the :focus-visible polyfill\n */\nexport const FocusVisiblePolyfillMixin = <\n T extends Constructor<MixableBaseClass>\n>(\n SuperClass: T\n): T => {\n const coordinateWithPolyfill = (\n instance: MixableBaseClass\n ): EndPolyfillCoordinationCallback => {\n // If there is no shadow root, there is no need to coordinate with\n // the polyfill. If we already coordinated with the polyfill, we can\n // skip subsequent invokcations:\n if (\n instance.shadowRoot == null ||\n instance.hasAttribute('data-js-focus-visible')\n ) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n }\n\n // The polyfill might already be loaded. If so, we can apply it to\n // the shadow root immediately:\n if (self.applyFocusVisiblePolyfill) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n } else {\n const coordinationHandler = (): void => {\n if (self.applyFocusVisiblePolyfill && instance.shadowRoot) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n }\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n };\n // Otherwise, wait for the polyfill to be loaded lazily. It might\n // never be loaded, but if it is then we can apply it to the\n // shadow root at the appropriate time by waiting for the ready\n // event:\n self.addEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler,\n { once: true }\n );\n\n return () => {\n self.removeEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler\n );\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n };\n\n const $endPolyfillCoordination = Symbol('endPolyfillCoordination');\n\n // IE11 doesn't natively support custom elements or JavaScript class\n // syntax The mixin implementation assumes that the user will take the\n // appropriate steps to support both:\n class FocusVisibleCoordinator extends SuperClass {\n private [$endPolyfillCoordination]: EndPolyfillCoordinationCallback | null =\n null;\n\n // Attempt to coordinate with the polyfill when connected to the\n // document:\n override connectedCallback(): void {\n super.connectedCallback && super.connectedCallback();\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] == null) {\n this[$endPolyfillCoordination] =\n coordinateWithPolyfill(this);\n }\n });\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback && super.disconnectedCallback();\n // It's important to remove the polyfill event listener when we\n // disconnect, otherwise we will leak the whole element via window:\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] != null) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this[$endPolyfillCoordination]!();\n this[$endPolyfillCoordination] = null;\n }\n });\n }\n }\n }\n\n return FocusVisibleCoordinator;\n};\n"],
5
+ "mappings": "AAkCA,IAAI,kBAAkB;AAEtB,IAAI;AACA,WAAS,KAAK,cAAc,gBAAgB;AAChD,SAAS,OAAP;AACE,oBAAkB;AAGlB,SAAO;AACX;AAcO,aAAM,4BAA4B,CAGrC,eACI;AA7DR;AA8DI,QAAM,yBAAyB,CAC3B,aACkC;AAIlC,QACI,SAAS,cAAc,QACvB,SAAS,aAAa,uBAAuB,GAC/C;AAEE,aAAO,MAAM;AAAA,MAAC;AAAA,IAClB;AAIA,QAAI,KAAK,2BAA2B;AAChC,WAAK,0BAA0B,SAAS,UAAU;AAElD,UAAI,SAAS,iBAAiB;AAC1B,iBAAS,gBAAgB;AAAA,MAC7B;AAAA,IACJ,OAAO;AACH,YAAM,sBAAsB,MAAY;AACpC,YAAI,KAAK,6BAA6B,SAAS,YAAY;AACvD,eAAK,0BAA0B,SAAS,UAAU;AAAA,QACtD;AAEA,YAAI,SAAS,iBAAiB;AAC1B,mBAAS,gBAAgB;AAAA,QAC7B;AAAA,MACJ;AAKA,WAAK,iBACD,gCACA,qBACA,EAAE,MAAM,KAAK,CACjB;AAEA,aAAO,MAAM;AACT,aAAK,oBACD,gCACA,mBACJ;AAAA,MACJ;AAAA,IACJ;AAGA,WAAO,MAAM;AAAA,IAAC;AAAA,EAClB;AAEA,QAAM,2BAA2B,OAAO,yBAAyB;AAKjE,QAAM,gCAAgC,WAAW;AAAA,IAAjD;AAAA;AACa,iBACL;AAAA;AAAA,IAIK,oBAA0B;AAC/B,YAAM,qBAAqB,MAAM,kBAAkB;AACnD,UAAI,CAAC,iBAAiB;AAClB,8BAAsB,MAAM;AACxB,cAAI,KAAK,6BAA6B,MAAM;AACxC,iBAAK,4BACD,uBAAuB,IAAI;AAAA,UACnC;AAAA,QACJ,CAAC;AAAA,MACL;AAAA,IACJ;AAAA,IAES,uBAA6B;AAClC,YAAM,wBAAwB,MAAM,qBAAqB;AAGzD,UAAI,CAAC,iBAAiB;AAClB,8BAAsB,MAAM;AACxB,cAAI,KAAK,6BAA6B,MAAM;AAExC,iBAAK,0BAA2B;AAChC,iBAAK,4BAA4B;AAAA,UACrC;AAAA,QACJ,CAAC;AAAA,MACL;AAAA,IACJ;AAAA,EACJ;AAzJJ,EA0HiB;AAiCb,SAAO;AACX;",
6
+ "names": []
7
+ }
@@ -0,0 +1,190 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result)
9
+ __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ import { SpectrumElement } from "@spectrum-web-components/base";
13
+ import { property } from "@spectrum-web-components/base/src/decorators.js";
14
+ import { FocusVisiblePolyfillMixin } from "./focus-visible.dev.js";
15
+ export class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.disabled = false;
19
+ this.autofocus = false;
20
+ this._tabIndex = 0;
21
+ this.manipulatingTabindex = false;
22
+ }
23
+ get tabIndex() {
24
+ if (this.focusElement === this) {
25
+ const tabindex = this.hasAttribute("tabindex") ? Number(this.getAttribute("tabindex")) : NaN;
26
+ return !isNaN(tabindex) ? tabindex : -1;
27
+ }
28
+ const tabIndexAttribute = parseFloat(this.hasAttribute("tabindex") ? this.getAttribute("tabindex") || "0" : "0");
29
+ if (this.disabled || tabIndexAttribute < 0) {
30
+ return -1;
31
+ }
32
+ if (!this.focusElement) {
33
+ return tabIndexAttribute;
34
+ }
35
+ return this.focusElement.tabIndex;
36
+ }
37
+ set tabIndex(tabIndex) {
38
+ if (this.manipulatingTabindex) {
39
+ this.manipulatingTabindex = false;
40
+ return;
41
+ }
42
+ if (this.focusElement === this) {
43
+ if (tabIndex !== this.tabIndex) {
44
+ this._tabIndex = tabIndex;
45
+ const tabindex = this.disabled ? "-1" : "" + tabIndex;
46
+ this.setAttribute("tabindex", tabindex);
47
+ }
48
+ return;
49
+ }
50
+ if (tabIndex === -1) {
51
+ this.addEventListener("pointerdown", this.onPointerdownManagementOfTabIndex);
52
+ } else {
53
+ this.manipulatingTabindex = true;
54
+ this.removeEventListener("pointerdown", this.onPointerdownManagementOfTabIndex);
55
+ }
56
+ if (tabIndex === -1 || this.disabled) {
57
+ this.setAttribute("tabindex", "-1");
58
+ this.removeAttribute("focusable");
59
+ if (tabIndex !== -1) {
60
+ this.manageFocusElementTabindex(tabIndex);
61
+ }
62
+ return;
63
+ }
64
+ this.setAttribute("focusable", "");
65
+ if (this.hasAttribute("tabindex")) {
66
+ this.removeAttribute("tabindex");
67
+ } else {
68
+ this.manipulatingTabindex = false;
69
+ }
70
+ this.manageFocusElementTabindex(tabIndex);
71
+ }
72
+ onPointerdownManagementOfTabIndex() {
73
+ if (this.tabIndex === -1) {
74
+ this.tabIndex = 0;
75
+ this.focus({ preventScroll: true });
76
+ }
77
+ }
78
+ async manageFocusElementTabindex(tabIndex) {
79
+ if (!this.focusElement) {
80
+ await this.updateComplete;
81
+ }
82
+ if (tabIndex === null) {
83
+ this.focusElement.removeAttribute("tabindex");
84
+ } else {
85
+ this.focusElement.tabIndex = tabIndex;
86
+ }
87
+ }
88
+ get focusElement() {
89
+ throw new Error("Must implement focusElement getter!");
90
+ }
91
+ focus(options) {
92
+ if (this.disabled || !this.focusElement) {
93
+ return;
94
+ }
95
+ if (this.focusElement !== this) {
96
+ this.focusElement.focus(options);
97
+ } else {
98
+ HTMLElement.prototype.focus.apply(this, [options]);
99
+ }
100
+ }
101
+ blur() {
102
+ const focusElement = this.focusElement || this;
103
+ if (focusElement !== this) {
104
+ focusElement.blur();
105
+ } else {
106
+ HTMLElement.prototype.blur.apply(this);
107
+ }
108
+ }
109
+ click() {
110
+ if (this.disabled) {
111
+ return;
112
+ }
113
+ const focusElement = this.focusElement || this;
114
+ if (focusElement !== this) {
115
+ focusElement.click();
116
+ } else {
117
+ HTMLElement.prototype.click.apply(this);
118
+ }
119
+ }
120
+ manageAutoFocus() {
121
+ if (this.autofocus) {
122
+ this.dispatchEvent(new KeyboardEvent("keydown", {
123
+ code: "Tab"
124
+ }));
125
+ this.focusElement.focus();
126
+ }
127
+ }
128
+ firstUpdated(changes) {
129
+ super.firstUpdated(changes);
130
+ if (!this.hasAttribute("tabindex") || this.getAttribute("tabindex") !== "-1") {
131
+ this.setAttribute("focusable", "");
132
+ }
133
+ }
134
+ update(changedProperties) {
135
+ if (changedProperties.has("disabled")) {
136
+ this.handleDisabledChanged(this.disabled, changedProperties.get("disabled"));
137
+ }
138
+ super.update(changedProperties);
139
+ }
140
+ updated(changedProperties) {
141
+ super.updated(changedProperties);
142
+ if (changedProperties.has("disabled") && this.disabled) {
143
+ this.blur();
144
+ }
145
+ }
146
+ async handleDisabledChanged(disabled, oldDisabled) {
147
+ const canSetDisabled = () => this.focusElement !== this && typeof this.focusElement.disabled !== "undefined";
148
+ if (disabled) {
149
+ this.manipulatingTabindex = true;
150
+ this.setAttribute("tabindex", "-1");
151
+ await this.updateComplete;
152
+ if (canSetDisabled()) {
153
+ this.focusElement.disabled = true;
154
+ } else {
155
+ this.setAttribute("aria-disabled", "true");
156
+ }
157
+ } else if (oldDisabled) {
158
+ this.manipulatingTabindex = true;
159
+ if (this.focusElement === this) {
160
+ this.setAttribute("tabindex", "" + this._tabIndex);
161
+ } else {
162
+ this.removeAttribute("tabindex");
163
+ }
164
+ await this.updateComplete;
165
+ if (canSetDisabled()) {
166
+ this.focusElement.disabled = false;
167
+ } else {
168
+ this.removeAttribute("aria-disabled");
169
+ }
170
+ }
171
+ }
172
+ connectedCallback() {
173
+ super.connectedCallback();
174
+ this.updateComplete.then(() => {
175
+ requestAnimationFrame(() => {
176
+ this.manageAutoFocus();
177
+ });
178
+ });
179
+ }
180
+ }
181
+ __decorateClass([
182
+ property({ type: Boolean, reflect: true })
183
+ ], Focusable.prototype, "disabled", 2);
184
+ __decorateClass([
185
+ property({ type: Boolean })
186
+ ], Focusable.prototype, "autofocus", 2);
187
+ __decorateClass([
188
+ property({ type: Number })
189
+ ], Focusable.prototype, "tabIndex", 1);
190
+ //# sourceMappingURL=focusable.dev.js.map