(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".cdx-font-size{line-height:1.2}#editorjs-font-size-picker-wrapper{display:flex;align-items:center;gap:5px;padding:5px;margin:auto}#editorjs-font-size-picker{width:50px;height:20px;margin:0 5px;font-size:14px;padding:2px 5px;border:1px solid #ccc;border-radius:4px;text-align:center}#editorjs-font-size-picker::-webkit-outer-spin-button,#editorjs-font-size-picker::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}#editorjs-font-size-picker{-moz-appearance:textfield}.cdx-underline{text-decoration:underline}")),document.head.appendChild(e)}}catch(i){console.error("vite-plugin-css-injected-by-js",i)}})();
const c = '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 20 20"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.6" d="M13.3333 7.5L10 4.16667L6.66668 7.5"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.6" d="M13.3333 12.5L10 15.8333L6.66668 12.5"/></svg>', a = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M14.5 17.5L9.64142 12.6414C9.56331 12.5633 9.56331 12.4367 9.64142 12.3586L14.5 7.5"/></svg>', l = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M9.58284 17.5L14.4414 12.6414C14.5195 12.5633 14.5195 12.4367 14.4414 12.3586L9.58284 7.5"/></svg>', h = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M8 9V7.2C8 7.08954 8.08954 7 8.2 7L12 7M16 9V7.2C16 7.08954 15.9105 7 15.8 7L12 7M12 7L12 17M12 17H10M12 17H14"/></svg>', o = class o {
  /**
   * @param options InlineToolConstructorOptions
   */
  constructor(t) {
    this.tag = "SPAN", this.api = t.api, this.iconClasses = {
      base: this.api.styles.inlineToolButton,
      active: this.api.styles.inlineToolButtonActive
    };
  }
  /**
   * Class name for term-tag
   *
   * @type {string}
   */
  static get CSS() {
    return "cdx-font-size";
  }
  /**
   * Create button element for Toolbar
   *
   * @returns {HTMLElement}
   */
  render() {
    return this.button = document.createElement("button"), this.button.type = "button", this.button.classList.add(this.iconClasses.base), this.button.innerHTML = this.toolboxIcon, this.button;
  }
  /**
   * Create input element for Toolbar
   *
   * @returns {HTMLElement}
   */
  renderActions() {
    return this.sizePickerWrapper || (this.sizePickerWrapper = document.createElement("div"), this.sizePickerWrapper.id = "editorjs-font-size-picker-wrapper", this.sizePickerWrapper.appendChild(this.datalist()), this.sizePickerWrapper.appendChild(this.decrementButton()), this.sizePickerWrapper.appendChild(this.sizePickerInput()), this.sizePickerWrapper.appendChild(this.incrementButton())), this.sizePickerWrapper;
  }
  /**
   * datalist element
   *
   * @returns {HTMLDataListElement}
   */
  datalist() {
    const t = document.createElement("datalist");
    return t.id = "font-size-list", ["8", "9", "10", "11", "12", "14", "16", "18", "24", "30", "36", "48", "60", "72", "96"].forEach((e) => {
      const i = document.createElement("option");
      i.value = e, t.appendChild(i);
    }), t;
  }
  /**
   * size picker input
   *
   * @returns {HTMLInputElement}
   */
  sizePickerInput() {
    return this.sizePicker = document.createElement("input"), this.sizePicker.id = "editorjs-font-size-picker", this.sizePicker.type = "number", this.sizePicker.step = "1", this.sizePicker.setAttribute("list", "font-size-list"), this.sizePicker;
  }
  /**
   * decrement button
   *
   * @returns {HTMLButtonElement}
   */
  decrementButton() {
    const t = document.createElement("button");
    return t.type = "button", t.classList.add("cdx-settings-button"), t.innerHTML = this.decrementButtonIcon, t.onclick = () => {
      this.sizePicker.stepDown(), this.sizePicker.dispatchEvent(new Event("input"));
    }, t;
  }
  /**
   * increment button
   *
   * @returns {HTMLButtonElement}
   */
  incrementButton() {
    const t = document.createElement("button");
    return t.type = "button", t.classList.add("cdx-settings-button"), t.innerHTML = this.incrementButtonIcon, t.onclick = () => {
      this.sizePicker.stepUp(), this.sizePicker.dispatchEvent(new Event("input"));
    }, t;
  }
  /**
   * Wrap/Unwrap selected fragment
   *
   * @param {Range} range - selected fragment
   */
  surround(t) {
    if (!t)
      return;
    const e = this.api.selection.findParentTag(this.tag, o.CSS), i = e ? this.isSelectionExactlyNode(t, e) : !1;
    e && i ? this.unwrap(e) : this.wrap(t);
  }
  /**
   * Wrap selection with term-tag
   *
   * @param {Range} range - selected fragment
   */
  wrap(t) {
    const e = document.createElement(this.tag);
    e.classList.add(o.CSS);
    const i = t.extractContents();
    this.cleanupSelection(i), e.appendChild(i), t.insertNode(e), this.api.selection.expandToTag(e);
  }
  /**
   * Unwrap term-tag
   *
   * @param {HTMLElement} termWrapper - term wrapper tag
   */
  unwrap(t) {
    var n;
    this.api.selection.expandToTag(t);
    const e = window.getSelection();
    if (!e)
      return;
    const i = e.getRangeAt(0);
    if (!i)
      return;
    const s = i.extractContents();
    s && ((n = t.parentNode) == null || n.removeChild(t), i.insertNode(s), e.removeAllRanges(), e.addRange(i));
  }
  /**
   * Shows input element
   *
   * @returns {void}
   */
  showActions(t) {
    this.sizePicker && t && (this.sizePicker.oninput = () => {
      var e;
      t.style.fontSize = ((e = this.sizePicker) == null ? void 0 : e.value) + "px";
    }, this.sizePicker.setAttribute("value", t.style.fontSize.replace("px", "") || "16"));
  }
  /**
   * Hides input element
   *
   * @returns {void}
   */
  hideActions() {
    this.sizePicker && (this.sizePicker.oninput = null);
  }
  /**
   * Check and change Term's state for current selection
   */
  checkState(t) {
    const e = this.api.selection.findParentTag(this.tag, o.CSS);
    let i = !1;
    if (e && t.rangeCount > 0) {
      const s = t.getRangeAt(0);
      i = this.isSelectionExactlyNode(s, e);
    }
    return this.state = i, this.state ? this.showActions(e) : this.hideActions(), this.button && this.button.classList.toggle(this.iconClasses.active, this.state), this.state;
  }
  /**
   * remove term-tags within selected fragment
   *
   * @param {Node} node
   */
  cleanupSelection(t) {
    const e = document.createTreeWalker(t, NodeFilter.SHOW_ELEMENT, null);
    let i = e.currentNode;
    for (; i; ) {
      const s = i;
      if (s.nodeType === Node.ELEMENT_NODE && s.classList.contains(o.CSS)) {
        const n = s.parentNode;
        for (; s.firstChild; )
          n == null || n.insertBefore(s.firstChild, s);
        n == null || n.removeChild(s);
      }
      i = e.nextNode();
    }
  }
  /**
   * Check if selection exactly covers the node
   *
   * @param range - The selection range
   * @param node - The DOM node to compare against
   */
  isSelectionExactlyNode(t, e) {
    const i = document.createRange();
    return i.selectNodeContents(e), t.compareBoundaryPoints(Range.START_TO_START, i) === 0 && t.compareBoundaryPoints(Range.END_TO_END, i) === 0;
  }
  /**
   * Get Tool icon's SVG
   *
   * @returns {string}
   */
  get toolboxIcon() {
    return h + c;
  }
  /**
   * Get decrement button icon's SVG
   *
   * @returns {string}
   */
  get decrementButtonIcon() {
    return a;
  }
  /**
   * Get increment button icon's SVG
   *
   * @returns {string}
   */
  get incrementButtonIcon() {
    return l;
  }
  /**
   * Sanitizer rule
   *
   * @returns {{span: {class: string}}}
   */
  static get sanitize() {
    return {
      span: {
        class: o.CSS
      }
    };
  }
};
o.isInline = !0;
let r = o;
export {
  r as default
};
