/*!
 * TOAST UI Editor : Font Size Plugin
 * @version 1.0.0 | Wed Dec 30 2020
 * @author Chow Jia Ying <chowjiaying211@gmail.com>
 * @license MIT
 */
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ 		}
/******/ 	};
/******/
/******/ 	// define __esModule on exports
/******/ 	__webpack_require__.r = function(exports) {
/******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 		}
/******/ 		Object.defineProperty(exports, '__esModule', { value: true });
/******/ 	};
/******/
/******/ 	// create a fake namespace object
/******/ 	// mode & 1: value is a module id, require it
/******/ 	// mode & 2: merge all properties of value into the ns
/******/ 	// mode & 4: return value when already ns object
/******/ 	// mode & 8|1: behave like require
/******/ 	__webpack_require__.t = function(value, mode) {
/******/ 		if(mode & 1) value = __webpack_require__(value);
/******/ 		if(mode & 8) return value;
/******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ 		var ns = Object.create(null);
/******/ 		__webpack_require__.r(ns);
/******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ 		return ns;
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 3);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
/* harmony import */ var _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_0__);
// Imports

var ___CSS_LOADER_EXPORT___ = _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_0___default()(function(i){return i[1]});
// Module
___CSS_LOADER_EXPORT___.push([module.i, ".font-dropdown {\n  padding-inline-start: 0px;\n  margin-block-start: 0px;\n  margin-block-end: 0px;\n}\n\n.fontDropdownContainer {\n  width: auto !important;\n  position: absolute;\n}\n\ndiv.fontDropdownContainer > div.tui-popup-body {\n  padding: unset;\n}\n\nli.font-dropdown-option {\n  padding: 2.5px 17px;\n  list-style: none;\n}\n\nli.font-dropdown-option:hover {\n  background-color: #eee;\n}\n\n.tui-font-size {\n  width: 40px;\n  margin: 5px 3px;\n  line-height: 12px;\n  font-size: 11px;\n  min-height: 14px;\n}\n\n.highlighted {\n  background-color: #ACCEF7;\n  width: 'fit-content';\n}\n", ""]);
// Exports
/* harmony default export */ __webpack_exports__["a"] = (___CSS_LOADER_EXPORT___);


/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";


var isOldIE = function isOldIE() {
  var memo;
  return function memorize() {
    if (typeof memo === 'undefined') {
      // Test for IE <= 9 as proposed by Browserhacks
      // @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805
      // Tests for existence of standard globals is to allow style-loader
      // to operate correctly into non-standard environments
      // @see https://github.com/webpack-contrib/style-loader/issues/177
      memo = Boolean(window && document && document.all && !window.atob);
    }

    return memo;
  };
}();

var getTarget = function getTarget() {
  var memo = {};
  return function memorize(target) {
    if (typeof memo[target] === 'undefined') {
      var styleTarget = document.querySelector(target); // Special case to return head of iframe instead of iframe itself

      if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) {
        try {
          // This will throw an exception if access to iframe is blocked
          // due to cross-origin restrictions
          styleTarget = styleTarget.contentDocument.head;
        } catch (e) {
          // istanbul ignore next
          styleTarget = null;
        }
      }

      memo[target] = styleTarget;
    }

    return memo[target];
  };
}();

var stylesInDom = [];

function getIndexByIdentifier(identifier) {
  var result = -1;

  for (var i = 0; i < stylesInDom.length; i++) {
    if (stylesInDom[i].identifier === identifier) {
      result = i;
      break;
    }
  }

  return result;
}

function modulesToDom(list, options) {
  var idCountMap = {};
  var identifiers = [];

  for (var i = 0; i < list.length; i++) {
    var item = list[i];
    var id = options.base ? item[0] + options.base : item[0];
    var count = idCountMap[id] || 0;
    var identifier = "".concat(id, " ").concat(count);
    idCountMap[id] = count + 1;
    var index = getIndexByIdentifier(identifier);
    var obj = {
      css: item[1],
      media: item[2],
      sourceMap: item[3]
    };

    if (index !== -1) {
      stylesInDom[index].references++;
      stylesInDom[index].updater(obj);
    } else {
      stylesInDom.push({
        identifier: identifier,
        updater: addStyle(obj, options),
        references: 1
      });
    }

    identifiers.push(identifier);
  }

  return identifiers;
}

