@nordhealth/components 1.2.0 → 1.5.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 (62) hide show
  1. package/custom-elements.json +2376 -1339
  2. package/lib/Avatar.js.map +1 -1
  3. package/lib/Banner.js.map +1 -1
  4. package/lib/Button.js +1 -1
  5. package/lib/Button.js.map +1 -1
  6. package/lib/Calendar-a389d216.js +2 -0
  7. package/lib/{Calendar-73a2fcfd.js.map → Calendar-a389d216.js.map} +1 -1
  8. package/lib/Calendar.js +1 -1
  9. package/lib/CommandMenu.js +1 -1
  10. package/lib/CommandMenu.js.map +1 -1
  11. package/lib/DatePicker.js +1 -1
  12. package/lib/DatePicker.js.map +1 -1
  13. package/lib/DropdownItem.js +1 -1
  14. package/lib/DropdownItem.js.map +1 -1
  15. package/lib/Header.js.map +1 -1
  16. package/lib/Icon.js +1 -1
  17. package/lib/Layout.js +1 -1
  18. package/lib/Layout.js.map +1 -1
  19. package/lib/NavGroup.js +1 -1
  20. package/lib/NavGroup.js.map +1 -1
  21. package/lib/NavItem.js +1 -1
  22. package/lib/NavItem.js.map +1 -1
  23. package/lib/Navigation.js +1 -1
  24. package/lib/Navigation.js.map +1 -1
  25. package/lib/Table.js +1 -1
  26. package/lib/Table.js.map +1 -1
  27. package/lib/Toggle.js +2 -0
  28. package/lib/Toggle.js.map +1 -0
  29. package/lib/Tooltip.js.map +1 -1
  30. package/lib/bundle.js +9 -9
  31. package/lib/bundle.js.map +1 -1
  32. package/lib/fsm-50373df9.js.map +1 -1
  33. package/lib/index.js +1 -1
  34. package/lib/number-c3ab3e95.js +2 -0
  35. package/lib/number-c3ab3e95.js.map +1 -0
  36. package/lib/observe-a9c6dfb6.js.map +1 -1
  37. package/lib/repeat-ed796481.js +7 -0
  38. package/lib/repeat-ed796481.js.map +1 -0
  39. package/lib/src/avatar/Avatar.d.ts +1 -1
  40. package/lib/src/banner/Banner.d.ts +1 -1
  41. package/lib/src/button/Button.d.ts +1 -1
  42. package/lib/src/common/controllers/MediaQueryController.d.ts +14 -0
  43. package/lib/src/common/fsm.d.ts +3 -2
  44. package/lib/src/common/number.d.ts +1 -0
  45. package/lib/src/common/storage.d.ts +7 -0
  46. package/lib/src/header/Header.d.ts +1 -1
  47. package/lib/src/index.d.ts +1 -0
  48. package/lib/src/layout/Layout.d.ts +47 -3
  49. package/lib/src/layout/Layout.test.d.ts +4 -0
  50. package/lib/src/nav-group/NavGroup.d.ts +1 -1
  51. package/lib/src/nav-item/NavItem.d.ts +1 -1
  52. package/lib/src/navigation/Navigation.d.ts +2 -4
  53. package/lib/src/navigation/Navigation.test.d.ts +1 -0
  54. package/lib/src/toggle/Toggle.d.ts +38 -0
  55. package/lib/src/toggle/Toggle.test.d.ts +3 -0
  56. package/lib/src/tooltip/Tooltip.d.ts +1 -1
  57. package/package.json +7 -7
  58. package/lib/Calendar-73a2fcfd.js +0 -2
  59. package/lib/DraftComponentMixin-9e4b7b34.js +0 -2
  60. package/lib/DraftComponentMixin-9e4b7b34.js.map +0 -1
  61. package/lib/number-1c122a1e.js +0 -7
  62. package/lib/number-1c122a1e.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","sources":["../src/common/attribute.ts","../src/tooltip/Tooltip.ts"],"sourcesContent":["function getTokens(element: Element, attr: string) {\n const value = element.getAttribute(attr)\n return value ? value.split(/\\s+/) : []\n}\n\nfunction setTokens(element: Element, attr: string, tokens: string[]) {\n element.setAttribute(attr, tokens.join(\" \"))\n}\n\n/**\n * Carefully adds a token to a space-separated attribute\n * Similar to classList, but for any attribute.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/add\n */\nexport function add(element: Element, attr: string, token: string) {\n const tokens = getTokens(element, attr)\n\n if (!tokens.includes(token)) {\n setTokens(element, attr, tokens.concat(token))\n }\n}\n\n/**\n * Carefully removes a token from a space-separated attribute.\n * Similar to classList, but for any attribute.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/remove\n */\nexport function remove(element: Element, attr: string, token: string) {\n const tokens = getTokens(element, attr)\n\n if (tokens.includes(token)) {\n setTokens(\n element,\n attr,\n tokens.filter(t => t !== token)\n )\n }\n}\n","import { LitElement, html } from \"lit\"\nimport { customElement, property, state } from \"lit/decorators.js\"\nimport { computePosition, flip, shift, offset } from \"@floating-ui/dom\"\n\nimport * as attr from \"../common/attribute.js\"\nimport type { FocusableMixinInterface } from \"../common/mixins/FocusableMixin.js\"\nimport { SlotController } from \"../common/controllers/SlotController.js\"\nimport componentStyle from \"../common/styles/Component.css\"\nimport style from \"./Tooltip.css\"\nimport { EventController } from \"../common/controllers/EventController.js\"\nimport { States, fsm } from \"../common/fsm.js\"\nimport { logicalToPhysical } from \"../common/positioning.js\"\nimport { observe } from \"../common/decorators/observe.js\"\n\n// @ts-expect-error we're being naughty and accessing a protected field!\n// however this means we always get the correct types,\n// and it will ensure this file is not forgotten about if focusable mixin ever changes\ntype FocusableElement = HTMLElement & Pick<FocusableMixinInterface, \"focusableRef\">\n\nfunction isElement(el: Node): el is Element {\n return el.nodeType === Node.ELEMENT_NODE\n}\n\nfunction referencesTooltip(node: Node, tooltip: Tooltip) {\n return Boolean(tooltip.id) && isElement(node) && node.getAttribute(\"aria-describedby\") === tooltip.id\n}\n\nconst { transition } = fsm({\n hidden: {\n show: \"waiting\",\n },\n visible: {\n hide: \"hidden\",\n reposition: \"positioning\",\n show: \"positioning\",\n },\n waiting: {\n timeout: \"positioning\",\n hide: \"hidden\",\n },\n positioning: {\n positioned: \"visible\",\n hide: \"hidden\",\n },\n})\n\ntype TooltipStates = States<typeof transition>\n\n/**\n * Tooltips are floating containers for displaying additional information\n * for the currently focused element. A tooltip can be useful when you want\n * to e.g. give a hint about an existing Command Menu shortcut.\n *\n * @status ready\n * @category overlay\n * @slot - The tooltip content\n * @slot shortcut - Optional slot that holds shortcut keys to access the subject\n */\n@customElement(\"nord-tooltip\")\nexport default class Tooltip extends LitElement {\n static styles = [componentStyle, style]\n\n // tracks the last tooltip opened, so we can enforce only one is ever open at a time\n static lastOpened?: Tooltip\n\n private shortcutSlot = new SlotController(this, \"shortcut\")\n private events = new EventController(this)\n\n // The current element which revealed the tooltip shown\n private currentElement?: FocusableElement\n private timeoutId?: ReturnType<typeof setTimeout>\n\n /**\n * the proxy element is for cases where the targetElement is a web component,\n * and the WC has a focusable child in its shadow root e.g. a button component.\n * in this case, when the tooltip is shown, we inject the proxy into targetElement's shadow root\n * and wire up aria-describedby from the focusable element to the proxy.\n * when the tooltip is hidden, we remove the proxy and remove the aria-describedby relationship.\n */\n private proxy = document.createElement(\"span\")\n\n /**\n * The current state of the tooltip, dependent on the state machine\n */\n @state() private state: TooltipStates = \"hidden\"\n\n // The current coordinates for the tooltip\n private coords: [number, number] = [0, 0]\n\n /**\n * Control the position of the tooltip component.\n * When set to \"none\", the tooltip will be shown above\n * but accommodate for browser boundaries.\n */\n @property({ reflect: true }) position: \"block-end\" | \"block-start\" | \"inline-start\" | \"inline-end\" = \"block-start\"\n\n /**\n * The tooltip role, set on the component by default.\n */\n @property({ reflect: true }) role = \"tooltip\"\n\n /**\n * The id for the active element to reference via aria-describedby.\n */\n @property({ reflect: true }) id: string = \"\"\n\n /**\n * The delay in milliseconds before the tooltip is opened.\n */\n @property({ reflect: true, type: Number }) delay: number = 500\n\n /**\n * Apply all event listeners\n */\n connectedCallback() {\n super.connectedCallback()\n\n const rootNode = this.getRootNode() as Document\n\n this.events.listen(rootNode, \"keydown\", this.hideOnEscape)\n\n // we treat mouseover and focusin the same, since they both show tooltip\n this.events.listen(rootNode, \"mouseover\", this.handleShow)\n this.events.listen(rootNode, \"focusin\", this.handleShow)\n\n // we treat focusout, mouseout, click the same, since they all hide tooltip\n this.events.listen(rootNode, \"mouseout\", this.handleHide)\n this.events.listen(rootNode, \"focusout\", this.handleHide)\n this.events.listen(rootNode, \"click\", this.handleHide)\n\n this.events.listen(window, \"resize\", this.reposition, { passive: true })\n this.events.listen(window, \"scroll\", this.reposition, { passive: true })\n }\n\n render() {\n return html`\n <div class=\"n-tooltip\">\n <slot></slot>\n <div class=\"n-tooltip-shortcut\" ?hidden=${this.shortcutSlot.isEmpty}>\n <slot class=\"n-tooltip-key\" name=\"shortcut\"></slot>\n </div>\n </div>\n `\n }\n\n @observe(\"id\")\n protected handleIdChange() {\n if (!this.id) {\n // eslint-disable-next-line no-console\n console.warn(\"NORD: The tooltip requires an id attribute and value\")\n }\n }\n\n @observe(\"state\")\n private handleStateChange(prevState: TooltipStates) {\n switch (this.state) {\n case \"hidden\": {\n if (prevState === \"waiting\" && this.timeoutId) {\n clearTimeout(this.timeoutId)\n }\n\n this.removeDescribedBy()\n this.currentElement = undefined\n this.style.visibility = \"hidden\"\n this.style.opacity = \"0\"\n break\n }\n\n case \"visible\": {\n this.timeoutId = undefined\n Tooltip.lastOpened = this\n this.addDescribedBy()\n\n const [x, y] = this.coords\n\n // use physical properties here since floating-ui\n // works exclusively in physical dimensions\n // we do all the mapping in logicalToPhysical\n this.style.left = `${x}px`\n this.style.top = `${y}px`\n this.style.visibility = \"visible\"\n this.style.opacity = \"1\"\n break\n }\n\n case \"waiting\": {\n this.timeoutId = setTimeout(() => {\n this.state = transition(this.state, \"timeout\")\n }, this.delay)\n break\n }\n\n case \"positioning\": {\n if (Tooltip.lastOpened !== this) {\n Tooltip.lastOpened?.hideTooltip()\n }\n\n if (this.currentElement) {\n this.updatePosition(this.currentElement)\n }\n break\n }\n }\n }\n\n /**\n * Setting and updating the position of the tooltip\n */\n private updatePosition = (currentElement: HTMLElement) =>\n computePosition(currentElement, this, {\n strategy: \"fixed\",\n placement: logicalToPhysical(this.position),\n middleware: [\n offset(8),\n flip(),\n shift({\n padding: 8,\n }),\n ],\n }).then(({ x, y }) => {\n this.coords = [x, y]\n this.state = transition(this.state, \"positioned\")\n })\n\n private hideTooltip = () => {\n this.state = transition(this.state, \"hide\")\n }\n\n private reposition = () => {\n this.state = transition(this.state, \"reposition\")\n }\n\n private handleShow = (e: Event) => {\n const target = e.target as FocusableElement\n\n if (referencesTooltip(target, this)) {\n this.currentElement = target\n this.state = transition(this.state, \"show\")\n }\n }\n\n private handleHide = (e: Event) => {\n if (e.target === this.currentElement) {\n this.hideTooltip()\n }\n }\n\n private hideOnEscape = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n this.hideTooltip()\n }\n }\n\n private addDescribedBy = () => {\n const focusable = this.currentElement?.focusableRef?.value\n\n if (focusable) {\n this.proxy.hidden = true\n this.proxy.id = this.id\n this.proxy.textContent = this.textContent\n\n focusable.insertAdjacentElement(\"afterend\", this.proxy)\n attr.add(focusable, \"aria-describedby\", this.id)\n }\n }\n\n private removeDescribedBy = () => {\n const focusable = this.currentElement?.focusableRef?.value\n\n if (focusable) {\n this.proxy.remove()\n attr.remove(focusable, \"aria-describedby\", this.id)\n }\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"nord-tooltip\": Tooltip\n }\n}\n"],"names":["getTokens","element","attr","value","getAttribute","split","setTokens","tokens","setAttribute","join","referencesTooltip","node","tooltip","Boolean","id","nodeType","Node","ELEMENT_NODE","transition","fsm","hidden","show","visible","hide","reposition","waiting","timeout","positioning","positioned","Tooltip","Tooltip_1","LitElement","constructor","this","shortcutSlot","SlotController","events","EventController","proxy","document","createElement","state","coords","position","role","delay","updatePosition","currentElement","computePosition","strategy","placement","logicalToPhysical","middleware","offset","flip","shift","padding","then","x","y","hideTooltip","handleShow","e","target","handleHide","hideOnEscape","key","addDescribedBy","focusable","_b","_a","focusableRef","textContent","insertAdjacentElement","token","includes","concat","attr.add","removeDescribedBy","remove","filter","t","attr.remove","connectedCallback","super","rootNode","getRootNode","listen","window","passive","render","html","isEmpty","handleIdChange","console","warn","handleStateChange","prevState","timeoutId","clearTimeout","undefined","style","visibility","opacity","lastOpened","left","top","setTimeout","styles","componentStyle","__decorate","prototype","property","reflect","type","Number","observe","customElement"],"mappings":"ofAAA,SAASA,EAAUC,EAAkBC,GACnC,MAAMC,EAAQ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CAACC,EAAgBR,GAwBxBS,EAAA,CAARrE,KAA+CZ,EAAAkF,UAAA,aAAA,GAUnBD,EAAA,CAA5BE,EAAS,CAAEC,SAAS,KAA6FpF,EAAAkF,UAAA,gBAAA,GAKrFD,EAAA,CAA5BE,EAAS,CAAEC,SAAS,KAAwBpF,EAAAkF,UAAA,YAAA,GAKhBD,EAAA,CAA5BE,EAAS,CAAEC,SAAS,KAAuBpF,EAAAkF,UAAA,UAAA,GAKDD,EAAA,CAA1CE,EAAS,CAAEC,SAAS,EAAMC,KAAMC,UAA6BtF,EAAAkF,UAAA,aAAA,GAqC9DD,EAAA,CADCM,EAAQ,OAMRvF,EAAAkF,UAAA,iBAAA,MAGDD,EAAA,CADCM,EAAQ,UAkDRvF,EAAAkF,UAAA,oBAAA,MAhJkBlF,EAAOC,EAAAgF,EAAA,CAD3BO,EAAc,iBACMxF,SAAAA"}
1
+ {"version":3,"file":"Tooltip.js","sources":["../src/common/attribute.ts","../src/tooltip/Tooltip.ts"],"sourcesContent":["function getTokens(element: Element, attr: string) {\n const value = element.getAttribute(attr)\n return value ? value.split(/\\s+/) : []\n}\n\nfunction setTokens(element: Element, attr: string, tokens: string[]) {\n element.setAttribute(attr, tokens.join(\" \"))\n}\n\n/**\n * Carefully adds a token to a space-separated attribute\n * Similar to classList, but for any attribute.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/add\n */\nexport function add(element: Element, attr: string, token: string) {\n const tokens = getTokens(element, attr)\n\n if (!tokens.includes(token)) {\n setTokens(element, attr, tokens.concat(token))\n }\n}\n\n/**\n * Carefully removes a token from a space-separated attribute.\n * Similar to classList, but for any attribute.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/remove\n */\nexport function remove(element: Element, attr: string, token: string) {\n const tokens = getTokens(element, attr)\n\n if (tokens.includes(token)) {\n setTokens(\n element,\n attr,\n tokens.filter(t => t !== token)\n )\n }\n}\n","import { LitElement, html } from \"lit\"\nimport { customElement, property, state } from \"lit/decorators.js\"\nimport { computePosition, flip, shift, offset } from \"@floating-ui/dom\"\n\nimport * as attr from \"../common/attribute.js\"\nimport type { FocusableMixinInterface } from \"../common/mixins/FocusableMixin.js\"\nimport { SlotController } from \"../common/controllers/SlotController.js\"\nimport componentStyle from \"../common/styles/Component.css\"\nimport style from \"./Tooltip.css\"\nimport { EventController } from \"../common/controllers/EventController.js\"\nimport { States, fsm } from \"../common/fsm.js\"\nimport { logicalToPhysical } from \"../common/positioning.js\"\nimport { observe } from \"../common/decorators/observe.js\"\n\n// @ts-expect-error we're being naughty and accessing a protected field!\n// however this means we always get the correct types,\n// and it will ensure this file is not forgotten about if focusable mixin ever changes\ntype FocusableElement = HTMLElement & Pick<FocusableMixinInterface, \"focusableRef\">\n\nfunction isElement(el: Node): el is Element {\n return el.nodeType === Node.ELEMENT_NODE\n}\n\nfunction referencesTooltip(node: Node, tooltip: Tooltip) {\n return Boolean(tooltip.id) && isElement(node) && node.getAttribute(\"aria-describedby\") === tooltip.id\n}\n\nconst { transition } = fsm({\n hidden: {\n show: \"waiting\",\n },\n visible: {\n hide: \"hidden\",\n reposition: \"positioning\",\n show: \"positioning\",\n },\n waiting: {\n timeout: \"positioning\",\n hide: \"hidden\",\n },\n positioning: {\n positioned: \"visible\",\n hide: \"hidden\",\n },\n})\n\ntype TooltipStates = States<typeof transition>\n\n/**\n * Tooltips are floating containers for displaying additional information\n * for the currently focused element. A tooltip can be useful when you want\n * to e.g. give a hint about an existing Command Menu shortcut.\n *\n * @status ready\n * @category overlay\n * @slot - The tooltip content\n * @slot shortcut - Optional slot that holds shortcut keys to access the subject\n */\n@customElement(\"nord-tooltip\")\nexport default class Tooltip extends LitElement {\n static styles = [componentStyle, style]\n\n // tracks the last tooltip opened, so we can enforce only one is ever open at a time\n private static lastOpened?: Tooltip\n\n private shortcutSlot = new SlotController(this, \"shortcut\")\n private events = new EventController(this)\n\n // The current element which revealed the tooltip shown\n private currentElement?: FocusableElement\n private timeoutId?: ReturnType<typeof setTimeout>\n\n /**\n * the proxy element is for cases where the targetElement is a web component,\n * and the WC has a focusable child in its shadow root e.g. a button component.\n * in this case, when the tooltip is shown, we inject the proxy into targetElement's shadow root\n * and wire up aria-describedby from the focusable element to the proxy.\n * when the tooltip is hidden, we remove the proxy and remove the aria-describedby relationship.\n */\n private proxy = document.createElement(\"span\")\n\n /**\n * The current state of the tooltip, dependent on the state machine\n */\n @state() private state: TooltipStates = \"hidden\"\n\n // The current coordinates for the tooltip\n private coords: [number, number] = [0, 0]\n\n /**\n * Control the position of the tooltip component.\n * When set to \"none\", the tooltip will be shown above\n * but accommodate for browser boundaries.\n */\n @property({ reflect: true }) position: \"block-end\" | \"block-start\" | \"inline-start\" | \"inline-end\" = \"block-start\"\n\n /**\n * The tooltip role, set on the component by default.\n */\n @property({ reflect: true }) role = \"tooltip\"\n\n /**\n * The id for the active element to reference via aria-describedby.\n */\n @property({ reflect: true }) id: string = \"\"\n\n /**\n * The delay in milliseconds before the tooltip is opened.\n */\n @property({ reflect: true, type: Number }) delay: number = 500\n\n /**\n * Apply all event listeners\n */\n connectedCallback() {\n super.connectedCallback()\n\n const rootNode = this.getRootNode() as Document\n\n this.events.listen(rootNode, \"keydown\", this.hideOnEscape)\n\n // we treat mouseover and focusin the same, since they both show tooltip\n this.events.listen(rootNode, \"mouseover\", this.handleShow)\n this.events.listen(rootNode, \"focusin\", this.handleShow)\n\n // we treat focusout, mouseout, click the same, since they all hide tooltip\n this.events.listen(rootNode, \"mouseout\", this.handleHide)\n this.events.listen(rootNode, \"focusout\", this.handleHide)\n this.events.listen(rootNode, \"click\", this.handleHide)\n\n this.events.listen(window, \"resize\", this.reposition, { passive: true })\n this.events.listen(window, \"scroll\", this.reposition, { passive: true })\n }\n\n render() {\n return html`\n <div class=\"n-tooltip\">\n <slot></slot>\n <div class=\"n-tooltip-shortcut\" ?hidden=${this.shortcutSlot.isEmpty}>\n <slot class=\"n-tooltip-key\" name=\"shortcut\"></slot>\n </div>\n </div>\n `\n }\n\n @observe(\"id\")\n protected handleIdChange() {\n if (!this.id) {\n // eslint-disable-next-line no-console\n console.warn(\"NORD: The tooltip requires an id attribute and value\")\n }\n }\n\n @observe(\"state\")\n private handleStateChange(prevState: TooltipStates) {\n switch (this.state) {\n case \"hidden\": {\n if (prevState === \"waiting\" && this.timeoutId) {\n clearTimeout(this.timeoutId)\n }\n\n this.removeDescribedBy()\n this.currentElement = undefined\n this.style.visibility = \"hidden\"\n this.style.opacity = \"0\"\n break\n }\n\n case \"visible\": {\n this.timeoutId = undefined\n Tooltip.lastOpened = this\n this.addDescribedBy()\n\n const [x, y] = this.coords\n\n // use physical properties here since floating-ui\n // works exclusively in physical dimensions\n // we do all the mapping in logicalToPhysical\n this.style.left = `${x}px`\n this.style.top = `${y}px`\n this.style.visibility = \"visible\"\n this.style.opacity = \"1\"\n break\n }\n\n case \"waiting\": {\n this.timeoutId = setTimeout(() => {\n this.state = transition(this.state, \"timeout\")\n }, this.delay)\n break\n }\n\n case \"positioning\": {\n if (Tooltip.lastOpened !== this) {\n Tooltip.lastOpened?.hideTooltip()\n }\n\n if (this.currentElement) {\n this.updatePosition(this.currentElement)\n }\n break\n }\n }\n }\n\n /**\n * Setting and updating the position of the tooltip\n */\n private updatePosition = (currentElement: HTMLElement) =>\n computePosition(currentElement, this, {\n strategy: \"fixed\",\n placement: logicalToPhysical(this.position),\n middleware: [\n offset(8),\n flip(),\n shift({\n padding: 8,\n }),\n ],\n }).then(({ x, y }) => {\n this.coords = [x, y]\n this.state = transition(this.state, \"positioned\")\n })\n\n private hideTooltip = () => {\n this.state = transition(this.state, \"hide\")\n }\n\n private reposition = () => {\n this.state = transition(this.state, \"reposition\")\n }\n\n private handleShow = (e: Event) => {\n const target = e.target as FocusableElement\n\n if (referencesTooltip(target, this)) {\n this.currentElement = target\n this.state = transition(this.state, \"show\")\n }\n }\n\n private handleHide = (e: Event) => {\n if (e.target === this.currentElement) {\n this.hideTooltip()\n }\n }\n\n private hideOnEscape = (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n this.hideTooltip()\n }\n }\n\n private addDescribedBy = () => {\n const focusable = this.currentElement?.focusableRef?.value\n\n if (focusable) {\n this.proxy.hidden = true\n this.proxy.id = this.id\n this.proxy.textContent = this.textContent\n\n focusable.insertAdjacentElement(\"afterend\", this.proxy)\n attr.add(focusable, \"aria-describedby\", this.id)\n }\n }\n\n private removeDescribedBy = () => {\n const focusable = this.currentElement?.focusableRef?.value\n\n if (focusable) {\n this.proxy.remove()\n attr.remove(focusable, \"aria-describedby\", this.id)\n }\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"nord-tooltip\": Tooltip\n }\n}\n"],"names":["getTokens","element","attr","value","getAttribute","split","setTokens","tokens","setAttribute","join","referencesTooltip","node","tooltip","Boolean","id","nodeType","Node","ELEMENT_NODE","transition","fsm","hidden","show","visible","hide","reposition","waiting","timeout","positioning","positioned","Tooltip","Tooltip_1","LitElement","constructor","this","shortcutSlot","SlotController","events","EventController","proxy","document","createElement","state","coords","position","role","delay","updatePosition","currentElement","computePosition","strategy","placement","logicalToPhysical","middleware","offset","flip","shift","padding","then","x","y","hideTooltip","handleShow","e","target","handleHide","hideOnEscape","key","addDescribedBy","focusable","_b","_a","focusableRef","textContent","insertAdjacentElement","token","includes","concat","attr.add","removeDescribedBy","remove","filter","t","attr.remove","connectedCallback","super","rootNode","getRootNode","listen","window","passive","render","html","isEmpty","handleIdChange","console","warn","handleStateChange","prevState","timeoutId","clearTimeout","undefined","style","visibility","opacity","lastOpened","left","top","setTimeout","styles","componentStyle","__decorate","prototype","property","reflect","type","Number","observe","customElement"],"mappings":"ofAAA,SAASA,EAAUC,EAAkBC,GACnC,MAAMC,EAAQF,EAAQG,aAAaF,GACnC,OAAOC,EAAQA,EAAME,MAAM,OAAS,GAGtC,SAASC,EAAUL,EAAkBC,EAAcK,GACjDN,EAAQO,aAAaN,EAAMK,EAAOE,KAAK,0sCCiBzC,SAASC,EAAkBC,EAAYC,GACrC,OAAO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