var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _PlayResizableTextInput_instances, _PlayResizableTextInput_onInput, _PlayResizableTextInput_resizeInput;
import { LitElement, css, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { Bubble } from '../bubble.js';
/** @fires {string} edit-text */
let PlayResizableTextInput = class PlayResizableTextInput extends LitElement {
    constructor() {
        super(...arguments);
        _PlayResizableTextInput_instances.add(this);
        this.text = '';
        this.placeholder = '';
    }
    render() {
        return html `
      <div>
        <input
          type="text"
          placeholder=${this.placeholder}
          .value=${this.text}
          @input=${__classPrivateFieldGet(this, _PlayResizableTextInput_instances, "m", _PlayResizableTextInput_onInput)}
        />
        <div class="label" aria-hidden="true">${this.text}</div>
      </div>
    `;
    }
    updated(props) {
        super.updated(props);
        __classPrivateFieldGet(this, _PlayResizableTextInput_instances, "m", _PlayResizableTextInput_resizeInput).call(this, this.shadowRoot?.querySelector('input'));
    }
};
_PlayResizableTextInput_instances = new WeakSet();
_PlayResizableTextInput_onInput = function _PlayResizableTextInput_onInput(ev) {
    this.dispatchEvent(Bubble('edit-text', ev.currentTarget.value));
};
_PlayResizableTextInput_resizeInput = function _PlayResizableTextInput_resizeInput(input) {
    const span = globalThis.document.createElement('span');
    span.innerText = this.text || this.placeholder;
    span.style.visibility = 'hidden';
    span.style.whiteSpace = 'pre';
    span.style.fontFamily = 'inherit';
    span.style.fontSize = '24px';
    span.style.fontStyle = 'normal';
    span.style.fontWeight = '400';
    globalThis.document.body.appendChild(span);
    input.style.maxWidth = `${span.offsetWidth}px`;
    globalThis.document.body.removeChild(span);
};
PlayResizableTextInput.styles = css `
    :host {
      position: relative;
      width: 100%;
      flex-shrink: 1;
      font-family: inherit;
      font-size: 24px;
      font-style: normal;
      font-weight: 400;
      line-height: 28px;
    }

    .label {
      position: absolute;
      top: 0;
      left: 0;
      pointer-events: none;
      user-select: none;
      text-overflow: ellipsis;
      white-space: pre;
      overflow-x: clip;
    }

    input {
      font: inherit;
      line-height: inherit;
      margin: 0;
      color: transparent;
      background-color: transparent;
      border: none;
      border-radius: 4px;
      caret-color: var(--color-brand-background);
    }

    input,
    .label {
      width: 100%;
      padding-top: 2px;
      padding-right: 8px;
      padding-bottom: 2px;
      padding-left: 8px;
    }

    input::placeholder {
      color: var(--color-neutral-content-weak);
    }

    input:focus,
    input:focus:hover {
      outline-width: 2px;
      outline-style: solid;
      outline-color: var(--color-brand-background);
      color: var(--color-secondary-plain);
    }

    input:focus + .label {
      display: none;
    }

    input:hover {
      outline-width: 1px;
      outline-style: solid;
      outline-color: var(--color-neutral-border);
    }

    input::selection {
      color: var(--color-brand-foreground);
      background-color: var(--color-brand-background);
    }
  `;
__decorate([
    property({ attribute: false })
], PlayResizableTextInput.prototype, "text", void 0);
__decorate([
    property()
], PlayResizableTextInput.prototype, "placeholder", void 0);
PlayResizableTextInput = __decorate([
    customElement('play-resizable-text-input')
], PlayResizableTextInput);
export { PlayResizableTextInput };
//# sourceMappingURL=play-resizable-text-input.js.map