goffeetabler/storage/public/dist/libs/hugerte/plugins/visualchars/plugin.min.js
2026-09-12 23:29:45 -05:00

7 lines
No EOL
5.9 KiB
JavaScript

/**
* HugeRTE version 1.0.12 (2026-06-29)
* Copyright (c) 2022 Ephox Corporation DBA Tiny Technologies, Inc.
* Copyright (c) 2026 HugeRTE contributors
* Licensed under the MIT license (https://github.com/hugerte/hugerte/blob/main/LICENSE.TXT)
*/
!function(){"use strict";var t=hugerte.util.Tools.resolve("hugerte.PluginManager");const e=t=>e=>(t=>{const e=typeof t;return null===t?"null":"object"===e&&Array.isArray(t)?"array":"object"===e&&(o=n=t,(r=String).prototype.isPrototypeOf(o)||(null===(s=n.constructor)||void 0===s?void 0:s.name)===r.name)?"string":e;var o,n,r,s})(e)===t,o=t=>e=>typeof e===t,n=e("string"),r=e("object"),s=t=>null===t;const a=o("boolean"),l=o("number");class i{constructor(t,e){this.tag=t,this.value=e}static some(t){return new i(!0,t)}static none(){return i.singletonNone}fold(t,e){return this.tag?e(this.value):t()}isSome(){return this.tag}isNone(){return!this.tag}map(t){return this.tag?i.some(t(this.value)):i.none()}bind(t){return this.tag?t(this.value):i.none()}exists(t){return this.tag&&t(this.value)}forall(t){return!this.tag||t(this.value)}filter(t){return!this.tag||t(this.value)?this:i.none()}getOr(t){return this.tag?this.value:t}or(t){return this.tag?this:t}getOrThunk(t){return this.tag?this.value:t()}orThunk(t){return this.tag?this:t()}getOrDie(t){if(this.tag)return this.value;throw new Error(null!=t?t:"Called getOrDie on None")}static from(t){return null==t?i.none():i.some(t)}getOrNull(){return this.tag?this.value:null}getOrUndefined(){return this.value}each(t){this.tag&&t(this.value)}toArray(){return this.tag?[this.value]:[]}toString(){return this.tag?`some(${this.value})`:"none()"}}i.singletonNone=new i(!1);const u=(t,e)=>{for(let o=0,n=t.length;o<n;o++)e(t[o],o)},c=Object.keys,d=(t,e)=>{const o=c(t);for(let n=0,r=o.length;n<r;n++){const r=o[n];e(t[r],r)}},h="undefined"!=typeof window?window:Function("return this;")(),g=(t,e)=>((t,e)=>{let o=null!=e?e:h;for(let e=0;e<t.length&&null!=o;++e)o=o[t[e]];return o})(t.split("."),e),m=Object.getPrototypeOf,v=t=>{const e=g("ownerDocument.defaultView",t);return r(t)&&((t=>((t,e)=>{const o=((t,e)=>g(t,e))(t,e);if(null==o)throw new Error(t+" not available on this browser");return o})("HTMLElement",t))(e).prototype.isPrototypeOf(t)||/^HTML\w*Element$/.test(m(t).constructor.name))},f=t=>t.dom.nodeValue,p=t=>e=>(t=>t.dom.nodeType)(e)===t,b=t=>w(t)&&v(t.dom),w=p(1),y=p(3),A=(t,e,o)=>{((t,e,o)=>{if(!(n(o)||a(o)||l(o)))throw console.error("Invalid call to Attribute.set. Key ",e,":: Value ",o,":: Element ",t),new Error("Attribute value was not simple");t.setAttribute(e,o+"")})(t.dom,e,o)},k=(t,e)=>{t.dom.removeAttribute(e)},N=(t,e)=>{const o=((t,e)=>{const o=t.dom.getAttribute(e);return null===o?void 0:o})(t,e);return void 0===o||""===o?[]:o.split(" ")},T=t=>void 0!==t.dom.classList,C=t=>{if(null==t)throw new Error("Node cannot be null or undefined");return{dom:t}},E=C,O={"\xa0":"nbsp","\xad":"shy"},L=(t,e)=>{let o="";return d(t,(t,e)=>{o+=e}),new RegExp("["+o+"]",e?"g":"")},V=L(O),j=L(O,!0),B=(t=>{let e="";return d(t,t=>{e&&(e+=","),e+="span.mce-"+t}),e})(O),S="mce-nbsp",x=t=>t.dom.contentEditable,M=t=>'<span data-mce-bogus="1" class="mce-'+O[t]+'">'+t+"</span>",P=t=>"span"===t.nodeName.toLowerCase()&&t.classList.contains("mce-nbsp-wrap"),_=t=>{const e=f(t);return y(t)&&n(e)&&V.test(e)},D=(t,e,o)=>{let n=[];const r=((t,e)=>{const o=t.length,n=new Array(o);for(let r=0;r<o;r++){const o=t[r];n[r]=e(o,r)}return n})(t.dom.childNodes,E);return u(r,t=>{var r;o&&(P((r=t).dom)||!(t=>b(t)&&"false"===x(t))(r))&&e(t)&&(n=n.concat([t])),n=n.concat(D(t,e,((t,e)=>{if(b(t)&&!P(t.dom)){const e=x(t);if("true"===e)return!0;if("false"===e)return!1}return e})(t,o)))}),n},H=(t,e)=>{const o=t.dom,n=D(E(e),_,t.dom.isEditable(e));u(n,e=>{var n;const r=e.dom.parentNode;if(P(r))s=E(r),a=S,T(s)?s.dom.classList.add(a):((t,e)=>{((t,e,o)=>{const n=N(t,e).concat([o]);A(t,e,n.join(" "))})(t,"class",e)})(s,a);else{const r=o.encode(null!==(n=f(e))&&void 0!==n?n:"").replace(j,M),s=o.create("div",{},r);let a;for(;a=s.lastChild;)o.insertAfter(a,e.dom);t.dom.remove(e.dom)}var s,a})},I=(t,e)=>{const o=t.dom.select(B,e);u(o,e=>{var o,n;P(e)?(o=E(e),n=S,T(o)?o.dom.classList.remove(n):((t,e)=>{((t,e,o)=>{const n=((t,e)=>{const o=[];for(let n=0,r=t.length;n<r;n++){const r=t[n];e(r)&&o.push(r)}return o})(N(t,e),t=>t!==o);n.length>0?A(t,e,n.join(" ")):k(t,e)})(t,"class",e)})(o,n),(t=>{const e=T(t)?t.dom.classList:(t=>N(t,"class"))(t);0===e.length&&k(t,"class")})(o)):t.dom.remove(e,!0)})},$=t=>{const e=t.getBody(),o=t.selection.getBookmark();let n=((t,e)=>{for(;t.parentNode;){if(t.parentNode===e)return e;t=t.parentNode}})(t.selection.getNode(),e);n=void 0!==n?n:e,I(t,n),H(t,n),t.selection.moveToBookmark(o)},F=(t,e)=>{((t,e)=>{t.dispatch("VisualChars",{state:e})})(t,e.get());const o=t.getBody();!0===e.get()?H(t,o):I(t,o)},K=t=>t.options.get("visualchars_default_state");const R=(t,e)=>{const o=(t=>{let e=null;return{cancel:()=>{s(e)||(clearTimeout(e),e=null)},throttle:(...o)=>{s(e)&&(e=setTimeout(()=>{e=null,t.apply(null,o)},300))}}})(()=>{$(t)});t.on("keydown",n=>{!0===e.get()&&(13===n.keyCode?$(t):o.throttle())}),t.on("remove",o.cancel)},U=(t,e)=>o=>{o.setActive(e.get());const n=t=>o.setActive(t.state);return t.on("VisualChars",n),()=>t.off("VisualChars",n)};t.add("visualchars",t=>{(t=>{(0,t.options.register)("visualchars_default_state",{processor:"boolean",default:!1})})(t);const e=(t=>{let e=t;return{get:()=>e,set:t=>{e=t}}})(K(t));return((t,e)=>{t.addCommand("mceVisualChars",()=>{((t,e)=>{e.set(!e.get());const o=t.selection.getBookmark();F(t,e),t.selection.moveToBookmark(o)})(t,e)})})(t,e),((t,e)=>{const o=()=>t.execCommand("mceVisualChars");t.ui.registry.addToggleButton("visualchars",{tooltip:"Show invisible characters",icon:"visualchars",onAction:o,onSetup:U(t,e)}),t.ui.registry.addToggleMenuItem("visualchars",{text:"Show invisible characters",icon:"visualchars",onAction:o,onSetup:U(t,e)})})(t,e),R(t,e),((t,e)=>{t.on("init",()=>{F(t,e)})})(t,e),(t=>({isEnabled:()=>t.get()}))(e)})}();