/**
 * Copyright 2019 Penn State University
 * @license Apache-2.0, see License.md for full text.
 */
import{LitElement as t,html as e,css as o}from"../../../../lit/index.js";import{SimpleToolbarButtonBehaviors as r}from"../../../simple-toolbar/lib/simple-toolbar-button.js";import{RichTextEditorRangeBehaviors as i}from"../singletons/rich-text-editor-range-behaviors.js";import"../../../simple-icon/lib/simple-icon-lite.js";import"../../../simple-icon/lib/simple-icons.js";import"../../../simple-icon/lib/simple-icon-button-lite.js";import"../../../hax-iconset/lib/simple-hax-iconset.js";const a=[o`
    :host {
      height: var(--rich-text-editor-button-height, 32px);
      --simple-toolbar-border-color: var(--rich-text-editor-border-color, #ddd);
      --simple-toolbar-border-width: var(--rich-text-editor-border-width, 1px);
      --simple-toolbar-button-bg: var(--rich-text-editor-bg, #ffffff);
      --simple-fields-focus-color: var(--rich-text-editor-focus-color, blue);
      --simple-fields-invalid-color: var(--rich-text-editor-error-color, #800);
    }
  `],l=[...a,o`
    :host {
      --simple-toolbar-border-color: var(--rich-text-editor-border-color, #ddd);
      --simple-toolbar-border-width: var(--rich-text-editor-border-width, 1px);
      --simple-toolbar-button-opacity: var(
        --rich-text-editor-button-opacity,
        1
      );
      --simple-toolbar-button-color: var(--rich-text-editor-button-color, #444);
      --simple-toolbar-button-bg: var(--rich-text-editor-button-bg, #ffffff);
      --simple-toolbar-button-border-color: var(
        --rich-text-editor-button-border-color,
        transparent
      );
      --simple-toolbar-button-toggled-opacity: var(
        --rich-text-editor-button-toggled-opacity,
        1
      );
      --simple-toolbar-button-toggled-color: var(
        --rich-text-editor-button-toggled-color,
        #222
      );
      --simple-toolbar-button-toggled-bg: var(
        --rich-text-editor-button-toggled-bg,
        #ddd
      );
      --simple-toolbar-button-toggled-border-color: var(
        --rich-text-editor-button-toggled-border-color,
        transparent
      );
      --simple-toolbar-button-hover-opacity: var(
        --rich-text-editor-button-hover-opacity,
        1
      );
      --simple-toolbar-button-hover-color: var(
        --rich-text-editor-button-hover-color,
        #000
      );
      --simple-toolbar-button-hover-bg: var(
        --rich-text-editor-button-hover-bg,
        #f0f0f0
      );
      --simple-toolbar-button-hover-border-color: var(
        --rich-text-editor-button-hover-border-color,
        unset
      );
      --simple-toolbar-button-disabled-opacity: var(
        --rich-text-editor-button-disabled-opacity,
        1
      );
      --simple-toolbar-button-disabled-color: var(
        --rich-text-editor-button-disabled-color,
        #666
      );
      --simple-toolbar-button-disabled-bg: var(
        --rich-text-editor-button-disabled-bg,
        transparent
      );
      --simple-toolbar-button-disabled-border-color: var(
        --rich-text-editor-button-disabled-border-color,
        transparent
      );
    }
    button[part="button"] {
      border-radius: var(--rich-text-editor-button-disabled-border-radius, 0px);
    }
  `],RichTextEditorButtonBehaviors=function(t){return class extends(i(r(t))){static get tag(){return"rich-text-editor-button"}static get styles(){return[super.styles,...l]}render(){return super.render()}static get properties(){return{...super.properties,disabled:{type:Boolean,reflect:!0,attribute:"disabled"},command:{type:String,reflect:!0,attribute:"command"},commandVal:{attribute:"command-val",type:Object},tagsList:{type:String},target:{type:Object},toggledCommand:{attribute:"toggled-command",type:String,reflect:!0},toggledCommandVal:{attribute:"toggled-command-val",type:Object},selectedNode:{type:Object},selectionAncestors:{type:Array}}}constructor(){super(),this.tagsList=""}get isToggled(){return this.commandIsToggled}get operationCommand(){return this.isToggled&&this.toggledCommand?this.toggledCommand:this.command}get operationCommandVal(){return this.isToggled&&this.toggledCommand?this.toggledCommandVal||"":this.commandVal}get tagsArray(){return(this.tagsList||"").replace(/\s*/g,"").toLowerCase().split(",")}firstUpdated(t){super.firstUpdated&&super.firstUpdated(t)}updated(t){super.updated(t),t.forEach(((t,e)=>{"controls"===e&&this._editorChanged(this.controls,t),"range"===e&&this._rangeChanged(this.range,t),["shortcutKeys","tagsList","tagClickCallback"].includes(e)&&this.updateButtonRegistry()}))}connectedCallback(){super.connectedCallback()}connectedCallback(){super.connectedCallback()}disconnectedCallback(){super.disconnectedCallback()}commandCallback(t,e,o){}wrapSelection(t){this.dispatchEvent(new CustomEvent("wrapselection",{bubbles:!0,composed:!0,cancelable:!0,detail:t}))}sendCommand(t){this._handleCommand(this.operationCommand,this.operationCommandVal,this.range),this.commandCallback&&this.commandCallback(this.target,this.__toolbar,this),this.dispatchEvent(new CustomEvent("command",{bubbles:!0,cancelable:!0,composed:!0,detail:{command:this.operationCommand,commandVal:this.operationCommandVal,range:this.range,button:this}}))}setRange(){if(!this.tagsList||""===this.tagsList)return;let t=this.rangeOrMatchingAncestor();t&&this.selectNode(t)}_handleClick(t){t.preventDefault(),this.sendCommand(t)}_editorChanged(t,e){}_getSelection(){return"formatBlock"===this.command?this.rangeOrMatchingAncestor():this._getSelectedHtml()}_getSelectedHtml(){if(this.range){let t,e=globalThis.document.createElement("div"),o=this.range.cloneContents();return e.appendChild(o),t=e.innerHTML,e.remove(),t?t.trim():void 0}}_getSelectedTag(){let t=this.rangeOrMatchingAncestor();return!(!t||!t.tagName)&&t.tagName.toLowerCase()}_getSelectionType(){return"formatBlock"===this.command?this._getSelectedTag():this._getSelectedHtml()}_rangeChanged(t,e){}}};class RichTextEditorButton extends(RichTextEditorButtonBehaviors(t)){}customElements.define(RichTextEditorButton.tag,RichTextEditorButton);export{RichTextEditorButton,RichTextEditorButtonBehaviors,a as RichTextStyles,l as RichTextToolbarStyles};