{"mappings":"AACA,cAAc,sBAAiC;AAE/C,SAAS,mBAAgC;;;;;;AAWzC,cA6BM,eAAe,YAAY;CAC/B,UACU,OAAO;CAEjB,UAAU,UAAU,eAAe;CAcnC;CAKA,UAAU,cAAc,GAAG;;;;;;;;;;;CAgB3B,UAAU,eAAe,GAAG,aAAa;EACvC;EACA;;;AAaJ,eAAe;AACf,SAAS","names":[],"sources":["../../../../src/web-components/rotate/component.ts"],"sourcesContent":["import { godown, htmlSlot, styles } from \"@godown/element\";\nimport { type TemplateResult, css, html } from \"lit\";\n\nimport { GlobalStyle, scopePrefix } from \"../../internal/global-style.js\";\nimport { query } from \"lit/decorators.js\";\n\nconst protoName = \"rotate\";\nconst cssScope = scopePrefix(protoName);\n\n/**\n * {@linkcode Rotate} Make child elements rotate.\n *\n * @category wrapper\n */\n@godown(protoName)\n@styles(css`\n  :host {\n    display: block;\n    width: fit-content;\n    transition: all 0.5s ease-in-out;\n    ${cssScope}--offset: .5em;\n  }\n\n  div {\n    position: relative;\n    transition: inherit;\n    transition-property: transform;\n  }\n\n  i {\n    width: 100%;\n    height: 100%;\n    position: absolute;\n    top: 0;\n    box-sizing: content-box;\n    padding: var(${cssScope}--offset);\n    margin: calc(-1 * var(${cssScope}--offset));\n  }\n\n  [part=\"slot\"] {\n    z-index: 2;\n  }\n`)\nclass Rotate extends GlobalStyle {\n  @query(\"[part=root]\")\n  protected _root: HTMLElement;\n\n  protected render(): TemplateResult<1> {\n    return html`\n      <div part=\"root\">\n        <div\n          part=\"slot\"\n          @mousemove=\"${this._handleRotate}\"\n        >\n          ${htmlSlot()}\n        </div>\n        <i @mouseleave=\"${this.reset}\"></i>\n      </div>\n    `;\n  }\n\n  reset(): void {\n    this._root.style.removeProperty(\"transform\");\n    this._root.style.removeProperty(\"transition\");\n  }\n\n  protected _handleRotate(e: MouseEvent): void {\n    const { rotateX, rotateY } = this._computeOffset(e);\n    this._root.style.setProperty(\"transform\", `rotateX(${rotateX}rad) rotateY(${rotateY}rad)`);\n    this._root.style.setProperty(\"transition\", \"0s\");\n  }\n\n  /**\n   * Compute offset.\n   *\n   * @returns rotateX, rotateY\n   * @example\n   * ```ts\n   * const { rotateX, rotateY } = this._computeOffset(e);\n   * `rotateX(${rotateX}rad) rotateY(${rotateY}rad)`;\n   * ```\n   */\n  protected _computeOffset(e: MouseEvent): {\n    rotateX: number;\n    rotateY: number;\n  } {\n    const { left, top, width, height } = this._root.getBoundingClientRect();\n    const { clientX, clientY } = e;\n    const offsetX = clientX - left;\n    const offsetY = clientY - top;\n\n    const rotateX = -(offsetY - height / 2) / height / 2;\n    const rotateY = (offsetX - width / 2) / width / 2;\n    return { rotateX, rotateY };\n  }\n}\n\nexport default Rotate;\nexport { Rotate };\n"],"version":3,"file":"component.d.ts"}