function insertStyleElement(options) {
  var style = document.createElement('style');
  var attributes = options.attributes || {};

  if (typeof attributes.nonce === 'undefined') {
    var nonce =  true ? __webpack_require__.nc : undefined;

    if (nonce) {
      attributes.nonce = nonce;
    }
  }

  Object.keys(attributes).forEach(function (key) {
    style.setAttribute(key, attributes[key]);
  });

  if (typeof options.insert === 'function') {
    options.insert(style);
  } else {
    var target = getTarget(options.insert || 'head');

    if (!target) {
      throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");
    }

    target.appendChild(style);
  }

  return style;
}

function removeStyleElement(style) {
  // istanbul ignore if
  if (style.parentNode === null) {
    return false;
  }

  style.parentNode.removeChild(style);
}
/* istanbul ignore next  */


var replaceText = function replaceText() {
  var textStore = [];
  return function replace(index, replacement) {
    textStore[index] = replacement;
    return textStore.filter(Boolean).join('\n');
  };
}();

function applyToSingletonTag(style, index, remove, obj) {
  var css = remove ? '' : obj.media ? "@media ".concat(obj.media, " {").concat(obj.css, "}") : obj.css; // For old IE

  /* istanbul ignore if  */

  if (style.styleSheet) {
    style.styleSheet.cssText = replaceText(index, css);
  } else {
    var cssNode = document.createTextNode(css);
    var childNodes = style.childNodes;

    if (childNodes[index]) {
      style.removeChild(childNodes[index]);
    }

    if (childNodes.length) {
      style.insertBefore(cssNode, childNodes[index]);
    } else {
      style.appendChild(cssNode);
    }
  }
}

function applyToTag(style, options, obj) {
  var css = obj.css;
  var media = obj.media;
  var sourceMap = obj.sourceMap;

  if (media) {
    style.setAttribute('media', media);
  } else {
    style.removeAttribute('media');
  }

  if (sourceMap && typeof btoa !== 'undefined') {
    css += "\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))), " */");
  } // For old IE

  /* istanbul ignore if  */


  if (style.styleSheet) {
    style.styleSheet.cssText = css;
  } else {
    while (style.firstChild) {
      style.removeChild(style.firstChild);
    }

    style.appendChild(document.createTextNode(css));
  }
}

var singleton = null;
var singletonCounter = 0;

function addStyle(obj, options) {
  var style;
  var update;
  var remove;

  if (options.singleton) {
    var styleIndex = singletonCounter++;
    style = singleton || (singleton = insertStyleElement(options));
    update = applyToSingletonTag.bind(null, style, styleIndex, false);
    remove = applyToSingletonTag.bind(null, style, styleIndex, true);
  } else {
    style = insertStyleElement(options);
    update = applyToTag.bind(null, style, options);

    remove = function remove() {
      removeStyleElement(style);
    };
  }

  update(obj);
  return function updateStyle(newObj) {
    if (newObj) {
      if (newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap) {
        return;
      }

      update(obj = newObj);
    } else {
      remove();
    }
  };
}

module.exports = function (list, options) {
  options = options || {}; // Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
  // tags it will allow on a page

  if (!options.singleton && typeof options.singleton !== 'boolean') {
    options.singleton = isOldIE();
  }

  list = list || [];
  var lastIdentifiers = modulesToDom(list, options);
  return function update(newList) {
    newList = newList || [];

    if (Object.prototype.toString.call(newList) !== '[object Array]') {
      return;
    }

    for (var i = 0; i < lastIdentifiers.length; i++) {
      var identifier = lastIdentifiers[i];
      var index = getIndexByIdentifier(identifier);
      stylesInDom[index].references--;
    }

    var newLastIdentifiers = modulesToDom(newList, options);

    for (var _i = 0; _i < lastIdentifiers.length; _i++) {
      var _identifier = lastIdentifiers[_i];

      var _index = getIndexByIdentifier(_identifier);

      if (stylesInDom[_index].references === 0) {
        stylesInDom[_index].updater();

        stylesInDom.splice(_index, 1);
      }
    }

    lastIdentifiers = newLastIdentifiers;
  };
};

/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";


