{"mappings":"AACA,OAAO,iBAAiB;AACxB,cAAyB,qBAAqB,sBAAsB;;;;;;;;;;;AAiBpE,cAsBM,gBAAgB,YAAY;CAChC;CAEA,AACA;CAEA,AACA,QAAQ,SAAS,SAAS,WAAW;CAErC,AACA,MAAM,SAAS,WAAW;;;;;CAM1B,AACA,UACI,WACA,SACA,aACA,gBACA,UACA,cACA,iBACA,QACA,aACA,cACA,WACA,gBACA,iBACA,UACA,gBACA,cACA,QACA,cACA;CAEJ,UACU,UAAU;CAEpB;CAeA,UAAU,UAAU,eAAe;CAmBnC,UAAU;CAUV;CAIA;CAIA,OAAO;CAIP,UAAU,QAAQ,oBAAoB;CAMtC,UAAU;CAiBV;;AAWF,SAAS,SAAS,WAAW","names":[],"sources":["../../../../src/web-components/popover/component.ts"],"sourcesContent":["import { property, query } from \"lit/decorators.js\";\nimport GlobalStyle from \"../../internal/global-style.js\";\nimport { css, html, type PropertyValues, type TemplateResult } from \"lit\";\nimport { godown, htmlSlot, StyleController, styles } from \"@godown/element\";\nimport { hidePopover, showPopover } from \"../../internal/popover.js\";\n\nconst POPOVER = \"popover\";\nconst protoName = POPOVER;\n\n/**\n * {@link Popover} renders a popover.\n *\n * This requires the support of the popover API and CSS position-area.\n *\n * @fires toggle - Fired when the popover is toggled.\n * @slot popover - Popover content.\n * @slot - Popover trigger.\n * @category display\n */\n@godown(protoName)\n@styles(css`\n  :host {\n    display: inline-block;\n  }\n\n  [part=\"trigger\"] {\n    display: contents;\n  }\n\n  [part=\"root\"] {\n    display: inherit;\n  }\n\n  [part=\"popover\"] {\n    inset: unset;\n    z-index: 1;\n    overflow: visible;\n    position: absolute;\n    position-try-fallbacks: flip-block;\n  }\n`)\nclass Popover extends GlobalStyle {\n  anchorName = `--${POPOVER}-${Math.random().toString(36).slice(2)}`;\n\n  @property({ type: Boolean, reflect: true })\n  open = false;\n\n  @property()\n  action: \"hide\" | \"show\" | \"toggle\" | \"none\" = \"show\";\n\n  @property()\n  span: \"span\" | \"spread\" | \"isolated\" = \"span\";\n\n  /**\n   * The position refers to the spatial location of the popover in relation to the trigger,\n   * rather than the alignment property between them.\n   */\n  @property()\n  position:\n    | \"center\"\n    | \"left\"\n    | \"left-top\"\n    | \"left-bottom\"\n    | \"right\"\n    | \"right-top\"\n    | \"right-bottom\"\n    | \"top\"\n    | \"top-left\"\n    | \"top-right\"\n    | \"bottom\"\n    | \"bottom-left\"\n    | \"bottom-right\"\n    | \"start\"\n    | \"start-start\"\n    | \"start-end\"\n    | \"end\"\n    | \"end-start\"\n    | \"end-end\" = \"bottom\";\n\n  @query(`[part=${POPOVER}]`, true)\n  protected _popover: HTMLElement;\n\n  constructor() {\n    super();\n    new StyleController(this, () => {\n      return {\n        \"[part=root],slot:not([name])::slotted(*)\": {\n          \"anchor-name\": this.anchorName,\n        },\n        \"[part=popover]\": {\n          \"position-anchor\": this.anchorName,\n          \"position-area\": this.resolveArea(),\n        },\n      };\n    });\n  }\n\n  protected render(): TemplateResult<1> {\n    return html`\n      <div part=\"root\">\n        <div\n          part=\"trigger\"\n          @click=${this._handleClick}\n        >\n          ${htmlSlot()}\n        </div>\n        <div\n          part=\"popover\"\n          popover=\"manual\"\n        >\n          ${htmlSlot(\"popover\")}\n        </div>\n      </div>\n    `;\n  }\n\n  protected _handleClick(): void {\n    const { action } = this;\n    switch (action) {\n      case \"show\":\n      case \"hide\":\n      case \"toggle\":\n        this[action]();\n    }\n  }\n\n  show(): void {\n    this.toggle(true);\n  }\n\n  hide(): void {\n    this.toggle(false);\n  }\n\n  toggle(force?: boolean): void {\n    this.open = force ?? !this.open;\n  }\n\n  protected updated(_changedProperties: PropertyValues): void {\n    if (_changedProperties.has(\"open\")) {\n      this._openChange();\n    }\n  }\n\n  protected _openChange(): void {\n    const { open } = this;\n    if (open) {\n      showPopover.call(this, this._popover);\n      const listener = (e) => {\n        if (!this.contains(e.target)) {\n          this.events.remove(document, \"click\", listener);\n          this.open = false;\n        }\n      };\n      this.events.add(document, \"click\", listener);\n    } else {\n      hidePopover(this._popover);\n    }\n    this.dispatchCustomEvent(\"toggle\", open);\n  }\n\n  resolveArea(): string {\n    const split = this.position.split(\"-\");\n    const firstValue = this.span === \"spread\" ? `span-${split[0]}` : split[0];\n    if (split.length < 2) {\n      return `${firstValue} center`;\n    }\n    const secondValue = this.span === \"isolated\" ? split[1] : `span-${split[1]}`;\n    return `${firstValue} ${secondValue}`;\n  }\n}\n\nexport { Popover, Popover as default };\n"],"version":3,"file":"component.d.ts"}