@ckeditor/ckeditor5-paste-from-office 47.5.0 → 47.6.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  /*!
2
2
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md.
4
- */(()=>{var e={237:e=>{"use strict";e.exports=CKEditor5.dll},331:(e,t,n)=>{e.exports=n(237)("./src/clipboard.js")},782:(e,t,n)=>{e.exports=n(237)("./src/core.js")},783:(e,t,n)=>{e.exports=n(237)("./src/engine.js")}},t={};function n(i){var s=t[i];if(void 0!==s)return s.exports;var r=t[i]={exports:{}};return e[i](r,r.exports,n),r.exports}n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};(()=>{"use strict";n.r(i),n.d(i,{PasteFromOffice:()=>G,PasteFromOfficeGoogleDocsNormalizer:()=>k,PasteFromOfficeGoogleSheetsNormalizer:()=>N,PasteFromOfficeMSWordNormalizer:()=>T,_convertHexToBase64:()=>x,_convertPasteOfficeCssLengthToPx:()=>o,_isPasteOfficePxValue:()=>l,_normalizePasteOfficeSpaceRunSpans:()=>U,_normalizePasteOfficeSpacing:()=>z,_removePasteGoogleOfficeSheetsTag:()=>B,_removePasteMSOfficeAttributes:()=>S,_removePasteOfficeBoldWrapper:()=>L,_removePasteOfficeInvalidTableWidths:()=>C,_removePasteOfficeStyleBlock:()=>D,_removePasteOfficeXmlnsAttributes:()=>j,_replacePasteOfficeImagesSourceWithBase64:()=>v,_toPasteOfficePxValue:()=>a,_transformPasteOfficeBlockBrsToParagraphs:()=>_,_transformPasteOfficeBookmarks:()=>s,_transformPasteOfficeListItemLikeElementsIntoLists:()=>c,_transformPasteOfficeTables:()=>w,_unwrapPasteOfficeParagraphInListItem:()=>f,parsePasteOfficeHtml:()=>H});var e=n(782),t=n(331);function s(e,t){const n=[];for(const i of t.createRangeIn(e)){const e=i.item;e.is("element","a")&&!e.hasAttribute("href")&&(e.hasAttribute("id")||e.hasAttribute("name"))&&n.push(e)}for(const e of n){const n=e.parent.getChildIndex(e)+1,i=e.getChildren();t.insertChild(n,i,e.parent)}}var r=n(783);function o(e){const t=parseFloat(e);return e.endsWith("pt")?a(96*t/72):e.endsWith("pc")?a(12*t*96/72):e.endsWith("in")?a(96*t):e.endsWith("cm")?a(96*t/2.54):e.endsWith("mm")?a(t/10*96/2.54):e}function l(e){return void 0!==e&&e.endsWith("px")}function a(e){return Math.round(e)+"px"}function c(e,t,n){if(!e.childCount)return;const i=new r.ViewUpcastWriter(e.document),s=function(e,t){const n=t.createRangeIn(e),i=[],s=new Set;for(const e of n.getItems()){if(!e.is("element")||!e.name.match(/^(p|h\d+|li|div)$/))continue;let t=y(e);if(void 0===t||0!=parseFloat(t)||Array.from(e.getClassNames()).find(e=>e.startsWith("MsoList"))||(t=void 0),e.hasStyle("mso-list")&&"none"!==e.getStyle("mso-list")||void 0!==t&&s.has(t)){const n=h(e);i.push({element:e,id:n.id,order:n.order,indent:n.indent,marginLeft:t}),void 0!==t&&s.add(t)}else s.clear()}return i}(e,i);if(!s.length)return;const o={},c=[];for(const e of s)if(void 0!==e.indent){m(e)||(c.length=0);const s=`${e.id}:${e.indent}`,r=Math.min(e.indent-1,c.length);if(r<c.length&&c[r].id!==e.id&&(c.length=r),r<c.length-1)c.length=r+1;else{const f=d(e,t);if(r>c.length-1||c[r].listElement.name!=f.type){0==r&&"ol"==f.type&&void 0!==e.id&&o[s]&&(f.startIndex=o[s]);const t=p(f,i,n);if(l(e.marginLeft)&&(0==r||l(c[r-1].marginLeft))){let n=e.marginLeft;r>0&&(n=a(parseFloat(n)-parseFloat(c[r-1].marginLeft))),i.setStyle("padding-left",n,t)}if(0==c.length){const n=e.element.parent,s=n.getChildIndex(e.element)+1;i.insertChild(s,t,n)}else{const e=c[r-1].listItemElements;i.appendChild(t,e[e.length-1])}c[r]={...e,listElement:t,listItemElements:[]},0==r&&void 0!==e.id&&(o[s]=f.startIndex||1)}}const f="li"==e.element.name?e.element:i.createElement("li");i.appendChild(f,c[r].listElement),c[r].listItemElements.push(f),0==r&&void 0!==e.id&&o[s]++,e.element!=f&&i.appendChild(e.element,f),b(e.element,i),i.removeStyle("text-indent",e.element),i.removeStyle("margin-left",e.element)}else{const t=c.find(t=>t.marginLeft==e.marginLeft);if(t){const n=t.listItemElements;i.appendChild(e.element,n[n.length-1]),i.removeStyle("margin-left",e.element)}else c.length=0}}function f(e,t){for(const n of t.createRangeIn(e)){const e=n.item;if(e.is("element","li")){const n=e.getChild(0);n&&n.is("element","p")&&t.unwrapElement(n)}}}function m(e){const t=e.element.previousSibling;if(!t){const t=e.element.parent;return u(t)&&(!t.previousSibling||u(t.previousSibling))}return u(t)}function u(e){return e.is("element","ol")||e.is("element","ul")}function d(e,t){const n=new RegExp(`@list l${e.id}:level${e.indent}\\s*({[^}]*)`,"gi"),i=/mso-level-number-format:([^;]{0,100});/gi,s=/mso-level-start-at:\s{0,100}([0-9]{0,10})\s{0,100};/gi,r=new RegExp(`@list\\s+l${e.id}:level\\d\\s*{[^{]*mso-level-text:"%\\d\\\\.`,"gi"),o=new RegExp(`@list l${e.id}:level\\d\\s*{[^{]*mso-level-number-format:`,"gi"),l=r.exec(t),a=o.exec(t),c=l&&!a,f=n.exec(t);let m="decimal",u="ol",d=null;if(f&&f[1]){const t=i.exec(f[1]);if(t&&t[1]&&(m=t[1].trim(),u="bullet"!==m&&"image"!==m?"ol":"ul"),"bullet"===m){const t=function(e){if("li"==e.name&&"ul"==e.parent.name&&e.parent.hasAttribute("type"))return e.parent.getAttribute("type");const t=function(e){if(e.getChild(0).is("$text"))return null;for(const t of e.getChildren()){if(!t.is("element","span"))continue;const e=t.getChild(0);if(e)return e.is("$text")?e:e.getChild(0)}return null}(e);if(!t)return null;const n=t._data;if("o"===n)return"circle";if("·"===n)return"disc";if("§"===n)return"square";return null}(e.element);t&&(m=t)}else{const e=s.exec(f[1]);e&&e[1]&&(d=parseInt(e[1]))}c&&(u="ol")}return{type:u,startIndex:d,style:g(m),isLegalStyleList:c}}function g(e){if(e.startsWith("arabic-leading-zero"))return"decimal-leading-zero";switch(e){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 e;default:return null}}function p(e,t,n){const i=t.createElement(e.type);return e.style&&t.setStyle("list-style-type",e.style,i),e.startIndex&&e.startIndex>1&&t.setAttribute("start",e.startIndex,i),e.isLegalStyleList&&n&&t.addClass("legal-list",i),i}function h(e){const t=e.getStyle("mso-list");if(void 0===t)return{};const n=t.match(/(^|\s{1,100})l(\d+)/i),i=t.match(/\s{0,100}lfo(\d+)/i),s=t.match(/\s{0,100}level(\d+)/i);return n&&i&&s?{id:n[2],order:i[1],indent:parseInt(s[1])}:{indent:1}}function b(e,t){const n=new r.Matcher({name:"span",styles:{"mso-list":"Ignore"}}),i=t.createRangeIn(e);for(const e of i)"elementStart"===e.type&&n.match(e.item)&&t.remove(e.item)}function y(e){const t=e.getStyle("margin-left");return void 0===t||t.endsWith("px")?t:o(t)}function v(e,t){if(!e.childCount)return;const n=new r.ViewUpcastWriter(e.document),i=function(e,t){const n=t.createRangeIn(e),i=new r.Matcher({name:/v:(.+)/}),s=[];for(const e of n){if("elementStart"!=e.type)continue;const t=e.item,n=t.previousSibling,r=n&&n.is("element")?n.name:null,o=["Chart"],l=i.match(t),a=t.getAttribute("o:gfxdata"),c="v:shapetype"===r,f=a&&o.some(e=>t.getAttribute("id").includes(e));l&&a&&!c&&!f&&s.push(e.item.getAttribute("id"))}return s}(e,n);!function(e,t,n){const i=n.createRangeIn(t),s=new r.Matcher({name:"img"}),o=[];for(const t of i)if(t.item.is("element")&&s.match(t.item)){const n=t.item,i=n.getAttribute("v:shapes")?n.getAttribute("v:shapes").split(" "):[];i.length&&i.every(t=>e.indexOf(t)>-1)?o.push(n):n.getAttribute("src")||o.push(n)}for(const e of o)n.remove(e)}(i,e,n),function(e,t,n){const i=n.createRangeIn(t),s=[];for(const t of i)if("elementStart"==t.type&&t.item.is("element","v:shape")){const n=t.item.getAttribute("id");if(e.includes(n))continue;r(t.item.parent.getChildren(),n)||s.push(t.item)}for(const e of s){const t={src:o(e)};e.hasAttribute("alt")&&(t.alt=e.getAttribute("alt"));const i=n.createElement("img",t);n.insertChild(e.index+1,i,e.parent)}function r(e,t){for(const n of e)if(n.is("element")){if("img"==n.name&&n.getAttribute("v:shapes")==t)return!0;if(r(n.getChildren(),t))return!0}return!1}function o(e){for(const t of e.getChildren())if(t.is("element")&&t.getAttribute("src"))return t.getAttribute("src")}}(i,e,n),function(e,t){const n=t.createRangeIn(e),i=new r.Matcher({name:/v:(.+)/}),s=[];for(const e of n)"elementStart"==e.type&&i.match(e.item)&&s.push(e.item);for(const e of s)t.remove(e)}(e,n);const s=function(e,t){const n=t.createRangeIn(e),i=new r.Matcher({name:"img"}),s=[];let o=0;for(const e of n)e.item.is("element")&&i.match(e.item)&&(e.item.getAttribute("src").startsWith("file://")&&s.push({element:e.item,imageIndex:o}),o++);return s}(e,n);s.length&&function(e,t,n){for(let i=0;i<e.length;i++){const{element:s,imageIndex:r}=e[i],o=t[r];if(o){const e=`data:${o.type};base64,${x(o.hex)}`;n.setAttribute("src",e,s)}}}(s,function(e){if(!e)return[];const t=/{\\pict[\s\S]+?\\bliptag-?\d+(\\blipupi-?\d+)?({\\\*\\blipuid\s?[\da-fA-F]+)?[\s}]*?/,n=new RegExp("(?:("+t.source+"))([\\da-fA-F\\s]+)\\}","g"),i=e.match(n),s=[];if(i)for(const e of i){let n=!1;e.includes("\\pngblip")?n="image/png":e.includes("\\jpegblip")&&(n="image/jpeg"),n&&s.push({hex:e.replace(t,"").replace(/[^\da-fA-F]/g,""),type:n})}return s}(t),n)}function x(e){return btoa(e.match(/\w{2}/g).map(e=>String.fromCharCode(parseInt(e,16))).join(""))}function S(e){const t=[],n=new r.ViewUpcastWriter(e.document);for(const{item:i}of n.createRangeIn(e))if(i.is("element")){for(const e of i.getClassNames())/\bmso/gi.exec(e)&&n.removeClass(e,i);for(const e of i.getStyleNames())/\bmso/gi.exec(e)&&n.removeStyle(e,i);(i.is("element","w:sdt")||i.is("element","w:sdtpr")&&i.isEmpty||i.is("element","o:p")&&i.isEmpty)&&t.push(i)}for(const e of t){const t=e.parent,i=t.getChildIndex(e);n.insertChild(i,e.getChildren(),t),n.remove(e)}}function w(e,t,n=!1,i=!1){for(const s of t.createRangeIn(e).getItems()){if(!s.is("element","table")&&!s.is("element","td")&&!s.is("element","th"))continue;if(n&&i&&s.is("element","table")){const e=s.parent?.is("element","div")?s.parent:null,n=s.parent?.parent?.is("element","div")?s.parent.parent:null,i=e??n;i&&"center"===i.getAttribute("align")&&!s.getAttribute("align")?(t.setStyle("margin-left","auto",s),t.setStyle("margin-right","auto",s)):i&&"right"===i.getAttribute("align")&&!s.getAttribute("align")?(t.setStyle("margin-left","auto",s),t.setStyle("margin-right","0",s)):i||s.getAttribute("align")||(t.setStyle("margin-left","0",s),t.setStyle("margin-right","auto",s))}const e=["left","top","right","bottom"];if(e.every(e=>!s.hasStyle(`border-${e}-style`)))t.setStyle("border-style","none",s);else for(const n of e)s.hasStyle(`border-${n}-style`)||t.setStyle(`border-${n}-style`,"none",s);const r=["width","height",...e.map(e=>`border-${e}-width`),...e.map(e=>`padding-${e}`)];for(const e of r)s.hasStyle(e)&&t.setStyle(e,o(s.getStyle(e)),s)}}function C(e,t){for(const n of t.createRangeIn(e).getItems())n.is("element","table")&&("0px"===n.getStyle("width")&&t.removeStyle("width",n),"0"===n.getAttribute("width")&&t.removeAttribute("width",n))}function P(e,t){const n=[],i=[];for(const{item:s}of e.createRangeIn(t))if(s.is("element")&&s.getStyle("mso-footnote-id")){n.unshift(s);const{nextSibling:e}=s;e?.is("$text")&&e.data.startsWith(" ")&&i.unshift(e)}for(const t of n)e.remove(t);for(const t of i){const n=t.data.substring(1);if(n.length>0){const i=t.parent,s=i.getChildIndex(t),r=e.createText(n);e.remove(t),e.insertChild(s,r,i)}else e.remove(t)}return t}function A(e,t){const n=e.createElement("sup",{class:"footnote"}),i=e.createElement("a",{id:`ref-${t}`,href:`#${t}`});return e.appendChild(i,n),n}function I(e,t){const n=e.createElement("li",{id:t,class:"footnote-definition"}),i=e.createElement("a",{href:`#ref-${t}`,class:"footnote-backlink"}),s=e.createElement("div",{class:"footnote-content"});return e.appendChild(e.createText("^"),i),e.appendChild(i,n),e.appendChild(s,n),{listItem:n,content:s}}const E=/<meta\s*name="?generator"?\s*content="?microsoft\s*word\s*\d+"?\/?>/i,O=/xmlns:o="urn:schemas-microsoft-com/i;class T{document;hasMultiLevelListPlugin;hasTablePropertiesPlugin;hasExtendedTableBlockAlignment;constructor(e,t=!1,n=!1,i=!1){this.document=e,this.hasMultiLevelListPlugin=t,this.hasTablePropertiesPlugin=n,this.hasExtendedTableBlockAlignment=i}isActive(e){return E.test(e)||O.test(e)}execute(e){const t=new r.ViewUpcastWriter(this.document),{body:n,stylesString:i}=e._parsedData;s(n,t),c(n,i,this.hasMultiLevelListPlugin),v(n,e.dataTransfer.getData("text/rtf")),w(n,t,this.hasTablePropertiesPlugin,this.hasExtendedTableBlockAlignment),C(n,t),function(e,t){const n=new Map,i=new Map;let s=null;for(const{item:r}of t.createRangeIn(e))if(r.is("element"))if("footnote-list"!==r.getStyle("mso-element")){if(r.hasStyle("mso-footnote-id")){const e=r.findAncestor("element",e=>"footnote"===e.getStyle("mso-element"));if(e){const t=e.getAttribute("id");i.set(t,e)}else{const e=r.getStyle("mso-footnote-id");n.set(e,r)}continue}}else s=r;if(!n.size||!s)return;const r=function(e){return e.createElement("ol",{class:"footnotes"})}(t);t.replace(s,r);for(const[e,s]of n){const n=i.get(e);if(!n)continue;t.replace(s,A(t,e));const o=I(t,e);P(t,n);for(const e of n.getChildren()){let n=e;e.is("element")&&(n=t.clone(e,!0)),t.appendChild(n,o.content)}t.appendChild(o.listItem,r)}}(n,t),S(n),e.content=n}}function L(e,t){for(const n of e.getChildren())if(n.is("element","b")&&"normal"===n.getStyle("font-weight")){const i=e.getChildIndex(n);t.remove(n),t.insertChild(i,n.getChildren(),e)}}function _(e,t){const n=new r.ViewDocument(t.document.stylesProcessor),i=new r.ViewDomConverter(n,{renderingMode:"data"}),s=i.blockElements,o=i.inlineObjectElements,l=[];for(const n of t.createRangeIn(e)){const e=n.item;if(e.is("element","br")){const n=$(e,"forward",t,{blockElements:s,inlineObjectElements:o}),i=$(e,"backward",t,{blockElements:s,inlineObjectElements:o}),r=M(n,s);(M(i,s)||r)&&l.push(e)}}for(const e of l)e.hasClass("Apple-interchange-newline")?t.remove(e):t.replace(e,t.createElement("p"))}function $(e,t,n,{blockElements:i,inlineObjectElements:s}){let r=n.createPositionAt(e,"forward"==t?"after":"before");return r=r.getLastMatchingPosition(({item:e})=>e.is("element")&&!i.includes(e.name)&&!s.includes(e.name),{direction:t}),"forward"==t?r.nodeAfter:r.nodeBefore}function M(e,t){return!!e&&e.is("element")&&t.includes(e.name)}function R(e){let t=e;for(;t;){if(t.is("element")){const e=t.getStyle?.("white-space");if("pre-wrap"===e)return!0}t=t.parent}return!1}function W(e,t,n){const{parent:i,data:s}=e,r=s.replaceAll("\t"," ".repeat(n)),o=i.getChildIndex(e);t.remove(e),t.insertChild(o,t.createText(r),i)}const F=/id=("|')docs-internal-guid-[-0-9a-f]+("|')/i;class k{document;constructor(e){this.document=e}isActive(e){return F.test(e)}execute(e){const t=new r.ViewUpcastWriter(this.document),{body:n}=e._parsedData;L(n,t),f(n,t),_(n,t),function(e,t,n){const i=new Set;for(const n of t.createRangeIn(e).getItems())n.is("view:$textProxy")&&n.data.includes("\t")&&R(n.parent)&&i.add(n.textNode);for(const e of i)W(e,t,n)}(n,t,8),e.content=n}}function j(e,t){for(const n of e.getChildren())n.is("element","table")&&n.hasAttribute("xmlns")&&t.removeAttribute("xmlns",n)}function B(e,t){for(const n of e.getChildren())if(n.is("element","google-sheets-html-origin")){const i=e.getChildIndex(n);t.remove(n),t.insertChild(i,n.getChildren(),e)}}function D(e,t){for(const n of Array.from(e.getChildren()))n.is("element","style")&&t.remove(n)}const V=/<google-sheets-html-origin/i;class N{document;constructor(e){this.document=e}isActive(e){return V.test(e)}execute(e){const t=new r.ViewUpcastWriter(this.document),{body:n}=e._parsedData;B(n,t),j(n,t),C(n,t),D(n,t),e.content=n}}function z(e){return q(q(e)).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," </").replace(/ <o:p><\/o:p>/g," <o:p></o:p>").replace(/<o:p>(&nbsp;|\u00A0)<\/o:p>/g,"").replace(/>([^\S\r\n]*[\r\n]\s*)</g,"><")}function U(e){e.querySelectorAll("span[style*=spacerun]").forEach(e=>{const t=e,n=t.innerText.length||0;t.innerText=Array(n+1).join("  ").substr(0,n)})}function q(e){return e.replace(/<span(?: class="Apple-converted-space"|)>(\s+)<\/span>/g,(e,t)=>1===t.length?" ":Array(t.length+1).join("  ").substr(0,t.length))}function H(e,t){const n=new DOMParser,i=z(function(e){const t="</body>",n="</html>",i=e.indexOf(t);if(i<0)return e;const s=e.indexOf(n,i+t.length);return e.substring(0,i+t.length)+(s>=0?e.substring(s):"")}(e=(e=e.replace(/<!--\[if gte vml 1]>/g,"")).replace(/<o:SmartTagType(?:\s+[^\s>=]+(?:="[^"]*")?)*\s*\/?>/gi,""))),s=n.parseFromString(i,"text/html");U(s);const o=s.body.innerHTML,l=function(e,t){const n=new r.ViewDocument(t),i=new r.ViewDomConverter(n,{renderingMode:"data"}),s=e.createDocumentFragment(),o=e.body.childNodes;for(;o.length>0;)s.appendChild(o[0]);return i.domToView(s,{skipComments:!0})}(s,t),a=function(e){const t=[],n=[],i=Array.from(e.getElementsByTagName("style"));for(const e of i)e.sheet&&e.sheet.cssRules&&e.sheet.cssRules.length&&(t.push(e.sheet),n.push(e.innerHTML));return{styles:t,stylesString:n.join(" ")}}(s);return{body:l,bodyString:o,styles:a.styles,stylesString:a.stylesString}}class G extends e.Plugin{static get pluginName(){return"PasteFromOffice"}static get licenseFeatureCode(){return"PFO"}static get isOfficialPlugin(){return!0}static get isPremiumPlugin(){return!0}static get requires(){return[t.ClipboardPipeline]}init(){const e=this.editor,t=e.plugins.get("ClipboardPipeline"),n=e.editing.view.document,i=[],s=this.editor.plugins.has("MultiLevelListEditing"),r=this.editor.plugins.has("TablePropertiesEditing"),o=!!this.editor.config.get("experimentalFlags.useExtendedTableBlockAlignment");i.push(new T(n,s,r,o)),i.push(new k(n)),i.push(new N(n)),t.on("inputTransformation",(t,s)=>{if(s._isTransformedWithPasteFromOffice)return;if(e.model.document.selection.getFirstPosition().parent.is("element","codeBlock"))return;const r=s.dataTransfer.getData("text/html"),o=i.find(e=>e.isActive(r));o&&(s._parsedData||(s._parsedData=H(r,n.stylesProcessor)),o.execute(s),s._isTransformedWithPasteFromOffice=!0)},{priority:"high"})}}})(),(window.CKEditor5=window.CKEditor5||{}).pasteFromOffice=i})();
4
+ */(()=>{var e={237:e=>{"use strict";e.exports=CKEditor5.dll},331:(e,t,n)=>{e.exports=n(237)("./src/clipboard.js")},782:(e,t,n)=>{e.exports=n(237)("./src/core.js")},783:(e,t,n)=>{e.exports=n(237)("./src/engine.js")}},t={};function n(i){var s=t[i];if(void 0!==s)return s.exports;var r=t[i]={exports:{}};return e[i](r,r.exports,n),r.exports}n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};(()=>{"use strict";n.r(i),n.d(i,{PasteFromOffice:()=>J,PasteFromOfficeGoogleDocsNormalizer:()=>D,PasteFromOfficeGoogleSheetsNormalizer:()=>q,PasteFromOfficeMSWordNormalizer:()=>_,_convertHexToBase64:()=>C,_convertPasteOfficeCssLengthToPx:()=>o,_isPasteOfficePxValue:()=>l,_normalizePasteOfficeSpaceRunSpans:()=>G,_normalizePasteOfficeSpacing:()=>H,_removePasteGoogleOfficeSheetsTag:()=>N,_removePasteMSOfficeAttributes:()=>A,_removePasteOfficeBoldWrapper:()=>$,_removePasteOfficeInvalidTableWidths:()=>I,_removePasteOfficeStyleBlock:()=>z,_removePasteOfficeXmlnsAttributes:()=>V,_replacePasteOfficeImagesSourceWithBase64:()=>w,_toPasteOfficePxValue:()=>a,_transformPasteOfficeBlockBrsToParagraphs:()=>R,_transformPasteOfficeBookmarks:()=>s,_transformPasteOfficeListItemLikeElementsIntoLists:()=>c,_transformPasteOfficeTables:()=>P,_unwrapPasteOfficeParagraphInListItem:()=>d,parsePasteOfficeHtml:()=>X});var e=n(782),t=n(331);function s(e,t){const n=[];for(const i of t.createRangeIn(e)){const e=i.item;e.is("element","a")&&!e.hasAttribute("href")&&(e.hasAttribute("id")||e.hasAttribute("name"))&&n.push(e)}for(const e of n){const n=e.parent.getChildIndex(e)+1,i=e.getChildren();t.insertChild(n,i,e.parent)}}var r=n(783);function o(e){const t=parseFloat(e);return e.endsWith("pt")?a(96*t/72):e.endsWith("pc")?a(12*t*96/72):e.endsWith("in")?a(96*t):e.endsWith("cm")?a(96*t/2.54):e.endsWith("mm")?a(t/10*96/2.54):e}function l(e){return void 0!==e&&e.endsWith("px")}function a(e){return Math.round(e)+"px"}function c(e,t,n){if(!e.childCount)return;const i=new r.ViewUpcastWriter(e.document),s=function(e,t){const n=t.createRangeIn(e),i=[],s=new Set;for(const e of n.getItems()){if(!e.is("element")||!e.name.match(/^(p|h\d+|li|div)$/))continue;let t=S(e);if(void 0===t||0!=parseFloat(t)||Array.from(e.getClassNames()).find(e=>e.startsWith("MsoList"))||(t=void 0),e.hasStyle("mso-list")&&"none"!==e.getStyle("mso-list")||void 0!==t&&s.has(t)){const n=v(e);i.push({element:e,id:n.id,order:n.order,indent:n.indent,marginLeft:t}),void 0!==t&&s.add(t)}else s.clear()}return i}(e,i);if(!s.length)return;const o={},l=[];let a=m();for(const e of s)if(void 0!==e.indent){g(e)||(u(i,l,a),a=m(),l.length=0);const s=`${e.id}:${e.indent}`,r=Math.min(e.indent-1,l.length);if(r<l.length&&l[r].id!==e.id&&(l.length=r),r<l.length-1)l.length=r+1;else{const a=h(e,t);if(r>l.length-1||l[r].listElement.name!=a.type){0==r&&"ol"==a.type&&void 0!==e.id&&o[s]&&(a.startIndex=o[s]);const t=b(a,i,n);if(0==l.length){const n=e.element.parent,s=n.getChildIndex(e.element)+1;i.insertChild(s,t,n)}else{const e=l[r-1].listItemElements;i.appendChild(t,e[e.length-1])}l[r]={...e,listElement:t,listItemElements:[]},0==r&&void 0!==e.id&&(o[s]=a.startIndex||1)}}const c="li"==e.element.name?e.element:i.createElement("li");f(i,l,a,e,c,r),i.appendChild(c,l[r].listElement),l[r].listItemElements.push(c),0==r&&void 0!==e.id&&o[s]++,e.element!=c&&i.appendChild(e.element,c),x(e.element,i),i.removeStyle("text-indent",e.element),i.removeStyle("margin-left",e.element)}else{const t=l.find(t=>t.marginLeft==e.marginLeft);if(t){const n=t.listItemElements;i.appendChild(e.element,n[n.length-1]),i.removeStyle("margin-left",e.element)}else l.length=0}u(i,l,a)}function f(e,t,n,i,s,r){if(void 0===i.marginLeft)return void(0==r&&(n.canApplyMarginOnList=!1));const o=parseFloat(i.marginLeft);let l=0;if(t.length>1){const e=t[t.length-2].listItemElements;if(e.length>0){const t=e[e.length-1].getStyle("margin-left");void 0!==t&&(l+=parseFloat(t))}}l+=40*t.length;const c=o-l,f=0!==c?a(c):void 0;f&&(e.setStyle("margin-left",f,s),0==r&&n.canApplyMarginOnList&&(void 0===n.marginLeft&&(n.marginLeft=f),f!==n.marginLeft&&(n.canApplyMarginOnList=!1),n.topLevelListItemElements.push(s)))}function m(){return{marginLeft:void 0,canApplyMarginOnList:!0,topLevelListItemElements:[]}}function u(e,t,n){if(n.canApplyMarginOnList&&n.marginLeft&&n.topLevelListItemElements.length>0){e.setStyle("margin-left",n.marginLeft,t[0].listElement);for(const t of n.topLevelListItemElements)e.removeStyle("margin-left",t)}}function d(e,t){for(const n of t.createRangeIn(e)){const e=n.item;if(e.is("element","li")){const n=e.getChild(0);n&&n.is("element","p")&&t.unwrapElement(n)}}}function g(e){const t=e.element.previousSibling;if(!t){const t=e.element.parent;return p(t)&&(!t.previousSibling||p(t.previousSibling))}return p(t)}function p(e){return e.is("element","ol")||e.is("element","ul")}function h(e,t){const n=new RegExp(`@list l${e.id}:level${e.indent}\\s*({[^}]*)`,"gi"),i=/mso-level-number-format:([^;]{0,100});/gi,s=/mso-level-start-at:\s{0,100}([0-9]{0,10})\s{0,100};/gi,r=new RegExp(`@list\\s+l${e.id}:level\\d\\s*{[^{]*mso-level-text:"%\\d\\\\.`,"gi"),o=new RegExp(`@list l${e.id}:level\\d\\s*{[^{]*mso-level-number-format:`,"gi"),l=r.exec(t),a=o.exec(t),c=l&&!a,f=n.exec(t);let m="decimal",u="ol",d=null;if(f&&f[1]){const t=i.exec(f[1]);if(t&&t[1]&&(m=t[1].trim(),u="bullet"!==m&&"image"!==m?"ol":"ul"),"bullet"===m){const t=function(e){if("li"==e.name&&"ul"==e.parent.name&&e.parent.hasAttribute("type"))return e.parent.getAttribute("type");const t=function(e){if(e.getChild(0).is("$text"))return null;for(const t of e.getChildren()){if(!t.is("element","span"))continue;const e=t.getChild(0);if(e)return e.is("$text")?e:e.getChild(0)}return null}(e);if(!t)return null;const n=t._data;if("o"===n)return"circle";if("·"===n)return"disc";if("§"===n)return"square";return null}(e.element);t&&(m=t)}else{const e=s.exec(f[1]);e&&e[1]&&(d=parseInt(e[1]))}c&&(u="ol")}return{type:u,startIndex:d,style:y(m),isLegalStyleList:c}}function y(e){if(e.startsWith("arabic-leading-zero"))return"decimal-leading-zero";switch(e){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 e;default:return null}}function b(e,t,n){const i=t.createElement(e.type);return e.style&&t.setStyle("list-style-type",e.style,i),e.startIndex&&e.startIndex>1&&t.setAttribute("start",e.startIndex,i),e.isLegalStyleList&&n&&t.addClass("legal-list",i),i}function v(e){const t=e.getStyle("mso-list");if(void 0===t)return{};const n=t.match(/(^|\s{1,100})l(\d+)/i),i=t.match(/\s{0,100}lfo(\d+)/i),s=t.match(/\s{0,100}level(\d+)/i);return n&&i&&s?{id:n[2],order:i[1],indent:parseInt(s[1])}:{indent:1}}function x(e,t){const n=new r.Matcher({name:"span",styles:{"mso-list":"Ignore"}}),i=t.createRangeIn(e);for(const e of i)"elementStart"===e.type&&n.match(e.item)&&t.remove(e.item)}function S(e){const t=e.getStyle("margin-left");return void 0===t||t.endsWith("px")?t:o(t)}function w(e,t){if(!e.childCount)return;const n=new r.ViewUpcastWriter(e.document),i=function(e,t){const n=t.createRangeIn(e),i=new r.Matcher({name:/v:(.+)/}),s=[];for(const e of n){if("elementStart"!=e.type)continue;const t=e.item,n=t.previousSibling,r=n&&n.is("element")?n.name:null,o=["Chart"],l=i.match(t),a=t.getAttribute("o:gfxdata"),c="v:shapetype"===r,f=a&&o.some(e=>t.getAttribute("id").includes(e));l&&a&&!c&&!f&&s.push(e.item.getAttribute("id"))}return s}(e,n);!function(e,t,n){const i=n.createRangeIn(t),s=new r.Matcher({name:"img"}),o=[];for(const t of i)if(t.item.is("element")&&s.match(t.item)){const n=t.item,i=n.getAttribute("v:shapes")?n.getAttribute("v:shapes").split(" "):[];i.length&&i.every(t=>e.indexOf(t)>-1)?o.push(n):n.getAttribute("src")||o.push(n)}for(const e of o)n.remove(e)}(i,e,n),function(e,t,n){const i=n.createRangeIn(t),s=[];for(const t of i)if("elementStart"==t.type&&t.item.is("element","v:shape")){const n=t.item.getAttribute("id");if(e.includes(n))continue;r(t.item.parent.getChildren(),n)||s.push(t.item)}for(const e of s){const t={src:o(e)};e.hasAttribute("alt")&&(t.alt=e.getAttribute("alt"));const i=n.createElement("img",t);n.insertChild(e.index+1,i,e.parent)}function r(e,t){for(const n of e)if(n.is("element")){if("img"==n.name&&n.getAttribute("v:shapes")==t)return!0;if(r(n.getChildren(),t))return!0}return!1}function o(e){for(const t of e.getChildren())if(t.is("element")&&t.getAttribute("src"))return t.getAttribute("src")}}(i,e,n),function(e,t){const n=t.createRangeIn(e),i=new r.Matcher({name:/v:(.+)/}),s=[];for(const e of n)"elementStart"==e.type&&i.match(e.item)&&s.push(e.item);for(const e of s)t.remove(e)}(e,n);const s=function(e,t){const n=t.createRangeIn(e),i=new r.Matcher({name:"img"}),s=[];let o=0;for(const e of n)e.item.is("element")&&i.match(e.item)&&(e.item.getAttribute("src").startsWith("file://")&&s.push({element:e.item,imageIndex:o}),o++);return s}(e,n);s.length&&function(e,t,n){for(let i=0;i<e.length;i++){const{element:s,imageIndex:r}=e[i],o=t[r];if(o){const e=`data:${o.type};base64,${C(o.hex)}`;n.setAttribute("src",e,s)}}}(s,function(e){if(!e)return[];const t=/{\\pict[\s\S]+?\\bliptag-?\d+(\\blipupi-?\d+)?({\\\*\\blipuid\s?[\da-fA-F]+)?[\s}]*?/,n=new RegExp("(?:("+t.source+"))([\\da-fA-F\\s]+)\\}","g"),i=e.match(n),s=[];if(i)for(const e of i){let n=!1;e.includes("\\pngblip")?n="image/png":e.includes("\\jpegblip")&&(n="image/jpeg"),n&&s.push({hex:e.replace(t,"").replace(/[^\da-fA-F]/g,""),type:n})}return s}(t),n)}function C(e){return btoa(e.match(/\w{2}/g).map(e=>String.fromCharCode(parseInt(e,16))).join(""))}function A(e){const t=[],n=new r.ViewUpcastWriter(e.document);for(const{item:i}of n.createRangeIn(e))if(i.is("element")){for(const e of i.getClassNames())/\bmso/gi.exec(e)&&n.removeClass(e,i);for(const e of i.getStyleNames())/\bmso/gi.exec(e)&&n.removeStyle(e,i);(i.is("element","w:sdt")||i.is("element","w:sdtpr")&&i.isEmpty||i.is("element","o:p")&&i.isEmpty)&&t.push(i)}for(const e of t){const t=e.parent,i=t.getChildIndex(e);n.insertChild(i,e.getChildren(),t),n.remove(e)}}function P(e,t,n=!1,i=!1){for(const s of t.createRangeIn(e).getItems()){if(!s.is("element","table")&&!s.is("element","td")&&!s.is("element","th"))continue;if(n&&i&&s.is("element","table")){const e=s.parent?.is("element","div")?s.parent:null,n=s.parent?.parent?.is("element","div")?s.parent.parent:null,i=e??n;i&&"center"===i.getAttribute("align")&&!s.getAttribute("align")?(t.setStyle("margin-left","auto",s),t.setStyle("margin-right","auto",s)):i&&"right"===i.getAttribute("align")&&!s.getAttribute("align")?(t.setStyle("margin-left","auto",s),t.setStyle("margin-right","0",s)):i||s.getAttribute("align")||(t.setStyle("margin-left","0",s),t.setStyle("margin-right","auto",s))}const e=["left","top","right","bottom"];if(e.every(e=>!s.hasStyle(`border-${e}-style`)))t.setStyle("border-style","none",s);else for(const n of e)s.hasStyle(`border-${n}-style`)||t.setStyle(`border-${n}-style`,"none",s);const r=["width","height",...e.map(e=>`border-${e}-width`),...e.map(e=>`padding-${e}`)];for(const e of r)s.hasStyle(e)&&t.setStyle(e,o(s.getStyle(e)),s)}}function I(e,t){for(const n of t.createRangeIn(e).getItems())n.is("element","table")&&("0px"===n.getStyle("width")&&t.removeStyle("width",n),"0"===n.getAttribute("width")&&t.removeAttribute("width",n))}function E(e,t){const n=[],i=[];for(const{item:s}of e.createRangeIn(t))if(s.is("element")&&s.getStyle("mso-footnote-id")){n.unshift(s);const{nextSibling:e}=s;e?.is("$text")&&e.data.startsWith(" ")&&i.unshift(e)}for(const t of n)e.remove(t);for(const t of i){const n=t.data.substring(1);if(n.length>0){const i=t.parent,s=i.getChildIndex(t),r=e.createText(n);e.remove(t),e.insertChild(s,r,i)}else e.remove(t)}return t}function O(e,t){const n=e.createElement("sup",{class:"footnote"}),i=e.createElement("a",{id:`ref-${t}`,href:`#${t}`});return e.appendChild(i,n),n}function L(e,t){const n=e.createElement("li",{id:t,class:"footnote-definition"}),i=e.createElement("a",{href:`#ref-${t}`,class:"footnote-backlink"}),s=e.createElement("div",{class:"footnote-content"});return e.appendChild(e.createText("^"),i),e.appendChild(i,n),e.appendChild(s,n),{listItem:n,content:s}}const T=/<meta\s*name="?generator"?\s*content="?microsoft\s*word\s*\d+"?\/?>/i,M=/xmlns:o="urn:schemas-microsoft-com/i;class _{document;hasMultiLevelListPlugin;hasTablePropertiesPlugin;hasExtendedTableBlockAlignment;constructor(e,t=!1,n=!1,i=!1){this.document=e,this.hasMultiLevelListPlugin=t,this.hasTablePropertiesPlugin=n,this.hasExtendedTableBlockAlignment=i}isActive(e){return T.test(e)||M.test(e)}execute(e){const t=new r.ViewUpcastWriter(this.document),{body:n,stylesString:i}=e._parsedData;s(n,t),c(n,i,this.hasMultiLevelListPlugin),w(n,e.dataTransfer.getData("text/rtf")),P(n,t,this.hasTablePropertiesPlugin,this.hasExtendedTableBlockAlignment),I(n,t),function(e,t){const n=new Map,i=new Map;let s=null;for(const{item:r}of t.createRangeIn(e))if(r.is("element"))if("footnote-list"!==r.getStyle("mso-element")){if(r.hasStyle("mso-footnote-id")){const e=r.findAncestor("element",e=>"footnote"===e.getStyle("mso-element"));if(e){const t=e.getAttribute("id");i.set(t,e)}else{const e=r.getStyle("mso-footnote-id");n.set(e,r)}continue}}else s=r;if(!n.size||!s)return;const r=function(e){return e.createElement("ol",{class:"footnotes"})}(t);t.replace(s,r);for(const[e,s]of n){const n=i.get(e);if(!n)continue;t.replace(s,O(t,e));const o=L(t,e);E(t,n);for(const e of n.getChildren()){let n=e;e.is("element")&&(n=t.clone(e,!0)),t.appendChild(n,o.content)}t.appendChild(o.listItem,r)}}(n,t),A(n),e.content=n}}function $(e,t){for(const n of e.getChildren())if(n.is("element","b")&&"normal"===n.getStyle("font-weight")){const i=e.getChildIndex(n);t.remove(n),t.insertChild(i,n.getChildren(),e)}}function R(e,t){const n=new r.ViewDocument(t.document.stylesProcessor),i=new r.ViewDomConverter(n,{renderingMode:"data"}),s=i.blockElements,o=i.inlineObjectElements,l=[];for(const n of t.createRangeIn(e)){const e=n.item;if(e.is("element","br")){const n=W(e,"forward",t,{blockElements:s,inlineObjectElements:o}),i=W(e,"backward",t,{blockElements:s,inlineObjectElements:o}),r=F(n,s);(F(i,s)||r)&&l.push(e)}}for(const e of l)e.hasClass("Apple-interchange-newline")?t.remove(e):t.replace(e,t.createElement("p"))}function W(e,t,n,{blockElements:i,inlineObjectElements:s}){let r=n.createPositionAt(e,"forward"==t?"after":"before");return r=r.getLastMatchingPosition(({item:e})=>e.is("element")&&!i.includes(e.name)&&!s.includes(e.name),{direction:t}),"forward"==t?r.nodeAfter:r.nodeBefore}function F(e,t){return!!e&&e.is("element")&&t.includes(e.name)}function k(e){let t=e;for(;t;){if(t.is("element")){const e=t.getStyle?.("white-space");if("pre-wrap"===e)return!0}t=t.parent}return!1}function j(e,t,n){const{parent:i,data:s}=e,r=s.replaceAll("\t"," ".repeat(n)),o=i.getChildIndex(e);t.remove(e),t.insertChild(o,t.createText(r),i)}const B=/id=("|')docs-internal-guid-[-0-9a-f]+("|')/i;class D{document;constructor(e){this.document=e}isActive(e){return B.test(e)}execute(e){const t=new r.ViewUpcastWriter(this.document),{body:n}=e._parsedData;$(n,t),d(n,t),R(n,t),function(e,t,n){const i=new Set;for(const n of t.createRangeIn(e).getItems())n.is("view:$textProxy")&&n.data.includes("\t")&&k(n.parent)&&i.add(n.textNode);for(const e of i)j(e,t,n)}(n,t,8),e.content=n}}function V(e,t){for(const n of e.getChildren())n.is("element","table")&&n.hasAttribute("xmlns")&&t.removeAttribute("xmlns",n)}function N(e,t){for(const n of e.getChildren())if(n.is("element","google-sheets-html-origin")){const i=e.getChildIndex(n);t.remove(n),t.insertChild(i,n.getChildren(),e)}}function z(e,t){for(const n of Array.from(e.getChildren()))n.is("element","style")&&t.remove(n)}const U=/<google-sheets-html-origin/i;class q{document;constructor(e){this.document=e}isActive(e){return U.test(e)}execute(e){const t=new r.ViewUpcastWriter(this.document),{body:n}=e._parsedData;N(n,t),V(n,t),I(n,t),z(n,t),e.content=n}}function H(e){return K(K(e)).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," </").replace(/ <o:p><\/o:p>/g," <o:p></o:p>").replace(/<o:p>(&nbsp;|\u00A0)<\/o:p>/g,"").replace(/>([^\S\r\n]*[\r\n]\s*)</g,"><")}function G(e){e.querySelectorAll("span[style*=spacerun]").forEach(e=>{const t=e,n=t.innerText.length||0;t.innerText=Array(n+1).join("  ").substr(0,n)})}function K(e){return e.replace(/<span(?: class="Apple-converted-space"|)>(\s+)<\/span>/g,(e,t)=>1===t.length?" ":Array(t.length+1).join("  ").substr(0,t.length))}function X(e,t){const n=new DOMParser,i=H(function(e){const t="</body>",n="</html>",i=e.indexOf(t);if(i<0)return e;const s=e.indexOf(n,i+t.length);return e.substring(0,i+t.length)+(s>=0?e.substring(s):"")}(e=(e=e.replace(/<!--\[if gte vml 1]>/g,"")).replace(/<o:SmartTagType(?:\s+[^\s>=]+(?:="[^"]*")?)*\s*\/?>/gi,""))),s=n.parseFromString(i,"text/html");G(s);const o=s.body.innerHTML,l=function(e,t){const n=new r.ViewDocument(t),i=new r.ViewDomConverter(n,{renderingMode:"data"}),s=e.createDocumentFragment(),o=e.body.childNodes;for(;o.length>0;)s.appendChild(o[0]);return i.domToView(s,{skipComments:!0})}(s,t),a=function(e){const t=[],n=[],i=Array.from(e.getElementsByTagName("style"));for(const e of i)e.sheet&&e.sheet.cssRules&&e.sheet.cssRules.length&&(t.push(e.sheet),n.push(e.innerHTML));return{styles:t,stylesString:n.join(" ")}}(s);return{body:l,bodyString:o,styles:a.styles,stylesString:a.stylesString}}class J extends e.Plugin{static get pluginName(){return"PasteFromOffice"}static get licenseFeatureCode(){return"PFO"}static get isOfficialPlugin(){return!0}static get isPremiumPlugin(){return!0}static get requires(){return[t.ClipboardPipeline]}init(){const e=this.editor,t=e.plugins.get("ClipboardPipeline"),n=e.editing.view.document,i=[],s=this.editor.plugins.has("MultiLevelListEditing"),r=this.editor.plugins.has("TablePropertiesEditing"),o=!!this.editor.config.get("experimentalFlags.useExtendedTableBlockAlignment");i.push(new _(n,s,r,o)),i.push(new D(n)),i.push(new q(n)),t.on("inputTransformation",(t,s)=>{if(s._isTransformedWithPasteFromOffice)return;if(e.model.document.selection.getFirstPosition().parent.is("element","codeBlock"))return;const r=s.dataTransfer.getData("text/html"),o=i.find(e=>e.isActive(r));o&&(s._parsedData||(s._parsedData=X(r,n.stylesProcessor)),o.execute(s),s._isTransformedWithPasteFromOffice=!0)},{priority:"high"})}}})(),(window.CKEditor5=window.CKEditor5||{}).pasteFromOffice=i})();
package/dist/index.js CHANGED
@@ -98,9 +98,12 @@ import { ViewUpcastWriter, Matcher, ViewDocument, ViewDomConverter } from '@cked
98
98
  }
99
99
  const encounteredLists = {};
100
100
  const stack = [];
101
+ let topLevelListInfo = createTopLevelListInfo();
101
102
  for (const itemLikeElement of itemLikeElements){
102
103
  if (itemLikeElement.indent !== undefined) {
103
104
  if (!isListContinuation(itemLikeElement)) {
105
+ applyIndentationToTopLevelList(writer, stack, topLevelListInfo);
106
+ topLevelListInfo = createTopLevelListInfo();
104
107
  stack.length = 0;
105
108
  }
106
109
  // Combined list ID for addressing encounter lists counters.
@@ -123,15 +126,6 @@ import { ViewUpcastWriter, Matcher, ViewDocument, ViewDomConverter } from '@cked
123
126
  listStyle.startIndex = encounteredLists[originalListId];
124
127
  }
125
128
  const listElement = createNewEmptyList(listStyle, writer, hasMultiLevelListPlugin);
126
- // Apply list padding only if we have margins for the item and the parent item.
127
- if (isPx(itemLikeElement.marginLeft) && (indent == 0 || isPx(stack[indent - 1].marginLeft))) {
128
- let marginLeft = itemLikeElement.marginLeft;
129
- if (indent > 0) {
130
- // Convert the padding from absolute to relative.
131
- marginLeft = toPx(parseFloat(marginLeft) - parseFloat(stack[indent - 1].marginLeft));
132
- }
133
- writer.setStyle('padding-left', marginLeft, listElement);
134
- }
135
129
  // Insert the new OL/UL.
136
130
  if (stack.length == 0) {
137
131
  const parent = itemLikeElement.element.parent;
@@ -156,6 +150,7 @@ import { ViewUpcastWriter, Matcher, ViewDocument, ViewDomConverter } from '@cked
156
150
  // Use LI if it is already it or create a new LI element.
157
151
  // https://github.com/ckeditor/ckeditor5/issues/15964
158
152
  const listItem = itemLikeElement.element.name == 'li' ? itemLikeElement.element : writer.createElement('li');
153
+ applyListItemMarginLeftAndUpdateTopLevelInfo(writer, stack, topLevelListInfo, itemLikeElement, listItem, indent);
159
154
  // Append the LI to OL/UL.
160
155
  writer.appendChild(listItem, stack[indent].listElement);
161
156
  stack[indent].listItemElements.push(listItem);
@@ -185,6 +180,67 @@ import { ViewUpcastWriter, Matcher, ViewDocument, ViewDomConverter } from '@cked
185
180
  }
186
181
  }
187
182
  }
183
+ applyIndentationToTopLevelList(writer, stack, topLevelListInfo);
184
+ }
185
+ function applyListItemMarginLeftAndUpdateTopLevelInfo(writer, stack, topLevelListInfo, itemLikeElement, listItem, indent) {
186
+ if (itemLikeElement.marginLeft === undefined) {
187
+ // If at least one of the list items at indent = 0 does not have margin-left style, we cannot set margin-left on the list.
188
+ if (indent == 0) {
189
+ topLevelListInfo.canApplyMarginOnList = false;
190
+ }
191
+ return;
192
+ }
193
+ const listItemBlockMarginLeft = parseFloat(itemLikeElement.marginLeft);
194
+ let currentListBlockIndent = 0;
195
+ if (stack.length > 1) {
196
+ const prevStackLevelItems = stack[stack.length - 2].listItemElements;
197
+ if (prevStackLevelItems.length > 0) {
198
+ // The margin-left style of the previous indent level last item is already a relative value applied in the previous iteration.
199
+ const lastItemMargin = prevStackLevelItems[prevStackLevelItems.length - 1].getStyle('margin-left');
200
+ if (lastItemMargin !== undefined) {
201
+ currentListBlockIndent += parseFloat(lastItemMargin);
202
+ }
203
+ }
204
+ }
205
+ // Add 40px for each indent level because by default HTML lists have 40px indentation (padding-inline-start: 40px).
206
+ // So every nested list is indented by another 40px.
207
+ // Additionally, the nested list itself may be placed in a list item with margin-left style.
208
+ currentListBlockIndent += stack.length * 40;
209
+ // Calculate relative list item indentation to the list it is in.
210
+ const adjustedListItemIndent = listItemBlockMarginLeft - currentListBlockIndent;
211
+ const listItemBlockMarginLeftPx = adjustedListItemIndent !== 0 ? toPx(adjustedListItemIndent) : undefined;
212
+ if (listItemBlockMarginLeftPx) {
213
+ writer.setStyle('margin-left', listItemBlockMarginLeftPx, listItem);
214
+ if (indent == 0 && topLevelListInfo.canApplyMarginOnList) {
215
+ if (topLevelListInfo.marginLeft === undefined) {
216
+ topLevelListInfo.marginLeft = listItemBlockMarginLeftPx;
217
+ }
218
+ if (listItemBlockMarginLeftPx !== topLevelListInfo.marginLeft) {
219
+ topLevelListInfo.canApplyMarginOnList = false;
220
+ }
221
+ topLevelListInfo.topLevelListItemElements.push(listItem);
222
+ }
223
+ }
224
+ }
225
+ function createTopLevelListInfo() {
226
+ return {
227
+ marginLeft: undefined,
228
+ canApplyMarginOnList: true,
229
+ topLevelListItemElements: []
230
+ };
231
+ }
232
+ /**
233
+ * Sets margin-left style to the top-level list if all its items have the same margin-left.
234
+ * If margin-left is set on the list, it is removed from all its items to avoid doubling of margins.
235
+ */ function applyIndentationToTopLevelList(writer, stack, topLevelListInfo) {
236
+ if (topLevelListInfo.canApplyMarginOnList && topLevelListInfo.marginLeft && topLevelListInfo.topLevelListItemElements.length > 0) {
237
+ // Apply margin-left to the top-level list if all its items have the same margin-left.
238
+ writer.setStyle('margin-left', topLevelListInfo.marginLeft, stack[0].listElement);
239
+ // Remove margin-left from all top-level list items.
240
+ for (const topLevelListItem of topLevelListInfo.topLevelListItemElements){
241
+ writer.removeStyle('margin-left', topLevelListItem);
242
+ }
243
+ }
188
244
  }
189
245
  /**
190
246
  * Removes paragraph wrapping content inside a list item.