/*! * Tiny AI plugin * * Copyright (c) 2023 Ephox Corporation DBA Tiny Technologies, Inc. * Licensed under the Tiny commercial license. See https://www.tiny.cloud/legal/ * * Version: 7.0.0-22 */ !function(){"use strict";const e=e=>parseInt(e,10),t=(e,t)=>{const n=e-t;return 0===n?0:n>0?1:-1},n=(e,t,n)=>({major:e,minor:t,patch:n}),r=t=>{const r=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(t);return r?n(e(r[1]),e(r[2]),e(r[3])):n(0,0,0)},o=e=>t=>(e=>{const t=typeof e;return null===e?"null":"object"===t&&Array.isArray(e)?"array":"object"===t&&(n=r=e,(o=String).prototype.isPrototypeOf(n)||(null===(s=r.constructor)||void 0===s?void 0:s.name)===o.name)?"string":t;var n,r,o,s})(t)===e,s=e=>t=>typeof t===e,i=o("string"),a=o("object"),l=o("array"),c=s("boolean"),p=e=>!(e=>null==e)(e),u=s("function"),m=()=>{};function d(e,...t){return(...n)=>{const r=t.concat(n);return e.apply(null,r)}}const g=e=>{e()},h=()=>!1;class y{constructor(e,t){this.tag=e,this.value=t}static some(e){return new y(!0,e)}static none(){return y.singletonNone}fold(e,t){return this.tag?t(this.value):e()}isSome(){return this.tag}isNone(){return!this.tag}map(e){return this.tag?y.some(e(this.value)):y.none()}bind(e){return this.tag?e(this.value):y.none()}exists(e){return this.tag&&e(this.value)}forall(e){return!this.tag||e(this.value)}filter(e){return!this.tag||e(this.value)?this:y.none()}getOr(e){return this.tag?this.value:e}or(e){return this.tag?this:e}getOrThunk(e){return this.tag?this.value:e()}orThunk(e){return this.tag?this:e()}getOrDie(e){if(this.tag)return this.value;throw new Error(null!=e?e:"Called getOrDie on None")}static from(e){return p(e)?y.some(e):y.none()}getOrNull(){return this.tag?this.value:null}getOrUndefined(){return this.value}each(e){this.tag&&e(this.value)}toArray(){return this.tag?[this.value]:[]}toString(){return this.tag?`some(${this.value})`:"none()"}}y.singletonNone=new y(!1);const f=(e,t)=>{for(let n=0,r=e.length;nb.call(e,t),w=(e,t)=>e?y.some(t):y.none(),A="generate",T="insert",I="discard",E="stop",S="regenerate",x="prompt",C="AI shortcuts",R="ai-prompt",k="Integration Error: {0}.",O="Response was not a string",D="respondWith was not used",_="An error occurred.",N=[{title:"Summarize content",prompt:"Provide the key points and concepts in this content in a succinct summary.",selection:!0},{title:"Improve writing",prompt:"Rewrite this content with no spelling mistakes, proper grammar, and with more descriptive language, using best writing practices without losing the original meaning.",selection:!0},{title:"Simplify language",prompt:"Rewrite this content with simplified language and reduce the complexity of the writing, so that the content is easier to understand.",selection:!0},{title:"Expand upon",prompt:"Expand upon this content with descriptive language and more detailed explanations, to make the writing easier to understand and increase the length of the content.",selection:!0},{title:"Trim content",prompt:"Remove any repetitive, redundant, or non-essential writing in this content without changing the meaning or losing any key information.",selection:!0},{title:"Change tone",subprompts:[{title:"Professional",prompt:"Rewrite this content using polished, formal, and respectful language to convey professional expertise and competence.",selection:!0},{title:"Casual",prompt:"Rewrite this content with casual, informal language to convey a casual conversation with a real person.",selection:!0},{title:"Direct",prompt:"Rewrite this content with direct language using only the essential information.",selection:!0},{title:"Confident",prompt:"Rewrite this content using compelling, optimistic language to convey confidence in the writing.",selection:!0},{title:"Friendly",prompt:"Rewrite this content using friendly, comforting language, to convey understanding and empathy.",selection:!0}]},{title:"Change style",subprompts:[{title:"Business",prompt:"Rewrite this content as a business professional with formal language.",selection:!0},{title:"Legal",prompt:"Rewrite this content as a legal professional using valid legal terminology.",selection:!0},{title:"Journalism",prompt:"Rewrite this content as a journalist using engaging language to convey the importance of the information.",selection:!0},{title:"Medical",prompt:"Rewrite this content as a medical professional using valid medical terminology.",selection:!0},{title:"Poetic",prompt:"Rewrite this content as a poem using poetic techniques without losing the original meaning.",selection:!0}]}],M=e=>t=>t.options.get(e),q=(j="ai_request",e=>(e=>t=>y.from(M(e)(t)).filter(u))(j)(e).getOrDie(j+" has not been implemented."));var j;const L=e=>y.from(M("ai_shortcuts")(e)).filter((e=>e.length>0)),$=M("body_class"),P=M("content_style"),B=M("content_css_cors"),z=(e,t)=>t.parse(e,{insert:!0}),U=(e,t)=>{e.execCommand("mceAiDialog",!1,t)},H=(e,t)=>n=>{const r=e=>()=>n.setEnabled(e),o=r(!0),s=r(!1);return e.on("AIResponse AIError AIDialogClose",o),e.on("AIRequest",s),t.isInProgress()?s():o(),()=>{e.off("AIResponse AIError AIDialogClose",o),e.off("AIRequest",s)}},K=(e,t)=>n=>(n.setEnabled(y.from(t.selection).forall((t=>e.selection.isCollapsed()!==t))),m),W=(e,t)=>((t,n)=>{const r=t.length,o=new Array(r);for(let n=0;n{return v(t=e,n="subprompts")&&void 0!==t[n]&&null!==t[n];var t,n})(s=r)?((e,t)=>({type:"nestedmenuitem",text:t.title,getSubmenuItems:()=>W(e,t.subprompts)}))(e,s):((e,t)=>({type:"menuitem",text:t.title,value:t.prompt,onSetup:K(e,t),onAction:()=>U(e,{prompt:t.prompt,generate:!0,display:!1})}))(e,s)}var s;return o})(t),J=e=>(t,n)=>{const r=(o=i(n)?z(n,t.parser):n,s=t.schema,tinymce.html.Serializer({validate:!0},s).serialize(o));var o,s;const a=y.from(P(t)).map((e=>``)).getOr(""),l=y.from(B(t)).map((e=>e?' crossorigin="anonymous"':"")).getOr(""),c=(p=t.contentCSS,u=(e,n)=>`${e}`,m="",f(p,((e,t)=>{m=u(m,e)})),m);var p,u,m;const d=t.dom.encode,g=`` class="${d(e)}"`)).getOr("")}${y.from(t.getBody()).map((e=>d(e.dir))).bind((e=>w(""!==e,` dir="${e}"`))).getOr("")}>`,h=tinymce.Env.os,b='