UNPKG

editorjs-inline-font-family-tool

Version:
1 lines 15.8 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.FontFamilyTool=e():t.FontFamilyTool=e()}(window,(function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(o,i,function(e){return t[e]}.bind(null,i));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="/",n(n.s=0)}([function(t,e,n){function o(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return i(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return i(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,l=!0,s=!1;return{s:function(){n=t[Symbol.iterator]()},n:function(){var t=n.next();return l=t.done,t},e:function(t){s=!0,a=t},f:function(){try{l||null==n.return||n.return()}finally{if(s)throw a}}}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n<e;n++)o[n]=t[n];return o}function r(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function a(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}function l(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}n(1).toString();var s=["Arial","Arial Black","Arial Narrow","Arial Rounded MT Bold","Avant Garde","Baskerville","Bodoni MT","Book Antiqua","Big Caslon","Calibri","Calisto MT","Cambria","Candara","Century Gothic","Charcoal","Copperplate","Comic Sans MS","Courier New","Didot","Franklin Gothic Medium","Futura","Geneva","Gill Sans","Garamond","Georgia","Goudy Old Style","Hoefler Text","Helvetica","Helvetica Neue","Impact","Lucida Sans Unicode","Lato","Lucida Grande","Lucida Bright","Monaco","Optima","Papyrus","PT Mono","Palatino","Perpetua","Rockwell","Roboto","Rockwell Extra Bold","Segoe UI","Tahoma","Times New Roman","Trebuchet MS","Verdana"],c=function(){function t(e){var n=this,o=e.api,i=e.config;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),l(this,"isDropDownOpen",!1),l(this,"emptyString","&nbsp;&nbsp"),l(this,"fontFamilyDropDown","fontFamilyDropDown"),l(this,"fontFamilyBtn","fontFamilyBtn"),l(this,"commandName","fontName"),l(this,"CSS",{button:"ce-inline-tool",buttonActive:"ce-font-family-tool--active",buttonModifier:"ce-inline-tool--font"}),l(this,"selectedFontFamily",null),l(this,"nodes",{button:void 0}),l(this,"selectionList",void 0),l(this,"buttonWrapperText",void 0),l(this,"togglingCallback",null),l(this,"toggleFontFamilySelector",(function(t){n.selectedFontFamily=t.target.innerHTML,n.toggle()})),l(this,"toggleDropDown",(function(t){t.target.id!==n.fontFamilyDropDown&&t.target.parentNode.id!==n.fontFamilyBtn&&t.target.id!==n.fontFamilyBtn||n.toggle((function(t){t&&(n.isDropDownOpen=!0)}))})),this.api=o,this.config=i}return a(t,null,[{key:"isInline",get:function(){return!0}},{key:"sanitize",get:function(){return{font:{size:!0,face:!0}}}}]),a(t,[{key:"createButton",value:function(){this.nodes.button=document.createElement("button"),this.nodes.button.type="button",this.nodes.button.classList.add(this.CSS.button,this.CSS.buttonModifier),this.nodes.button.setAttribute("id",this.fontFamilyBtn),this.getFontFamilyForButton(),this.nodes.button.appendChild(this.svg("toggler-down",13,13))}},{key:"getFontFamilyForButton",value:function(){this.buttonWrapperText=document.createElement("div"),this.buttonWrapperText.classList.add("button-wrapper-text-font-family");var t=document.createElement("div");t.classList.add("selected-font-family"),t.setAttribute("id",this.fontFamilyDropDown),t.innerHTML=this.emptyString,this.buttonWrapperText.append(t),this.nodes.button.append(this.buttonWrapperText)}},{key:"addFontFamilyOptions",value:function(){var t=this;this.selectionList=document.createElement("div"),this.selectionList.setAttribute("class","selectionList-font-family");var e=document.createElement("div");e.setAttribute("class","selection-list-wrapper-font");var n,i=o(this.config.fontFamilyList?this.config.fontFamilyList:s);try{for(i.s();!(n=i.n()).done;){var r=n.value,a=document.createElement("div");a.setAttribute("value",r),a.setAttribute("style","font-family:".concat(r)),a.setAttribute("title",r),a.classList.add("selection-list-option"),document.getElementById(this.fontFamilyDropDown).innerHTML!==r&&this.selectedFontFamily!==r||a.classList.add("selection-list-option-active"),a.innerHTML=r,e.append(a)}}catch(t){i.e(t)}finally{i.f()}this.selectionList.append(e),this.nodes.button.append(this.selectionList),this.selectionList.addEventListener("click",this.toggleFontFamilySelector),setTimeout((function(){"function"==typeof t.togglingCallback&&t.togglingCallback(!0)}),50)}},{key:"removeFontOptions",value:function(){this.selectionList&&(this.isDropDownOpen=!1,this.selectionList=this.selectionList.remove()),"function"==typeof this.togglingCallback&&this.togglingCallback(!1)}},{key:"render",value:function(){return this.createButton(),this.nodes.button.addEventListener("click",this.toggleDropDown),this.nodes.button}},{key:"toggle",value:function(t){!this.isDropDownOpen&&t?this.addFontFamilyOptions():this.removeFontOptions(),"function"==typeof t&&(this.togglingCallback=t)}},{key:"surround",value:function(t){this.selectedFontFamily&&document.execCommand(this.commandName,!1,this.selectedFontFamily)}},{key:"getComputedFontFamilyStyle",value:function(t){return window.getComputedStyle(t.parentElement,null).getPropertyValue("font-family")}},{key:"checkState",value:function(t){var e=document.queryCommandState(this.commandName),n=this.getComputedFontFamilyStyle(t.anchorNode);if(n===this.getComputedFontFamilyStyle(t.focusNode)){if('"'===n.slice(0,1))n=n.slice(1,-1);else if("-"===n.slice(0,1)){var o=n.slice(n.indexOf('"')+1,n.indexOf('"',n.indexOf('"')+1));n=o}else-1!==n.indexOf(",")&&(n=n.slice(0,n.indexOf(",")));this.replaceFontSizeInWrapper(n)}else{var i=this.emptyString;this.replaceFontSizeInWrapper(i)}return e}},{key:"replaceFontSizeInWrapper",value:function(t){document.getElementById(this.fontFamilyDropDown).innerHTML=t}},{key:"clear",value:function(){this.toggle(),this.selectedFontFamily=null}},{key:"svg",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:14,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:14,o=document.createElementNS("http://www.w3.org/2000/svg","svg");return o.classList.add("icon","icon--"+t),o.setAttribute("width",e+"px"),o.setAttribute("height",n+"px"),o.innerHTML='<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#'.concat(t,'"></use>'),o}}]),t}();l(c,"title","Font Family"),t.exports=c},function(t,e,n){var o=n(2);"string"==typeof o&&(o=[[t.i,o,""]]);var i={hmr:!0,transform:void 0,insertInto:void 0};n(4)(o,i);o.locals&&(t.exports=o.locals)},function(t,e,n){(t.exports=n(3)(!1)).push([t.i,".ce-inline-tool.ce-inline-tool--font {\n display: flex;\n flex-direction: row;\n position: relative;\n }\n \n .ce-inline-tool.ce-inline-tool--font .button-wrapper-text-font-family {\n width: 80px;\n padding-right: 5px;\n }\n \n .ce-inline-tool.ce-inline-tool--font .button-wrapper-text-font-family .selected-font-family {\n width: 80px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n \n .ce-inline-tool.ce-inline-tool--font .selectionList-font-family {\n position: absolute;\n top: 35px;\n left: 0;\n max-height: 300px;\n overflow: auto;\n }\n \n .ce-inline-tool.ce-inline-tool--font .selectionList-font-family .selection-list-wrapper {\n width: 50px;\n background: #fff;\n border: 1px solid #eaeaea;\n }\n \n .ce-inline-tool.ce-inline-tool--font .selectionList-font-family .selection-list-wrapper-font {\n background: #fff;\n border: 1px solid #eaeaea;\n }\n \n .ce-inline-tool.ce-inline-tool--font .selectionList-font-family .selection-list-wrapper-font .selection-list-option {\n padding: 5px;\n border-bottom: 1px solid #eaeaea;\n width: 140px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n \n .ce-inline-tool.ce-inline-tool--font .selectionList-font-family .selection-list-wrapper-font .selection-list-option-active {\n background-color: #eff2f5;\n }\n \n .ce-inline-tool.ce-inline-tool--font .selectionList-font-family .selection-list-wrapper-font .selection-list-option:hover {\n background-color: #eff2f5;\n }",""])},function(t,e){t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var n=function(t,e){var n=t[1]||"",o=t[3];if(!o)return n;if(e&&"function"==typeof btoa){var i=(a=o,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(a))))+" */"),r=o.sources.map((function(t){return"/*# sourceURL="+o.sourceRoot+t+" */"}));return[n].concat(r).concat([i]).join("\n")}var a;return[n].join("\n")}(e,t);return e[2]?"@media "+e[2]+"{"+n+"}":n})).join("")},e.i=function(t,n){"string"==typeof t&&(t=[[null,t,""]]);for(var o={},i=0;i<this.length;i++){var r=this[i][0];"number"==typeof r&&(o[r]=!0)}for(i=0;i<t.length;i++){var a=t[i];"number"==typeof a[0]&&o[a[0]]||(n&&!a[2]?a[2]=n:n&&(a[2]="("+a[2]+") and ("+n+")"),e.push(a))}},e}},function(t,e,n){var o,i,r={},a=(o=function(){return window&&document&&document.all&&!window.atob},function(){return void 0===i&&(i=o.apply(this,arguments)),i}),l=function(t){return document.querySelector(t)},s=function(t){var e={};return function(t){if("function"==typeof t)return t();if(void 0===e[t]){var n=l.call(this,t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(t){n=null}e[t]=n}return e[t]}}(),c=null,u=0,f=[],p=n(5);function d(t,e){for(var n=0;n<t.length;n++){var o=t[n],i=r[o.id];if(i){i.refs++;for(var a=0;a<i.parts.length;a++)i.parts[a](o.parts[a]);for(;a<o.parts.length;a++)i.parts.push(g(o.parts[a],e))}else{var l=[];for(a=0;a<o.parts.length;a++)l.push(g(o.parts[a],e));r[o.id]={id:o.id,refs:1,parts:l}}}}function h(t,e){for(var n=[],o={},i=0;i<t.length;i++){var r=t[i],a=e.base?r[0]+e.base:r[0],l={css:r[1],media:r[2],sourceMap:r[3]};o[a]?o[a].parts.push(l):n.push(o[a]={id:a,parts:[l]})}return n}function m(t,e){var n=s(t.insertInto);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");var o=f[f.length-1];if("top"===t.insertAt)o?o.nextSibling?n.insertBefore(e,o.nextSibling):n.appendChild(e):n.insertBefore(e,n.firstChild),f.push(e);else if("bottom"===t.insertAt)n.appendChild(e);else{if("object"!=typeof t.insertAt||!t.insertAt.before)throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");var i=s(t.insertInto+" "+t.insertAt.before);n.insertBefore(e,i)}}function y(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t);var e=f.indexOf(t);e>=0&&f.splice(e,1)}function v(t){var e=document.createElement("style");return void 0===t.attrs.type&&(t.attrs.type="text/css"),b(e,t.attrs),m(t,e),e}function b(t,e){Object.keys(e).forEach((function(n){t.setAttribute(n,e[n])}))}function g(t,e){var n,o,i,r;if(e.transform&&t.css){if(!(r=e.transform(t.css)))return function(){};t.css=r}if(e.singleton){var a=u++;n=c||(c=v(e)),o=F.bind(null,n,a,!1),i=F.bind(null,n,a,!0)}else t.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(t){var e=document.createElement("link");return void 0===t.attrs.type&&(t.attrs.type="text/css"),t.attrs.rel="stylesheet",b(e,t.attrs),m(t,e),e}(e),o=S.bind(null,n,e),i=function(){y(n),n.href&&URL.revokeObjectURL(n.href)}):(n=v(e),o=L.bind(null,n),i=function(){y(n)});return o(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;o(t=e)}else i()}}t.exports=function(t,e){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(e=e||{}).attrs="object"==typeof e.attrs?e.attrs:{},e.singleton||"boolean"==typeof e.singleton||(e.singleton=a()),e.insertInto||(e.insertInto="head"),e.insertAt||(e.insertAt="bottom");var n=h(t,e);return d(n,e),function(t){for(var o=[],i=0;i<n.length;i++){var a=n[i];(l=r[a.id]).refs--,o.push(l)}t&&d(h(t,e),e);for(i=0;i<o.length;i++){var l;if(0===(l=o[i]).refs){for(var s=0;s<l.parts.length;s++)l.parts[s]();delete r[l.id]}}}};var w,x=(w=[],function(t,e){return w[t]=e,w.filter(Boolean).join("\n")});function F(t,e,n,o){var i=n?"":o.css;if(t.styleSheet)t.styleSheet.cssText=x(e,i);else{var r=document.createTextNode(i),a=t.childNodes;a[e]&&t.removeChild(a[e]),a.length?t.insertBefore(r,a[e]):t.appendChild(r)}}function L(t,e){var n=e.css,o=e.media;if(o&&t.setAttribute("media",o),t.styleSheet)t.styleSheet.cssText=n;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(n))}}function S(t,e,n){var o=n.css,i=n.sourceMap,r=void 0===e.convertToAbsoluteUrls&&i;(e.convertToAbsoluteUrls||r)&&(o=p(o)),i&&(o+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(i))))+" */");var a=new Blob([o],{type:"text/css"}),l=t.href;t.href=URL.createObjectURL(a),l&&URL.revokeObjectURL(l)}},function(t,e){t.exports=function(t){var e="undefined"!=typeof window&&window.location;if(!e)throw new Error("fixUrls requires window.location");if(!t||"string"!=typeof t)return t;var n=e.protocol+"//"+e.host,o=n+e.pathname.replace(/\/[^\/]*$/,"/");return t.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,(function(t,e){var i,r=e.trim().replace(/^"(.*)"$/,(function(t,e){return e})).replace(/^'(.*)'$/,(function(t,e){return e}));return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(r)?t:(i=0===r.indexOf("//")?r:0===r.indexOf("/")?n+r:o+r.replace(/^\.\//,""),"url("+JSON.stringify(i)+")")}))}}])}));