/*
Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
!function(){var t=!1;CKEDITOR.plugins.add("balloonpanel",{init:function(){t||(CKEDITOR.document.appendStyleSheet(this.path+"skins/"+CKEDITOR.skin.name+"/balloonpanel.css"),t=!0)}}),CKEDITOR.ui.balloonPanel=function(t,e){this.editor=t,CKEDITOR.tools.extend(this,{width:360,height:"auto",triangleWidth:20,triangleHeight:20,triangleMinDistance:40},e,!0),this.templates={};for(var i in this.templateDefinitions)this.templates[i]=new CKEDITOR.template(this.templateDefinitions[i]);this.parts={},this.focusables={},this.showListeners={},this.activeShowListeners={},this.rect={visible:!1},this.build(),t.on("destroy",function(){this.destroy()},this)},CKEDITOR.ui.balloonPanel.prototype={templateDefinitions:{panel:'
',content:'{content}
',title:'{title}
',close:'X',triangleOuter:'',triangleInner:''},build:function(){var t=this.editor;this.parts={title:CKEDITOR.dom.element.createFromHtml(this.templates.title.output({title:this.title})),close:CKEDITOR.dom.element.createFromHtml(this.templates.close.output()),panel:CKEDITOR.dom.element.createFromHtml(this.templates.panel.output({id:t.id,langDir:t.lang.dir,langCode:t.langCode,name:t.name,style:"display:none;",voiceLabel:t.lang.editorPanel+", "+t.name})),content:CKEDITOR.dom.element.createFromHtml(this.templates.content.output({content:this.content||""})),triangleOuter:CKEDITOR.dom.element.createFromHtml(this.templates.triangleOuter.output()),triangleInner:CKEDITOR.dom.element.createFromHtml(this.templates.triangleInner.output())},this.parts.panel.append(this.parts.title,1),this.parts.panel.append(this.parts.close,1),this.parts.panel.append(this.parts.triangleOuter),this.parts.panel.append(this.parts.content),this.parts.triangleOuter.append(this.parts.triangleInner),this.registerFocusable(this.parts.panel),this.registerFocusable(this.parts.close),this.parts.title.unselectable(),this.parts.close.unselectable(),CKEDITOR.document.getBody().append(this.parts.panel),this.resize(this.width,this.height),this.on("show",this.activateShowListeners,this),this.on("hide",this.deactivateShowListeners,this),this.parts.close.on("click",function(t){this.hide(),t.data.preventDefault()},this)},show:function(){this.rect.visible||(this.rect.visible=!0,this.parts.panel.show(),this.fire("show"))},hide:function(){this.rect.visible&&(this.rect.visible=!1,this.parts.panel.hide(),this.blur(),this.fire("hide"))},blur:function(){this.editor.focus()},move:function(t,e){this.rect.left=e,this.rect.top=t,this.parts.panel.setStyles({left:CKEDITOR.tools.cssLength(e),top:CKEDITOR.tools.cssLength(t)})},attach:function(){function t(t,e){var i=Math.max(0,Math.min(t.right,e.right)-Math.max(t.left,e.left)),n=Math.max(0,Math.min(t.bottom,e.bottom)-Math.max(t.top,e.top));return i*n}function e(t,e,i,n){return t={top:t,left:e},t.right=t.left+i,t.bottom=t.top+n,t}function i(t,e){return t.right=e.right,t.width=t.right-t.left,e.y&&(t.y=e.y),t}function n(t){var e=s(t,!0);return t=s(t),e=i(e[0],e.pop()),t=i(t[0],t.pop()),e.bottom=t.bottom,e.height=e.bottom-e.top,t.y&&(e.y=t.y),t.top=e.top,t.height=e.height,[e,t]}function s(t,e){var i=e?t[0]:t[t.length-1],n=e?"top":"bottom";return CKEDITOR.tools.array.filter(t,function(t){return t[n]===i[n]?t:void 0})}var o,a,l,h,r={right:"left",top:"bottom",topLeft:"bottomLeft",topRight:"bottomRight",bottom:"top",bottomLeft:"topLeft",bottomRight:"topRight",left:"right"};return function(s,c){if(s instanceof CKEDITOR.dom.selection){var g,p=s.getRanges(),p=s.isFake&&s.isInTable()?CKEDITOR.tools.array.map(p,function(t){return t.getClientRects(!0)[0]}):p[p.length-1].getClientRects(!0),m=p[0],d=p[p.length-1];g=m===d?[m]:m.top===d.top?[i(m,d)]:n(p)}(c instanceof CKEDITOR.dom.element||!c)&&(c={focusElement:c}),c=CKEDITOR.tools.extend(c,{show:!0}),!0===c.show&&this.show(),this.fire("attach"),o=CKEDITOR.document.getWindow(),a=this.editor.window.getFrame(),l=this.editor.editable(),h=l.isInline(),!h&&CKEDITOR.env.safari&&(a=a.getParent());var u,f,b,p=this.getWidth(),m=this.getHeight(),d=p*m;u=s.getClientRect&&s.getClientRect(!0);var v=h?l.getClientRect(!0):a.getClientRect(!0),_=o.getViewPaneSize(),w=o.getScrollPosition(),C={top:Math.max(v.top,w.y),left:Math.max(v.left,w.x),right:Math.min(v.right,_.width+w.x),bottom:Math.min(v.bottom,_.height+w.y)};h&&this.editor.elementMode===CKEDITOR.ELEMENT_MODE_INLINE&&(C=this._getViewPaneRect(o),C.right+=this.triangleWidth,C.bottom+=this.triangleHeight),g?(CKEDITOR.tools.array.forEach(g,function(t){this._adjustElementRect(t,h?C:v)},this),u=this._getAlignments(g[0],p,m),1