UNPKG

wysiwyg4all

Version:

Free opensource minimal WYSIWYG editor for web developers

2 lines 72.4 kB
/*! For license information please see wysiwyg4all.js.LICENSE.txt */ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(self,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Wysiwyg4All:()=>o});const n={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",goldenrod:"#daa520",gold:"#ffd700",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavenderblush:"#fff0f5",lavender:"#e6e6fa",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};class i{constructor(e="#4848db",t=!0){this.fineTuned=t;let n=this._colorType(e);this.type=n.type,this.color=n.color}_colorType(e=this.color,t=!0){let i,o;try{if(!e)throw"invalid color";if("object"==typeof e&&e.string&&(e=e.string),"string"!=typeof e)throw"invalid color";if((e=e.toLowerCase())===this.color)return{type:this.type,color:this.color};if(n[e])return{type:"hex",color:n[e]};if(i=e.match(/^(rgba?|rgb?|hsla?|#)/g),Array.isArray(i)){if("#"===i[0]){if(4===e.length&&(e=e[0]+e[1]+e[1]+e[2]+e[2]+e[3]+e[3]),!/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e))throw"invalid hex";o="hex"}else")"===e[e.length-1]&&(o=i[0]);return{type:o,color:e}}}catch(n){if(t)throw n+":"+e}return{}}_extractDigit(e=this.color){let{type:t=this.type,color:n=this.color}=this._colorType(e);"hex"===t&&(n=this.rgba(1,n).string);const i=[];for(const e of n.match(/\d+(\.\d+)?/g))i.push(parseFloat(e));return i.length<4&&i.push(1),i}getAlpha(e=this.color){let t=this._extractDigit(e);return t&&t[3]||1}colorScheme(e=this.color,t=!1){let n,i,o={black:.88,white:1},s={"--background":t?"#121212":"#f7f7f7","--content":t?"#2b2b2b":"#ffffff"},l=this.isHighLuminance(s["--content"]),u=(()=>{if(e&&"object"==typeof e){if(e["--button"])return n=e["--button"],n;for(let t of e)if(t.includes("focus"))return n=e[t],n}return n=e,i=this.matchLuminance(e,s["--content"],l?1.5:4.5),t?i:e})(),r=1,a=(()=>{let e=this.analogous(n,30),t=this.hsla(1,n).h,i=this.hsla(1,e[0]).h,o=this.hsla(1,e[1]).h;return t+30>360&&(i+=360),t-30<0&&(o=360-o),Math.abs(t-i)>Math.abs(t-o)?(r=-1,e[1]):e[0]})(),h=this.matchLuminance(this.complementary(u,60*r),s["--background"],3.1),c={"--placeholder":t?"rgba(255, 255, 255, 0.55)":"rgba(0, 0, 0, 0.44)"},d=t?this.matchLuminance(a,s["--background"],4.5):a,f=this.matchLuminance(a,s["--background"],4.5);for(let e in s)s[e+"-text"]=this.textColor(o,s[e]),s[e+"-focus"]=e.includes("--background")?d:u,s[e+"-text_focus"]=e.includes("--background")?f:this.matchLuminance(t?u:i,s[e],1.66),s[e+"-focus-text"]=this.textColor(1,e.includes("--background")?d:u);if(s["--focus"]=n,s["--focus-text"]=this.textColor(1,n),s["--saturate"]=i,s["--saturate-text"]=this.textColor(1,i),Object.assign(s,{"--complementary":h,"--complementary-text":this.textColor(1,h),"--analogous":a,"--analogous-text":this.textColor(1,a),"--alert":"tomato","--success":"limegreen","--button":u,"--text-button":t?this.matchLuminance(i,s["--content"],7):this.contrastRatio(s["--content"],i)<4.5?"inherit":i,"--button-text":this.textColor(1,u)}),e&&"object"==typeof e){for(let t of e)if("-"!==t[0])throw"invalid color scheme";Object.assign(s,e)}let g=Object.assign(s,c);return Object.keys(g).sort().reduce(((e,t)=>(e[t]=g[t],e)),{})}matchLuminance(e,t=this.color,n,i,o){let{color:s}=this._colorType(t),l=this._colorType(e).color;if(n){let e=l,t=this.contrastRatio(e,s);if(t<n){let l=i||this.isHighLuminance(s)?-1:1,u=100;for(;t<n&&u--;){let n;switch(o){case"brightness":n=this.adjustBrightness(1*l,e);break;case"luminance":n=this.adjustLuminance(1*l,e);break;default:n=this.adjustBrightness(1*l,{legacy:!0,color:e})}if(e===n)break;e=n,t=this.contrastRatio(e,s)}}return this.hex(e)}{let e=this._luminance(s),t=this._luminance(l);if(Math.abs(t-e)<.01)return l;let n=this.hex(l),i=(e,t)=>e<t?1:-1,u=i(t,e);for(;Math.abs(t-e)>.01&&u===i(t,e);){let s;switch(o){case"saturation":s=this.adjustBrightness(u,{color:n,legacy:!0});break;case"luminance":s=this.adjustLuminance(u,n);break;default:s=this.adjustBrightness(u,n)}let l=this._luminance(s);if(l===t||u!==i(l,e))break;t=l,n=s}return this.hex(n)}}analogous(e=this.color,t=30){let{color:n}=this._colorType(e),i=(e,t)=>{let n=e+t;return n<0?360+n:n>360?n-360:n},o=this.hsla(this.getAlpha(n),n),s="hsla("+i(o.h,t)+", "+o.s+"%, "+o.l+"%, "+o.a+")",l="hsla("+i(o.h,-t)+", "+o.s+"%, "+o.l+"%, "+o.a+")";return[this.matchLuminance(s,n),this.matchLuminance(l,n)]}complementary(e=this.color,t=0){let{color:n}=this._colorType(e),i=this.hsla(this.getAlpha(n),n);return i.h<180?i.h+=180:i.h-=180,i.h+=t,i.h=i.h>360?i.h-360:i.h<0?360-i.h:i.h,this.hex(this._toString(i))}isHighLuminance(e=this.color,t=this.fineTuned){const{r:n,g:i,b:o}=this.rgba(1,this._colorType(e).color);return(t?(235*n+733.75*i+114*o)/1e3:(299*n+587*i+114*o)/1e3)>=(t?188:128)}_luminance(e=this.color){let t=this.rgba(1,e),n=[t.r,t.g,t.b].map((function(e){return(e/=255)<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}));return.2126*n[0]+.7152*n[1]+.0722*n[2]}_toString(e){let t=(e,t=100)=>"number"==typeof e?e:t;if("string"==typeof e)return e;if(e.hasOwnProperty("h"))return"hsla("+(e.h||0)+", "+t(e.s)+"%, "+t(e.l)+"%, "+t(e.a,1)+")";if(e.hasOwnProperty("r"))return"rgba("+t(e.r)+", "+t(e.g)+", "+t(e.b)+", "+t(e.a,1)+")";throw e}contrastRatio(e,t=this.color){let n=this._luminance(t)+.05,i=this._luminance(e)+.05;return n>i?n/i:i/n}textColor(e=1,t=this.color){"string"==typeof t&&(t={color:t});let n,i,{color:o=this.color,fineTuned:s=!0}=t;if(o=this._colorType(o).color,this.getAlpha(o)<.5)return"";if("number"==typeof e&&e<1)n=e,i=e;else if(e&&"object"==typeof e)for(let t of["black","white"]){let o=e[t];"number"==typeof o&&o<1&&("black"===t?n=o:"white"===t&&(i=o))}const l=e=>"number"==typeof e?e<1&&e>0?e:e>1?1:0:1;return this.isHighLuminance(o,s)?n?`rgba(0, 0, 0, ${l(n)})`:"black":i?`rgba(255, 255, 255, ${l(i)})`:"white"}hsla(e,t=this.color){const{type:n=this.type,color:i=this.color}=this._colorType(t),o=(e,t,n)=>{e/=255,t/=255,n/=255;let i=Math.min(e,t,n),o=Math.max(e,t,n),s=o-i,l=0,u=0,r=0;return l=0===s?0:o===e?(t-n)/s%6:o===t?(n-e)/s+2:(e-t)/s+4,l=Math.round(60*l),l<0&&(l+=360),r=(o+i)/2,u=0===s?0:s/(1-Math.abs(2*r-1)),u=+(100*u).toFixed(1),r=+(100*r).toFixed(1),{h:l,s:u,l:r}};if("hex"===n){e="number"==typeof e?e:1;const t=this.rgba(e,i),{r:n,g:s,b:l,a:u}=t,{h:r,s:a,l:h}=o(n,s,l);return{r:n,g:s,b:l,a:u,h:r,s:a,l:h,string:this._toString({h:r,s:a,l:h,a:e})}}{const t=this._extractDigit(i);if(e="number"==typeof e?e:t[3]||1,n.includes("hsl")){const{r:n,g:o,b:s,a:l}=this.rgba(e,i);return{r:n,g:o,b:s,a:l,h:t[0],s:t[1],l:t[2],string:this._toString({h:t[0],s:t[1],l:t[2],a:l})}}if(n.includes("rgb")){const n={r:t[0],g:t[1],b:t[2],a:e},{h:i,s,l}=o(n.r,n.g,n.b);return Object.assign(n,{r:n.r,g:n.g,b:n.b,h:i,s,l,a:n.a,string:this._toString({h:i,s,l,a:n.a})})}}}hex(e=this.color){const{type:t=this.type,color:n=this.color}=this._colorType(e);if(t.includes("rgb")||t.includes("hsl")){const e=this.rgba(1,n);return"#"+((1<<24)+(e.r<<16)+(e.g<<8)+e.b).toString(16).slice(1)}return n}rgba(e,t=this.color){const{type:n=this.type,color:i=this.color}=this._colorType(t);if("hex"===n){const t=i;let n={r:null,g:null,b:null},o=t.match(/[a-fA-F0-9]{2}/g);4===t.length&&(o=t.match(/[a-fA-F0-9]{1}/g),o=o.map((e=>""+e+e)));let s=0;for(const e in n)n[e]=parseInt(o[s],16),s++;const l="number"==typeof e?e:1;let{r:u,g:r,b:a}=n;return{...n,a:l,string:this._toString({r:+u,g:+r,b:+a,a:l})}}{const t=this._extractDigit(i),o="number"==typeof e?e:t[3]||1;if(n.includes("rgb")){let e={r:t[0],g:t[1],b:t[2],a:o};return Object.assign({string:this._toString(e)},e)}if(n.includes("hsl")){let e=t[0],n=t[1],i=t[2];n/=100,i/=100;let s=(1-Math.abs(2*i-1))*n,l=s*(1-Math.abs(e/60%2-1)),u=i-s/2,r=0,a=0,h=0;return 0<=e&&e<60?(r=s,a=l,h=0):60<=e&&e<120?(r=l,a=s,h=0):120<=e&&e<180?(r=0,a=s,h=l):180<=e&&e<240?(r=0,a=l,h=s):240<=e&&e<300?(r=l,a=0,h=s):300<=e&&e<360&&(r=s,a=0,h=l),r=Math.round(255*(r+u)),a=Math.round(255*(a+u)),h=Math.round(255*(h+u)),{r,g:a,b:h,a:o,string:this._toString({r,g:a,b:h,a:o})}}}}adjustBrightness(e=0,t=this.color){let n,i=!1;if("string"==typeof t?n=t||this.color:(n=t.color||this.color,i=t.legacy||!1),i){let{color:t}=this._colorType(n),i=this.hsla(this.getAlpha(t),t),o=(e,t=100)=>e>t?t:e<0?0:e;return i.s+=(e>0?100-i.s:i.s)/100*e,i.s=o(i.s),i.l+=(e>0?100-i.l:i.l)/100*e,i.l=o(i.l),this._toString(i)}let{type:o=this.type,color:s=this.color}=this._colorType(n);if(0===e)return s;const l="hex"===o?1:this._extractDigit(s)[3]||1,u=this.rgba(l,s);let r={r:0-u.r,g:0-u.g,b:0-u.b};e>0&&Object.keys(r).map((function(e){r[e]=255-u[e]})),["r","g","b"].map((function(t){u[t]+=parseInt(r[t]/100*Math.abs(e))}));const a="rgb("+u.r+", "+u.g+", "+u.b+")";return"hex"===o?this.hex(a):o.includes("rgb")?this.rgba(u.a,a).string:o.includes("hsl")?this.hsla(u.a,a).string:void 0}adjustLuminance(e=0,t=this.color){let{color:n}=this._colorType(t),i=this.hsla(this.getAlpha(n),n);return i.l+=(e>0?100-i.l:i.l)/100*e,i.l=((e,t=100)=>e>t?t:e<0?0:e)(i.l),this._toString(i)}adjustSaturation(e=0,t=this.color){let{color:n}=this._colorType(t),i=this.hsla(this.getAlpha(n),n);return i.s+=(e>0?100-i.s:i.s)/100*e,i.s=((e,t=100)=>e>t?t:e<0?0:e)(i.s),this._toString(i)}}class o{constructor(e){console.log("Wysiwyg4All 1.0.72"),this.hashtag_regex=/#[\u0041-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC\w-]+(?:\+[\w-]+)*/g,this.hashtag_stopper_regex=/[^\u0041-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0\u08A2-\u08AC\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097F\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191C\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA697\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA793\uA7A0-\uA7AA\uA7F8-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA80-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC\w-]/g,this.urllink_regex=/(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gi;let{elementId:t="",editable:n=!0,placeholder:o="",spellcheck:s=!1,highlightColor:l="teal",html:u="",callback:r,fontSize:a={desktop:"18px",tablet:"16px",phone:"14px",h1:4.2,h2:3.56,h3:2.92,h4:2.28,h5:1.64,h6:1.15,small:.8},lastLineBlank:h=!1,hashtag:c=!1,urllink:d=!1,logMutation:f=!1,logExecution:g=!1}=e;if(this.hashtag=c,this.urllink=d,this.logMutation=f,this.logExecution=g,this.fontSizeCssVariable={},"number"==typeof a)this.fontSizeCssVariable={"--wysiwyg-font-desktop":`${a}`,"--wysiwyg-font-tablet":`${a}`,"--wysiwyg-font-phone":`${a}`};else if("object"==typeof a&&Object.keys(a).length){let e,t=["desktop","tablet","phone"];for(let n of t)a[n]&&(e=a[n],"number"==typeof e&&(e=`${e}px`)),this.fontSizeCssVariable[`--wysiwyg-font-${n}`]=`${e}`}if(!t||"string"!=typeof t)throw new Error("The wysiwyg element should have an ID");if(t="#"===t[0]?t.substring(1):t,this.html=u,this.elementId="#"===t[0]?t.substring(1):t,this.placeholder=o,this.spellcheck=s,this.lastLineBlank=h,"string"==typeof l&&(l=new i(l).color),this.colorScheme=l,this.callback=r||null,this.image_array=[],this.hashtag_array=[],this.urllink_array=[],this.custom_array=[],this.blockElement_queryArray=["HR","BLOCKQUOTE","UL","OL","._media_","._custom_"],this.specialTextElement_queryArray=["._hashtag_","._urllink_"],this.restrictedElement_queryArray=["._media_"],this.textAreaElement_queryArray=["BLOCKQUOTE","LI"],this.textBlockElement_queryArray=["P","LI","TD","TH","TR"],this.ceilingElement_queryArray=["UL","OL","LI","BLOCKQUOTE",`#${t}`],this.unSelectable_queryArray=["._media_","._hashtag_","._urllink_","HR"],this.needSafeGuard=["._media_","._custom_","._hashtag_","._urllink_","HR","UL","OL","BLOCKQUOTE"],this.styleAllowedElement_queryArray=["._backgroundColor","._color","._hashtag_","._urllink_","TD","TH","TR",`#${t}`],this.alignClass=["_alignCenter_","_alignRight_"],this.hashtag_flag=!1,this.urllink_flag=!1,this.range_backup=null,this.commandTracker={},this.range=null,this.isRangeDirectionForward=!0,this.insertTabPending_tabString="",this.removeSandwichedLine_array=[],this.lastKey=null,this.element=document.getElementById(this.elementId),!this.element)throw`element #${this.elementId} is null`;this.element.innerHTML="",this.cssVariable=(new i).colorScheme(this.colorScheme),Object.assign(this.cssVariable,this.fontSizeCssVariable);for(const e in this.cssVariable)this.element.style.setProperty(e,this.cssVariable[e]);this.elementComputedStyle=window.getComputedStyle(this.element),this.defaultFontColor=new i(this.cssVariable["--content-text"]).hex(),this.defaultBackgroundColor=new i(this.cssVariable["--content"]).hex(),this.highlightColor=new i(this.cssVariable["--content-focus"]).hex(),this.element.classList.contains("_wysiwyg4all")||this.element.classList.add("_wysiwyg4all"),this.setPlaceholder(this.placeholder),this.setSpellcheck(this.spellcheck);let m=this.elementComputedStyle.paddingBottom,p=this.elementComputedStyle.paddingTop,A=this.elementComputedStyle.borderTopWidth,_=this.elementComputedStyle.borderBottomWidth;this.element.style.minHeight=`calc(${m} + ${p} + ${A} + ${_} + 1.6em)`;const C={h1:["_h1","fontSize",["_small","_h2","_h3","_h4","_h5","_h6"]],h2:["_h2","fontSize",["_small","_h1","_h3","_h4","_h5","_h6"]],h3:["_h3","fontSize",["_small","_h1","_h2","_h4","_h5","_h6"]],h4:["_h4","fontSize",["_small","_h1","_h2","_h3","_h5","_h6"]],h5:["_h5","fontSize",["_small","_h1","_h2","_h3","_h4","_h6"]],h6:["_h6","fontSize",["_small","_h1","_h2","_h3","_h4","_h5"]],italic:["_i","fontStyle"],small:["_small","fontSize",["_h1","_h2","_h3","_h4","_h5","_h6","_b"]],bold:["_b","fontWeight",["_small"]],underline:["_u","textDecoration",["_del"]],strike:["_del","textDecoration",["_u"]],color:["_color","color"],backgroundColor:["_backgroundColor","backgroundColor"]},y={h1:a.h1||4.2,h2:a.h2||3.56,h3:a.h3||2.92,h4:a.h4||2.28,h5:a.h5||1.64,h6:a.h6||1.15,small:a.small||.8};for(const[e,t]of Object.entries(y))if("number"==typeof t)this.element.style.setProperty(`--wysiwyg-${e}`,`calc(var(--wysiwyg-font) * ${t})`);else if("string"==typeof t)if(t.includes("px"))this.element.style.setProperty(`--wysiwyg-${e}`,t);else if(t.includes("em")||t.includes("rem")){let n=parseFloat(t);n>0&&this.element.style.setProperty(`--wysiwyg-${e}`,`calc(var(--wysiwyg-font) * ${n})`)}this.styleTagOfCommand={},this.counterTagOf={},this.cssPropertyOf={},this.cssPropertyChecker={textDecoration:e=>e.includes("underline")?"underline":!!e.includes("line-through")&&"strike",fontSize:e=>{let t=parseFloat(this.elementComputedStyle.fontSize),n=parseFloat(e);for(let i in y){let o=y[i];if("number"==typeof o){let e=t*o;if(e+.01>n&&e-.01<n)return i}else if("string"==typeof o)if(o.includes("px")){if(e===o)return i}else if(o.includes("em")||o.includes("rem")){let e=parseFloat(o);if(e>0){let o=t*e;if(o+.01>n&&o-.01<n)return i}}}return!1},fontStyle:e=>!!e.includes("italic")&&"italic"};for(let e in C)this.commandTracker[e]=!1,this.styleTagOfCommand[e]=C[e][0],this.cssPropertyOf[C[e][0]]=C[e][1],this.cssPropertyChecker.hasOwnProperty(C[e][1])||(this.cssPropertyChecker[C[e][1]]=e),C[e][2]&&(this.counterTagOf[C[e][0]]=C[e][2]);this.loadHTML(this.html,n).catch((e=>{throw e}))}_adjustSelection(e,t=this.ceilingElement_queryArray){this.logExecution&&console.log("_adjustSelection()",{target:e,ceilingElement_query:t});let n,i=(e,t=!1)=>Array.isArray(e)?e:"string"==typeof e&&e||"number"==typeof e||"boolean"==typeof e||t&&"object"==typeof e?[e]:[],o=!!e,{node:s=null,position:l=!0}=e||{},u=window.getSelection();if(!u)return null;try{n=u.getRangeAt(0)}catch(e){o&&(n=document.createRange())}if(o){s=i(s,!0),l=i(l,!0);for(let e of l)if("number"!=typeof e&&"boolean"!=typeof e&&null!==e)throw"INVALID_POSITION";for(let e of s)if(!(e instanceof Node)&&null!==e){if(!1===e)return;throw"INVALID_NODE"}const e=(e,t)=>{if(e instanceof Node){if(1===e.nodeType){if("boolean"==typeof t)for(;!1===t?e.lastChild:e.firstChild;)e=!1===t?e.lastChild:e.firstChild;else if("number"==typeof t){let n=0;if(this._nodeCrawler((i=>{if(3===i.nodeType&&i.textContent.length){let o=i.textContent.length;if("false"===i.parentNode.getAttribute("contenteditable"))return t-(n+o)>=0?(n+=o,i):(t=o,"BREAK");if(e=i,!(t-(n+o)>=0))return t-=n,"BREAK";n+=o}return i}),{node:e}),1===e.nodeType){let n=document.createTextNode("​");e.insertBefore(n,e.childNodes[0]),e=n,t=0}}"BR"===e.nodeName&&e.parentNode.childNodes.length>1&&(e=e.previousSibling||e)}return t="boolean"==typeof t?t?0:e.textContent.length:t>e.textContent.length?e.textContent.length:t,{node:e,position:t}}};let t,o=!1,r=(s[0]=null===s[0]?n.startContainer:s[0],l[0]=null===l[0]?n.startOffset:l[0],e(s[0],l[0]));n.setStart(r.node,r.position),l.length>1?t=e((null===s[1]?n.endContainer:s[1])||s[0],null===l[1]?n.endOffset:l[1]):(t=r,o=!0),n.setEnd(t.node,t.position),o&&n.collapse(!0),u.removeAllRanges(),u.addRange(n)}if(t&&n){let e,i;for(let o of t){if(e&&i)break;let t=3===n.endContainer.nodeType?n.endContainer.parentNode:n.endContainer,s=3===n.startContainer.nodeType?n.startContainer.parentNode:n.startContainer;!e&&s.closest(o)&&(e=this._climbUpToEldestParent(s,s.closest(o))),!i&&t.closest(o)&&(i=this._climbUpToEldestParent(t,t.closest(o)))}n.startLine=e,n.endLine=i}return n}_generateId(e){this.logExecution&&console.log("_generateId()",{option:e});let t=12,n="";"number"==typeof e?t=e:"string"==typeof e&&(n=`${e}_`);let i="";for(let e=0;e<t-6;e++)i+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".charAt(Math.floor(51*Math.random()));return n+(new Date).getTime().toString().substring(7,13)+i}_nodeCrawler(e,t){this.logExecution&&console.log("_nodeCrawler()",{run:e,option:t});const{parentNode:n,node:i,startFromEldestChild:o,startNode:s}=t;if(o&&!n)throw new Error("Need parentNode to crawl up single child");if(!i||!(i instanceof Node||i?.commonAncestorContainer))throw new Error("No node to crawl");let l,u,r,a=[],h=!!i.commonAncestorContainer,c=null;if(n&&n instanceof Node&&1===n?.nodeType&&(l=n),h?(c=i.commonAncestorContainer,c=3===c.nodeType&&c.parentNode||c):c=i,o&&(c=this._climbUpToEldestParent(c,n,!0)),l)for(;3===c.nodeType||c!==l&&c.parentNode&&c.parentNode!==l;)c=c.parentNode;if(3===c.nodeType)return a.push(e(c)),{nodes:a,commonContainer:c};1===c.nodeType&&(r=c.id||(()=>(u=this._generateId("crawl"),c.id=u,u))());let d=(s instanceof Node?s:null)||(h?i.startContainer:c.childNodes[0]),f=h?i.endContainer:c.childNodes[c.childNodes.length?c.childNodes.length-1:0],g=e=>!!(e&&e instanceof Node)&&(1!==e.nodeType||e.id!==r&&e.parentNode?.closest("#"+r));for(;g(d);)if(1===d.nodeType&&d.childNodes.length)d=d.childNodes[0];else if(d){if("function"==typeof e&&(d=e(d)),"BREAK"===d||!g(d))break;if(a.push(d),d===f)break;let t=!1;for(;!d.nextSibling&&d.parentNode&&g(d.parentNode);)if(d=d.parentNode,d){if("function"==typeof e&&(d=e(d)),"BREAK"===d||!g(d)){t=!0;break}d&&a.push(d)}if(t)break;d=d.nextSibling}return u&&c.removeAttribute("id"),{node:a,commonContainer:c}}_wrapNode(e,t,n=!1){if(this.logExecution&&console.log("_wrapNode()",{node:e,wrapper:t,appendWhole:n}),!(e instanceof Node))return;if(!e.parentNode)throw new Error("can't unwrap document fragment");let i=window.getSelection().getRangeAt(0),o=null,s=i.startOffset,l=null,u=i.endOffset;const r=e=>{i.startContainer===e&&(o=e),i.endContainer===e&&(l=e)};if(1===e.nodeType?this._nodeCrawler((e=>(r(e),e)),{node:e}):r(e),t&&e.parentNode.insertBefore(t,e),3===e.nodeType){if(!t)throw new Error("no wrapper for text content");t.append(e)}else if(n)t.append(e);else for(;e.childNodes[0];){let n=e.childNodes[0];t?t.append(n):e.parentNode.insertBefore(n,e)}let a;if(1===e.nodeType&&!n){let n=(t||e).parentNode;a=e.previousSibling,n.removeChild(e)}return(a||e).textContent&&(o||l)&&(i=o&&o===l&&s===u?this._adjustSelection({node:a||e,position:s}):this._adjustSelection({node:[o,l],position:[s,u]})),this.range=i,{node:a||e,range:i}}_climbUpToEldestParent(e,t,n=!1,i){if(this.logExecution&&console.log("_climbUpToEldestParent()",{node:e,wrapper:t,singleChildParent:n,callback:i}),i=i||(e=>e),!(t instanceof Node)||3===t?.nodeType)throw new Error("invalid wrapper node");let o,s=t.id||(()=>(o=this._generateId("eldest"),t.id=o,o))();function l(e){if(!e||3===e.nodeType)return!1;let t=e?.children?.length;return 0===t||(()=>{let t=e.childNodes.length,n=0,i=!1;for(;t--;){let o=e.childNodes[t];if(3===o.nodeType&&o.textContent.length>0&&"​"!==o.textContent?i=!0:1===o.nodeType&&"BR"!==o.nodeName&&n++,n>1&&!i||n&&i)return!1}return!0})()}for(;e?.id!==s&&e.parentNode&&e.parentNode.closest("#"+s)&&e.parentNode.id!==s&&(!n||l(e?.parentNode));){let t=i(e.parentNode);if(!t||"BREAK"===t)break;e=t}return o&&t.removeAttribute("id"),e}_getStartEndLine(e=this.range,t=this.element,n=!1){if(this.logExecution&&console.log("_getStartEndLine()",{range:e,element:t}),!e)return[null,null,null];let i=this._climbUpToEldestParent(e.startContainer,t),o=this._climbUpToEldestParent(e.endContainer,t),s=[];if(n){let e=i.nextSibling;for(;e&&e!==o;)1===e.nodeType&&this.blockElement_queryArray.some((t=>e.matches(this._classNameToQuery(t))))&&s.push(e),e=e.nextSibling}return this.logExecution&&console.log("startLine | endLine",{startLine:i,endLine:o,inBetween:s}),[i,o,s]}_isThereContentEditableOverMyHead(e,t=this.element){if(e&&e!==this.element){let t=e;for(;t&&this.element!==t;){if("true"===t.getAttribute("contenteditable"))return!0;if("false"===t.getAttribute("contenteditable"))return!1;t=t.parentNode}}return!0}_isSelectionWithinRestrictedRange(e=this.range,t=this.element){if(!e)return this.logExecution&&console.log("_isSelectionWithinRestrictedRange():true",{range:e,element:t}),!0;let{commonAncestorContainer:n,startContainer:i,endContainer:o}=e,s=this.restrictedElement_queryArray,[l,u,r]=this._getStartEndLine(e,t,!0);if(l===u){n=3===n.nodeType?n.parentNode:n;for(let e of s)if(n.closest(this._classNameToQuery(e))&&!this._isThereContentEditableOverMyHead(n,t))return!0}else if(r?.length)for(let e=0;e<r.length;e++)for(let t of s)if(r[e].closest(this._classNameToQuery(t))&&!this._isThereContentEditableOverMyHead(r[e]))return!0;return!1}_classNameToQuery(e){return this.logExecution&&console.log("_classNameToQuery()",{q:e}),e.includes("_stop")&&"."!==e[0]||"_"===e[0]?"."+e:e}_createEmptyParagraph(e){this.logExecution&&console.log("_createEmptyParagraph()",{append:e});let t=document.createElement("p");return e&&"string"==typeof e&&(e=document.createTextNode(e)),t.append(e||document.createTextNode("")),e||t.append(document.createElement("br")),t}_trackStyle(e,t){this.logExecution&&console.log("_trackStyle()",{n:e,cls:t});let n={},o=window.getComputedStyle(e);for(let t of this.alignClass)e.closest("."+t)&&(n[t.substring(1,t.length-1)]=!0);let s=s=>{let l=this.cssPropertyChecker[s];if("function"==typeof l){if(l=l(o[s]),l){if(t)return l;n[l]=!0}}else if("color"===s&&o[s]){let e="#"===o[s][0]?o[s]:new i(o[s]).hex();if(e!==this.defaultFontColor){if(t)return e;n[l]=e}}else if("backgroundColor"===s&&o[s]){let e=null;if("#"===o[s][0])e=o[s];else{let t=o[s].split(",");if(4===t.length&&"0)"===t[t.length-1].trim())return!1;e=new i(o[s]).hex()}if(e&&e!==this.defaultBackgroundColor){if(t)return e;n[l]=e}}else if(o[s]!==this.elementComputedStyle[s]&&this._isTextElement(e)){if(t)return!0;n[l]=!0}return!1};if(t)return s(this.cssPropertyOf[t]);for(let e in this.cssPropertyChecker)s(e);return n}_lastLineBlank(e){if(this.logExecution&&console.log("_lastLineBlank()",{force:e}),this.lastLineBlank||e){let e=this.element.lastChild;("P"!==e.nodeName||"P"===e.nodeName&&e.textContent&&"​"!==e.textContent)&&this.element.append(this._createEmptyParagraph())}}_setEventListener(e){if(this.logExecution&&console.log("_setEventListener()",{listen:e}),document.removeEventListener("selectionchange",this._selectionchange),this.imgInput=null,!e)return;let t=document.createElement("input");for(const[e,n]of Object.entries({id:this._generateId("imageInput"),type:"file",accept:"image/gif,image/png,image/jpeg,image/webp",hidden:!0,multiple:!0}))t.setAttribute(e,n);this.imgInput=t,this.imgInput.addEventListener("change",(e=>{this._imageSelected(e).catch((e=>{console.error(e)}))})),this._keydown=function(e){this._isSelectionWithinRestrictedRange()?this.logExecution&&console.log("_keydown(): restricted range",{e}):this._modifySelection((()=>{if(!this.range)return;let{startContainer:t,startOffset:n,collapsed:i,startLine:o,endLine:s}=this.range,l=e.key.toUpperCase(),u=e.shiftKey;if(this.lastKey=l,"ENTER"===l&&e.shiftKey)this.range.endLine.closest("LI")||e.preventDefault();else if(["BACKSPACE","DELETE"].includes(l)){if(this.isRangeDirectionForward=!0,this.logExecution&&console.log("_keydown(): delete key",{e}),!this.element.textContent&&this.element.childNodes.length<=1&&this._isTextElement(this.element.childNodes[0])&&this.element.childNodes[0]===o)return this.logExecution&&console.log("_keydown(): delete key","nothing to delete"),void e.preventDefault();if(1===this.element.childNodes.length&&this._isTextBlockElement(this.element.childNodes[0])&&0===this.element.childNodes[0].textContent.length)return this.logExecution&&console.log("_keydown(): delete key","dead end"),e.preventDefault(),this.element.childNodes[0].innerHTML="<p><br></p>",this.range=this._adjustSelection({node:this.element.childNodes[0],position:0}),void this._lastLineBlank(!0);let t=this.range.startContainer;if(this.range.collapsed){let n=(3===t.nodeType?t.parentNode:t).closest("blockquote");if(n&&n.childNodes[0]===this._climbUpToEldestParent(t,n)&&0===this.range.startOffset)return this.logExecution&&console.log("_keydown(): delete key","block is empty and the cursor is on the first offset position within the blockquote"),e.preventDefault(),void this.command("quote");if(0===this.range.startOffset){this.logExecution&&console.log("_keydown(): delete key","this.range.startOffset === 0");let e=this._climbUpToEldestParent(t,this.element),n=e?.previousSibling;n&&"false"===n.getAttribute("contenteditable")&&n.remove()}return}}else if("#"!==l||this.hashtag_flag)if(![":","/","."].includes(l)||this.urllink_flag){if((this.hashtag_flag||this.urllink_flag)&&([" ","ENTER","TAB"].includes(l)||l.includes("ARROW"))&&this._replaceText(),u){if("PAGEUP"===l||"HOME"===l)return void(this.isRangeDirectionForward=!1);if("PAGEDOWN"===l||"END"===l)return void(this.isRangeDirectionForward=!0)}if(!l.includes("ARROW"))if("TAB"!==l){if("ENTER"===l&&"\t"===s.textContent[0])for(let e of s.textContent){if("\t"!==e)break;this.insertTabPending_tabString+="\t"}this.isRangeDirectionForward=!0}else{this.isRangeDirectionForward=!0,e.preventDefault();let l=[];if(!i){let e=o;for(;e&&e!==s;)l.push(e),e=e.nextSibling;l.push(s)}if(u){let e=!1,i=t=>{for(;t.childNodes[0];){for(t=t.childNodes[0];3===t.nodeType&&!t.textContent;)t=t.nextSibling;if(3===t.nodeType&&"\t"===t.textContent[0]){e=!0,t.textContent=t.textContent.substring(1);break}}};if(l.length){for(let e of l)"\t"===e.textContent[0]&&i(e);e&&this._adjustSelection({node:[o,s],position:[!0,!1]})}else if("\t"===o.textContent[0]){let s=((e,t,n)=>(e===t||this._nodeCrawler((e=>t===e?"BREAK":(3===e.nodeType&&e.textContent.length&&(n+=e.textContent.length),e)),{node:e}),n))(o,t,n)-1;s=s<0?0:s,i(o),e&&this._adjustSelection({node:o,position:s})}}else if(l.length){let e=!1;for(let t of l){e=!0;let n=document.createTextNode("\t");t.insertBefore(n,t.childNodes[0])}e&&this._adjustSelection({node:[o,s],position:[!0,!1]})}else{let e=document.createTextNode("\t");this.range.insertNode(e),this._adjustSelection({node:e,position:!1})}}}else this.urllink_flag=!0;else this.hashtag_flag=!0}))}.bind(this),this._normalize=function(e){this._modifySelection((()=>{this._normalizeDocument(!0),this.range_backup=this.range.cloneRange(),this._replaceText(!0)}))}.bind(this),this._paste=function(e){e.preventDefault(),this._isSelectionWithinRestrictedRange()||this._modifySelection((async()=>{if(this.range){if(this._isSelectionWithinRestrictedRange())return;let t=await this._callback({paste:e});if(!t){t=document.createDocumentFragment(),t.textContent=e.clipboardData.getData("text/plain").replace(/\n\n/g,"\n"),t.textContent.includes("#")&&(this.hashtag_flag=!0);for(let e of[":","/","."])t.textContent.includes(e),this.urllink_flag=!0}if(t&&!(t instanceof DocumentFragment))throw new Error("invalid document fragment");this.range.collapsed||this.range.extractContents(),this.range.insertNode(t)}}))}.bind(this),this._selectionchange=function(){this._modifySelection((()=>{this.isRangeDirectionForward=function(){const e=window.getSelection();return e.anchorNode!==e.focusNode?e.anchorNode.compareDocumentPosition(e.focusNode)&Node.DOCUMENT_POSITION_PRECEDING:e.anchorOffset>e.focusOffset}();let e=!("DELETE"===this.lastKey||"BACKSPACE"===this.lastKey)||this.isRangeDirectionForward,t=e?this.range.endContainer:this.range.startContainer;this.lastKey=null;let n=this._isUnSelectableElement(t);if(n){let t=e?n.nextSibling:n.previousSibling;this.logExecution&&console.log("nudging range",{unSel:n,selNext:t,isForward:e}),t||e||(t=document.createTextNode("​"),n.parentNode.insertBefore(t,e?n.nextSibling:n)),t&&(this.range=this._adjustSelection({node:this.range.collapsed?t:e?[null,t]:[t,null],position:this.range.collapsed?e?0:t.textContent.length:e?[null,0]:[0,null]}))}let i={};for(let e in this.styleTagOfCommand)i[e]=!1;if(this._isSelectionWithinRestrictedRange())return void(this.commandTracker=i);let o,s=this.restrictedElement_queryArray.concat(this.specialTextElement_queryArray);if(!this._nodeCrawler((e=>{(1===e.nodeType&&e.closest("blockquote")||3===e.nodeType&&e.parentNode.closest("blockquote"))&&(i.quote=!0);for(let n of s)if(t=n,3===e.nodeType?e.parentNode.closest(t):1===e.nodeType?e.closest(t):!(e instanceof Node))return e;var t;if(3===e.nodeType||"BR"===e.nodeName||1===e.nodeType&&1===e.childNodes.length&&("BR"===e.childNodes[0].nodeName||3===e.childNodes[0].nodeType)){let t=3===e.nodeType||"BR"===e.nodeName?e.parentNode:e,n=this._trackStyle(t);for(let e in n)i[e]=n[e]}return e}),{node:this.range,parentNode:this.element}).node.length){let e=this._trackStyle(this.range.startContainer);for(let t in e)i[t]=e[t]}this.commandTracker=i;let l=this.isRangeDirectionForward?this.range.endContainer:this.range.startContainer;3===l.nodeType?o=this.range.getBoundingClientRect():1===l.nodeType&&(o=l.getBoundingClientRect()),this._callback({commandTracker:i,range:this.range,caratPosition:o}).catch((e=>console.error(e))),this._lastLineBlank()}))}.bind(this),document.addEventListener("selectionchange",this._selectionchange),this.element.addEventListener("keydown",this._keydown),window.addEventListener("mousedown",this._normalize),this.element.addEventListener("paste",this._paste)}_observeMutation(e){this.observer&&this.observer.disconnect(),this.observer=null,e&&(this.observer=new MutationObserver((e=>{if(this.logMutation){let t=e.map((e=>({target:e.target.cloneNode(!0),type:e.type,name:e.attributeName,added:(()=>{let t=[];for(let n of e.addedNodes)3===n.nodeType?t.push(n.textContent):t.push(n.cloneNode(!0));return t})(),removed:(()=>{let t=[];for(let n of e.removedNodes)3===n.nodeType?t.push(n.textContent):t.push(n.cloneNode(!0));return t})()}))),n=[];for(let e of t)"childList"!==e.type&&"class"!==e.attributeName||n.push(e);n.length&&this._callback({mutation:n}).catch((e=>e))}for(const t of e)if("attributes"!==t.type){if("childList"===t.type){let e=t.target;if(t.removedNodes.length)for(let n of t.removedNodes){let t=(e,t)=>{if(!t.id)return;let n,i=this[`${e}_array`].length;for(;i--;)if(this[`${e}_array`][i].elementId===t.id){n=this[`${e}_array`].splice(i,1);break}n&&this._callback({removed:{[e]:n}})};if(n?.classList?.contains("_media_")){let e=n.childNodes,i=e.length;for(;i--;){let n=e[i];"IMG"===n.nodeName&&t("image",n)}continue}let i=!1;for(let e of["hashtag","urllink","custom"])if(n?.id?.includes(e)){t(e,n),i=!0;break}i=!1,this._isCeilingElement(e)&&(()=>{let t=e.childNodes.length;if(t)for(;t--;){let n=e.childNodes[t];if(1===n.nodeType||n.textContent)return!1}return!0})()?e.remove():this._isTextBlockElement(e)&&1===e.childNodes.length&&this._isUnSelectableElement(e.childNodes[0])&&e.append(document.createTextNode(""))}if(t.addedNodes.length)for(let n of t.addedNodes){let t=e=>{let t=e?.childNodes?.length,n=[];for(;t--;){let i=e.childNodes[t];"BR"===i.nodeName&&n.push(i)}return n};if(3!==n.nodeType){if(1===n.nodeType){let i=(()=>{let t=n.closest(`#${this.elementId}`)&&n.id!==this.elementId,i=(()=>!!t&&this._isCeilingElement(e))(),o=(()=>{for(let e of this.ceilingElement_queryArray){if(e==="#"+this.elementId)return this.element;let t=n.closest(e);if(t)return t}return null})(),s=i?n:t&&(()=>{let e=n;for(;e&&!this._isCeilingElement(e.parentNode);)e=e.parentNode;return e})();return{isWysiwygChild:t,isWysiwygEldestChild:i,isMediaElement:n.closest("._media_"),isBlockQuoteElement:n.closest("blockquote"),isCustomElement:n.closest("._custom_"),isHashtagElement:n.closest("._hashtag_"),isUrlLinkElement:n.closest("._urllink_"),ceiling:o,line:s}})();if(!i.isWysiwygChild)continue;if(i.isMediaElement||i.isHashtagElement||i.isUrlLinkElement){i.isMediaElement||i.isHashtagElement||i.isUrlLinkElement;continue}if((!i.isWysiwygEldestChild&&!i.isCustomElement||!this._isBlockElement(n)&&!this._isTextBlockElement(n))&&"BR"!==n.nodeName&&!n.classList.length){this._wrapNode(n);continue}if((()=>{if(this._isStyleAllowedElement(n))return!1;for(let e of this.restrictedElement_queryArray)if(n.closest(e))return!1;return!0})()&&n.removeAttribute("style"),i.isWysiwygEldestChild&&!this._isBlockElement(n)&&!this._isTextBlockElement(n)){"BR"===n.nodeName?n.remove():this._wrapNode(n,document.createElement("p"),!0);continue}if(e.textContent&&"​"!==e.textContent){let i=t(e),o=!1;if(i.length)for(let e of i)e===n&&(o=!0),e.remove();if(o)continue}if(i.isWysiwygEldestChild&&!this._isCeilingElement(n)){if(this.insertTabPending_tabString){let e=document.createTextNode(this.insertTabPending_tabString);i.line.insertBefore(e,i.line.childNodes[0]),this.insertTabPending_tabString="",this._adjustSelection({node:e,position:!1})}if(!i.line.textContent||"​"===i.line.textContent){let e=!0;this._nodeCrawler((t=>"BR"===t.nodeName?(e=!1,"BREAK"):t),{node:i.line}),e&&i.line.append(document.createElement("br"))}continue}let o=e=>{let t=this.counterTagOf[e]||[];return t.length&&(t=t.concat(t.map((e=>e+"_stop")))),[e,e.includes("_stop")?e.replace("_stop",""):e+"_stop"].concat(t)},s=[];n.classList.length&&this._climbUpToEldestParent(n,i.ceiling,!0,(e=>{let t=n.classList.length;for(;t--;)(()=>{let i=o(n.classList[t]);for(let t of i)if(e.classList.contains(t))return!0;return!1})()&&s.push(e);return e}));let l=s.length;for(;l--;)this._wrapNode(s[l]);let u=n.classList.length;for(;u--;){let e=n.classList[u];this._trackStyle(n,e.replace("_stop",""))===this._trackStyle(n.parentNode,e.replace("_stop",""))&&n.classList.remove(e)}n.classList.length||n.removeAttribute("class"),this._isTextBlockElement(e)&&1===e.childNodes.length&&this._isUnSelectableElement(e.childNodes[0])&&e.append(document.createTextNode(""))}}else if(this._isCeilingElement(e))this._wrapNode(n,document.createElement("p"));else if(n.textContent&&"​"!==n.textContent){let n=t(e);if(n.length)for(let e of n)e.remove()}}}}else{const{target:e,attributeName:n}=t;"class"===n&&(!e.parentNode||e.classList.length||this._isTextBlockElement(e)||this._isBlockElement(e)||"P"===e.nodeName||this._wrapNode(e),e.classList.length||e.removeAttribute("class")),"style"!==n||this._isStyleAllowedElement(e)||e.removeAttribute("style")}})),this.observer.observe(this.element,{attributes:!0,childList:!0,subtree:!0}))}_setArrow(e){if(this.logExecution&&console.log("_setArrow",{e}),!this.range||!e?.key)return;let t,n,i,o,s,l,u,r,a,h,c,d=e.key.toUpperCase(),f=e?.shiftKey||!1,g=e?.ctrlKey||e?.metaKey||!1,m=()=>{t=this.range?.endContainer,n=this.range?.endOffset,i=this.range?.startContainer,o=this.range?.startOffset,s=this.range?.collapsed,l=this.range?.startLine,u=this.range?.endLine,r=l===u,a=this.isRangeDirectionForward?u:l,h=this.isRangeDirectionForward?t:i,h=3===h?.nodeType?h?.parentNode:h},p=()=>{try{e.preventDefault()}catch(e){}},A=()=>{let e=this.isRangeDirectionForward?t:i,n=!1;return!s||!e.textContent.includes("​")&&e.textContent||this._nodeCrawler((t=>{if(3===t.nodeType&&("​"===t.textContent||!t.textContent)){let i=t.nextSibling||t.parentNode,o=this.isRangeDirectionForward?"nextSibling":"previousSibling";if(t===e||(()=>{if(1===e.nodeType){let n=e.childNodes.length;for(;n--;)if(e.childNodes[n]===t)return!0;return!1}})()){let e=i;return 1===e.nodeType&&t.parentNode===e?e[o]&&(n=e[o]):n=i,t.remove(),this.range=this._adjustSelection({node:s?n:this.isRangeDirectionForward?[null,n||i]:[n||i,null],position:s?this.isRangeDirectionForward:this.isRangeDirectionForward?[null,n]:[!n,null]}),m(),p(),"BREAK"}}return t}),{node:e}),!!n},_=e=>{let t="DOWN"===c?"bottom":"top",n=this.range.getBoundingClientRect(),i=e.getBoundingClientRect()[t],o=parseInt(this.fontSizeCssVariable["--wysiwyg-font-phone"]);return!!n.height&&!(("bottom"===t?i-n[t]:n[t]-i)<o)},C=()=>{if(!A()&&"inline-block"===window.getComputedStyle(h).display){let e=3===h.nodeType?h.parentNode:h;for(;"inline-block"===window.getComputedStyle(e).display;)e=e.parentNode;let t="UP"===c?"previousSibling":"nextSibling",n=e[t];if(!n){let i=document.createTextNode("");e.parentNode.insertBefore(i,"previousSibling"===t?e:n)}if(e=e[t],e){let t="DOWN"===c;return this.range=this._adjustSelection({node:f?this.isRangeDirectionForward?[null,e]:[e,null]:e,position:f?this.isRangeDirectionForward?[null,t]:[t,null]:t}),m(),!0}}return!1};switch(m(),d){case"ARROWLEFT":c="LEFT";case"ARROWRIGHT":let e;c=c||"RIGHT",(g||s&&f)&&(this.isRangeDirectionForward="RIGHT"===c,m()),!_(h)&&g&&"RIGHT"===c&&(e=C()),e||A();break;case"ARROWUP":c="UP";case"ARROWDOWN":if(c=c||"DOWN",!s&&!f){p();let e="UP"===c?[i,o]:[t,n];this.range=this._adjustSelection({node:e[0],position:e[1]});break}if((s||r)&&(this.isRangeDirectionForward="DOWN"===c,m()),_(h))break;if(C())break;A();let l=_(a);if(l)break;let u=this._climbUpToEldestParent(a,this.element),d=u.id!==this.elementId&&this._isCeilingElement(u);if(d&&("UP"===c&&u.firstChild!==a||"DOWN"===c&&u.lastChild!==a))break;let y=[d?u.previousSibling:a.previousSibling,d?u.nextSibling:a.nextSibling];"UP"===c&&y.reverse();let[E,b]=y,F=d?u:b;if(F){if(this._isBlockElement(F)&&!f){p();let e="UP"===c?F.previousSibling:F.nextSibling;if(!e||this._isBlockElement(e)){let t=this._createEmptyParagraph();F.parentNode.insertBefore(t,"UP"===c?F:e),F=t}else F=e;this.range=this._adjustSelection({node:F,position:"DOWN"===c}),f||a.textContent||!this._isBlockElement(E)&&(E||a!==this.element.firstChild)||this.removeSandwichedLine_array.push(a)}else if(!l&&"DOWN"===c){p();let e=0,i=this.isRangeDirectionForward?n:o;this._nodeCrawler((n=>n===t?"BREAK":(3===n.nodeType&&n.textContent&&(e+=n.textContent.length),n)),{node:a}),e+=i,this.range=this._adjustSelection({node:s?b:this.isRangeDirectionForward?[null,b]:[b,null],position:s?e:this.isRangeDirectionForward?[null,e]:[e,null]})}}else