fuck-tiny-cloud/plugins/autocorrect/plugin.min.js

10 lines
12 KiB
JavaScript
Raw Normal View History

2023-11-01 22:54:59 -04:00
/*!
* Tiny Spelling Autocorrect plugin
*
* Copyright (c) 2022 Ephox Corporation DBA Tiny Technologies, Inc.
* Licensed under the Tiny commercial license. See https://www.tiny.cloud/legal/
*
* Version: 1.0.1-54
*/
!function(){"use strict";const t=t=>parseInt(t,10),e=(t,e)=>{const r=t-e;return 0===r?0:r>0?1:-1},r=(t,e,r)=>({major:t,minor:e,patch:r}),o=e=>{const o=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(e);return o?r(t(o[1]),t(o[2]),t(o[3])):r(0,0,0)},n=t=>e=>e.options.get(t),a=n("autocorrect_capitalize"),s=n("autocorrect_autocorrect"),c=("array",t=>"array"===(t=>{const e=typeof t;return null===t?"null":"object"===e&&Array.isArray(t)?"array":"object"===e&&(r=o=t,(n=String).prototype.isPrototypeOf(r)||(null===(a=o.constructor)||void 0===a?void 0:a.name)===n.name)?"string":e;var r,o,n,a})(t));const i=(void 0,t=>undefined===t);const u=t=>"function"==typeof t;class l{constructor(t,e){this.tag=t,this.value=e}static some(t){return new l(!0,t)}static none(){return l.singletonNone}fold(t,e){return this.tag?e(this.value):t()}isSome(){return this.tag}isNone(){return!this.tag}map(t){return this.tag?l.some(t(this.value)):l.none()}bind(t){return this.tag?t(this.value):l.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:l.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?l.none():l.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()"}}l.singletonNone=new l(!1);const p=(t,e,r)=>""===e||t.length>=e.length&&t.substr(r,r+e.length)===e,g=t=>""===t?"":t.charAt(0).toUpperCase()+t.substring(1),h=(t,e)=>p(t,e,0),d=(t,e)=>p(t,e,t.length-e.length),m="AutocorrectStart AutocorrectEnd",f="CapitalizeStart CapitalizeEnd",y=t=>{t.dispatch("AutocorrectStart")},v=t=>{t.dispatch("AutocorrectEnd")},T=t=>t.dispatch("CapitalizeStart"),_=t=>t.dispatch("CapitalizeEnd"),w=(t,e,r)=>{(r.cache?e.autocorrect().setAndCache:e.autocorrect().set)(r.on),(r.on?y:v)(t)},x=(t,e,r)=>{(r.cache?e.capitalize().setAndCache:e.capitalize().set)(r.on),(r.on?T:_)(t)},O=t=>{let e=t;return{get:()=>e,set:t=>{e=t}}},b=()=>{},S=t=>()=>t,k=t=>t,z=t=>t(),A=S(!1),C=S(!0),E=Object.keys,j=(t,e)=>{const r=E(t);for(let o=0,n=r.length;o<n;o++){const n=r[o];e(t[n],n)}},N=Array.prototype.push,R={normalisation:[new RegExp(["([A-Z][A-Z]+)","([a-z]+)","(\\s*)","$"].join(""))],capitalisation:[new RegExp(["([.?!]\\s+)","([a-z][^\\s]+)","(\\s*)","$"].join("")),new RegExp(["^()","([a-z][^\\s]*)","(\\s*)","$"].join(""))],autocorrect:[new RegExp(["(^|\\W)","(\\w+)","(\\W*)","(\\s*)","$"].join(""))]},I=t=>{const e=["all","start","word","endOfWord","space"];return{regexes:R.autocorrect,identify:r=>{if(r&&r.length>=e.length){const e=r[2],o=r[3]+r[4],n=e+o;return t.lookup(e).map((t=>({start:n,replacement:t+o})))}return l.none()}}},J=(t,e)=>(t=>{const e=[];for(let r=0,o=t.length;r<o;++r){if(!c(t[r]))throw new Error("Arr.flatten item "+r+" was not an array, input: "+t);N.apply(e,t[r])}return e})(((t,e)=>{const r=t.length,o=new Array(r);for(let n=0;n<r;n++){const r=t[n];o[n]=e(r,n)}return o})(e,(e=>((t,e)=>{for(let r=0;r<t.length;r++){const o=e(t[r]);if(o.isSome())return o}return l.none()})(e.regexes,(r=>{const o=t.match(r);return null!==o?e.identify(o):l.none()})).toArray())));var P;!function(t){t.JSON="json",t.Blob="blob",t.Text="text",t.FormData="formdata",t.MultipartFormData="multipart/form-data"}(P||(P={}));const F=t=>{let e=l.none(),r=[];const o=t=>{n()?a(t):r.push(t)},n=()=>e.isSome(),a=t=>{e.each((e=>{setTimeout((()=>{t(e)}),0)}))};return t((t=>{n()||(e=l.some(t),((t,e)=>{for(let r=0,o=t.length;r<o;r++)e(t[r],r)})(r,a),r=[])})),{get:o,map:t=>F((e=>{o((r=>{e(t(r))}))})),isReady:n}},D={nu:F,pure:t=>F((e=>{e(t)}))},q=t=>{setTimeout((()=>{throw t}),0)},M=t=>{const e=e=>{t().then(e,q)};return{map:e=>M((()=>t().then(e))),bind:e=>M((()=>t().then((t=>e(t).toPromise())))),anonBind:e=>M((()=>t().then((()=>e.toPromise())))),toLazy:()=>D.nu(e),toC