@spectrum-web-components/shared 1.1.0 → 1.1.1

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 (81) hide show
  1. package/package.json +3 -3
  2. package/src/first-focusable-in.d.ts +3 -0
  3. package/src/first-focusable-in.dev.js +15 -0
  4. package/src/first-focusable-in.dev.js.map +7 -0
  5. package/src/first-focusable-in.js +2 -0
  6. package/src/first-focusable-in.js.map +7 -0
  7. package/src/focus-visible.d.ts +29 -0
  8. package/src/focus-visible.dev.js +77 -0
  9. package/src/focus-visible.dev.js.map +7 -0
  10. package/src/focus-visible.js +2 -0
  11. package/src/focus-visible.js.map +7 -0
  12. package/src/focusable-selectors.d.ts +2 -0
  13. package/src/focusable-selectors.dev.js +15 -0
  14. package/src/focusable-selectors.dev.js.map +7 -0
  15. package/src/focusable-selectors.js +2 -0
  16. package/src/focusable-selectors.js.map +7 -0
  17. package/src/focusable.d.ts +56 -0
  18. package/src/focusable.dev.js +245 -0
  19. package/src/focusable.dev.js.map +7 -0
  20. package/src/focusable.js +2 -0
  21. package/src/focusable.js.map +7 -0
  22. package/src/get-active-element.d.ts +1 -0
  23. package/src/get-active-element.dev.js +5 -0
  24. package/src/get-active-element.dev.js.map +7 -0
  25. package/src/get-active-element.js +2 -0
  26. package/src/get-active-element.js.map +7 -0
  27. package/src/get-deep-element-from-point.d.ts +1 -0
  28. package/src/get-deep-element-from-point.dev.js +13 -0
  29. package/src/get-deep-element-from-point.dev.js.map +7 -0
  30. package/src/get-deep-element-from-point.js +2 -0
  31. package/src/get-deep-element-from-point.js.map +7 -0
  32. package/src/get-label-from-slot.d.ts +1 -0
  33. package/src/get-label-from-slot.dev.js +17 -0
  34. package/src/get-label-from-slot.dev.js.map +7 -0
  35. package/src/get-label-from-slot.js +2 -0
  36. package/src/get-label-from-slot.js.map +7 -0
  37. package/src/index.d.ts +12 -0
  38. package/src/index.dev.js +14 -0
  39. package/src/index.dev.js.map +7 -0
  40. package/src/index.js +2 -0
  41. package/src/index.js.map +7 -0
  42. package/src/like-anchor.d.ts +23 -0
  43. package/src/like-anchor.dev.js +63 -0
  44. package/src/like-anchor.dev.js.map +7 -0
  45. package/src/like-anchor.js +14 -0
  46. package/src/like-anchor.js.map +7 -0
  47. package/src/observe-slot-presence.d.ts +12 -0
  48. package/src/observe-slot-presence.dev.js +63 -0
  49. package/src/observe-slot-presence.dev.js.map +7 -0
  50. package/src/observe-slot-presence.js +2 -0
  51. package/src/observe-slot-presence.js.map +7 -0
  52. package/src/observe-slot-text.d.ts +11 -0
  53. package/src/observe-slot-text.dev.js +95 -0
  54. package/src/observe-slot-text.dev.js.map +7 -0
  55. package/src/observe-slot-text.js +2 -0
  56. package/src/observe-slot-text.js.map +7 -0
  57. package/src/platform.d.ts +10 -0
  58. package/src/platform.dev.js +39 -0
  59. package/src/platform.dev.js.map +7 -0
  60. package/src/platform.js +2 -0
  61. package/src/platform.js.map +7 -0
  62. package/src/random-id.d.ts +1 -0
  63. package/src/random-id.dev.js +8 -0
  64. package/src/random-id.dev.js.map +7 -0
  65. package/src/random-id.js +2 -0
  66. package/src/random-id.js.map +7 -0
  67. package/src/reparent-children.d.ts +4 -0
  68. package/src/reparent-children.dev.js +57 -0
  69. package/src/reparent-children.dev.js.map +7 -0
  70. package/src/reparent-children.js +2 -0
  71. package/src/reparent-children.js.map +7 -0
  72. package/test/focusable.test.js +25 -0
  73. package/test/focusable.test.js.map +7 -0
  74. package/test/observe-slot-presence.test.js +30 -0
  75. package/test/observe-slot-presence.test.js.map +7 -0
  76. package/test/observe-slot-text.test.js +27 -0
  77. package/test/observe-slot-text.test.js.map +7 -0
  78. package/test/random-id.test.js +25 -0
  79. package/test/random-id.test.js.map +7 -0
  80. package/test/reparent-children.test.js +254 -0
  81. package/test/reparent-children.test.js.map +7 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["focusable.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, 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\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\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 return this._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\n if (this.focusElement === this) {\n if (this.disabled) {\n this._tabIndex = tabIndex;\n } else if (tabIndex !== this._tabIndex) {\n this._tabIndex = tabIndex;\n const tabindex = '' + tabIndex;\n this.manipulatingTabindex = true;\n this.setAttribute('tabindex', tabindex);\n }\n return;\n }\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\n if (tabIndex === -1 || this.disabled) {\n this.manipulatingTabindex = true;\n this.setAttribute('tabindex', '-1');\n this.removeAttribute('focusable');\n\n if (this.selfManageFocusElement) {\n return;\n }\n\n if (tabIndex !== -1) {\n this._tabIndex = tabIndex;\n this.manageFocusElementTabindex(tabIndex);\n } else {\n this.focusElement?.removeAttribute('tabindex');\n }\n return;\n }\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\n this._tabIndex = tabIndex;\n this.manageFocusElementTabindex(tabIndex);\n }\n private _tabIndex = 0;\n\n private onPointerdownManagementOfTabIndex(): void {\n if (this.tabIndex === -1) {\n setTimeout(() => {\n // Ensure this happens _after_ WebKit attempts to focus the :host.\n this.tabIndex = 0;\n this.focus({ preventScroll: true });\n this.tabIndex = -1;\n });\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 if (this.focusElement !== this) {\n this.focusElement.tabIndex = tabIndex;\n }\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 /**\n * @public\n * @returns {boolean} whether the component should manage its focusElement tab-index or not\n * Needed for action-menu to be supported in action-group in an accessible way\n */\n public get selfManageFocusElement(): boolean {\n return false;\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 protected override async getUpdateComplete(): Promise<boolean> {\n const complete = (await super.getUpdateComplete()) as boolean;\n await this.autofocusReady;\n return complete;\n }\n\n private autofocusReady = Promise.resolve();\n\n public override connectedCallback(): void {\n super.connectedCallback();\n if (this.autofocus) {\n this.autofocusReady = new Promise(async (res) => {\n // If at connect time the [autofocus] content is placed within\n // content that needs to be \"hidden\" by default, it would need to wait\n // two rAFs for animations to be triggered on that content in\n // order for the [autofocus] to become \"visisble\" and have its\n // focus() capabilities enabled.\n //\n // Await this with `getUpdateComplete` so that the element cannot\n // become \"ready\" until `manageFocus` has occured.\n await nextFrame();\n await nextFrame();\n res();\n });\n this.updateComplete.then(() => {\n this.manageAutoFocus();\n });\n }\n }\n}\n"],
