UNPKG

wysiwyg4all

Version:

Free opensource minimal WYSIWYG editor for web developers

3 lines 72.2 kB
/*! For license information please see wysiwyg4all.cjs.LICENSE.txt */
(()=>{"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:()=>s});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,s;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";s="hex"}else")"===e[e.length-1]&&(s=i[0]);return{type:s,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,s={black:.88,white:1},o={"--background":t?"#121212":"#f7f7f7","--content":t?"#2b2b2b":"#ffffff"},l=this.isHighLuminance(o["--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,o["--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,s=this.hsla(1,e[1]).h;return t+30>360&&(i+=360),t-30<0&&(s=360-s),Math.abs(t-i)>Math.abs(t-s)?(r=-1,e[1]):e[0]})(),h=this.matchLuminance(this.complementary(u,60*r),o["--background"],3.1),c={"--placeholder":t?"rgba(255, 255, 255, 0.55)":"rgba(0, 0, 0, 0.44)"},d=t?this.matchLuminance(a,o["--background"],4.5):a,f=this.matchLuminance(a,o["--background"],4.5);for(let e in o)o[e+"-text"]=this.textColor(s,o[e]),o[e+"-focus"]=e.includes("--background")?d:u,o[e+"-text_focus"]=e.includes("--background")?f:this.matchLuminance(t?u:i,o[e],1.66),o[e+"-focus-text"]=this.textColor(1,e.includes("--background")?d:u);if(o["--focus"]=n,o["--focus-text"]=this.textColor(1,n),o["--saturate"]=i,o["--saturate-text"]=this.textColor(1,i),Object.assign(o,{"--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,o["--content"],7):this.contrastRatio(o["--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(o,e)}let g=Object.assign(o,c);return Object.keys(g).sort().reduce(((e,t)=>(e[t]=g[t],e)),{})}matchLuminance(e,t=this.color,n,i,s){let{color:o}=this._colorType(t),l=this._colorType(e).color;if(n){let e=l,t=this.contrastRatio(e,o);if(t<n){let l=i||this.isHighLuminance(o)?-1:1,u=100;for(;t<n&&u--;){let n;switch(s){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,o)}}return this.hex(e)}{let e=this._luminance(o),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 o;switch(s){case"saturation":o=this.adjustBrightness(u,{color:n,legacy:!0});break;case"luminance":o=this.adjustLuminance(u,n);break;default:o=this.adjustBrightness(u,n)}let l=this._luminance(o);if(l===t||u!==i(l,e))break;t=l,n=o}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},s=this.hsla(this.getAlpha(n),n),o="hsla("+i(s.h,t)+", "+s.s+"%, "+s.l+"%, "+s.a+")",l="hsla("+i(s.h,-t)+", "+s.s+"%, "+s.l+"%, "+s.a+")";return[this.matchLuminance(o,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:s}=this.rgba(1,this._colorType(e).color);return(t?(235*n+733.75*i+114*s)/1e3:(299*n+587*i+114*s)/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:s=this.color,fineTuned:o=!0}=t;if(s=this._colorType(s).color,this.getAlpha(s)<.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 s=e[t];"number"==typeof s&&s<1&&("black"===t?n=s:"white"===t&&(i=s))}const l=e=>"number"==typeof e?e<1&&e>0?e:e>1?1:0:1;return this.isHighLuminance(s,o)?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),s=(e,t,n)=>{e/=255,t/=255,n/=255;let i=Math.min(e,t,n),s=Math.max(e,t,n),o=s-i,l=0,u=0,r=0;return l=0===o?0:s===e?(t-n)/o%6:s===t?(n-e)/o+2:(e-t)/o+4,l=Math.round(60*l),l<0&&(l+=360),r=(s+i)/2,u=0===o?0:o/(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:o,b:l,a:u}=t,{h:r,s:a,l:h}=s(n,o,l);return{r:n,g:o,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:s,b:o,a:l}=this.rgba(e,i);return{r:n,g:s,b:o,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:o,l}=s(n.r,n.g,n.b);return Object.assign(n,{r:n.r,g:n.g,b:n.b,h:i,s:o,l,a:n.a,string:this._toString({h:i,s:o,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},s=t.match(/[a-fA-F0-9]{2}/g);4===t.length&&(s=t.match(/[a-fA-F0-9]{1}/g),s=s.map((e=>""+e+e)));let o=0;for(const e in n)n[e]=parseInt(s[o],16),o++;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),s="number"==typeof e?e:t[3]||1;if(n.includes("rgb")){let e={r:t[0],g:t[1],b:t[2],a:s};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 o=(1-Math.abs(2*i-1))*n,l=o*(1-Math.abs(e/60%2-1)),u=i-o/2,r=0,a=0,h=0;return 0<=e&&e<60?(r=o,a=l,h=0):60<=e&&e<120?(r=l,a=o,h=0):120<=e&&e<180?(r=0,a=o,h=l):180<=e&&e<240?(r=0,a=l,h=o):240<=e&&e<300?(r=l,a=0,h=o):300<=e&&e<360&&(r=o,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:s,string:this._toString({r,g:a,b:h,a:s})}}}}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),s=(e,t=100)=>e>t?t:e<0?0:e;return i.s+=(e>0?100-i.s:i.s)/100*e,i.s=s(i.s),i.l+=(e>0?100-i.l:i.l)/100*e,i.l=s(i.l),this._toString(i)}let{type:s=this.type,color:o=this.color}=this._colorType(n);if(0===e)return o;const l="hex"===s?1:this._extractDigit(o)[3]||1,u=this.rgba(l,o);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"===s?this.hex(a):s.includes("rgb")?this.rgba(u.a,a).string:s.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 s{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:s="",spellcheck:o=!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=s,this.spellcheck=o,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 s=y[i];if("number"==typeof s){let e=t*s;if(e+.01>n&&e-.01<n)return i}else if("string"==typeof s)if(s.includes("px")){if(e===s)return i}else if(s.includes("em")||s.includes("rem")){let e=parseFloat(s);if(e>0){let s=t*e;if(s+.01>n&&s-.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]:[],s=!!e,{node:o=null,position:l=!0}=e||{},u=window.getSelection();if(!u)return null;try{n=u.getRangeAt(0)}catch(e){s&&(n=document.createRange())}if(s){o=i(o,!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 o)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 s=i.textContent.length;if("false"===i.parentNode.getAttribute("contenteditable"))return t-(n+s)>=0?(n+=s,i):(t=s,"BREAK");if(e=i,!(t-(n+s)>=0))return t-=n,"BREAK";n+=s}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,s=!1,r=(o[0]=null===o[0]?n.startContainer:o[0],l[0]=null===l[0]?n.startOffset:l[0],e(o[0],l[0]));n.setStart(r.node,r.position),l.length>1?t=e((null===o[1]?n.endContainer:o[1])||o[0],null===l[1]?n.endOffset:l[1]):(t=r,s=!0),n.setEnd(t.node,t.position),s&&n.collapse(!0),u.removeAllRanges(),u.addRange(n)}if(t&&n){let e,i;for(let s of t){if(e&&i)break;let t=3===n.endContainer.nodeType?n.endContainer.parentNode:n.endContainer,o=3===n.startContainer.nodeType?n.startContainer.parentNode:n.startContainer;!e&&o.closest(s)&&(e=this._climbUpToEldestParent(o,o.closest(s))),!i&&t.closest(s)&&(i=this._climbUpToEldestParent(t,t.closest(s)))}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:s,startNode:o}=t;if(s&&!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,s&&(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=(o instanceof Node?o: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),s=null,o=i.startOffset,l=null,u=i.endOffset;const r=e=>{i.startContainer===e&&(s=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&&(s||l)&&(i=s&&s===l&&o===u?this._adjustSelection({node:a||e,position:o}):this._adjustSelection({node:[s,l],position:[o,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 s,o=t.id||(()=>(s=this._generateId("eldest"),t.id=s,s))();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 s=e.childNodes[t];if(3===s.nodeType&&s.textContent.length>0&&"​"!==s.textContent?i=!0:1===s.nodeType&&"BR"!==s.nodeName&&n++,n>1&&!i||n&&i)return!1}return!0})()}for(;e?.id!==o&&e.parentNode&&e.parentNode.closest("#"+o)&&e.parentNode.id!==o&&(!n||l(e?.parentNode));){let t=i(e.parentNode);if(!t||"BREAK"===t)break;e=t}return s&&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),s=this._climbUpToEldestParent(e.endContainer,t),o=[];if(n){let e=i.nextSibling;for(;e&&e!==s;)1===e.nodeType&&this.blockElement_queryArray.some((t=>e.matches(this._classNameToQuery(t))))&&o.push(e),e=e.nextSibling}return this.logExecution&&console.log("startLine | endLine",{startLine:i,endLine:s,inBetween:o}),[i,s,o]}_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:s}=e,o=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 o)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 o)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={},s=window.getComputedStyle(e);for(let t of this.alignClass)e.closest("."+t)&&(n[t.substring(1,t.length-1)]=!0);let o=o=>{let l=this.cssPropertyChecker[o];if("function"==typeof l){if(l=l(s[o]),l){if(t)return l;n[l]=!0}}else if("color"===o&&s[o]){let e="#"===s[o][0]?s[o]:new i(s[o]).hex();if(e!==this.defaultFontColor){if(t)return e;n[l]=e}}else if("backgroundColor"===o&&s[o]){let e=null;if("#"===s[o][0])e=s[o];else{let t=s[o].split(",");if(4===t.length&&"0)"===t[t.length-1].trim())return!1;e=new i(s[o]).hex()}if(e&&e!==this.defaultBackgroundColor){if(t)return e;n[l]=e}}else if(s[o]!==this.elementComputedStyle[o]&&this._isTextElement(e)){if(t)return!0;n[l]=!0}return!1};if(t)return o(this.cssPropertyOf[t]);for(let e in this.cssPropertyChecker)o(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:s,endLine:o}=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]===s)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"===o.textContent[0])for(let e of o.textContent){if("\t"!==e)break;this.insertTabPending_tabString+="\t"}this.isRangeDirectionForward=!0}else{this.isRangeDirectionForward=!0,e.preventDefault();let l=[];if(!i){let e=s;for(;e&&e!==o;)l.push(e),e=e.nextSibling;l.push(o)}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:[s,o],position:[!0,!1]})}else if("\t"===s.textContent[0]){let o=((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))(s,t,n)-1;o=o<0?0:o,i(s),e&&this._adjustSelection({node:s,position:o})}}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:[s,o],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 s,o=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 o)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?s=this.range.getBoundingClientRect():1===l.nodeType&&(s=l.getBoundingClientRect()),this._callback({commandTracker:i,range:this.range,caratPosition:s}).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))(),s=(()=>{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})(),o=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:s,line:o}})();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),s=!1;if(i.length)for(let e of i)e===n&&(s=!0),e.remove();if(s)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 s=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)},o=[];n.classList.length&&this._climbUpToEldestParent(n,i.ceiling,!0,(e=>{let t=n.classList.length;for(;t--;)(()=>{let i=s(n.classList[t]);for(let t of i)if(e.classList.contains(t))return!0;return!1})()&&o.push(e);return e}));let l=o.length;for(;l--;)this._wrapNode(o[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,s,o,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,s=this.range?.startOffset,o=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!o||!e.textContent.includes("​")&&e.textContent||this._nodeCrawler((t=>{if(3===t.nodeType&&("​"===t.textContent||!t.textContent)){let i=t.nextSibling||t.parentNode,s=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[s]&&(n=e[s]):n=i,t.remove(),this.range=this._adjustSelection({node:o?n:this.isRangeDirectionForward?[null,n||i]:[n||i,null],position:o?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],s=parseInt(this.fontSizeCssVariable["--wysiwyg-font-phone"]);return!!n.height&&!(("bottom"===t?i-n[t]:n[t]-i)<s)},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||o&&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",!o&&!f){p();let e="UP"===c?[i,s]:[t,n];this.range=this._adjustSelection({node:e[0],position:e[1]});break}if((o||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:s;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:o?b:this.isRangeDirectionForward?[null,b]:[b,null],position:o?e:this.isRangeDirectionForward?[null,e]:[e,null]})}}else p()}}_append(e,t,n=!1,i){this.logExecution&&console.log("_append",{i:e,insertAfter:t,wrap:n,focusElement:i});let s=this._climbUpToEldestParent(this.range.commonAncestorContainer,this.element),[o,l]=this._getStartEndLine(),u=["HR","UL","LI","._media_","._custom_"],r=n=>{n===this.element&&(n=this.element.childNodes[this.element.childNodes.length-1]);let i=n.nextSibling;t&&n.parentNode.insertBefore(t,i),n.parentNode.insertBefore(e,t||i),this._isTextElement(n)&&!n.textContent&&this.element.lastChild!==n&&n.remove()};if(n){let t={},n=!1,a=(e,n)=>{!n||t[e]&&!(()=>{for(let e in t)if(t[e]===n)return!1;return!0})()||(t[e]=n)};if(this.range.collapsed){a(e.nodeName,o.closest(e.nodeName));let t=e.classList.length;for(;t--;){let n=e.classList[t];a(n,o.closest("."+n))}}else this._nodeCrawler((t=>{let i=3===t.nodeType?t.parentNode:t;if(1!==i.nodeType)return n=!0,"BREAK";if(1===t.nodeType)for(let e of u)if(t.nodeName===e||t.closest(e))return n=!0,"BREAK";a(e.nodeName,i.closest(e.nodeName));let s=e.classList.length;for(;s--;){let t=e.classList[s];a(t,i.closest("."+t))}return t===this.range.endContainer?"BREAK":t}),{node:s,startNode:this.range.startContainer});if(n)return;if(Object.keys(t).length)for(let e in t)this._wrapNode(t[e]);else{r(l);let t=this.range.extractContents();if(t.childNodes[0])for(;t.childNodes[0];){let n=t.childNodes[0];n.textContent?e.append(n):n.remove()}else e.append(this._createEmptyParagraph());this.range=this._adjustSelection({node:i||e,position:!1});let n=e.previousSibling;n&&(n=3===n.nodeType?n.parentNode:n,!this._isTextElement(n)||n.textContent&&"​"!==n.textContent||n.remove())}}else{for(let e of u)l.closest(e)&&(l=l.closest(e));r(l),t&&(this.range=this._adjustSelection({node:i||t}))}}async _callback(e){if("function"==typeof this.callback){let t=this.callback(e)||e;return t instanceof Promise&&(t=await t),t||e}return e}async _imageSelected(e){this.logExecution&&console.log("_imageSelected",{e});let t=e.target.files;const n={image:[]};let i=new FileReader;const s=e=>new Promise((t=>{i.onload=n=>{const{lastModified:i,name:s,size:o,type:l}=e,u=n.target.result;let r=new Image;r.onload=()=>{t({dimension:{width:r.width,height:r.height},lastModified:i,filename:s,fileSize:o,fileType:l,source:u,elementId:this._generateId("img")})},r.src=u},i.readAsDataURL(e)}));this.callback({loading:!0});for(let e=0;t.length>e;e++)n.image[e]=await s(t[e]);this.callback({loading:!1}),this.imgInput.value="";let o=await this._callback(n);this.range||this.restoreLastSelection(),this.range&&!(()=>{let e=this.range.commonAncestorContainer;return e=3===e.nodeType?e.parentNode:e,!e.closest("#"+this.elementId)})()||this.element.focus(),this._modifySelection((()=>{for(let e of o.image){let t=this._loadImage(e,document.createElement("div"));this._append(t,this._createEmptyParagraph())}}))}_loadImage(e,t){if(this.logExecution&&console.log("_loadImage",{imageObject:e,wrapper:t}),!(t instanceof Node))throw"image needs _media_ wrapper";return t.classList.contains("_media_")||t.classList.add("_media_"),"false"!==t.getAttribute("contenteditable")&&t.setAttribute("contenteditable","false"),(e=>{let n=e?.element instanceof Node?e.element:null;if(n&&(n.id?e.elementId=n.id:n.id=e.elementId),!n){n=document.createElement("img"),e.element=n;let i="_img_"+e.source.substring(e.source.length-128).replace(/[/:."'\\@#$%\?= \{\}\|&*`!<>+]/g,"");if(n.classList.contains(i)&&n.classList.add(i),Array.isArray(e.class))for(let t of e.class)n.classList.add(t);if("IMG"===n.tagName&&n.setAttribute("src",e.source),"function"==typeof e.onclick&&(n.addEventListener("click",e.onclick),n.classList.add("_hover_")),e.style&&"object"==typeof e.style&&Object.keys(e.style).length)for(let n in e.style)t.style.setProperty(n,e.style[n])}t.setAttribute("contenteditable","false"),t.append(n);let i=!0;for(let t of this.image_array)if(t.elementId===e.elementId){i=!1;break}i&&this.image_array.push(e)})(e),t}_getAnchorOffsetFromLine(e){const t=window.getSelection();if(!t||!t.anchorNode)return 0;let n=t.anchorNode,i=t.anchorOffset;if(!e.contains(n)&&e!==n)return 0;let s=0,o=!1;return function e(t){if(!o){if(t===n)return s+=i,void(o=!0);if(3===t.nodeType)s+=t.textContent.length;else for(let n of t.childNodes)if(e(n),o)break}}(e),s}_getFocusOffsetFromLine(e){const t=window.getSelection();if(!t||!t.focusNode)return 0;let n=t.focusNode,i=t.focusOffset;if(!e.contains(n)&&e!==n)return 0;let s=0,o=!1;return function e(t){if(!o){if(t===n)return s+=i,void(o=!0);if(3===t.nodeType)s+=t.textContent.length;else for(let n of t.childNodes)if(e(n),o)break}}(e),s}_modifySelection(e,t){this.logExecution&&console.log("_modifySelection",{run:e});let n=window.getSelection();return n?(t=>{let n=3===t.anchorNode?.nodeType?t.anchorNode.parentNode:t.anchorNode;if(n&&n.closest(`#${this.elementId}`)){if(n.id===this.elementId){let e=this.element.lastChild;e||(e=this._createEmptyParagraph(),this.element.appendChild(e),this.range=this._adjustSelection({node:e,position:!0}))}else this.range=this._adjustSelection(null);"function"==typeof e&&e()}else this.range=null,this.commandTracker={}})(n):(this.range=null,void(this.commandTracker={}))}_isFirstOrLastChild(e){let t=this.element.firstChild,n=this.element.lastChild;if(!t||!n)return!1;if(this.logExecution&&console.log("_isFirstOrLastChild",{node:e}),!e||!e.parentNode)return!1;if(3===e.nodeType&&(e=e.parentNode),t===e||n===e)return e;let i=this._climbUpToEldestParent(e,this.element);return(i===t||i===n)&&i}_normalizeDocument(e){if(this.logExecution&&console.log("_normalizeDocument",{normalize:e}),!e)return;let t=[];this._nodeCrawler((e=>{let n=this._isFirstOrLastChild(e);if(n&&!n.classList.contains("_media_")&&!n.classList.contains("_custom_")){if(3===e.nodeType){let t=e.parentNode;if(!(t!==this.element.firstChild&&t!==this.element.lastChild||t.firstChild!==e&&t.lastChild!==e))return e}if(1===e.nodeType&&n===e)return e.normalize(),e.textContent||(e.textContent="​"),e}return"BR"===e.tagName||1!==e.nodeType||e.classList.contains("_media_")||e.classList.contains("_custom_")||!e.textContent.includes("​")||(e.textContent=e.textContent.replaceAll("​",""),e.normalize()),1!==e.nodeType||e.classList.contains("_media_")||e.classList.contains("_custom_")||this._isCeilingElement(e)||e.textContent||e.childNodes.length||"BR"===e.tagName||t.push(e),e}),{node:this.element}),t.forEach((e=>{e.remove()}))}_replaceText(e=!1){this.logExecution&&console.log("_replaceText",{wholeDocument:e});const t=(t,n)=>{if(!this[t])return;let i=this[`${t}_regex`]||null;if(null===i)throw new Error("no regex to process");if("function"!=typeof n)throw new Error("setData should be returning function");let s=e?this.element:this.range?.commonAncestorContainer;if(!s)return;3===s.nodeType&&(s=s.parentNode);let o=(()=>{let e,n=`_${t}_`,o=[],l=[],u=[];if(this._nodeCrawler((e=>{if(3===e.nodeType&&e.textContent)if(3===e.nextSibling?.nodeType&&e.nextSibling.textContent&&"​"!==e.nextSibling.textContent){let t=e.parentNode;t.normalize(),e=t}else"​"===e.textContent||e.parentNode.closest("."+n)||u.push(e);return e}),{node:s}),u.forEach((e=>{!function(e,t,n){let i,s=e.parentNode,u=e.nextSibling,r=e.ownerDocument;if(t.global)for(;e&&(i=t.exec(e.nodeValue));)t.lastIndex=0,e=a(e,i,n.apply(this,i));else(i=t.exec(e.nodeValue))&&a(e,i,n.apply(this,i));function a(e,t,n){let i=e.nodeValue;e.nodeValue=i.slice(0,t.index),[].concat(h(s,n)).forEach((function(e){let t=s.insertBefore(e,u);o.push(t)}));let l=i.slice(t.index+t[0].length);if(l){let e=r.createTextNode(l);return s.insertBefore(e,u)}}function h(e,t){if(t.map)return t.map((function(t){return h(e,t)}));if("object"==typeof t){let n=r.createElementNS(t.namespaceURI||e.namespaceURI,t.name);if(t.attrs)for(let e in t.attrs)n.setAttribute(e,t.attrs[e]);return t.content&&[].concat(h(n,t.content)).forEach(n.appendChild,n),"string"==typeof t.content&&l.push(t.content),n.contentEditable="false",n}return r.createTextNode(t+"")}}(e,i,(function(e){if(e.length>1)return{name:"span",attrs:{class:`${n} ${n}${e}`},content:e}}))})),o.length)for(let t of o)e=s.ownerDocument.createTextNode(""),t.parentNode.insertBefore(e,t.nextSibling);return{collected:l,element:o,anchorText:e}})(),l=o.element;e||(this.range=this._adjustSelection({node:o.anchorText,position:!1}));let u=[],r=[];if(l[0])for(let e of l){let i=this._generateId(t);e.setAttribute("id",i);let s=n(e)||{};s.elementId=e.id,s.element=e,e.removeAttribute("style"),r.push(e.id),u.push(s)}u.length&&this._callback({[t]:u}).then((e=>{for(let n=0;r.length>n;n++)e[t][n].elementId=r[n];if(Array.isArray(e[t])&&e[t].length)for(let n of e[t]){let e=document.getElementById(n.elementId);if(e.setAttribute("id",n.elementId),e.setAttribute("contenteditable","false"),"function"==typeof n.onclick&&(e.addEventListener("click",n.onclick),e.classList.add("_hover_")),n.style&&"object"==typeof n.style&&Object.keys(n.style).length)for(let t in n.style)e.style.setProperty(t,n.style[t]);this[`${t}_array`].push(n)}})).catch((e=>{console.error(e)}))};this.urllink_flag&&t("urllink",(e=>{let t=e.textContent;return e.addEventListener("click",(function(){t.match(/^https?:\/\//i)||(t="http://"+t),window.open(t,"_blank")})),{url:t}})),this.hashtag_flag&&t("hashtag",(e=>{let t=e.textContent;return{tag:"#"===t[0]?t.substring(1):t}})),this.hashtag_flag=!1,this.urllink_flag=!1}_checkElement(e,t,n,i){if(this.logExecution&&console.log("_checkElement",{node:e,chkArr:t,closest:n,exp:i}),e&&1===e.nodeType)for(let s of t)if(n){let t=e.closest(s);if(t){if(i&&i[s]){if("._custom_"!==s)return t.getAttribute(i[s].attr)!==i[s].value&&t;{let t=e,n=!1;if(e!==this.element)for(;t&&this.element!==t;){if(n=t.getAttribute(i[s].attr)===i[s].value,n)return!1;t=t.parentNode}}}return t}}else if("#"===s[0]?e.id===s.substring(1):"."===s[0]?e.classList.contains(s.substring(1)):e.nodeName===s)return!0;return!1}_isUnSelectableElement(e){return this.logExecution&&console.log("_isUnSelectableElement",{node:e}),e=3===e?.nodeType?e.parentNode:e,this._checkElement(e,this.unSelectable_queryArray,!0)}_isStyleAllowedElement(e){return this.logExecution&&console.log("_isStyleAllowedElement",{node:e}),this._checkElement(e,this.styleAllowedElement_queryArray)}_isCeilingElement(e){return this.logExecution&&console.log("_isCeilingElement",{node:e}),this._checkElement(e,this.ceilingElement_queryArray)}_isBlockElement(e){return this.logExecution&&console.log("_isBlockElement",{node:e}),this._checkElement(e,this.blockElement_queryArray)}_isTextAreaElement(e){return this.logExecution&&console.log("_isTextAreaElement",{node:e}),this._checkElement(e,this.textAreaElement_queryArray)}_isTextBlockElement(e){return this.logExecution&&console.log("_isTextBlockElement",{node:e}),e=3===e?.nodeType?e.parentNode:e,this._checkElement(e,this.textBlockElement_queryArray)}_isSpecialTextElement(e){return this.logExecution&&console.log("_isSpecialTextElement",{node:e}),e=3===e?.nodeType?e.parentNode:e,this._checkElement(e,this.specialTextElement_queryArray)}_isTextElement(e){return this.logExecution&&console.log("_isTextElement",{node:e}),e=3===e?.nodeType?e.parentNode:e,(this._isTextBlockElement(e)||"SPAN"===e.nodeName)&&!this._isSpecialTextElement(e)}command(e){if(!e)return;switch(this.range||this.restoreLastSelection(),e){case"quote":return this.range&&!(()=>{let e=this.range.commonAncestorContainer;return e=3===e.nodeType?e.parentNode:e,!e.closest("#"+this.elementId)})()||this.element.focus(),void this._modifySelection((()=>{let e=document.createElement("blockquote");this._append(e,null,!0),this.setSafeLine()}));case"unorderedList":return this.range&&!(()=>{let e=this.range.commonAncestorContainer;return e=3===e.nodeType?e.parentNode:e,!e.closest("#"+this.elementId)})()||this.element.focus(),void this._modifySelection((()=>{let e=document.createElement("li"),t=document.createElement("ul");t.append(e),this._append(t,null,!1,e),this.setSafeLine()}));case"orderedList":return this.range&&!(()=>{let e=this.range.commonAncestorContainer;return e=3===e.nodeType?e.parentNode:e,!e.closest("#"+this.elementId)})()||this.element.focus(),void this._modifySelection((()=>{let e=document.createElement("li"),t=document.createElement("ol");t.append(e),this._append(t,null,!1,e),this.setSafeLine()}));case"divider":return this.range&&!(()=>{let e=this.range.commonAncestorContainer;return e=3===e.nodeType?e.parentNode:e,!e.closest("#"+this.elementId)})()||this.element.focus(),void this._modifySelection((()=>{let e=document.createElement("hr");e.setAttribute("contenteditable","false"),this._append(e,null,!1),this.setSafeLine()}));case"image":return void this.imgInput.click();case"alignLeft":case"alignCenter":case"alignRight":if(!this.range)return;return void this._modifySelection((()=>{let t=this.range.startLine,n=this.range.endLine,i=[];for(i.push(t);i[i.length-1]!==n;){let e=i[i.length-1].nextSibling;for(;e&&!this._isTextBlockElement(e);){if(this._isCeilingElement(e)&&e.firstChild&&this._isTextBlockElement(e.firstChild)){e=e.firstChild;break}e=e.nextSibling}if(!e&&this._isCeilingElement(i[i.length-1].parentNode)&&(e=i[i.length-1].parentNode.nextSibling),!e)break;i.push(e)}let s=Object.assign({},this.commandTracker);for(let t of i){for(let e of this.alignClass)t.classList.contains(e)&&t.classList.remove(e),s[e.substring(1,e.length-1)]=!1;if("alignLeft"!==e&&!this.commandTracker[e]){for(let n of this.alignClass)n.includes(e)&&t.classList.add(n);s[e]=!0}}this.commandTracker=s,this._callback({commandTracker:s,range:this.range}).catch((e=>e))}))}let t,n;try{t=new i(e).hex(),e="color"}catch{}try{e?.backgroundColor&&(n=new i(e?.backgroundColor).hex(),e="backgroundColor")}catch{}this.styleTagOfCommand[e]?this._modifySelection((()=>{let i,s=this.styleTagOfCommand[e],o=!1,l=this.counterTagOf[s]?this.counterTagOf[s].map((e=>this._classNameToQuery(e))):[];if(l.length&&(l=l.concat(l.map((e=>e+"_stop")))),s=this._classNameToQuery(s),this.commandTracker[e]){let i;i="color"===e?t===this.commandTracker[e]||void 0===t&&this.commandTracker[e]===this.highlightColor:"backgroundColor"!==e||n===this.commandTracker[e]||void 0===n&&this.commandTracker[e]===this.highlightColor,i&&(s=this._classNameToQuery(s+"_stop"),o=!0)}"."===s[0]?(i=document.createElement("SPAN"),i.classList.add(s.substring(1))):i=document.createElement(s),t&&!o&&(i.style.color=t),n&&!o&&(i.style.backgroundColor=n);let u=this._isSelectionWithinRestrictedRange();if(this.range.collapsed){if(u)return;let e=document.createTextNode("​");i.append(e),"BR"===this.range.startContainer.nodeName?this.range.startContainer.parentNode.insertBefore(i,this.range.startContainer):this.range.insertNode(i),this.range=this._adjustSelection({node:e,position:!1})}else{if(u)return void(this.range=this._adjustSelection({node:this.range.endContainer,position:this.range.endOffset}));let e=this.range.extractContents(),t=document.createElement("span");for(;e.childNodes[0];)t.append(e.childNodes[0]);for(this._nodeCrawler((e=>{let t=u?this._classNameToQuery(u):null,n=3===e.nodeType?e.parentNode:e,i=!(!t||!n.hasOwnProperty("closest"))&&n.closest(t);return 3!==e.nodeType||i||(e.textContent=e.textContent.replaceAll("\t","")),e}),{node:t,startFromEldestChild:!0,parentNode:this.element});t.childNodes[0];)e.append(t.childNodes[0]);let n=[s];if(o){let e=s.replace("_stop","").substring(1);e="_"===e[0]?"."+e:e,n.push(e)}else{let e=s+"_stop";e="."===e[0]?e:"."+e,n.push(e)}n=n.concat(l);let r=e.querySelectorAll(n.join()),a=r.length;if(a)for(;a--;)this._wrapNode(r[a]);let h=[i.cloneNode(!0)];for(;e.childNodes[0];){let t=e.childNodes[0];if(1===t.nodeType&&this._isBlockElement(t)){if(this._isTextAreaElement(t)){for(let e=0;t.childNodes.length>e;e++){let n=t.childNodes[e];if(this._isTextElement(n)){let e=i.cloneNode(!0);for(;n.childNodes[0];)n.childNodes[0].textContent?e.append(n.childNodes[0]):n.childNodes[0].remove();n.append(e)}}if(!t.textContent){t.remove();continue}}let e=document.createDocumentFragment();e.append(t),h.push(e)}else if(1===t.nodeType&&this._isTextBlockElement(t)){let e=i.cloneNode(!0);for(;t.childNodes[0];)e.append(t.childNodes[0]);if(1===e.childNodes.length&&"BR"!==e.childNodes[0].nodeName&&!e.textContent.length){t.remove();continue}t.append(e);let n=document.createDocumentFragment();n.append(t),h.push(n)}else h[h.length-1].append(t)}let c=document.createDocumentFragment();for(let e of h)c.append(e);let d=c.firstChild,f=c.lastChild;if(this._isTextElement(d)&&!d.textContent){let e=d.nextSibling;d.remove(),d=e}if(this._isTextElement(f)&&!d.textContent){let e=f.nextSibling;f.remove(),f=e}this.range.insertNode(c),this.range=this._adjustSelection({node:[d,f],position:[!0,!1]}),d=3===d.nodeType?d.parentNode:d,f=3===f.nodeType?f.parentNode:f;let g=f.nextSibling;!this._isTextElement(g)||g.textContent&&"​"!==g.textContent||g.remove();let m=d.previousSibling;(this._isTextElement(m)&&!m.textContent||"​"===m.textContent)&&m.remove()}}),!0):"object"==typeof e&&this._modifySelection((()=>{let t=null;if(e.style)for(let n in e.style)t.style[n]=e.style[n];e.elementId=e.elementId||this._generateId("custom"),"string"==typeof e.element?(t=document.createTextNode(e.element),e.insert=!0):e.element instanceof HTMLElement&&(t=e.element,t.id=e.elementId,t.classList.add("_custom_")),this.range||this.element.focus(),this.custom_array.push(e),this._callback({custom:e}).then((n=>{let i=document.createTextNode("");e.insert?(this.range.insertNode(i),this.range.insertNode(t)):this._append(t,i,!1),this.range=this._adjustSelection({node:i,position:!1}),this.setSafeLine()}))}))}setSafeLine(){let e=this.element.firstChild,t=this.element.lastChild,n=document.createElement("br");this.needSafeGuard.forEach((i=>{"."===i[0]?(i=i.substring(1),e&&1===e.nodeType&&e.classList.contains(i)&&this.element.insertBefore(this._createEmptyParagraph(n),e),t&&1===t.nodeType&&t.classList.contains(i)&&this.element.appendChild(this._createEmptyParagraph(n))):(e&&e?.tagName===i&&this.element.insertBefore(this._createEmptyParagraph(n),e),t&&t?.tagName===i&&this.element.appendChild(this._createEmptyParagraph(n)))}))}restoreLastSelection(){if(this.logExecution&&console.log("restoreLastSelection",{range_backup:this.range_backup}),this.range_backup){this.range=this._adjustSelection({node:[this.range_backup.startContainer,this.range_backup.endContainer],position:[this.range_backup.startOffset,this.range_backup.endOffset]});let e=window.getSelection(),t=document.createRange();t.setStart(this.range.startContainer,this.range.startOffset),t.setEnd(this.range.endContainer,this.range.endOffset),e.removeAllRanges(),e.addRange(t)}}async loadHTML(e=this.html,t=!1){if("string"!=typeof e)throw new Error("html should be a string");this.setEditable(!1),this.html=e||"";const n=document.createElement("div");n.innerHTML=e;const i=n.querySelectorAll("img"),s=[];if(i.length)for(let e of i){if(e.closest("._media_")){const t=e.getAttribute("src");let n=e.id||this._generateId("img");e.setAttribute("id",n),s.push({source:t,elementId:n,element:e})}this.image_array=JSON.parse(JSON.stringify(s))}const o=n.querySelectorAll("._hashtag_"),l=[];if(o.length)for(let e of o){let t,n=e.classList.length,i=e.id||this._generateId("hashtag");for(;n--;){let i=e.classList[n];"#"===i.replace("_hashtag_","")[0]&&(t=i.replace("_hashtag_",""))}t="#"===t?.[0]?t.substring(1):t,t&&l.push({tag:t,elementId:i,element:e})}const u=n.querySelectorAll("._urllink_"),r=[];if(u.length)for(let e of u){let t,n=e.id||this._generateId("urllink"),i=e.classList.length;for(;i--;){let n=e.classList[i];n.includes("_urllink_").length&&(t=n.replace("_urllink_",""))}t&&r.push({url:t,elementId:n,element:e})}const a=n.querySelectorAll("._custom_"),h=[];if(a.length)for(let e of a){let t=e.id||this._generateId("custom");h.push({elementId:t,element:e})}let c=await this._callback({image:s,hashtag:l,urllink:r,custom:h});for(let e in c)if("image"===e){let t=c[e];for(let e of t){const t=n.querySelector("#"+e.elementId).closest("._media_");this._loadImage(e,t)}}else this[e+"_array"]=c[e];for(this.element.innerHTML="";n.childNodes[0];)this.element.append(n.childNodes[0]);t&&this.setEditable(!0)}async export(e){this._normalizeDocument(!0);const t=this.element.cloneNode(!0),{hashtag_array:n,image_array:i,urllink_array:s,custom_array:o}=this;let l="",u="",r={dom:t,urllink:this.urllink?s:void 0,hashtag:this.hashtag?n:void 0,image:i,custom:o};if("function"==typeof e){let t=e(r);r=t instanceof Promise?await t||r:t||r,this.hashtag&&(this.hashtag_array=r.hashtag),this.urllink&&(this.urllink_array=r.urllink),this.image_array=r.image,this.custom_array=r.custom,l=r.title||""}const a=r.dom.querySelectorAll(":scope > *");for(let e=0;e<a.length;e++){let t=a[e];if(t.textContent.length){let e=t.textContent;if(l)u+=`${e}\n`;else{let t,n=/([^\s^.]{2,}[^\s]+[.][^\s^.]{2,})/g,i=e.match(n);if(i){for(let t=0;t<i.length;t++)e=e.replace(i[t].replace(/\.+$/,""),"[§url§]"+t+"[/§url§]");t=e.split(".");for(let e=0;e<t.length;e++)for(let n=0;n<i.length;n++)t[e]=t[e].replace("[§url§]"+n+"[/§url§]",i[n].replace(/\.+$/,""))}else t=e.split(".");l=t[0],l.length>200&&(u+=l.substring(200)+".",l=l.substring(0,200)),t.shift(),e=t.join(".").replace(/\s\s+/g," "),u+=e+" "}}if(t.classList.contains("_media_")){let e=t.childNodes.length;for(;e--;){let n=t.childNodes[e];if("IMG"===n.nodeName)for(const e of this.image_array)if(e.elementId===n.id&&e.source!==n.getAttribute("src")){n.setAttribute("src",e.source);let t=n.classList.length;for(;t--;)if(n.classList[t].includes("_img_")&&n.classList[t].length>5){n.classList.remove(n.classList[t]);let i=e.source.split("/"),s=i[i.length-1],o=s.length-64;const l=i[i.length-1].substring(o>0?s:0);n.classList.add("_img_"+l)}}}}}return{html:r.dom.innerHTML,title:l.trim(),text:u.trim(),urllink:this.urllink?this.urllink_array:void 0,hashtag:this.hashtag?this.hashtag_array:void 0,image:this.image_array,custom:this.custom_array}}setPlaceholder(e){this.logExecution&&console.log("setPlaceholder",{p:e}),this.element&&(e&&"string"==typeof e?this.element.setAttribute("placeholder",e):this.element.removeAttribute("placeholder"))}setSpellcheck(e){this.logExecution&&console.log("setSpellcheck",{bool:e}),this.element&&this.element.setAttribute("spellcheck",e?"on":"off")}setEditable(e){this.logExecution&&console.log("setEditable",{bool:e}),e=!!this.element&&e,this.element&&this.element.setAttribute("contenteditable",e?"true":"false"),this._setEventListener(e),this._observeMutation(e)}}module.exports=t})();
//# sourceMappingURL=wysiwyg4all.cjs.map