import{Plugin as q}from"@ckeditor/ckeditor5-core";import{ClipboardPipeline as U}from"@ckeditor/ckeditor5-clipboard";import{ViewUpcastWriter as y,Matcher as b,ViewDocument as P,ViewDomConverter as C}from"@ckeditor/ckeditor5-engine";/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function A(t,e){const n=[];for(const s of e.createRangeIn(t)){const i=s.item;i.is("element","a")&&!i.hasAttribute("href")&&(i.hasAttribute("id")||i.hasAttribute("name"))&&n.push(i)}for(const s of n){const i=s.parent.getChildIndex(s)+1,r=s.getChildren();e.insertChild(i,r,s.parent)}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function x(t){const e=parseFloat(t);return t.endsWith("pt")?g(e*96/72):t.endsWith("pc")?g(e*12*96/72):t.endsWith("in")?g(e*96):t.endsWith("cm")?g(e*96/2.54):t.endsWith("mm")?g(e/10*96/2.54):t}function S(t){return t!==void 0&&t.endsWith("px")}function g(t){return Math.round(t)+"px"}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function L(t,e,n){if(!t.childCount)return;const s=new y(t.document),i=X(t,s);if(!i.length)return;const r={},l=[];for(const o of i)if(o.indent!==void 0){J(o)||(l.length=0);const c=`${o.id}:${o.indent}`,a=Math.min(o.indent-1,l.length);if(a<l.length&&l[a].id!==o.id&&(l.length=a),a<l.length-1)l.length=a+1;else{const f=K(o,e);if(a>l.length-1||l[a].listElement.name!=f.type){a==0&&f.type=="ol"&&o.id!==void 0&&r[c]&&(f.startIndex=r[c]);const d=ee(f,s,n);if(S(o.marginLeft)&&(a==0||S(l[a-1].marginLeft))){let u=o.marginLeft;a>0&&(u=g(parseFloat(u)-parseFloat(l[a-1].marginLeft))),s.setStyle("padding-left",u,d)}if(l.length==0){const u=o.element.parent,p=u.getChildIndex(o.element)+1;s.insertChild(p,d,u)}else{const u=l[a-1].listItemElements;s.appendChild(d,u[u.length-1])}l[a]={...o,listElement:d,listItemElements:[]},a==0&&o.id!==void 0&&(r[c]=f.startIndex||1)}}const m=o.element.name=="li"?o.element:s.createElement("li");s.appendChild(m,l[a].listElement),l[a].listItemElements.push(m),a==0&&o.id!==void 0&&r[c]++,o.element!=m&&s.appendChild(o.element,m),ne(o.element,s),s.removeStyle("text-indent",o.element),s.removeStyle("margin-left",o.element)}else{const c=l.find(a=>a.marginLeft==o.marginLeft);if(c){const a=c.listItemElements;s.appendChild(o.element,a[a.length-1]),s.removeStyle("margin-left",o.element)}else l.length=0}}function w(t,e){for(const n of e.createRangeIn(t)){const s=n.item;if(s.is("element","li")){const i=s.getChild(0);i&&i.is("element","p")&&e.unwrapElement(i)}}}function X(t,e){const n=e.createRangeIn(t),s=[],i=new Set;for(const r of n.getItems()){if(!r.is("element")||!r.name.match(/^(p|h\d+|li|div)$/))continue;let l=se(r);if(l!==void 0&&parseFloat(l)==0&&!Array.from(r.getClassNames()).find(o=>o.startsWith("MsoList"))&&(l=void 0),r.hasStyle("mso-list")||l!==void 0&&i.has(l)){const o=te(r);s.push({element:r,id:o.id,order:o.order,indent:o.indent,marginLeft:l}),l!==void 0&&i.add(l)}else i.clear()}return s}function J(t){const e=t.element.previousSibling;if(!e){const n=t.element.parent;return v(n)&&(!n.previousSibling||v(n.previousSibling))}return v(e)}function v(t){return t.is("element","ol")||t.is("element","ul")}function K(t,e){const n=new RegExp(`@list l${t.id}:level${t.indent}\\s*({[^}]*)`,"gi"),s=/mso-level-number-format:([^;]{0,100});/gi,i=/mso-level-start-at:\s{0,100}([0-9]{0,10})\s{0,100};/gi,r=new RegExp(`@list\\s+l${t.id}:level\\d\\s*{[^{]*mso-level-text:"%\\d\\\\.`,"gi"),l=new RegExp(`@list l${t.id}:level\\d\\s*{[^{]*mso-level-number-format:`,"gi"),o=r.exec(e),c=l.exec(e),a=o&&!c,m=n.exec(e);let f="decimal",d="ol",u=null;if(m&&m[1]){const p=s.exec(m[1]);if(p&&p[1]&&(f=p[1].trim(),d=f!=="bullet"&&f!=="image"?"ol":"ul"),f==="bullet"){const h=Q(t.element);h&&(f=h)}else{const h=i.exec(m[1]);h&&h[1]&&(u=parseInt(h[1]))}a&&(d="ol")}return{type:d,startIndex:u,style:Z(f),isLegalStyleList:a}}function Q(t){if(t.name=="li"&&t.parent.name=="ul"&&t.parent.hasAttribute("type"))return t.parent.getAttribute("type");const e=Y(t);if(!e)return null;const n=e._data;return n==="o"?"circle":n==="\xB7"?"disc":n==="\xA7"?"square":null}function Y(t){if(t.getChild(0).is("$text"))return null;for(const e of t.getChildren()){if(!e.is("element","span"))continue;const n=e.getChild(0);if(n)return n.is("$text")?n:n.getChild(0)}/* istanbul ignore next -- @preserve */return null}function Z(t){if(t.startsWith("arabic-leading-zero"))return"decimal-leading-zero";switch(t){case"alpha-upper":return"upper-alpha";case"alpha-lower":return"lower-alpha";case"roman-upper":return"upper-roman";case"roman-lower":return"lower-roman";case"circle":case"disc":case"square":return t;default:return null}}function ee(t,e,n){const s=e.createElement(t.type);return t.style&&e.setStyle("list-style-type",t.style,s),t.startIndex&&t.startIndex>1&&e.setAttribute("start",t.startIndex,s),t.isLegalStyleList&&n&&e.addClass("legal-list",s),s}function te(t){const e=t.getStyle("mso-list");if(e===void 0)return{};const n=e.match(/(^|\s{1,100})l(\d+)/i),s=e.match(/\s{0,100}lfo(\d+)/i),i=e.match(/\s{0,100}level(\d+)/i);return n&&s&&i?{id:n[2],order:s[1],indent:parseInt(i[1])}:{indent:1}}function ne(t,e){const n=new b({name:"span",styles:{"mso-list":"Ignore"}}),s=e.createRangeIn(t);for(const i of s)i.type==="elementStart"&&n.match(i.item)&&e.remove(i.item)}function se(t){const e=t.getStyle("margin-left");return e===void 0||e.endsWith("px")?e:x(e)}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function E(t,e){if(!t.childCount)return;const n=new y(t.document),s=ie(t,n);oe(s,t,n),le(s,t,n),re(t,n);const i=ae(t,n);i.length&&fe(i,ce(e),n)}function M(t){return btoa(t.match(/\w{2}/g).map(e=>String.fromCharCode(parseInt(e,16))).join(""))}function ie(t,e){const n=e.createRangeIn(t),s=new b({name:/v:(.+)/}),i=[];for(const r of n){if(r.type!="elementStart")continue;const l=r.item,o=l.previousSibling,c=o&&o.is("element")?o.name:null,a=["Chart"],m=s.match(l),f=l.getAttribute("o:gfxdata"),d=c==="v:shapetype",u=f&&a.some(p=>l.getAttribute("id").includes(p));m&&f&&!d&&!u&&i.push(r.item.getAttribute("id"))}return i}function oe(t,e,n){const s=n.createRangeIn(e),i=new b({name:"img"}),r=[];for(const l of s)if(l.item.is("element")&&i.match(l.item)){const o=l.item,c=o.getAttribute("v:shapes")?o.getAttribute("v:shapes").split(" "):[];c.length&&c.every(a=>t.indexOf(a)>-1)?r.push(o):o.getAttribute("src")||r.push(o)}for(const l of r)n.remove(l)}function re(t,e){const n=e.createRangeIn(t),s=new b({name:/v:(.+)/}),i=[];for(const r of n)r.type=="elementStart"&&s.match(r.item)&&i.push(r.item);for(const r of i)e.remove(r)}function le(t,e,n){const s=n.createRangeIn(e),i=[];for(const o of s)if(o.type=="elementStart"&&o.item.is("element","v:shape")){const c=o.item.getAttribute("id");if(t.includes(c))continue;r(o.item.parent.getChildren(),c)||i.push(o.item)}for(const o of i){const c={src:l(o)};o.hasAttribute("alt")&&(c.alt=o.getAttribute("alt"));const a=n.createElement("img",c);n.insertChild(o.index+1,a,o.parent)}function r(o,c){for(const a of o){/* istanbul ignore else -- @preserve */if(a.is("element")&&(a.name=="img"&&a.getAttribute("v:shapes")==c||r(a.getChildren(),c)))return!0}return!1}function l(o){for(const c of o.getChildren()){/* istanbul ignore else -- @preserve */if(c.is("element")&&c.getAttribute("src"))return c.getAttribute("src")}}}function ae(t,e){const n=e.createRangeIn(t),s=new b({name:"img"}),i=[];let r=0;for(const l of n)l.item.is("element")&&s.match(l.item)&&(l.item.getAttribute("src").startsWith("file://")&&i.push({element:l.item,imageIndex:r}),r++);return i}function ce(t){if(!t)return[];const e=/{\\pict[\s\S]+?\\bliptag-?\d+(\\blipupi-?\d+)?({\\\*\\blipuid\s?[\da-fA-F]+)?[\s}]*?/,n=new RegExp("(?:("+e.source+"))([\\da-fA-F\\s]+)\\}","g"),s=t.match(n),i=[];if(s)for(const r of s){let l=!1;r.includes("\\pngblip")?l="image/png":r.includes("\\jpegblip")&&(l="image/jpeg"),l&&i.push({hex:r.replace(e,"").replace(/[^\da-fA-F]/g,""),type:l})}return i}function fe(t,e,n){for(let s=0;s<t.length;s++){const{element:i,imageIndex:r}=t[s],l=e[r];if(l){const o=`data:${l.type};base64,${M(l.hex)}`;n.setAttribute("src",o,i)}}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function T(t){const e=[],n=new y(t.document);for(const{item:s}of n.createRangeIn(t))if(s.is("element")){for(const i of s.getClassNames())/\bmso/gi.exec(i)&&n.removeClass(i,s);for(const i of s.getStyleNames())/\bmso/gi.exec(i)&&n.removeStyle(i,s);(s.is("element","w:sdt")||s.is("element","w:sdtpr")&&s.isEmpty||s.is("element","o:p")&&s.isEmpty)&&e.push(s)}for(const s of e){const i=s.parent,r=i.getChildIndex(s);n.insertChild(r,s.getChildren(),i),n.remove(s)}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function O(t,e){for(const n of e.createRangeIn(t).getItems()){if(!n.is("element","table")&&!n.is("element","td")&&!n.is("element","th"))continue;const s=["left","top","right","bottom"];if(s.every(r=>!n.hasStyle(`border-${r}-style`)))e.setStyle("border-style","none",n);else for(const r of s)n.hasStyle(`border-${r}-style`)||e.setStyle(`border-${r}-style`,"none",n);const i=["width","height",...s.map(r=>`border-${r}-width`),...s.map(r=>`padding-${r}`)];for(const r of i)n.hasStyle(r)&&e.setStyle(r,x(n.getStyle(r)),n)}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function I(t,e){for(const n of e.createRangeIn(t).getItems())n.is("element","table")&&(n.getStyle("width")==="0px"&&e.removeStyle("width",n),n.getAttribute("width")==="0"&&e.removeAttribute("width",n))}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/const me=/<meta\s*name="?generator"?\s*content="?microsoft\s*word\s*\d+"?\/?>/i,ue=/xmlns:o="urn:schemas-microsoft-com/i;class R{document;hasMultiLevelListPlugin;constructor(e,n=!1){this.document=e,this.hasMultiLevelListPlugin=n}isActive(e){return me.test(e)||ue.test(e)}execute(e){const n=new y(this.document),{body:s,stylesString:i}=e._parsedData;A(s,n),L(s,i,this.hasMultiLevelListPlugin),E(s,e.dataTransfer.getData("text/rtf")),O(s,n),I(s,n),T(s),e.content=s}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function W(t,e){for(const n of t.getChildren())if(n.is("element","b")&&n.getStyle("font-weight")==="normal"){const s=t.getChildIndex(n);e.remove(n),e.insertChild(s,n.getChildren(),t)}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function k(t,e){const n=new P(e.document.stylesProcessor),s=new C(n,{renderingMode:"data"}),i=s.blockElements,r=s.inlineObjectElements,l=[];for(const o of e.createRangeIn(t)){const c=o.item;if(c.is("element","br")){const a=_(c,"forward",e,{blockElements:i,inlineObjectElements:r}),m=_(c,"backward",e,{blockElements:i,inlineObjectElements:r}),f=B(a,i);(B(m,i)||f)&&l.push(c)}}for(const o of l)o.hasClass("Apple-interchange-newline")?e.remove(o):e.replace(o,e.createElement("p"))}function _(t,e,n,{blockElements:s,inlineObjectElements:i}){let r=n.createPositionAt(t,e=="forward"?"after":"before");return r=r.getLastMatchingPosition(({item:l})=>l.is("element")&&!s.includes(l.name)&&!i.includes(l.name),{direction:e}),e=="forward"?r.nodeAfter:r.nodeBefore}function B(t,e){return!!t&&t.is("element")&&e.includes(t.name)}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function de(t,e,n){const s=new Set;for(const i of e.createRangeIn(t).getItems())!i.is("view:$textProxy")||!i.data.includes("	")||pe(i.parent)&&s.add(i.textNode);for(const i of s)ge(i,e,n)}function pe(t){let e=t;for(;e;){if(e.is("element")&&e.getStyle?.("white-space")==="pre-wrap")return!0;e=e.parent}return!1}function ge(t,e,n){const{parent:s,data:i}=t,r=i.replaceAll("	"," ".repeat(n)),l=s.getChildIndex(t);e.remove(t),e.insertChild(l,e.createText(r),s)}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/const he=/id=("|')docs-internal-guid-[-0-9a-f]+("|')/i;class N{document;constructor(e){this.document=e}isActive(e){return he.test(e)}execute(e){const n=new y(this.document),{body:s}=e._parsedData;W(s,n),w(s,n),k(s,n),de(s,n,8),e.content=s}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function D(t,e){for(const n of t.getChildren())n.is("element","table")&&n.hasAttribute("xmlns")&&e.removeAttribute("xmlns",n)}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function $(t,e){for(const n of t.getChildren())if(n.is("element","google-sheets-html-origin")){const s=t.getChildIndex(n);e.remove(n),e.insertChild(s,n.getChildren(),t)}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function z(t,e){for(const n of Array.from(t.getChildren()))n.is("element","style")&&e.remove(n)}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/const ye=/<google-sheets-html-origin/i;class F{document;constructor(e){this.document=e}isActive(e){return ye.test(e)}execute(e){const n=new y(this.document),{body:s}=e._parsedData;$(s,n),D(s,n),I(s,n),z(s,n),e.content=s}}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function V(t){return G(G(t)).replace(/(<span\s+style=['"]mso-spacerun:yes['"]>[^\S\r\n]*?)[\r\n]+([^\S\r\n]*<\/span>)/g,"$1$2").replace(/<span\s+style=['"]mso-spacerun:yes['"]><\/span>/g,"").replace(/(<span\s+style=['"]letter-spacing:[^'"]+?['"]>)[\r\n]+(<\/span>)/g,"$1 $2").replace(/ <\//g,"\xA0</").replace(/ <o:p><\/o:p>/g,"\xA0<o:p></o:p>").replace(/<o:p>(&nbsp;|\u00A0)<\/o:p>/g,"").replace(/>([^\S\r\n]*[\r\n]\s*)</g,"><")}function j(t){t.querySelectorAll("span[style*=spacerun]").forEach(e=>{const n=e,s=n.innerText.length||0;n.innerText=Array(s+1).join("\xA0 ").substr(0,s)})}function G(t){return t.replace(/<span(?: class="Apple-converted-space"|)>(\s+)<\/span>/g,(e,n)=>n.length===1?" ":Array(n.length+1).join("\xA0 ").substr(0,n.length))}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/function H(t,e){const n=new DOMParser;t=t.replace(/<!--\[if gte vml 1]>/g,""),t=t.replace(/<o:SmartTagType(?:\s+[^\s>=]+(?:="[^"]*")?)*\s*\/?>/gi,"");const s=V(Se(t)),i=n.parseFromString(s,"text/html");j(i);const r=i.body.innerHTML,l=be(i,e),o=xe(i);return{body:l,bodyString:r,styles:o.styles,stylesString:o.stylesString}}function be(t,e){const n=new P(e),s=new C(n,{renderingMode:"data"}),i=t.createDocumentFragment(),r=t.body.childNodes;for(;r.length>0;)i.appendChild(r[0]);return s.domToView(i,{skipComments:!0})}function xe(t){const e=[],n=[],s=Array.from(t.getElementsByTagName("style"));for(const i of s)i.sheet&&i.sheet.cssRules&&i.sheet.cssRules.length&&(e.push(i.sheet),n.push(i.innerHTML));return{styles:e,stylesString:n.join(" ")}}function Se(t){const e="</body>",n="</html>",s=t.indexOf(e);if(s<0)return t;const i=t.indexOf(n,s+e.length);return t.substring(0,s+e.length)+(i>=0?t.substring(i):"")}/**
* @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
*/class ve extends q{static get pluginName(){return"PasteFromOffice"}static get licenseFeatureCode(){return"PFO"}static get isOfficialPlugin(){return!0}static get isPremiumPlugin(){return!0}static get requires(){return[U]}init(){const e=this.editor,n=e.plugins.get("ClipboardPipeline"),s=e.editing.view.document,i=[],r=this.editor.plugins.has("MultiLevelList");i.push(new R(s,r)),i.push(new N(s)),i.push(new F(s)),n.on("inputTransformation",(l,o)=>{if(o._isTransformedWithPasteFromOffice||e.model.document.selection.getFirstPosition().parent.is("element","codeBlock"))return;const a=o.dataTransfer.getData("text/html"),m=i.find(f=>f.isActive(a));m&&(o._parsedData||(o._parsedData=H(a,s.stylesProcessor)),m.execute(o),o._isTransformedWithPasteFromOffice=!0)},{priority:"high"})}}export{ve as PasteFromOffice,N as PasteFromOfficeGoogleDocsNormalizer,F as PasteFromOfficeGoogleSheetsNormalizer,R as PasteFromOfficeMSWordNormalizer,M as _convertHexToBase64,x as _convertPasteOfficeCssLengthToPx,S as _isPasteOfficePxValue,j as _normalizePasteOfficeSpaceRunSpans,V as _normalizePasteOfficeSpacing,$ as _removePasteGoogleOfficeSheetsTag,T as _removePasteMSOfficeAttributes,W as _removePasteOfficeBoldWrapper,I as _removePasteOfficeInvalidTableWidths,z as _removePasteOfficeStyleBlock,D as _removePasteOfficeXmlnsAttributes,E as _replacePasteOfficeImagesSourceWithBase64,g as _toPasteOfficePxValue,k as _transformPasteOfficeBlockBrsToParagraphs,A as _transformPasteOfficeBookmarks,L as _transformPasteOfficeListItemLikeElementsIntoLists,O as _transformPasteOfficeTables,w as _unwrapPasteOfficeParagraphInListItem,H as parsePasteOfficeHtml};