/*
  MIT License http://www.opensource.org/licenses/mit-license.php
  Author Tobias Koppers @sokra
*/
// css base code, injected by the css-loader
// eslint-disable-next-line func-names
module.exports = function (cssWithMappingToString) {
  var list = []; // return the list of modules as css string

  list.toString = function toString() {
    return this.map(function (item) {
      var content = cssWithMappingToString(item);

      if (item[2]) {
        return "@media ".concat(item[2], " {").concat(content, "}");
      }

      return content;
    }).join('');
  }; // import a list of modules into the list
  // eslint-disable-next-line func-names


  list.i = function (modules, mediaQuery, dedupe) {
    if (typeof modules === 'string') {
      // eslint-disable-next-line no-param-reassign
      modules = [[null, modules, '']];
    }

    var alreadyImportedModules = {};

    if (dedupe) {
      for (var i = 0; i < this.length; i++) {
        // eslint-disable-next-line prefer-destructuring
        var id = this[i][0];

        if (id != null) {
          alreadyImportedModules[id] = true;
        }
      }
    }

    for (var _i = 0; _i < modules.length; _i++) {
      var item = [].concat(modules[_i]);

      if (dedupe && alreadyImportedModules[item[0]]) {
        // eslint-disable-next-line no-continue
        continue;
      }

      if (mediaQuery) {
        if (!item[2]) {
          item[2] = mediaQuery;
        } else {
          item[2] = "".concat(mediaQuery, " and ").concat(item[2]);
        }
      }

      list.push(item);
    }
  };

  return list;
};

/***/ }),
/* 3 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);

// EXPORTS
__webpack_require__.d(__webpack_exports__, "default", function() { return /* binding */ fontSizePlugin; });

// EXTERNAL MODULE: ./node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js
var injectStylesIntoStyleTag = __webpack_require__(1);
var injectStylesIntoStyleTag_default = /*#__PURE__*/__webpack_require__.n(injectStylesIntoStyleTag);

// EXTERNAL MODULE: ./node_modules/css-loader/dist/cjs.js!./src/index.css
var cjs_js_src = __webpack_require__(0);

// CONCATENATED MODULE: ./src/index.css

            

var options = {};

options.insert = "head";
options.singleton = false;

var update = injectStylesIntoStyleTag_default()(cjs_js_src["a" /* default */], options);



/* harmony default export */ var src = (cjs_js_src["a" /* default */].locals || {});
// CONCATENATED MODULE: ./src/helpers.js
/**
 * A helper method to set more than one CSS attribute for a JS element at once
 * @param {HTMLElement} element - the element to set attributes for
 * @param {Object} attributes - an object containing CSS properties to value mappings
 */
function setAttributes(element, attributes) {
  for (const prop in attributes) {
    element.setAttribute(prop, attributes[prop]);
  }
}
// CONCATENATED MODULE: ./src/index.js


/**
 * @fileoverview Code for the font size plugin
 * @author Chow Jia Ying <chowjiaying211@gmail.com>
 *
 * This is a plugin to adjust the font size of a block of text in both the Markdown and WYSIWYG versions.
 *
 */

const fontStyleRegex = /style="font-size: \d+px"/g;
/**
 * Apply CSS styling to text to give the impression of the text being selected
 * @param {Editor} editor - instance of Editor
 * @param {boolean} toHighlight - indicates if the highlight style is to be added or removed
 */

function applyHighlightStyle(editor, toHighlight) {
  const sq = editor.getSquire();
  const range = sq.getSelection();
  const highlightStyle = {
    tag: "SPAN",
    attributes: {
      class: "highlighted"
    }
  };

  if (toHighlight) {
    sq.changeFormat(highlightStyle, null, range);
  } else {
    sq.changeFormat(null, highlightStyle, range);
  }
}
/**
 * Renders a list of font sizes for users to choose from
 * @param {Editor} editor - instance of Editor or Viewer
 */


function initDropdown(editor) {
  const dropdownContainer = document.createElement("div");
  const dropdown = document.createElement("ul");
  dropdown.classList.add("font-dropdown");
  const fontSizeValues = [5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72];
  fontSizeValues.forEach(fontSize => {
    const option = document.createElement("li");
    option.classList.add("font-dropdown-option");
    option.textContent = fontSize;
    option.value = fontSize; // program what happens when option is clicked

    option.addEventListener("click", () => {
      editor.exec("changeFontSize", fontSize); // emit change font size event
    });
    dropdown.appendChild(option);
  });
  dropdownContainer.appendChild(dropdown);
  const popup = editor.getUI().createPopup({
    header: false,
    title: null,
    content: dropdownContainer,
    className: "fontDropdownContainer",
    target: editor.getUI().getToolbar().el
  });
  return popup;
}
/**
 * Renders an input for users to change font sizes
 * @param {Editor} editor
 */


