UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

2 lines (1 loc) 1.59 kB
var m=Object.defineProperty;var d=(t,e)=>m(t,"name",{value:e,configurable:!0});import{toArray as c}from"jodit/esm/core/helpers/index.js";const j=d((t,e)=>{var l,h;if(e.rtf&&t.name==="#comment"&&t.attributes.nodeValue&&t.attributes.nodeValue.indexOf("<v:shape")!==-1){e.shapes||(e.shapes={});const n=e.jodit.create.fromHTML(t.attributes.nodeValue);return c(n.getElementsByTagName("v:shape")).forEach(s=>{e.shapes[s.id]=s.getAttribute("o:spid")}),t}if(t.name!=="img")return t;if(e.rtf&&t.attributes["v:shapes"]){const n=(l=e.shapes)===null||l===void 0?void 0:l[t.attributes["v:shapes"]];if(n){const s=(h=e.imageMap)!==null&&h!==void 0?h:{};e.imageMap||(e.imageMap=s,b(e.rtf,"i","\\shppict",e.imageMap),b(e.rtf,"s","\\shp{",e.imageMap));const p=s[n.substring(7)];if(p){const a=[],o=p.hex.match(/[0-9a-f]{2}/gi);if(o){for(let i=0;i<o.length;i++){const r=parseInt(o[i],16);a.push(String.fromCharCode(r))}t.attributes.src="data:"+p.type+";base64,"+btoa(a.join(""))}}}}return t},"processImage");function b(t,e,l,h){const n=t.split(l);for(const s of n){const p=s.split("shplid");if(1<p.length){const a=p[1];let o="";for(let u=0;u<a.length&&!/[{ \r\n\\]/.test(a[u]);u++)o+=a[u];const i=a.split("bliptag");if(i&&i.length<2)continue;let r=null;if(i[0].indexOf("pngblip")?r="image/png":i[0].indexOf("jpegblip")!==-1&&(r="image/jpeg"),!r)continue;const f=i[1].split("}");if(f&&f.length<2)continue;let g;if(2<f.length&&f[0].includes("blipuid"))g=f[1].split(" ");else{if(g=f[0].split(" "),g&&g.length<2)continue;g.shift()}h[e+o]={hex:g.join(""),type:r}}}}d(b,"parseImages");export{j as processImage};