@spectrum-web-components/shared 0.14.2 → 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 (56) hide show
  1. package/README.md +4 -0
  2. package/package.json +53 -6
  3. package/src/first-focusable-in.dev.js +6 -0
  4. package/src/first-focusable-in.dev.js.map +7 -0
  5. package/src/first-focusable-in.js +3 -14
  6. package/src/first-focusable-in.js.map +7 -1
  7. package/src/focus-visible.dev.js +68 -0
  8. package/src/focus-visible.dev.js.map +7 -0
  9. package/src/focus-visible.js +59 -105
  10. package/src/focus-visible.js.map +7 -1
  11. package/src/focusable.dev.js +190 -0
  12. package/src/focusable.dev.js.map +7 -0
  13. package/src/focusable.js +185 -244
  14. package/src/focusable.js.map +7 -1
  15. package/src/get-active-element.dev.js +4 -0
  16. package/src/get-active-element.dev.js.map +7 -0
  17. package/src/get-active-element.js +2 -14
  18. package/src/get-active-element.js.map +7 -1
  19. package/src/get-deep-element-from-point.d.ts +1 -0
  20. package/src/get-deep-element-from-point.dev.js +12 -0
  21. package/src/get-deep-element-from-point.dev.js.map +7 -0
  22. package/src/get-deep-element-from-point.js +12 -0
  23. package/src/get-deep-element-from-point.js.map +7 -0
  24. package/src/index.dev.js +10 -0
  25. package/src/index.dev.js.map +7 -0
  26. package/src/index.js +10 -21
  27. package/src/index.js.map +7 -1
  28. package/src/like-anchor.dev.js +58 -0
  29. package/src/like-anchor.dev.js.map +7 -0
  30. package/src/like-anchor.js +45 -40
  31. package/src/like-anchor.js.map +7 -1
  32. package/src/observe-slot-presence.dev.js +52 -0
  33. package/src/observe-slot-presence.dev.js.map +7 -0
  34. package/src/observe-slot-presence.js +47 -52
  35. package/src/observe-slot-presence.js.map +7 -1
  36. package/src/observe-slot-text.d.ts +1 -1
  37. package/src/observe-slot-text.dev.js +79 -0
  38. package/src/observe-slot-text.dev.js.map +7 -0
  39. package/src/observe-slot-text.js +74 -57
  40. package/src/observe-slot-text.js.map +7 -1
  41. package/src/platform.dev.js +31 -0
  42. package/src/platform.dev.js.map +7 -0
  43. package/src/platform.js +11 -32
  44. package/src/platform.js.map +7 -1
  45. package/src/reparent-children.dev.js +50 -0
  46. package/src/reparent-children.dev.js.map +7 -0
  47. package/src/reparent-children.js +44 -52
  48. package/src/reparent-children.js.map +7 -1
  49. package/test/focusable.test.js +19 -31
  50. package/test/focusable.test.js.map +7 -1
  51. package/test/observe-slot-presence.test.js +17 -27
  52. package/test/observe-slot-presence.test.js.map +7 -1
  53. package/test/observe-slot-text.test.js +17 -28
  54. package/test/observe-slot-text.test.js.map +7 -1
  55. package/test/reparent-children.test.js +151 -162
  56. package/test/reparent-children.test.js.map +7 -1
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["get-deep-element-from-point.ts"],
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;",
6
+ "names": []
7
+ }
@@ -0,0 +1,10 @@
1
+ export * from "./first-focusable-in.dev.js";
2
+ export * from "./focus-visible.dev.js";
3
+ export * from "./focusable.dev.js";
4
+ export * from "./get-active-element.dev.js";
5
+ export * from "./like-anchor.dev.js";
6
+ export * from "./observe-slot-presence.dev.js";
7
+ export * from "./observe-slot-text.dev.js";
8
+ export * from "./platform.dev.js";
9
+ export * from "./reparent-children.dev.js";
10
+ //# sourceMappingURL=index.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.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\nexport * from './first-focusable-in.dev.js'\nexport * from './focus-visible.dev.js'\nexport * from './focusable.dev.js'\nexport * from './get-active-element.dev.js'\nexport * from './like-anchor.dev.js'\nexport * from './observe-slot-presence.dev.js'\nexport * from './observe-slot-text.dev.js'\nexport * from './platform.dev.js'\nexport * from './reparent-children.dev.js'\n"],
5
+ "mappings": "AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;",
6
+ "names": []
7
+ }
package/src/index.js CHANGED
@@ -1,21 +1,10 @@
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
- export * from './first-focusable-in.js';
13
- export * from './focus-visible.js';
14
- export * from './focusable.js';
15
- export * from './get-active-element.js';
16
- export * from './like-anchor.js';
17
- export * from './observe-slot-presence.js';
18
- export * from './observe-slot-text.js';
19
- export * from './platform.js';
20
- export * from './reparent-children.js';
21
- //# sourceMappingURL=index.js.map
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";
10
+ //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1,7 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,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\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"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.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\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;",
6
+ "names": []
7
+ }
@@ -0,0 +1,58 @@
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
+ }
58
+ //# sourceMappingURL=like-anchor.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["like-anchor.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*/\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;",
6
+ "names": []
7
+ }
@@ -1,25 +1,30 @@
1
- import { __decorate } from "tslib";
2
- /*
3
- Copyright 2020 Adobe. All rights reserved.
4
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License. You may obtain a copy
6
- of the License at http://www.apache.org/licenses/LICENSE-2.0
7
-
8
- Unless required by applicable law or agreed to in writing, software distributed under
9
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
10
- OF ANY KIND, either express or implied. See the License for the specific language
11
- governing permissions and limitations under the License.
12
- */
13
- import { html, } from '@spectrum-web-components/base';
14
- import { property } from '@spectrum-web-components/base/src/decorators.js';
15
- import { ifDefined } from '@spectrum-web-components/base/src/directives.js';
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";
16
17
  export function LikeAnchor(constructor) {
17
- class LikeAnchorElement extends constructor {
18
- renderAnchor({ id, className, ariaHidden, labelledby, tabindex,
19
- // prettier-ignore
20
- anchorContent = html `<slot></slot>`, }) {
21
- // prettier-ignore
22
- return html `<a
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
23
28
  id=${id}
24
29
  class=${ifDefined(className)}
25
30
  href=${ifDefined(this.href)}
@@ -27,27 +32,27 @@ export function LikeAnchor(constructor) {
27
32
  target=${ifDefined(this.target)}
28
33
  aria-label=${ifDefined(this.label)}
29
34
  aria-labelledby=${ifDefined(labelledby)}
30
- aria-hidden=${ifDefined(ariaHidden ? 'true' : undefined)}
35
+ aria-hidden=${ifDefined(ariaHidden ? "true" : void 0)}
31
36
  tabindex=${ifDefined(tabindex)}
32
37
  rel=${ifDefined(this.rel)}
33
38
  >${anchorContent}</a>`;
34
- }
35
39
  }
36
- __decorate([
37
- property({ reflect: true })
38
- ], LikeAnchorElement.prototype, "download", void 0);
39
- __decorate([
40
- property()
41
- ], LikeAnchorElement.prototype, "label", void 0);
42
- __decorate([
43
- property({ reflect: true })
44
- ], LikeAnchorElement.prototype, "href", void 0);
45
- __decorate([
46
- property({ reflect: true })
47
- ], LikeAnchorElement.prototype, "target", void 0);
48
- __decorate([
49
- property({ reflect: true })
50
- ], LikeAnchorElement.prototype, "rel", void 0);
51
- return LikeAnchorElement;
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;
52
57
  }