function initFontSizeInput(editor) {
  const toolbar = editor.getUI().getToolbar();
  const fontSizeInput = document.createElement("input");
  fontSizeInput.classList.add("tui-font-size");
  toolbar.insertItem(-1, {
    type: "divider"
  });
  toolbar.insertItem(-2, {
    type: "button",
    options: {
      name: "fontSizePlugin",
      event: "showDropdown",
      tooltip: "Font Size",
      el: fontSizeInput
    }
  });
  setAttributes(fontSizeInput, {
    type: "number",
    value: "12"
  });
  return fontSizeInput;
}
/**
 * Initialise UI rendering logic
 * @param {Editor} editor - instance of editor
 * @param {HTMLInputElement} fontSizeInput - HTMLInputElement to enter font sizes
 * @param {HTMLDivElement} dropdown - dropdown of font sizes
 */


function initUIEvents(editor, fontSizeInput, dropdown) {
  fontSizeInput.addEventListener("change", event => {
    const fontSize = parseInt(event.target.value, 10);

    if (isNaN(fontSize) || fontSize <= 0) {
      return;
    }

    editor.exec("changeFontSize", fontSize);
  });
  editor.eventManager.addEventType("showDropdown");
  editor.eventManager.addEventType("hideDropdown");
  editor.eventManager.listen("showDropdown", () => {
    if (dropdown.isShow()) {
      dropdown.hide();
      return;
    }

    const {
      offsetLeft,
      offsetTop,
      offsetHeight
    } = fontSizeInput;
    dropdown.el.setAttribute("style", `top: ${offsetTop + offsetHeight}px; left: ${offsetLeft}px`);
    dropdown.show();
    applyHighlightStyle(editor, true);
  });
  editor.eventManager.listen("hideDropdown", () => {
    dropdown.hide();
  });
}
/**
 * Renders the UI of the editor
 * @param {Editor|Viewer} editor - instance of Editor or Viewer
 */


function initUI(editor) {
  return {
    fontSizeInput: initFontSizeInput(editor),
    dropdown: initDropdown(editor)
  };
}
/**
 * Apply <span> tags around text to style text in Markdown mode
 * @param {string} text - text to add HTML tags to
 */


function applyFontSizeHTMLTag(text, fontSize) {
  const fontStyleApplied = text.match(fontStyleRegex);

  if (fontStyleApplied) {
    const result = text.replace(fontStyleRegex, `style="font-size: ${fontSize}px"`);
    return {
      result,
      to: result.length
    };
  }

  const result = `<span class="size" style="font-size: ${fontSize}px">${text}</span>`;
  return {
    result,
    to: result.length
  };
}
/**
 * Font size plugin
 * Some code was modified from https://github.com/nhn/tui.editor/blob/master/plugins/color-syntax/src/js/index.js to learn how to make use of the TUI Editor's API to create the plugin
 * @param {Editor|Viewer} editor - instance of Editor or Viewer
 */


function fontSizePlugin(editor) {
  const {
    fontSizeInput,
    dropdown
  } = initUI(editor);
  initUIEvents(editor, fontSizeInput, dropdown); // add commands for editor

  editor.addCommand("markdown", {
    name: "changeFontSize",

    exec(md, fontSize) {
      // replace selected text
      const cm = md.getEditor();
      const rangeFrom = md.getCursor("from");
      const rangeTo = md.getCursor("to");
      const selectedText = cm.getSelection();
      const {
        result,
        to
      } = applyFontSizeHTMLTag(selectedText, fontSize);
      cm.replaceSelection(result); // move cursor

      const newStart = {
        line: rangeFrom.line,
        ch: rangeFrom.ch
      };
      const newEnd = {
        line: rangeTo.line,
        ch: rangeFrom.line === rangeTo.line ? rangeTo.ch + to : to
      };
      cm.setSelection(newStart, newEnd);
      fontSizeInput.value = fontSize;
      editor.eventManager.emit("hideDropdown");
      md.focus();
    }

  });
  editor.addCommand("wysiwyg", {
    name: "changeFontSize",

    // sets font size and applies highlighting style
    exec(wwe, fontSize) {
      const sq = wwe.getEditor();
      const tableSelectionManager = wwe.componentManager.getManager("tableSelection");

      if (sq.hasFormat("table") && tableSelectionManager.getSelectedCells().length) {
        tableSelectionManager.styleToSelectedCells((squire, fontSizeValue) => {
          squire.setFontSize(`${fontSizeValue}px`);
        }, fontSize);
        const range = sq.getSelection();
        range.collapse(true);
        sq.setSelection(range);
      } else {
        sq.setFontSize(`${fontSize}px`);
      }

      fontSizeInput.value = fontSize;
      applyHighlightStyle(editor, false);
      editor.eventManager.emit("hideDropdown");
    }

  });
}

/***/ })
/******/ ])["default"];