{"version":3,"sources":["../src/elements/flipcard.ts","../src/styles/elements/flipcard.ts"],"sourcesContent":["import { html, LitElement } from 'lit';\nimport {\n  customElement, property, state, query,\n} from 'lit/decorators.js';\nimport { stylesBase } from '../styles/elements/flipcard';\n\n/**\n * @since 1.0.0\n * @status stable\n *\n * @tagname kemet-flipcard\n * @summary A card that has a front and back side which can be flipped.\n *\n * @prop {string} axis\n * @prop {boolean} flipped\n * @prop {boolean} flipOnHover\n * @prop {string} height\n * @prop {boolean} measure\n *\n * @slot front - The front of the card.\n * @slot back - The back of the card.\n *\n * @csspart front - The front of the card.\n * @csspart back - The back of the card.\n * @csspart wrapper - A container for both front and back of the card.\n *\n * @cssproperty --kemet-flipcard-front-color - The text color for the front of the card.\n * @cssproperty --kemet-flipcard-back-color - The text color for the back of the card.\n * @cssproperty --kemet-flipcard-front-background-color - The background color for the front of the card.\n * @cssproperty --kemet-flipcard-back-background-color - The background color for the back of the card.\n * @cssproperty --kemet-flipcard-border - The border on the front and back of the card.\n * @cssproperty --kemet-flipcard-border-radius - The border radius on the front and back of the card.\n * @cssproperty --kemet-flipcard-ratio - The aspect ratio of the card.\n *\n */\n\n@customElement('kemet-flipcard')\nexport default class KemetFlipcard extends LitElement {\n  static styles = [stylesBase];\n\n  @property({ type: String, reflect: true })\n  axis: string = 'horizontal';\n\n  @property({ type: Boolean, reflect: true })\n  flipped: boolean = false;\n\n  @property({ type: Boolean, attribute: 'flip-on-hover' })\n  flipOnHover: boolean = false;\n\n  @property({ type: String })\n  height: string = 'auto';\n\n  @property({ type: Boolean })\n  measure: boolean = false;\n\n  @query('[name=\"front\"]')\n  frontChildren: HTMLSlotElement;\n\n  @query('[name=\"back\"]')\n  backChildren: HTMLSlotElement;\n\n  @state()\n  frontElement: HTMLElement;\n\n  @state()\n  backElement: HTMLElement;\n\n  constructor() {\n    super();\n\n    this.addEventListener('kemet-flipped', () => {\n      this.flipped = !this.flipped;\n    });\n  }\n\n  firstUpdated() {\n    this.frontElement = this.querySelector('[slot=front]');\n    this.backElement = this.querySelector('[slot=back]');\n    window.addEventListener('resize', this.determineHeight.bind(this));\n  }\n\n  updated() {\n    this.determineHeight();\n  }\n\n  render() {\n    return html`\n      <section\n        tabindex=\"0\"\n        part=\"wrapper\"\n        @blur=${() => { if (this.flipOnHover) this.flipped = false; }}\n        @focus=${() => { if (this.flipOnHover) this.flipped = true; }}\n        @mouseover=${() => { if (this.flipOnHover) this.flipped = true; }}\n        @mouseout=${() => { if (this.flipOnHover) this.flipped = false; }}>\n        <div id=\"front\" class=\"front\" part=\"front\">\n          <slot name=\"front\" @slotchange=\"${() => this.determineHeight()}\"></slot>\n        </div>\n        <div id=\"back\" class=\"back\" part=\"back\">\n          <slot name=\"back\" @slotchange=\"${() => this.determineHeight()}\"></slot>\n        </div>\n      </section>\n    `;\n  }\n\n  determineHeight() {\n    // setTimeout is need to simulate a DOM repaint\n    // without the repaint, offsetHeight on Custom Elements = 0\n    // so this is needed for 'measure' to work correctly\n\n    setTimeout(() => {\n      if (this.measure) {\n        if (this.frontElement?.offsetHeight > this.backElement?.offsetHeight) {\n          this.height = `${this.frontElement?.offsetHeight}px`;\n        } else {\n          this.height = `${this.backElement?.offsetHeight}px`;\n        }\n\n        this.style.height = this.height;\n      } else {\n        this.style.removeProperty('height');\n      }\n    }, 0);\n  }\n}\n\ndeclare global {\n  interface HTMLElementTagNameMap {\n    'kemet-flipcard': KemetFlipcard\n  }\n}\n","import { css } from 'lit';\n\nexport const stylesBase = css`\n  *,\n  ::after,\n  ::before {\n    box-sizing: border-box;\n  }\n\n  :host {\n    --kemet-flipcard-width: 100%;\n    --kemet-flipcard-height: auto;\n    --kemet-flipcard-ratio: 16/9;\n    --kemet-flipcard-border-radius: 0;\n    --kemet-flipcard-border: 2px solid rgb(var(--kemet-color-primary));\n    --kemet-flipcard-front-color: rgb(var(--kemet-color-gray-950));\n    --kemet-flipcard-front-background-color: rgb(var(--kemet-color-gray-50));\n    --kemet-flipcard-back-color: rgb(var(--kemet-color-gray-950));\n    --kemet-flipcard-back-background-color: rgb(var(--kemet-color-gray-50));\n\n    display: inline-block;\n    width: var(--kemet-flipcard-width);\n    height: var(--kemet-flipcard-height);\n    aspect-ratio: var(--kemet-flipcard-ratio);\n    perspective: 1000px;\n  }\n\n  section {\n    position: relative;\n    width: 100%;\n    height: 100%;\n    transition: transform 0.8s;\n    transform-style: preserve-3d;\n  }\n\n  .front,\n  .back {\n    position: absolute;\n    display: flex;\n    width: 100%;\n    height: 100%;\n    backface-visibility: hidden;\n    /* overflow: hidden; */\n    border-radius: var(--kemet-flipcard-border-radius);\n    border: var(--kemet-flipcard-border);\n  }\n\n  :host([rounded]) .front,\n  :host([rounded]) .back {\n    border-radius: var(--kemet-border-radius-xl);\n  }\n\n  .front {\n    color: var(--kemet-flipcard-front-color);\n    background-color: var(--kemet-flipcard-front-background-color);\n  }\n\n  :host([flipped]) .front {\n    z-index: -1;\n  }\n\n  .back {\n    color: var(--kemet-flipcard-back-color);\n    background-color: var(--kemet-flipcard-back-background-color)\n  }\n\n  :host([axis=\"horizontal\"]) .back {\n    transform: rotateY(180deg);\n  }\n\n  :host([flipped][axis=\"horizontal\"]) section {\n    transform: rotateY(180deg);\n  }\n\n  :host([axis=\"vertical\"]) .back {\n    transform: rotateX(180deg);\n  }\n\n  :host([flipped][axis=\"vertical\"]) section {\n    transform: rotateX(180deg);\n  }\n\n  :host([flip-on-hover]) section {\n    cursor: pointer;\n  }\n\n  ::slotted([slot=\"front\"]),\n  ::slotted([slot=\"back\"]) {\n    display: inline-block;\n    margin: auto;\n    position: relative;\n    width: 100%;\n    height: 100%;\n  }\n`;\n"],"mappings":";;;;;AAAA,SAAS,MAAM,kBAAkB;AACjC;AAAA,EACE;AAAA,EAAe;AAAA,EAAU;AAAA,EAAO;AAAA,OAC3B;;;ACHP,SAAS,WAAW;AAEb,IAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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