@spectrum-web-components/shared 0.14.6-devmode.0 → 0.15.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/shared",
3
- "version": "0.14.6-devmode.0+1a8b29491",
3
+ "version": "0.15.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -89,14 +89,14 @@
89
89
  ],
90
90
  "dependencies": {
91
91
  "@lit-labs/observers": "^1.0.1",
92
- "@spectrum-web-components/base": "^0.6.1-devmode.0+1a8b29491",
92
+ "@spectrum-web-components/base": "^0.7.0",
93
93
  "focus-visible": "^5.1.0",
94
94
  "tslib": "^2.0.0"
95
95
  },
96
96
  "types": "./src/index.d.ts",
97
97
  "customElements": "custom-elements.json",
98
98
  "sideEffects": [
99
- "./**/*.dev.ts"
99
+ "./**/*.dev.js"
100
100
  ],
101
- "gitHead": "1a8b294911ab377fa4f07e16eb016f1e3bf7b517"
101
+ "gitHead": "05c81318844160db3f8156144106e643507fef97"
102
102
  }
@@ -1,6 +1,2 @@
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
- };
1
+ const e='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"])';export const firstFocusableIn=t=>t.querySelector(e);
6
2
  //# sourceMappingURL=first-focusable-in.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["first-focusable-in.ts"],
4
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;",
5
+ "mappings": "AAcA,KAAM,GACF,sNAEG,YAAM,kBAAmB,AAC5B,GAEuB,EAAK,cACxB,CACJ",
6
6
  "names": []
7
7
  }
@@ -1,68 +1,2 @@
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
- };
1
+ let e=!0;try{document.body.querySelector(":focus-visible")}catch(i){e=!1,import("focus-visible")}export const FocusVisiblePolyfillMixin=i=>{var n;const s=l=>{if(l.shadowRoot==null||l.hasAttribute("data-js-focus-visible"))return()=>{};if(self.applyFocusVisiblePolyfill)self.applyFocusVisiblePolyfill(l.shadowRoot),l.manageAutoFocus&&l.manageAutoFocus();else{const a=()=>{self.applyFocusVisiblePolyfill&&l.shadowRoot&&self.applyFocusVisiblePolyfill(l.shadowRoot),l.manageAutoFocus&&l.manageAutoFocus()};return self.addEventListener("focus-visible-polyfill-ready",a,{once:!0}),()=>{self.removeEventListener("focus-visible-polyfill-ready",a)}}return()=>{}},o=Symbol("endPolyfillCoordination");class t extends i{constructor(){super(...arguments);this[n]=null}connectedCallback(){super.connectedCallback&&super.connectedCallback(),e||requestAnimationFrame(()=>{this[o]==null&&(this[o]=s(this))})}disconnectedCallback(){super.disconnectedCallback&&super.disconnectedCallback(),e||requestAnimationFrame(()=>{this[o]!=null&&(this[o](),this[o]=null)})}}return n=o,t};
68
2
  //# sourceMappingURL=focus-visible.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["focus-visible.ts"],
4
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,QA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M,EAA2B,OAAO,yBAAyB,EAKjE,MAAM,SAAgC,EAAW,CAAjD,kCACa,QACL,KAIK,mBAA0B,CAC/B,MAAM,mBAAqB,MAAM,kBAAkB,EAC9C,GACD,sBAAsB,IAAM,CACxB,AAAI,KAAK,IAA6B,MAClC,MAAK,GACD,EAAuB,IAAI,EAEvC,CAAC,CAET,CAES,sBAA6B,CAClC,MAAM,sBAAwB,MAAM,qBAAqB,EAGpD,GACD,sBAAsB,IAAM,CACxB,AAAI,KAAK,IAA6B,MAElC,MAAK,GAA2B,EAChC,KAAK,GAA4B,KAEzC,CAAC,CAET,CACJ,CAzJJ,MA0HiB,KAiCN,CACX",
6
6
  "names": []
7
7
  }