53
- //# sourceMappingURL=like-anchor.js.map
58
+ //# sourceMappingURL=like-anchor.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"like-anchor.js","sourceRoot":"","sources":["like-anchor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;AACF,OAAO,EACH,IAAI,GAGP,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,iDAAiD,CAAC;AA0B5E,MAAM,UAAU,UAAU,CACtB,WAAc;IAEd,MAAM,iBAAkB,SAAQ,WAAW;QAgBhC,YAAY,CAAC,EAChB,EAAE,EACF,SAAS,EACT,UAAU,EACV,UAAU,EACV,QAAQ;QACR,kBAAkB;QAClB,aAAa,GAAG,IAAI,CAAA,eAAe,GACjB;YAClB,kBAAkB;YAClB,OAAO,IAAI,CACP;yBACS,EAAE;4BACC,SAAS,CAAC,SAAS,CAAC;2BACrB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;+BAChB,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC;6BAC1B,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;iCAClB,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;sCAChB,SAAS,CAAC,UAAU,CAAC;kCACzB,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;+BAC7C,SAAS,CAAC,QAAQ,CAAC;0BACxB,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;mBAC1B,aAAa,MAAM,CAAC;QAC/B,CAAC;KACJ;IAtCG;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;uDACH;IAGzB;QADC,QAAQ,EAAE;oDACW;IAGtB;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;mDACP;IAGrB;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;qDAC4B;IAGxD;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;kDACR;IA2BxB,OAAO,iBAAiB,CAAC;AAC7B,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*/\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"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["like-anchor.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*/\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;",
6
+ "names": []
7
+ }
@@ -0,0 +1,52 @@
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
+ }
52
+ //# sourceMappingURL=observe-slot-presence.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["observe-slot-presence.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\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 { ReactiveElement } from '@spectrum-web-components/base';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\n\nconst slotContentIsPresent = Symbol('slotContentIsPresent');\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\nexport interface SlotPresenceObservingInterface {\n slotContentIsPresent: boolean;\n getSlotContentPresence(selector: string): boolean;\n managePresenceObservedSlot(): void;\n}\n\nexport function ObserveSlotPresence<T extends Constructor<ReactiveElement>>(\n constructor: T,\n lightDomSelector: string | string[]\n): T & Constructor<SlotPresenceObservingInterface> {\n const lightDomSelectors = Array.isArray(lightDomSelector)\n ? lightDomSelector\n : [lightDomSelector];\n class SlotPresenceObservingElement\n extends constructor\n implements SlotPresenceObservingInterface\n {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(args);\n\n new MutationController(this, {\n config: {\n childList: true,\n subtree: true,\n },\n callback: () => {\n this.managePresenceObservedSlot();\n },\n });\n\n this.managePresenceObservedSlot();\n }\n\n /**\n * @private\n */\n public get slotContentIsPresent(): boolean {\n if (lightDomSelectors.length === 1) {\n return (\n this[slotContentIsPresent].get(lightDomSelectors[0]) ||\n false\n );\n } else {\n throw new Error(\n 'Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.'\n );\n }\n }\n private [slotContentIsPresent]: Map<string, boolean> = new Map();\n\n public getSlotContentPresence(selector: string): boolean {\n if (this[slotContentIsPresent].has(selector)) {\n return this[slotContentIsPresent].get(selector) || false;\n }\n throw new Error(\n `The provided selector \\`${selector}\\` is not being observed.`\n );\n }\n\n public managePresenceObservedSlot = (): void => {\n let changes = false;\n lightDomSelectors.forEach((selector) => {\n const nextValue = !!this.querySelector(selector);\n const previousValue =\n this[slotContentIsPresent].get(selector) || false;\n changes = changes || previousValue !== nextValue;\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(selector)\n );\n });\n if (changes) {\n this.updateComplete.then(() => {\n this.requestUpdate();\n });\n }\n };\n }\n return SlotPresenceObservingElement;\n}\n"],
5
+ "mappings": "AAWA;AAEA,MAAM,uBAAuB,OAAO,sBAAsB;AAcnD,oCACH,aACA,kBAC+C;AA9BnD;AA+BI,QAAM,oBAAoB,MAAM,QAAQ,gBAAgB,IAClD,mBACA,CAAC,gBAAgB;AACvB,QAAM,qCACM,YAEZ;AAAA,IAEI,eAAe,MAAa;AACxB,YAAM,IAAI;AA8BL,iBAA8C,oBAAI,IAAI;AAWxD,wCAA6B,MAAY;AAC5C,YAAI,UAAU;AACd,0BAAkB,QAAQ,CAAC,aAAa;AACpC,gBAAM,YAAY,CAAC,CAAC,KAAK,cAAc,QAAQ;AAC/C,gBAAM,gBACF,KAAK,sBAAsB,IAAI,QAAQ,KAAK;AAChD,oBAAU,WAAW,kBAAkB;AACvC,eAAK,sBAAsB,IACvB,UACA,CAAC,CAAC,KAAK,cAAc,QAAQ,CACjC;AAAA,QACJ,CAAC;AACD,YAAI,SAAS;AACT,eAAK,eAAe,KAAK,MAAM;AAC3B,iBAAK,cAAc;AAAA,UACvB,CAAC;AAAA,QACL;AAAA,MACJ;AAxDI,UAAI,mBAAmB,MAAM;AAAA,QACzB,QAAQ;AAAA,UACJ,WAAW;AAAA,UACX,SAAS;AAAA,QACb;AAAA,QACA,UAAU,MAAM;AACZ,eAAK,2BAA2B;AAAA,QACpC;AAAA,MACJ,CAAC;AAED,WAAK,2BAA2B;AAAA,IACpC;AAAA,QAKW,uBAAgC;AACvC,UAAI,kBAAkB,WAAW,GAAG;AAChC,eACI,KAAK,sBAAsB,IAAI,kBAAkB,EAAE,KACnD;AAAA,MAER,OAAO;AACH,cAAM,IAAI,MACN,8GACJ;AAAA,MACJ;AAAA,IACJ;AAAA,IAGO,uBAAuB,UAA2B;AACrD,UAAI,KAAK,sBAAsB,IAAI,QAAQ,GAAG;AAC1C,eAAO,KAAK,sBAAsB,IAAI,QAAQ,KAAK;AAAA,MACvD;AACA,YAAM,IAAI,MACN,2BAA2B,mCAC/B;AAAA,IACJ;AAAA,EAoBJ;AAnGJ,EAsEiB;AA8Bb,SAAO;AACX;",
6
+ "names": []
7
+ }
@@ -1,57 +1,52 @@
1
- const slotElementObserver = Symbol('slotElementObserver');
2
- const startObserving = Symbol('startObserving');
3
- const slotContentIsPresent = Symbol('slotContentIsPresent');
1
+ import { MutationController } from "@lit-labs/observers/mutation_controller.js";
2
+ const slotContentIsPresent = Symbol("slotContentIsPresent");
4
3
  export function ObserveSlotPresence(constructor, lightDomSelector) {
5
- var _a;
6
- const lightDomSelectors = Array.isArray(lightDomSelector)
7
- ? lightDomSelector
8
- : [lightDomSelector];
9
- class SlotPresenceObservingElement extends constructor {
10
- constructor() {
11
- super(...arguments);
12
- this[_a] = new Map();
13
- this.managePresenceObservedSlot = () => {
14
- lightDomSelectors.forEach((selector) => {
15
- this[slotContentIsPresent].set(selector, !!this.querySelector(selector));
16
- });
17
- this.requestUpdate();
18
- };
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
+ });
19
22
  }
