{"mappings":"AAAA,cAAc,oBAAsC;AACpD,cAAc,sBAAiC;AAI/C,SAAS,mBAAmB;AAC5B,cAAiC,gBAAgB;AAkBjD,cACM,WAAW,oBAAoB,YAAY;CAC/C;CACA,AACA;CAEA,AACA,UAAU;CAEV,AACA;CAEA,AACA;CAEA,AACA;CAEA,AACA,OAAO;CAEP,IAAI,kBAAkB;;;;CAOtB,AACA;CAEA,UACU,QAAQ;;;;CAKlB;CAEA,IAAI,aAAa,cAAc,KAAK;CAIpC,IAAI,uBAJ2B,KAAK;CAQpC,UAAU;CAEV;CAIA;CAEA;CAKA,UAAU,aAAa,GAAG,aAAa;CASvC,UAAU,cAAc,GAAG,aAAa;CAIxC;CAKA,UAAU;CAKV,UAAU;CAUV,MAAM,UAAU;CAIhB,UAAU;CAIV,UAAU,iBAAiB,eAAe;CAM1C,UAAU,iBAAiB,eAAe;;AAO5C,eAAe;AACf,SAAS","names":[],"sources":["../../../src/internal/super-input.ts"],"sourcesContent":["import { type HandlerEvent, htmlSlot, styles } from \"@godown/element\";\nimport { type TemplateResult, css, html } from \"lit\";\nimport { property, query } from \"lit/decorators.js\";\nimport { omit } from \"sharekit\";\n\nimport { GlobalStyle } from \"./global-style.js\";\nimport { ringTypeAttribute, type RingType } from \"./ring.js\";\n\nconst inputStyle = css`\n  :host([disabled]) {\n    cursor: not-allowed;\n    filter: brightness(0.85);\n  }\n\n  input:disabled {\n    cursor: inherit;\n  }\n\n  input::-ms-reveal,\n  input::-ms-clear {\n    display: none;\n  }\n`;\n\n@styles(inputStyle)\nclass SuperInput<V = string> extends GlobalStyle {\n  autofocus = false;\n  @property()\n  autocomplete: string | boolean;\n\n  @property({ attribute: ringTypeAttribute })\n  ringType: RingType = \"border\";\n\n  @property({ type: Boolean, reflect: true })\n  disabled = false;\n\n  @property({ reflect: true })\n  placeholder: string;\n\n  @property({ reflect: true })\n  name: string;\n\n  @property()\n  value: V;\n\n  get observedRecord(): Record<string, any> {\n    return omit(super.observedRecord, \"default\", \"value\");\n  }\n\n  /**\n   * default property records the default or initial value and is used to reset the input.\n   */\n  @property()\n  default: any;\n\n  @query(\"[part=input]\")\n  protected _input: HTMLInputElement;\n\n  /**\n   * Returns true when the input is compositing.\n   */\n  compositing = false;\n\n  set defaultValue(value: typeof this.default) {\n    this.default = value;\n  }\n\n  get defaultValue() {\n    return this.default;\n  }\n\n  protected makeId: string = Math.random().toString(36).slice(1);\n\n  namevalue(): [string, any] {\n    return [this.name, this.value];\n  }\n\n  nameValue: () => [string, any] = this.namevalue;\n\n  reset(): void {\n    this.value = this.default;\n    this._input.value = this.default;\n  }\n\n  protected _handleInput(e: HandlerEvent<HTMLInputElement>): void {\n    e.stopPropagation();\n    if (this.compositing) {\n      return;\n    }\n    (this.value as string) = e.target.value?.trim();\n    this.dispatchCustomEvent(\"input\", this.value, { bubbles: true });\n  }\n\n  protected _handleChange(e: HandlerEvent<HTMLInputElement>): void {\n    this.dispatchCustomEvent(\"change\", this.value);\n  }\n\n  connectedCallback(): void {\n    super.connectedCallback();\n    this._connectedInit();\n  }\n\n  protected _connectedInit(): void {\n    this.default ??= this.value || \"\";\n    this.value ??= this.default;\n  }\n\n  protected _compositionInit(): void {\n    if (this._input) {\n      this.events.add(this._input, \"compositionstart\", () => (this.compositing = true));\n      this.events.add(this._input, \"compositionend\", (e: HandlerEvent<HTMLInputElement>) => {\n        this.compositing = false;\n        this._handleInput(e);\n      });\n    }\n  }\n\n  focus(options?: FocusOptions): void {\n    this._input?.focus(options);\n  }\n\n  protected firstUpdated(): void {\n    this._compositionInit();\n  }\n\n  protected _renderPrefix(): TemplateResult<1> {\n    return html`\n      <i part=\"prefix\">${htmlSlot(\"prefix\")}</i>\n    `;\n  }\n\n  protected _renderSuffix(): TemplateResult<1> {\n    return html`\n      <i part=\"suffix\">${htmlSlot(\"suffix\")}</i>\n    `;\n  }\n}\n\nexport default SuperInput;\nexport { SuperInput };\n"],"version":3,"file":"super-input.d.ts"}