ai-helper-agent 2.8.20 → 2.8.22
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.
- package/dist/assets/chat-export-DWrq6XW7.js +37 -0
- package/dist/assets/{context-indicator-DAI73n4e.js → context-indicator-Sf2n8eWg.js} +344 -344
- package/dist/assets/options.js +13 -13
- package/dist/assets/side_panel.css +1 -1
- package/dist/assets/side_panel.js +208 -208
- package/dist/assets/{version-hglyyU4j.js → version-DLS0FCk4.js} +14 -10
- package/dist/manifest.json +1 -1
- package/dist/options.html +1 -1
- package/dist/side_panel.html +2 -2
- package/package.json +1 -1
- package/dist/assets/chat-export-DcDe1GQ_.js +0 -37
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import{a as e,c as t,l as n}from"./i18n-5c8prpFJ.js";import{C as r,S as i,Y as a,g as o,h as s,w as c}from"./version-DLS0FCk4.js";import{AlignmentType as l,BorderStyle as u,Document as d,ExternalHyperlink as f,HeadingLevel as p,ImageRun as m,LevelFormat as h,Packer as ee,Paragraph as g,Table as te,TableCell as ne,TableRow as _,TextRun as v,WidthType as y,convertInchesToTwip as b}from"./dist-BUuoW_84.js";var x=40,S=3e3,C=/^\s{0,3}(`{3,}|~{3,})/,w=/^\s{0,3}(#{1,6})[ \t]+(.*)$/,T=/^\s{0,3}=+\s*$/,E=/^\s{0,3}([-*_])(?:\s*\1){2,}\s*$/,D=/^\s*\|.*\|\s*$/,re=/^\s*(?:\d+(?:\.\d+)+[.、))]?\s*|\d+[.、))]\s*|[一二三四五六七八九十]+[、.]\s*|[((][一二三四五六七八九十\d]+[))]\s*)/,ie=/[/\\:*?"<>|]/g,ae=/[\u0000-\u001f\u007f\u200b-\u200f\u2028\u2029\ufeff]/g,O=`
|
|
2
|
+
`;function oe(e){return typeof e==`string`?e.replace(/\r\n?/g,O).replace(/\n{3,}/g,`
|
|
3
|
+
|
|
4
|
+
`):``}function se(e){return(e.length>S?e.slice(0,S):e).split(O).slice(0,x).join(O)}function ce(e){return String(e).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/`+/g,``).replace(/(\*\*|__|\*|_|~~)/g,``).replace(/https?:\/\/\S+/gi,``).replace(/<[^>]+>/g,``)}function k(e){if(typeof e!=`string`||!e.trim())return``;let t=ce(e);return t=t.replace(ae,``),t=t.replace(re,``),t=t.replace(ie,`_`),t=t.replace(/\s+/g,`-`).replace(/-{2,}/g,`-`),t=t.replace(/^[-_.\s]+/,``).replace(/[-_.\s]+$/,``),t}function A(e,t=40){let n=Array.from(e);return(n.length>t?n.slice(0,t).join(``):e).replace(/[-_.,;:、,。;:\s]+$/u,``)}function le(e){if(typeof e!=`string`||!e.trim())return``;let t=se(e).split(O),n=[],r=``;for(let e=0;e<t.length;e++){let i=t[e],a=i.match(C);if(r){a&&a[1][0]===r&&(r=``);continue}if(a){r=a[1][0];continue}let o=i.match(w);if(o){let e=o[2].replace(/[ \t]+#+[ \t]*$/,``).trim();e&&n.push({level:o[1].length,text:e});continue}let s=t[e+1];s&&T.test(s)&&i.trim()&&!E.test(i)&&!D.test(i)&&(n.push({level:1,text:i.trim()}),e++)}return n.length===0?``:A(k((n.find(e=>e.level===1)||n[0]).text))}function ue({title:e=``,kind:t,timestamp:n,ext:r}){let i=`${t}-${n}.${r}`,a=A(k(e));return a?`${a}-${i}`:i}function j(e,{kind:t,ext:n,timestamp:r=Date.now()}){return ue({title:le(e),kind:t,timestamp:r,ext:n})}e(`zh`,{chatExport:{exportFailed:`导出失败:{message}`,pdfLibNotLoaded:`PDF 库未加载,无法导出`,noContent:`没有可导出的内容`,imageLibNotLoaded:`图片库未加载,无法导出为图片`,imagePlaceholder:`[图片: {name}]`,canvasFailed:`Canvas 转 DataURL 失败:{message}`,svgLoadFailed:`SVG 图片加载失败`}}),e(`en`,{chatExport:{exportFailed:`Export failed: {message}`,pdfLibNotLoaded:`PDF library not loaded, cannot export`,noContent:`No content to export`,imageLibNotLoaded:`Image library not loaded, cannot export as image`,imagePlaceholder:`[Image: {name}]`,canvasFailed:`Canvas to DataURL failed: {message}`,svgLoadFailed:`SVG image loading failed`}});var M=new Map,N=/Mac|iPhone|iPad|iPod/i.test(typeof navigator<`u`?navigator.userAgent:``)?`Apple Color Emoji`:`Segoe UI Emoji`,P=RegExp(`(?:\\p{Regional_Indicator}{2})|(?:\\p{Emoji_Presentation}|\\p{Extended_Pictographic}\\uFE0F)(?:[\\u{1F3FB}-\\u{1F3FF}]|\\u200D(?:\\p{Emoji_Presentation}|\\p{Extended_Pictographic}\\uFE0F))*`,`gu`),F=/[\u0000-\u0008\u000B\u000C\u000E-\u001F\uFFFE\uFFFF]/g,I=/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;function L(e){return e==null||e===``?e:String(e).replace(F,``).replace(I,`�`)}var R=0;function z(){return R+=1,R}var B=new Set([`png`,`jpg`,`jpeg`,`gif`,`bmp`]);function V(e){return B.has(String(e||``).toLowerCase())}function H(e,t={}){if(!e)return[];let n=[];return String(e).split(/\r?\n/).forEach((e,r)=>{r>0&&n.push(new v({...t,break:1}));let i=0;for(let r of e.matchAll(P))r.index>i&&n.push(new v({...t,text:e.slice(i,r.index)})),n.push(new v({...t,text:r[0],font:{name:N}})),i=r.index+r[0].length;i<e.length&&n.push(new v({...t,text:e.slice(i)}))}),n}function U(e){if(!e)return[];let r=/(\*\*(.+?)\*\*|(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)|__(.+?)__|(?<!_)_(?!_)(.+?)(?<!_)_(?!_)|`([^`]+)`|\[([^\]]+)\]\(([^)]+)\)|!\[([^\]]*)\]\(([^)]+)\))/,i=[],a=e;for(;a.length>0;){let e=a.match(r);if(!e){i.push(...H(a));break}let o=e.index;o>0&&i.push(...H(a.slice(0,o)));let s=e[1];if(e[2]!==void 0)i.push(...H(e[2],{bold:!0}));else if(e[3]!==void 0)i.push(...H(e[3],{italics:!0}));else if(e[4]!==void 0)i.push(...H(e[4],{bold:!0}));else if(e[5]!==void 0)i.push(...H(e[5],{italics:!0}));else if(e[6]!==void 0)i.push(new v({text:e[6],font:`Consolas`,size:20}));else if(e[7]!==void 0)i.push(new f({children:[new v({text:e[7],style:`Hyperlink`})],link:e[8]}));else if(e[9]!==void 0){let r=e[10];if(r.startsWith(`data:`))try{let[n,a]=r.split(`,`),o=n.match(/data:(image\/(\w+))/);if(o&&a&&V(o[2])){let t=atob(a),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);let r=o[2],s=de(n,r),c=s.width,l=s.height;if(c>567){let e=567/c;c=Math.round(c*e),l=Math.round(l*e)}i.push(new m({data:n,transformation:{width:c,height:l},type:r,altText:{id:z(),name:e[9]||`image`}}))}else i.push(new v({text:t(`chatExport.imagePlaceholder`,{name:e[9]||`image`}),italics:!0,color:`999999`}))}catch(r){n.warn(`[ChatExport] ImageRun create failed:`,r.message),i.push(new v({text:t(`chatExport.imagePlaceholder`,{name:e[9]||`image`}),italics:!0,color:`999999`}))}else i.push(new v({text:t(`chatExport.imagePlaceholder`,{name:e[9]||r}),italics:!0,color:`999999`}))}a=a.slice(o+s.length)}return i}function de(e,t){if(t===`png`&&e.length>24){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);return{width:t.getUint32(16),height:t.getUint32(20)}}if((t===`jpeg`||t===`jpg`)&&e.length>100){let t=2;for(;t<e.length-9;)if(e[t]===255){let n=e[t+1];if(n>=192&&n<=195){let n=new DataView(e.buffer,e.byteOffset,e.byteLength);return{height:n.getUint16(t+5),width:n.getUint16(t+7)}}t+=2+(e[t+2]<<8|e[t+3])}else t++}return{width:600,height:400}}async function W(e){if(!e||!e.trim())return[new g({children:[new v({text:``})]})];let t=[],n=L(e),r=[];n=n.replace(/```(\w*)\n([\s\S]*?)```/g,(e,t,n)=>{let i=r.length;return r.push({lang:t||``,code:n.trimEnd()}),`\n\n%%CODEBLOCK_${i}%%\n\n`});let i=[];n=n.replace(/<table[\s\S]*?<\/table>/gi,e=>{let t=i.length;return i.push(e),`\n\n%%HTMLTABLE_${t}%%\n\n`});let a=s(n,`MDTABLE`);n=a.text;let o=a.blocks.map(e=>e.full),c=n.split(/\n{2,}/).filter(e=>e.trim());for(let e of c){let n=e.trim(),a=n.match(/^%%CODEBLOCK_(\d+)%%$/);if(a){let{lang:e,code:n}=r[parseInt(a[1])],i=e?`${e} code`:`code`;t.push(new g({children:[new v({text:i,bold:!0,font:`Consolas`,size:18})]}));let o=n.split(`
|
|
5
|
+
`);for(let e of o)t.push(new g({children:[new v({text:e||` `,font:`Consolas`,size:18})],spacing:{before:0,after:0,line:240},shading:{fill:`F5F5F5`}}));t.push(new g({children:[new v({text:``})]}));continue}let s=n.match(/^%%HTMLTABLE_(\d+)%%$/);if(s){let e=i[parseInt(s[1])],n=fe(e);n.length>0&&(t.push(G(n)),t.push(new g({children:[new v({text:``})]})));continue}let c=n.match(/^%%MDTABLE_(\d+)%%$/);if(c){let e=o[parseInt(c[1])],n=pe(e);t.push(G(n)),t.push(new g({children:[new v({text:``})]}));continue}let l=n.match(/^(#{1,6})\s+(.+)/);if(l){let e=l[1].length,r=l[2],i={1:p.HEADING_1,2:p.HEADING_2,3:p.HEADING_3,4:p.HEADING_4,5:p.HEADING_5,6:p.HEADING_6};t.push(new g({children:U(r),heading:i[e]||p.HEADING_1,border:{bottom:{style:u.SINGLE,size:6,color:`EAECEF`}}}));let a=n.slice(l[0].length).replace(/^\n+/,``).trim();a&&t.push(new g({children:U(a),spacing:{before:60,after:60}}));continue}if(/^(---|\*\*\*|___)\s*$/.test(n)){t.push(new g({children:[],border:{bottom:{style:u.SINGLE,size:6,color:`CCCCCC`}},spacing:{before:200,after:200}}));continue}if(/^[\-\*\+]\s+/.test(n)){let n=e.split(/\n(?=[\-\*\+]\s+)/);for(let e of n){let n=e.replace(/^[\-\*\+]\s+/,``);t.push(new g({children:U(n),bullet:{level:0},spacing:{before:40,after:40}}))}continue}if(/^\d+\.\s+/.test(n)){let n=e.split(/\n(?=\d+\.\s+)/);for(let e of n){let n=e.replace(/^\d+\.\s+/,``);t.push(new g({children:U(n),numbering:{reference:`default`,level:0},spacing:{before:40,after:40}}))}continue}if(n.startsWith(`>`)){let n=e.split(`
|
|
6
|
+
`).map(e=>e.replace(/^>\s?/,``)).join(`
|
|
7
|
+
`);t.push(new g({children:U(n),indent:{left:b(.5)},border:{left:{style:u.SINGLE,size:12,color:`CCCCCC`}},spacing:{before:60,after:60}}));continue}let d=U(n);t.push(new g({children:d.length>0?d:H(n),spacing:{before:60,after:60}}))}return t}function fe(e){let t=new DOMParser().parseFromString(e,`text/html`),n=[];return t.querySelectorAll(`tr`).forEach(e=>{let t=[];e.querySelectorAll(`th, td`).forEach(e=>{t.push(e.textContent.trim())}),t.length>0&&n.push(t)}),n}function pe(e){let t=e.trim().split(`
|
|
8
|
+
`),n=[];for(let e of t){if(/^[\s\|:\-]+$/.test(e.replace(/\|/g,``)))continue;let t=i(e).map(e=>e.trim());t.length>0&&n.push(t)}return n}function G(e){if(e.length===0)return new g({children:[]});let t=Math.max(...e.map(e=>e.length)),n=Math.round(100/t*100)/100;return new te({rows:e.map((e,r)=>{let i=[];for(let a=0;a<t;a++){let t=e[a]||``;i.push(new ne({children:[new g({children:U(t),spacing:{before:40,after:40}})],shading:r===0?{fill:`F2F2F2`}:void 0,width:{size:n,type:y.PERCENTAGE}}))}return new _({children:i})}),width:{size:100,type:y.PERCENTAGE},borders:{top:{style:u.SINGLE,size:1,color:`DDDDDD`},bottom:{style:u.SINGLE,size:1,color:`DDDDDD`},left:{style:u.SINGLE,size:1,color:`DDDDDD`},right:{style:u.SINGLE,size:1,color:`DDDDDD`},insideHorizontal:{style:u.SINGLE,size:1,color:`DDDDDD`},insideVertical:{style:u.SINGLE,size:1,color:`DDDDDD`}}})}function K(e){try{let t=e.toDataURL(`image/jpeg`,.85);if(t&&t.length>100)return{dataUrl:t,format:`JPEG`}}catch(e){n.debug(`[ChatExport] JPEG toDataURL failed, downgrade to PNG:`,e.message)}try{return{dataUrl:e.toDataURL(`image/png`),format:`PNG`}}catch{try{return{dataUrl:e.toDataURL(`image/jpeg`,.5),format:`JPEG`}}catch(e){throw Error(t(`chatExport.canvasFailed`,{message:e.message}))}}}async function q(e){if(typeof mermaid>`u`)return;let t=e.querySelectorAll(`.mermaid`);if(t.length!==0){for(let e of t)if(!e.querySelector(`svg`))try{await mermaid.run({nodes:[e]})}catch(e){n.warn(`[SidePanel] exporthour mermaid render failed:`,e)}}}function me(e){let t=e.closest(`.mermaid`);if(!t)return!1;let n=t.getAttribute(`data-raw-code`);if(!n)return!1;try{let e=decodeURIComponent(n);return/^\s*classDiagram/im.test(e)}catch{return!1}}function he(e){e.querySelectorAll(`foreignObject`).forEach(e=>{let t=e.querySelector(`div`);if(!t){e.remove();return}let n=t.querySelector(`span`),r=(n||t).textContent.trim();if(!r){e.remove();return}let i=parseFloat(e.getAttribute(`width`))||100,a=parseFloat(e.getAttribute(`height`))||30,o=e.getAttribute(`transform`),s=document.createElementNS(`http://www.w3.org/2000/svg`,`text`);s.setAttribute(`x`,String(i/2)),s.setAttribute(`y`,String(a/2)),s.setAttribute(`text-anchor`,`middle`),s.setAttribute(`dominant-baseline`,`central`),o&&s.setAttribute(`transform`,o);let c=n?n.getAttribute(`class`):``;c&&s.setAttribute(`class`,c),s.textContent=r,e.parentNode.replaceChild(s,e)})}async function J(e){let r=e.querySelectorAll(`svg`);if(r.length!==0)for(let e of r)try{let n=e.cloneNode(!0);me(e)?he(n):n.querySelectorAll(`foreignObject`).forEach(e=>{let t=e.querySelector(`div`);if(!t)return;let n=document.createElementNS(`http://www.w3.org/2000/svg`,`text`),r=parseFloat(e.getAttribute(`x`))||0,i=parseFloat(e.getAttribute(`y`))||0,a=parseFloat(e.getAttribute(`width`))||100,o=parseFloat(e.getAttribute(`height`))||30;window.getComputedStyle(t);let s=t.querySelector(`span`)||t,c=window.getComputedStyle(s);n.textContent=s.textContent.trim(),n.setAttribute(`x`,String(r+a/2)),n.setAttribute(`y`,String(i+o/2)),n.setAttribute(`text-anchor`,`middle`),n.setAttribute(`dominant-baseline`,`central`),n.setAttribute(`fill`,c.color||`#333`),n.setAttribute(`font-family`,c.fontFamily||`sans-serif`),n.setAttribute(`font-size`,c.fontSize||`14px`),(c.fontWeight===`bold`||parseInt(c.fontWeight)>=600)&&n.setAttribute(`font-weight`,`bold`),e.parentNode.replaceChild(n,e)});let r=e.getAttribute(`viewBox`),i,a;if(r){let e=r.split(/\s+/);i=Math.ceil(parseFloat(e[2])),a=Math.ceil(parseFloat(e[3]))}else{let t=e.getBoundingClientRect();i=Math.ceil(t.width||e.getAttribute(`width`)||300),a=Math.ceil(t.height||e.getAttribute(`height`)||200)}let o=new XMLSerializer().serializeToString(n),s=new Blob([o],{type:`image/svg+xml;charset=utf-8`}),c=URL.createObjectURL(s),l=await new Promise((e,n)=>{let r=new Image;r.onload=()=>e(r),r.onerror=()=>n(Error(t(`chatExport.svgLoadFailed`))),r.src=c}),u=document.createElement(`canvas`);u.width=i*2,u.height=a*2;let d=u.getContext(`2d`,{willReadFrequently:!0});d.scale(2,2),d.fillStyle=`#ffffff`,d.fillRect(0,0,u.width,u.height),d.drawImage(l,0,0,i,a);let{dataUrl:f,format:p}=K(u);URL.revokeObjectURL(c);let m=document.createElement(`img`);m.src=f,m.style.cssText=`max-width:100%;width:${i}px;height:auto;`,e.parentNode.replaceChild(m,e)}catch(e){n.warn(`[SidePanel] SVG rotationimage failed:`,e.name,e.message)}}function Y(e,t,n){if(!e)return;let r=e.dataset.exportBtnKey||Date.now().toString();e.dataset.exportBtnKey=r;let i=e.querySelector(`svg`),a=i?i.outerHTML:``;M.set(r,{originalSvgHTML:a,timer:null,dropdown:n||null}),i&&(i.outerHTML=`
|
|
9
|
+
<svg viewBox="0 0 24 24" fill="none" style="animation: spin 0.8s linear infinite; width: 18px; height: 18px; flex-shrink: 0;">
|
|
10
|
+
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-dasharray="31.4" stroke-dashoffset="10" opacity="0.25"/>
|
|
11
|
+
<circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-dasharray="31.4" stroke-dashoffset="10"/>
|
|
12
|
+
</svg>
|
|
13
|
+
`),e.disabled=!0,e.style.opacity=`0.6`,e.style.transition=`all 0.3s ease`}function X(e,t){if(!e)return;let n=e.dataset.exportBtnKey,r=n?M.get(n):null,i=r&&r.dropdown;i&&i.classList.remove(`show`),r&&r.timer&&clearTimeout(r.timer);let a=e.querySelector(`svg`);a&&r&&r.originalSvgHTML&&(a.outerHTML=r.originalSvgHTML),e.disabled=!1,e.style.opacity=`1`,e.style.transition=`all 0.3s ease`,n&&M.delete(n)}function Z(e){if(!e)return;let t=e.dataset.exportBtnKey,n=t?M.get(t):null,r=n&&n.dropdown;r&&r.classList.remove(`show`),n&&n.timer&&clearTimeout(n.timer);let i=e.querySelector(`svg`);i&&n&&n.originalSvgHTML&&(i.outerHTML=n.originalSvgHTML),e.disabled=!1,e.style.opacity=`1`,e.style.transition=`all 0.3s ease`,t&&M.delete(t)}async function ge(e){if(typeof mermaid>`u`||!/```mermaid/i.test(e))return e;try{let t=o(e),n=document.createElement(`div`);n.style.cssText=`position:fixed;left:-9999px;top:-9999px;`,n.innerHTML=t,document.body.appendChild(n),await q(n),await J(n);let r=n.querySelectorAll(`.mermaid`),i=[];for(let e of r){let t=e.querySelector(`img`);t&&t.src&&t.src.startsWith(`data:`)?i.push(t.src):i.push(null)}if(document.body.removeChild(n),i.length===0)return e;let a=0;return e.replace(/```\s*mermaid\s*[\r\n]+([\s\S]*?)```/gi,e=>{let t=i[a];return a++,t?``:e})}catch(t){return n.warn(`[ChatExport] Mermaid pre-render failed,will keep ascodeblock:`,t.message),e}}function Q(e){return new d({styles:{default:{document:{run:{font:`Calibri`,size:22}},heading1:{run:{size:40,bold:!0,color:`333333`},paragraph:{spacing:{before:320,after:160}}},heading2:{run:{size:30,bold:!0,color:`333333`},paragraph:{spacing:{before:280,after:120}}},heading3:{run:{size:26,bold:!0,color:`333333`},paragraph:{spacing:{before:240,after:100}}}}},numbering:{config:[{reference:`default`,levels:[0,1,2].map(e=>({level:e,format:h.DECIMAL,text:`%`+(e+1)+`.`,alignment:l.START,style:{paragraph:{indent:{left:b(.25*(e+1)),hanging:b(.25)}}}}))}]},sections:[{properties:{page:{margin:{top:b(1),right:b(1),bottom:b(1),left:b(1)}}},children:e}]})}async function $(e,r,i){let o=r.dataset.exportBtnKey;o&&M.has(o)||(Y(r,`docx`,i),requestAnimationFrame(()=>{requestAnimationFrame(async()=>{try{let t=e.dataset.rawMarkdown||e.dataset.rawContent||``;if(!t){let n=e.querySelector(`.markdown-body`);t=n?n.innerText:e.innerText}t=await ge(t);let i=Q(await W(t)),a=await ee.toBlob(i),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=j(t,{kind:`word`,ext:`docx`}),document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o),X(r,`docx`),n.debug(`[SidePanel] Word (docx) document export successful`)}catch(e){n.error(`[SidePanel] export Word failed:`,e),a(t(`chatExport.exportFailed`,{message:e.message}),`error`),Z(r)}})}))}function _e(e,r,i){let s=r.dataset.exportBtnKey;s&&M.has(s)||(Y(r,`pdf`,i),requestAnimationFrame(()=>{requestAnimationFrame(async()=>{try{let{jsPDF:i,html2canvas:s}=await c();if(!i||!s){a(t(`chatExport.pdfLibNotLoaded`),`error`),Z(r);return}let l=e.dataset.rawMarkdown||e.dataset.rawContent||``;if(!l){let t=e.querySelector(`.markdown-body`);l=t?t.innerText:e.innerText}let u=j(l,{kind:`pdf`,ext:`pdf`}),d=document.createElement(`div`);d.style.cssText=`
|
|
14
|
+
position: fixed;
|
|
15
|
+
left: -9999px;
|
|
16
|
+
top: -9999px;
|
|
17
|
+
width: 515px;
|
|
18
|
+
padding: 40px;
|
|
19
|
+
background: white;
|
|
20
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
|
|
21
|
+
font-size: 12px;
|
|
22
|
+
line-height: 1.6;
|
|
23
|
+
color: #333;
|
|
24
|
+
box-sizing: border-box;
|
|
25
|
+
`;let f=document.createElement(`div`);f.className=`markdown-body`,f.innerHTML=o(l),d.appendChild(f),document.body.appendChild(d),await q(d),await J(d);let p=d.scrollHeight,m=Math.ceil(p/762);s(d,{scale:2,useCORS:!0,logging:!1,backgroundColor:`#ffffff`,willReadFrequently:!0}).then(e=>{let t=new i({orientation:`portrait`,unit:`px`,format:[595,842],compress:!0}),a=e.width,o=e.height,s=o/p,c=762*s;for(let n=0;n<m;n++){n>0&&t.addPage();let r=n*c,i=Math.min(r+c,o)-r,l=document.createElement(`canvas`);l.width=a,l.height=i;let u=l.getContext(`2d`,{willReadFrequently:!0});u.fillStyle=`#ffffff`,u.fillRect(0,0,l.width,l.height),u.drawImage(e,0,r,a,i,0,0,a,i);let{dataUrl:d,format:f}=K(l),p=i/s;t.addImage(d,f,0,0,595,p,void 0,`FAST`)}t.save(u),X(r,`pdf`),document.body.removeChild(d),n.debug(`[SidePanel] PDF export successful:`,u)}).catch(e=>{n.error(`[SidePanel] PDF export failed:`,e),a(t(`chatExport.exportFailed`,{message:e.message}),`error`),document.body.removeChild(d),Z(r)})}catch(e){n.error(`[SidePanel] export PDF failed:`,e),a(t(`chatExport.exportFailed`,{message:e.message}),`error`),Z(r)}})}))}function ve(e,r,i){let o=r.dataset.exportBtnKey;o&&M.has(o)||(Y(r,`md`,i),requestAnimationFrame(()=>{requestAnimationFrame(()=>{try{let i=e.dataset.rawMarkdown||e.dataset.rawContent||``;if(!i){let t=e.querySelector(`.assistant-message-content, .message-content`);t&&(i=t.innerText||t.textContent||``)}if(!i.trim()){a(t(`chatExport.noContent`),`error`),Z(r);return}i=oe(i);let o=j(i,{kind:`md`,ext:`md`}),s=new Blob([i],{type:`text/markdown;charset=utf-8`}),c=URL.createObjectURL(s),l=document.createElement(`a`);l.href=c,l.download=o,document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(c),X(r,`md`),n.debug(`[SidePanel] Markdown export successful:`,o)}catch(e){n.error(`[SidePanel] export Markdown failed:`,e),a(t(`chatExport.exportFailed`,{message:e.message}),`error`),Z(r)}})}))}function ye(e,i,s){let c=i.dataset.exportBtnKey;c&&M.has(c)||(Y(i,`image`,s),requestAnimationFrame(()=>{requestAnimationFrame(async()=>{let s=null;try{let c=await r();if(!c){a(t(`chatExport.imageLibNotLoaded`),`error`),Z(i);return}let l=e.dataset.rawMarkdown||e.dataset.rawContent||``;if(!l){let t=e.querySelector(`.markdown-body`);l=t?t.innerText:e.innerText}let u=j(l,{kind:`image`,ext:`jpg`}),d=Math.ceil(e.getBoundingClientRect().width),f=Math.max(595,d);s=document.createElement(`div`),s.style.cssText=`
|
|
26
|
+
position: fixed;
|
|
27
|
+
left: -9999px;
|
|
28
|
+
top: -9999px;
|
|
29
|
+
width: ${f}px;
|
|
30
|
+
padding: 40px;
|
|
31
|
+
background: white;
|
|
32
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
|
|
33
|
+
font-size: 14px;
|
|
34
|
+
line-height: 1.6;
|
|
35
|
+
color: #333;
|
|
36
|
+
box-sizing: border-box;
|
|
37
|
+
`;let p=document.createElement(`div`);p.className=`markdown-body`,p.innerHTML=o(l),s.appendChild(p),document.body.appendChild(s),await q(s),await J(s),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(e)));let m=(await c(s,{scale:2,useCORS:!0,logging:!1,backgroundColor:`#ffffff`,willReadFrequently:!0})).toDataURL(`image/jpeg`,.92),h=document.createElement(`a`);h.href=m,h.download=u,document.body.appendChild(h),h.click(),document.body.removeChild(h),X(i,`image`),document.body.removeChild(s),s=null,n.debug(`[SidePanel] image export successful:`,u)}catch(e){n.error(`[SidePanel] export image failed:`,e),a(t(`chatExport.exportFailed`,{message:e.message}),`error`),s&&s.parentNode&&document.body.removeChild(s),Z(i)}})}))}export{J as convertSvgsToImages,Q as createDocxDocument,H as createTextRuns,$ as exportAssistantMessageToDocx,ye as exportAssistantMessageToImage,ve as exportAssistantMessageToMarkdown,_e as exportAssistantMessageToPdf,V as isDocxEmbeddableImageType,z as nextDocxImageId,U as parseInlineMarkdown,W as parseMarkdownToDocxChildren,q as renderMermaidInContainer,Z as resetExportButton,L as sanitizeDocxText,Y as setExportButtonLoading,X as setExportButtonSuccess};
|