20
- /**
21
- * @private
22
- */
23
- get slotContentIsPresent() {
24
- if (lightDomSelectors.length === 1) {
25
- return (this[slotContentIsPresent].get(lightDomSelectors[0]) ||
26
- false);
27
- }
28
- else {
29
- throw new Error('Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.');
30
- }
31
- }
32
- getSlotContentPresence(selector) {
33
- if (this[slotContentIsPresent].has(selector)) {
34
- return this[slotContentIsPresent].get(selector) || false;
35
- }
36
- throw new Error(`The provided selector \`\` is not being observed.`);
37
- }
38
- [(_a = slotContentIsPresent, startObserving)]() {
39
- const config = { childList: true, subtree: true };
40
- if (!this[slotElementObserver]) {
41
- this[slotElementObserver] = new MutationObserver(this.managePresenceObservedSlot);
42
- }
43
- this[slotElementObserver].observe(this, config);
44
- this.managePresenceObservedSlot();
45
- }
46
- connectedCallback() {
47
- super.connectedCallback();
48
- this[startObserving]();
49
- }
50
- disconnectedCallback() {
51
- this[slotElementObserver].disconnect();
52
- super.disconnectedCallback();
23
+ };
24
+ new MutationController(this, {
25
+ config: {
26
+ childList: true,
27
+ subtree: true
28
+ },
29
+ callback: () => {
30
+ this.managePresenceObservedSlot();
53
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.`);
54
47
  }
55
- return SlotPresenceObservingElement;
48
+ }
49
+ _a = slotContentIsPresent;
50
+ return SlotPresenceObservingElement;
56
51
  }
57
- //# sourceMappingURL=observe-slot-presence.js.map
52
+ //# sourceMappingURL=observe-slot-presence.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"observe-slot-presence.js","sourceRoot":"","sources":["observe-slot-presence.ts"],"names":[],"mappings":"AAYA,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAC1D,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAChD,MAAM,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAc5D,MAAM,UAAU,mBAAmB,CAC/B,WAAc,EACd,gBAAmC;;IAEnC,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC;QACrD,CAAC,CAAC,gBAAgB;QAClB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC;IACzB,MAAM,4BACF,SAAQ,WAAW;QADvB;;YAqBY,QAAsB,GAAyB,IAAI,GAAG,E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CAAC,0BAA0B,EAAE,CAAC;QACtC,CAAC;QAEe,iBAAiB;YAC7B,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC1B,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;QAC3B,CAAC;QAEe,oBAAoB;YAChC,IAAI,CAAC,mBAAmB,CAAC,CAAC,UAAU,EAAE,CAAC;YACvC,KAAK,CAAC,oBAAoB,EAAE,CAAC;QACjC,CAAC;KACJ;IACD,OAAO,4BAA4B,CAAC;AACxC,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\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 { ReactiveElement } from '@spectrum-web-components/base';\n\nconst slotElementObserver = Symbol('slotElementObserver');\nconst startObserving = Symbol('startObserving');\nconst slotContentIsPresent = Symbol('slotContentIsPresent');\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\nexport interface SlotPresenceObservingInterface {\n slotContentIsPresent: boolean;\n getSlotContentPresence(selector: string): boolean;\n managePresenceObservedSlot(): void;\n}\n\nexport function ObserveSlotPresence<T extends Constructor<ReactiveElement>>(\n constructor: T,\n lightDomSelector: string | string[]\n): T & Constructor<SlotPresenceObservingInterface> {\n const lightDomSelectors = Array.isArray(lightDomSelector)\n ? lightDomSelector\n : [lightDomSelector];\n class SlotPresenceObservingElement\n extends constructor\n implements SlotPresenceObservingInterface\n {\n private [slotElementObserver]!: MutationObserver;\n\n /**\n * @private\n */\n public get slotContentIsPresent(): boolean {\n if (lightDomSelectors.length === 1) {\n return (\n this[slotContentIsPresent].get(lightDomSelectors[0]) ||\n false\n );\n } else {\n throw new Error(\n 'Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.'\n );\n }\n }\n private [slotContentIsPresent]: Map<string, boolean> = new Map();\n\n public getSlotContentPresence(selector: string): boolean {\n if (this[slotContentIsPresent].has(selector)) {\n return this[slotContentIsPresent].get(selector) || false;\n }\n throw new Error(\n `The provided selector \\`\\` is not being observed.`\n );\n }\n\n public managePresenceObservedSlot = (): void => {\n lightDomSelectors.forEach((selector) => {\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(selector)\n );\n });\n this.requestUpdate();\n };\n\n private [startObserving](): void {\n const config = { childList: true, subtree: true };\n if (!this[slotElementObserver]) {\n this[slotElementObserver] = new MutationObserver(\n this.managePresenceObservedSlot\n );\n }\n this[slotElementObserver].observe(this, config);\n this.managePresenceObservedSlot();\n }\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this[startObserving]();\n }\n\n public override disconnectedCallback(): void {\n this[slotElementObserver].disconnect();\n super.disconnectedCallback();\n }\n }\n return SlotPresenceObservingElement;\n}\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["observe-slot-presence.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\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 { ReactiveElement } from '@spectrum-web-components/base';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\n\nconst slotContentIsPresent = Symbol('slotContentIsPresent');\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\nexport interface SlotPresenceObservingInterface {\n slotContentIsPresent: boolean;\n getSlotContentPresence(selector: string): boolean;\n managePresenceObservedSlot(): void;\n}\n\nexport function ObserveSlotPresence<T extends Constructor<ReactiveElement>>(\n constructor: T,\n lightDomSelector: string | string[]\n): T & Constructor<SlotPresenceObservingInterface> {\n const lightDomSelectors = Array.isArray(lightDomSelector)\n ? lightDomSelector\n : [lightDomSelector];\n class SlotPresenceObservingElement\n extends constructor\n implements SlotPresenceObservingInterface\n {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(args);\n\n new MutationController(this, {\n config: {\n childList: true,\n subtree: true,\n },\n callback: () => {\n this.managePresenceObservedSlot();\n },\n });\n\n this.managePresenceObservedSlot();\n }\n\n /**\n * @private\n */\n public get slotContentIsPresent(): boolean {\n if (lightDomSelectors.length === 1) {\n return (\n this[slotContentIsPresent].get(lightDomSelectors[0]) ||\n false\n );\n } else {\n throw new Error(\n 'Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.'\n );\n }\n }\n private [slotContentIsPresent]: Map<string, boolean> = new Map();\n\n public getSlotContentPresence(selector: string): boolean {\n if (this[slotContentIsPresent].has(selector)) {\n return this[slotContentIsPresent].get(selector) || false;\n }\n throw new Error(\n `The provided selector \\`${selector}\\` is not being observed.`\n );\n }\n\n public managePresenceObservedSlot = (): void => {\n let changes = false;\n lightDomSelectors.forEach((selector) => {\n const nextValue = !!this.querySelector(selector);\n const previousValue =\n this[slotContentIsPresent].get(selector) || false;\n changes = changes || previousValue !== nextValue;\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(selector)\n );\n });\n if (changes) {\n this.updateComplete.then(() => {\n this.requestUpdate();\n });\n }\n };\n }\n return SlotPresenceObservingElement;\n}\n"],
5
+ "mappings": "AAWA;AAEA,MAAM,uBAAuB,OAAO,sBAAsB;AAcnD,oCACH,aACA,kBAC+C;AA9BnD;AA+BI,QAAM,oBAAoB,MAAM,QA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servedSlot(): void;
9
9
  }
10
- export declare function ObserveSlotText<T extends Constructor<ReactiveElement>>(constructor: T, slotSelector?: string): T & Constructor<SlotTextObservingInterface>;
10
+ export declare function ObserveSlotText<T extends Constructor<ReactiveElement>>(constructor: T, slotName?: string): T & Constructor<SlotTextObservingInterface>;
11
11
  export {};
@@ -0,0 +1,79 @@
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
+ property,
14
+ queryAssignedNodes
15
+ } from "@spectrum-web-components/base/src/decorators.js";
16
+ import { MutationController } from "@lit-labs/observers/mutation_controller.js";
17
+ const assignedNodesList = Symbol("assignedNodes");
18
+ export function ObserveSlotText(constructor, slotName) {
19
+ var _a;
20
+ class SlotTextObservingElement extends constructor {
21
+ constructor(...args) {
22
+ super(args);
23
+ this.slotHasContent = false;
24
+ new MutationController(this, {
25
+ config: {
26
+ characterData: true,
27
+ subtree: true
28
+ },
29
+ callback: (mutationsList) => {
30
+ for (const mutation of mutationsList) {
31
+ if (mutation.type === "characterData") {
32
+ this.manageTextObservedSlot();
33
+ return;
34
+ }
35
+ }
36
+ }
37
+ });
38
+ }
39
+ manageTextObservedSlot() {
40
+ if (!this[assignedNodesList])
41
+ return;
42
+ const assignedNodes = [...this[assignedNodesList]].filter((node) => {
43
+ if (node.tagName) {
44
+ return true;
45
+ }
46
+ return node.textContent ? node.textContent.trim() : false;
47
+ });
48
+ this.slotHasContent = assignedNodes.length > 0;
49
+ }
50
+ update(changedProperties) {
51
+ if (!this.hasUpdated) {
52
+ const { childNodes } = this;
53
+ const textNodes = [...childNodes].filter((node) => {
54
+ if (node.tagName) {
55
+ return slotName ? node.getAttribute("slot") === slotName : !node.hasAttribute("slot");
56
+ }
57
+ return node.textContent ? node.textContent.trim() : false;
58
+ });
59
+ this.slotHasContent = textNodes.length > 0;
60
+ }
61
+ super.update(changedProperties);
62
+ }
63
+ firstUpdated(changedProperties) {
64
+ super.firstUpdated(changedProperties);
65
+ this.updateComplete.then(() => {
66
+ this.manageTextObservedSlot();
67
+ });
68
+ }
69
+ }
70
+ _a = assignedNodesList;
71
+ __decorateClass([
72
+ property({ type: Boolean, attribute: false })
73
+ ], SlotTextObservingElement.prototype, "slotHasContent", 2);
74
+ __decorateClass([
75
+ queryAssignedNodes(slotName, true)
76
+ ], SlotTextObservingElement.prototype, _a, 2);
77
+ return SlotTextObservingElement;
78
+ }
79
+ //# sourceMappingURL=observe-slot-text.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["observe-slot-text.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*/\nimport { PropertyValues, ReactiveElement } from '@spectrum-web-components/base';\nimport {\n property,\n queryAssignedNodes,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\n\nconst assignedNodesList = Symbol('assignedNodes');\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\nexport interface SlotTextObservingInterface {\n slotHasContent: boolean;\n manageTextObservedSlot(): void;\n}\n\nexport function ObserveSlotText<T extends Constructor<ReactiveElement>>(\n constructor: T,\n slotName?: string\n): T & Constructor<SlotTextObservingInterface> {\n class SlotTextObservingElement\n extends constructor\n implements SlotTextObservingInterface\n {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(args);\n\n new MutationController(this, {\n config: {\n characterData: true,\n subtree: true,\n },\n callback: (mutationsList: Array<MutationRecord>) => {\n for (const mutation of mutationsList) {\n if (mutation.type === 'characterData') {\n this.manageTextObservedSlot();\n return;\n }\n }\n },\n });\n }\n\n @property({ type: Boolean, attribute: false })\n public slotHasContent = false;\n\n @queryAssignedNodes(slotName, true)\n private [assignedNodesList]!: NodeListOf<HTMLElement>;\n\n public manageTextObservedSlot(): void {\n if (!this[assignedNodesList]) return;\n const assignedNodes = [...this[assignedNodesList]].filter(\n (node) => {\n if ((node as HTMLElement).tagName) {\n return true;\n }\n return node.textContent ? node.textContent.trim() : false;\n }\n );\n this.slotHasContent = assignedNodes.length > 0;\n }\n\n protected override update(changedProperties: PropertyValues): void {\n if (!this.hasUpdated) {\n const { childNodes } = this;\n const textNodes = [...childNodes].filter((node) => {\n if ((node as HTMLElement).tagName) {\n return slotName\n ? (node as HTMLElement).getAttribute('slot') ===\n slotName\n : !(node as HTMLElement).hasAttribute('slot');\n }\n return node.textContent ? node.textContent.trim() : false;\n });\n this.slotHasContent = textNodes.length > 0;\n }\n super.update(changedProperties);\n }\n\n protected override firstUpdated(\n changedProperties: PropertyValues\n ): void {\n super.firstUpdated(changedProperties);\n this.updateComplete.then(() => {\n this.manageTextObservedSlot();\n });\n }\n }\n return SlotTextObservingElement;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;AAYA;AAAA;AAAA;AAAA;AAIA;AAEA,MAAM,oBAAoB,OAAO,eAAe;AAazC,gCACH,aACA,UAC2C;AAlC/C;AAmCI,QAAM,iCACM,YAEZ;AAAA,IAEI,eAAe,MAAa;AACxB,YAAM,IAAI;AAmBP,4BAAiB;AAjBpB,UAAI,m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