5
+ "mappings": "qNAWA,OAAyB,mBAAAA,MAAuB,gCAChD,OAAS,YAAAC,MAAgB,kDAEzB,OAAS,6BAAAC,MAAiC,qBAI1C,SAASC,GAA2B,CAChC,OAAO,IAAI,QAASC,GAAQ,sBAAsB,IAAMA,EAAI,CAAC,CAAC,CAClE,CAQO,aAAM,kBAAkBF,EAA0BF,CAAe,CAAE,CAAnE,kCAKH,KAAO,SAAW,GAOlB,KAAgB,UAAY,GAoG5B,KAAQ,UAAY,EA2BpB,KAAQ,qBAAuB,GAuI/B,KAAQ,eAAiB,QAAQ,QAAQ,EA7PzC,IAA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AE3BA,EAAkB,IAAI,UAAU,GAAK,KAAK,UAC1C,KAAK,KAAK,CAElB,CAEA,MAAc,sBACVC,EACAC,EACa,CACb,MAAMC,EAAiB,IACnB,KAAK,eAAiB,MACtB,OAAO,KAAK,aAAa,UAAa,YACtCF,GACA,KAAK,qBAAuB,GAC5B,KAAK,aAAa,WAAY,IAAI,EAClC,MAAM,KAAK,eACPE,EAAe,EACf,KAAK,aAAa,SAAW,GAE7B,KAAK,aAAa,gBAAiB,MAAM,GAEtCD,IACP,KAAK,qBAAuB,GACxB,KAAK,eAAiB,KACtB,KAAK,aAAa,WAAY,GAAK,KAAK,SAAS,EAEjD,KAAK,gBAAgB,UAAU,EAEnC,MAAM,KAAK,eACPC,EAAe,EACf,KAAK,aAAa,SAAW,GAE7B,KAAK,gBAAgB,eAAe,EAGhD,CAEA,MAAyB,mBAAsC,CAC3D,MAAMC,EAAY,MAAM,MAAM,kBAAkB,EAChD,aAAM,KAAK,eACJA,CACX,CAIgB,mBAA0B,CACtC,MAAM,kBAAkB,EACpB,KAAK,YACL,KAAK,eAAiB,IAAI,QAAQ,MAAOZ,GAAQ,CAS7C,MAAMD,EAAU,EAChB,MAAMA,EAAU,EAChBC,EAAI,CACR,CAAC,EACD,KAAK,eAAe,KAAK,IAAM,CAC3B,KAAK,gBAAgB,CACzB,CAAC,EAET,CACJ,CApSWa,EAAA,CADNhB,EAAS,CAAE,KAAM,QAAS,QAAS,EAAK,CAAC,GAJjC,UAKF,wBAOSgB,EAAA,CADfhB,EAAS,CAAE,KAAM,OAAQ,CAAC,GAXlB,UAYO,yBASIgB,EAAA,CADnBhB,EAAS,CAAE,KAAM,MAAO,CAAC,GApBjB,UAqBW",
6
+ "names": ["SpectrumElement", "property", "FocusVisiblePolyfillMixin", "nextFrame", "res", "tabindex", "tabIndexAttribute", "tabIndex", "_a", "options", "focusElement", "changes", "changedProperties", "disabled", "oldDisabled", "canSetDisabled", "complete", "__decorateClass"]
7
+ }
@@ -0,0 +1 @@
1
+ export declare const getActiveElement: (el: Node) => Element | null;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ export const getActiveElement = (el) => {
3
+ return el.getRootNode().activeElement;
4
+ };
5
+ //# sourceMappingURL=get-active-element.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["get-active-element.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\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;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";export const getActiveElement=e=>e.getRootNode().activeElement;
2
+ //# sourceMappingURL=get-active-element.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["get-active-element.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\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,iBAAoBA,GACrBA,EAAG,YAAY,EAAe",
6
+ "names": ["el"]
7
+ }
@@ -0,0 +1 @@
1
+ export declare const getDeepElementFromPoint: (x: number, y: number) => Element | null;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ export const getDeepElementFromPoint = (x, y) => {
3
+ let target = document.elementFromPoint(x, y);
4
+ while (target == null ? void 0 : target.shadowRoot) {
5
+ const innerTarget = target.shadowRoot.elementFromPoint(x, y);
6
+ if (!innerTarget || innerTarget === target) {
7
+ break;
8
+ }
9
+ target = innerTarget;
10
+ }
11
+ return target;
12
+ };
13
+ //# sourceMappingURL=get-deep-element-from-point.dev.js.map
@@ -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,2 @@
1
+ "use strict";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};
2
+ //# sourceMappingURL=get-deep-element-from-point.js.map
@@ -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,wBAA0B,CACnCA,EACAC,IACiB,CACjB,IAAIC,EAAS,SAAS,iBAAiBF,EAAGC,CAAC,EAC3C,KAAOC,GAAA,MAAAA,EAAQ,YAAY,CACvB,MAAMC,EACFD,EAAO,WAGT,iBAAiBF,EAAGC,CAAC,EACvB,GAAI,CAACE,GAAeA,IAAgBD,EAChC,MAEJA,EAASC,CACb,CACA,OAAOD,CACX",
6
+ "names": ["x", "y", "target", "innerTarget"]
7
+ }
@@ -0,0 +1 @@
1
+ export declare const getLabelFromSlot: (label: string, slotEl: HTMLSlotElement) => string | null;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ export const getLabelFromSlot = (label, slotEl) => {
3
+ if (label) return null;
4
+ const textContent = slotEl.assignedNodes().reduce((accumulator, node) => {
5
+ if (node.textContent) {
6
+ return accumulator + node.textContent;
7
+ } else {
8
+ return accumulator;
9
+ }
10
+ }, "");
11
+ if (textContent) {
12
+ return textContent.trim();
13
+ } else {
14
+ return null;
15
+ }
16
+ };
17
+ //# sourceMappingURL=get-label-from-slot.dev.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["get-label-from-slot.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 getLabelFromSlot = (\n label: string,\n slotEl: HTMLSlotElement\n): string | null => {\n if (label) return null;\n const textContent = slotEl\n .assignedNodes()\n .reduce((accumulator: string, node: Node) => {\n if (node.textContent) {\n return accumulator + node.textContent;\n } else {\n return accumulator;\n }\n }, '');\n if (textContent) {\n return textContent.trim();\n } else {\n return null;\n }\n};\n"],
5
+ "mappings": ";AAYO,aAAM,mBAAmB,CAC5B,OACA,WACgB;AAChB,MAAI,MAAO,QAAO;AAClB,QAAM,cAAc,OACf,cAAc,EACd,OAAO,CAAC,aAAqB,SAAe;AACzC,QAAI,KAAK,aAAa;AAClB,aAAO,cAAc,KAAK;AAAA,IAC9B,OAAO;AACH,aAAO;AAAA,IACX;AAAA,EACJ,GAAG,EAAE;AACT,MAAI,aAAa;AACb,WAAO,YAAY,KAAK;AAAA,EAC5B,OAAO;AACH,WAAO;AAAA,EACX;AACJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";export const getLabelFromSlot=(r,l)=>{if(r)return null;const t=l.assignedNodes().reduce((e,n)=>n.textContent?e+n.textContent:e,"");return t?t.trim():null};
2
+ //# sourceMappingURL=get-label-from-slot.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["get-label-from-slot.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 getLabelFromSlot = (\n label: string,\n slotEl: HTMLSlotElement\n): string | null => {\n if (label) return null;\n const textContent = slotEl\n .assignedNodes()\n .reduce((accumulator: string, node: Node) => {\n if (node.textContent) {\n return accumulator + node.textContent;\n } else {\n return accumulator;\n }\n }, '');\n if (textContent) {\n return textContent.trim();\n } else {\n return null;\n }\n};\n"],
5
+ "mappings": "aAYO,aAAM,iBAAmB,CAC5BA,EACAC,IACgB,CAChB,GAAID,EAAO,OAAO,KAClB,MAAME,EAAcD,EACf,cAAc,EACd,OAAO,CAACE,EAAqBC,IACtBA,EAAK,YACED,EAAcC,EAAK,YAEnBD,EAEZ,EAAE,EACT,OAAID,EACOA,EAAY,KAAK,EAEjB,IAEf",
6
+ "names": ["label", "slotEl", "textContent", "accumulator", "node"]
7
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export * from './first-focusable-in.js';
2
+ export * from './focus-visible.js';
3
+ export * from './focusable.js';
4
+ export * from './focusable-selectors.js';
5
+ export * from './get-active-element.js';
6
+ export * from './like-anchor.js';
7
+ export * from './observe-slot-presence.js';
8
+ export * from './observe-slot-text.js';
9
+ export * from './platform.js';
10
+ export * from './reparent-children.js';
11
+ export * from './get-label-from-slot.js';
12
+ export * from './random-id.js';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ export * from "./first-focusable-in.dev.js";
3
+ export * from "./focus-visible.dev.js";
4
+ export * from "./focusable.dev.js";
5
+ export * from "./focusable-selectors.dev.js";
6
+ export * from "./get-active-element.dev.js";
7
+ export * from "./like-anchor.dev.js";
8
+ export * from "./observe-slot-presence.dev.js";
9
+ export * from "./observe-slot-text.dev.js";
10
+ export * from "./platform.dev.js";
11
+ export * from "./reparent-children.dev.js";
12
+ export * from "./get-label-from-slot.dev.js";
13
+ export * from "./random-id.dev.js";
14
+ //# 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 './focusable-selectors.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'\nexport * from './get-label-from-slot.dev.js'\nexport * from './random-id.dev.js'\n"],
5
+ "mappings": ";AAYA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
+ "names": []
7
+ }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";export*from"./first-focusable-in.js";export*from"./focus-visible.js";export*from"./focusable.js";export*from"./focusable-selectors.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";export*from"./get-label-from-slot.js";export*from"./random-id.js";
2
+ //# sourceMappingURL=index.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.js';\nexport * from './focus-visible.js';\nexport * from './focusable.js';\nexport * from './focusable-selectors.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';\nexport * from './get-label-from-slot.js';\nexport * from './random-id.js';\n"],
5
+ "mappings": "aAYA,WAAc,0BACd,WAAc,qBACd,WAAc,iBACd,WAAc,2BACd,WAAc,0BACd,WAAc,mBACd,WAAc,6BACd,WAAc,yBACd,WAAc,gBACd,WAAc,yBACd,WAAc,2BACd,WAAc",
6
+ "names": []
7
+ }
@@ -0,0 +1,23 @@
1
+ import { ReactiveElement, TemplateResult } from '@spectrum-web-components/base';
2
+ type Constructor<T = Record<string, unknown>> = {
3
+ new (...args: any[]): T;
4
+ prototype: T;
5
+ };
6
+ type RenderAnchorOptions = {
7
+ id: string;
8
+ className?: string;
9
+ ariaHidden?: boolean;
10
+ anchorContent?: TemplateResult | TemplateResult[];
11
+ labelledby?: string;
12
+ tabindex?: -1 | 0;
13
+ };
14
+ export interface LikeAnchorInterface {
15
+ download?: string;
16
+ label?: string;
17
+ href?: string;
18
+ rel?: string;
19
+ target?: '_blank' | '_parent' | '_self' | '_top';
20
+ renderAnchor(options: RenderAnchorOptions): TemplateResult;
21
+ }
22
+ export declare function LikeAnchor<T extends Constructor<ReactiveElement>>(constructor: T): T & Constructor<LikeAnchorInterface>;
23
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __decorateClass = (decorators, target, key, kind) => {
5
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
6
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
7
+ if (decorator = decorators[i])
8
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9
+ if (kind && result) __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
+ // prettier-ignore
26
+ anchorContent = html`<slot></slot>`
27
+ }) {
28
+ return html`<a
29
+ id=${id}
30
+ class=${ifDefined(className)}
31
+ href=${ifDefined(this.href)}
32
+ download=${ifDefined(this.download)}
33
+ target=${ifDefined(this.target)}
34
+ aria-label=${ifDefined(this.label)}
35
+ aria-labelledby=${ifDefined(labelledby)}
36
+ aria-hidden=${ifDefined(ariaHidden ? "true" : void 0)}
37
+ tabindex=${ifDefined(tabindex)}
38
+ referrerpolicy=${ifDefined(this.referrerpolicy)}
39
+ rel=${ifDefined(this.rel)}
40
+ >${anchorContent}</a>`;
41
+ }
42
+ }
43
+ __decorateClass([
44
+ property()
45
+ ], LikeAnchorElement.prototype, "download", 2);
46
+ __decorateClass([
47
+ property()
48
+ ], LikeAnchorElement.prototype, "label", 2);
49
+ __decorateClass([
50
+ property()
51
+ ], LikeAnchorElement.prototype, "href", 2);
52
+ __decorateClass([
53
+ property()
54
+ ], LikeAnchorElement.prototype, "target", 2);
55
+ __decorateClass([
56
+ property()
57
+ ], LikeAnchorElement.prototype, "referrerpolicy", 2);
58
+ __decorateClass([
59
+ property()
60
+ ], LikeAnchorElement.prototype, "rel", 2);
61
+ return LikeAnchorElement;
62
+ }
63
+ //# 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 /**\n * Causes the browser to treat the linked URL as a download.\n */\n @property()\n public download?: string;\n\n /**\n * An accessible label that describes the component.\n * It will be applied to aria-label, but not visually rendered.\n */\n @property()\n public label?: string;\n\n /**\n * The URL that the hyperlink points to.\n */\n @property()\n public href?: string;\n\n /**\n * Where to display the linked URL, as the name for a browsing context (a tab, window, or &lt;iframe&gt;).\n */\n @property()\n public target?: '_blank' | '_parent' | '_self' | '_top';\n\n /**\n * How much of the referrer to send when following the link.\n */\n @property()\n public referrerpolicy?:\n | 'no-referrer'\n | 'no-referrer-when-downgrade'\n | 'origin'\n | 'origin-when-cross-origin'\n | 'same-origin'\n | 'strict-origin'\n | 'strict-origin-when-cross-origin'\n | 'unsafe-url';\n\n /**\n * The relationship of the linked URL as space-separated link types.\n */\n @property()\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 referrerpolicy=${ifDefined(this.referrerpolicy)}\n rel=${ifDefined(this.rel)}\n >${anchorContent}</a>`;\n }\n }\n return LikeAnchorElement;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;AAWA;AAAA,EACI;AAAA,OAGG;AACP,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AA0BnB,gBAAS,WACZ,aACoC;AAAA,EACpC,MAAM,0BAA0B,YAAY;AAAA,IA8CjC,aAAa;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,MAEA,gBAAgB;AAAA,IACpB,GAAwC;AAEpC,aAAO;AAAA,yBAEM,EAAE;AAAA,4BACC,UAAU,SAAS,CAAC;AAAA,2BACrB,UAAU,KAAK,IAAI,CAAC;AAAA,+BAChB,UAAU,KAAK,QAAQ,CAAC;AAAA,6BAC1B,UAAU,KAAK,MAAM,CAAC;AAAA,iCAClB,UAAU,KAAK,KAAK,CAAC;AAAA,sCAChB,UAAU,UAAU,CAAC;AAAA,kCACzB,UAAU,aAAa,SAAS,MAAS,CAAC;AAAA,+BAC7C,UAAU,QAAQ,CAAC;AAAA,qCACb,UAAU,KAAK,cAAc,CAAC;AAAA,0BACzC,UAAU,KAAK,GAAG,CAAC;AAAA,mBAC1B,aAAa;AAAA,IACxB;AAAA,EACJ;AAlEW;AAAA,IADN,SAAS;AAAA,KAJR,kBAKK;AAOA;AAAA,IADN,SAAS;AAAA,KAXR,kBAYK;AAMA;AAAA,IADN,SAAS;AAAA,KAjBR,kBAkBK;AAMA;AAAA,IADN,SAAS;AAAA,KAvBR,kBAwBK;AAMA;AAAA,IADN,SAAS;AAAA,KA7BR,kBA8BK;AAcA;AAAA,IADN,SAAS;AAAA,KA3CR,kBA4CK;AA4BX,SAAO;AACX;",
6
+ "names": []
7
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var n=(s,r,p,i)=>{for(var t=i>1?void 0:i?f(r,p):r,a=s.length-1,l;a>=0;a--)(l=s[a])&&(t=(i?l(r,p,t):l(t))||t);return i&&t&&u(r,p,t),t};import{html as c}from"@spectrum-web-components/base";import{property as o}from"@spectrum-web-components/base/src/decorators.js";import{ifDefined as e}from"@spectrum-web-components/base/src/directives.js";export function LikeAnchor(s){class r extends s{renderAnchor({id:i,className:t,ariaHidden:a,labelledby:l,tabindex:d,anchorContent:g=c`<slot></slot>`}){return c`<a
2
+ id=${i}
3
+ class=${e(t)}
4
+ href=${e(this.href)}
5
+ download=${e(this.download)}
6
+ target=${e(this.target)}
7
+ aria-label=${e(this.label)}
8
+ aria-labelledby=${e(l)}
9
+ aria-hidden=${e(a?"true":void 0)}
10
+ tabindex=${e(d)}
11
+ referrerpolicy=${e(this.referrerpolicy)}
12
+ rel=${e(this.rel)}
13
+ >${g}</a>`}}return n([o()],r.prototype,"download",2),n([o()],r.prototype,"label",2),n([o()],r.prototype,"href",2),n([o()],r.prototype,"target",2),n([o()],r.prototype,"referrerpolicy",2),n([o()],r.prototype,"rel",2),r}
14
+ //# sourceMappingURL=like-anchor.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 /**\n * Causes the browser to treat the linked URL as a download.\n */\n @property()\n public download?: string;\n\n /**\n * An accessible label that describes the component.\n * It will be applied to aria-label, but not visually rendered.\n */\n @property()\n public label?: string;\n\n /**\n * The URL that the hyperlink points to.\n */\n @property()\n public href?: string;\n\n /**\n * Where to display the linked URL, as the name for a browsing context (a tab, window, or &lt;iframe&gt;).\n */\n @property()\n public target?: '_blank' | '_parent' | '_self' | '_top';\n\n /**\n * How much of the referrer to send when following the link.\n */\n @property()\n public referrerpolicy?:\n | 'no-referrer'\n | 'no-referrer-when-downgrade'\n | 'origin'\n | 'origin-when-cross-origin'\n | 'same-origin'\n | 'strict-origin'\n | 'strict-origin-when-cross-origin'\n | 'unsafe-url';\n\n /**\n * The relationship of the linked URL as space-separated link types.\n */\n @property()\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 referrerpolicy=${ifDefined(this.referrerpolicy)}\n rel=${ifDefined(this.rel)}\n >${anchorContent}</a>`;\n }\n }\n return LikeAnchorElement;\n}\n"],
5
+ "mappings": "qNAWA,OACI,QAAAA,MAGG,gCACP,OAAS,YAAAC,MAAgB,kDACzB,OAAS,aAAAC,MAAiB,kDA0BnB,gBAAS,WACZC,EACoC,CACpC,MAAMC,UAA0BD,CAAY,CA8CjC,aAAa,CAChB,GAAAE,EACA,UAAAC,EACA,WAAAC,EACA,WAAAC,EACA,SAAAC,EAEA,cAAAC,EAAgBV,gBACpB,EAAwC,CAEpC,OAAOA;AAAA,yBAEMK,CAAE;AAAA,4BACCH,EAAUI,CAAS,CAAC;AAAA,2BACrBJ,EAAU,KAAK,IAAI,CAAC;AAAA,+BAChBA,EAAU,KAAK,QAAQ,CAAC;AAAA,6BAC1BA,EAAU,KAAK,MAAM,CAAC;AAAA,iCAClBA,EAAU,KAAK,KAAK,CAAC;AAAA,sCAChBA,EAAUM,CAAU,CAAC;AAAA,kCACzBN,EAAUK,EAAa,OAAS,MAAS,CAAC;AAAA,+BAC7CL,EAAUO,CAAQ,CAAC;AAAA,qCACbP,EAAU,KAAK,cAAc,CAAC;AAAA,0BACzCA,EAAU,KAAK,GAAG,CAAC;AAAA,mBAC1BQ,CAAa,MACxB,CACJ,CAlEW,OAAAC,EAAA,CADNV,EAAS,GAJRG,EAKK,wBAOAO,EAAA,CADNV,EAAS,GAXRG,EAYK,qBAMAO,EAAA,CADNV,EAAS,GAjBRG,EAkBK,oBAMAO,EAAA,CADNV,EAAS,GAvBRG,EAwBK,sBAMAO,EAAA,CADNV,EAAS,GA7BRG,EA8BK,8BAcAO,EAAA,CADNV,EAAS,GA3CRG,EA4CK,mBA4BJA,CACX",
6
+ "names": ["html", "property", "ifDefined", "constructor", "LikeAnchorElement", "id", "className", "ariaHidden", "labelledby", "tabindex", "anchorContent", "__decorateClass"]
7
+ }
@@ -0,0 +1,12 @@
1
+ import { ReactiveElement } from '@spectrum-web-components/base';
2
+ type Constructor<T = Record<string, unknown>> = {
3
+ new (...args: any[]): T;
4
+ prototype: T;
5
+ };
6
+ export interface SlotPresenceObservingInterface {
7
+ slotContentIsPresent: boolean;
8
+ getSlotContentPresence(selector: string): boolean;
9
+ managePresenceObservedSlot(): void;
10
+ }
11
+ export declare function ObserveSlotPresence<T extends Constructor<ReactiveElement>>(constructor: T, lightDomSelector: string | string[]): T & Constructor<SlotPresenceObservingInterface>;
12
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ import { MutationController } from "@lit-labs/observers/mutation-controller.js";
3
+ const slotContentIsPresent = Symbol("slotContentIsPresent");
4
+ export function ObserveSlotPresence(constructor, lightDomSelector) {
5
+ var _a, _b;
6
+ const lightDomSelectors = Array.isArray(lightDomSelector) ? lightDomSelector : [lightDomSelector];
7
+ class SlotPresenceObservingElement extends (_b = constructor, _a = slotContentIsPresent, _b) {
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ constructor(...args) {
10
+ super(args);
11
+ this[_a] = /* @__PURE__ */ new Map();
12
+ this.managePresenceObservedSlot = () => {
13
+ let changes = false;
14
+ lightDomSelectors.forEach((selector) => {
15
+ const nextValue = !!this.querySelector(`:scope > ${selector}`);
16
+ const previousValue = this[slotContentIsPresent].get(selector) || false;
17
+ changes = changes || previousValue !== nextValue;
18
+ this[slotContentIsPresent].set(
19
+ selector,
20
+ !!this.querySelector(`:scope > ${selector}`)
21
+ );
22
+ });
23
+ if (changes) {
24
+ this.updateComplete.then(() => {
25
+ this.requestUpdate();
26
+ });
27
+ }
28
+ };
29
+ new MutationController(this, {
30
+ config: {
31
+ childList: true,
32
+ subtree: true
33
+ },
34
+ callback: () => {
35
+ this.managePresenceObservedSlot();
36
+ }
37
+ });
38
+ this.managePresenceObservedSlot();
39
+ }
40
+ /**
41
+ * @private
42
+ */
43
+ get slotContentIsPresent() {
44
+ if (lightDomSelectors.length === 1) {
45
+ return this[slotContentIsPresent].get(lightDomSelectors[0]) || false;
46
+ } else {
47
+ throw new Error(
48
+ "Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead."
49
+ );
50
+ }
51
+ }
52
+ getSlotContentPresence(selector) {
53
+ if (this[slotContentIsPresent].has(selector)) {
54
+ return this[slotContentIsPresent].get(selector) || false;
55
+ }
56
+ throw new Error(
57
+ `The provided selector \`${selector}\` is not being observed.`
58
+ );
59
+ }
60
+ }
61
+ return SlotPresenceObservingElement;
62
+ }
63
+ //# 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(`:scope > ${selector}`);\n const previousValue =\n this[slotContentIsPresent].get(selector) || false;\n changes = changes || previousValue !== nextValue;\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(`:scope > ${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,SAAS,0BAA0B;AAEnC,MAAM,uBAAuB,OAAO,sBAAsB;AAcnD,gBAAS,oBACZ,aACA,kBAC+C;AA9BnD;AA+BI,QAAM,oBAAoB,MAAM,QAAQ,gBAAgB,IAClD,mBACA,CAAC,gBAAgB;AAAA,EACvB,MAAM,sCACM,kBAmCC,2BAnCD,IAEZ;AAAA;AAAA,IAEI,eAAe,MAAa;AACxB,YAAM,IAAI;AA8Bd,WAAS,MAA8C,oBAAI,IAAI;AAW/D,WAAO,6BAA6B,MAAY;AAC5C,YAAI,UAAU;AACd,0BAAkB,QAAQ,CAAC,aAAa;AACpC,gBAAM,YAAY,CAAC,CAAC,KAAK,cAAc,YAAY,QAAQ,EAAE;AAC7D,gBAAM,gBACF,KAAK,oBAAoB,EAAE,IAAI,QAAQ,KAAK;AAChD,oBAAU,WAAW,kBAAkB;AACvC,eAAK,oBAAoB,EAAE;AAAA,YACvB;AAAA,YACA,CAAC,CAAC,KAAK,cAAc,YAAY,QAAQ,EAAE;AAAA,UAC/C;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;AAAA;AAAA;AAAA,IAKA,IAAW,uBAAgC;AACvC,UAAI,kBAAkB,WAAW,GAAG;AAChC,eACI,KAAK,oBAAoB,EAAE,IAAI,kBAAkB,CAAC,CAAC,KACnD;AAAA,MAER,OAAO;AACH,cAAM,IAAI;AAAA,UACN;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAAA,IAGO,uBAAuB,UAA2B;AACrD,UAAI,KAAK,oBAAoB,EAAE,IAAI,QAAQ,GAAG;AAC1C,eAAO,KAAK,oBAAoB,EAAE,IAAI,QAAQ,KAAK;AAAA,MACvD;AACA,YAAM,IAAI;AAAA,QACN,2BAA2B,QAAQ;AAAA,MACvC;AAAA,IACJ;AAAA,EAoBJ;AACA,SAAO;AACX;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";import{MutationController as u}from"@lit-labs/observers/mutation-controller.js";const t=Symbol("slotContentIsPresent");export function ObserveSlotPresence(l,s){var o,i;const r=Array.isArray(s)?s:[s];class a extends(i=l,o=t,i){constructor(...e){super(e);this[o]=new Map;this.managePresenceObservedSlot=()=>{let e=!1;r.forEach(n=>{const c=!!this.querySelector(`:scope > ${n}`),g=this[t].get(n)||!1;e=e||g!==c,this[t].set(n,!!this.querySelector(`:scope > ${n}`))}),e&&this.updateComplete.then(()=>{this.requestUpdate()})};new u(this,{config:{childList:!0,subtree:!0},callback:()=>{this.managePresenceObservedSlot()}}),this.managePresenceObservedSlot()}get slotContentIsPresent(){if(r.length===1)return this[t].get(r[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 a}
2
+ //# sourceMappingURL=observe-slot-presence.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(`:scope > ${selector}`);\n const previousValue =\n this[slotContentIsPresent].get(selector) || false;\n changes = changes || previousValue !== nextValue;\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(`:scope > ${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,OAAS,sBAAAA,MAA0B,6CAEnC,MAAMC,EAAuB,OAAO,sBAAsB,EAcnD,gBAAS,oBACZC,EACAC,EAC+C,CA9BnD,IAAAC,EAAAC,EA+BI,MAAMC,EAAoB,MAAM,QAAQH,CAAgB,EAClDA,EACA,CAACA,CAAgB,EACvB,MAAMI,UACMF,EAAAH,EAmCCE,EAAAH,EAnCDI,EAEZ,CAEI,eAAeG,EAAa,CACxB,MAAMA,CAAI,EA8Bd,KAASJ,GAA8C,IAAI,IAW3D,KAAO,2BAA6B,IAAY,CAC5C,IAAIK,EAAU,GACdH,EAAkB,QAASI,GAAa,CACpC,MAAMC,EAAY,CAAC,CAAC,KAAK,cAAc,YAAYD,CAAQ,EAAE,EACvDE,EACF,KAAKX,CAAoB,EAAE,IAAIS,CAAQ,GAAK,GAChDD,EAAUA,GAAWG,IAAkBD,EACvC,KAAKV,CAAoB,EAAE,IACvBS,EACA,CAAC,CAAC,KAAK,cAAc,YAAYA,CAAQ,EAAE,CAC/C,CACJ,CAAC,EACGD,GACA,KAAK,eAAe,KAAK,IAAM,CAC3B,KAAK,cAAc,CACvB,CAAC,CAET,EAxDI,IAAIT,EAAmB,KAAM,CACzB,OAAQ,CACJ,UAAW,GACX,QAAS,EACb,EACA,SAAU,IAAM,CACZ,KAAK,2BAA2B,CACpC,CACJ,CAAC,EAED,KAAK,2BAA2B,CACpC,CAKA,IAAW,sBAAgC,CACvC,GAAIM,EAAkB,SAAW,EAC7B,OACI,KAAKL,CAAoB,EAAE,IAAIK,EAAkB,CAAC,CAAC,GACnD,GAGJ,MAAM,IAAI,MACN,8GACJ,CAER,CAGO,uBAAuBI,EAA2B,CACrD,GAAI,KAAKT,CAAoB,EAAE,IAAIS,CAAQ,EACvC,OAAO,KAAKT,CAAoB,EAAE,IAAIS,CAAQ,GAAK,GAEvD,MAAM,IAAI,MACN,2BAA2BA,CAAQ,2BACvC,CACJ,CAoBJ,CACA,OAAOH,CACX",
6
+ "names": ["MutationController", "slotContentIsPresent", "constructor", "lightDomSelector", "_a", "_b", "lightDomSelectors", "SlotPresenceObservingElement", "args", "changes", "selector", "nextValue", "previousValue"]
7
+ }
@@ -0,0 +1,11 @@
1
+ import { ReactiveElement } from '@spectrum-web-components/base';
2
+ type Constructor<T = Record<string, unknown>> = {
3
+ new (...args: any[]): T;
4
+ prototype: T;
5
+ };
6
+ export interface SlotTextObservingInterface {
7
+ slotHasContent: boolean;
8
+ manageTextObservedSlot(): void;
9
+ }
10
+ export declare function ObserveSlotText<T extends Constructor<ReactiveElement>>(constructor: T, slotName?: string, excludedSelectors?: string[]): T & Constructor<SlotTextObservingInterface>;
11
+ export {};
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __decorateClass = (decorators, target, key, kind) => {
5
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
6
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
7
+ if (decorator = decorators[i])
8
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
9
+ if (kind && result) __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, excludedSelectors = []) {
19
+ var _a, _b;
20
+ const notExcluded = (el) => (selector) => {
21
+ return el.matches(selector);
22
+ };
23
+ class SlotTextObservingElement extends (_b = constructor, _a = assignedNodesList, _b) {
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ constructor(...args) {
26
+ super(args);
27
+ this.slotHasContent = false;
28
+ new MutationController(this, {
29
+ config: {
30
+ characterData: true,
31
+ subtree: true
32
+ },
33
+ callback: (mutationsList) => {
34
+ for (const mutation of mutationsList) {
35
+ if (mutation.type === "characterData") {
36
+ this.manageTextObservedSlot();
37
+ return;
38
+ }
39
+ }
40
+ }
41
+ });
42
+ }
43
+ manageTextObservedSlot() {
44
+ if (!this[assignedNodesList]) return;
45
+ const assignedNodes = [...this[assignedNodesList]].filter(
46
+ (currentNode) => {
47
+ const node = currentNode;
48
+ if (node.tagName) {
49
+ return !excludedSelectors.some(notExcluded(node));
50
+ }
51
+ return node.textContent ? node.textContent.trim() : false;
52
+ }
53
+ );
54
+ this.slotHasContent = assignedNodes.length > 0;
55
+ }
56
+ update(changedProperties) {
57
+ if (!this.hasUpdated) {
58
+ const { childNodes } = this;
59
+ const textNodes = [...childNodes].filter((currentNode) => {
60
+ const node = currentNode;
61
+ if (node.tagName) {
62
+ const excluded = excludedSelectors.some(
63
+ notExcluded(node)
64
+ );
65
+ return !excluded ? (
66
+ // This pass happens at element upgrade and before slot rendering.
67
+ // Confirm it would exisit in a targeted slot if there was one supplied.
68
+ slotName ? node.getAttribute("slot") === slotName : !node.hasAttribute("slot")
69
+ ) : false;
70
+ }
71
+ return node.textContent ? node.textContent.trim() : false;
72
+ });
73
+ this.slotHasContent = textNodes.length > 0;
74
+ }
75
+ super.update(changedProperties);
76
+ }
77
+ firstUpdated(changedProperties) {
78
+ super.firstUpdated(changedProperties);
79
+ this.updateComplete.then(() => {
80
+ this.manageTextObservedSlot();
81
+ });
82
+ }
83
+ }
84
+ __decorateClass([
85
+ property({ type: Boolean, attribute: false })
86
+ ], SlotTextObservingElement.prototype, "slotHasContent", 2);
87
+ __decorateClass([
88
+ queryAssignedNodes({
89
+ slot: slotName,
90
+ flatten: true
91
+ })
92
+ ], SlotTextObservingElement.prototype, _a, 2);
93
+ return SlotTextObservingElement;
94
+ }
95
+ //# 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 excludedSelectors: string[] = []\n): T & Constructor<SlotTextObservingInterface> {\n const notExcluded = (el: HTMLElement) => (selector: string) => {\n return el.matches(selector);\n };\n\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({\n slot: slotName,\n flatten: true,\n })\n private [assignedNodesList]!: NodeListOf<HTMLElement>;\n\n public manageTextObservedSlot(): void {\n if (!this[assignedNodesList]) return;\n const assignedNodes = [...this[assignedNodesList]].filter(\n (currentNode) => {\n const node = currentNode as HTMLElement;\n if (node.tagName) {\n return !excludedSelectors.some(notExcluded(node));\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((currentNode) => {\n const node = currentNode as HTMLElement;\n if (node.tagName) {\n const excluded = excludedSelectors.some(\n notExcluded(node)\n );\n return !excluded\n ? // This pass happens at element upgrade and before slot rendering.\n // Confirm it would exisit in a targeted slot if there was one supplied.\n slotName\n ? node.getAttribute('slot') === slotName\n : !node.hasAttribute('slot')\n : false;\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": ";;;;;;;;;;;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