package/src/focusable.js CHANGED
@@ -1,190 +1,2 @@
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.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);
1
+ var d=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var a=(n,e,t,i)=>{for(var s=i>1?void 0:i?u(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&d(e,t,s),s};import{SpectrumElement as b}from"@spectrum-web-components/base";import{property as l}from"@spectrum-web-components/base/src/decorators.js";import{FocusVisiblePolyfillMixin as h}from"./focus-visible.js";export class Focusable extends h(b){constructor(){super(...arguments);this.disabled=!1;this.autofocus=!1;this._tabIndex=0;this.manipulatingTabindex=!1}get tabIndex(){if(this.focusElement===this){const t=this.hasAttribute("tabindex")?Number(this.getAttribute("tabindex")):NaN;return isNaN(t)?-1:t}const e=parseFloat(this.hasAttribute("tabindex")&&this.getAttribute("tabindex")||"0");return this.disabled||e<0?-1:this.focusElement?this.focusElement.tabIndex:e}set tabIndex(e){if(this.manipulatingTabindex){this.manipulatingTabindex=!1;return}if(this.focusElement===this){if(e!==this.tabIndex){this._tabIndex=e;const t=this.disabled?"-1":""+e;this.setAttribute("tabindex",t)}return}if(e===-1?this.addEventListener("pointerdown",this.onPointerdownManagementOfTabIndex):(this.manipulatingTabindex=!0,this.removeEventListener("pointerdown",this.onPointerdownManagementOfTabIndex)),e===-1||this.disabled){this.setAttribute("tabindex","-1"),this.removeAttribute("focusable"),e!==-1&&this.manageFocusElementTabindex(e);return}this.setAttribute("focusable",""),this.hasAttribute("tabindex")?this.removeAttribute("tabindex"):this.manipulatingTabindex=!1,this.manageFocusElementTabindex(e)}onPointerdownManagementOfTabIndex(){this.tabIndex===-1&&(this.tabIndex=0,this.focus({preventScroll:!0}))}async manageFocusElementTabindex(e){this.focusElement||await this.updateComplete,e===null?this.focusElement.removeAttribute("tabindex"):this.focusElement.tabIndex=e}get focusElement(){throw new Error("Must implement focusElement getter!")}focus(e){this.disabled||!this.focusElement||(this.focusElement!==this?this.focusElement.focus(e):HTMLElement.prototype.focus.apply(this,[e]))}blur(){const e=this.focusElement||this;e!==this?e.blur():HTMLElement.prototype.blur.apply(this)}click(){if(this.disabled)return;const e=this.focusElement||this;e!==this?e.click():HTMLElement.prototype.click.apply(this)}manageAutoFocus(){this.autofocus&&(this.dispatchEvent(new KeyboardEvent("keydown",{code:"Tab"})),this.focusElement.focus())}firstUpdated(e){super.firstUpdated(e),(!this.hasAttribute("tabindex")||this.getAttribute("tabindex")!=="-1")&&this.setAttribute("focusable","")}update(e){e.has("disabled")&&this.handleDisabledChanged(this.disabled,e.get("disabled")),super.update(e)}updated(e){super.updated(e),e.has("disabled")&&this.disabled&&this.blur()}async handleDisabledChanged(e,t){const i=()=>this.focusElement!==this&&typeof this.focusElement.disabled!="undefined";e?(this.manipulatingTabindex=!0,this.setAttribute("tabindex","-1"),await this.updateComplete,i()?this.focusElement.disabled=!0:this.setAttribute("aria-disabled","true")):t&&(this.manipulatingTabindex=!0,this.focusElement===this?this.setAttribute("tabindex",""+this._tabIndex):this.removeAttribute("tabindex"),await this.updateComplete,i()?this.focusElement.disabled=!1:this.removeAttribute("aria-disabled"))}connectedCallback(){super.connectedCallback(),this.updateComplete.then(()=>{requestAnimationFrame(()=>{this.manageAutoFocus()})})}}a([l({type:Boolean,reflect:!0})],Focusable.prototype,"disabled",2),a([l({type:Boolean})],Focusable.prototype,"autofocus",2),a([l({type:Number})],Focusable.prototype,"tabIndex",1);
190
2
  //# sourceMappingURL=focusable.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["focusable.ts"],
4
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*/\nimport { PropertyValues, SpectrumElement } from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\n\nimport { FocusVisiblePolyfillMixin } from './focus-visible.js';\n\ntype DisableableElement = HTMLElement & { disabled?: boolean };\n\n/**\n * Focusable base class handles tabindex setting into shadowed elements automatically.\n *\n * This implementation is based heavily on the aybolit delegate-focus-mixin at\n * https://github.com/web-padawan/aybolit/blob/master/packages/core/src/mixins/delegate-focus-mixin.js\n */\nexport class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {\n /**\n * Disable this control. It will not receive focus or events\n */\n @property({ type: Boolean, reflect: true })\n public disabled = false;\n\n /**\n * When this control is rendered, focus it automatically\n * @private\n */\n @property({ type: Boolean })\n public override autofocus = false;\n\n /**\n * The tab index to apply to this control. See general documentation about\n * the tabindex HTML property\n *\n * @private\n */\n @property({ type: Number })\n public override get tabIndex(): number {\n if (this.focusElement === this) {\n const tabindex = this.hasAttribute('tabindex')\n ? Number(this.getAttribute('tabindex'))\n : NaN;\n return !isNaN(tabindex) ? tabindex : -1;\n }\n const tabIndexAttribute = parseFloat(\n this.hasAttribute('tabindex')\n ? (this.getAttribute('tabindex') as string) || '0'\n : '0'\n );\n // When `disabled` tabindex is -1.\n // When host tabindex -1, use that as the cache.\n if (this.disabled || tabIndexAttribute < 0) {\n return -1;\n }\n // When `focusElement` isn't available yet,\n // use host tabindex as the cache.\n if (!this.focusElement) {\n return tabIndexAttribute;\n }\n // All other times, use the tabindex of `focusElement`\n // as the cache for this value.\n return this.focusElement.tabIndex;\n }\n public override set tabIndex(tabIndex: number) {\n // Flipping `manipulatingTabindex` to true before a change\n // allows for that change NOT to effect the cached value of tabindex\n if (this.manipulatingTabindex) {\n this.manipulatingTabindex = false;\n return;\n }\n if (this.focusElement === this) {\n if (tabIndex !== this.tabIndex) {\n this._tabIndex = tabIndex;\n const tabindex = this.disabled ? '-1' : '' + tabIndex;\n this.setAttribute('tabindex', tabindex);\n }\n return;\n }\n if (tabIndex === -1) {\n this.addEventListener(\n 'pointerdown',\n this.onPointerdownManagementOfTabIndex\n );\n } else {\n // All code paths are about to address the host tabindex without side effect.\n this.manipulatingTabindex = true;\n this.removeEventListener(\n 'pointerdown',\n this.onPointerdownManagementOfTabIndex\n );\n }\n if (tabIndex === -1 || this.disabled) {\n // Do not cange the tabindex of `focusElement` as it is the \"old\" value cache.\n // Make element NOT focusable.\n this.setAttribute('tabindex', '-1');\n this.removeAttribute('focusable');\n if (tabIndex !== -1) {\n // Cache all NON-`-1` values on the `focusElement`.\n this.manageFocusElementTabindex(tabIndex);\n }\n return;\n }\n this.setAttribute('focusable', '');\n if (this.hasAttribute('tabindex')) {\n this.removeAttribute('tabindex');\n } else {\n // You can't remove an attribute that isn't there,\n // manually end the `manipulatingTabindex` guard.\n this.manipulatingTabindex = false;\n }\n this.manageFocusElementTabindex(tabIndex);\n }\n private _tabIndex = 0;\n\n private onPointerdownManagementOfTabIndex(): void {\n if (this.tabIndex === -1) {\n this.tabIndex = 0;\n this.focus({ preventScroll: true });\n }\n }\n\n private async manageFocusElementTabindex(tabIndex: number): Promise<void> {\n if (!this.focusElement) {\n // allow setting these values to be async when needed.\n await this.updateComplete;\n }\n if (tabIndex === null) {\n this.focusElement.removeAttribute('tabindex');\n } else {\n this.focusElement.tabIndex = tabIndex;\n }\n }\n\n private manipulatingTabindex = false;\n\n /**\n * @private\n */\n public get focusElement(): DisableableElement {\n throw new Error('Must implement focusElement getter!');\n }\n\n public override focus(options?: FocusOptions): void {\n if (this.disabled || !this.focusElement) {\n return;\n }\n\n if (this.focusElement !== this) {\n this.focusElement.focus(options);\n } else {\n HTMLElement.prototype.focus.apply(this, [options]);\n }\n }\n\n public override blur(): void {\n const focusElement = this.focusElement || this;\n if (focusElement !== this) {\n focusElement.blur();\n } else {\n HTMLElement.prototype.blur.apply(this);\n }\n }\n\n public override click(): void {\n if (this.disabled) {\n return;\n }\n\n const focusElement = this.focusElement || this;\n if (focusElement !== this) {\n focusElement.click();\n } else {\n HTMLElement.prototype.click.apply(this);\n }\n }\n\n protected manageAutoFocus(): void {\n if (this.autofocus) {\n /**\n * Trick :focus-visible polyfill into thinking keyboard based focus\n *\n * @private\n **/\n this.dispatchEvent(\n new KeyboardEvent('keydown', {\n code: 'Tab',\n })\n );\n this.focusElement.focus();\n }\n }\n\n protected override firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n if (\n !this.hasAttribute('tabindex') ||\n this.getAttribute('tabindex') !== '-1'\n ) {\n this.setAttribute('focusable', '');\n }\n }\n\n protected override update(changedProperties: PropertyValues): void {\n if (changedProperties.has('disabled')) {\n this.handleDisabledChanged(\n this.disabled,\n changedProperties.get('disabled') as boolean\n );\n }\n\n super.update(changedProperties);\n }\n\n protected override updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n\n if (changedProperties.has('disabled') && this.disabled) {\n this.blur();\n }\n }\n\n private async handleDisabledChanged(\n disabled: boolean,\n oldDisabled: boolean\n ): Promise<void> {\n const canSetDisabled = (): boolean =>\n this.focusElement !== this &&\n typeof this.focusElement.disabled !== 'undefined';\n if (disabled) {\n this.manipulatingTabindex = true;\n this.setAttribute('tabindex', '-1');\n await this.updateComplete;\n if (canSetDisabled()) {\n this.focusElement.disabled = true;\n } else {\n this.setAttribute('aria-disabled', 'true');\n }\n } else if (oldDisabled) {\n this.manipulatingTabindex = true;\n if (this.focusElement === this) {\n this.setAttribute('tabindex', '' + this._tabIndex);\n } else {\n this.removeAttribute('tabindex');\n }\n await this.updateComplete;\n if (canSetDisabled()) {\n this.focusElement.disabled = false;\n } else {\n this.removeAttribute('aria-disabled');\n }\n }\n }\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this.upd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AAC,GACN,AArBjB,UAqBiB",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,2 @@
1
- export const getActiveElement = (el) => {
2
- return el.getRootNode().activeElement;
3
- };
1
+ export const getActiveElement=e=>e.getRootNode().activeElement;
4
2
  //# sourceMappingURL=get-active-element.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["get-active-element.ts"],
4
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\n/* c8 ignore next 3 */\nexport const getActiveElement = (el: Node): Element | null => {\n return (el.getRootNode() as Document).activeElement;\n};\n"],
5
- "mappings": "AAaO,aAAM,mBAAmB,CAAC,OAA6B;AAC1D,SAAQ,GAAG,YAAY,EAAe;AAC1C;",
5
+ "mappings": "AAaO,YAAM,kBAAmB,AAAC,GACrB,EAAG,YAAY,EAAe",
6
6
  "names": []
7
7
  }
@@ -1,12 +1,2 @@
1
- export const getDeepElementFromPoint = (x, y) => {
2
- let target = document.elementFromPoint(x, y);
3
- while (target == null ? void 0 : target.shadowRoot) {
4
- const innerTarget = target.shadowRoot.elementFromPoint(x, y);
5
- if (!innerTarget || innerTarget === target) {
6
- break;
7
- }
8
- target = innerTarget;
9
- }
10
- return target;
11
- };
1
+ export const getDeepElementFromPoint=(o,t)=>{let e=document.elementFromPoint(o,t);for(;e!=null&&e.shadowRoot;){const n=e.shadowRoot.elementFromPoint(o,t);if(!n||n===e)break;e=n}return e};
12
2
  //# sourceMappingURL=get-deep-element-from-point.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["get-deep-element-from-point.ts"],
4
4
  "sourcesContent": ["/*\nCopyright 2022 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\nexport const getDeepElementFromPoint = (\n x: number,\n y: number\n): Element | null => {\n let target = document.elementFromPoint(x, y);\n while (target?.shadowRoot) {\n const innerTarget = (\n target.shadowRoot as unknown as {\n elementFromPoint: (x: number, y: number) => Element | null;\n }\n ).elementFromPoint(x, y);\n if (!innerTarget || innerTarget === target) {\n break;\n }\n target = innerTarget;\n }\n return target;\n};\n"],
5
- "mappings": "AAYO,aAAM,0BAA0B,CACnC,GACA,MACiB;AACjB,MAAI,SAAS,SAAS,iBAAiB,GAAG,CAAC;AAC3C,SAAO,iCAAQ,YAAY;AACvB,UAAM,cACF,OAAO,WAGT,iBAAiB,GAAG,CAAC;AACvB,QAAI,CAAC,eAAe,gBAAgB,QAAQ;AACxC;AAAA,IACJ;AACA,aAAS;AAAA,EACb;AACA,SAAO;AACX;",
5
+ "mappings": "AAYO,YAAM,yBAA0B,CACnC,EACA,IACiB,CACjB,GAAI,GAAS,SAAS,iBAAiB,EAAG,CAAC,EAC3C,KAAO,WAAQ,YAAY,CACvB,KAAM,GACF,EAAO,WAGT,iBAAiB,EAAG,CAAC,EACvB,GAAI,CAAC,GAAe,IAAgB,EAChC,MAEJ,EAAS,CACb,CACA,MAAO,EACX",
6
6
  "names": []
7
7
  }
package/src/index.js CHANGED
@@ -1,10 +1,2 @@
1
- export * from "./first-focusable-in.js";
2
- export * from "./focus-visible.js";
3
- export * from "./focusable.js";
4
- export * from "./get-active-element.js";
5
- export * from "./like-anchor.js";
6
- export * from "./observe-slot-presence.js";
7
- export * from "./observe-slot-text.js";
8
- export * from "./platform.js";
9
- export * from "./reparent-children.js";
1
+ export*from"./first-focusable-in.js";export*from"./focus-visible.js";export*from"./focusable.js";export*from"./get-active-element.js";export*from"./like-anchor.js";export*from"./observe-slot-presence.js";export*from"./observe-slot-text.js";export*from"./platform.js";export*from"./reparent-children.js";
10
2
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["index.ts"],
4
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\nexport * from './first-focusable-in.js';\nexport * from './focus-visible.js';\nexport * from './focusable.js';\nexport * from './get-active-element.js';\nexport * from './like-anchor.js';\nexport * from './observe-slot-presence.js';\nexport * from './observe-slot-text.js';\nexport * from './platform.js';\nexport * from './reparent-children.js';\n"],
5
- "mappings": "AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;",
5
+ "mappings": "AAYA,qCACA,gCACA,4BACA,qCACA,8BACA,wCACA,oCACA,2BACA",
6
6
  "names": []
7
7
  }
@@ -1,58 +1,13 @@
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 {
13
- html
14
- } from "@spectrum-web-components/base";
15
- import { property } from "@spectrum-web-components/base/src/decorators.js";
16
- import { ifDefined } from "@spectrum-web-components/base/src/directives.js";
17
- export function LikeAnchor(constructor) {
18
- class LikeAnchorElement extends constructor {
19
- renderAnchor({
20
- id,
21
- className,
22
- ariaHidden,
23
- labelledby,
24
- tabindex,
25
- anchorContent = html`<slot></slot>`
26
- }) {
27
- return html`<a
28
- id=${id}
29
- class=${ifDefined(className)}
30
- href=${ifDefined(this.href)}
31
- download=${ifDefined(this.download)}
32
- target=${ifDefined(this.target)}
33
- aria-label=${ifDefined(this.label)}
34
- aria-labelledby=${ifDefined(labelledby)}
35
- aria-hidden=${ifDefined(ariaHidden ? "true" : void 0)}
36
- tabindex=${ifDefined(tabindex)}
37
- rel=${ifDefined(this.rel)}
38
- >${anchorContent}</a>`;
39
- }
40
- }
41
- __decorateClass([
42
- property({ reflect: true })
43
- ], LikeAnchorElement.prototype, "download", 2);
44
- __decorateClass([
45
- property()
46
- ], LikeAnchorElement.prototype, "label", 2);
47
- __decorateClass([
48
- property({ reflect: true })
49
- ], LikeAnchorElement.prototype, "href", 2);
50
- __decorateClass([
51
- property({ reflect: true })
52
- ], LikeAnchorElement.prototype, "target", 2);
53
- __decorateClass([
54
- property({ reflect: true })
55
- ], LikeAnchorElement.prototype, "rel", 2);
56
- return LikeAnchorElement;
57
- }
1
+ var f=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var l=(s,e,p,n)=>{for(var t=n>1?void 0:n?b(e,p):e,a=s.length-1,i;a>=0;a--)(i=s[a])&&(t=(n?i(e,p,t):i(t))||t);return n&&t&&f(e,p,t),t};import{html as d}from"@spectrum-web-components/base";import{property as o}from"@spectrum-web-components/base/src/decorators.js";import{ifDefined as r}from"@spectrum-web-components/base/src/directives.js";export function LikeAnchor(s){class e extends s{renderAnchor({id:n,className:t,ariaHidden:a,labelledby:i,tabindex:c,anchorContent:u=d`<slot></slot>`}){return d`<a
2
+ id=${n}
3
+ class=${r(t)}
4
+ href=${r(this.href)}
5
+ download=${r(this.download)}
6
+ target=${r(this.target)}
7
+ aria-label=${r(this.label)}
8
+ aria-labelledby=${r(i)}
9
+ aria-hidden=${r(a?"true":void 0)}
10
+ tabindex=${r(c)}
11
+ rel=${r(this.rel)}
12
+ >${u}</a>`}}return l([o({reflect:!0})],e.prototype,"download",2),l([o()],e.prototype,"label",2),l([o({reflect:!0})],e.prototype,"href",2),l([o({reflect:!0})],e.prototype,"target",2),l([o({reflect:!0})],e.prototype,"rel",2),e}
58
13
  //# sourceMappingURL=like-anchor.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["like-anchor.ts"],
4
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*/\nimport {\n html,\n ReactiveElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\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\ntype RenderAnchorOptions = {\n id: string;\n className?: string;\n ariaHidden?: boolean;\n anchorContent?: TemplateResult | TemplateResult[];\n labelledby?: string;\n tabindex?: -1 | 0;\n};\n\nexport interface LikeAnchorInterface {\n download?: string;\n label?: string;\n href?: string;\n rel?: string;\n target?: '_blank' | '_parent' | '_self' | '_top';\n renderAnchor(options: RenderAnchorOptions): TemplateResult;\n}\n\nexport function LikeAnchor<T extends Constructor<ReactiveElement>>(\n constructor: T\n): T & Constructor<LikeAnchorInterface> {\n class LikeAnchorElement extends constructor {\n @property({ reflect: true })\n public download?: string;\n\n @property()\n public label?: string;\n\n @property({ reflect: true })\n public href?: string;\n\n @property({ reflect: true })\n public target?: '_blank' | '_parent' | '_self' | '_top';\n\n @property({ reflect: true })\n public rel?: string;\n\n public renderAnchor({\n id,\n className,\n ariaHidden,\n labelledby,\n tabindex,\n // prettier-ignore\n anchorContent = html`<slot></slot>`,\n }: RenderAnchorOptions): TemplateResult {\n // prettier-ignore\n return html\n `<a\n id=${id}\n class=${ifDefined(className)}\n href=${ifDefined(this.href)}\n download=${ifDefined(this.download)}\n target=${ifDefined(this.target)}\n aria-label=${ifDefined(this.label)}\n aria-labelledby=${ifDefined(labelledby)}\n aria-hidden=${ifDefined(ariaHidden ? 'true' : undefined)}\n tabindex=${ifDefined(tabindex)}\n rel=${ifDefined(this.rel)}\n >${anchorContent}</a>`;\n }\n }\n return LikeAnchorElement;\n}\n"],
5
- "mappings": ";;;;;;;;;;;AAWA;AAAA;AAAA;AAKA;AACA;AA0BO,2BACH,aACoC;AACpC,QAAM,0BAA0B,YAAY;AAAA,IAgBjC,aAAa;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEA,gBAAgB;AAAA,OACoB;AAEpC,aAAO;AAAA,yBAEM;AAAA,4BACG,UAAU,SAAS;AAAA,2BACpB,UAAU,KAAK,IAAI;AAAA,+BACf,UAAU,KAAK,QAAQ;AAAA,6BACzB,UAAU,KAAK,MAAM;AAAA,iCACjB,UAAU,KAAK,KAAK;AAAA,sCACf,UAAU,UAAU;AAAA,kCACxB,UAAU,aAAa,SAAS,MAAS;AAAA,+BAC5C,UAAU,QAAQ;AAAA,0BACvB,UAAU,KAAK,GAAG;AAAA,mBACzB;AAAA,IACX;AAAA,EACJ;AAtCW;AAAA,IADP,AAAC,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KACpB,AAFX,kBAEW;AAGA;AAAA,IADP,AAAC,SAAS;AAAA,KACH,AALX,kBAKW;AAGA;AAAA,IADP,AAAC,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KACpB,AARX,kBAQW;AAGA;AAAA,IADP,AAAC,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KACpB,AAXX,kBAWW;AAGA;AAAA,IADP,AAAC,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KACpB,AAdX,kBAcW;AA2BX,SAAO;AACX;",
5
+ "mappings": "wMAWA,qDAKA,2EACA,4EA0BO,2BACH,EACoC,CACpC,MAAM,SAA0B,EAAY,CAgBjC,aAAa,CAChB,KACA,YACA,aACA,aACA,WAEA,gBAAgB,kBACoB,CAEpC,MAAO;AAAA,yBAEM;AAAA,4BACG,EAAU,CAAS;AAAA,2BACpB,EAAU,KAAK,IAAI;AAAA,+BACf,EAAU,KAAK,QAAQ;AAAA,6BACzB,EAAU,KAAK,MAAM;AAAA,iCACjB,EAAU,KAAK,KAAK;AAAA,sCACf,EAAU,CAAU;AAAA,kCACxB,EAAU,EAAa,OAAS,MAAS;AAAA,+BAC5C,EAAU,CAAQ;AAAA,0BACvB,EAAU,KAAK,GAAG;AAAA,mBACzB,OACX,CACJ,CAtCW,UADP,AAAC,EAAS,CAAE,QAAS,EAAK,CAAC,GACpB,AAFX,EAEW,wBAGA,GADP,AAAC,EAAS,GACH,AALX,EAKW,qBAGA,GADP,AAAC,EAAS,CAAE,QAAS,EAAK,CAAC,GACpB,AARX,EAQW,oBAGA,GADP,AAAC,EAAS,CAAE,QAAS,EAAK,CAAC,GACpB,AAXX,EAWW,sBAGA,GADP,AAAC,EAAS,CAAE,QAAS,EAAK,CAAC,GACpB,AAdX,EAcW,mBA2BJ,CACX",
6
6
  "names": []
7
7
  }
@@ -1,52 +1,2 @@
1
- import { MutationController } from "@lit-labs/observers/mutation_controller.js";
2
- const slotContentIsPresent = Symbol("slotContentIsPresent");
3
- export function ObserveSlotPresence(constructor, lightDomSelector) {
4
- var _a;
5
- const lightDomSelectors = Array.isArray(lightDomSelector) ? lightDomSelector : [lightDomSelector];
6
- class SlotPresenceObservingElement extends constructor {
7
- constructor(...args) {
8
- super(args);
9
- this[_a] = /* @__PURE__ */ new Map();
10
- this.managePresenceObservedSlot = () => {
11
- let changes = false;
12
- lightDomSelectors.forEach((selector) => {
13
- const nextValue = !!this.querySelector(selector);
14
- const previousValue = this[slotContentIsPresent].get(selector) || false;
15
- changes = changes || previousValue !== nextValue;
16
- this[slotContentIsPresent].set(selector, !!this.querySelector(selector));
17
- });
18
- if (changes) {
19
- this.updateComplete.then(() => {
20
- this.requestUpdate();
21
- });
22
- }
23
- };
24
- new MutationController(this, {
25
- config: {
26
- childList: true,
27
- subtree: true
28
- },
29
- callback: () => {
30
- this.managePresenceObservedSlot();
31
- }
32
- });
33
- this.managePresenceObservedSlot();
34
- }
35
- get slotContentIsPresent() {
36
- if (lightDomSelectors.length === 1) {
37
- return this[slotContentIsPresent].get(lightDomSelectors[0]) || false;
38
- } else {
39
- throw new Error("Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.");
40
- }
41
- }
42
- getSlotContentPresence(selector) {
43
- if (this[slotContentIsPresent].has(selector)) {
44
- return this[slotContentIsPresent].get(selector) || false;
45
- }
46
- throw new Error(`The provided selector \`${selector}\` is not being observed.`);
47
- }
48
- }
49
- _a = slotContentIsPresent;
50
- return SlotPresenceObservingElement;
51
- }
1
+ import{MutationController as c}from"@lit-labs/observers/mutation_controller.js";const t=Symbol("slotContentIsPresent");export function ObserveSlotPresence(o,r){var g;const s=Array.isArray(r)?r:[r];class i extends o{constructor(...e){super(e);this[g]=new Map;this.managePresenceObservedSlot=()=>{let e=!1;s.forEach(n=>{const l=!!this.querySelector(n),a=this[t].get(n)||!1;e=e||a!==l,this[t].set(n,!!this.querySelector(n))}),e&&this.updateComplete.then(()=>{this.requestUpdate()})};new c(this,{config:{childList:!0,subtree:!0},callback:()=>{this.managePresenceObservedSlot()}}),this.managePresenceObservedSlot()}get slotContentIsPresent(){if(s.length===1)return this[t].get(s[0])||!1;throw new Error("Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.")}getSlotContentPresence(e){if(this[t].has(e))return this[t].get(e)||!1;throw new Error(`The provided selector \`${e}\` is not being observed.`)}}return g=t,i}
52
2
  //# sourceMappingURL=observe-slot-presence.js.map