/** * Copyright (c) Tiny Technologies, Inc. All rights reserved. * Licensed under the LGPL or a commercial license. * For LGPL see License.txt in the project root for license information. * For commercial licenses see https://www.tiny.cloud/ * * Version: 5.3.1 (2020-05-27) */ !function(f){"use strict";var t=tinymce.util.Tools.resolve("tinymce.PluginManager"),u=function(){return(u=Object.assign||function(t){for(var n,r=1,e=arguments.length;rn.start.length?-1:1},(e=b.call(n,0)).sort(r),e;var n,r,e},U=function(o){var a=function(t){return D.error({message:t,pattern:o})},t=function(t,n,r){if(o.format===undefined)return o.cmd!==undefined?p(o.cmd)?D.value(r(o.cmd,o.value)):a(t+" pattern has non-string `cmd` parameter"):a(t+" pattern is missing both `format` and `cmd` parameters");var e=void 0;if(v(o.format)){if(!T(o.format,p))return a(t+" pattern has non-string items in the `format` array");e=o.format}else{if(!p(o.format))return a(t+" pattern has non-string `format` parameter");e=[o.format]}return D.value(n(e))};if(!h(o))return a("Raw pattern is not an object");if(!p(o.start))return a("Raw pattern is missing `start` parameter");if(o.end===undefined)return o.replacement!==undefined?p(o.replacement)?0===o.start.length?a("Replacement pattern has empty `start` parameter"):D.value({type:"inline-command",start:"",end:o.start,cmd:"mceInsertContent",value:o.replacement}):a("Replacement pattern has non-string `replacement` parameter"):0===o.start.length?a("Block pattern has empty `start` parameter"):t("Block",function(t){return{type:"block-format",start:o.start,format:t[0]}},function(t,n){return{type:"block-command",start:o.start,cmd:t,value:n}});if(!p(o.end))return a("Inline pattern has non-string `end` parameter");if(0===o.start.length&&0===o.end.length)return a("Inline pattern has empty `start` and `end` parameters");var r=o.start,e=o.end;return 0===e.length&&(e=r,r=""),t("Inline",function(t){return{type:"inline-format",start:r,end:e,format:t}},function(t,n){return{type:"inline-command",start:r,end:e,cmd:t,value:n}})},q=function(t){return"block-command"===t.type?{start:t.start,cmd:t.cmd,value:t.value}:"block-format"===t.type?{start:t.start,format:t.format}:"inline-command"===t.type?"mceInsertContent"===t.cmd&&""===t.start?{start:t.end,replacement:t.value}:{start:t.start,end:t.end,cmd:t.cmd,value:t.value}:"inline-format"===t.type?{start:t.start,end:t.end,format:1===t.format.length?t.format[0]:t.format}:void 0},L=function(t){return{inlinePatterns:E(t,I),blockPatterns:_(E(t,j))}},V=function(e){return{setPatterns:function(t){var n=M(w(t,U));if(0n.data.length))return[];for(var e=[r],o=n;o!==t&&o.parentNode;){for(var a=o.parentNode,i=0;i=t.length)return y.some(Z(t,n));var e=Y(at);return y.from(e.forwards(t,n,it(t),r)).map(function(t){return Z(t.container,0)})})(o,0,o).each(function(t){var r=t.container;ct(r,n.start.length,o).each(function(t){var n=e.createRng();n.setStart(r,0),n.setEnd(t.container,t.offset),nt(e,n,function(t){return t===o})})})},ht=function(e,a){var i=e.dom,t=e.selection.getRng();return ot(e,t).filter(function(t){var n=J(e),r=""===n&&i.is(t,"body")||i.is(t,n);return null!==t&&r}).bind(function(n){var t,r,e,o=n.textContent;return(t=a,e=(r=o).replace("\xa0"," "),R(t,function(t){return 0===r.indexOf(t.start)||0===e.indexOf(t.start)})).map(function(t){return z.trim(o).length===t.start.length?[]:[{pattern:t,range:dt(i.getRoot(),n,0,n,0)}]})}).getOr([])},vt=function(i,t){if(0!==t.length){var n=i.selection.getBookmark();C(t,function(t){return r=t,e=(n=i).dom,o=r.pattern,a=gt(e.getRoot(),r.range).getOrDie("Unable to resolve path range"),ot(n,a).each(function(t){"block-format"===o.type?rt(o.format,n.formatter)&&n.undoManager.transact(function(){pt(n.dom,t,o),n.formatter.apply(o.format)}):"block-command"===o.type&&n.undoManager.transact(function(){pt(n.dom,t,o),n.execCommand(o.cmd,!1,o.value)})}),1;var n,r,e,o,a}),i.selection.moveToBookmark(n)}},yt=0,bt=function(t,n){return t.create("span",{"data-mce-type":"bookmark",id:n})},kt=function(t,n){var r=t.createRng();return r.setStartAfter(n.start),r.setEndBefore(n.end),r},Ot=function(t,n,r){var e=gt(t.getRoot(),r).getOrDie("Unable to resolve path range"),o=e.startContainer,a=e.endContainer,i=0===e.endOffset?a:a.splitText(e.endOffset),u=0===e.startOffset?o:o.splitText(e.startOffset);return{prefix:n,end:i.parentNode.insertBefore(bt(t,n+"-end"),i),start:u.parentNode.insertBefore(bt(t,n+"-start"),u)}},wt=function(t,n,r){tt(t,t.get(n.prefix+"-end"),r),tt(t,t.get(n.prefix+"-start"),r)},Ct=function(e,o,a,t){var i,u=o.start;return st(e,t.container,t.offset,(i=u,function(t,n){var r=t.data.substring(0,n),e=r.lastIndexOf(i.charAt(i.length-1)),o=r.lastIndexOf(i);return-1!==o?o+i.length:-1!==e?e+1:-1}),a).bind(function(r){if(r.offset>=u.length){var t=e.createRng();return t.setStart(r.container,r.offset-u.length),t.setEnd(r.container,r.offset),y.some(t)}var n=r.offset-u.length;return ft(r.container,n,a).map(function(t){var n=e.createRng();return n.setStart(t.container,t.offset),n.setEnd(r.container,r.offset),n}).filter(function(t){return t.toString()===u}).orThunk(function(){return Ct(e,o,a,Z(r.container,0))})})},Et=function(a,i,u){var f=a.dom,c=f.getRoot(),s=u.pattern,l=u.position.container,d=u.position.offset;return ft(l,d-u.pattern.end.length,i).bind(function(t){var e=dt(c,t.container,t.offset,l,d);if(et(s))return y.some({matches:[{pattern:s,startRng:e,endRng:e}],position:t});var n=xt(a,u.remainingPatterns,t.container,t.offset,i),o=n.getOr({matches:[],position:t}),r=o.position;return function(t,r,n,e,o,a){if(void 0===a&&(a=!1),0!==r.start.length||a)return ut(n,e,o).bind(function(n){return Ct(t,r,o,n).bind(function(t){if(a){if(t.endContainer===n.container&&t.endOffset===n.offset)return y.none();if(0===n.offset&&t.endContainer.textContent.length===t.endOffset)return y.none()}return y.some(t)})});var i=t.createRng();return i.setStart(n,e),i.setEnd(n,e),y.some(i)}(f,s,r.container,r.offset,i,n.isNone()).map(function(t){var n,r=dt(c,(n=t).startContainer,n.startOffset,n.endContainer,n.endOffset);return{matches:o.matches.concat([{pattern:s,startRng:r,endRng:e}]),position:Z(t.startContainer,t.startOffset)}})})},xt=function(d,m,g,p,h){var v=d.dom;return ut(g,p,v.getRoot()).bind(function(t){var n=v.createRng();n.setStart(h,0),n.setEnd(g,p);for(var r,e,o,a,i,u=n.toString(),f=0;f=a.length&&o.substr(i,i+a.length)===a){var s=m.slice();s.splice(f,1);var l=Et(d,h,{pattern:c,remainingPatterns:s,position:t});if(l.isSome())return l}}return y.none()})},Rt=function(n,t,r){n.selection.setRng(r),"inline-format"===t.type?C(t.format,function(t){n.formatter.apply(t)}):n.execCommand(t.cmd,!1,t.value)},Tt=function(o,t){var n,r,a=(n="mce_textpattern",r=(new Date).getTime(),n+"_"+Math.floor(1e9*Math.random())+ ++yt+String(r)),i=x(t,function(t,n){var r=Ot(o,a+"_end"+t.length,n.endRng);return t.concat([u(u({},n),{endMarker:r})])},[]);return x(i,function(t,n){var r=i.length-t.length-1,e=et(n.pattern)?n.endMarker:Ot(o,a+"_start"+r,n.startRng);return t.concat([u(u({},n),{startMarker:e})])},[])},Nt=function(r,e,o){var a=r.selection.getRng();return!1===a.collapsed?[]:ot(r,a).bind(function(t){var n=a.startOffset-(o?1:0);return xt(r,e,a.startContainer,n,t)}).fold(function(){return[]},function(t){return t.matches})},Pt=function(f,t){if(0!==t.length){var c=f.dom,n=f.selection.getBookmark(),r=Tt(c,t);C(r,function(t){var n,r,e,o,a,i=c.getParent(t.startMarker.start,c.isBlock),u=function(t){return t===i};et(t.pattern)?(n=f,r=t.pattern,e=t.endMarker,o=u,a=kt(n.dom,e),nt(n.dom,a,o),Rt(n,r,a)):function(t,n,r,e,o){var a=t.dom,i=kt(a,e),u=kt(a,r);nt(a,u,o),nt(a,i,o);var f={prefix:r.prefix,start:r.end,end:e.start},c=kt(a,f);Rt(t,n,c)}(f,t.pattern,t.startMarker,t.endMarker,u),wt(c,t.endMarker,u),wt(c,t.startMarker,u)}),f.selection.moveToBookmark(n)}},St=function(t,n){var r=Nt(t,n.inlinePatterns,!0);0